Search in sources :

Example 6 with PositionablePoint

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;
}
Also used : LayoutSlip(jmri.jmrit.display.layoutEditor.LayoutSlip) LevelXing(jmri.jmrit.display.layoutEditor.LevelXing) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) SignalHead(jmri.SignalHead) SignalMast(jmri.SignalMast) PositionablePoint(jmri.jmrit.display.layoutEditor.PositionablePoint) Sensor(jmri.Sensor)

Aggregations

PositionablePoint (jmri.jmrit.display.layoutEditor.PositionablePoint)6 LayoutSlip (jmri.jmrit.display.layoutEditor.LayoutSlip)4 LayoutTurnout (jmri.jmrit.display.layoutEditor.LayoutTurnout)4 LevelXing (jmri.jmrit.display.layoutEditor.LevelXing)4 Point2D (java.awt.geom.Point2D)2 Sensor (jmri.Sensor)2 SignalHead (jmri.SignalHead)2 SignalMast (jmri.SignalMast)2 NamedBean (jmri.NamedBean)1 ConnectivityUtil (jmri.jmrit.display.layoutEditor.ConnectivityUtil)1 LayoutBlock (jmri.jmrit.display.layoutEditor.LayoutBlock)1 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)1 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)1 TrackNode (jmri.jmrit.display.layoutEditor.TrackNode)1 TrackSegment (jmri.jmrit.display.layoutEditor.TrackSegment)1 Attribute (org.jdom2.Attribute)1 Element (org.jdom2.Element)1