use of jmri.jmrit.display.layoutEditor.PositionablePoint in project JMRI by JMRI.
the class PositionablePointXml method load.
/**
* Load, starting with the layoutblock element, then all the value-icon
* pairs
*
* @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 attributes
String name = element.getAttribute("ident").getValue();
int type = PositionablePoint.ANCHOR;
double x = 0.0;
double y = 0.0;
try {
x = element.getAttribute("x").getFloatValue();
y = element.getAttribute("y").getFloatValue();
type = element.getAttribute("type").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert positionablepoint attribute");
}
// create the new PositionablePoint
PositionablePoint l = new PositionablePoint(name, type, new Point2D.Double(x, y), p);
// get remaining attributes
Attribute a = element.getAttribute("connect1name");
if (a != null) {
l.trackSegment1Name = a.getValue();
}
a = element.getAttribute("connect2name");
if (a != null) {
l.trackSegment2Name = a.getValue();
}
a = element.getAttribute("eastboundsignal");
if (a != null) {
l.setEastBoundSignal(a.getValue());
}
a = element.getAttribute("westboundsignal");
if (a != null) {
l.setWestBoundSignal(a.getValue());
}
a = element.getAttribute("eastboundsignalmast");
if (a != null) {
l.setEastBoundSignalMast(a.getValue());
}
a = element.getAttribute("westboundsignalmast");
if (a != null) {
l.setWestBoundSignalMast(a.getValue());
}
a = element.getAttribute("eastboundsensor");
if (a != null) {
l.setEastBoundSensor(a.getValue());
}
a = element.getAttribute("westboundsensor");
if (a != null) {
l.setWestBoundSensor(a.getValue());
}
if (type == PositionablePoint.EDGE_CONNECTOR && element.getAttribute("linkedpanel") != null && element.getAttribute("linkpointid") != null) {
String linkedEditorName = element.getAttribute("linkedpanel").getValue();
LayoutEditor linkedEditor = (LayoutEditor) jmri.jmrit.display.PanelMenu.instance().getEditorByName(linkedEditorName);
if (linkedEditor != null) {
String linkedPoint = element.getAttribute("linkpointid").getValue();
for (PositionablePoint point : linkedEditor.pointList) {
if (point.getType() == PositionablePoint.EDGE_CONNECTOR && point.getID().equals(linkedPoint)) {
point.setLinkedPoint(l);
l.setLinkedPoint(point);
break;
}
}
}
}
p.pointList.add(l);
}
use of jmri.jmrit.display.layoutEditor.PositionablePoint 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.PositionablePoint 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.PositionablePoint in project JMRI by JMRI.
the class PositionablePointXml method store.
/**
* Default implementation for storing the contents of a PositionablePoint
*
* @param o Object to store, of type PositionablePoint
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
PositionablePoint p = (PositionablePoint) o;
Element element = new Element("positionablepoint");
// include attributes
element.setAttribute("ident", p.getID());
element.setAttribute("type", "" + p.getType());
Point2D coords = p.getCoords();
element.setAttribute("x", "" + coords.getX());
element.setAttribute("y", "" + coords.getY());
if (p.getConnect1() != null) {
element.setAttribute("connect1name", p.getConnect1().getID());
}
if (p.getConnect2() != null) {
element.setAttribute("connect2name", p.getConnect2().getID());
}
if (p.getEastBoundSignal().length() > 0) {
element.setAttribute("eastboundsignal", p.getEastBoundSignal());
}
if (p.getWestBoundSignal().length() > 0) {
element.setAttribute("westboundsignal", p.getWestBoundSignal());
}
if (p.getEastBoundSignalMastName().length() > 0) {
element.setAttribute("eastboundsignalmast", p.getEastBoundSignalMastName());
}
if (p.getWestBoundSignalMastName().length() > 0) {
element.setAttribute("westboundsignalmast", p.getWestBoundSignalMastName());
}
if (p.getEastBoundSensorName().length() > 0) {
element.setAttribute("eastboundsensor", p.getEastBoundSensorName());
}
if (p.getWestBoundSensorName().length() > 0) {
element.setAttribute("westboundsensor", p.getWestBoundSensorName());
}
if (p.getType() == PositionablePoint.EDGE_CONNECTOR) {
element.setAttribute("linkedpanel", p.getLinkEditorName());
element.setAttribute("linkpointid", p.getLinkedPointId());
}
element.setAttribute("class", getClass().getName());
return element;
}
use of jmri.jmrit.display.layoutEditor.PositionablePoint 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());
}
}
Aggregations