Search in sources :

Example 1 with SignalMastLogic

use of jmri.SignalMastLogic in project JMRI by JMRI.

the class DefaultSignalMastLogicManager method swapSignalMasts.

@Override
public void swapSignalMasts(SignalMast mastA, SignalMast mastB) {
    if (mastA == null || mastB == null) {
        return;
    }
    ArrayList<SignalMastLogic> mastALogicList = getLogicsByDestination(mastA);
    SignalMastLogic mastALogicSource = getSignalMastLogic(mastA);
    ArrayList<SignalMastLogic> mastBLogicList = getLogicsByDestination(mastB);
    SignalMastLogic mastBLogicSource = getSignalMastLogic(mastB);
    if (mastALogicSource != null) {
        mastALogicSource.replaceSourceMast(mastA, mastB);
    }
    if (mastBLogicSource != null) {
        mastBLogicSource.replaceSourceMast(mastB, mastA);
    }
    for (SignalMastLogic mastALogic : mastALogicList) {
        mastALogic.replaceDestinationMast(mastA, mastB);
    }
    for (SignalMastLogic mastBLogic : mastBLogicList) {
        mastBLogic.replaceDestinationMast(mastB, mastA);
    }
}
Also used : SignalMastLogic(jmri.SignalMastLogic) DefaultSignalMastLogic(jmri.implementation.DefaultSignalMastLogic)

Example 2 with SignalMastLogic

use of jmri.SignalMastLogic 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 3 with SignalMastLogic

use of jmri.SignalMastLogic 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 4 with SignalMastLogic

use of jmri.SignalMastLogic in project JMRI by JMRI.

the class DefaultSignalMastLogicManager method vetoableChange.

@Override
public void vetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException {
    if ("CanDelete".equals(evt.getPropertyName())) {
        //NOI18N
        StringBuilder message = new StringBuilder();
        boolean found = false;
        message.append(Bundle.getMessage("VetoFoundInSignalMastLogic"));
        message.append("<ul>");
        for (int i = 0; i < signalMastLogic.size(); i++) {
            try {
                signalMastLogic.get(i).vetoableChange(evt);
            } catch (java.beans.PropertyVetoException e) {
                if (e.getPropertyChangeEvent().getPropertyName().equals("DoNotDelete")) {
                    //NOI18N
                    throw e;
                }
                found = true;
                message.append(e.getMessage());
                message.append("<br>");
            }
        }
        message.append("</ul>");
        if (found) {
            throw new java.beans.PropertyVetoException(message.toString(), evt);
        }
    } else {
        for (SignalMastLogic sml : signalMastLogic) {
            try {
                sml.vetoableChange(evt);
            } catch (java.beans.PropertyVetoException e) {
                throw e;
            }
        }
    }
}
Also used : SignalMastLogic(jmri.SignalMastLogic) DefaultSignalMastLogic(jmri.implementation.DefaultSignalMastLogic)

Example 5 with SignalMastLogic

use of jmri.SignalMastLogic 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)

Aggregations

SignalMastLogic (jmri.SignalMastLogic)12 SignalMast (jmri.SignalMast)7 DefaultSignalMastLogic (jmri.implementation.DefaultSignalMastLogic)6 Hashtable (java.util.Hashtable)4 NamedBean (jmri.NamedBean)4 ArrayList (java.util.ArrayList)3 NamedBeanHandle (jmri.NamedBeanHandle)3 Sensor (jmri.Sensor)3 SignalMastLogicManager (jmri.SignalMastLogicManager)3 Block (jmri.Block)2 JmriException (jmri.JmriException)2 Section (jmri.Section)2 Turnout (jmri.Turnout)2 Element (org.jdom2.Element)2 MouseEvent (java.awt.event.MouseEvent)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 Enumeration (java.util.Enumeration)1 List (java.util.List)1 JButton (javax.swing.JButton)1 JTable (javax.swing.JTable)1