Search in sources :

Example 6 with LayoutSlip

use of jmri.jmrit.display.layoutEditor.LayoutSlip in project JMRI by JMRI.

the class LayoutSlipXml method load.

/**
     * Load, starting with the LayoutSlip element, then all the other data
     *
     * @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 center point
    String name = element.getAttribute("ident").getValue();
    double x = 0.0;
    double y = 0.0;
    try {
        x = element.getAttribute("xcen").getFloatValue();
        y = element.getAttribute("ycen").getFloatValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert layoutslip center  attribute");
    }
    int type = LayoutSlip.SINGLE_SLIP;
    try {
        type = element.getAttribute("slipType").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert layoutslip type attribute");
    }
    // create the new LayoutSlip
    LayoutSlip l = new LayoutSlip(name, new Point2D.Double(x, y), 0.0, p, type);
    // get remaining attributes
    Attribute a = element.getAttribute("blockname");
    if (a != null) {
        l.tBlockName = a.getValue();
    }
    a = element.getAttribute("connectaname");
    if (a != null) {
        l.connectAName = a.getValue();
    }
    a = element.getAttribute("connectbname");
    if (a != null) {
        l.connectBName = a.getValue();
    }
    a = element.getAttribute("connectcname");
    if (a != null) {
        l.connectCName = a.getValue();
    }
    a = element.getAttribute("connectdname");
    if (a != null) {
        l.connectDName = a.getValue();
    }
    l.setSignalA1Name(getElement(element, "signala1name"));
    l.setSignalB1Name(getElement(element, "signalb1name"));
    l.setSignalC1Name(getElement(element, "signalc1name"));
    l.setSignalD1Name(getElement(element, "signald1name"));
    l.setSignalA2Name(getElement(element, "signala2name"));
    l.setSignalB2Name(getElement(element, "signalb2name"));
    l.setSignalC2Name(getElement(element, "signalc2name"));
    l.setSignalD2Name(getElement(element, "signald2name"));
    try {
        x = element.getAttribute("xa").getFloatValue();
        y = element.getAttribute("ya").getFloatValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert LayoutSlip a coords attribute");
    }
    l.setCoordsA(new Point2D.Double(x, y));
    try {
        x = element.getAttribute("xb").getFloatValue();
        y = element.getAttribute("yb").getFloatValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert LayoutSlip b coords attribute");
    }
    l.setCoordsB(new Point2D.Double(x, y));
    l.setSignalAMast(getElement(element, "signalAMast"));
    l.setSignalBMast(getElement(element, "signalBMast"));
    l.setSignalCMast(getElement(element, "signalCMast"));
    l.setSignalDMast(getElement(element, "signalDMast"));
    l.setSensorA(getElement(element, "sensorA"));
    l.setSensorB(getElement(element, "sensorB"));
    l.setSensorC(getElement(element, "sensorC"));
    l.setSensorD(getElement(element, "sensorD"));
    l.setTurnout(getElement(element, "turnout"));
    l.setTurnoutB(getElement(element, "turnoutB"));
    if (element.getChild("states") != null) {
        Element state = element.getChild("states");
        if (state.getChild("A-C") != null) {
            Element ac = state.getChild("A-C");
            l.setTurnoutStates(LayoutSlip.STATE_AC, ac.getChild("turnout").getText(), ac.getChild("turnoutB").getText());
        }
        if (state.getChild("A-D") != null) {
            Element ad = state.getChild("A-D");
            l.setTurnoutStates(LayoutSlip.STATE_AD, ad.getChild("turnout").getText(), ad.getChild("turnoutB").getText());
        }
        if (state.getChild("B-D") != null) {
            Element bd = state.getChild("B-D");
            l.setTurnoutStates(LayoutSlip.STATE_BD, bd.getChild("turnout").getText(), bd.getChild("turnoutB").getText());
        }
        if (state.getChild("B-C") != null) {
            Element bc = state.getChild("B-C");
            l.setTurnoutStates(LayoutSlip.STATE_BC, bc.getChild("turnout").getText(), bc.getChild("turnoutB").getText());
        }
    }
    p.slipList.add(l);
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) LayoutSlip(jmri.jmrit.display.layoutEditor.LayoutSlip) Point2D(java.awt.geom.Point2D) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 7 with LayoutSlip

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

Example 8 with LayoutSlip

use of jmri.jmrit.display.layoutEditor.LayoutSlip 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

LayoutSlip (jmri.jmrit.display.layoutEditor.LayoutSlip)8 LayoutTurnout (jmri.jmrit.display.layoutEditor.LayoutTurnout)6 LevelXing (jmri.jmrit.display.layoutEditor.LevelXing)4 PositionablePoint (jmri.jmrit.display.layoutEditor.PositionablePoint)4 SignalHead (jmri.SignalHead)3 SignalMast (jmri.SignalMast)3 ConnectivityUtil (jmri.jmrit.display.layoutEditor.ConnectivityUtil)3 Point2D (java.awt.geom.Point2D)2 ArrayList (java.util.ArrayList)2 Block (jmri.Block)2 Sensor (jmri.Sensor)2 Turnout (jmri.Turnout)2 LayoutBlock (jmri.jmrit.display.layoutEditor.LayoutBlock)2 Element (org.jdom2.Element)2 Color (java.awt.Color)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 Hashtable (java.util.Hashtable)1