use of jmri.jmrit.display.layoutEditor.LayoutBlockManager in project JMRI by JMRI.
the class Section method setAlternateColorFromActiveBlock.
/**
* This function sets/resets the display to use alternate color for
* unoccupied blocks in this section. If the section already contains an
* active block, then the alternative colour will be set from the active
* block, if no active block is found or we are clearing the alternative
* colour then all the blocks in the section will be set. If Layout Editor
* panel is not present, Layout Blocks will not be present, and nothing will
* be set.
*
* @param set true to use alternate unoccupied color; false otherwise
*/
public void setAlternateColorFromActiveBlock(boolean set) {
LayoutBlockManager lbm = InstanceManager.getDefault(LayoutBlockManager.class);
boolean beenSet = false;
if (!set || getState() == FREE || getState() == UNKNOWN) {
setAlternateColor(set);
} else if (getState() == FORWARD) {
for (int i = 0; i < mBlockEntries.size(); i++) {
Block b = mBlockEntries.get(i);
if (b.getState() == Block.OCCUPIED) {
beenSet = true;
}
if (beenSet) {
LayoutBlock lb = lbm.getByUserName(b.getUserName());
if (lb != null) {
lb.setUseExtraColor(set);
}
}
}
} else if (getState() == REVERSE) {
for (int i = mBlockEntries.size(); i < 0; i--) {
Block b = mBlockEntries.get(i);
if (b.getState() == Block.OCCUPIED) {
beenSet = true;
}
if (beenSet) {
LayoutBlock lb = lbm.getByUserName(b.getUserName());
if (lb != null) {
lb.setUseExtraColor(set);
}
}
}
}
if (!beenSet) {
setAlternateColor(set);
}
}
use of jmri.jmrit.display.layoutEditor.LayoutBlockManager in project JMRI by JMRI.
the class LayoutBlockManagerXml method replaceLayoutBlockManager.
/**
* Replace the current LayoutBlockManager, if there is one, with one newly
* created during a load operation. This is skipped if they are of the same
* absolute type.
*/
protected void replaceLayoutBlockManager() {
if (InstanceManager.getDefault(LayoutBlockManager.class).getClass().getName().equals(LayoutBlockManager.class.getName())) {
return;
}
// if old manager exists, remove it from configuration process
if (InstanceManager.getNullableDefault(LayoutBlockManager.class) != null) {
InstanceManager.getDefault(jmri.ConfigureManager.class).deregister(InstanceManager.getDefault(LayoutBlockManager.class));
}
// register new one with InstanceManager
LayoutBlockManager pManager = LayoutBlockManager.instance();
InstanceManager.store(pManager, jmri.jmrit.display.layoutEditor.LayoutBlockManager.class);
// register new one for configuration
ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cm != null) {
cm.registerConfig(pManager, jmri.Manager.LAYOUTBLOCKS);
}
}
use of jmri.jmrit.display.layoutEditor.LayoutBlockManager in project JMRI by JMRI.
the class LayoutBlockManagerXml method loadLayoutBlocks.
/**
* Utility method to load the individual LayoutBlock objects. If there's no
* additional info needed for a specific layoutblock type, invoke this with
* the parent of the set of layoutblock elements.
*
* @param layoutblocks Element containing the layoutblock elements to load.
*/
public void loadLayoutBlocks(Element layoutblocks) {
LayoutBlockManager tm = InstanceManager.getDefault(LayoutBlockManager.class);
if (layoutblocks.getAttribute("blockrouting") != null) {
if (layoutblocks.getAttribute("blockrouting").getValue().equals("yes")) {
tm.enableAdvancedRouting(true);
}
}
if (layoutblocks.getAttribute("routingStablisedSensor") != null) {
try {
tm.setStabilisedSensor(layoutblocks.getAttribute("routingStablisedSensor").getValue());
} catch (jmri.JmriException e) {
}
}
List<Element> layoutblockList = layoutblocks.getChildren("layoutblock");
if (log.isDebugEnabled()) {
log.debug("Found " + layoutblockList.size() + " layoutblocks");
}
for (int i = 0; i < layoutblockList.size(); i++) {
String sysName = getSystemName(layoutblockList.get(i));
if (sysName == null) {
log.warn("unexpected null in systemName " + ((layoutblockList.get(i))) + " " + ((layoutblockList.get(i))).getAttributes());
break;
}
String userName = getUserName(layoutblockList.get(i));
LayoutBlock b = tm.createNewLayoutBlock(sysName, userName);
// load common parts
loadCommon(b, layoutblockList.get(i));
if (b != null) {
// set attributes
Color color = ColorUtil.stringToColor(((layoutblockList.get(i))).getAttribute("trackcolor").getValue());
b.setBlockTrackColor(color);
color = ColorUtil.stringToColor(((layoutblockList.get(i))).getAttribute("occupiedcolor").getValue());
b.setBlockOccupiedColor(color);
Attribute a = ((layoutblockList.get(i))).getAttribute("extracolor");
if (a != null) {
b.setBlockExtraColor(ColorUtil.stringToColor(a.getValue()));
}
a = ((layoutblockList.get(i))).getAttribute("occupancysensor");
if (a != null) {
b.setOccupancySensorName(a.getValue());
}
a = ((layoutblockList.get(i))).getAttribute("memory");
if (a != null) {
b.setMemoryName(a.getValue());
}
a = ((layoutblockList.get(i))).getAttribute("occupancysensorsense");
int sense = Sensor.ACTIVE;
try {
sense = ((layoutblockList.get(i))).getAttribute("occupiedsense").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert occupiedsense attribute");
}
b.setOccupiedSense(sense);
if (((layoutblockList.get(i))).getChild("metric") != null) {
String stMetric = ((layoutblockList.get(i))).getChild("metric").getText();
try {
b.setBlockMetric(Integer.valueOf(stMetric));
} catch (java.lang.NumberFormatException e) {
log.error("failed to convert metric attribute for block " + b.getDisplayName());
}
}
}
}
}
use of jmri.jmrit.display.layoutEditor.LayoutBlockManager in project JMRI by JMRI.
the class InstanceManagerTest method testLayoutBlockManager.
//
// Tests of individual types, to make sure they
// properly create defaults
//
public void testLayoutBlockManager() {
LayoutBlockManager obj = InstanceManager.getDefault(LayoutBlockManager.class);
Assert.assertNotNull(obj);
Assert.assertEquals(obj, InstanceManager.getDefault(LayoutBlockManager.class));
Assert.assertEquals(obj, InstanceManager.getDefault(LayoutBlockManager.class));
Assert.assertEquals(obj, InstanceManager.getDefault(LayoutBlockManager.class));
}
use of jmri.jmrit.display.layoutEditor.LayoutBlockManager 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