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;
}
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;
}
Aggregations