use of jmri.SignalMast 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;
}
use of jmri.SignalMast in project JMRI by JMRI.
the class DefaultSignalMastManagerXml method store.
/**
* Default implementation for storing the contents of a
* DefaultSignalMastManager
*
* @param o Object to store
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
DefaultSignalMastManager m = (DefaultSignalMastManager) o;
Element element = new Element("signalmasts");
element.setAttribute("class", this.getClass().getName());
if (m != null) {
// include contents
List<String> names = m.getSystemNameList();
for (int i = 0; i < names.size(); i++) {
//Element e = new Element("signalmast");
SignalMast p = m.getSignalMast(names.get(i));
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(p);
if (e != null) {
element.addContent(e);
}
} catch (Exception ex) {
log.error("Error storing signalmast: {}", ex);
}
}
List<SignalMastRepeater> repeaterList = m.getRepeaterList();
if (repeaterList.size() > 0) {
//Element repeatElem= new Element("signalmastrepeaters");
for (SignalMastRepeater smr : repeaterList) {
if (smr.getMasterMast() != null && smr.getSlaveMast() != null) {
Element e = new Element("signalmastrepeater");
e.addContent(new Element("masterMast").addContent(smr.getMasterMastName()));
e.addContent(new Element("slaveMast").addContent(smr.getSlaveMastName()));
e.addContent(new Element("enabled").addContent(smr.getEnabled() ? "true" : "false"));
switch(smr.getDirection()) {
case 1:
e.addContent(new Element("update").addContent("MasterToSlave"));
break;
case 2:
e.addContent(new Element("update").addContent("SlaveToMaster"));
break;
default:
e.addContent(new Element("update").addContent("BothWay"));
break;
}
element.addContent(e);
}
}
//element.add(repeatElem);
}
}
return element;
}
use of jmri.SignalMast in project JMRI by JMRI.
the class LevelXing method setSignalAMast.
public void setSignalAMast(String signalMast) {
if (signalMast == null || signalMast.equals("")) {
signalAMastNamed = null;
return;
}
try {
SignalMast mast = InstanceManager.getDefault(jmri.SignalMastManager.class).provideSignalMast(signalMast);
signalAMastNamed = InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(signalMast, mast);
} catch (IllegalArgumentException ex) {
signalAMastNamed = null;
}
}
use of jmri.SignalMast in project JMRI by JMRI.
the class LayoutTurnout method setSignalDMast.
public void setSignalDMast(String signalMast) {
if (signalMast == null || signalMast.equals("")) {
signalDMastNamed = null;
return;
}
SignalMast mast = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(signalMast);
if (mast != null) {
signalDMastNamed = InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(signalMast, mast);
} else {
log.error("Signal Mast " + signalMast + " Not found for turnout " + getTurnoutName());
signalDMastNamed = null;
}
}
use of jmri.SignalMast in project JMRI by JMRI.
the class LevelXing method setSignalBMast.
public void setSignalBMast(String signalMast) {
if (signalMast == null || signalMast.equals("")) {
signalBMastNamed = null;
return;
}
try {
SignalMast mast = InstanceManager.getDefault(jmri.SignalMastManager.class).provideSignalMast(signalMast);
signalBMastNamed = InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(signalMast, mast);
} catch (IllegalArgumentException ex) {
signalBMastNamed = null;
}
}
Aggregations