Search in sources :

Example 11 with BeanSetting

use of jmri.BeanSetting in project JMRI by JMRI.

the class OPath method equals.

/**
     * {@inheritDoc}
     *
     * Override to indicate logical equality for use as paths in OBlocks.
     */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    OPath path = (OPath) obj;
    if (getBlock() != path.getBlock()) {
        return false;
    }
    if (_fromPortal != null && !_fromPortal.equals(path.getFromPortal()) && !_fromPortal.equals(path.getToPortal())) {
        return false;
    }
    if (_toPortal != null && !_toPortal.equals(path.getToPortal()) && !_toPortal.equals(path.getFromPortal())) {
        return false;
    }
    Iterator<BeanSetting> iter = path.getSettings().iterator();
    while (iter.hasNext()) {
        BeanSetting beanSetting = iter.next();
        Iterator<BeanSetting> it = getSettings().iterator();
        while (it.hasNext()) {
            BeanSetting bs = it.next();
            if (!bs.getBeanName().equals(beanSetting.getBeanName())) {
                return false;
            }
            if (bs.getSetting() != beanSetting.getSetting()) {
                return false;
            }
        }
    }
    return true;
}
Also used : BeanSetting(jmri.BeanSetting)

Example 12 with BeanSetting

use of jmri.BeanSetting in project JMRI by JMRI.

the class EditCircuitPaths method addPath.

/**
     * Create or update the selected path named in the text field
     * Checks that icons have been selected for the path
     */
private void addPath() {
    String name = _pathName.getText();
    if (name == null || name.trim().length() == 0) {
        JOptionPane.showMessageDialog(this, Bundle.getMessage("TooltipPathName"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    OPath otherPath = _block.getPathByName(name);
    boolean sameName = false;
    if (otherPath != null) {
        _pathList.setSelectedValue(otherPath, true);
        sameName = true;
        if (!_pathChange) {
            // check portals OK
            Portal p = otherPath.getFromPortal();
            if (p != null && !p.isValidPath(otherPath)) {
                p.addPath(otherPath);
            }
            p = otherPath.getToPortal();
            if (p != null && !p.isValidPath(otherPath)) {
                p.addPath(otherPath);
            }
            setPathLength(otherPath);
            return;
        }
    }
    OPath path = makeOPath(name, _pathGroup, true);
    if (path == null) {
        // proper OPath cannot be made
        return;
    }
    if (otherPath == null) {
        // is this path already defined?
        Iterator<Path> iter = _block.getPaths().iterator();
        while (iter.hasNext()) {
            OPath p = (OPath) iter.next();
            if (pathsEqual(path, p)) {
                otherPath = p;
                break;
            }
        }
    }
    // match icons to current selections
    changePathNameInIcons(name, path);
    if (otherPath != null) {
        // same path
        if (!sameName) {
            int result = JOptionPane.showConfirmDialog(this, Bundle.getMessage("samePath", otherPath.getName(), name), Bundle.getMessage("makePath"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (result == JOptionPane.YES_OPTION) {
                changePathName();
            }
        }
        _pathList.setSelectedValue(otherPath, true);
    }
    Portal toPortal = path.getToPortal();
    Portal fromPortal = path.getFromPortal();
    if (fromPortal != null && fromPortal.equals(toPortal)) {
        int result = JOptionPane.showConfirmDialog(this, Bundle.getMessage("balloonTrack", name, fromPortal.getDescription()), Bundle.getMessage("makePath"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (result == JOptionPane.NO_OPTION) {
            fromPortal = null;
        }
    }
    _pathChange = false;
    // Just update OPath changes
    if (sameName) {
        OPath oldPath = _block.getPathByName(name);
        oldPath.setToPortal(toPortal);
        oldPath.setFromPortal(fromPortal);
        setPathLength(oldPath);
        oldPath.clearSettings();
        Iterator<BeanSetting> it = path.getSettings().iterator();
        while (it.hasNext()) {
            oldPath.addSetting(it.next());
        }
        toPortal.addPath(oldPath);
        if (fromPortal != null) {
            fromPortal.addPath(oldPath);
        }
    } else {
        // OBlock adds path to portals and checks for duplicate path names
        _block.addPath(path);
        setPathLength(path);
    }
    _pathList.setSelectedValue(path, true);
    _pathListModel.dataChange();
}
Also used : OPath(jmri.jmrit.logix.OPath) Path(jmri.Path) BeanSetting(jmri.BeanSetting) Portal(jmri.jmrit.logix.Portal) OPath(jmri.jmrit.logix.OPath) Point(java.awt.Point)

Example 13 with BeanSetting

use of jmri.BeanSetting in project JMRI by JMRI.

the class EditCircuitPaths method makeOPath.

/**
     * Make the OPath from the icons in the Iterator
     */
private OPath makeOPath(String name, ArrayList<Positionable> pathGp, boolean showMsg) {
    if (pathGp.size() == 0) {
        if (showMsg) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("noPathIcons"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
        }
        return null;
    }
    Iterator<Positionable> it = pathGp.iterator();
    ArrayList<BeanSetting> settings = new ArrayList<BeanSetting>();
    Portal fromPortal = null;
    Portal toPortal = null;
    boolean hasTrack = false;
    int portalIconCount = 0;
    while (it.hasNext()) {
        Positionable pos = it.next();
        if (pos instanceof IndicatorTurnoutIcon) {
            jmri.Turnout t = ((IndicatorTurnoutIcon) pos).getTurnout();
            String turnoutName = ((IndicatorTurnoutIcon) pos).getNamedTurnout().getName();
            int state = t.getKnownState();
            if (state != Turnout.CLOSED && state != Turnout.THROWN) {
                if (showMsg) {
                    JOptionPane.showMessageDialog(this, Bundle.getMessage("turnoutNotSet", t.getDisplayName()), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
                }
                return null;
            }
            settings.add(new BeanSetting(t, turnoutName, state));
            hasTrack = true;
        } else if (pos instanceof PortalIcon) {
            if (toPortal == null) {
                toPortal = ((PortalIcon) pos).getPortal();
            } else if (fromPortal == null) {
                fromPortal = ((PortalIcon) pos).getPortal();
            }
            portalIconCount++;
        } else if (pos instanceof IndicatorTrack) {
            hasTrack = true;
        }
    }
    if (showMsg) {
        if (!hasTrack) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("noPathIcons"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
            return null;
        }
        if (toPortal == null && fromPortal == null) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("tooFewPortals"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
            return null;
        }
        if (portalIconCount == 0) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("noPortalIcons"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
        }
        if (portalIconCount > 2) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("tooManyPortals"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
            return null;
        }
    }
    if (hasTrack && portalIconCount > 0 && portalIconCount < 3) {
        return new OPath(name, _block, fromPortal, toPortal, settings);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) Turnout(jmri.Turnout) OPath(jmri.jmrit.logix.OPath) Point(java.awt.Point) BeanSetting(jmri.BeanSetting) IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Portal(jmri.jmrit.logix.Portal) Positionable(jmri.jmrit.display.Positionable)

Example 14 with BeanSetting

use of jmri.BeanSetting in project JMRI by JMRI.

the class BlockManagerXmlTest method testStore.

/**
     * This test checks that the store operation runs, but doesn't check the
     * output for correctness.
     */
public void testStore() throws jmri.JmriException {
    JUnitUtil.resetInstanceManager();
    JUnitUtil.initConfigureManager();
    JUnitUtil.initInternalTurnoutManager();
    JUnitUtil.initInternalLightManager();
    JUnitUtil.initInternalSensorManager();
    JUnitUtil.initMemoryManager();
    JUnitUtil.initLayoutBlockManager();
    Block b1 = InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock("SystemNameb1", "");
    Block b2 = InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock("SystemNameb2", "");
    Sensor s2 = new AbstractSensor("IS2") {

        @Override
        public void requestUpdateFromLayout() {
        }
    };
    b2.setSensor("IS2");
    s2.setState(Sensor.ACTIVE);
    b2.setValue("b2 contents");
    Path p21 = new Path();
    p21.setBlock(b1);
    p21.setFromBlockDirection(Path.RIGHT);
    p21.setToBlockDirection(Path.LEFT);
    p21.addSetting(new BeanSetting(new jmri.implementation.AbstractTurnout("IT1") {

        @Override
        public void turnoutPushbuttonLockout(boolean b) {
        }

        @Override
        public void forwardCommandChangeToLayout(int i) {
        }
    }, jmri.Turnout.THROWN));
    b2.addPath(p21);
//BlockManagerXml tb = new BlockManagerXml();
}
Also used : Path(jmri.Path) BeanSetting(jmri.BeanSetting) Block(jmri.Block) AbstractSensor(jmri.implementation.AbstractSensor) Sensor(jmri.Sensor) AbstractSensor(jmri.implementation.AbstractSensor)

Example 15 with BeanSetting

use of jmri.BeanSetting in project JMRI by JMRI.

the class WarrantTest method testWarrant.

/**
     * tests depend on the order of execution.
     * So this will be one large test.
     */
@Test
public void testWarrant() {
    _OBlockMgr = InstanceManager.getDefault(OBlockManager.class);
    OBlock bWest = _OBlockMgr.createNewOBlock("OB1", "West");
    OBlock bEast = _OBlockMgr.createNewOBlock("OB2", "East");
    OBlock bNorth = _OBlockMgr.createNewOBlock("OB3", "North");
    OBlock bSouth = _OBlockMgr.createNewOBlock("OB4", "South");
    Assert.assertEquals("OBlock", bNorth, _OBlockMgr.getOBlock("North"));
    Assert.assertEquals("OBlock", bEast, _OBlockMgr.getOBlock("OB2"));
    _portalMgr = InstanceManager.getDefault(PortalManager.class);
    Portal pNorthWest = _portalMgr.createNewPortal(null, "NorthWest");
    pNorthWest.setToBlock(bWest, false);
    pNorthWest.setFromBlock(bNorth, false);
    Portal pSouthWest = _portalMgr.createNewPortal(null, "SouthWest");
    pSouthWest.setToBlock(bWest, false);
    pSouthWest.setFromBlock(bSouth, false);
    Assert.assertEquals("Portal", pNorthWest, _portalMgr.getPortal("NorthWest"));
    Assert.assertEquals("Portal Block", bSouth, _portalMgr.getPortal("SouthWest").getFromBlock());
    Assert.assertEquals("Portal", pSouthWest, bSouth.getPortalByName("SouthWest"));
    Assert.assertEquals("Portal Block", "West", _portalMgr.getPortal("NorthWest").getToBlockName());
    Assert.assertEquals("Portal Block", "North", _portalMgr.getPortal("NorthWest").getFromBlockName());
    Portal pNorthEast = _portalMgr.createNewPortal(null, "NorthEast");
    pNorthEast.setToBlock(_OBlockMgr.getOBlock("OB2"), false);
    pNorthEast.setFromBlock(_OBlockMgr.getOBlock("North"), false);
    Portal pSouthEast = _portalMgr.createNewPortal(null, "SouthEast");
    OBlock east = _OBlockMgr.getOBlock("OB2");
    pSouthEast.setToBlock(east, false);
    pSouthEast.setFromBlock(_OBlockMgr.getOBlock("South"), false);
    Assert.assertEquals("Portal Block", east, _portalMgr.getPortal("SouthEast").getToBlock());
    Assert.assertEquals("Portal Block", "West", _portalMgr.getPortal("NorthWest").getToBlockName());
    Assert.assertEquals("Portal Block", _OBlockMgr.getOBlock("South"), _portalMgr.getPortal("SouthWest").getFromBlock());
    _turnoutMgr = InstanceManager.turnoutManagerInstance();
    Turnout northSwitch = _turnoutMgr.newTurnout("IT1", "NorthSwitch");
    ArrayList<BeanSetting> settings = new ArrayList<BeanSetting>();
    settings.add(new BeanSetting(northSwitch, "NorthSwitch", Turnout.CLOSED));
    OBlock north = _OBlockMgr.getOBlock("North");
    OPath path = new OPath("NorthToWest", north, null, _portalMgr.getPortal("NorthWest"), settings);
    north.addPath(path);
    settings = new ArrayList<BeanSetting>();
    settings.add(new BeanSetting(northSwitch, "NorthSwitch", Turnout.THROWN));
    path = new OPath("NorthToEast", north, null, _portalMgr.getPortal("NorthEast"), settings);
    north.addPath(path);
    Assert.assertEquals("Path Block", path, north.getPathByName("NorthToEast"));
    Assert.assertEquals("Path Block", "NorthToWest", north.getPathByName("NorthToWest").getName());
    Turnout southSwitch = _turnoutMgr.newTurnout("IT2", "SouthSwitch");
    OBlock south = _OBlockMgr.getOBlock("South");
    settings = new ArrayList<BeanSetting>();
    settings.add(new BeanSetting(southSwitch, "SouthSwitch", Turnout.THROWN));
    path = new OPath("SouthToEast", south, null, _portalMgr.getPortal("SouthEast"), settings);
    south.addPath(path);
    settings = new ArrayList<BeanSetting>();
    settings.add(new BeanSetting(southSwitch, "SouthSwitch", Turnout.CLOSED));
    path = new OPath("SouthToWest", south, null, south.getPortalByName("SouthWest"), settings);
    south.addPath(path);
    Assert.assertEquals("Path Block", path, south.getPathByName("SouthToWest"));
    Assert.assertEquals("Path Block", "SouthToEast", south.getPathByName("SouthToEast").getName());
    settings = new ArrayList<BeanSetting>();
    OBlock block = _OBlockMgr.getOBlock("West");
    path = new OPath("SouthToNorth", block, _portalMgr.getPortal("NorthWest"), _portalMgr.getPortal("SouthWest"), settings);
    _OBlockMgr.getOBlock("West").addPath(path);
    Assert.assertEquals("Path Block", path, block.getPathByName("SouthToNorth"));
    settings = new ArrayList<BeanSetting>();
    block = _OBlockMgr.getOBlock("East");
    path = new OPath("NorthToSouth", block, south.getPortalByName("SouthEast"), north.getPortalByName("NorthEast"), settings);
    _OBlockMgr.getOBlock("East").addPath(path);
    Assert.assertEquals("Path Block", path, block.getPathByName("NorthToSouth"));
    _sensorMgr = InstanceManager.getDefault(SensorManager.class);
    Sensor sWest = _sensorMgr.newSensor("IS1", "WestSensor");
    Sensor sEast = _sensorMgr.newSensor("IS2", "EastSensor");
    Sensor sNorth = _sensorMgr.newSensor("IS3", "NorthSensor");
    Sensor sSouth = _sensorMgr.newSensor("IS4", "SouthSensor");
    bWest.setSensor("WestSensor");
    bEast.setSensor("IS2");
    bNorth.setSensor("NorthSensor");
    bSouth.setSensor("IS4");
    Assert.assertEquals("Sensor Block", sNorth, bNorth.getSensor());
    Assert.assertEquals("Sensor Block", sSouth, bSouth.getSensor());
    try {
        sWest.setState(Sensor.INACTIVE);
        sEast.setState(Sensor.ACTIVE);
        sNorth.setState(Sensor.INACTIVE);
        sSouth.setState(Sensor.ACTIVE);
    } catch (JmriException je) {
    }
    Assert.assertEquals("Block Detection 1", OBlock.UNOCCUPIED, bWest.getState());
    Assert.assertEquals("Block Detection 2", OBlock.OCCUPIED, bEast.getState());
    Warrant warrant = new Warrant("IW0", "AllTestWarrant");
    bWest.allocate(warrant);
    bEast.allocate(warrant);
    Assert.assertEquals("Block Detection 3", OBlock.UNOCCUPIED | OBlock.ALLOCATED, bWest.getState());
    Assert.assertEquals("Block Detection 4", OBlock.OCCUPIED | OBlock.ALLOCATED, bEast.getState());
    try {
        sEast.setState(Sensor.INACTIVE);
        sSouth.setState(Sensor.INACTIVE);
        // start block of warrant
        sNorth.setState(Sensor.ACTIVE);
    } catch (JmriException je) {
    }
    bWest.deAllocate(warrant);
    bEast.deAllocate(warrant);
    Assert.assertEquals("Block Detection 5", OBlock.UNOCCUPIED, bWest.getState());
    Assert.assertEquals("Block Detection 6", OBlock.UNOCCUPIED, bEast.getState());
    ArrayList<BlockOrder> orders = new ArrayList<BlockOrder>();
    orders.add(new BlockOrder(_OBlockMgr.getOBlock("North"), "NorthToWest", "", "NorthWest"));
    BlockOrder viaOrder = new BlockOrder(_OBlockMgr.getOBlock("West"), "SouthToNorth", "NorthWest", "SouthWest");
    orders.add(viaOrder);
    BlockOrder lastOrder = new BlockOrder(_OBlockMgr.getOBlock("South"), "SouthToWest", "SouthWest", null);
    orders.add(lastOrder);
    warrant.setViaOrder(viaOrder);
    warrant.setBlockOrders(orders);
    Assert.assertEquals("BlockOrder", warrant.getLastOrder().toString(), lastOrder.toString());
    Assert.assertEquals("BlockOrder", warrant.getViaOrder().toString(), viaOrder.toString());
    String msg = warrant.allocateRoute(orders);
    Assert.assertNull("allocateRoute - " + msg, msg);
    warrant.deAllocate();
    warrant.setThrottleCommands(new ArrayList<ThrottleSetting>());
    warrant.addThrottleCommand(new ThrottleSetting(0, "Speed", "0.0", "North"));
    warrant.addThrottleCommand(new ThrottleSetting(10, "Speed", "0.4", "North"));
    warrant.addThrottleCommand(new ThrottleSetting(100, "NoOp", "Enter Block", "West"));
    warrant.addThrottleCommand(new ThrottleSetting(100, "Speed", "0.5", "West"));
    warrant.addThrottleCommand(new ThrottleSetting(100, "NoOp", "Enter Block", "South"));
    warrant.addThrottleCommand(new ThrottleSetting(100, "Speed", "0.3", "South"));
    warrant.addThrottleCommand(new ThrottleSetting(100, "Speed", "0.0", "South"));
    List<ThrottleSetting> list = warrant.getThrottleCommands();
    Assert.assertEquals("ThrottleCommands", 7, list.size());
    //        DccLocoAddress dccAddress = new DccLocoAddress(999, true);
    //        Assert.assertNotNull("dccAddress", dccAddress);
    warrant.setDccAddress("999(L)");
    msg = warrant.setRoute(0, orders);
    Assert.assertNull("setRoute - " + msg, msg);
    msg = warrant.checkStartBlock(Warrant.MODE_RUN);
    Assert.assertNull("checkStartBlock - " + msg, msg);
    msg = warrant.checkRoute();
    Assert.assertNull("checkRoute - " + msg, msg);
    warrant.setTrainName("TestTrain");
    PropertyChangeListener listener = new WarrantListener(warrant);
    Assert.assertNotNull("PropertyChangeListener", listener);
    warrant.addPropertyChangeListener(listener);
    msg = warrant.setRunMode(Warrant.MODE_RUN, null, null, null, false);
    Assert.assertNull("setRunMode - " + msg, msg);
    jmri.util.JUnitUtil.waitFor(() -> {
        String m = warrant.getRunningMessage();
        return m.endsWith("Cmd #2.");
    }, "Train starts to move after 2nd command");
    // nothing specific to wait for...
    jmri.util.JUnitUtil.releaseThread(this);
    jmri.util.ThreadingUtil.runOnLayout(() -> {
        try {
            sWest.setState(Sensor.ACTIVE);
        } catch (jmri.JmriException e) {
            Assert.fail("Unexpected Exception: " + e);
        }
    });
    jmri.util.JUnitUtil.releaseThread(this);
    jmri.util.ThreadingUtil.runOnLayout(() -> {
        try {
            sSouth.setState(Sensor.ACTIVE);
        } catch (jmri.JmriException e) {
            Assert.fail("Unexpected Exception: " + e);
        }
    });
    jmri.util.JUnitUtil.releaseThread(this);
    // confirm one message logged
    jmri.util.JUnitAppender.assertWarnMessage("RosterSpeedProfile not found. Using default ThrottleFactor 0.75");
    // wait for done
    jmri.util.JUnitUtil.waitFor(() -> {
        return warrant.getThrottle() == null;
    }, "engineer blocked");
    msg = warrant.getRunningMessage();
    Assert.assertEquals("getRunningMessage", "Idle", msg);
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) JmriException(jmri.JmriException) ArrayList(java.util.ArrayList) JmriException(jmri.JmriException) SensorManager(jmri.SensorManager) BeanSetting(jmri.BeanSetting) Turnout(jmri.Turnout) Sensor(jmri.Sensor) Test(org.junit.Test)

Aggregations

BeanSetting (jmri.BeanSetting)15 Turnout (jmri.Turnout)6 Portal (jmri.jmrit.logix.Portal)5 Element (org.jdom2.Element)4 OPath (jmri.jmrit.logix.OPath)3 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)2 Path (jmri.Path)2 Sensor (jmri.Sensor)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 Block (jmri.Block)1 JmriException (jmri.JmriException)1 NamedBean (jmri.NamedBean)1 SensorManager (jmri.SensorManager)1 AbstractSensor (jmri.implementation.AbstractSensor)1 IndicatorTrack (jmri.jmrit.display.IndicatorTrack)1 IndicatorTurnoutIcon (jmri.jmrit.display.IndicatorTurnoutIcon)1 Positionable (jmri.jmrit.display.Positionable)1 Attribute (org.jdom2.Attribute)1