Search in sources :

Example 1 with SignalGroupManager

use of jmri.SignalGroupManager in project JMRI by JMRI.

the class DefaultSignalGroupManagerXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    // loop over contained signalgroup elements
    List<Element> list = shared.getChildren("signalgroup");
    SignalGroupManager sgm = InstanceManager.getDefault(jmri.SignalGroupManager.class);
    for (int i = 0; i < list.size(); i++) {
        SignalGroup m;
        Element e = list.get(i);
        String primary;
        String yesno;
        boolean inverse = false;
        int state = 0x00;
        String sys = getSystemName(e);
        m = sgm.newSignalGroup(sys);
        if (getUserName(e) != null) {
            m.setUserName(getUserName(e));
        }
        //loadCommon(m, e); // would store comment, now a separate element
        loadComment(m, e);
        primary = e.getAttribute("signalMast").getValue();
        m.setSignalMast(primary);
        // deprecated 4.7.2 for aspect
        List<Element> appList = e.getChildren("appearance");
        for (int y = 0; y < appList.size(); y++) {
            String value = appList.get(y).getAttribute("valid").getValue();
            m.addSignalMastAspect(value);
        }
        List<Element> aspList = e.getChildren("aspect");
        for (int y = 0; y < aspList.size(); y++) {
            String value = aspList.get(y).getAttribute("valid").getValue();
            m.addSignalMastAspect(value);
        }
        List<Element> signalHeadList = list.get(i).getChildren("signalHead");
        if (signalHeadList.size() > 0) {
            for (int y = 0; y < signalHeadList.size(); y++) {
                String head = signalHeadList.get(y).getAttribute("name").getValue();
                SignalHead sigHead = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(head);
                m.addSignalHead(sigHead);
                yesno = signalHeadList.get(y).getAttribute("sensorTurnoutLogic").getValue();
                inverse = false;
                if ((yesno != null) && (!yesno.equals(""))) {
                    if (yesno.equals("AND")) {
                        inverse = true;
                    } else if (yesno.equals("OR")) {
                        inverse = false;
                    }
                }
                m.setSensorTurnoutOper(sigHead, inverse);
                try {
                    m.setHeadOnState(sigHead, getIntFromColour(signalHeadList.get(y).getAttribute("onAppearance").getValue()));
                } catch (NullPointerException ex) {
                // considered normal if the attributes are not present
                }
                try {
                    m.setHeadOffState(sigHead, getIntFromColour(signalHeadList.get(y).getAttribute("offAppearance").getValue()));
                } catch (NullPointerException ex) {
                // considered normal if the attributes are not present
                }
                List<Element> signalTurnoutList = signalHeadList.get(y).getChildren("turnout");
                if (signalTurnoutList.size() > 0) {
                    for (int k = 0; k < signalTurnoutList.size(); k++) {
                        String tName = signalTurnoutList.get(k).getAttribute("name").getValue();
                        jmri.Turnout turnout = jmri.InstanceManager.turnoutManagerInstance().getTurnout(tName);
                        state = 0;
                        try {
                            state = signalTurnoutList.get(k).getAttribute("state").getIntValue();
                        } catch (org.jdom2.DataConversionException ex) {
                            log.warn("invalid state attribute value");
                        }
                        m.setHeadAlignTurnout(sigHead, turnout, state);
                    }
                }
                List<Element> signalSensorList = signalHeadList.get(y).getChildren("sensor");
                if (signalSensorList.size() > 0) {
                    for (int k = 0; k < signalSensorList.size(); k++) {
                        String sName = signalSensorList.get(k).getAttribute("name").getValue();
                        jmri.Sensor sensor = jmri.InstanceManager.sensorManagerInstance().getSensor(sName);
                        state = 0;
                        try {
                            state = signalSensorList.get(k).getAttribute("state").getIntValue();
                        } catch (org.jdom2.DataConversionException ex) {
                            log.warn("invalid style attribute value");
                        }
                        m.setHeadAlignSensor(sigHead, sensor, state);
                    }
                }
            }
        }
    }
    return true;
}
Also used : SignalGroup(jmri.SignalGroup) Element(org.jdom2.Element) SignalHead(jmri.SignalHead) SignalGroupManager(jmri.SignalGroupManager)

Example 2 with SignalGroupManager

use of jmri.SignalGroupManager in project JMRI by JMRI.

the class DefaultSignalGroupManagerXml method store.

/**
     * Default implementation for storing the contents of a
     * DefaultSignalGroupManager
     *
     * @param o Object to store, of type TripleTurnoutSignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    SignalGroupManager m = (SignalGroupManager) o;
    Element element = new Element("signalgroups");
    element.setAttribute("class", this.getClass().getName());
    // include contents
    List<String> names = m.getSystemNameList();
    for (int i = 0; i < names.size(); i++) {
        Element e = new Element("signalgroup");
        SignalGroup p = m.getSignalGroup(names.get(i));
        e.addContent(new Element("systemName").addContent(p.getSystemName()));
        e.addContent(new Element("userName").addContent(p.getUserName()));
        //storeCommon(p, e); would store comment, now a separate element
        storeComment(p, e);
        element.addContent(e);
        for (int x = 0; x < p.getNumSignalMastAspects(); x++) {
            Element app = new Element("aspect").setAttribute("valid", p.getSignalMastAspectByIndex(x));
            e.addContent(app);
        }
        e.setAttribute("signalMast", p.getSignalMastName());
        for (int x = 0; x < p.getNumHeadItems(); x++) {
            storeSignalHead(e, p, x);
        }
    }
    return element;
}
Also used : SignalGroup(jmri.SignalGroup) SignalGroupManager(jmri.SignalGroupManager) Element(org.jdom2.Element)

Aggregations

SignalGroup (jmri.SignalGroup)2 SignalGroupManager (jmri.SignalGroupManager)2 Element (org.jdom2.Element)2 SignalHead (jmri.SignalHead)1