use of jmri.jmrit.display.layoutEditor.PositionablePoint in project JMRI by JMRI.
the class PointDetails method getSensor.
Sensor getSensor() {
if (getRefObject() == null) {
return null;
}
if ((getPanel() != null) && (!getPanel().isEditable()) && (sensor != null)) {
return sensor;
}
if (getRefObject() instanceof Sensor) {
setSensor((Sensor) getRefObject());
return (Sensor) getRefObject();
}
Object objLoc = getRefLocation();
Object objRef = getRefObject();
SignalHead head = null;
SignalMast mast = null;
String username = "";
String systemname = "";
Sensor foundSensor = null;
if (objRef instanceof SignalMast) {
mast = (SignalMast) objRef;
}
if (objRef instanceof SignalHead) {
head = (SignalHead) objRef;
username = head.getUserName();
systemname = head.getSystemName();
}
jmri.SensorManager sm = InstanceManager.sensorManagerInstance();
if (objLoc instanceof PositionablePoint) {
PositionablePoint p = (PositionablePoint) objLoc;
if (mast != null) {
if (p.getEastBoundSignalMast() == objRef) {
foundSensor = p.getEastBoundSensor();
} else if (p.getWestBoundSignalMast() == objRef) {
foundSensor = p.getWestBoundSensor();
}
} else if (head != null) {
if ((p.getEastBoundSignal().equals(username)) || p.getEastBoundSignal().equals(systemname)) {
foundSensor = p.getEastBoundSensor();
} else if ((p.getWestBoundSignal().equals(username)) || p.getWestBoundSignal().equals(systemname)) {
foundSensor = p.getWestBoundSensor();
}
}
} else if (objLoc instanceof LayoutTurnout) {
LayoutTurnout t = (LayoutTurnout) objLoc;
if (mast != null) {
if (t.getSignalAMast() == objRef) {
foundSensor = t.getSensorA();
} else if (t.getSignalBMast() == objRef) {
foundSensor = t.getSensorB();
} else if (t.getSignalCMast() == objRef) {
foundSensor = t.getSensorC();
} else if (t.getSignalDMast() == objRef) {
foundSensor = t.getSensorD();
}
}
if (head != null) {
if ((t.getSignalA1Name().equals(username)) || (t.getSignalA1Name().equals(systemname))) {
foundSensor = t.getSensorA();
} else if ((t.getSignalA2Name().equals(username)) || (t.getSignalA2Name().equals(systemname))) {
foundSensor = t.getSensorA();
} else if ((t.getSignalA3Name().equals(username)) || (t.getSignalA3Name().equals(systemname))) {
foundSensor = t.getSensorA();
} else if ((t.getSignalB1Name().equals(username)) || (t.getSignalB1Name().equals(systemname))) {
foundSensor = t.getSensorB();
} else if ((t.getSignalB2Name().equals(username)) || (t.getSignalB2Name().equals(systemname))) {
foundSensor = t.getSensorB();
} else if ((t.getSignalC1Name().equals(username)) || (t.getSignalC1Name().equals(systemname))) {
foundSensor = t.getSensorC();
} else if ((t.getSignalC2Name().equals(username)) || (t.getSignalC2Name().equals(systemname))) {
foundSensor = t.getSensorC();
} else if ((t.getSignalD1Name().equals(username)) || (t.getSignalD1Name().equals(systemname))) {
foundSensor = t.getSensorD();
} else if ((t.getSignalD2Name().equals(username)) || (t.getSignalD2Name().equals(systemname))) {
foundSensor = t.getSensorD();
}
}
} else if (objLoc instanceof LevelXing) {
LevelXing x = (LevelXing) objLoc;
if (mast != null) {
if (x.getSignalAMast() == objRef) {
foundSensor = x.getSensorA();
} else if (x.getSignalBMast() == objRef) {
foundSensor = x.getSensorB();
} else if (x.getSignalCMast() == objRef) {
foundSensor = x.getSensorC();
} else if (x.getSignalDMast() == objRef) {
foundSensor = x.getSensorD();
}
}
if (head != null) {
if ((x.getSignalAName().equals(username)) || (x.getSignalAName().equals(systemname))) {
foundSensor = x.getSensorA();
} else if ((x.getSignalBName().equals(username)) || (x.getSignalBName().equals(systemname))) {
foundSensor = x.getSensorB();
} else if ((x.getSignalCName().equals(username)) || (x.getSignalCName().equals(systemname))) {
foundSensor = x.getSensorC();
} else if ((x.getSignalDName().equals(username)) || (x.getSignalDName().equals(systemname))) {
foundSensor = x.getSensorD();
}
}
} else if (objLoc instanceof LayoutSlip) {
LayoutSlip sl = (LayoutSlip) objLoc;
if (mast != null) {
if (sl.getSignalAMast() == objRef) {
foundSensor = sl.getSensorA();
} else if (sl.getSignalBMast() == objRef) {
foundSensor = sl.getSensorB();
} else if (sl.getSignalCMast() == objRef) {
foundSensor = sl.getSensorC();
} else if (sl.getSignalDMast() == objRef) {
foundSensor = sl.getSensorD();
}
}
if (head != null) {
if ((sl.getSignalA1Name().equals(username)) || (sl.getSignalA1Name().equals(systemname))) {
foundSensor = sm.getSensor(sl.getSensorAName());
} else if ((sl.getSignalB1Name().equals(username)) || (sl.getSignalB1Name().equals(systemname))) {
foundSensor = sm.getSensor(sl.getSensorBName());
} else if ((sl.getSignalC1Name().equals(username)) || (sl.getSignalC1Name().equals(systemname))) {
foundSensor = sm.getSensor(sl.getSensorCName());
} else if ((sl.getSignalD1Name().equals(username)) || (sl.getSignalD1Name().equals(systemname))) {
foundSensor = sm.getSensor(sl.getSensorDName());
}
}
}
setSensor(foundSensor);
return foundSensor;
}
Aggregations