Search in sources :

Example 1 with TrackSegment

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

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

the class TrackSegmentXml method load.

/**
     * Load, starting with the tracksegment element, then all all attributes
     *
     * @param element Top level Element to unpack.
     * @param o       LayoutEditor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    LayoutEditor p = (LayoutEditor) o;
    // get attributes
    String name = element.getAttribute("ident").getValue();
    int type1 = LayoutTrack.NONE;
    int type2 = LayoutTrack.NONE;
    try {
        type1 = element.getAttribute("type1").getIntValue();
        type2 = element.getAttribute("type2").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert tracksegment attribute");
    }
    boolean dash = true;
    if (element.getAttribute("dashed").getValue().equals("no")) {
        dash = false;
    }
    boolean main = true;
    if (element.getAttribute("mainline").getValue().equals("no")) {
        main = false;
    }
    boolean hide = true;
    if (element.getAttribute("hidden").getValue().equals("no")) {
        hide = false;
    }
    String con1Name = element.getAttribute("connect1name").getValue();
    String con2Name = element.getAttribute("connect2name").getValue();
    // create the new TrackSegment
    TrackSegment l = new TrackSegment(name, con1Name, type1, con2Name, type2, dash, main, hide, p);
    try {
        if (element.getAttribute("arc").getValue().equals("yes")) {
            l.setArc(true);
        }
    } catch (NullPointerException e) {
    }
    if (l.getArc()) {
        //int startangle = 0;
        try {
            if (element.getAttribute("flip").getValue().equals("yes")) {
                l.setFlip(true);
            }
        } catch (NullPointerException e) {
        }
        //considered normal if the attribute is not present }
        try {
            if (element.getAttribute("circle").getValue().equals("yes")) {
                l.setCircle(true);
            }
        } catch (NullPointerException e) {
        }
        if (l.getCircle()) {
            try {
                l.setAngle(element.getAttribute("angle").getDoubleValue());
            } catch (org.jdom2.DataConversionException e) {
                log.error("failed to convert tracksegment attribute");
            } catch (NullPointerException e) {
            // considered normal if the attribute not present
            }
        }
        try {
            if (element.getAttribute("hideConLines").getValue().equals("yes")) {
                l.hideConstructionLines(TrackSegment.HIDECON);
            }
        } catch (NullPointerException e) {
        }
    //considered normal if the attribute is not present }
    }
    try {
        if (element.getAttribute("bezier").getValue().equals("yes")) {
            // load control points
            Element controlpointsElement = element.getChild("controlpoints");
            if (null != controlpointsElement) {
                List<Element> elementList = controlpointsElement.getChildren("controlpoint");
                if (null != elementList) {
                    if (elementList.size() >= 2) {
                        for (int i = 0; i < elementList.size(); i++) {
                            double x = 0.0;
                            double y = 0.0;
                            int index = 0;
                            Element relem = elementList.get(i);
                            try {
                                index = (relem.getAttribute("index")).getIntValue();
                                x = (relem.getAttribute("x")).getFloatValue();
                                y = (relem.getAttribute("y")).getFloatValue();
                            } catch (org.jdom2.DataConversionException e) {
                                log.error("failed to convert controlpoint coordinates or index attributes");
                            }
                            l.setBezierControlPoint(new Point2D.Double(x, y), index);
                        }
                    } else {
                        log.error("Track segment Bezier two controlpoint elements not found. (found " + elementList.size() + ")");
                    }
                } else {
                    log.error("Track segment Bezier controlpoint elements not found.");
                }
            } else {
                log.error("Track segment Bezier controlpoints element not found.");
            }
            // NOTE: do this LAST (so reCenter won't be called yet)
            l.setBezier(true);
        }
    } catch (NullPointerException e) {
    }
    //considered normal if the attribute is not present }
    // get remaining attribute
    Attribute a = element.getAttribute("blockname");
    if (a != null) {
        l.tBlockName = a.getValue();
    }
    p.trackList.add(l);
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) TrackSegment(jmri.jmrit.display.layoutEditor.TrackSegment) Point2D(java.awt.geom.Point2D)

Example 3 with TrackSegment

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

the class TrackSegmentXml method store.

/**
     * Default implementation for storing the contents of a TrackSegment
     *
     * @param o Object to store, of type TrackSegment
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    TrackSegment p = (TrackSegment) o;
    // NOI18N
    Element element = new Element("tracksegment");
    // include attributes
    element.setAttribute("ident", p.getID());
    if (p.getBlockName().length() > 0) {
        element.setAttribute("blockname", p.getBlockName());
    }
    element.setAttribute("connect1name", p.getConnect1Name());
    element.setAttribute("type1", "" + p.getType1());
    element.setAttribute("connect2name", p.getConnect2Name());
    element.setAttribute("type2", "" + p.getType2());
    element.setAttribute("dashed", "" + (p.getDashed() ? "yes" : "no"));
    element.setAttribute("mainline", "" + (p.getMainline() ? "yes" : "no"));
    element.setAttribute("hidden", "" + (p.isHidden() ? "yes" : "no"));
    element.setAttribute("arc", "" + (p.getArc() ? "yes" : "no"));
    if (p.getArc()) {
        element.setAttribute("flip", "" + (p.getFlip() ? "yes" : "no"));
        element.setAttribute("circle", "" + (p.getCircle() ? "yes" : "no"));
        if ((p.getCircle()) && (p.getAngle() != 0.0D)) {
            element.setAttribute("angle", "" + (p.getAngle()));
            element.setAttribute("hideConLines", "" + (p.hideConstructionLines() ? "yes" : "no"));
        }
    }
    if (p.getBezier()) {
        element.setAttribute("bezier", "yes");
    }
    element.setAttribute("class", getClass().getName());
    if (p.getBezier()) {
        // add control points
        Element elementControlpoints = new Element("controlpoints");
        for (int i = 0; i < p.getNumberOfBezierControlPoints(); i++) {
            Element elementControlpoint = new Element("controlpoint");
            elementControlpoint.setAttribute("index", "" + i);
            Point2D pt = p.getBezierControlPoint(i);
            elementControlpoint.setAttribute("x", "" + pt.getX());
            elementControlpoint.setAttribute("y", "" + pt.getY());
            elementControlpoints.addContent(elementControlpoint);
        }
        element.addContent(elementControlpoints);
    }
    return element;
}
Also used : Point2D(java.awt.geom.Point2D) Element(org.jdom2.Element) TrackSegment(jmri.jmrit.display.layoutEditor.TrackSegment)

Example 4 with TrackSegment

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

Example 5 with TrackSegment

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

the class Section method getDirectionSlip.

/**
     * Returns EntryPoint.FORWARD if proceeding from A to C or D (or B to D or
     * C) is movement in the forward direction. Returns EntryPoint.REVERSE if
     * proceeding from C or D to A (or D or C to B) 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 getDirectionSlip(LayoutSlip t, ConnectivityUtil cUtil) {
    LayoutBlock aBlock = ((TrackSegment) t.getConnectA()).getLayoutBlock();
    LayoutBlock bBlock = ((TrackSegment) t.getConnectB()).getLayoutBlock();
    LayoutBlock cBlock = ((TrackSegment) t.getConnectC()).getLayoutBlock();
    LayoutBlock dBlock = ((TrackSegment) t.getConnectD()).getLayoutBlock();
    if ((aBlock == null) || (bBlock == null) || (cBlock == null) || (dBlock == null)) {
        log.error("All blocks not assigned for track segments connecting to crossover turnout - " + t.getTurnout().getSystemName() + ".");
        return EntryPoint.UNKNOWN;
    }
    if ((aBlock == bBlock) && (aBlock == cBlock) && (aBlock == dBlock)) {
        log.error("Block setup problem - All track segments connecting to crossover turnout - " + t.getTurnout().getSystemName() + " are assigned to the same Block.");
        return EntryPoint.UNKNOWN;
    }
    if ((containsBlock(aBlock.getBlock())) || (containsBlock(cBlock.getBlock()))) {
        LayoutBlock exBlock = null;
        if (aBlock == cBlock) {
            if ((t.getTurnoutType() == LayoutSlip.DOUBLE_SLIP) && (bBlock == dBlock)) {
                exBlock = bBlock;
            }
        }
        if (exBlock != null) {
            // set direction by tracking from a or b
            int dir = EntryPoint.UNKNOWN;
            Block tBlock = null;
            TrackNode tn = new TrackNode(t, LayoutTrack.SLIP_A, (TrackSegment) t.getConnectA(), false, LayoutTurnout.STATE_AC);
            while ((tBlock == null) && (tn != null) && (!tn.reachedEndOfTrack())) {
                tn = cUtil.getNextNode(tn, 0);
                tBlock = cUtil.getExitBlockForTrackNode(tn, exBlock.getBlock());
            }
            if (tBlock != null) {
                LayoutBlock lb = InstanceManager.getDefault(LayoutBlockManager.class).getByUserName(tBlock.getUserName());
                if (lb != null) {
                    dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, lb);
                }
            } else {
                tn = new TrackNode(t, LayoutTrack.SLIP_C, (TrackSegment) t.getConnectC(), false, LayoutTurnout.STATE_AC);
                while ((tBlock == null) && (tn != null) && (!tn.reachedEndOfTrack())) {
                    tn = cUtil.getNextNode(tn, 0);
                    tBlock = cUtil.getExitBlockForTrackNode(tn, exBlock.getBlock());
                }
                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 crossover slip " + t.getTurnout().getSystemName() + " in Section " + getSystemName() + ".");
            }
            return dir;
        }
        if ((aBlock != cBlock) && containsBlock(aBlock.getBlock()) && containsBlock(cBlock.getBlock())) {
            if (getBlockSequenceNumber(aBlock.getBlock()) < getBlockSequenceNumber(cBlock.getBlock())) {
                return EntryPoint.FORWARD;
            } else {
                return EntryPoint.REVERSE;
            }
        }
        if (containsBlock(aBlock.getBlock()) && (!containsBlock(cBlock.getBlock()))) {
            int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, cBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
        if (containsBlock(cBlock.getBlock()) && (!containsBlock(aBlock.getBlock()))) {
            int dir = checkLists(mForwardEntryPoints, mReverseEntryPoints, aBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
        int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, dBlock);
        if (dir != EntryPoint.UNKNOWN) {
            return dir;
        }
    }
    if ((containsBlock(dBlock.getBlock())) || (containsBlock(bBlock.getBlock()))) {
        LayoutBlock exBlock = null;
        if (dBlock == bBlock) {
            if ((t.getTurnoutType() == LayoutSlip.DOUBLE_SLIP) && (cBlock == aBlock)) {
                exBlock = aBlock;
            }
        }
        if (exBlock != null) {
            // set direction by tracking from c or d
            int dir = EntryPoint.UNKNOWN;
            Block tBlock = null;
            TrackNode tn = new TrackNode(t, LayoutTrack.SLIP_D, (TrackSegment) t.getConnectD(), false, LayoutTurnout.STATE_BD);
            while ((tBlock == null) && (tn != null) && (!tn.reachedEndOfTrack())) {
                tn = cUtil.getNextNode(tn, 0);
                tBlock = cUtil.getExitBlockForTrackNode(tn, exBlock.getBlock());
            }
            if (tBlock != null) {
                LayoutBlock lb = InstanceManager.getDefault(LayoutBlockManager.class).getByUserName(tBlock.getUserName());
                if (lb != null) {
                    dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, lb);
                }
            } else {
                tn = new TrackNode(t, LayoutTrack.TURNOUT_B, (TrackSegment) t.getConnectB(), false, LayoutTurnout.STATE_BD);
                while ((tBlock == null) && (tn != null) && (!tn.reachedEndOfTrack())) {
                    tn = cUtil.getNextNode(tn, 0);
                    tBlock = cUtil.getExitBlockForTrackNode(tn, exBlock.getBlock());
                }
                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 slip " + t.getTurnout().getSystemName() + " in Section " + getSystemName() + ".");
            }
            return dir;
        }
        if ((dBlock != bBlock) && containsBlock(dBlock.getBlock()) && containsBlock(bBlock.getBlock())) {
            if (getBlockSequenceNumber(dBlock.getBlock()) < getBlockSequenceNumber(bBlock.getBlock())) {
                return EntryPoint.FORWARD;
            } else {
                return EntryPoint.REVERSE;
            }
        }
        if (containsBlock(dBlock.getBlock()) && (!containsBlock(bBlock.getBlock()))) {
            int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, bBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
        if (containsBlock(bBlock.getBlock()) && (!containsBlock(dBlock.getBlock()))) {
            int dir = checkLists(mForwardEntryPoints, mReverseEntryPoints, dBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
        if (t.getTurnoutType() == LayoutSlip.DOUBLE_SLIP) {
            int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, aBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
    }
    //If all else fails the slip must be in a block of its own so we shall work it out from there.
    if (t.getLayoutBlock() != aBlock) {
        //Block is not the same as that connected to A
        int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, aBlock);
        if (dir != EntryPoint.UNKNOWN) {
            return dir;
        }
    }
    if (t.getLayoutBlock() != bBlock) {
        //Block is not the same as that connected to B
        int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, bBlock);
        if (dir != EntryPoint.UNKNOWN) {
            return dir;
        }
    }
    if (t.getLayoutBlock() != cBlock) {
        //Block is not the same as that connected to C
        int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, cBlock);
        if (dir != EntryPoint.UNKNOWN) {
            return dir;
        }
    }
    if (t.getLayoutBlock() != dBlock) {
        //Block is not the same as that connected to D
        int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, dBlock);
        if (dir != EntryPoint.UNKNOWN) {
            return dir;
        }
    }
    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)

Aggregations

TrackSegment (jmri.jmrit.display.layoutEditor.TrackSegment)7 LayoutBlock (jmri.jmrit.display.layoutEditor.LayoutBlock)4 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)4 PositionablePoint (jmri.jmrit.display.layoutEditor.PositionablePoint)4 TrackNode (jmri.jmrit.display.layoutEditor.TrackNode)4 Point2D (java.awt.geom.Point2D)3 Element (org.jdom2.Element)3 ConnectivityUtil (jmri.jmrit.display.layoutEditor.ConnectivityUtil)1 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)1 LayoutSlip (jmri.jmrit.display.layoutEditor.LayoutSlip)1 LayoutTurnout (jmri.jmrit.display.layoutEditor.LayoutTurnout)1 LayoutTurntable (jmri.jmrit.display.layoutEditor.LayoutTurntable)1 LevelXing (jmri.jmrit.display.layoutEditor.LevelXing)1 Attribute (org.jdom2.Attribute)1