Search in sources :

Example 71 with SignalMast

use of jmri.SignalMast in project JMRI by JMRI.

the class DefaultSignalMastLogic method checkStates.

/**
     * Check if routes to the destination Signal Mast are clear.
     *
     * @return true if the path to the next signal is clear
     */
boolean checkStates() {
    SignalMast oldActiveMast = destination;
    if (destination != null) {
        firePropertyChange("state", oldActiveMast, null);
        log.debug("Remove listener from destination");
        destination.removePropertyChangeListener(propertyDestinationMastListener);
        if (destList.containsKey(destination)) {
            destList.get(destination).clearTurnoutLock();
        }
    }
    Enumeration<SignalMast> en = destList.keys();
    log.debug("checkStates enumerates over {} masts", destList.size());
    while (en.hasMoreElements()) {
        SignalMast key = en.nextElement();
        log.debug("  Destination mast {}", key.getDisplayName());
        log.debug("    isEnabled: {}", (destList.get(key)).isEnabled());
        log.debug("    isActive: {}", destList.get(key).isActive());
        if ((destList.get(key)).isEnabled() && (destList.get(key).isActive())) {
            destination = key;
            log.debug("      Add listener to destination");
            destination.addPropertyChangeListener(propertyDestinationMastListener);
            log.debug("      firePropertyChange: \"state\"");
            firePropertyChange("state", oldActiveMast, destination);
            destList.get(key).lockTurnouts();
            return true;
        }
    }
    return false;
}
Also used : SignalMast(jmri.SignalMast)

Example 72 with SignalMast

use of jmri.SignalMast in project JMRI by JMRI.

the class DefaultSignalMastLogic method vetoableChange.

//@todo need to think how we deal with auto generated lists based upon the layout editor.
@Override
public void vetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException {
    NamedBean nb = (NamedBean) evt.getOldValue();
    if ("CanDelete".equals(evt.getPropertyName())) {
        //NOI18N
        boolean found = false;
        StringBuilder message = new StringBuilder();
        if (nb instanceof SignalMast) {
            if (nb.equals(source)) {
                message.append("Has SignalMast Logic attached which will be <b>Deleted</b> to <ul>");
                for (SignalMast sm : getDestinationList()) {
                    message.append("<li>");
                    message.append(sm.getDisplayName());
                    message.append("</li>");
                }
                message.append("</ul>");
                throw new java.beans.PropertyVetoException(message.toString(), evt);
            } else if (isDestinationValid((SignalMast) nb)) {
                throw new java.beans.PropertyVetoException("Is the end point mast for logic attached to signal mast " + source.getDisplayName() + " which will be <b>Deleted</b> ", evt);
            }
            for (SignalMast sm : getDestinationList()) {
                if (isSignalMastIncluded((SignalMast) nb, sm)) {
                    message.append("<li>");
                    message.append("Used in conflicting logic of " + source.getDisplayName() + " & " + sm.getDisplayName());
                    message.append("</li>");
                }
            }
        }
        if (nb instanceof Turnout) {
            for (SignalMast sm : getDestinationList()) {
                if (isTurnoutIncluded((Turnout) nb, sm)) {
                    message.append("<li>Is in logic between Signal Masts " + source.getDisplayName() + " " + sm.getDisplayName() + "</li>");
                    found = true;
                }
            }
        }
        if (nb instanceof Sensor) {
            for (SignalMast sm : getDestinationList()) {
                if (isSensorIncluded((Sensor) nb, sm)) {
                    message.append("<li>");
                    message.append("Is in logic between Signal Masts " + source.getDisplayName() + " " + sm.getDisplayName());
                    message.append("</li>");
                    found = true;
                }
            }
        }
        if (found) {
            throw new java.beans.PropertyVetoException(message.toString(), evt);
        }
    } else if ("DoDelete".equals(evt.getPropertyName())) {
        //IN18N
        if (nb instanceof SignalMast) {
            if (nb.equals(source)) {
                dispose();
            }
            if (isDestinationValid((SignalMast) nb)) {
                removeDestination((SignalMast) nb);
            }
            for (SignalMast sm : getDestinationList()) {
                if (isSignalMastIncluded((SignalMast) nb, sm)) {
                    log.warn("Unhandled condition: signal mast included during DoDelete");
                // @todo need to deal with this situation
                }
            }
        }
        if (nb instanceof Turnout) {
            Turnout t = (Turnout) nb;
            for (SignalMast sm : getDestinationList()) {
                if (isTurnoutIncluded(t, sm)) {
                    removeTurnout(t, sm);
                }
            }
        }
        if (nb instanceof Sensor) {
            Sensor s = (Sensor) nb;
            for (SignalMast sm : getDestinationList()) {
                if (isSensorIncluded(s, sm)) {
                    removeSensor(s, sm);
                }
            }
        }
    }
}
Also used : NamedBean(jmri.NamedBean) SignalMast(jmri.SignalMast) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Example 73 with SignalMast

use of jmri.SignalMast in project JMRI by JMRI.

the class DefaultSignalMastLogic method replaceSourceMast.

@Override
public void replaceSourceMast(SignalMast oldMast, SignalMast newMast) {
    if (oldMast != source) {
        //Old mast does not match new mast so will exit
        return;
    }
    source.removePropertyChangeListener(propertySourceMastListener);
    source = newMast;
    stopAspect = source.getAppearanceMap().getSpecificAppearance(jmri.SignalAppearanceMap.DANGER);
    source.addPropertyChangeListener(propertySourceMastListener);
    if (source.getAspect() == null) {
        source.setAspect(stopAspect);
    }
    for (SignalMast sm : getDestinationList()) {
        DestinationMast destMast = destList.get(sm);
        if (destMast.getAssociatedSection() != null) {
            String oldUserName = destMast.getAssociatedSection().getUserName();
            String newUserName = source.getDisplayName() + ":" + sm.getDisplayName();
            jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).renameBean(oldUserName, newUserName, ((NamedBean) destMast.getAssociatedSection()));
        }
    }
    firePropertyChange("updatedSource", oldMast, newMast);
}
Also used : NamedBean(jmri.NamedBean) SignalMast(jmri.SignalMast)

Example 74 with SignalMast

use of jmri.SignalMast in project JMRI by JMRI.

the class JsonSignalMastServer method parseRequest.

public void parseRequest(Locale locale, JsonNode data) throws JmriException, IOException, JsonException {
    String name = data.path(NAME).asText();
    String state = data.path(STATE).asText();
    if ("".equals(state)) {
        //if not passed, retrieve current and respond
        SignalMast sm = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name);
        try {
            state = sm.getAspect();
            if (state == null) {
                //if null, set state to "Unknown"   
                state = ASPECT_UNKNOWN;
            }
            if ((sm.getHeld()) && (sm.getAppearanceMap().getSpecificAppearance(jmri.SignalAppearanceMap.HELD) != null)) {
                state = ASPECT_HELD;
            } else if ((!sm.getLit()) && (sm.getAppearanceMap().getSpecificAppearance(jmri.SignalAppearanceMap.DARK) != null)) {
                state = ASPECT_DARK;
            }
            this.sendStatus(name, state);
        } catch (IOException ex) {
            this.sendErrorStatus(name);
        } catch (NullPointerException e) {
            log.error("Unable to get signalMast [{}].", name);
            throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", SIGNAL_MAST, name));
        }
    } else {
        //else set the aspect to the state passed in
        this.setSignalMastAspect(name, state);
    }
    this.addSignalMastToList(name);
}
Also used : JsonException(jmri.server.json.JsonException) SignalMast(jmri.SignalMast) IOException(java.io.IOException)

Example 75 with SignalMast

use of jmri.SignalMast in project JMRI by JMRI.

the class TransitTableAction method validateSignal.

private boolean validateSignal(String sName, boolean when) {
    // check if anything entered
    if (sName.length() < 1) {
        // no sensor entered
        JOptionPane.showMessageDialog(addEditActionFrame, (rbx.getString("NoSignalError")), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        return false;
    }
    // get the signalMast or signalHead corresponding to this name
    SignalMast sm = null;
    SignalHead sh = null;
    sm = InstanceManager.getDefault(SignalMastManager.class).getSignalMast(sName);
    if (sm == null) {
        sh = InstanceManager.getDefault(SignalHeadManager.class).getSignalHead(sName);
    }
    if (sm == null && sh == null) {
        // There is no signal corresponding to this name
        JOptionPane.showMessageDialog(addEditActionFrame, (rbx.getString("SignalEntryError")), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        return false;
    }
    return true;
}
Also used : SignalMast(jmri.SignalMast) SignalHead(jmri.SignalHead)

Aggregations

SignalMast (jmri.SignalMast)80 Test (org.junit.Test)19 NamedBean (jmri.NamedBean)11 Sensor (jmri.Sensor)11 SignalHead (jmri.SignalHead)11 Turnout (jmri.Turnout)10 SignalMastManager (jmri.SignalMastManager)9 JsonException (jmri.server.json.JsonException)9 ArrayList (java.util.ArrayList)8 JmriException (jmri.JmriException)8 Block (jmri.Block)7 SignalMastLogic (jmri.SignalMastLogic)7 Hashtable (java.util.Hashtable)6 Element (org.jdom2.Element)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 IOException (java.io.IOException)4 NamedBeanHandle (jmri.NamedBeanHandle)4 Section (jmri.Section)4 LayoutTurnout (jmri.jmrit.display.layoutEditor.LayoutTurnout)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3