Search in sources :

Example 11 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class WarrantManagerXml method loadBlockOrder.

static BlockOrder loadBlockOrder(Element elem) {
    OBlock block = null;
    List<Element> blocks = elem.getChildren("block");
    if (blocks.size() > 1)
        log.error("More than one block present: {}", blocks.size());
    if (blocks.size() > 0) {
        // sensor
        String name = blocks.get(0).getAttribute("systemName").getValue();
        try {
            block = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class).provideOBlock(name);
        } catch (IllegalArgumentException ex) {
            log.error("Unknown Block \"{}\" is null in BlockOrder.", name);
            return null;
        }
        if (log.isDebugEnabled())
            log.debug("Load Block {}.", name);
    } else {
        log.error("Null BlockOrder element");
        return null;
    }
    Attribute attr = elem.getAttribute("pathName");
    String pathName = null;
    if (attr != null)
        pathName = attr.getValue();
    attr = elem.getAttribute("entryName");
    String entryName = null;
    if (attr != null)
        entryName = attr.getValue();
    attr = elem.getAttribute("exitName");
    String exitName = null;
    if (attr != null)
        exitName = attr.getValue();
    return new BlockOrder(block, pathName, entryName, exitName);
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) OBlock(jmri.jmrit.logix.OBlock) BlockOrder(jmri.jmrit.logix.BlockOrder)

Example 12 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class OBlockManagerXml method loadBlock.

void loadBlock(Element elem) {
    if (elem.getAttribute("systemName") == null) {
        log.error("unexpected null in systemName " + elem + " " + elem.getAttributes());
        return;
    }
    String sysName = elem.getAttribute("systemName").getValue();
    String userName = null;
    if (elem.getAttribute("userName") != null) {
        userName = elem.getAttribute("userName").getValue();
    }
    if (log.isDebugEnabled()) {
        log.debug("Load block sysName= " + sysName + " userName= " + userName);
    }
    // Portal may have already created a skeleton of this block
    OBlock block = getBlock(sysName);
    if (block == null) {
        log.error("Null block!! sysName= " + sysName + ", userName= " + userName);
        return;
    }
    block.setUserName(userName);
    String c = elem.getChildText("comment");
    if (c != null) {
        block.setComment(c);
    }
    if (elem.getAttribute("units") != null) {
        block.setMetricUnits(elem.getAttribute("units").getValue().equals("true"));
    } else {
        block.setMetricUnits(false);
    }
    if (elem.getAttribute("length") != null) {
        block.setLength(Float.valueOf(elem.getAttribute("length").getValue()).floatValue());
    }
    if (elem.getAttribute("curve") != null) {
        block.setCurvature(Integer.parseInt((elem.getAttribute("curve")).getValue()));
    }
    List<Element> sensors = elem.getChildren("sensor");
    if (sensors.size() > 1) {
        log.error("More than one sensor present: " + sensors.size());
    }
    if (sensors.size() > 0) {
        // sensor
        String name = sensors.get(0).getAttribute("systemName").getValue();
        block.setSensor(name);
    }
    Element errSensor = elem.getChild("errorSensor");
    if (errSensor != null) {
        // sensor
        String name = errSensor.getAttribute("systemName").getValue();
        block.setErrorSensor(name);
    }
    Element reporter = elem.getChild("reporter");
    if (reporter != null) {
        // sensor
        String name = reporter.getAttribute("systemName").getValue();
        try {
            Reporter rep = InstanceManager.getDefault(jmri.ReporterManager.class).getReporter(name);
            if (rep != null) {
                block.setReporter(rep);
            }
        } catch (Exception ex) {
            log.error("No Reporter named \"" + name + "\" found. threw exception: " + ex);
        }
        if (reporter.getAttribute("reportCurrent") != null) {
            block.setReportingCurrent(reporter.getAttribute("reportCurrent").getValue().equals("true"));
        } else {
            block.setReportingCurrent(false);
        }
    }
    if (elem.getAttribute("permissive") != null) {
        block.setPermissiveWorking(elem.getAttribute("permissive").getValue().equals("true"));
    } else {
        block.setPermissiveWorking(false);
    }
    if (elem.getAttribute("speedNotch") != null) {
        try {
            block.setBlockSpeed(elem.getAttribute("speedNotch").getValue());
        } catch (jmri.JmriException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + elem.getAttribute("speedNotch").getValue());
        }
    }
    List<Element> portals = elem.getChildren("portal");
    for (int k = 0; k < portals.size(); k++) {
        block.addPortal(loadPortal(portals.get(k)));
    }
    List<Element> paths = elem.getChildren("path");
    for (int j = 0; j < paths.size(); j++) {
        if (!block.addPath(loadPath(paths.get(j), block))) {
            log.error("load: block \"" + sysName + "\" failed to add path \"" + paths.get(j).getName() + "\" in block \"" + block.getSystemName() + "\"");
        }
    }
}
Also used : Element(org.jdom2.Element) Reporter(jmri.Reporter) OBlock(jmri.jmrit.logix.OBlock)

Example 13 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class OBlockManagerXml method getBlock.

OBlock getBlock(String sysName) {
    OBlock block = _blockMap.get(sysName);
    if (block == null) {
        try {
            block = _manager.provideOBlock(sysName);
            log.debug("found OBlock: ({}) {}", sysName, block);
        } catch (IllegalArgumentException ex) {
            block = _manager.createNewOBlock(sysName, null);
            log.debug("create OBlock: ({})", sysName);
        }
        _blockMap.put(sysName, block);
    }
    return block;
}
Also used : OBlock(jmri.jmrit.logix.OBlock)

Example 14 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class OBlockManagerXml method loadPortal.

Portal loadPortal(Element elem) {
    String sysName = null;
    String userName = elem.getAttribute("portalName").getValue();
    if (elem.getAttribute("systemName") == null) {
        if (log.isDebugEnabled()) {
            log.debug("Portal systemName is null");
        }
    } else {
        sysName = elem.getAttribute("systemName").getValue();
    }
    String fromBlockName = null;
    String toBlockName = null;
    // Portals must have user names.
    Portal portal = _portalMgr.getByUserName(userName);
    if (portal != null) {
        fromBlockName = portal.getFromBlock().getSystemName();
        toBlockName = portal.getToBlock().getSystemName();
    } else {
        portal = _portalMgr.providePortal(userName);
    }
    if (portal == null) {
        log.error("unable to create Portal (" + sysName + ", " + userName + ") " + elem + " " + elem.getAttributes());
        return null;
    }
    if (log.isDebugEnabled()) {
        log.debug("create Portal: (" + sysName + ", " + userName + ")");
    }
    OBlock fromBlock = null;
    Element eFromBlk = elem.getChild("fromBlock");
    if (eFromBlk != null && eFromBlk.getAttribute("blockName") != null) {
        String name = eFromBlk.getAttribute("blockName").getValue();
        if (fromBlockName != null && !fromBlockName.equals(name)) {
            log.error("Portal has user name \"" + userName + "\" conflicting with " + portal.toString());
        } else {
            fromBlock = getBlock(name);
            if (fromBlock != null) {
                portal.setFromBlock(fromBlock, false);
                fromBlock.addPortal(portal);
                List<Element> ePathsFromBlock = eFromBlk.getChildren("path");
                for (int i = 0; i < ePathsFromBlock.size(); i++) {
                    Element e = ePathsFromBlock.get(i);
                    String pathName = e.getAttribute("pathName").getValue();
                    String blockName = e.getAttribute("blockName").getValue();
                    if (log.isDebugEnabled()) {
                        log.debug("Load portal= " + userName + " fromBlock= " + fromBlock.getSystemName() + " pathName= " + pathName + " blockName= " + blockName);
                    }
                    /*(if (fromBlock.getSystemName().equals(blockName))*/
                    {
                        // path is in the fromBlock
                        OPath path = getPath(fromBlock, pathName);
                        portal.addPath(path);
                    }
                }
            }
        }
    } else {
        log.error("Portal \"" + userName + "\" has no fromBlock!");
    }
    OBlock toBlock = null;
    Element eToBlk = elem.getChild("toBlock");
    if (eToBlk != null && eToBlk.getAttribute("blockName") != null) {
        String name = eToBlk.getAttribute("blockName").getValue();
        if (toBlockName != null && !toBlockName.equals(name)) {
            log.error("Portal has user name \"" + userName + "\" conflicting with " + portal.toString());
        } else {
            toBlock = getBlock(name);
            if (toBlock != null) {
                portal.setToBlock(toBlock, false);
                toBlock.addPortal(portal);
                List<Element> ePathsToBlock = eToBlk.getChildren("path");
                for (int i = 0; i < ePathsToBlock.size(); i++) {
                    Element e = ePathsToBlock.get(i);
                    String pathName = e.getAttribute("pathName").getValue();
                    String blockName = e.getAttribute("blockName").getValue();
                    if (log.isDebugEnabled()) {
                        log.debug("Load portal= " + userName + " toBlock= " + toBlock.getSystemName() + " pathName= " + pathName + " blockName= " + blockName);
                    }
                    /*if (toBlock.getSystemName().equals(blockName))*/
                    {
                        // path is in the toBlock
                        OPath path = getPath(toBlock, pathName);
                        portal.addPath(path);
                    }
                }
            }
        }
    } else {
        log.error("Portal \"" + userName + "\" has no toBlock!");
    }
    Element eSignal = elem.getChild("fromSignal");
    if (eSignal != null) {
        String name = eSignal.getAttribute("signalName").getValue();
        float length = 0.0f;
        try {
            Attribute attr = eSignal.getAttribute("signalDelay");
            if (attr != null) {
                length = attr.getFloatValue();
            }
        } catch (org.jdom2.DataConversionException e) {
            log.error("Could not parse signalDelay for signal (" + name + ") in portal (" + userName + ")");
        }
        portal.setProtectSignal(Portal.getSignal(name), length, toBlock);
    }
    eSignal = elem.getChild("toSignal");
    if (eSignal != null) {
        String name = eSignal.getAttribute("signalName").getValue();
        float length = 0.0f;
        try {
            Attribute attr = eSignal.getAttribute("signalDelay");
            if (attr != null) {
                length = attr.getFloatValue();
            }
        } catch (org.jdom2.DataConversionException e) {
            log.error("Could not parse signalDelay for signal (" + name + ") in portal (" + userName + ")");
        }
        portal.setProtectSignal(Portal.getSignal(name), length, fromBlock);
    }
    if (log.isDebugEnabled()) {
        log.debug("End Load portal " + userName);
    }
    return portal;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Portal(jmri.jmrit.logix.Portal) OPath(jmri.jmrit.logix.OPath) OBlock(jmri.jmrit.logix.OBlock)

Example 15 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class WarrantManagerXml method storeOrder.

static Element storeOrder(BlockOrder order, String type) {
    Element elem = new Element(type);
    OBlock block = order.getBlock();
    if (block != null) {
        Element blk = new Element("block");
        blk.setAttribute("systemName", block.getSystemName());
        String uname = block.getUserName();
        if (uname == null)
            uname = "";
        if (uname.length() > 0) {
            blk.setAttribute("userName", uname);
        }
        elem.addContent(blk);
    } else {
        log.error("Null block in BlockOrder!");
    }
    String str = order.getPathName();
    if (str == null)
        str = "";
    elem.setAttribute("pathName", str);
    str = order.getEntryName();
    if (str == null)
        str = "";
    elem.setAttribute("entryName", str);
    str = order.getExitName();
    if (str == null)
        str = "";
    elem.setAttribute("exitName", str);
    return elem;
}
Also used : Element(org.jdom2.Element) OBlock(jmri.jmrit.logix.OBlock)

Aggregations

OBlock (jmri.jmrit.logix.OBlock)40 Portal (jmri.jmrit.logix.Portal)13 OBlockManager (jmri.jmrit.logix.OBlockManager)10 Element (org.jdom2.Element)10 ArrayList (java.util.ArrayList)6 Positionable (jmri.jmrit.display.Positionable)6 NamedBean (jmri.NamedBean)5 Sensor (jmri.Sensor)5 Point (java.awt.Point)4 OPath (jmri.jmrit.logix.OPath)4 PropertyVetoException (java.beans.PropertyVetoException)3 Entry (java.util.Map.Entry)3 JMenu (javax.swing.JMenu)3 Reporter (jmri.Reporter)3 Attribute (org.jdom2.Attribute)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 JInternalFrame (javax.swing.JInternalFrame)2