use of jmri.jmrit.display.layoutEditor.LayoutTurnout 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;
}
use of jmri.jmrit.display.layoutEditor.LayoutTurnout in project JMRI by JMRI.
the class LayoutTurnoutXml method store.
/**
* Default implementation for storing the contents of a LayoutTurnout
*
* @param o Object to store, of type LayoutTurnout
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
LayoutTurnout p = (LayoutTurnout) o;
Element element = new Element("layoutturnout");
// include attributes
element.setAttribute("ident", p.getName());
if (p.getTurnoutName().length() > 0) {
element.setAttribute("turnoutname", p.getTurnoutName());
}
if (p.getSecondTurnoutName().length() > 0) {
element.setAttribute("secondturnoutname", p.getSecondTurnoutName());
}
if (p.getBlockName().length() > 0) {
element.setAttribute("blockname", p.getBlockName());
}
if (p.getBlockBName().length() > 0) {
element.setAttribute("blockbname", p.getBlockBName());
}
if (p.getBlockCName().length() > 0) {
element.setAttribute("blockcname", p.getBlockCName());
}
if (p.getBlockDName().length() > 0) {
element.setAttribute("blockdname", p.getBlockDName());
}
element.setAttribute("type", "" + p.getTurnoutType());
if (p.isHidden()) {
element.setAttribute("hidden", "" + (p.isHidden() ? "yes" : "no"));
}
if (p.getConnectA() != null) {
element.setAttribute("connectaname", ((TrackSegment) p.getConnectA()).getID());
}
if (p.getConnectB() != null) {
element.setAttribute("connectbname", ((TrackSegment) p.getConnectB()).getID());
}
if (p.getConnectC() != null) {
element.setAttribute("connectcname", ((TrackSegment) p.getConnectC()).getID());
}
if (p.getConnectD() != null) {
element.setAttribute("connectdname", ((TrackSegment) p.getConnectD()).getID());
}
if (p.getSignalA1Name().length() > 0) {
element.setAttribute("signala1name", p.getSignalA1Name());
}
if (p.getSignalA2Name().length() > 0) {
element.setAttribute("signala2name", p.getSignalA2Name());
}
if (p.getSignalA3Name().length() > 0) {
element.setAttribute("signala3name", p.getSignalA3Name());
}
if (p.getSignalB1Name().length() > 0) {
element.setAttribute("signalb1name", p.getSignalB1Name());
}
if (p.getSignalB2Name().length() > 0) {
element.setAttribute("signalb2name", p.getSignalB2Name());
}
if (p.getSignalC1Name().length() > 0) {
element.setAttribute("signalc1name", p.getSignalC1Name());
}
if (p.getSignalC2Name().length() > 0) {
element.setAttribute("signalc2name", p.getSignalC2Name());
}
if (p.getSignalD1Name().length() > 0) {
element.setAttribute("signald1name", p.getSignalD1Name());
}
if (p.getSignalD2Name().length() > 0) {
element.setAttribute("signald2name", p.getSignalD2Name());
}
if (p.getLinkedTurnoutName().length() > 0) {
element.setAttribute("linkedturnoutname", p.getLinkedTurnoutName());
element.setAttribute("linktype", "" + p.getLinkType());
}
if (p.getSignalAMastName().length() > 0) {
element.addContent(new Element("signalAMast").addContent(p.getSignalAMastName()));
}
if (p.getSignalBMastName().length() > 0) {
element.addContent(new Element("signalBMast").addContent(p.getSignalBMastName()));
}
if (p.getSignalCMastName().length() > 0) {
element.addContent(new Element("signalCMast").addContent(p.getSignalCMastName()));
}
if (p.getSignalDMastName().length() > 0) {
element.addContent(new Element("signalDMast").addContent(p.getSignalDMastName()));
}
if (p.getSensorAName().length() > 0) {
element.addContent(new Element("sensorA").addContent(p.getSensorAName()));
}
if (p.getSensorBName().length() > 0) {
element.addContent(new Element("sensorB").addContent(p.getSensorBName()));
}
if (p.getSensorCName().length() > 0) {
element.addContent(new Element("sensorC").addContent(p.getSensorCName()));
}
if (p.getSensorDName().length() > 0) {
element.addContent(new Element("sensorD").addContent(p.getSensorDName()));
}
element.setAttribute("continuing", "" + p.getContinuingSense());
element.setAttribute("disabled", "" + (p.isDisabled() ? "yes" : "no"));
element.setAttribute("disableWhenOccupied", "" + (p.isDisabledWhenOccupied() ? "yes" : "no"));
Point2D coords = p.getCoordsCenter();
element.setAttribute("xcen", "" + coords.getX());
element.setAttribute("ycen", "" + coords.getY());
coords = p.getCoordsA();
element.setAttribute("xa", "" + coords.getX());
element.setAttribute("ya", "" + coords.getY());
coords = p.getCoordsB();
element.setAttribute("xb", "" + coords.getX());
element.setAttribute("yb", "" + coords.getY());
coords = p.getCoordsC();
element.setAttribute("xc", "" + coords.getX());
element.setAttribute("yc", "" + coords.getY());
coords = p.getCoordsD();
element.setAttribute("xd", "" + coords.getX());
element.setAttribute("yd", "" + coords.getY());
element.setAttribute("ver", "" + p.getVersion());
element.setAttribute("class", getClass().getName());
return element;
}
use of jmri.jmrit.display.layoutEditor.LayoutTurnout in project JMRI by JMRI.
the class AddEntryExitPairPanel method selectPointsFromPanel.
private void selectPointsFromPanel() {
if (selectPanel.getSelectedIndex() == -1) {
return;
}
if (panel == panels.get(selectPanel.getSelectedIndex())) {
return;
}
panel = panels.get(selectPanel.getSelectedIndex());
fromPoint.removeAllItems();
toPoint.removeAllItems();
for (PositionablePoint pp : panel.pointList) {
addPointToCombo(pp.getWestBoundSignalMastName(), pp.getWestBoundSensorName());
addPointToCombo(pp.getEastBoundSignalMastName(), pp.getEastBoundSensorName());
}
for (LayoutTurnout t : panel.turnoutList) {
addPointToCombo(t.getSignalAMastName(), t.getSensorAName());
addPointToCombo(t.getSignalBMastName(), t.getSensorBName());
addPointToCombo(t.getSignalCMastName(), t.getSensorCName());
addPointToCombo(t.getSignalDMastName(), t.getSensorDName());
}
for (LevelXing xing : panel.xingList) {
addPointToCombo(xing.getSignalAMastName(), xing.getSensorAName());
addPointToCombo(xing.getSignalBMastName(), xing.getSensorBName());
addPointToCombo(xing.getSignalCMastName(), xing.getSensorCName());
addPointToCombo(xing.getSignalDMastName(), xing.getSensorDName());
}
for (LayoutSlip slip : panel.slipList) {
addPointToCombo(slip.getSignalAMastName(), slip.getSensorAName());
addPointToCombo(slip.getSignalBMastName(), slip.getSensorBName());
addPointToCombo(slip.getSignalCMastName(), slip.getSensorCName());
addPointToCombo(slip.getSignalDMastName(), slip.getSensorDName());
}
}
use of jmri.jmrit.display.layoutEditor.LayoutTurnout in project JMRI by JMRI.
the class PointDetails method getSensor.
Sensor getSensor() {
if (getRefObject() == null) {
return null;
}
if ((getPanel() != null) && (!getPanel().isEditable()) && (sensor != null)) {
return sensor;
}
if (getRefObject() instanceof Sensor) {
setSensor((Sensor) getRefObject());
return (Sensor) getRefObject();
}
Object objLoc = getRefLocation();
Object objRef = getRefObject();
SignalHead head = null;
SignalMast mast = null;
String username = "";
String systemname = "";
Sensor foundSensor = null;
if (objRef instanceof SignalMast) {
mast = (SignalMast) objRef;
}
if (objRef instanceof SignalHead) {
head = (SignalHead) objRef;
username = head.getUserName();
systemname = head.getSystemName();
}
jmri.SensorManager sm = InstanceManager.sensorManagerInstance();
if (objLoc instanceof PositionablePoint) {
PositionablePoint p = (PositionablePoint) objLoc;
if (mast != null) {
if (p.getEastBoundSignalMast() == objRef) {
foundSensor = p.getEastBoundSensor();
} else if (p.getWestBoundSignalMast() == objRef) {
foundSensor = p.getWestBoundSensor();
}
} else if (head != null) {
if ((p.getEastBoundSignal().equals(username)) || p.getEastBoundSignal().equals(systemname)) {
foundSensor = p.getEastBoundSensor();
} else if ((p.getWestBoundSignal().equals(username)) || p.getWestBoundSignal().equals(systemname)) {
foundSensor = p.getWestBoundSensor();
}
}
} else if (objLoc instanceof LayoutTurnout) {
LayoutTurnout t = (LayoutTurnout) objLoc;
if (mast != null) {
if (t.getSignalAMast() == objRef) {
foundSensor = t.getSensorA();
} else if (t.getSignalBMast() == objRef) {
foundSensor = t.getSensorB();
} else if (t.getSignalCMast() == objRef) {
foundSensor = t.getSensorC();
} else if (t.getSignalDMast() == objRef) {
foundSensor = t.getSensorD();
}
}
if (head != null) {
if ((t.getSignalA1Name().equals(username)) || (t.getSignalA1Name().equals(systemname))) {
foundSensor = t.getSensorA();
} else if ((t.getSignalA2Name().equals(username)) || (t.getSignalA2Name().equals(systemname))) {
foundSensor = t.getSensorA();
} else if ((t.getSignalA3Name().equals(username)) || (t.getSignalA3Name().equals(systemname))) {
foundSensor = t.getSensorA();
} else if ((t.getSignalB1Name().equals(username)) || (t.getSignalB1Name().equals(systemname))) {
foundSensor = t.getSensorB();
} else if ((t.getSignalB2Name().equals(username)) || (t.getSignalB2Name().equals(systemname))) {
foundSensor = t.getSensorB();
} else if ((t.getSignalC1Name().equals(username)) || (t.getSignalC1Name().equals(systemname))) {
foundSensor = t.getSensorC();
} else if ((t.getSignalC2Name().equals(username)) || (t.getSignalC2Name().equals(systemname))) {
foundSensor = t.getSensorC();
} else if ((t.getSignalD1Name().equals(username)) || (t.getSignalD1Name().equals(systemname))) {
foundSensor = t.getSensorD();
} else if ((t.getSignalD2Name().equals(username)) || (t.getSignalD2Name().equals(systemname))) {
foundSensor = t.getSensorD();
}
}
} else if (objLoc instanceof LevelXing) {
LevelXing x = (LevelXing) objLoc;
if (mast != null) {
if (x.getSignalAMast() == objRef) {
foundSensor = x.getSensorA();
} else if (x.getSignalBMast() == objRef) {
foundSensor = x.getSensorB();
} else if (x.getSignalCMast() == objRef) {
foundSensor = x.getSensorC();
} else if (x.getSignalDMast() == objRef) {
foundSensor = x.getSensorD();
}
}
if (head != null) {
if ((x.getSignalAName().equals(username)) || (x.getSignalAName().equals(systemname))) {
foundSensor = x.getSensorA();
} else if ((x.getSignalBName().equals(username)) || (x.getSignalBName().equals(systemname))) {
foundSensor = x.getSensorB();
} else if ((x.getSignalCName().equals(username)) || (x.getSignalCName().equals(systemname))) {
foundSensor = x.getSensorC();
} else if ((x.getSignalDName().equals(username)) || (x.getSignalDName().equals(systemname))) {
foundSensor = x.getSensorD();
}
}
} else if (objLoc instanceof LayoutSlip) {
LayoutSlip sl = (LayoutSlip) objLoc;
if (mast != null) {
if (sl.getSignalAMast() == objRef) {
foundSensor = sl.getSensorA();
} else if (sl.getSignalBMast() == objRef) {
foundSensor = sl.getSensorB();
} else if (sl.getSignalCMast() == objRef) {
foundSensor = sl.getSensorC();
} else if (sl.getSignalDMast() == objRef) {
foundSensor = sl.getSensorD();
}
}
if (head != null) {
if ((sl.getSignalA1Name().equals(username)) || (sl.getSignalA1Name().equals(systemname))) {
foundSensor = sm.getSensor(sl.getSensorAName());
} else if ((sl.getSignalB1Name().equals(username)) || (sl.getSignalB1Name().equals(systemname))) {
foundSensor = sm.getSensor(sl.getSensorBName());
} else if ((sl.getSignalC1Name().equals(username)) || (sl.getSignalC1Name().equals(systemname))) {
foundSensor = sm.getSensor(sl.getSensorCName());
} else if ((sl.getSignalD1Name().equals(username)) || (sl.getSignalD1Name().equals(systemname))) {
foundSensor = sm.getSensor(sl.getSensorDName());
}
}
}
setSensor(foundSensor);
return foundSensor;
}
Aggregations