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());
}
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);
}
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;
}
}
}
}
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());
}
}
}
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);
}
Aggregations