Search in sources :

Example 1 with LayoutBlock

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

the class Section method getDirectionStandardTurnout.

/**
     * Returns EntryPoint.FORWARD if proceeding from the throat to the other end
     * is movement in the forward direction. Returns EntryPoint.REVERSE if
     * proceeding from the throat to the other end is movement in the reverse
     * direction. Returns EntryPoint.UNKNOWN if cannot determine direction. This
     * should only happen if blocks are not set up correctly--if all connections
     * go to the same Block, or not all Blocks set. An error message is logged
     * if EntryPoint.UNKNOWN is returned.
     */
private int getDirectionStandardTurnout(LayoutTurnout t, ConnectivityUtil cUtil) {
    LayoutBlock aBlock = ((TrackSegment) t.getConnectA()).getLayoutBlock();
    LayoutBlock bBlock = ((TrackSegment) t.getConnectB()).getLayoutBlock();
    LayoutBlock cBlock = ((TrackSegment) t.getConnectC()).getLayoutBlock();
    if ((aBlock == null) || (bBlock == null) || (cBlock == null)) {
        log.error("All blocks not assigned for track segments connecting to turnout - " + t.getTurnout().getSystemName() + ".");
        return EntryPoint.UNKNOWN;
    }
    Block exBlock = checkDualDirection(aBlock, bBlock, cBlock);
    if ((exBlock != null) || ((aBlock == bBlock) && (aBlock == cBlock))) {
        // using Entry Points directly will lead to a problem, try following track - first from A following B
        int dir = EntryPoint.UNKNOWN;
        Block tBlock = null;
        TrackNode tn = new TrackNode(t, LayoutTrack.TURNOUT_A, (TrackSegment) t.getConnectA(), false, Turnout.CLOSED);
        while ((tBlock == null) && (tn != null) && (!tn.reachedEndOfTrack())) {
            tn = cUtil.getNextNode(tn, 0);
            tBlock = cUtil.getExitBlockForTrackNode(tn, exBlock);
        }
        if (tBlock == null) {
            // try from A following C
            tn = new TrackNode(t, LayoutTrack.TURNOUT_A, (TrackSegment) t.getConnectA(), false, Turnout.THROWN);
            while ((tBlock == null) && (tn != null) && (!tn.reachedEndOfTrack())) {
                tn = cUtil.getNextNode(tn, 0);
                tBlock = cUtil.getExitBlockForTrackNode(tn, exBlock);
            }
        }
        if (tBlock != null) {
            LayoutBlock lb = InstanceManager.getDefault(LayoutBlockManager.class).getByUserName(tBlock.getUserName());
            if (lb != null) {
                dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, lb);
            }
        }
        if (dir == EntryPoint.UNKNOWN) {
            // try from B following A
            tBlock = null;
            tn = new TrackNode(t, LayoutTrack.TURNOUT_B, (TrackSegment) t.getConnectB(), false, Turnout.CLOSED);
            while ((tBlock == null) && (tn != null && (!tn.reachedEndOfTrack()))) {
                tn = cUtil.getNextNode(tn, 0);
                tBlock = cUtil.getExitBlockForTrackNode(tn, exBlock);
            }
            if (tBlock != null) {
                LayoutBlock lb = InstanceManager.getDefault(LayoutBlockManager.class).getByUserName(tBlock.getUserName());
                if (lb != null) {
                    dir = checkLists(mForwardEntryPoints, mReverseEntryPoints, lb);
                }
            }
        }
        if (dir == EntryPoint.UNKNOWN) {
            log.error("Block definition ambiguity - cannot determine direction of Turnout " + t.getTurnout().getSystemName() + " in Section " + getSystemName() + ".");
        }
        return dir;
    }
    if ((aBlock != bBlock) && containsBlock(aBlock.getBlock()) && containsBlock(bBlock.getBlock())) {
        // both blocks are different, but are in this Section
        if (getBlockSequenceNumber(aBlock.getBlock()) < getBlockSequenceNumber(bBlock.getBlock())) {
            return EntryPoint.FORWARD;
        } else {
            return EntryPoint.REVERSE;
        }
    } else if ((aBlock != cBlock) && containsBlock(aBlock.getBlock()) && containsBlock(cBlock.getBlock())) {
        // both blocks are different, but are in this Section
        if (getBlockSequenceNumber(aBlock.getBlock()) < getBlockSequenceNumber(cBlock.getBlock())) {
            return EntryPoint.FORWARD;
        } else {
            return EntryPoint.REVERSE;
        }
    }
    LayoutBlock tBlock = t.getLayoutBlock();
    if (tBlock == null) {
        log.error("Block not assigned for turnout " + t.getTurnout().getSystemName());
        return EntryPoint.UNKNOWN;
    }
    if (containsBlock(aBlock.getBlock()) && (!containsBlock(bBlock.getBlock()))) {
        // aBlock is in Section, bBlock is not
        int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, bBlock);
        if (dir != EntryPoint.UNKNOWN) {
            return dir;
        }
        if ((tBlock != bBlock) && (!containsBlock(tBlock.getBlock()))) {
            dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, tBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
    }
    if (containsBlock(aBlock.getBlock()) && (!containsBlock(cBlock.getBlock()))) {
        // aBlock is in Section, cBlock is not
        int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, cBlock);
        if (dir != EntryPoint.UNKNOWN) {
            return dir;
        }
        if ((tBlock != cBlock) && (!containsBlock(tBlock.getBlock()))) {
            dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, tBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
    }
    if ((containsBlock(bBlock.getBlock()) || containsBlock(cBlock.getBlock())) && (!containsBlock(aBlock.getBlock()))) {
        // bBlock or cBlock is in Section, aBlock is not
        int dir = checkLists(mForwardEntryPoints, mReverseEntryPoints, aBlock);
        if (dir != EntryPoint.UNKNOWN) {
            return dir;
        }
        if ((tBlock != aBlock) && (!containsBlock(tBlock.getBlock()))) {
            dir = checkLists(mForwardEntryPoints, mReverseEntryPoints, tBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
    }
    if (!containsBlock(aBlock.getBlock()) && !containsBlock(bBlock.getBlock()) && !containsBlock(cBlock.getBlock()) && containsBlock(tBlock.getBlock())) {
        //is the turnout in a section of its own?
        int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, aBlock);
        return dir;
    }
    // should never get here
    log.error("Unexpected error in getDirectionStandardTurnout when working with turnout " + t.getTurnout().getSystemName());
    return EntryPoint.UNKNOWN;
}
Also used : LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) TrackNode(jmri.jmrit.display.layoutEditor.TrackNode) LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) PositionablePoint(jmri.jmrit.display.layoutEditor.PositionablePoint) TrackSegment(jmri.jmrit.display.layoutEditor.TrackSegment)

Example 2 with LayoutBlock

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

the class EntryExitPairs method setMultiPointRoute.

private void setMultiPointRoute(PointDetails fromPd, PointDetails toPd) {
    boolean cleardown = false;
    if (fromPd.isRouteFromPointSet() && toPd.isRouteToPointSet()) {
        cleardown = true;
    }
    for (LayoutBlock pro : fromPd.getProtecting()) {
        try {
            jmri.jmrit.display.layoutEditor.LayoutBlockManager lbm = InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class);
            LayoutBlock toProt = null;
            if (!toPd.getProtecting().isEmpty()) {
                toProt = toPd.getProtecting().get(0);
            }
            boolean result = lbm.getLayoutBlockConnectivityTools().checkValidDest(fromPd.getFacing(), pro, toPd.getFacing(), toProt, LayoutBlockConnectivityTools.SENSORTOSENSOR);
            if (result) {
                ArrayList<LayoutBlock> blkList = lbm.getLayoutBlockConnectivityTools().getLayoutBlocks(fromPd.getFacing(), toPd.getFacing(), pro, cleardown, LayoutBlockConnectivityTools.NONE);
                if (!blkList.isEmpty()) {
                    List<jmri.NamedBean> beanList = lbm.getLayoutBlockConnectivityTools().getBeansInPath(blkList, fromPd.getPanel(), jmri.Sensor.class);
                    PointDetails fromPoint = fromPd;
                    refCounter++;
                    if (!beanList.isEmpty()) {
                        for (int i = 1; i < beanList.size(); i++) {
                            NamedBean nb = beanList.get(i);
                            PointDetails cur = getPointDetails(nb, fromPd.getPanel());
                            Source s = nxpair.get(fromPoint);
                            if (s != null) {
                                routesToSet.add(new SourceToDest(s, s.getDestForPoint(cur), false, refCounter));
                            }
                            fromPoint = cur;
                        }
                    }
                    Source s = nxpair.get(fromPoint);
                    if (s != null) {
                        routesToSet.add(new SourceToDest(s, s.getDestForPoint(toPd), false, refCounter));
                    }
                    processRoutesToSet();
                    return;
                }
            }
        } catch (jmri.JmriException e) {
        //Can be considered normal if route is blocked
        }
    }
    fromPd.setNXButtonState(NXBUTTONINACTIVE);
    toPd.setNXButtonState(NXBUTTONINACTIVE);
}
Also used : NamedBean(jmri.NamedBean) JmriException(jmri.JmriException) Source(jmri.jmrit.signalling.entryexit.Source) LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) PointDetails(jmri.jmrit.signalling.entryexit.PointDetails)

Example 3 with LayoutBlock

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

the class Section method setAlternateColorFromActiveBlock.

/**
     * This function sets/resets the display to use alternate color for
     * unoccupied blocks in this section. If the section already contains an
     * active block, then the alternative colour will be set from the active
     * block, if no active block is found or we are clearing the alternative
     * colour then all the blocks in the section will be set. If Layout Editor
     * panel is not present, Layout Blocks will not be present, and nothing will
     * be set.
     *
     * @param set true to use alternate unoccupied color; false otherwise
     */
public void setAlternateColorFromActiveBlock(boolean set) {
    LayoutBlockManager lbm = InstanceManager.getDefault(LayoutBlockManager.class);
    boolean beenSet = false;
    if (!set || getState() == FREE || getState() == UNKNOWN) {
        setAlternateColor(set);
    } else if (getState() == FORWARD) {
        for (int i = 0; i < mBlockEntries.size(); i++) {
            Block b = mBlockEntries.get(i);
            if (b.getState() == Block.OCCUPIED) {
                beenSet = true;
            }
            if (beenSet) {
                LayoutBlock lb = lbm.getByUserName(b.getUserName());
                if (lb != null) {
                    lb.setUseExtraColor(set);
                }
            }
        }
    } else if (getState() == REVERSE) {
        for (int i = mBlockEntries.size(); i < 0; i--) {
            Block b = mBlockEntries.get(i);
            if (b.getState() == Block.OCCUPIED) {
                beenSet = true;
            }
            if (beenSet) {
                LayoutBlock lb = lbm.getByUserName(b.getUserName());
                if (lb != null) {
                    lb.setUseExtraColor(set);
                }
            }
        }
    }
    if (!beenSet) {
        setAlternateColor(set);
    }
}
Also used : LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) PositionablePoint(jmri.jmrit.display.layoutEditor.PositionablePoint)

Example 4 with LayoutBlock

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

the class LayoutBlockManagerXml method loadLayoutBlocks.

/**
     * Utility method to load the individual LayoutBlock objects. If there's no
     * additional info needed for a specific layoutblock type, invoke this with
     * the parent of the set of layoutblock elements.
     *
     * @param layoutblocks Element containing the layoutblock elements to load.
     */
public void loadLayoutBlocks(Element layoutblocks) {
    LayoutBlockManager tm = InstanceManager.getDefault(LayoutBlockManager.class);
    if (layoutblocks.getAttribute("blockrouting") != null) {
        if (layoutblocks.getAttribute("blockrouting").getValue().equals("yes")) {
            tm.enableAdvancedRouting(true);
        }
    }
    if (layoutblocks.getAttribute("routingStablisedSensor") != null) {
        try {
            tm.setStabilisedSensor(layoutblocks.getAttribute("routingStablisedSensor").getValue());
        } catch (jmri.JmriException e) {
        }
    }
    List<Element> layoutblockList = layoutblocks.getChildren("layoutblock");
    if (log.isDebugEnabled()) {
        log.debug("Found " + layoutblockList.size() + " layoutblocks");
    }
    for (int i = 0; i < layoutblockList.size(); i++) {
        String sysName = getSystemName(layoutblockList.get(i));
        if (sysName == null) {
            log.warn("unexpected null in systemName " + ((layoutblockList.get(i))) + " " + ((layoutblockList.get(i))).getAttributes());
            break;
        }
        String userName = getUserName(layoutblockList.get(i));
        LayoutBlock b = tm.createNewLayoutBlock(sysName, userName);
        // load common parts
        loadCommon(b, layoutblockList.get(i));
        if (b != null) {
            // set attributes
            Color color = ColorUtil.stringToColor(((layoutblockList.get(i))).getAttribute("trackcolor").getValue());
            b.setBlockTrackColor(color);
            color = ColorUtil.stringToColor(((layoutblockList.get(i))).getAttribute("occupiedcolor").getValue());
            b.setBlockOccupiedColor(color);
            Attribute a = ((layoutblockList.get(i))).getAttribute("extracolor");
            if (a != null) {
                b.setBlockExtraColor(ColorUtil.stringToColor(a.getValue()));
            }
            a = ((layoutblockList.get(i))).getAttribute("occupancysensor");
            if (a != null) {
                b.setOccupancySensorName(a.getValue());
            }
            a = ((layoutblockList.get(i))).getAttribute("memory");
            if (a != null) {
                b.setMemoryName(a.getValue());
            }
            a = ((layoutblockList.get(i))).getAttribute("occupancysensorsense");
            int sense = Sensor.ACTIVE;
            try {
                sense = ((layoutblockList.get(i))).getAttribute("occupiedsense").getIntValue();
            } catch (org.jdom2.DataConversionException e) {
                log.error("failed to convert occupiedsense attribute");
            }
            b.setOccupiedSense(sense);
            if (((layoutblockList.get(i))).getChild("metric") != null) {
                String stMetric = ((layoutblockList.get(i))).getChild("metric").getText();
                try {
                    b.setBlockMetric(Integer.valueOf(stMetric));
                } catch (java.lang.NumberFormatException e) {
                    log.error("failed to convert metric attribute for block " + b.getDisplayName());
                }
            }
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Color(java.awt.Color) LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager)

Example 5 with LayoutBlock

use of jmri.jmrit.display.layoutEditor.LayoutBlock 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)

Aggregations

LayoutBlock (jmri.jmrit.display.layoutEditor.LayoutBlock)20 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)11 PositionablePoint (jmri.jmrit.display.layoutEditor.PositionablePoint)7 TrackNode (jmri.jmrit.display.layoutEditor.TrackNode)5 TrackSegment (jmri.jmrit.display.layoutEditor.TrackSegment)4 Block (jmri.Block)3 JmriException (jmri.JmriException)3 SignalMast (jmri.SignalMast)3 Element (org.jdom2.Element)3 Color (java.awt.Color)2 ArrayList (java.util.ArrayList)2 SignalHead (jmri.SignalHead)2 ActiveTrain (jmri.jmrit.dispatcher.ActiveTrain)2 ConnectivityUtil (jmri.jmrit.display.layoutEditor.ConnectivityUtil)2 LayoutSlip (jmri.jmrit.display.layoutEditor.LayoutSlip)2 LayoutTurnout (jmri.jmrit.display.layoutEditor.LayoutTurnout)2 PointDetails (jmri.jmrit.signalling.entryexit.PointDetails)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1