Search in sources :

Example 1 with EntryExitPairs

use of jmri.jmrit.signalling.EntryExitPairs 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)

Example 2 with EntryExitPairs

use of jmri.jmrit.signalling.EntryExitPairs in project JMRI by JMRI.

the class AppsBase method installManagers.

protected void installManagers() {
    // Install a history manager
    InstanceManager.store(new FileHistory(), FileHistory.class);
    // record startup
    InstanceManager.getDefault(FileHistory.class).addOperation("app", Application.getApplicationName(), null);
    // Install a user preferences manager
    InstanceManager.store(JmriUserPreferencesManager.getDefault(), UserPreferencesManager.class);
    // install the abstract action model that allows items to be added to the, both 
    // CreateButton and Perform Action Model use a common Abstract class
    InstanceManager.store(new CreateButtonModel(), CreateButtonModel.class);
    // install preference manager
    InstanceManager.store(new TabbedPreferences(), TabbedPreferences.class);
    // install the named bean handler
    InstanceManager.store(new NamedBeanHandleManager(), NamedBeanHandleManager.class);
    //Install Entry Exit Pairs Manager
    InstanceManager.store(new EntryExitPairs(), EntryExitPairs.class);
}
Also used : NamedBeanHandleManager(jmri.NamedBeanHandleManager) EntryExitPairs(jmri.jmrit.signalling.EntryExitPairs) FileHistory(jmri.jmrit.revhistory.FileHistory) TabbedPreferences(apps.gui3.TabbedPreferences)

Example 3 with EntryExitPairs

use of jmri.jmrit.signalling.EntryExitPairs in project JMRI by JMRI.

the class EntryExitPairsXml method load.

/**
     * Load, starting with the layoutBlock element, then all the value-icon
     * pairs.
     *
     * @param shared Top level Element to unpack
     * @param perNode ignored in this application
     */
@Override
public boolean load(Element shared, Element perNode) {
    // create the objects
    EntryExitPairs eep = jmri.InstanceManager.getDefault(jmri.jmrit.signalling.EntryExitPairs.class);
    try {
        String clearoption = shared.getChild("cleardown").getText();
        eep.setClearDownOption(Integer.parseInt(clearoption));
    } catch (java.lang.NullPointerException e) {
    //Considered normal if it doesn't exist
    }
    // get attributes
    ConfigureManager cm = jmri.InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    ArrayList<Object> loadedPanel;
    if (cm != null) {
        loadedPanel = cm.getInstanceList(LayoutEditor.class);
    } else {
        log.error("Failed getting optional default config manager");
        loadedPanel = new ArrayList<Object>();
    }
    if (shared.getChild("dispatcherintegration") != null && shared.getChild("dispatcherintegration").getText().equals("yes")) {
        eep.setDispatcherIntegration(true);
    }
    if (shared.getChild("colourwhilesetting") != null) {
        eep.setSettingRouteColor(stringToColor(shared.getChild("colourwhilesetting").getText()));
        int settingTimer = 2000;
        try {
            settingTimer = Integer.parseInt(shared.getChild("settingTimer").getText());
        } catch (Exception e) {
            log.error("Error in converting timer to int " + shared.getChild("settingTimer"));
        }
        eep.setSettingTimer(settingTimer);
    }
    List<Element> panelList = shared.getChildren("layoutPanel");
    for (int k = 0; k < panelList.size(); k++) {
        String panelName = panelList.get(k).getAttribute("name").getValue();
        LayoutEditor panel = null;
        for (int i = 0; i < loadedPanel.size(); i++) {
            LayoutEditor tmp = (LayoutEditor) loadedPanel.get(i);
            if (tmp.getLayoutName().equals(panelName)) {
                panel = tmp;
                break;
            }
        }
        if (panel != null) {
            List<Element> sourceList = panelList.get(k).getChildren("source");
            for (int i = 0; i < sourceList.size(); i++) {
                String sourceType = sourceList.get(i).getAttribute("type").getValue();
                String sourceItem = sourceList.get(i).getAttribute("item").getValue();
                NamedBean source = null;
                if (sourceType.equals("signalMast")) {
                    source = jmri.InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(sourceItem);
                } else if (sourceType.equals("sensor")) {
                    source = jmri.InstanceManager.sensorManagerInstance().getSensor(sourceItem);
                } else if (sourceType.equals("signalHead")) {
                    source = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(sourceItem);
                }
                //These two could be subbed off.
                List<Element> destinationList = sourceList.get(i).getChildren("destination");
                if (destinationList.size() > 0) {
                    eep.addNXSourcePoint(source, panel);
                }
                for (int j = 0; j < destinationList.size(); j++) {
                    String id = null;
                    if (destinationList.get(j).getAttribute("uniqueid") != null) {
                        id = destinationList.get(j).getAttribute("uniqueid").getValue();
                    }
                    String destType = destinationList.get(j).getAttribute("type").getValue();
                    String destItem = destinationList.get(j).getAttribute("item").getValue();
                    NamedBean dest = null;
                    if (destType.equals("signalMast")) {
                        dest = jmri.InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(destItem);
                    } else if (destType.equals("sensor")) {
                        dest = jmri.InstanceManager.sensorManagerInstance().getSensor(destItem);
                    } else if (destType.equals("signalHead")) {
                        dest = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(destItem);
                    }
                    try {
                        eep.addNXDestination(source, dest, panel, id);
                    } catch (java.lang.NullPointerException e) {
                        log.error("An error occured while trying to add a point");
                    }
                    if ((destinationList.get(j).getAttribute("uniDirection") != null) && (destinationList.get(j).getAttribute("uniDirection").getValue().equals("no"))) {
                        eep.setUniDirection(source, panel, dest, false);
                    }
                    if ((destinationList.get(j).getAttribute("enabled") != null) && (destinationList.get(j).getAttribute("enabled").getValue().equals("no"))) {
                        eep.setEnabled(source, panel, dest, false);
                    }
                    if (destinationList.get(j).getAttribute("nxType") != null) {
                        String nxType = destinationList.get(j).getAttribute("nxType").getValue();
                        if (nxType.equals("turnoutsetting")) {
                            eep.setEntryExitType(source, panel, dest, 0x00);
                        } else if (nxType.equals("signalmastlogic")) {
                            eep.setEntryExitType(source, panel, dest, 0x01);
                        } else if (nxType.equals("fullinterlocking")) {
                            eep.setEntryExitType(source, panel, dest, 0x02);
                        }
                    }
                }
            }
        } else {
            log.error("Panel has not been loaded");
        }
    }
    return true;
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) NamedBean(jmri.NamedBean) Element(org.jdom2.Element) ConfigureManager(jmri.ConfigureManager) EntryExitPairs(jmri.jmrit.signalling.EntryExitPairs)

Aggregations

EntryExitPairs (jmri.jmrit.signalling.EntryExitPairs)3 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)2 Element (org.jdom2.Element)2 TabbedPreferences (apps.gui3.TabbedPreferences)1 ConfigureManager (jmri.ConfigureManager)1 NamedBean (jmri.NamedBean)1 NamedBeanHandleManager (jmri.NamedBeanHandleManager)1 Sensor (jmri.Sensor)1 SignalHead (jmri.SignalHead)1 SignalMast (jmri.SignalMast)1 FileHistory (jmri.jmrit.revhistory.FileHistory)1