Search in sources :

Example 6 with TrackSegment

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

the class Section method getDirectionXoverTurnout.

/**
     * Returns EntryPoint.FORWARD if proceeding from A to B (or D to C) is
     * movement in the forward direction. Returns EntryPoint.REVERSE if
     * proceeding from A to B (or D to C) 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 getDirectionXoverTurnout(LayoutTurnout 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(bBlock.getBlock()))) {
        LayoutBlock exBlock = null;
        if (aBlock == bBlock) {
            if ((t.getTurnoutType() == LayoutTurnout.DOUBLE_XOVER) && (cBlock == dBlock)) {
                exBlock = cBlock;
            }
        }
        if (exBlock != null) {
            // set direction by tracking from a or 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.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, Turnout.CLOSED);
                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 Turnout " + t.getTurnout().getSystemName() + " in Section " + getSystemName() + ".");
            }
            return dir;
        }
        if ((aBlock != bBlock) && containsBlock(aBlock.getBlock()) && containsBlock(bBlock.getBlock())) {
            if (getBlockSequenceNumber(aBlock.getBlock()) < getBlockSequenceNumber(bBlock.getBlock())) {
                return EntryPoint.FORWARD;
            } else {
                return EntryPoint.REVERSE;
            }
        }
        if (containsBlock(aBlock.getBlock()) && (!containsBlock(bBlock.getBlock()))) {
            int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, bBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
        if (containsBlock(bBlock.getBlock()) && (!containsBlock(aBlock.getBlock()))) {
            int dir = checkLists(mForwardEntryPoints, mReverseEntryPoints, aBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
        if ((t.getTurnoutType() != LayoutTurnout.LH_XOVER) && containsBlock(aBlock.getBlock()) && (!containsBlock(cBlock.getBlock()))) {
            int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, cBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
        if ((t.getTurnoutType() != LayoutTurnout.RH_XOVER) && containsBlock(bBlock.getBlock()) && (!containsBlock(dBlock.getBlock()))) {
            int dir = checkLists(mForwardEntryPoints, mReverseEntryPoints, dBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
    }
    if ((containsBlock(dBlock.getBlock())) || (containsBlock(cBlock.getBlock()))) {
        LayoutBlock exBlock = null;
        if (dBlock == cBlock) {
            if ((t.getTurnoutType() == LayoutTurnout.DOUBLE_XOVER) && (bBlock == 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.TURNOUT_D, (TrackSegment) t.getConnectD(), false, Turnout.CLOSED);
            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_C, (TrackSegment) t.getConnectC(), false, Turnout.CLOSED);
                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 Turnout " + t.getTurnout().getSystemName() + " in Section " + getSystemName() + ".");
            }
            return dir;
        }
        if ((dBlock != cBlock) && containsBlock(dBlock.getBlock()) && containsBlock(cBlock.getBlock())) {
            if (getBlockSequenceNumber(dBlock.getBlock()) < getBlockSequenceNumber(cBlock.getBlock())) {
                return EntryPoint.FORWARD;
            } else {
                return EntryPoint.REVERSE;
            }
        }
        if (containsBlock(dBlock.getBlock()) && (!containsBlock(cBlock.getBlock()))) {
            int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, cBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
        if (containsBlock(cBlock.getBlock()) && (!containsBlock(dBlock.getBlock()))) {
            int dir = checkLists(mForwardEntryPoints, mReverseEntryPoints, dBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
        if ((t.getTurnoutType() != LayoutTurnout.RH_XOVER) && containsBlock(dBlock.getBlock()) && (!containsBlock(bBlock.getBlock()))) {
            int dir = checkLists(mReverseEntryPoints, mForwardEntryPoints, bBlock);
            if (dir != EntryPoint.UNKNOWN) {
                return dir;
            }
        }
        if ((t.getTurnoutType() != LayoutTurnout.LH_XOVER) && containsBlock(cBlock.getBlock()) && (!containsBlock(aBlock.getBlock()))) {
            int dir = checkLists(mForwardEntryPoints, mReverseEntryPoints, aBlock);
            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)

Example 7 with TrackSegment

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

the class LayoutTurntableXml method store.

/**
     * Default implementation for storing the contents of a LayoutTurntable
     *
     * @param o Object to store, of type LayoutTurntable
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    LayoutTurntable p = (LayoutTurntable) o;
    Element element = new Element("layoutturntable");
    boolean turnoutControl = p.isTurnoutControlled();
    // include attributes
    element.setAttribute("ident", p.getID());
    element.setAttribute("radius", "" + p.getRadius());
    Point2D coords = p.getCoordsCenter();
    element.setAttribute("xcen", "" + coords.getX());
    element.setAttribute("ycen", "" + coords.getY());
    element.setAttribute("turnoutControlled", "" + (turnoutControl ? "yes" : "no"));
    element.setAttribute("class", getClass().getName());
    // add ray tracks
    for (int i = 0; i < p.getNumberRays(); i++) {
        Element rElem = new Element("raytrack");
        rElem.setAttribute("angle", "" + p.getRayAngle(i));
        TrackSegment t = p.getRayConnectOrdered(i);
        if (t != null) {
            rElem.setAttribute("connectname", t.getID());
        }
        rElem.setAttribute("index", "" + p.getRayIndex(i));
        if (turnoutControl && p.getRayTurnoutName(i) != null) {
            rElem.setAttribute("turnout", p.getRayTurnoutName(i));
            if (p.getRayTurnoutState(i) == Turnout.THROWN) {
                rElem.setAttribute("turnoutstate", "thrown");
            } else {
                rElem.setAttribute("turnoutstate", "closed");
            }
        }
        element.addContent(rElem);
    }
    return element;
}
Also used : Point2D(java.awt.geom.Point2D) Element(org.jdom2.Element) LayoutTurntable(jmri.jmrit.display.layoutEditor.LayoutTurntable) 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