Search in sources :

Example 36 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class DefaultSignalMastLogicManager method discoverSignallingDest.

/**
     * Discover valid destination Signal Masts for a given source Signal Mast on a
     * given Layout Editor Panel.
     *
     * @param source Source SignalMast
     * @param layout Layout Editor panel to check.
     */
@Override
public void discoverSignallingDest(SignalMast source, LayoutEditor layout) throws JmriException {
    firePropertyChange("autoSignalMastGenerateStart", null, source.getDisplayName());
    Hashtable<NamedBean, List<NamedBean>> validPaths = new Hashtable<NamedBean, List<NamedBean>>();
    jmri.jmrit.display.layoutEditor.LayoutBlockManager lbm = InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class);
    if (!lbm.isAdvancedRoutingEnabled()) {
        //log.debug("advanced routing not enabled");
        throw new JmriException("advanced routing not enabled");
    }
    if (!lbm.routingStablised()) {
        throw new JmriException("routing not stabilised");
    }
    try {
        validPaths.put(source, lbm.getLayoutBlockConnectivityTools().discoverPairDest(source, layout, SignalMast.class, LayoutBlockConnectivityTools.MASTTOMAST));
    } catch (JmriException e) {
        throw e;
    }
    Enumeration<NamedBean> en = validPaths.keys();
    while (en.hasMoreElements()) {
        SignalMast key = (SignalMast) en.nextElement();
        SignalMastLogic sml = getSignalMastLogic(key);
        if (sml == null) {
            sml = newSignalMastLogic(key);
        }
        List<NamedBean> validDestMast = validPaths.get(key);
        for (int i = 0; i < validDestMast.size(); i++) {
            if (!sml.isDestinationValid((SignalMast) validDestMast.get(i))) {
                try {
                    sml.setDestinationMast((SignalMast) validDestMast.get(i));
                    sml.useLayoutEditorDetails(true, true, (SignalMast) validDestMast.get(i));
                    sml.useLayoutEditor(true, (SignalMast) validDestMast.get(i));
                } catch (JmriException e) {
                    //log.debug("We shouldn't get an exception here");
                    log.error("Exception found when adding pair " + source.getDisplayName() + " to destination " + validDestMast.get(i).getDisplayName() + "\n" + e.toString());
                //throw e;
                }
            }
        }
        if (sml.getDestinationList().size() == 1 && sml.getAutoTurnouts(sml.getDestinationList().get(0)).size() == 0) {
            key.setProperty("intermediateSignal", true);
        } else {
            key.removeProperty("intermediateSignal");
        }
    }
    initialise();
    firePropertyChange("autoSignalMastGenerateComplete", null, source.getDisplayName());
}
Also used : NamedBean(jmri.NamedBean) Hashtable(java.util.Hashtable) JmriException(jmri.JmriException) SignalMastLogic(jmri.SignalMastLogic) DefaultSignalMastLogic(jmri.implementation.DefaultSignalMastLogic) SignalMast(jmri.SignalMast) ArrayList(java.util.ArrayList) List(java.util.List)

Example 37 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class DefaultSignalMastLogicManager method automaticallyDiscoverSignallingPairs.

/**
     * Discover all possible valid source + destination signal mast pairs
     * on all Layout Editor Panels.
     */
@Override
public void automaticallyDiscoverSignallingPairs() throws JmriException {
    runWhenStablised = false;
    jmri.jmrit.display.layoutEditor.LayoutBlockManager lbm = InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class);
    if (!lbm.isAdvancedRoutingEnabled()) {
        throw new JmriException("advanced routing not enabled");
    }
    if (!lbm.routingStablised()) {
        runWhenStablised = true;
        return;
    }
    Hashtable<NamedBean, ArrayList<NamedBean>> validPaths = lbm.getLayoutBlockConnectivityTools().discoverValidBeanPairs(null, SignalMast.class, LayoutBlockConnectivityTools.MASTTOMAST);
    Enumeration<NamedBean> en = validPaths.keys();
    firePropertyChange("autoGenerateUpdate", null, ("Found " + validPaths.size() + " masts as sources for logic"));
    for (NamedBean nb : InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBeanList()) {
        nb.removeProperty("intermediateSignal");
    }
    while (en.hasMoreElements()) {
        SignalMast key = (SignalMast) en.nextElement();
        SignalMastLogic sml = getSignalMastLogic(key);
        if (sml == null) {
            sml = newSignalMastLogic(key);
        }
        ArrayList<NamedBean> validDestMast = validPaths.get(key);
        for (int i = 0; i < validDestMast.size(); i++) {
            if (!sml.isDestinationValid((SignalMast) validDestMast.get(i))) {
                try {
                    sml.setDestinationMast((SignalMast) validDestMast.get(i));
                    sml.useLayoutEditorDetails(true, true, (SignalMast) validDestMast.get(i));
                    sml.useLayoutEditor(true, (SignalMast) validDestMast.get(i));
                } catch (jmri.JmriException ex) {
                    //log.debug("we shouldn't get an exception here!");
                    log.debug(ex.getLocalizedMessage(), ex);
                }
            }
        }
        if (sml.getDestinationList().size() == 1 && sml.getAutoTurnouts(sml.getDestinationList().get(0)).size() == 0) {
            key.setProperty("intermediateSignal", true);
        }
    }
    initialise();
    firePropertyChange("autoGenerateComplete", null, null);
}
Also used : NamedBean(jmri.NamedBean) JmriException(jmri.JmriException) ArrayList(java.util.ArrayList) JmriException(jmri.JmriException) SignalMastLogic(jmri.SignalMastLogic) DefaultSignalMastLogic(jmri.implementation.DefaultSignalMastLogic) SignalMast(jmri.SignalMast)

Example 38 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class AbstractManager method vetoableChange.

@Override
@OverridingMethodsMustInvokeSuper
public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
    if ("CanDelete".equals(evt.getPropertyName())) {
        //IN18N
        StringBuilder message = new StringBuilder();
        message.append(Bundle.getMessage("VetoFoundIn", getBeanTypeHandled())).append("<ul>");
        boolean found = false;
        for (NamedBean nb : _tsys.values()) {
            try {
                nb.vetoableChange(evt);
            } catch (PropertyVetoException e) {
                if (e.getPropertyChangeEvent().getPropertyName().equals("DoNotDelete")) {
                    //IN18N
                    throw e;
                }
                found = true;
                message.append("<li>").append(e.getMessage()).append("</li>");
            }
        }
        message.append("</ul>").append(Bundle.getMessage("VetoWillBeRemovedFrom", getBeanTypeHandled()));
        if (found) {
            throw new PropertyVetoException(message.toString(), evt);
        }
    } else {
        for (NamedBean nb : _tsys.values()) {
            try {
                nb.vetoableChange(evt);
            } catch (PropertyVetoException e) {
                throw e;
            }
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) NamedBean(jmri.NamedBean) OverridingMethodsMustInvokeSuper(javax.annotation.OverridingMethodsMustInvokeSuper)

Example 39 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class DefaultSignalMastLogicManager method generateSection.

/**
     * Populate Sections of type SIGNALMASTLOGIC used with Layout Editor with Signal Mast attributes
     * as stored in Signal Mast Logic.
     */
public void generateSection() {
    SectionManager sm = InstanceManager.getDefault(jmri.SectionManager.class);
    for (NamedBean nb : sm.getNamedBeanList()) {
        if (((Section) nb).getSectionType() == Section.SIGNALMASTLOGIC) {
            nb.removeProperty("intermediateSection");
        }
        nb.removeProperty("forwardMast");
    }
    for (SignalMastLogic sml : getSignalMastLogicList()) {
        jmri.jmrit.display.layoutEditor.LayoutBlock faceLBlock = sml.getFacingBlock();
        if (faceLBlock != null) {
            boolean sourceIntermediate = false;
            if (sml.getSourceMast().getProperty("intermediateSignal") != null) {
                sourceIntermediate = ((Boolean) sml.getSourceMast().getProperty("intermediateSignal")).booleanValue();
            }
            for (SignalMast destMast : sml.getDestinationList()) {
                if (sml.getAutoBlocksBetweenMasts(destMast).size() != 0) {
                    Section sec = sm.createNewSection(sml.getSourceMast().getDisplayName() + ":" + destMast.getDisplayName());
                    if (sec == null) {
                        //A Section already exists, lets grab it and check that it is one used with the SML, if so carry on using that.
                        sec = sm.getSection(sml.getSourceMast().getDisplayName() + ":" + destMast.getDisplayName());
                        if (sec.getSectionType() != Section.SIGNALMASTLOGIC) {
                            break;
                        }
                    } else {
                        sec.setSectionType(Section.SIGNALMASTLOGIC);
                        try {
                            //Auto running requires forward/reverse sensors, but at this stage SML does not support that, so just create dummy internal ones for now.
                            Sensor sen = InstanceManager.sensorManagerInstance().provideSensor("IS:" + sec.getSystemName() + ":forward");
                            sen.setUserName(sec.getSystemName() + ":forward");
                            sen = InstanceManager.sensorManagerInstance().provideSensor("IS:" + sec.getSystemName() + ":reverse");
                            sen.setUserName(sec.getSystemName() + ":reverse");
                            sec.setForwardBlockingSensorName(sec.getSystemName() + ":forward");
                            sec.setReverseBlockingSensorName(sec.getSystemName() + ":reverse");
                        } catch (IllegalArgumentException ex) {
                            log.warn("Failed to provide Sensor in generateSection");
                        }
                    }
                    sml.setAssociatedSection(sec, destMast);
                    sec.setProperty("forwardMast", destMast.getDisplayName());
                    boolean destIntermediate = false;
                    if (destMast.getProperty("intermediateSignal") != null) {
                        destIntermediate = ((Boolean) destMast.getProperty("intermediateSignal")).booleanValue();
                    }
                    if (sourceIntermediate || destIntermediate) {
                        sec.setProperty("intermediateSection", true);
                    } else {
                        sec.setProperty("intermediateSection", false);
                    }
                //Not 100% sure about this for now so will comment out
                //sml.addSensor(sec.getSystemName()+":forward", Sensor.INACTIVE, destMast);
                }
            }
        } else {
            log.info("No facing block found " + sml.getSourceMast().getDisplayName());
        }
    }
}
Also used : SectionManager(jmri.SectionManager) NamedBean(jmri.NamedBean) SignalMastLogic(jmri.SignalMastLogic) DefaultSignalMastLogic(jmri.implementation.DefaultSignalMastLogic) SignalMast(jmri.SignalMast) Section(jmri.Section) Sensor(jmri.Sensor)

Example 40 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class AbstractProxyManager method getNamedBeanList.

@Override
public List<NamedBean> getNamedBeanList() {
    TreeSet<NamedBean> ts = new TreeSet<>(new SystemNameComparator());
    mgrs.stream().forEach((m) -> {
        ts.addAll(m.getNamedBeanList());
    });
    return new ArrayList<>(ts);
}
Also used : NamedBean(jmri.NamedBean) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) SystemNameComparator(jmri.util.SystemNameComparator)

Aggregations

NamedBean (jmri.NamedBean)104 ArrayList (java.util.ArrayList)18 JTextField (javax.swing.JTextField)12 JmriException (jmri.JmriException)12 SignalMast (jmri.SignalMast)12 JTable (javax.swing.JTable)11 Manager (jmri.Manager)9 Sensor (jmri.Sensor)9 JButton (javax.swing.JButton)8 InstanceManager (jmri.InstanceManager)8 JComboBox (javax.swing.JComboBox)7 MouseEvent (java.awt.event.MouseEvent)6 Hashtable (java.util.Hashtable)6 SignalHead (jmri.SignalHead)6 Turnout (jmri.Turnout)6 OBlock (jmri.jmrit.logix.OBlock)5 File (java.io.File)4 JLabel (javax.swing.JLabel)4 TableCellEditor (javax.swing.table.TableCellEditor)4 TableCellRenderer (javax.swing.table.TableCellRenderer)4