Search in sources :

Example 1 with OPath

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

the class OBlockManagerXml method getPath.

OPath getPath(OBlock block, String name) {
    String key = block.getSystemName() + name;
    OPath path = _pathMap.get(key);
    if (path == null) {
        path = new OPath(block, name);
        _pathMap.put(key, path);
        if (log.isDebugEnabled()) {
            log.debug("create OPath: (" + name + ") in block (" + block.getSystemName() + ")");
        }
    }
    return path;
}
Also used : OPath(jmri.jmrit.logix.OPath)

Example 2 with OPath

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

the class OBlockManagerXml method loadPath.

OPath loadPath(Element elem, OBlock block) {
    String pName = elem.getAttribute("pathName").getValue();
    OPath path = getPath(block, pName);
    try {
        Attribute attr = elem.getAttribute("fromDirection");
        if (attr != null) {
            path.setFromBlockDirection(attr.getIntValue());
        }
        attr = elem.getAttribute("toDirection");
        if (attr != null) {
            path.setToBlockDirection(attr.getIntValue());
        }
        attr = elem.getAttribute("length");
        if (attr != null) {
            path.setLength(attr.getFloatValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("Could not parse attribute of path (" + pName + ") block (" + block.getSystemName() + ")");
    }
    Attribute attr = elem.getAttribute("fromPortal");
    if (attr != null) {
        Portal portal = getPortal(attr.getValue());
        if (portal != null) {
            path.setFromPortal(portal);
            portal.addPath(path);
        }
    }
    attr = elem.getAttribute("toPortal");
    if (attr != null) {
        Portal portal = getPortal(attr.getValue());
        if (portal != null) {
            path.setToPortal(portal);
            portal.addPath(path);
        }
    }
    List<Element> settings = elem.getChildren("setting");
    if (log.isDebugEnabled()) {
        log.debug("Path (" + pName + ") has " + settings.size() + " settings.");
    }
    java.util.HashSet<String> turnouts = new java.util.HashSet<String>();
    int dups = 0;
    for (int i = 0; i < settings.size(); i++) {
        Element setElem = settings.get(i);
        int setting = 0;
        try {
            setting = setElem.getAttribute("set").getIntValue();
        } catch (org.jdom2.DataConversionException e) {
            log.error("Could not parse 'set' attribute for path (" + pName + ") block (" + block.getSystemName() + ")");
        }
        String sysName = setElem.getAttribute("turnout").getValue();
        if (!turnouts.contains(sysName)) {
            Turnout to = InstanceManager.turnoutManagerInstance().provideTurnout(sysName);
            turnouts.add(sysName);
            BeanSetting bs = new BeanSetting(to, sysName, setting);
            path.addSetting(bs);
        } else {
            dups++;
        }
    }
    if (dups > 0) {
        log.warn(dups + " duplicate settings not loaded for path \"" + pName + "\"");
    }
    return path;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) OPath(jmri.jmrit.logix.OPath) BeanSetting(jmri.BeanSetting) Portal(jmri.jmrit.logix.Portal) Turnout(jmri.Turnout)

Example 3 with OPath

use of jmri.jmrit.logix.OPath 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 4 with OPath

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

the class TableFrames method updateOpenMenu.

protected void updateOpenMenu() {
    _openMenu.removeAll();
    JMenuItem openBlock = new JMenuItem(Bundle.getMessage("OpenBlockMenu"));
    _openMenu.add(openBlock);
    openBlock.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            _blockTableFrame.setVisible(true);
            try {
                _blockTableFrame.setIcon(false);
            } catch (PropertyVetoException pve) {
                log.warn("Block Table Frame vetoed setIcon " + pve.toString());
            }
            _blockTableFrame.moveToFront();
        }
    });
    JMenuItem openPortal = new JMenuItem(Bundle.getMessage("OpenPortalMenu"));
    _openMenu.add(openPortal);
    openPortal.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            _portalTableFrame.setVisible(true);
            try {
                _portalTableFrame.setIcon(false);
            } catch (PropertyVetoException pve) {
                log.warn("Portal Table Frame vetoed setIcon " + pve.toString());
            }
            _portalTableFrame.moveToFront();
        }
    });
    JMenuItem openXRef = new JMenuItem(Bundle.getMessage("OpenXRefMenu"));
    _openMenu.add(openXRef);
    openXRef.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            _blockPortalXRefFrame.setVisible(true);
            try {
                _blockPortalXRefFrame.setIcon(false);
            } catch (PropertyVetoException pve) {
                log.warn("XRef Table Frame vetoed setIcon " + pve.toString());
            }
            _blockPortalXRefFrame.moveToFront();
        }
    });
    JMenuItem openSignal = new JMenuItem(Bundle.getMessage("OpenSignalMenu"));
    _openMenu.add(openSignal);
    openSignal.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            _signalTableFrame.setVisible(true);
            try {
                _signalTableFrame.setIcon(false);
            } catch (PropertyVetoException pve) {
                log.warn("Signal Table Frame vetoed setIcon " + pve.toString());
            }
            _signalTableFrame.moveToFront();
        }
    });
    JMenu openBlockPath = new JMenu(Bundle.getMessage("OpenBlockPathMenu"));
    ActionListener openFrameAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            String sysName = e.getActionCommand();
            openBlockPathFrame(sysName);
        }
    };
    OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
    String[] sysNames = manager.getSystemNameArray();
    for (int i = 0; i < sysNames.length; i++) {
        OBlock block = manager.getBySystemName(sysNames[i]);
        JMenuItem mi = new JMenuItem(Bundle.getMessage("OpenPathMenu", block.getDisplayName()));
        mi.setActionCommand(sysNames[i]);
        mi.addActionListener(openFrameAction);
        openBlockPath.add(mi);
    }
    _openMenu.add(openBlockPath);
    JMenu openTurnoutPath = new JMenu(Bundle.getMessage("OpenBlockPathTurnoutMenu"));
    sysNames = manager.getSystemNameArray();
    for (int i = 0; i < sysNames.length; i++) {
        OBlock block = manager.getBySystemName(sysNames[i]);
        JMenu openTurnoutMenu = new JMenu(Bundle.getMessage("OpenTurnoutMenu", block.getDisplayName()));
        openTurnoutPath.add(openTurnoutMenu);
        openFrameAction = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                String pathTurnoutName = e.getActionCommand();
                openPathTurnoutFrame(pathTurnoutName);
            }
        };
        Iterator<Path> iter = block.getPaths().iterator();
        while (iter.hasNext()) {
            OPath path = (OPath) iter.next();
            JMenuItem mi = new JMenuItem(Bundle.getMessage("OpenPathTurnoutMenu", path.getName()));
            mi.setActionCommand(makePathTurnoutName(sysNames[i], path.getName()));
            mi.addActionListener(openFrameAction);
            openTurnoutMenu.add(mi);
        }
    }
    _openMenu.add(openTurnoutPath);
}
Also used : OPath(jmri.jmrit.logix.OPath) Path(jmri.Path) ActionEvent(java.awt.event.ActionEvent) OBlockManager(jmri.jmrit.logix.OBlockManager) OPath(jmri.jmrit.logix.OPath) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) ActionListener(java.awt.event.ActionListener) TransferActionListener(jmri.util.com.sun.TransferActionListener) JMenuItem(javax.swing.JMenuItem) OBlock(jmri.jmrit.logix.OBlock) JMenu(javax.swing.JMenu)

Example 5 with OPath

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

the class EditCircuitPaths method findErrors.

private boolean findErrors() {
    boolean error = false;
    if (checkForSavePath()) {
        return true;
    }
    java.util.List<Path> list = _block.getPaths();
    if (list.size() == 0) {
        JOptionPane.showMessageDialog(this, Bundle.getMessage("noPaths", _block.getDisplayName()), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
    }
    for (int i = 0; i < list.size(); i++) {
        OPath path = (OPath) list.get(i);
        ArrayList<Positionable> pathGp = makePathGroup(path);
        if (pathGp.size() == 0) {
            error = true;
            break;
        }
        OPath p = makeOPath(path.getName(), pathGp, false);
        if (p == null) {
            error = true;
            break;
        }
    }
    if (error) {
        int result = JOptionPane.showConfirmDialog(this, Bundle.getMessage("hasPathErrors"), Bundle.getMessage("makePath"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (result == JOptionPane.YES_OPTION) {
            error = false;
        }
    }
    return error;
}
Also used : OPath(jmri.jmrit.logix.OPath) Path(jmri.Path) OPath(jmri.jmrit.logix.OPath) Positionable(jmri.jmrit.display.Positionable) Point(java.awt.Point)

Aggregations

OPath (jmri.jmrit.logix.OPath)16 Point (java.awt.Point)7 Portal (jmri.jmrit.logix.Portal)6 Path (jmri.Path)5 OBlock (jmri.jmrit.logix.OBlock)4 Element (org.jdom2.Element)4 JPanel (javax.swing.JPanel)3 BeanSetting (jmri.BeanSetting)3 Positionable (jmri.jmrit.display.Positionable)3 Dimension (java.awt.Dimension)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ArrayList (java.util.ArrayList)2 BoxLayout (javax.swing.BoxLayout)2 JButton (javax.swing.JButton)2 JLabel (javax.swing.JLabel)2 JScrollPane (javax.swing.JScrollPane)2 Turnout (jmri.Turnout)2 IndicatorTrack (jmri.jmrit.display.IndicatorTrack)2 OBlockManager (jmri.jmrit.logix.OBlockManager)2