Search in sources :

Example 1 with TurnoutOperationXml

use of jmri.configurexml.turnoutoperations.TurnoutOperationXml in project JMRI by JMRI.

the class TurnoutOperationManagerXml method store.

@Override
public Element store(Object o) {
    Element elem = new Element("operations");
    if (o instanceof TurnoutOperationManager) {
        TurnoutOperationManager manager = (TurnoutOperationManager) o;
        elem.setAttribute("automate", String.valueOf(manager.getDoOperations()));
        TurnoutOperation[] operations = manager.getTurnoutOperations();
        for (int i = 0; i < operations.length; ++i) {
            TurnoutOperation op = operations[i];
            if (!op.isNonce()) {
                // nonces are stored with their respective turnouts
                TurnoutOperationXml adapter = TurnoutOperationXml.getAdapter(op);
                if (adapter != null) {
                    Element opElem = adapter.store(op);
                    if (opElem != null) {
                        elem.addContent(opElem);
                    }
                }
            }
        }
    }
    return elem;
}
Also used : TurnoutOperation(jmri.TurnoutOperation) Element(org.jdom2.Element) TurnoutOperationXml(jmri.configurexml.turnoutoperations.TurnoutOperationXml) TurnoutOperationManager(jmri.TurnoutOperationManager)

Example 2 with TurnoutOperationXml

use of jmri.configurexml.turnoutoperations.TurnoutOperationXml in project JMRI by JMRI.

the class AbstractTurnoutManagerConfigXML method store.

/**
     * Default implementation for storing the contents of a TurnoutManager and
     * associated TurnoutOperation's
     *
     * @param o Object to store, of type TurnoutManager
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Element turnouts = new Element("turnouts");
    setStoreElementClass(turnouts);
    TurnoutManager tm = (TurnoutManager) o;
    if (tm != null) {
        TurnoutOperationManagerXml tomx = new TurnoutOperationManagerXml();
        Element opElem = tomx.store(TurnoutOperationManager.getInstance());
        turnouts.addContent(opElem);
        java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
        // don't return an element if there are not turnouts to include
        if (!iter.hasNext()) {
            return null;
        }
        String defaultclosed = tm.getDefaultClosedSpeed();
        String defaultthrown = tm.getDefaultThrownSpeed();
        turnouts.addContent(new Element("defaultclosedspeed").addContent(defaultclosed));
        turnouts.addContent(new Element("defaultthrownspeed").addContent(defaultthrown));
        // store the turnouts
        while (iter.hasNext()) {
            String sname = iter.next();
            log.debug("system name is " + sname);
            Turnout t = tm.getBySystemName(sname);
            Element elem = new Element("turnout");
            elem.addContent(new Element("systemName").addContent(sname));
            log.debug("store turnout " + sname);
            storeCommon(t, elem);
            // include feedback info
            elem.setAttribute("feedback", t.getFeedbackModeName());
            NamedBeanHandle<Sensor> s;
            s = t.getFirstNamedSensor();
            if (s != null) {
                elem.setAttribute("sensor1", s.getName());
            }
            s = t.getSecondNamedSensor();
            if (s != null) {
                elem.setAttribute("sensor2", s.getName());
            }
            // include turnout inverted
            elem.setAttribute("inverted", t.getInverted() ? "true" : "false");
            if (t.canLock(Turnout.CABLOCKOUT | Turnout.PUSHBUTTONLOCKOUT)) {
                // include turnout locked
                elem.setAttribute("locked", t.getLocked(Turnout.CABLOCKOUT + Turnout.PUSHBUTTONLOCKOUT) ? "true" : "false");
                // include turnout lock mode
                String lockOpr;
                if (t.canLock(Turnout.CABLOCKOUT) && t.canLock(Turnout.PUSHBUTTONLOCKOUT)) {
                    lockOpr = "both";
                } else if (t.canLock(Turnout.CABLOCKOUT)) {
                    lockOpr = "cab";
                } else if (t.canLock(Turnout.PUSHBUTTONLOCKOUT)) {
                    lockOpr = "pushbutton";
                } else {
                    lockOpr = "none";
                }
                elem.setAttribute("lockMode", lockOpr);
                // include turnout decoder
                elem.setAttribute("decoder", t.getDecoderName());
            }
            // include number of control bits, if different from one
            int iNum = t.getNumberOutputBits();
            if (iNum != 1) {
                elem.setAttribute("numBits", "" + iNum);
            }
            // include turnout control type, if different from 0
            int iType = t.getControlType();
            if (iType != 0) {
                elem.setAttribute("controlType", "" + iType);
            }
            // add operation stuff
            String opstr = null;
            TurnoutOperation op = t.getTurnoutOperation();
            if (t.getInhibitOperation()) {
                opstr = "Off";
            } else if (op == null) {
                opstr = "Default";
            } else if (op.isNonce()) {
                // nonce operation appears as subelement
                TurnoutOperationXml adapter = TurnoutOperationXml.getAdapter(op);
                if (adapter != null) {
                    Element nonceOpElem = adapter.store(op);
                    elem.addContent(nonceOpElem);
                }
            } else {
                opstr = op.getName();
            }
            if (opstr != null) {
                elem.setAttribute("automate", opstr);
            }
            if ((t.getDivergingSpeed() != null) && (!t.getDivergingSpeed().equals("")) && !t.getDivergingSpeed().contains("Global")) {
                elem.addContent(new Element("divergingSpeed").addContent(t.getDivergingSpeed()));
            }
            if ((t.getStraightSpeed() != null) && (!t.getStraightSpeed().equals("")) && !t.getStraightSpeed().contains("Global")) {
                elem.addContent(new Element("straightSpeed").addContent(t.getStraightSpeed()));
            }
            // add element
            turnouts.addContent(elem);
        }
    }
    return turnouts;
}
Also used : TurnoutOperationManagerXml(jmri.configurexml.TurnoutOperationManagerXml) TurnoutOperation(jmri.TurnoutOperation) Element(org.jdom2.Element) TurnoutOperationXml(jmri.configurexml.turnoutoperations.TurnoutOperationXml) TurnoutManager(jmri.TurnoutManager) Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Aggregations

TurnoutOperation (jmri.TurnoutOperation)2 TurnoutOperationXml (jmri.configurexml.turnoutoperations.TurnoutOperationXml)2 Element (org.jdom2.Element)2 Sensor (jmri.Sensor)1 Turnout (jmri.Turnout)1 TurnoutManager (jmri.TurnoutManager)1 TurnoutOperationManager (jmri.TurnoutOperationManager)1 TurnoutOperationManagerXml (jmri.configurexml.TurnoutOperationManagerXml)1