Search in sources :

Example 1 with LayoutSlip

use of jmri.jmrit.display.layoutEditor.LayoutSlip in project JMRI by JMRI.

the class AutoTurnouts method turnoutUtil.

/**
     * Internal method implementing the above two methods Returns 'true' if
     * turnouts are set correctly, 'false' otherwise If 'set' is 'true' this
     * routine will attempt to set the turnouts, if 'false' it reports what it
     * finds.
     */
private boolean turnoutUtil(Section s, int seqNum, Section nextSection, ActiveTrain at, LayoutEditor le, boolean trustKnownTurnouts, boolean set, Section prevSection) {
    // validate input and initialize
    Transit tran = at.getTransit();
    if ((s == null) || (seqNum > tran.getMaxSequence()) || (!tran.containsSection(s)) || (le == null)) {
        log.error("Invalid argument when checking or setting turnouts in Section.");
        return false;
    }
    int direction = at.getAllocationDirectionFromSectionAndSeq(s, seqNum);
    if (direction == 0) {
        log.error("Invalid Section/sequence arguments when checking or setting turnouts");
        return false;
    }
    // check for no turnouts in this section
    if (_dispatcher.getSignalType() == DispatcherFrame.SIGNALHEAD && (s.getForwardEntryPointList().size() <= 1) && (s.getReverseEntryPointList().size() <= 1)) {
        log.debug("No entry points lists");
        // no possibility of turnouts
        return true;
    }
    // initialize connectivity utilities and beginning block pointers
    ConnectivityUtil ct = le.getConnectivityUtil();
    EntryPoint entryPt = null;
    if (prevSection != null) {
        entryPt = s.getEntryPointFromSection(prevSection, direction);
    } else if (!s.containsBlock(at.getStartBlock())) {
        entryPt = s.getEntryPointFromBlock(at.getStartBlock(), direction);
    }
    EntryPoint exitPt = null;
    if (nextSection != null) {
        exitPt = s.getExitPointToSection(nextSection, direction);
    }
    // must be in the section
    Block curBlock = null;
    // must start outside the section or be null
    Block prevBlock = null;
    // sequence number of curBlock in Section
    int curBlockSeqNum = -1;
    if (entryPt != null) {
        curBlock = entryPt.getBlock();
        prevBlock = entryPt.getFromBlock();
        curBlockSeqNum = s.getBlockSequenceNumber(curBlock);
    } else if (!at.isAllocationReversed() && s.containsBlock(at.getStartBlock())) {
        curBlock = at.getStartBlock();
        curBlockSeqNum = s.getBlockSequenceNumber(curBlock);
        //Get the previous block so that we can set the turnouts in the current block correctly.
        if (direction == Section.FORWARD) {
            prevBlock = s.getBlockBySequenceNumber(curBlockSeqNum - 1);
        } else if (direction == Section.REVERSE) {
            prevBlock = s.getBlockBySequenceNumber(curBlockSeqNum + 1);
        }
    } else if (at.isAllocationReversed() && s.containsBlock(at.getEndBlock())) {
        curBlock = at.getEndBlock();
        curBlockSeqNum = s.getBlockSequenceNumber(curBlock);
        //Get the previous block so that we can set the turnouts in the current block correctly.
        if (direction == Section.REVERSE) {
            prevBlock = s.getBlockBySequenceNumber(curBlockSeqNum + 1);
        } else if (direction == Section.FORWARD) {
            prevBlock = s.getBlockBySequenceNumber(curBlockSeqNum - 1);
        }
    } else {
        if (_dispatcher.getSignalType() == DispatcherFrame.SIGNALMAST) {
            //This can be considered normal where SignalMast Logic is used.
            return true;
        }
        log.error("Error in turnout check/set request - initial Block and Section mismatch");
        return false;
    }
    Block nextBlock = null;
    // may be either in the section or the first block in the next section
    // sequence number of nextBlock in Section (-1 indicates outside Section)
    int nextBlockSeqNum = -1;
    if (exitPt != null && curBlock == exitPt.getBlock()) {
        // next Block is outside of the Section
        nextBlock = exitPt.getFromBlock();
    } else {
        // next Block is inside the Section
        if (direction == Section.FORWARD) {
            nextBlock = s.getBlockBySequenceNumber(curBlockSeqNum + 1);
            nextBlockSeqNum = curBlockSeqNum + 1;
        } else if (direction == Section.REVERSE) {
            nextBlock = s.getBlockBySequenceNumber(curBlockSeqNum - 1);
            nextBlockSeqNum = curBlockSeqNum - 1;
        }
        if ((nextBlock == null) && (curBlock != at.getEndBlock())) {
            log.error("Error in block sequence numbers when setting/checking turnouts");
            return false;
        }
    }
    ArrayList<LayoutTurnout> turnoutList = new ArrayList<LayoutTurnout>();
    ArrayList<Integer> settingsList = new ArrayList<Integer>();
    // get turnouts by Block
    boolean turnoutsOK = true;
    while (curBlock != null) {
        /*No point in getting the list if the previous block is null as it will return empty and generate an error, 
             this will only happen on the first run.  Plus working on the basis that the turnouts in the current block would have already of 
             been set correctly for the train to have arrived in the first place.
             */
        if (prevBlock != null) {
            turnoutList = ct.getTurnoutList(curBlock, prevBlock, nextBlock);
            settingsList = ct.getTurnoutSettingList();
        }
        // loop over turnouts checking and optionally setting turnouts
        for (int i = 0; i < turnoutList.size(); i++) {
            Turnout to = turnoutList.get(i).getTurnout();
            int setting = settingsList.get(i).intValue();
            if (turnoutList.get(i) instanceof LayoutSlip) {
                setting = ((LayoutSlip) turnoutList.get(i)).getTurnoutState(settingsList.get(i));
            }
            // check or ignore current setting based on flag, set in Options
            if (!trustKnownTurnouts) {
                log.debug("{}: setting turnout {} to {}", at.getTrainName(), to.getFullyFormattedDisplayName(), (setting == Turnout.CLOSED ? closedText : thrownText));
                to.setCommandedState(setting);
                try {
                    Thread.sleep(100);
                } catch (Exception ex) {
                }
            //TODO: move this to separate thread
            } else {
                if (to.getKnownState() != setting) {
                    // turnout is not set correctly
                    if (set) {
                        // setting has been requested, is Section free and Block unoccupied
                        if ((s.getState() == Section.FREE) && (curBlock.getState() != Block.OCCUPIED)) {
                            // send setting command
                            log.debug("{}: turnout {} commanded to {}", at.getTrainName(), to.getFullyFormattedDisplayName(), (setting == Turnout.CLOSED ? closedText : thrownText));
                            to.setCommandedState(setting);
                            try {
                                Thread.sleep(100);
                            } catch (Exception ex) {
                            }
                        //TODO: move this to separate thread
                        } else {
                            turnoutsOK = false;
                        }
                    } else {
                        turnoutsOK = false;
                    }
                } else {
                    log.debug("{}: turnout {} already {}, skipping", at.getTrainName(), to.getFullyFormattedDisplayName(), (setting == Turnout.CLOSED ? closedText : thrownText));
                }
            }
            if (turnoutList.get(i) instanceof LayoutSlip) {
                //Look at the state of the second turnout in the slip
                setting = ((LayoutSlip) turnoutList.get(i)).getTurnoutBState(settingsList.get(i));
                to = ((LayoutSlip) turnoutList.get(i)).getTurnoutB();
                if (!trustKnownTurnouts) {
                    to.setCommandedState(setting);
                } else if (to.getKnownState() != setting) {
                    // turnout is not set correctly
                    if (set) {
                        // setting has been requested, is Section free and Block unoccupied
                        if ((s.getState() == Section.FREE) && (curBlock.getState() != Block.OCCUPIED)) {
                            // send setting command
                            to.setCommandedState(setting);
                        } else {
                            turnoutsOK = false;
                        }
                    } else {
                        turnoutsOK = false;
                    }
                }
            }
        }
        if (turnoutsOK) {
            // move to next Block if any
            if (nextBlockSeqNum >= 0) {
                prevBlock = curBlock;
                curBlock = nextBlock;
                curBlockSeqNum = nextBlockSeqNum;
                if ((exitPt != null) && (curBlock == exitPt.getBlock())) {
                    // next block is outside of the Section
                    nextBlock = exitPt.getFromBlock();
                    nextBlockSeqNum = -1;
                } else {
                    if (direction == Section.FORWARD) {
                        nextBlockSeqNum++;
                    } else {
                        nextBlockSeqNum--;
                    }
                    nextBlock = s.getBlockBySequenceNumber(nextBlockSeqNum);
                    if (nextBlock == null) {
                        // there is no next Block
                        nextBlockSeqNum = -1;
                    }
                }
            } else {
                curBlock = null;
            }
        } else {
            curBlock = null;
        }
    }
    return turnoutsOK;
}
Also used : LayoutSlip(jmri.jmrit.display.layoutEditor.LayoutSlip) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) ArrayList(java.util.ArrayList) EntryPoint(jmri.EntryPoint) Transit(jmri.Transit) EntryPoint(jmri.EntryPoint) Block(jmri.Block) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) Turnout(jmri.Turnout) ConnectivityUtil(jmri.jmrit.display.layoutEditor.ConnectivityUtil)

Example 2 with LayoutSlip

use of jmri.jmrit.display.layoutEditor.LayoutSlip in project JMRI by JMRI.

the class LayoutSlipXml method store.

/**
     * Default implementation for storing the contents of a LayoutSlip
     *
     * @param o Object to store, of type LayoutSlip
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    LayoutSlip p = (LayoutSlip) o;
    Element element = new Element("layoutSlip");
    // include attributes
    element.setAttribute("ident", p.getName());
    element.setAttribute("slipType", "" + p.getSlipType());
    if (p.getBlockName().length() > 0) {
        element.setAttribute("blockname", p.getBlockName());
    }
    if (p.getConnectA() != null) {
        element.setAttribute("connectaname", ((TrackSegment) p.getConnectA()).getID());
    }
    if (p.getConnectB() != null) {
        element.setAttribute("connectbname", ((TrackSegment) p.getConnectB()).getID());
    }
    if (p.getConnectC() != null) {
        element.setAttribute("connectcname", ((TrackSegment) p.getConnectC()).getID());
    }
    if (p.getConnectD() != null) {
        element.setAttribute("connectdname", ((TrackSegment) p.getConnectD()).getID());
    }
    if (p.getSignalA1Name().length() > 0) {
        element.addContent(new Element("signala1name").addContent(p.getSignalA1Name()));
    }
    if (p.getSignalB1Name().length() > 0) {
        element.addContent(new Element("signalb1name").addContent(p.getSignalB1Name()));
    }
    if (p.getSignalC1Name().length() > 0) {
        element.addContent(new Element("signalc1name").addContent(p.getSignalC1Name()));
    }
    if (p.getSignalD1Name().length() > 0) {
        element.addContent(new Element("signald1name").addContent(p.getSignalD1Name()));
    }
    if (p.getSignalA2Name().length() > 0) {
        element.addContent(new Element("signala2name").addContent(p.getSignalA2Name()));
    }
    if (p.getSignalB2Name().length() > 0) {
        element.addContent(new Element("signalb2name").addContent(p.getSignalB2Name()));
    }
    if (p.getSignalC2Name().length() > 0) {
        element.addContent(new Element("signalc2name").addContent(p.getSignalC2Name()));
    }
    if (p.getSignalD2Name().length() > 0) {
        element.addContent(new Element("signald2name").addContent(p.getSignalD2Name()));
    }
    Point2D coords = p.getCoordsCenter();
    element.setAttribute("xcen", "" + coords.getX());
    element.setAttribute("ycen", "" + coords.getY());
    coords = p.getCoordsA();
    element.setAttribute("xa", "" + coords.getX());
    element.setAttribute("ya", "" + coords.getY());
    coords = p.getCoordsB();
    element.setAttribute("xb", "" + coords.getX());
    element.setAttribute("yb", "" + coords.getY());
    if (p.getSignalAMastName().length() > 0) {
        element.addContent(new Element("signalAMast").addContent(p.getSignalAMastName()));
    }
    if (p.getSignalBMastName().length() > 0) {
        element.addContent(new Element("signalBMast").addContent(p.getSignalBMastName()));
    }
    if (p.getSignalCMastName().length() > 0) {
        element.addContent(new Element("signalCMast").addContent(p.getSignalCMastName()));
    }
    if (p.getSignalDMastName().length() > 0) {
        element.addContent(new Element("signalDMast").addContent(p.getSignalDMastName()));
    }
    if (p.getSensorAName().length() > 0) {
        element.addContent(new Element("sensorA").addContent(p.getSensorAName()));
    }
    if (p.getSensorBName().length() > 0) {
        element.addContent(new Element("sensorB").addContent(p.getSensorBName()));
    }
    if (p.getSensorCName().length() > 0) {
        element.addContent(new Element("sensorC").addContent(p.getSensorCName()));
    }
    if (p.getSensorDName().length() > 0) {
        element.addContent(new Element("sensorD").addContent(p.getSensorDName()));
    }
    if (p.getTurnoutName().length() > 0) {
        element.addContent(new Element("turnout").addContent(p.getTurnoutName()));
    }
    if (p.getTurnoutBName().length() > 0) {
        element.addContent(new Element("turnoutB").addContent(p.getTurnoutBName()));
    }
    Element states = new Element("states");
    Element state = new Element("A-C");
    state.addContent(new Element("turnout").addContent("" + p.getTurnoutState(LayoutSlip.STATE_AC)));
    state.addContent(new Element("turnoutB").addContent("" + p.getTurnoutBState(LayoutSlip.STATE_AC)));
    states.addContent(state);
    state = new Element("A-D");
    state.addContent(new Element("turnout").addContent("" + p.getTurnoutState(LayoutSlip.STATE_AD)));
    state.addContent(new Element("turnoutB").addContent("" + p.getTurnoutBState(LayoutSlip.STATE_AD)));
    states.addContent(state);
    state = new Element("B-D");
    state.addContent(new Element("turnout").addContent("" + p.getTurnoutState(LayoutSlip.STATE_BD)));
    state.addContent(new Element("turnoutB").addContent("" + p.getTurnoutBState(LayoutSlip.STATE_BD)));
    states.addContent(state);
    if (p.getSlipType() == LayoutSlip.DOUBLE_SLIP) {
        state = new Element("B-C");
        state.addContent(new Element("turnout").addContent("" + p.getTurnoutState(LayoutSlip.STATE_BC)));
        state.addContent(new Element("turnoutB").addContent("" + p.getTurnoutBState(LayoutSlip.STATE_BC)));
        states.addContent(state);
    }
    element.addContent(states);
    element.setAttribute("class", getClass().getName());
    return element;
}
Also used : LayoutSlip(jmri.jmrit.display.layoutEditor.LayoutSlip) Point2D(java.awt.geom.Point2D) Element(org.jdom2.Element)

Example 3 with LayoutSlip

use of jmri.jmrit.display.layoutEditor.LayoutSlip 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 4 with LayoutSlip

use of jmri.jmrit.display.layoutEditor.LayoutSlip in project JMRI by JMRI.

the class PointDetails method getSignal.

NamedBean getSignal() {
    if ((getPanel() != null) && (!getPanel().isEditable()) && (getSignalMast() != null)) {
        return getSignalMast();
    }
    if ((getPanel() != null) && (!getPanel().isEditable()) && (getSignalHead() != null)) {
        return getSignalHead();
    }
    jmri.SignalHeadManager sh = InstanceManager.getDefault(jmri.SignalHeadManager.class);
    NamedBean signal = null;
    if (getRefObject() == null) {
        log.error("Signal not found at point");
        return null;
    } else if (getRefObject() instanceof SignalMast) {
        signal = getRefObject();
        setSignalMast(((SignalMast) getRefObject()));
        return signal;
    } else if (getRefObject() instanceof SignalHead) {
        signal = getRefObject();
        setSignalHead(((SignalHead) getRefObject()));
        return signal;
    }
    Sensor sen = (Sensor) getRefObject();
    log.debug("looking at Sensor " + sen.getDisplayName());
    if (getRefLocation() instanceof PositionablePoint) {
        PositionablePoint p = (PositionablePoint) getRefLocation();
        if (p.getEastBoundSensor() == sen) {
            if (p.getEastBoundSignalMast() != null) {
                signal = p.getEastBoundSignalMast();
            } else if (!p.getEastBoundSignal().equals("")) {
                signal = sh.getSignalHead(p.getEastBoundSignal());
            }
        } else if (p.getWestBoundSensor() == sen) {
            if (p.getWestBoundSignalMast() != null) {
                signal = p.getWestBoundSignalMast();
            } else if (!p.getWestBoundSignal().equals("")) {
                signal = sh.getSignalHead(p.getWestBoundSignal());
            }
        }
    } else if (getRefLocation() instanceof LayoutTurnout) {
        LayoutTurnout t = (LayoutTurnout) getRefLocation();
        if (t.getSensorA() == sen) {
            if (t.getSignalAMast() != null) {
                signal = t.getSignalAMast();
            } else if (!t.getSignalA1Name().equals("")) {
                signal = sh.getSignalHead(t.getSignalA1Name());
            }
        } else if (t.getSensorB() == sen) {
            if (t.getSignalBMast() != null) {
                signal = t.getSignalBMast();
            } else if (!t.getSignalB1Name().equals("")) {
                signal = sh.getSignalHead(t.getSignalB1Name());
            }
        } else if (t.getSensorC() == sen) {
            if (t.getSignalCMast() != null) {
                signal = t.getSignalCMast();
            } else if (!t.getSignalC1Name().equals("")) {
                signal = sh.getSignalHead(t.getSignalC1Name());
            }
        } else if (t.getSensorD() == sen) {
            if (t.getSignalDMast() != null) {
                signal = t.getSignalDMast();
            } else if (!t.getSignalD1Name().equals("")) {
                signal = sh.getSignalHead(t.getSignalD1Name());
            }
        }
    } else if (getRefLocation() instanceof LevelXing) {
        LevelXing x = (LevelXing) getRefLocation();
        if (x.getSensorA() == sen) {
            if (x.getSignalAMast() != null) {
                signal = x.getSignalAMast();
            } else if (!x.getSignalAName().equals("")) {
                signal = sh.getSignalHead(x.getSignalAName());
            }
        } else if (x.getSensorB() == sen) {
            if (x.getSignalBMast() != null) {
                signal = x.getSignalBMast();
            } else if (!x.getSignalBName().equals("")) {
                signal = sh.getSignalHead(x.getSignalBName());
            }
        } else if (x.getSensorC() == sen) {
            if (x.getSignalCMast() != null) {
                signal = x.getSignalCMast();
            } else if (!x.getSignalCName().equals("")) {
                signal = sh.getSignalHead(x.getSignalCName());
            }
        } else if (x.getSensorD() == sen) {
            if (x.getSignalDMast() != null) {
                signal = x.getSignalDMast();
            } else if (!x.getSignalDName().equals("")) {
                signal = sh.getSignalHead(x.getSignalDName());
            }
        }
    } else if (getRefLocation() instanceof LayoutSlip) {
        LayoutSlip t = (LayoutSlip) getRefLocation();
        if (t.getSensorA() == sen) {
            if (t.getSignalAMast() != null) {
                signal = t.getSignalAMast();
            } else if (!t.getSignalA1Name().equals("")) {
                signal = sh.getSignalHead(t.getSignalA1Name());
            }
        } else if (t.getSensorB() == sen) {
            if (t.getSignalBMast() != null) {
                signal = t.getSignalBMast();
            } else if (!t.getSignalB1Name().equals("")) {
                signal = sh.getSignalHead(t.getSignalB1Name());
            }
        } else if (t.getSensorC() == sen) {
            if (t.getSignalCMast() != null) {
                signal = t.getSignalCMast();
            } else if (!t.getSignalC1Name().equals("")) {
                signal = sh.getSignalHead(t.getSignalC1Name());
            }
        } else if (t.getSensorD() == sen) {
            if (t.getSignalDMast() != null) {
                signal = t.getSignalDMast();
            } else if (!t.getSignalD1Name().equals("")) {
                signal = sh.getSignalHead(t.getSignalD1Name());
            }
        }
    }
    if (signal instanceof SignalMast) {
        setSignalMast(((SignalMast) signal));
    } else if (signal instanceof SignalHead) {
        setSignalHead(((SignalHead) signal));
    }
    return signal;
}
Also used : NamedBean(jmri.NamedBean) LayoutSlip(jmri.jmrit.display.layoutEditor.LayoutSlip) LevelXing(jmri.jmrit.display.layoutEditor.LevelXing) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) SignalMast(jmri.SignalMast) SignalHead(jmri.SignalHead) PositionablePoint(jmri.jmrit.display.layoutEditor.PositionablePoint) Sensor(jmri.Sensor)

Example 5 with LayoutSlip

use of jmri.jmrit.display.layoutEditor.LayoutSlip in project JMRI by JMRI.

the class Section method placeDirectionSensors.

/**
     * Places direction sensors in SSL for all Signal Heads in this Section if
     * the Sensors are not already present in the SSL. Only anchor point block
     * boundaries that have assigned signals are considered. Only turnouts that
     * have assigned signals are considered. Only level crossings that have
     * assigned signals are considered. Turnouts and anchor points without
     * signals are counted, and reported in warning messages during this
     * procedure, if there are any missing signals. If this method has trouble,
     * an error message is placed in the log describing the trouble.
     *
     * @param panel the panel to place direction sensors on
     * @return the number or errors placing sensors; 1 is returned if no
     *         direction sensor is defined for this section
     */
public int placeDirectionSensors(LayoutEditor panel) {
    int missingSignalsBB = 0;
    int missingSignalsTurnouts = 0;
    int missingSignalsLevelXings = 0;
    int errorCount = 0;
    if (panel == null) {
        log.error("Null Layout Editor panel on call to 'placeDirectionSensors'");
        return 1;
    }
    if (initializationNeeded) {
        initializeBlocks();
    }
    if ((mForwardBlockingSensorName == null) || (mForwardBlockingSensorName.equals("")) || (mReverseBlockingSensorName == null) || (mReverseBlockingSensorName.equals(""))) {
        log.error("Missing direction sensor in Section " + getSystemName());
        return 1;
    }
    LayoutBlockManager layoutBlockManager = InstanceManager.getDefault(LayoutBlockManager.class);
    ConnectivityUtil cUtil = panel.getConnectivityUtil();
    for (int i = 0; i < mBlockEntries.size(); i++) {
        Block cBlock = mBlockEntries.get(i);
        LayoutBlock lBlock = layoutBlockManager.getByUserName(cBlock.getUserName());
        ArrayList<PositionablePoint> anchorList = cUtil.getAnchorBoundariesThisBlock(cBlock);
        for (int j = 0; j < anchorList.size(); j++) {
            PositionablePoint p = anchorList.get(j);
            if ((!p.getEastBoundSignal().equals("")) && (!p.getWestBoundSignal().equals(""))) {
                // have a signalled block boundary
                SignalHead sh = cUtil.getSignalHeadAtAnchor(p, cBlock, false);
                if (sh == null) {
                    log.warn("Unexpected missing signal head at boundary of Block " + cBlock.getUserName());
                    errorCount++;
                } else {
                    int direction = cUtil.getDirectionFromAnchor(mForwardEntryPoints, mReverseEntryPoints, p);
                    if (direction == EntryPoint.UNKNOWN) {
                        // anchor is at a Block boundary within the Section
                        sh = cUtil.getSignalHeadAtAnchor(p, cBlock, true);
                        Block otherBlock = ((p.getConnect1()).getLayoutBlock()).getBlock();
                        if (otherBlock == cBlock) {
                            otherBlock = ((p.getConnect2()).getLayoutBlock()).getBlock();
                        }
                        if (getBlockSequenceNumber(cBlock) < getBlockSequenceNumber(otherBlock)) {
                            direction = EntryPoint.FORWARD;
                        } else {
                            direction = EntryPoint.REVERSE;
                        }
                    }
                    if (!checkDirectionSensor(sh, direction, ConnectivityUtil.OVERALL, cUtil)) {
                        errorCount++;
                    }
                }
            } else {
                errorCount++;
                missingSignalsBB++;
            }
        }
        ArrayList<LevelXing> xingList = cUtil.getLevelCrossingsThisBlock(cBlock);
        for (int k = 0; k < xingList.size(); k++) {
            LevelXing x = xingList.get(k);
            LayoutBlock alBlock = ((TrackSegment) x.getConnectA()).getLayoutBlock();
            LayoutBlock blBlock = ((TrackSegment) x.getConnectB()).getLayoutBlock();
            LayoutBlock clBlock = ((TrackSegment) x.getConnectC()).getLayoutBlock();
            LayoutBlock dlBlock = ((TrackSegment) x.getConnectD()).getLayoutBlock();
            if (cUtil.isInternalLevelXingAC(x, cBlock)) {
                // have an internal AC level crossing - is it signaled?
                if (((x.getSignalAName() != null) && (!x.getSignalAName().equals(""))) || ((x.getSignalCName() != null) && (!x.getSignalCName().equals("")))) {
                    // have a signaled AC level crossing internal to this block
                    if ((x.getSignalAName() != null) && (!x.getSignalAName().equals(""))) {
                        // there is a signal at A in the level crossing
                        TrackNode tn = new TrackNode(x, LayoutTrack.LEVEL_XING_A, (TrackSegment) x.getConnectA(), false, 0);
                        TrackNode altNode = new TrackNode(x, LayoutTrack.LEVEL_XING_C, (TrackSegment) x.getConnectC(), false, 0);
                        SignalHead sh = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(x.getSignalAName());
                        if (!setDirectionSensorByConnectivity(tn, altNode, sh, cBlock, cUtil)) {
                            errorCount++;
                        }
                    }
                    if ((x.getSignalCName() != null) && (!x.getSignalCName().equals(""))) {
                        // there is a signal at C in the level crossing
                        TrackNode tn = new TrackNode(x, LayoutTrack.LEVEL_XING_C, (TrackSegment) x.getConnectC(), false, 0);
                        TrackNode altNode = new TrackNode(x, LayoutTrack.LEVEL_XING_A, (TrackSegment) x.getConnectA(), false, 0);
                        SignalHead sh = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(x.getSignalCName());
                        if (!setDirectionSensorByConnectivity(tn, altNode, sh, cBlock, cUtil)) {
                            errorCount++;
                        }
                    }
                }
            } else if (alBlock == lBlock) {
                // have a level crossing with AC spanning a block boundary, with A in this Block
                int direction = getDirectionForBlocks(alBlock, clBlock);
                if (direction != EntryPoint.UNKNOWN) {
                    if ((x.getSignalCName() != null) && (!x.getSignalCName().equals(""))) {
                        SignalHead sh = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(x.getSignalCName());
                        if (!checkDirectionSensor(sh, direction, ConnectivityUtil.OVERALL, cUtil)) {
                            errorCount++;
                        }
                    }
                } else {
                    errorCount++;
                }
            } else if (clBlock == lBlock) {
                // have a level crossing with AC spanning a block boundary, with C in this Block
                int direction = getDirectionForBlocks(clBlock, alBlock);
                if (direction != EntryPoint.UNKNOWN) {
                    if ((x.getSignalAName() != null) && (!x.getSignalAName().equals(""))) {
                        SignalHead sh = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(x.getSignalAName());
                        if (!checkDirectionSensor(sh, direction, ConnectivityUtil.OVERALL, cUtil)) {
                            errorCount++;
                        }
                    }
                } else {
                    errorCount++;
                }
            }
            if (cUtil.isInternalLevelXingBD(x, cBlock)) {
                // have an internal BD level crossing - is it signaled?
                if (((x.getSignalBName() != null) && (!x.getSignalBName().equals(""))) || ((x.getSignalDName() != null) && (!x.getSignalDName().equals("")))) {
                    // have a signaled BD level crossing internal to this block
                    if ((x.getSignalBName() != null) && (!x.getSignalBName().equals(""))) {
                        // there is a signal at B in the level crossing
                        TrackNode tn = new TrackNode(x, LayoutTrack.LEVEL_XING_B, (TrackSegment) x.getConnectB(), false, 0);
                        TrackNode altNode = new TrackNode(x, LayoutTrack.LEVEL_XING_D, (TrackSegment) x.getConnectD(), false, 0);
                        SignalHead sh = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(x.getSignalBName());
                        if (!setDirectionSensorByConnectivity(tn, altNode, sh, cBlock, cUtil)) {
                            errorCount++;
                        }
                    }
                    if ((x.getSignalDName() != null) && (!x.getSignalDName().equals(""))) {
                        // there is a signal at C in the level crossing
                        TrackNode tn = new TrackNode(x, LayoutTrack.LEVEL_XING_D, (TrackSegment) x.getConnectD(), false, 0);
                        TrackNode altNode = new TrackNode(x, LayoutTrack.LEVEL_XING_B, (TrackSegment) x.getConnectB(), false, 0);
                        SignalHead sh = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(x.getSignalDName());
                        if (!setDirectionSensorByConnectivity(tn, altNode, sh, cBlock, cUtil)) {
                            errorCount++;
                        }
                    }
                }
            } else if (blBlock == lBlock) {
                // have a level crossing with BD spanning a block boundary, with B in this Block
                int direction = getDirectionForBlocks(blBlock, dlBlock);
                if (direction != EntryPoint.UNKNOWN) {
                    if ((x.getSignalDName() != null) && (!x.getSignalDName().equals(""))) {
                        SignalHead sh = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(x.getSignalDName());
                        if (!checkDirectionSensor(sh, direction, ConnectivityUtil.OVERALL, cUtil)) {
                            errorCount++;
                        }
                    }
                } else {
                    errorCount++;
                }
            } else if (dlBlock == lBlock) {
                // have a level crossing with BD spanning a block boundary, with D in this Block
                int direction = getDirectionForBlocks(dlBlock, blBlock);
                if (direction != EntryPoint.UNKNOWN) {
                    if ((x.getSignalBName() != null) && (!x.getSignalBName().equals(""))) {
                        SignalHead sh = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(x.getSignalBName());
                        if (!checkDirectionSensor(sh, direction, ConnectivityUtil.OVERALL, cUtil)) {
                            errorCount++;
                        }
                    }
                } else {
                    errorCount++;
                }
            }
        }
        ArrayList<LayoutTurnout> turnoutList = cUtil.getLayoutTurnoutsThisBlock(cBlock);
        for (int m = 0; m < turnoutList.size(); m++) {
            LayoutTurnout t = turnoutList.get(m);
            if (cUtil.layoutTurnoutHasRequiredSignals(t)) {
                // have a signalled turnout
                if ((t.getLinkType() == LayoutTurnout.NO_LINK) && ((t.getTurnoutType() == LayoutTurnout.RH_TURNOUT) || (t.getTurnoutType() == LayoutTurnout.LH_TURNOUT) || (t.getTurnoutType() == LayoutTurnout.WYE_TURNOUT))) {
                    // standard turnout - nothing special
                    // Note: direction is for proceeding from the throat to either other track
                    int direction = getDirectionStandardTurnout(t, cUtil);
                    int altDirection = EntryPoint.FORWARD;
                    if (direction == EntryPoint.FORWARD) {
                        altDirection = EntryPoint.REVERSE;
                    }
                    if (direction == EntryPoint.UNKNOWN) {
                        errorCount++;
                    } else {
                        SignalHead aHead = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalA1Name());
                        SignalHead a2Head = null;
                        String a2Name = t.getSignalA2Name();
                        if ((a2Name != null) && (!a2Name.equals(""))) {
                            a2Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(a2Name);
                        }
                        SignalHead bHead = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalB1Name());
                        SignalHead cHead = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalC1Name());
                        if (t.getLayoutBlock().getBlock() == cBlock) {
                            // Note: need allocation to traverse this turnout
                            if (!checkDirectionSensor(aHead, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                errorCount++;
                            }
                            if (a2Head != null) {
                                if (!checkDirectionSensor(a2Head, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                    errorCount++;
                                }
                            }
                            if (!checkDirectionSensor(bHead, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                errorCount++;
                            }
                            if (!checkDirectionSensor(cHead, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                errorCount++;
                            }
                        } else {
                            if (((TrackSegment) t.getConnectA()).getLayoutBlock().getBlock() == cBlock) {
                                // throat Track Segment is in this Block
                                if (!checkDirectionSensor(bHead, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                    errorCount++;
                                }
                                if (!checkDirectionSensor(cHead, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                    errorCount++;
                                }
                            } else if (((t.getContinuingSense() == Turnout.CLOSED) && (((TrackSegment) t.getConnectB()).getLayoutBlock().getBlock() == cBlock)) || ((t.getContinuingSense() == Turnout.THROWN) && (((TrackSegment) t.getConnectC()).getLayoutBlock().getBlock() == cBlock))) {
                                //  diverging track segment is in this block, reverse continuing sense.
                                if (a2Head == null) {
                                    // single head at throat
                                    if (!checkDirectionSensor(aHead, direction, ConnectivityUtil.CONTINUING, cUtil)) {
                                        errorCount++;
                                    }
                                } else {
                                    // two heads at throat
                                    if (!checkDirectionSensor(aHead, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                        errorCount++;
                                    }
                                }
                                if (!checkDirectionSensor(bHead, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                    errorCount++;
                                }
                            } else if (((t.getContinuingSense() == Turnout.CLOSED) && (((TrackSegment) t.getConnectC()).getLayoutBlock().getBlock() == cBlock)) || ((t.getContinuingSense() == Turnout.THROWN) && (((TrackSegment) t.getConnectB()).getLayoutBlock().getBlock() == cBlock))) {
                                //  continuing track segment is in this block, reverse continuing sense.
                                if (a2Head == null) {
                                    // single head at throat
                                    if (!checkDirectionSensor(aHead, direction, ConnectivityUtil.DIVERGING, cUtil)) {
                                        errorCount++;
                                    }
                                } else {
                                    // two heads at throat
                                    if (!checkDirectionSensor(a2Head, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                        errorCount++;
                                    }
                                }
                                if (!checkDirectionSensor(cHead, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                    errorCount++;
                                }
                            }
                        }
                    }
                } else if (t.getLinkType() != LayoutTurnout.NO_LINK) {
                    // special linked turnout
                    LayoutTurnout tLinked = getLayoutTurnoutFromTurnoutName(t.getLinkedTurnoutName(), panel);
                    if (tLinked == null) {
                        log.error("null Layout Turnout linked to turnout " + t.getTurnout().getSystemName());
                    } else if (t.getLinkType() == LayoutTurnout.THROAT_TO_THROAT) {
                        SignalHead b1Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalB1Name());
                        SignalHead b2Head = null;
                        String hName = t.getSignalB2Name();
                        if ((hName != null) && (!hName.equals(""))) {
                            b2Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(hName);
                        }
                        SignalHead c1Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalC1Name());
                        SignalHead c2Head = null;
                        hName = t.getSignalC2Name();
                        if ((hName != null) && (!hName.equals(""))) {
                            c2Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(hName);
                        }
                        int direction = getDirectionStandardTurnout(t, cUtil);
                        int altDirection = EntryPoint.FORWARD;
                        if (direction == EntryPoint.FORWARD) {
                            altDirection = EntryPoint.REVERSE;
                        }
                        if (direction != EntryPoint.UNKNOWN) {
                            if (t.getLayoutBlock().getBlock() == cBlock) {
                                // Note: need allocation to traverse this turnout
                                if (!checkDirectionSensor(b1Head, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                    errorCount++;
                                }
                                if (b2Head != null) {
                                    if (!checkDirectionSensor(b2Head, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                        errorCount++;
                                    }
                                }
                                if (!checkDirectionSensor(c1Head, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                    errorCount++;
                                }
                                if (c2Head != null) {
                                    if (!checkDirectionSensor(c2Head, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                        errorCount++;
                                    }
                                }
                            } else {
                                // turnout is not in this block, switch to heads of linked turnout
                                b1Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(tLinked.getSignalB1Name());
                                hName = tLinked.getSignalB2Name();
                                b2Head = null;
                                if ((hName != null) && (!hName.equals(""))) {
                                    b2Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(hName);
                                }
                                c1Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(tLinked.getSignalC1Name());
                                c2Head = null;
                                hName = tLinked.getSignalC2Name();
                                if ((hName != null) && (!hName.equals(""))) {
                                    c2Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(hName);
                                }
                                if (((t.getContinuingSense() == Turnout.CLOSED) && (((TrackSegment) t.getConnectB()).getLayoutBlock().getBlock() == cBlock)) || ((t.getContinuingSense() == Turnout.THROWN) && (((TrackSegment) t.getConnectC()).getLayoutBlock().getBlock() == cBlock))) {
                                    // continuing track segment is in this block
                                    if (b2Head != null) {
                                        if (!checkDirectionSensor(b1Head, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                            errorCount++;
                                        }
                                    } else {
                                        if (!checkDirectionSensor(b1Head, direction, ConnectivityUtil.CONTINUING, cUtil)) {
                                            errorCount++;
                                        }
                                    }
                                    if (c2Head != null) {
                                        if (!checkDirectionSensor(c1Head, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                            errorCount++;
                                        }
                                    } else {
                                        if (!checkDirectionSensor(c1Head, direction, ConnectivityUtil.CONTINUING, cUtil)) {
                                            errorCount++;
                                        }
                                    }
                                } else if (((t.getContinuingSense() == Turnout.CLOSED) && (((TrackSegment) t.getConnectC()).getLayoutBlock().getBlock() == cBlock)) || ((t.getContinuingSense() == Turnout.THROWN) && (((TrackSegment) t.getConnectB()).getLayoutBlock().getBlock() == cBlock))) {
                                    // diverging track segment is in this block
                                    if (b2Head != null) {
                                        if (!checkDirectionSensor(b2Head, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                            errorCount++;
                                        }
                                    } else {
                                        if (!checkDirectionSensor(b1Head, direction, ConnectivityUtil.DIVERGING, cUtil)) {
                                            errorCount++;
                                        }
                                    }
                                    if (c2Head != null) {
                                        if (!checkDirectionSensor(c2Head, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                            errorCount++;
                                        }
                                    } else {
                                        if (!checkDirectionSensor(c1Head, direction, ConnectivityUtil.DIVERGING, cUtil)) {
                                            errorCount++;
                                        }
                                    }
                                }
                            }
                        }
                    } else if (t.getLinkType() == LayoutTurnout.FIRST_3_WAY) {
                        SignalHead a1Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalA1Name());
                        SignalHead a2Head = null;
                        String hName = t.getSignalA2Name();
                        if ((hName != null) && (!hName.equals(""))) {
                            a2Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(hName);
                        }
                        SignalHead a3Head = null;
                        hName = t.getSignalA3Name();
                        if ((hName != null) && (!hName.equals(""))) {
                            a3Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(hName);
                        }
                        SignalHead cHead = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalC1Name());
                        int direction = getDirectionStandardTurnout(t, cUtil);
                        int altDirection = EntryPoint.FORWARD;
                        if (direction == EntryPoint.FORWARD) {
                            altDirection = EntryPoint.REVERSE;
                        }
                        if (direction != EntryPoint.UNKNOWN) {
                            if (t.getLayoutBlock().getBlock() == cBlock) {
                                // Note: need allocation to traverse this turnout
                                if (!checkDirectionSensor(a1Head, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                    errorCount++;
                                }
                                if ((a2Head != null) && (a3Head != null)) {
                                    if (!checkDirectionSensor(a2Head, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                        errorCount++;
                                    }
                                    if (!checkDirectionSensor(a3Head, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                        errorCount++;
                                    }
                                }
                                if (!checkDirectionSensor(cHead, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                    errorCount++;
                                }
                            } else {
                                // turnout is not in this block
                                if (((TrackSegment) t.getConnectA()).getLayoutBlock().getBlock() == cBlock) {
                                    // throat Track Segment is in this Block
                                    if (!checkDirectionSensor(cHead, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                        errorCount++;
                                    }
                                } else if (((TrackSegment) t.getConnectC()).getLayoutBlock().getBlock() == cBlock) {
                                    // diverging track segment is in this Block
                                    if (a2Head != null) {
                                        if (!checkDirectionSensor(a2Head, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                            errorCount++;
                                        }
                                    } else {
                                        if (!checkDirectionSensor(a1Head, direction, ConnectivityUtil.DIVERGING, cUtil)) {
                                            errorCount++;
                                        }
                                    }
                                }
                            }
                        }
                    } else if (t.getLinkType() == LayoutTurnout.SECOND_3_WAY) {
                        SignalHead bHead = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalB1Name());
                        SignalHead cHead = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalC1Name());
                        SignalHead a1Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(tLinked.getSignalA1Name());
                        SignalHead a3Head = null;
                        String hName = tLinked.getSignalA3Name();
                        if ((hName != null) && (!hName.equals(""))) {
                            a3Head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(hName);
                        }
                        int direction = getDirectionStandardTurnout(t, cUtil);
                        int altDirection = EntryPoint.FORWARD;
                        if (direction == EntryPoint.FORWARD) {
                            altDirection = EntryPoint.REVERSE;
                        }
                        if (direction != EntryPoint.UNKNOWN) {
                            if (t.getLayoutBlock().getBlock() == cBlock) {
                                // Note: need allocation to traverse this turnout
                                if (!checkDirectionSensor(bHead, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                    errorCount++;
                                }
                                if (!checkDirectionSensor(cHead, altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                    errorCount++;
                                }
                            }
                            if (((TrackSegment) t.getConnectC()).getLayoutBlock().getBlock() == cBlock) {
                                // diverging track segment is in this Block
                                if (a3Head != null) {
                                    if (!checkDirectionSensor(a3Head, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                        errorCount++;
                                    }
                                } else {
                                    log.warn("Turnout " + tLinked.getTurnoutName() + " - SSL for head " + a1Head.getSystemName() + " cannot handle direction sensor for second diverging track.");
                                    errorCount++;
                                }
                            } else if (((TrackSegment) t.getConnectB()).getLayoutBlock().getBlock() == cBlock) {
                                // continuing track segment is in this Block
                                if (a3Head != null) {
                                    if (!checkDirectionSensor(a1Head, direction, ConnectivityUtil.OVERALL, cUtil)) {
                                        errorCount++;
                                    }
                                } else {
                                    if (!checkDirectionSensor(a1Head, direction, ConnectivityUtil.CONTINUING, cUtil)) {
                                        errorCount++;
                                    }
                                }
                            }
                        }
                    }
                } else if ((t.getTurnoutType() == LayoutTurnout.RH_XOVER) || (t.getTurnoutType() == LayoutTurnout.LH_XOVER) || (t.getTurnoutType() == LayoutTurnout.DOUBLE_XOVER)) {
                    // crossover turnout
                    // Note: direction is for proceeding from A to B (or D to C)
                    int direction = getDirectionXoverTurnout(t, cUtil);
                    int altDirection = EntryPoint.FORWARD;
                    if (direction == EntryPoint.FORWARD) {
                        altDirection = EntryPoint.REVERSE;
                    }
                    if (direction == EntryPoint.UNKNOWN) {
                        errorCount++;
                    } else {
                        if (((TrackSegment) t.getConnectA()).getLayoutBlock().getBlock() == cBlock) {
                            if ((t.getTurnoutType() == LayoutTurnout.DOUBLE_XOVER) || (t.getTurnoutType() == LayoutTurnout.RH_XOVER)) {
                                if (!placeSensorInCrossover(t.getSignalB1Name(), t.getSignalB2Name(), t.getSignalC1Name(), t.getSignalC2Name(), altDirection, cUtil)) {
                                    errorCount++;
                                }
                            } else {
                                if (!placeSensorInCrossover(t.getSignalB1Name(), t.getSignalB2Name(), null, null, altDirection, cUtil)) {
                                    errorCount++;
                                }
                            }
                        }
                        if (((TrackSegment) t.getConnectB()).getLayoutBlock().getBlock() == cBlock) {
                            if ((t.getTurnoutType() == LayoutTurnout.DOUBLE_XOVER) || (t.getTurnoutType() == LayoutTurnout.LH_XOVER)) {
                                if (!placeSensorInCrossover(t.getSignalA1Name(), t.getSignalA2Name(), t.getSignalD1Name(), t.getSignalD2Name(), direction, cUtil)) {
                                    errorCount++;
                                }
                            } else {
                                if (!placeSensorInCrossover(t.getSignalA1Name(), t.getSignalA2Name(), null, null, direction, cUtil)) {
                                    errorCount++;
                                }
                            }
                        }
                        if (((TrackSegment) t.getConnectC()).getLayoutBlock().getBlock() == cBlock) {
                            if ((t.getTurnoutType() == LayoutTurnout.DOUBLE_XOVER) || (t.getTurnoutType() == LayoutTurnout.RH_XOVER)) {
                                if (!placeSensorInCrossover(t.getSignalD1Name(), t.getSignalD2Name(), t.getSignalA1Name(), t.getSignalA2Name(), direction, cUtil)) {
                                    errorCount++;
                                }
                            } else {
                                if (!placeSensorInCrossover(t.getSignalD1Name(), t.getSignalD2Name(), null, null, direction, cUtil)) {
                                    errorCount++;
                                }
                            }
                        }
                        if (((TrackSegment) t.getConnectD()).getLayoutBlock().getBlock() == cBlock) {
                            if ((t.getTurnoutType() == LayoutTurnout.DOUBLE_XOVER) || (t.getTurnoutType() == LayoutTurnout.LH_XOVER)) {
                                if (!placeSensorInCrossover(t.getSignalC1Name(), t.getSignalC2Name(), t.getSignalB1Name(), t.getSignalB2Name(), altDirection, cUtil)) {
                                    errorCount++;
                                }
                            } else {
                                if (!placeSensorInCrossover(t.getSignalC1Name(), t.getSignalC2Name(), null, null, altDirection, cUtil)) {
                                    errorCount++;
                                }
                            }
                        }
                    }
                } else if (t.getTurnoutType() == LayoutSlip.SINGLE_SLIP || t.getTurnoutType() == LayoutSlip.DOUBLE_SLIP) {
                    int direction = getDirectionSlip((LayoutSlip) t, cUtil);
                    int altDirection = EntryPoint.FORWARD;
                    if (direction == EntryPoint.FORWARD) {
                        altDirection = EntryPoint.REVERSE;
                    }
                    if (direction == EntryPoint.UNKNOWN) {
                        errorCount++;
                    } else {
                        if (!checkDirectionSensor(InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalA1Name()), altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                            errorCount++;
                        }
                        if (!checkDirectionSensor(InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalA2Name()), altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                            errorCount++;
                        }
                        if (t.getTurnoutType() == LayoutSlip.SINGLE_SLIP) {
                            if (!checkDirectionSensor(InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalB1Name()), altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                errorCount++;
                            }
                        } else {
                            if (!checkDirectionSensor(InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalB1Name()), altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                errorCount++;
                            }
                            if (!checkDirectionSensor(InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalB2Name()), altDirection, ConnectivityUtil.OVERALL, cUtil)) {
                                errorCount++;
                            }
                        }
                        if (t.getTurnoutType() == LayoutSlip.SINGLE_SLIP) {
                            if (!checkDirectionSensor(InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalC1Name()), direction, ConnectivityUtil.OVERALL, cUtil)) {
                                errorCount++;
                            }
                        } else {
                            if (!checkDirectionSensor(InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalC1Name()), direction, ConnectivityUtil.OVERALL, cUtil)) {
                                errorCount++;
                            }
                            if (!checkDirectionSensor(InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalC2Name()), direction, ConnectivityUtil.OVERALL, cUtil)) {
                                errorCount++;
                            }
                        }
                        if (!checkDirectionSensor(InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalD1Name()), direction, ConnectivityUtil.OVERALL, cUtil)) {
                            errorCount++;
                        }
                        if (!checkDirectionSensor(InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(t.getSignalD2Name()), direction, ConnectivityUtil.OVERALL, cUtil)) {
                            errorCount++;
                        }
                    }
                } else {
                    log.error("Unknown turnout type for turnout " + t.getTurnout().getSystemName() + " in Section " + getSystemName() + ".");
                    errorCount++;
                }
            } else {
                // signal heads missing in turnout
                missingSignalsTurnouts++;
            }
        }
    }
    // set up missing signal head message, if any
    if ((missingSignalsBB + missingSignalsTurnouts + missingSignalsLevelXings) > 0) {
        String s = "Section - " + getSystemName();
        String uname = getUserName();
        if ((uname != null) && (!uname.equals(""))) {
            s = s + "(" + uname + ")";
        }
        if (missingSignalsBB > 0) {
            s = s + ", " + (missingSignalsBB) + " anchor point signal heads missing";
        }
        if (missingSignalsTurnouts > 0) {
            s = s + ", " + (missingSignalsTurnouts) + " turnouts missing signals";
        }
        if (missingSignalsLevelXings > 0) {
            s = s + ", " + (missingSignalsLevelXings) + " level crossings missing signals";
        }
        log.warn(s);
    }
    return errorCount;
}
Also used : TrackNode(jmri.jmrit.display.layoutEditor.TrackNode) LayoutSlip(jmri.jmrit.display.layoutEditor.LayoutSlip) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) PositionablePoint(jmri.jmrit.display.layoutEditor.PositionablePoint) PositionablePoint(jmri.jmrit.display.layoutEditor.PositionablePoint) TrackSegment(jmri.jmrit.display.layoutEditor.TrackSegment) LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) LevelXing(jmri.jmrit.display.layoutEditor.LevelXing) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) ConnectivityUtil(jmri.jmrit.display.layoutEditor.ConnectivityUtil)

Aggregations

LayoutSlip (jmri.jmrit.display.layoutEditor.LayoutSlip)8 LayoutTurnout (jmri.jmrit.display.layoutEditor.LayoutTurnout)6 LevelXing (jmri.jmrit.display.layoutEditor.LevelXing)4 PositionablePoint (jmri.jmrit.display.layoutEditor.PositionablePoint)4 SignalHead (jmri.SignalHead)3 SignalMast (jmri.SignalMast)3 ConnectivityUtil (jmri.jmrit.display.layoutEditor.ConnectivityUtil)3 Point2D (java.awt.geom.Point2D)2 ArrayList (java.util.ArrayList)2 Block (jmri.Block)2 Sensor (jmri.Sensor)2 Turnout (jmri.Turnout)2 LayoutBlock (jmri.jmrit.display.layoutEditor.LayoutBlock)2 Element (org.jdom2.Element)2 Color (java.awt.Color)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 Hashtable (java.util.Hashtable)1