Search in sources :

Example 11 with LayoutEditor

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

the class LevelXingXml method load.

/**
     * Load, starting with the levelxing 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 levelxing center  attribute");
    }
    // create the new LevelXing
    LevelXing l = new LevelXing(name, new Point2D.Double(x, y), p);
    // get remaining attributes
    Attribute a = element.getAttribute("blocknameac");
    if (a != null) {
        l.tBlockNameAC = a.getValue();
    }
    a = element.getAttribute("blocknamebd");
    if (a != null) {
        l.tBlockNameBD = 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();
    }
    a = element.getAttribute("signalaname");
    if (a != null) {
        l.setSignalAName(a.getValue());
    }
    a = element.getAttribute("signalbname");
    if (a != null) {
        l.setSignalBName(a.getValue());
    }
    a = element.getAttribute("signalcname");
    if (a != null) {
        l.setSignalCName(a.getValue());
    }
    a = element.getAttribute("signaldname");
    if (a != null) {
        l.setSignalDName(a.getValue());
    }
    try {
        x = element.getAttribute("xa").getFloatValue();
        y = element.getAttribute("ya").getFloatValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert levelxing 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 levelxing b coords attribute");
    }
    l.setCoordsB(new Point2D.Double(x, y));
    if (element.getChild("signalAMast") != null) {
        String mast = element.getChild("signalAMast").getText();
        if (mast != null && !mast.equals("")) {
            l.setSignalAMast(mast);
        }
    }
    if (element.getChild("signalBMast") != null) {
        String mast = element.getChild("signalBMast").getText();
        if (mast != null && !mast.equals("")) {
            l.setSignalBMast(mast);
        }
    }
    if (element.getChild("signalCMast") != null) {
        String mast = element.getChild("signalCMast").getText();
        if (mast != null && !mast.equals("")) {
            l.setSignalCMast(mast);
        }
    }
    if (element.getChild("signalDMast") != null) {
        String mast = element.getChild("signalDMast").getText();
        if (mast != null && !mast.equals("")) {
            l.setSignalDMast(mast);
        }
    }
    if (element.getChild("sensorA") != null) {
        String sensor = element.getChild("sensorA").getText();
        if (sensor != null && !sensor.equals("")) {
            l.setSensorAName(sensor);
        }
    }
    if (element.getChild("sensorB") != null) {
        String sensor = element.getChild("sensorB").getText();
        if (sensor != null && !sensor.equals("")) {
            l.setSensorBName(sensor);
        }
    }
    if (element.getChild("sensorC") != null) {
        String sensor = element.getChild("sensorC").getText();
        if (sensor != null && !sensor.equals("")) {
            l.setSensorCName(sensor);
        }
    }
    if (element.getChild("sensorD") != null) {
        String sensor = element.getChild("sensorD").getText();
        if (sensor != null && !sensor.equals("")) {
            l.setSensorDName(sensor);
        }
    }
    p.xingList.add(l);
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) LevelXing(jmri.jmrit.display.layoutEditor.LevelXing) Point2D(java.awt.geom.Point2D) Attribute(org.jdom2.Attribute)

Example 12 with LayoutEditor

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

the class TrackSegmentXml method load.

/**
     * Load, starting with the tracksegment element, then all all attributes
     *
     * @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 type1 = LayoutTrack.NONE;
    int type2 = LayoutTrack.NONE;
    try {
        type1 = element.getAttribute("type1").getIntValue();
        type2 = element.getAttribute("type2").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert tracksegment attribute");
    }
    boolean dash = true;
    if (element.getAttribute("dashed").getValue().equals("no")) {
        dash = false;
    }
    boolean main = true;
    if (element.getAttribute("mainline").getValue().equals("no")) {
        main = false;
    }
    boolean hide = true;
    if (element.getAttribute("hidden").getValue().equals("no")) {
        hide = false;
    }
    String con1Name = element.getAttribute("connect1name").getValue();
    String con2Name = element.getAttribute("connect2name").getValue();
    // create the new TrackSegment
    TrackSegment l = new TrackSegment(name, con1Name, type1, con2Name, type2, dash, main, hide, p);
    try {
        if (element.getAttribute("arc").getValue().equals("yes")) {
            l.setArc(true);
        }
    } catch (NullPointerException e) {
    }
    if (l.getArc()) {
        //int startangle = 0;
        try {
            if (element.getAttribute("flip").getValue().equals("yes")) {
                l.setFlip(true);
            }
        } catch (NullPointerException e) {
        }
        //considered normal if the attribute is not present }
        try {
            if (element.getAttribute("circle").getValue().equals("yes")) {
                l.setCircle(true);
            }
        } catch (NullPointerException e) {
        }
        if (l.getCircle()) {
            try {
                l.setAngle(element.getAttribute("angle").getDoubleValue());
            } catch (org.jdom2.DataConversionException e) {
                log.error("failed to convert tracksegment attribute");
            } catch (NullPointerException e) {
            // considered normal if the attribute not present
            }
        }
        try {
            if (element.getAttribute("hideConLines").getValue().equals("yes")) {
                l.hideConstructionLines(TrackSegment.HIDECON);
            }
        } catch (NullPointerException e) {
        }
    //considered normal if the attribute is not present }
    }
    try {
        if (element.getAttribute("bezier").getValue().equals("yes")) {
            // load control points
            Element controlpointsElement = element.getChild("controlpoints");
            if (null != controlpointsElement) {
                List<Element> elementList = controlpointsElement.getChildren("controlpoint");
                if (null != elementList) {
                    if (elementList.size() >= 2) {
                        for (int i = 0; i < elementList.size(); i++) {
                            double x = 0.0;
                            double y = 0.0;
                            int index = 0;
                            Element relem = elementList.get(i);
                            try {
                                index = (relem.getAttribute("index")).getIntValue();
                                x = (relem.getAttribute("x")).getFloatValue();
                                y = (relem.getAttribute("y")).getFloatValue();
                            } catch (org.jdom2.DataConversionException e) {
                                log.error("failed to convert controlpoint coordinates or index attributes");
                            }
                            l.setBezierControlPoint(new Point2D.Double(x, y), index);
                        }
                    } else {
                        log.error("Track segment Bezier two controlpoint elements not found. (found " + elementList.size() + ")");
                    }
                } else {
                    log.error("Track segment Bezier controlpoint elements not found.");
                }
            } else {
                log.error("Track segment Bezier controlpoints element not found.");
            }
            // NOTE: do this LAST (so reCenter won't be called yet)
            l.setBezier(true);
        }
    } catch (NullPointerException e) {
    }
    //considered normal if the attribute is not present }
    // get remaining attribute
    Attribute a = element.getAttribute("blockname");
    if (a != null) {
        l.tBlockName = a.getValue();
    }
    p.trackList.add(l);
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) TrackSegment(jmri.jmrit.display.layoutEditor.TrackSegment) Point2D(java.awt.geom.Point2D)

Example 13 with LayoutEditor

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

the class LayoutTurntableXml method load.

/**
     * Load, starting with the layoutturntable 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;
    double radius = 25.0;
    try {
        x = element.getAttribute("xcen").getFloatValue();
        y = element.getAttribute("ycen").getFloatValue();
        radius = element.getAttribute("radius").getFloatValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert layoutturntable center or radius attributes");
    }
    // create the new LayoutTurntable
    LayoutTurntable l = new LayoutTurntable(name, new Point2D.Double(x, y), p);
    l.setRadius(radius);
    boolean turnoutControl = false;
    if (element.getAttribute("turnoutControlled") != null) {
        if (element.getAttribute("turnoutControlled").getValue().equals("yes")) {
            turnoutControl = true;
        }
    }
    l.setTurnoutControlled(turnoutControl);
    // load ray tracks 
    List<Element> rayTrackList = element.getChildren("raytrack");
    if (rayTrackList.size() > 0) {
        for (int i = 0; i < rayTrackList.size(); i++) {
            double angle = 0.0;
            int index = 0;
            Element relem = rayTrackList.get(i);
            try {
                angle = (relem.getAttribute("angle")).getFloatValue();
                index = (relem.getAttribute("index")).getIntValue();
            } catch (org.jdom2.DataConversionException e) {
                log.error("failed to convert ray track angle or index attributes");
            }
            String connectName = "";
            Attribute a = relem.getAttribute("connectname");
            if (a != null) {
                connectName = a.getValue();
            }
            l.addRayTrack(angle, index, connectName);
            if (turnoutControl && relem.getAttribute("turnout") != null) {
                //Turnout t = jmri.InstanceManager.turnoutManagerInstance().getTurnout();
                if (relem.getAttribute("turnoutstate").getValue().equals("thrown")) {
                    l.setRayTurnout(index, relem.getAttribute("turnout").getValue(), Turnout.THROWN);
                } else {
                    l.setRayTurnout(index, relem.getAttribute("turnout").getValue(), Turnout.CLOSED);
                }
            }
        }
    }
    p.turntableList.add(l);
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Point2D(java.awt.geom.Point2D) LayoutTurntable(jmri.jmrit.display.layoutEditor.LayoutTurntable)

Example 14 with LayoutEditor

use of jmri.jmrit.display.layoutEditor.LayoutEditor 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);
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Point2D(java.awt.geom.Point2D) Attribute(org.jdom2.Attribute) PositionablePoint(jmri.jmrit.display.layoutEditor.PositionablePoint) PositionablePoint(jmri.jmrit.display.layoutEditor.PositionablePoint)

Example 15 with LayoutEditor

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

the class EntryExitPairsXml 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) {
    EntryExitPairs p = (EntryExitPairs) o;
    Element element = new Element("entryexitpairs");
    setStoreElementClass(element);
    ArrayList<LayoutEditor> editors = p.getSourcePanelList();
    if (editors.size() == 0) {
        return element;
    }
    element.addContent(new Element("cleardown").addContent("" + p.getClearDownOption()));
    if (p.getDispatcherIntegration()) {
        element.addContent(new Element("dispatcherintegration").addContent("yes"));
    }
    if (p.useDifferentColorWhenSetting()) {
        element.addContent(new Element("colourwhilesetting").addContent(colorToString(p.getSettingRouteColor())));
        element.addContent(new Element("settingTimer").addContent("" + p.getSettingTimer()));
    }
    for (int k = 0; k < editors.size(); k++) {
        LayoutEditor panel = editors.get(k);
        List<Object> nxpair = p.getSourceList(panel);
        Element panelElem = new Element("layoutPanel");
        panelElem.setAttribute("name", panel.getLayoutName());
        for (int j = 0; j < nxpair.size(); j++) {
            Object key = nxpair.get(j);
            Element source = new Element("source");
            String type = "";
            String item = "";
            if (key instanceof SignalMast) {
                type = "signalMast";
                item = ((SignalMast) key).getDisplayName();
            } else if (key instanceof Sensor) {
                type = "sensor";
                item = ((Sensor) key).getDisplayName();
            } else if (key instanceof SignalHead) {
                type = "signalHead";
                item = ((SignalHead) key).getDisplayName();
            }
            source.setAttribute("type", type);
            source.setAttribute("item", item);
            ArrayList<Object> a = p.getDestinationList(key, panel);
            for (int i = 0; i < a.size(); i++) {
                Object keyDest = a.get(i);
                String typeDest = "";
                String itemDest = "";
                if (keyDest instanceof SignalMast) {
                    typeDest = "signalMast";
                    itemDest = ((SignalMast) keyDest).getDisplayName();
                } else if (keyDest instanceof Sensor) {
                    typeDest = "sensor";
                    itemDest = ((Sensor) keyDest).getDisplayName();
                } else if (keyDest instanceof SignalHead) {
                    typeDest = "signalHead";
                    itemDest = ((SignalHead) keyDest).getDisplayName();
                }
                Element dest = new Element("destination");
                dest.setAttribute("type", typeDest);
                dest.setAttribute("item", itemDest);
                if (!p.isUniDirection(key, panel, keyDest)) {
                    dest.setAttribute("uniDirection", "no");
                }
                if (!p.isEnabled(key, panel, keyDest)) {
                    dest.setAttribute("enabled", "no");
                }
                int nxType = p.getEntryExitType(key, panel, keyDest);
                switch(nxType) {
                    case 0x00:
                        dest.setAttribute("nxType", "turnoutsetting");
                        break;
                    case 0x01:
                        dest.setAttribute("nxType", "signalmastlogic");
                        break;
                    case 0x02:
                        dest.setAttribute("nxType", "fullinterlocking");
                        break;
                    default:
                        dest.setAttribute("nxType", "turnoutsetting");
                        break;
                }
                if (p.getUniqueId(key, panel, keyDest) != null) {
                    dest.setAttribute("uniqueid", p.getUniqueId(key, panel, keyDest));
                }
                source.addContent(dest);
            }
            panelElem.addContent(source);
        }
        element.addContent(panelElem);
    }
    return element;
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Element(org.jdom2.Element) SignalMast(jmri.SignalMast) SignalHead(jmri.SignalHead) EntryExitPairs(jmri.jmrit.signalling.EntryExitPairs) Sensor(jmri.Sensor)

Aggregations

LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)28 Element (org.jdom2.Element)12 Attribute (org.jdom2.Attribute)9 Point2D (java.awt.geom.Point2D)6 ArrayList (java.util.ArrayList)5 PointDetails (jmri.jmrit.signalling.entryexit.PointDetails)5 Source (jmri.jmrit.signalling.entryexit.Source)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Editor (jmri.jmrit.display.Editor)3 ControlPanelEditor (jmri.jmrit.display.controlPanelEditor.ControlPanelEditor)3 JmriJFrame (jmri.util.JmriJFrame)3 ConfigureManager (jmri.ConfigureManager)2 Sensor (jmri.Sensor)2 NamedIcon (jmri.jmrit.catalog.NamedIcon)2 Positionable (jmri.jmrit.display.Positionable)2 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)2 SwitchboardEditor (jmri.jmrit.display.switchboardEditor.SwitchboardEditor)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1