Search in sources :

Example 26 with SignalMast

use of jmri.SignalMast in project JMRI by JMRI.

the class JsonSignalMastSocketServiceTest method testSignalMastChange.

@Test
@Ignore("Needs setup completed")
public void testSignalMastChange() {
    try {
        //create a signalmast for testing
        String sysName = "IF$shsm:basic:one-searchlight:SM2";
        String userName = "SM2";
        SignalMastManager manager = InstanceManager.getDefault(SignalMastManager.class);
        SignalMast s = manager.provideSignalMast(sysName);
        s.setUserName(userName);
        JsonMockConnection connection = new JsonMockConnection((DataOutputStream) null);
        JsonNode message = connection.getObjectMapper().createObjectNode().put(JSON.NAME, sysName);
        JsonSignalMastSocketService service = new JsonSignalMastSocketService(connection);
        service.onMessage(JsonSignalMast.SIGNAL_MAST, message, Locale.ENGLISH);
        // TODO: test that service is listener in SignalMastManager
        Assert.assertEquals(JSON.ASPECT_UNKNOWN, connection.getMessage().path(JSON.DATA).path(JSON.STATE).asText());
        //change to Approach, and wait for change to show up
        s.setAspect("Approach");
        JUnitUtil.waitFor(() -> {
            return s.getAspect().equals("Approach");
        }, "SignalMast is now Approach");
        Assert.assertEquals("Approach", connection.getMessage().path(JSON.DATA).path(JSON.STATE).asText());
        //change to Stop, and wait for change to show up
        s.setAspect("Stop");
        JUnitUtil.waitFor(() -> {
            return s.getAspect().equals("Stop");
        }, "SignalMast is now Stop");
        Assert.assertEquals("Stop", connection.getMessage().path(JSON.DATA).path(JSON.STATE).asText());
        service.onClose();
    //            // TODO: test that service is no longer a listener in SignalMastManager
    } catch (IOException | JmriException | JsonException ex) {
        Assert.fail(ex.getMessage());
    }
}
Also used : JsonException(jmri.server.json.JsonException) JsonMockConnection(jmri.server.json.JsonMockConnection) SignalMastManager(jmri.SignalMastManager) SignalMast(jmri.SignalMast) JmriException(jmri.JmriException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 27 with SignalMast

use of jmri.SignalMast in project JMRI by JMRI.

the class EntryExitPairsXml method store.

/**
     * Default implementation for storing the contents of a PositionablePoint.
     *
     * @param o Object to store, of type PositionablePoint
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    EntryExitPairs p = (EntryExitPairs) o;
    Element element = new Element("entryexitpairs");
    setStoreElementClass(element);
    ArrayList<LayoutEditor> editors = p.getSourcePanelList();
    if (editors.size() == 0) {
        return element;
    }
    element.addContent(new Element("cleardown").addContent("" + p.getClearDownOption()));
    if (p.getDispatcherIntegration()) {
        element.addContent(new Element("dispatcherintegration").addContent("yes"));
    }
    if (p.useDifferentColorWhenSetting()) {
        element.addContent(new Element("colourwhilesetting").addContent(colorToString(p.getSettingRouteColor())));
        element.addContent(new Element("settingTimer").addContent("" + p.getSettingTimer()));
    }
    for (int k = 0; k < editors.size(); k++) {
        LayoutEditor panel = editors.get(k);
        List<Object> nxpair = p.getSourceList(panel);
        Element panelElem = new Element("layoutPanel");
        panelElem.setAttribute("name", panel.getLayoutName());
        for (int j = 0; j < nxpair.size(); j++) {
            Object key = nxpair.get(j);
            Element source = new Element("source");
            String type = "";
            String item = "";
            if (key instanceof SignalMast) {
                type = "signalMast";
                item = ((SignalMast) key).getDisplayName();
            } else if (key instanceof Sensor) {
                type = "sensor";
                item = ((Sensor) key).getDisplayName();
            } else if (key instanceof SignalHead) {
                type = "signalHead";
                item = ((SignalHead) key).getDisplayName();
            }
            source.setAttribute("type", type);
            source.setAttribute("item", item);
            ArrayList<Object> a = p.getDestinationList(key, panel);
            for (int i = 0; i < a.size(); i++) {
                Object keyDest = a.get(i);
                String typeDest = "";
                String itemDest = "";
                if (keyDest instanceof SignalMast) {
                    typeDest = "signalMast";
                    itemDest = ((SignalMast) keyDest).getDisplayName();
                } else if (keyDest instanceof Sensor) {
                    typeDest = "sensor";
                    itemDest = ((Sensor) keyDest).getDisplayName();
                } else if (keyDest instanceof SignalHead) {
                    typeDest = "signalHead";
                    itemDest = ((SignalHead) keyDest).getDisplayName();
                }
                Element dest = new Element("destination");
                dest.setAttribute("type", typeDest);
                dest.setAttribute("item", itemDest);
                if (!p.isUniDirection(key, panel, keyDest)) {
                    dest.setAttribute("uniDirection", "no");
                }
                if (!p.isEnabled(key, panel, keyDest)) {
                    dest.setAttribute("enabled", "no");
                }
                int nxType = p.getEntryExitType(key, panel, keyDest);
                switch(nxType) {
                    case 0x00:
                        dest.setAttribute("nxType", "turnoutsetting");
                        break;
                    case 0x01:
                        dest.setAttribute("nxType", "signalmastlogic");
                        break;
                    case 0x02:
                        dest.setAttribute("nxType", "fullinterlocking");
                        break;
                    default:
                        dest.setAttribute("nxType", "turnoutsetting");
                        break;
                }
                if (p.getUniqueId(key, panel, keyDest) != null) {
                    dest.setAttribute("uniqueid", p.getUniqueId(key, panel, keyDest));
                }
                source.addContent(dest);
            }
            panelElem.addContent(source);
        }
        element.addContent(panelElem);
    }
    return element;
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Element(org.jdom2.Element) SignalMast(jmri.SignalMast) SignalHead(jmri.SignalHead) EntryExitPairs(jmri.jmrit.signalling.EntryExitPairs) Sensor(jmri.Sensor)

Example 28 with SignalMast

use of jmri.SignalMast in project JMRI by JMRI.

the class DestinationPoints method setRoute.

//For a clear down we need to add a message, if it is a cancel, manual clear down or I didn't mean it.
void setRoute(boolean state) {
    if (log.isDebugEnabled()) {
        log.debug("Set route " + src.getPoint().getDisplayName());
    }
    if (disposed) {
        log.error("Set route called even though interlock has been disposed of");
        return;
    }
    if (routeDetails == null) {
        log.error("No route to set or clear down");
        setActiveEntryExit(false);
        setRouteTo(false);
        setRouteFrom(false);
        if ((getSignal() instanceof SignalMast) && (getEntryExitType() != EntryExitPairs.FULLINTERLOCK)) {
            SignalMast mast = (SignalMast) getSignal();
            mast.setHeld(false);
        }
        synchronized (this) {
            destination = null;
        }
        return;
    }
    if (!state) {
        switch(manager.getClearDownOption()) {
            case EntryExitPairs.PROMPTUSER:
                cancelClearOptionBox();
                break;
            case EntryExitPairs.AUTOCANCEL:
                cancelClearInterlock(EntryExitPairs.CANCELROUTE);
                break;
            case EntryExitPairs.AUTOCLEAR:
                cancelClearInterlock(EntryExitPairs.CLEARROUTE);
                break;
            default:
                cancelClearOptionBox();
                break;
        }
        if (log.isDebugEnabled()) {
            log.debug("Exit " + src.getPoint().getDisplayName());
        }
        return;
    }
    if (manager.isRouteStacked(this, false)) {
        manager.cancelStackedRoute(this, false);
    }
    /* We put the setting of the route into a seperate thread and put a glass pane in front of the layout editor.
         The swing thread for flashing the icons will carry on without interuption. */
    final ArrayList<Color> realColorStd = new ArrayList<Color>();
    final ArrayList<Color> realColorXtra = new ArrayList<Color>();
    final ArrayList<LayoutBlock> routeBlocks = new ArrayList<LayoutBlock>();
    if (manager.useDifferentColorWhenSetting()) {
        for (LayoutBlock lbk : routeDetails) {
            routeBlocks.add(lbk);
            realColorXtra.add(lbk.getBlockExtraColor());
            realColorStd.add(lbk.getBlockTrackColor());
            lbk.setBlockExtraColor(manager.getSettingRouteColor());
            lbk.setBlockTrackColor(manager.getSettingRouteColor());
        }
        //Force a redraw, to reflect color change
        src.getPoint().getPanel().redrawPanel();
    }
    ActiveTrain tmpat = null;
    if (manager.getDispatcherIntegration() && jmri.InstanceManager.getNullableDefault(jmri.jmrit.dispatcher.DispatcherFrame.class) != null) {
        jmri.jmrit.dispatcher.DispatcherFrame df = jmri.InstanceManager.getDefault(jmri.jmrit.dispatcher.DispatcherFrame.class);
        for (ActiveTrain atl : df.getActiveTrainsList()) {
            if (atl.getEndBlock() == src.getStart().getBlock()) {
                if (atl.getLastAllocatedSection() == atl.getEndBlockSection()) {
                    if (!atl.getReverseAtEnd() && !atl.getResetWhenDone()) {
                        tmpat = atl;
                        break;
                    }
                    log.warn("Interlock will not be added to existing Active Train as it is set for back and forth operation");
                }
            }
        }
    }
    final ActiveTrain at = tmpat;
    Runnable setRouteRun = new Runnable() {

        @Override
        public void run() {
            src.getPoint().getPanel().getGlassPane().setVisible(true);
            try {
                Hashtable<Turnout, Integer> turnoutSettings = new Hashtable<Turnout, Integer>();
                ConnectivityUtil connection = new ConnectivityUtil(point.getPanel());
                // Last block in the route is the one that we are protecting at the last sensor/signalmast
                for (int i = 0; i < routeDetails.size(); i++) {
                    //if we are not using the dispatcher and the signal logic is dynamic, then set the turnouts
                    if (at == null && isSignalLogicDynamic()) {
                        if (i > 0) {
                            ArrayList<LayoutTurnout> turnoutlist;
                            int nxtBlk = i + 1;
                            int preBlk = i - 1;
                            if (i < routeDetails.size() - 1) {
                                turnoutlist = connection.getTurnoutList(routeDetails.get(i).getBlock(), routeDetails.get(preBlk).getBlock(), routeDetails.get(nxtBlk).getBlock());
                                ArrayList<Integer> throwlist = connection.getTurnoutSettingList();
                                for (int x = 0; x < turnoutlist.size(); x++) {
                                    if (turnoutlist.get(x) instanceof LayoutSlip) {
                                        int slipState = throwlist.get(x);
                                        LayoutSlip ls = (LayoutSlip) turnoutlist.get(x);
                                        int taState = ls.getTurnoutState(slipState);
                                        turnoutSettings.put(ls.getTurnout(), taState);
                                        int tbState = ls.getTurnoutBState(slipState);
                                        ls.getTurnoutB().setCommandedState(tbState);
                                        turnoutSettings.put(ls.getTurnoutB(), tbState);
                                    } else {
                                        String t = turnoutlist.get(x).getTurnoutName();
                                        Turnout turnout = InstanceManager.turnoutManagerInstance().getTurnout(t);
                                        turnoutSettings.put(turnout, throwlist.get(x));
                                        if (turnoutlist.get(x).getSecondTurnout() != null) {
                                            turnoutSettings.put(turnoutlist.get(x).getSecondTurnout(), throwlist.get(x));
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if ((getEntryExitType() == EntryExitPairs.FULLINTERLOCK)) {
                        // was set against occupancy sensor
                        routeDetails.get(i).getBlock().addPropertyChangeListener(propertyBlockListener);
                        if (i > 0) {
                            routeDetails.get(i).setUseExtraColor(true);
                        }
                    } else {
                        // was set against occupancy sensor
                        routeDetails.get(i).getBlock().removePropertyChangeListener(propertyBlockListener);
                    }
                }
                if (at == null) {
                    if (!isSignalLogicDynamic()) {
                        jmri.SignalMastLogic tmSml = InstanceManager.getDefault(jmri.SignalMastLogicManager.class).getSignalMastLogic((SignalMast) src.sourceSignal);
                        for (Turnout t : tmSml.getAutoTurnouts((SignalMast) getSignal())) {
                            turnoutSettings.put(t, tmSml.getAutoTurnoutState(t, (SignalMast) getSignal()));
                        }
                    }
                    for (Map.Entry<Turnout, Integer> entry : turnoutSettings.entrySet()) {
                        entry.getKey().setCommandedState(entry.getValue());
                        Runnable r = new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    Thread.sleep(250 + manager.turnoutSetDelay);
                                } catch (InterruptedException ex) {
                                    Thread.currentThread().interrupt();
                                }
                            }
                        };
                        Thread thr = new Thread(r, "Entry Exit Route, turnout setting");
                        thr.start();
                        try {
                            thr.join();
                        } catch (InterruptedException ex) {
                        //            log.info("interrupted at join " + ex);
                        }
                    }
                }
                src.getPoint().getPanel().redrawPanel();
                if (getEntryExitType() != EntryExitPairs.SETUPTURNOUTSONLY) {
                    if (getEntryExitType() == EntryExitPairs.FULLINTERLOCK) {
                        //If our start block is already active we will set it as our lastSeenActiveBlock.
                        if (src.getStart().getState() == Block.OCCUPIED) {
                            src.getStart().removePropertyChangeListener(propertyBlockListener);
                            lastSeenActiveBlockObject = src.getStart().getBlock().getValue();
                            log.debug("Last seen value " + lastSeenActiveBlockObject);
                        }
                    }
                    if ((src.sourceSignal instanceof SignalMast) && (getSignal() instanceof SignalMast)) {
                        SignalMast smSource = (SignalMast) src.sourceSignal;
                        SignalMast smDest = (SignalMast) getSignal();
                        synchronized (this) {
                            sml = InstanceManager.getDefault(jmri.SignalMastLogicManager.class).newSignalMastLogic(smSource);
                            if (!sml.isDestinationValid(smDest)) {
                                //if no signalmastlogic existed then created it, but set it not to be stored.
                                sml.setDestinationMast(smDest);
                                sml.setStore(jmri.SignalMastLogic.STORENONE, smDest);
                            }
                        }
                        //Remove the first block as it is our start block
                        routeDetails.remove(0);
                        synchronized (this) {
                            smSource.setHeld(false);
                            //Only change the block and turnout details if this a temp signalmast logic
                            if (sml.getStoreState(smDest) == jmri.SignalMastLogic.STORENONE) {
                                LinkedHashMap<Block, Integer> blks = new LinkedHashMap<Block, Integer>();
                                for (int i = 0; i < routeDetails.size(); i++) {
                                    if (routeDetails.get(i).getBlock().getState() == Block.UNKNOWN) {
                                        routeDetails.get(i).getBlock().setState(Block.UNOCCUPIED);
                                    }
                                    blks.put(routeDetails.get(i).getBlock(), Block.UNOCCUPIED);
                                }
                                sml.setAutoBlocks(blks, smDest);
                                sml.setAutoTurnouts(turnoutSettings, smDest);
                                sml.initialise(smDest);
                            }
                        }
                        smSource.addPropertyChangeListener(new PropertyChangeListener() {

                            @Override
                            public void propertyChange(PropertyChangeEvent e) {
                                SignalMast source = (SignalMast) e.getSource();
                                source.removePropertyChangeListener(this);
                                setRouteFrom(true);
                                setRouteTo(true);
                            }
                        });
                        src.pd.extendedtime = true;
                        point.extendedtime = true;
                    } else {
                        if (src.sourceSignal instanceof SignalMast) {
                            SignalMast mast = (SignalMast) src.sourceSignal;
                            mast.setHeld(false);
                        } else if (src.sourceSignal instanceof SignalHead) {
                            SignalHead head = (SignalHead) src.sourceSignal;
                            head.setHeld(false);
                        }
                        setRouteFrom(true);
                        setRouteTo(true);
                    }
                }
                if (manager.useDifferentColorWhenSetting()) {
                    //final ArrayList<Color> realColorXtra = realColorXtra;
                    javax.swing.Timer resetColorBack = new javax.swing.Timer(manager.getSettingTimer(), new java.awt.event.ActionListener() {

                        @Override
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                            for (int i = 0; i < routeBlocks.size(); i++) {
                                LayoutBlock lbk = routeBlocks.get(i);
                                lbk.setBlockExtraColor(realColorXtra.get(i));
                                lbk.setBlockTrackColor(realColorStd.get(i));
                            }
                            src.getPoint().getPanel().redrawPanel();
                        }
                    });
                    resetColorBack.setRepeats(false);
                    resetColorBack.start();
                }
                if (at != null) {
                    jmri.Section sec = null;
                    if (sml != null && sml.getAssociatedSection((SignalMast) getSignal()) != null) {
                        sec = sml.getAssociatedSection((SignalMast) getSignal());
                    } else {
                        sec = InstanceManager.getDefault(jmri.SectionManager.class).createNewSection(src.getPoint().getDisplayName() + ":" + point.getDisplayName());
                        if (sec == null) {
                            //A Section already exists, lets grab it and check that it is one used with the Interlocking, if so carry on using that.
                            sec = InstanceManager.getDefault(jmri.SectionManager.class).getSection(src.getPoint().getDisplayName() + ":" + point.getDisplayName());
                        } else {
                            sec.setSectionType(jmri.Section.DYNAMICADHOC);
                        }
                        if (sec.getSectionType() == jmri.Section.DYNAMICADHOC) {
                            sec.removeAllBlocksFromSection();
                            for (LayoutBlock key : routeDetails) {
                                if (key != src.getStart()) {
                                    sec.addBlock(key.getBlock());
                                }
                            }
                            String dir = jmri.Path.decodeDirection(src.getStart().getNeighbourDirection(routeDetails.get(0).getBlock()));
                            jmri.EntryPoint ep = new jmri.EntryPoint(routeDetails.get(0).getBlock(), src.getStart().getBlock(), dir);
                            ep.setTypeForward();
                            sec.addToForwardList(ep);
                            LayoutBlock proDestLBlock = point.getProtecting().get(0);
                            if (proDestLBlock != null) {
                                dir = jmri.Path.decodeDirection(proDestLBlock.getNeighbourDirection(point.getFacing()));
                                ep = new jmri.EntryPoint(point.getFacing().getBlock(), proDestLBlock.getBlock(), dir);
                                ep.setTypeReverse();
                                sec.addToReverseList(ep);
                            }
                        }
                    }
                    jmri.InstanceManager.getDefault(jmri.jmrit.dispatcher.DispatcherFrame.class).extendActiveTrainsPath(sec, at, src.getPoint().getPanel());
                }
                src.pd.setNXButtonState(EntryExitPairs.NXBUTTONINACTIVE);
                point.setNXButtonState(EntryExitPairs.NXBUTTONINACTIVE);
            } catch (RuntimeException ex) {
                log.error("An error occured while setting the route");
                ex.printStackTrace();
                src.pd.setNXButtonState(EntryExitPairs.NXBUTTONINACTIVE);
                point.setNXButtonState(EntryExitPairs.NXBUTTONINACTIVE);
                if (manager.useDifferentColorWhenSetting()) {
                    for (int i = 0; i < routeBlocks.size(); i++) {
                        LayoutBlock lbk = routeBlocks.get(i);
                        lbk.setBlockExtraColor(realColorXtra.get(i));
                        lbk.setBlockTrackColor(realColorStd.get(i));
                    }
                }
                src.getPoint().getPanel().redrawPanel();
            }
            src.getPoint().getPanel().getGlassPane().setVisible(false);
        //src.setMenuEnabled(true);
        }
    };
    Thread thrMain = new Thread(setRouteRun, "Entry Exit Set Route");
    thrMain.start();
    try {
        thrMain.join();
    } catch (InterruptedException e) {
        log.error("Interuption exception " + e.toString());
    }
    if (log.isDebugEnabled()) {
        log.debug("finish route " + src.getPoint().getDisplayName());
    }
}
Also used : LayoutSlip(jmri.jmrit.display.layoutEditor.LayoutSlip) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ActiveTrain(jmri.jmrit.dispatcher.ActiveTrain) PropertyChangeEvent(java.beans.PropertyChangeEvent) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) Color(java.awt.Color) Block(jmri.Block) LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) Turnout(jmri.Turnout) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConnectivityUtil(jmri.jmrit.display.layoutEditor.ConnectivityUtil) ActionListener(java.awt.event.ActionListener) PropertyChangeListener(java.beans.PropertyChangeListener) SignalHead(jmri.SignalHead) LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) SignalMast(jmri.SignalMast) Hashtable(java.util.Hashtable) ActionEvent(java.awt.event.ActionEvent)

Example 29 with SignalMast

use of jmri.SignalMast in project JMRI by JMRI.

the class SignallingPanel method updatePressed.

/**
     * Update changes in SML when Update button is pressed in the Edit Logic - Add Logic pane.
     *
     * @param e the event heard
     */
void updatePressed(ActionEvent e) {
    sourceMast = (SignalMast) sourceMastBox.getSelectedBean();
    destMast = (SignalMast) destMastBox.getSelectedBean();
    boolean smlPairAdded = false;
    destOK = true;
    if (sourceMast == destMast || fixedSourceMastLabel.getText() == destMast.getDisplayName()) {
        JOptionPane.showMessageDialog(null, rb.getString("ErrorSignalMastIdentical"));
        destOK = false;
        log.debug("Destination Mast check failed, keep pane open");
        return;
    }
    if ((sml == null) && (useLayoutEditor.isSelected())) {
        boolean valid = false;
        try {
            valid = InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlockConnectivityTools().checkValidDest(sourceMast, destMast, LayoutBlockConnectivityTools.MASTTOMAST);
            if (!valid) {
                JOptionPane.showMessageDialog(null, rb.getString("ErrorUnReachableDestination"));
                return;
            }
        } catch (jmri.JmriException je) {
            JOptionPane.showMessageDialog(null, rb.getString("WarningUnabletoValidate"));
        }
    }
    if (sml == null) {
        // a new SML directly from the SML Table
        sml = InstanceManager.getDefault(jmri.SignalMastLogicManager.class).newSignalMastLogic(sourceMast);
        // check if a similar SML pair already exists when in Add New session
        if (!sml.getDestinationList().contains(destMast)) {
            // not yet defined as a pair
            smlPairAdded = true;
            sml.setDestinationMast(destMast);
        } else {
            // show replace/update dialog
            int mes = JOptionPane.showConfirmDialog(null, rb.getString("WarningExistingPair"), Bundle.getMessage("WarningTitle"), JOptionPane.YES_NO_OPTION);
            if (mes == JOptionPane.NO_OPTION) {
                return;
            }
        }
        fixedSourceMastLabel.setText(sourceMast.getDisplayName());
        fixedDestMastLabel.setText(destMast.getDisplayName());
        sourceMastBox.setVisible(false);
        destMastBox.setVisible(false);
        fixedSourceMastLabel.setVisible(true);
        fixedDestMastLabel.setVisible(true);
        _autoTurnoutModel.smlValid();
        _autoBlockModel.smlValid();
        _autoSignalMastModel.smlValid();
    }
    initializeIncludedList();
    sml.allowAutoMaticSignalMastGeneration(allowAutoMastGeneration.isSelected(), destMast);
    boolean layouteditorgen = true;
    try {
        sml.useLayoutEditor(useLayoutEditor.isSelected(), destMast);
    } catch (jmri.JmriException je) {
        JOptionPane.showMessageDialog(null, je.toString());
        layouteditorgen = false;
    }
    try {
        if (useLayoutEditor.isSelected()) {
            sml.useLayoutEditorDetails(useLayoutEditorTurnout.isSelected(), useLayoutEditorBlock.isSelected(), destMast);
        }
    } catch (jmri.JmriException ji) {
        if (layouteditorgen) {
            JOptionPane.showMessageDialog(null, ji.toString());
        }
    }
    Hashtable<Block, Integer> hashBlocks = new Hashtable<Block, Integer>();
    for (int i = 0; i < _includedManualBlockList.size(); i++) {
        Block blk = jmri.InstanceManager.getDefault(jmri.BlockManager.class).getBlock(_includedManualBlockList.get(i).getSysName());
        hashBlocks.put(blk, _includedManualBlockList.get(i).getState());
    }
    sml.setBlocks(hashBlocks, destMast);
    Hashtable<NamedBeanHandle<Turnout>, Integer> hashTurnouts = new Hashtable<NamedBeanHandle<Turnout>, Integer>();
    for (int i = 0; i < _includedManualTurnoutList.size(); i++) {
        String turnoutName = _includedManualTurnoutList.get(i).getDisplayName();
        Turnout turnout = jmri.InstanceManager.turnoutManagerInstance().getTurnout(_includedManualTurnoutList.get(i).getDisplayName());
        NamedBeanHandle<Turnout> namedTurnout = nbhm.getNamedBeanHandle(turnoutName, turnout);
        hashTurnouts.put(namedTurnout, _includedManualTurnoutList.get(i).getState());
    // no specific value, just show the current turnout state as selection in comboBox.
    // for existing SML pair, will be updated to show present setting by editDetails()
    }
    sml.setTurnouts(hashTurnouts, destMast);
    Hashtable<NamedBeanHandle<Sensor>, Integer> hashSensors = new Hashtable<NamedBeanHandle<Sensor>, Integer>();
    for (int i = 0; i < _includedManualSensorList.size(); i++) {
        String sensorName = _includedManualSensorList.get(i).getDisplayName();
        Sensor sensor = jmri.InstanceManager.sensorManagerInstance().getSensor(_includedManualSensorList.get(i).getDisplayName());
        NamedBeanHandle<Sensor> namedSensor = nbhm.getNamedBeanHandle(sensorName, sensor);
        hashSensors.put(namedSensor, _includedManualSensorList.get(i).getState());
    // no specific value, just show the current sensor state as selection in comboBox.
    // for existing SML pair, will be updated to show present setting by editDetails()
    }
    sml.setSensors(hashSensors, destMast);
    Hashtable<SignalMast, String> hashSignalMasts = new Hashtable<SignalMast, String>();
    for (int i = 0; i < _includedManualSignalMastList.size(); i++) {
        if (_includedManualSignalMastList.get(i).getMast() == sourceMast || _includedManualSignalMastList.get(i).getMast() == destMast) {
            // warn user that control mast is either source or destination mast of this pair, but allow as a valid choice
            int mes = JOptionPane.showConfirmDialog(null, java.text.MessageFormat.format(rb.getString("SignalMastCriteriaOwn"), new Object[] { _includedManualSignalMastList.get(i).getMast().getDisplayName() }), rb.getString("SignalMastCriteriaOwnTitle"), JOptionPane.YES_NO_OPTION);
            if (mes == 0) {
                // Yes
                hashSignalMasts.put(_includedManualSignalMastList.get(i).getMast(), _includedManualSignalMastList.get(i).getSetToState());
            } else {
                // No
                // deselect "Included" checkBox for signal mast in manualSignalList
                _includedManualSignalMastList.get(i).setIncluded(false);
                initializeIncludedList();
                _signalMastModel.fireTableDataChanged();
            }
        } else {
            hashSignalMasts.put(_includedManualSignalMastList.get(i).getMast(), _includedManualSignalMastList.get(i).getSetToState());
        }
    }
    sml.setMasts(hashSignalMasts, destMast);
    sml.allowTurnoutLock(lockTurnouts.isSelected(), destMast);
    sml.initialise(destMast);
    if (smlPairAdded) {
        log.debug("New SML");
        // to show new SML in underlying table
        firePropertyChange("newDestination", null, destMastBox.getSelectedBean());
    }
}
Also used : Hashtable(java.util.Hashtable) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) Block(jmri.Block) SignalMast(jmri.SignalMast) Turnout(jmri.Turnout) NamedBeanHandle(jmri.NamedBeanHandle) Sensor(jmri.Sensor)

Example 30 with SignalMast

use of jmri.SignalMast in project JMRI by JMRI.

the class SignallingPanel method initializeIncludedList.

/**
     * Create new lists of control items configured as part of an SML.
     */
void initializeIncludedList() {
    _includedManualBlockList = new ArrayList<ManualBlockList>();
    for (int i = 0; i < _manualBlockList.size(); i++) {
        if (_manualBlockList.get(i).isIncluded()) {
            _includedManualBlockList.add(_manualBlockList.get(i));
        }
    }
    if ((sml != null) && (destMast != null)) {
        ArrayList<Block> blkList = sml.getAutoBlocks(destMast);
        _automaticBlockList = new ArrayList<AutoBlockList>(blkList.size());
        Iterator<Block> iter = blkList.iterator();
        while (iter.hasNext()) {
            Block blk = iter.next();
            AutoBlockList newABlk = new AutoBlockList(blk);
            _automaticBlockList.add(newABlk);
            newABlk.setState(sml.getAutoBlockState(blk, destMast));
        }
    }
    _includedManualTurnoutList = new ArrayList<ManualTurnoutList>();
    for (int i = 0; i < _manualTurnoutList.size(); i++) {
        if (_manualTurnoutList.get(i).isIncluded()) {
            _includedManualTurnoutList.add(_manualTurnoutList.get(i));
        }
    }
    if ((sml != null) && (destMast != null)) {
        ArrayList<Turnout> turnList = sml.getAutoTurnouts(destMast);
        _automaticTurnoutList = new ArrayList<AutoTurnoutList>(turnList.size());
        Iterator<Turnout> iter = turnList.iterator();
        while (iter.hasNext()) {
            Turnout turn = iter.next();
            String systemName = turn.getSystemName();
            String userName = turn.getUserName();
            AutoTurnoutList newAturn = new AutoTurnoutList(systemName, userName);
            _automaticTurnoutList.add(newAturn);
            newAturn.setState(sml.getAutoTurnoutState(turn, destMast));
        }
    }
    _includedManualSensorList = new ArrayList<ManualSensorList>();
    for (int i = 0; i < _manualSensorList.size(); i++) {
        if (_manualSensorList.get(i).isIncluded()) {
            _includedManualSensorList.add(_manualSensorList.get(i));
        }
    }
    _includedManualSignalMastList = new ArrayList<ManualSignalMastList>();
    for (int i = 0; i < _manualSignalMastList.size(); i++) {
        if (_manualSignalMastList.get(i).isIncluded()) {
            _includedManualSignalMastList.add(_manualSignalMastList.get(i));
        }
    }
    if ((sml != null) && (destMast != null)) {
        ArrayList<SignalMast> mastList = sml.getAutoMasts(destMast);
        _automaticSignalMastList = new ArrayList<AutoSignalMastList>(mastList.size());
        Iterator<SignalMast> iter = mastList.iterator();
        while (iter.hasNext()) {
            SignalMast mast = iter.next();
            AutoSignalMastList newAmast = new AutoSignalMastList(mast);
            _automaticSignalMastList.add(newAmast);
            newAmast.setState(sml.getAutoSignalMastState(mast, destMast));
        }
    }
}
Also used : SignalMast(jmri.SignalMast) Block(jmri.Block) Turnout(jmri.Turnout)

Aggregations

SignalMast (jmri.SignalMast)80 Test (org.junit.Test)19 NamedBean (jmri.NamedBean)11 Sensor (jmri.Sensor)11 SignalHead (jmri.SignalHead)11 Turnout (jmri.Turnout)10 SignalMastManager (jmri.SignalMastManager)9 JsonException (jmri.server.json.JsonException)9 ArrayList (java.util.ArrayList)8 JmriException (jmri.JmriException)8 Block (jmri.Block)7 SignalMastLogic (jmri.SignalMastLogic)7 Hashtable (java.util.Hashtable)6 Element (org.jdom2.Element)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 IOException (java.io.IOException)4 NamedBeanHandle (jmri.NamedBeanHandle)4 Section (jmri.Section)4 LayoutTurnout (jmri.jmrit.display.layoutEditor.LayoutTurnout)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3