use of jmri.jmrit.display.layoutEditor.LevelXing in project JMRI by JMRI.
the class AutoAllocate method willLevelXingsBlockTrain.
private boolean willLevelXingsBlockTrain(ActiveTrain at) {
// returns true if any LevelXings in _levelXingList will block the specified train
if (at == null) {
log.error("null argument on entry to 'willLevelXingsBlockTrain'");
// returns true to be safe
return true;
}
if (_levelXingList.size() <= 0) {
return false;
}
for (int i = 0; i < _levelXingList.size(); i++) {
LevelXing lx = _levelXingList.get(i);
Block bAC = lx.getLayoutBlockAC().getBlock();
Block bBD = lx.getLayoutBlockBD().getBlock();
if (at.getTransit().containsBlock(bAC) || at.getTransit().containsBlock(bBD)) {
return true;
}
}
return false;
}
use of jmri.jmrit.display.layoutEditor.LevelXing in project JMRI by JMRI.
the class LevelXingXml method store.
/**
* Default implementation for storing the contents of a LevelXing
*
* @param o Object to store, of type LevelXing
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
LevelXing p = (LevelXing) o;
Element element = new Element("levelxing");
// include attributes
element.setAttribute("ident", p.getID());
if (p.getBlockNameAC().length() > 0) {
element.setAttribute("blocknameac", p.getBlockNameAC());
}
if (p.getBlockNameBD().length() > 0) {
element.setAttribute("blocknamebd", p.getBlockNameBD());
}
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.getSignalAName().length() > 0) {
element.setAttribute("signalaname", p.getSignalAName());
}
if (p.getSignalBName().length() > 0) {
element.setAttribute("signalbname", p.getSignalBName());
}
if (p.getSignalCName().length() > 0) {
element.setAttribute("signalcname", p.getSignalCName());
}
if (p.getSignalDName().length() > 0) {
element.setAttribute("signaldname", p.getSignalDName());
}
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());
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("class", getClass().getName());
return element;
}
use of jmri.jmrit.display.layoutEditor.LevelXing in project JMRI by JMRI.
the class LevelXingXml method load.
/**
* Load, starting with the levelxing element, then all the other data
*
* @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 center point
String name = element.getAttribute("ident").getValue();
double x = 0.0;
double y = 0.0;
try {
x = element.getAttribute("xcen").getFloatValue();
y = element.getAttribute("ycen").getFloatValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert levelxing center attribute");
}
// create the new LevelXing
LevelXing l = new LevelXing(name, new Point2D.Double(x, y), p);
// get remaining attributes
Attribute a = element.getAttribute("blocknameac");
if (a != null) {
l.tBlockNameAC = a.getValue();
}
a = element.getAttribute("blocknamebd");
if (a != null) {
l.tBlockNameBD = a.getValue();
}
a = element.getAttribute("connectaname");
if (a != null) {
l.connectAName = a.getValue();
}
a = element.getAttribute("connectbname");
if (a != null) {
l.connectBName = a.getValue();
}
a = element.getAttribute("connectcname");
if (a != null) {
l.connectCName = a.getValue();
}
a = element.getAttribute("connectdname");
if (a != null) {
l.connectDName = a.getValue();
}
a = element.getAttribute("signalaname");
if (a != null) {
l.setSignalAName(a.getValue());
}
a = element.getAttribute("signalbname");
if (a != null) {
l.setSignalBName(a.getValue());
}
a = element.getAttribute("signalcname");
if (a != null) {
l.setSignalCName(a.getValue());
}
a = element.getAttribute("signaldname");
if (a != null) {
l.setSignalDName(a.getValue());
}
try {
x = element.getAttribute("xa").getFloatValue();
y = element.getAttribute("ya").getFloatValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert levelxing a coords attribute");
}
l.setCoordsA(new Point2D.Double(x, y));
try {
x = element.getAttribute("xb").getFloatValue();
y = element.getAttribute("yb").getFloatValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert levelxing b coords attribute");
}
l.setCoordsB(new Point2D.Double(x, y));
if (element.getChild("signalAMast") != null) {
String mast = element.getChild("signalAMast").getText();
if (mast != null && !mast.equals("")) {
l.setSignalAMast(mast);
}
}
if (element.getChild("signalBMast") != null) {
String mast = element.getChild("signalBMast").getText();
if (mast != null && !mast.equals("")) {
l.setSignalBMast(mast);
}
}
if (element.getChild("signalCMast") != null) {
String mast = element.getChild("signalCMast").getText();
if (mast != null && !mast.equals("")) {
l.setSignalCMast(mast);
}
}
if (element.getChild("signalDMast") != null) {
String mast = element.getChild("signalDMast").getText();
if (mast != null && !mast.equals("")) {
l.setSignalDMast(mast);
}
}
if (element.getChild("sensorA") != null) {
String sensor = element.getChild("sensorA").getText();
if (sensor != null && !sensor.equals("")) {
l.setSensorAName(sensor);
}
}
if (element.getChild("sensorB") != null) {
String sensor = element.getChild("sensorB").getText();
if (sensor != null && !sensor.equals("")) {
l.setSensorBName(sensor);
}
}
if (element.getChild("sensorC") != null) {
String sensor = element.getChild("sensorC").getText();
if (sensor != null && !sensor.equals("")) {
l.setSensorCName(sensor);
}
}
if (element.getChild("sensorD") != null) {
String sensor = element.getChild("sensorD").getText();
if (sensor != null && !sensor.equals("")) {
l.setSensorDName(sensor);
}
}
p.xingList.add(l);
}
use of jmri.jmrit.display.layoutEditor.LevelXing in project JMRI by JMRI.
the class PointDetails method getSignal.
NamedBean getSignal() {
if ((getPanel() != null) && (!getPanel().isEditable()) && (getSignalMast() != null)) {
return getSignalMast();
}
if ((getPanel() != null) && (!getPanel().isEditable()) && (getSignalHead() != null)) {
return getSignalHead();
}
jmri.SignalHeadManager sh = InstanceManager.getDefault(jmri.SignalHeadManager.class);
NamedBean signal = null;
if (getRefObject() == null) {
log.error("Signal not found at point");
return null;
} else if (getRefObject() instanceof SignalMast) {
signal = getRefObject();
setSignalMast(((SignalMast) getRefObject()));
return signal;
} else if (getRefObject() instanceof SignalHead) {
signal = getRefObject();
setSignalHead(((SignalHead) getRefObject()));
return signal;
}
Sensor sen = (Sensor) getRefObject();
log.debug("looking at Sensor " + sen.getDisplayName());
if (getRefLocation() instanceof PositionablePoint) {
PositionablePoint p = (PositionablePoint) getRefLocation();
if (p.getEastBoundSensor() == sen) {
if (p.getEastBoundSignalMast() != null) {
signal = p.getEastBoundSignalMast();
} else if (!p.getEastBoundSignal().equals("")) {
signal = sh.getSignalHead(p.getEastBoundSignal());
}
} else if (p.getWestBoundSensor() == sen) {
if (p.getWestBoundSignalMast() != null) {
signal = p.getWestBoundSignalMast();
} else if (!p.getWestBoundSignal().equals("")) {
signal = sh.getSignalHead(p.getWestBoundSignal());
}
}
} else if (getRefLocation() instanceof LayoutTurnout) {
LayoutTurnout t = (LayoutTurnout) getRefLocation();
if (t.getSensorA() == sen) {
if (t.getSignalAMast() != null) {
signal = t.getSignalAMast();
} else if (!t.getSignalA1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalA1Name());
}
} else if (t.getSensorB() == sen) {
if (t.getSignalBMast() != null) {
signal = t.getSignalBMast();
} else if (!t.getSignalB1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalB1Name());
}
} else if (t.getSensorC() == sen) {
if (t.getSignalCMast() != null) {
signal = t.getSignalCMast();
} else if (!t.getSignalC1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalC1Name());
}
} else if (t.getSensorD() == sen) {
if (t.getSignalDMast() != null) {
signal = t.getSignalDMast();
} else if (!t.getSignalD1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalD1Name());
}
}
} else if (getRefLocation() instanceof LevelXing) {
LevelXing x = (LevelXing) getRefLocation();
if (x.getSensorA() == sen) {
if (x.getSignalAMast() != null) {
signal = x.getSignalAMast();
} else if (!x.getSignalAName().equals("")) {
signal = sh.getSignalHead(x.getSignalAName());
}
} else if (x.getSensorB() == sen) {
if (x.getSignalBMast() != null) {
signal = x.getSignalBMast();
} else if (!x.getSignalBName().equals("")) {
signal = sh.getSignalHead(x.getSignalBName());
}
} else if (x.getSensorC() == sen) {
if (x.getSignalCMast() != null) {
signal = x.getSignalCMast();
} else if (!x.getSignalCName().equals("")) {
signal = sh.getSignalHead(x.getSignalCName());
}
} else if (x.getSensorD() == sen) {
if (x.getSignalDMast() != null) {
signal = x.getSignalDMast();
} else if (!x.getSignalDName().equals("")) {
signal = sh.getSignalHead(x.getSignalDName());
}
}
} else if (getRefLocation() instanceof LayoutSlip) {
LayoutSlip t = (LayoutSlip) getRefLocation();
if (t.getSensorA() == sen) {
if (t.getSignalAMast() != null) {
signal = t.getSignalAMast();
} else if (!t.getSignalA1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalA1Name());
}
} else if (t.getSensorB() == sen) {
if (t.getSignalBMast() != null) {
signal = t.getSignalBMast();
} else if (!t.getSignalB1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalB1Name());
}
} else if (t.getSensorC() == sen) {
if (t.getSignalCMast() != null) {
signal = t.getSignalCMast();
} else if (!t.getSignalC1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalC1Name());
}
} else if (t.getSensorD() == sen) {
if (t.getSignalDMast() != null) {
signal = t.getSignalDMast();
} else if (!t.getSignalD1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalD1Name());
}
}
}
if (signal instanceof SignalMast) {
setSignalMast(((SignalMast) signal));
} else if (signal instanceof SignalHead) {
setSignalHead(((SignalHead) signal));
}
return signal;
}
use of jmri.jmrit.display.layoutEditor.LevelXing 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;
}
Aggregations