use of jmri.SignalMast in project JMRI by JMRI.
the class LayoutBlockConnectivityTools method getBeansInPath.
/**
* Returns a list of NamedBeans (Signalhead, Signalmast or Sensor) that are
* assinged to block boundaries in a given list
*
* @param blocklist The list of block in order that need to be checked.
* @param panel (Optional) panel that the blocks need to be checked
* against
* @param T (Optional) the class that we want to check against,
* either Sensor, SignalMast or SignalHead, set null will
* return any.
*/
public List<NamedBean> getBeansInPath(List<LayoutBlock> blocklist, LayoutEditor panel, Class<?> T) {
ArrayList<NamedBean> beansInPath = new ArrayList<NamedBean>();
if (blocklist.size() >= 2) {
LayoutBlockManager lbm = InstanceManager.getDefault(LayoutBlockManager.class);
for (int x = 1; x < blocklist.size(); x++) {
LayoutBlock facingBlock = blocklist.get(x - 1);
LayoutBlock protectingBlock = blocklist.get(x);
NamedBean nb = null;
if (T == null) {
nb = lbm.getFacingNamedBean(facingBlock.getBlock(), protectingBlock.getBlock(), panel);
} else if (T.equals(jmri.SignalMast.class)) {
nb = lbm.getFacingSignalMast(facingBlock.getBlock(), protectingBlock.getBlock(), panel);
} else if (T.equals(jmri.Sensor.class)) {
nb = lbm.getFacingSensor(facingBlock.getBlock(), protectingBlock.getBlock(), panel);
} else if (T.equals(jmri.SignalHead.class)) {
nb = lbm.getFacingSignalHead(facingBlock.getBlock(), protectingBlock.getBlock());
}
if (nb != null) {
beansInPath.add(nb);
}
}
}
return beansInPath;
}
use of jmri.SignalMast in project JMRI by JMRI.
the class SignalMastRepeaterPanel method setSlaveBoxLists.
void setSlaveBoxLists() {
SignalMast masterMast = (SignalMast) _MasterBox.getSelectedBean();
if (masterMast == null) {
_SlaveBox.setEnabled(false);
_addRepeater.setEnabled(false);
return;
}
java.util.Iterator<String> iter = dsmm.getSystemNameList().iterator();
// don't return an element if there are not sensors to include
if (!iter.hasNext()) {
return;
}
ArrayList<NamedBean> excludeList = new ArrayList<NamedBean>();
while (iter.hasNext()) {
String mname = iter.next();
if (mname != null) {
SignalMast s = dsmm.getBySystemName(mname);
if (s.getAppearanceMap() != masterMast.getAppearanceMap()) {
excludeList.add(s);
} else if (s == masterMast) {
excludeList.add(s);
}
}
}
_SlaveBox.excludeItems(excludeList);
if (excludeList.size() == dsmm.getSystemNameList().size()) {
_SlaveBox.setEnabled(false);
_addRepeater.setEnabled(false);
} else {
_SlaveBox.setEnabled(true);
_addRepeater.setEnabled(true);
}
}
use of jmri.SignalMast in project JMRI by JMRI.
the class AutoActiveTrain method setupNewCurrentSignal.
protected synchronized void setupNewCurrentSignal(AllocatedSection as) {
removeCurrentSignal();
if (DispatcherFrame.instance().getSignalType() == DispatcherFrame.SIGNALHEAD) {
SignalHead sh = _lbManager.getFacingSignalHead(_currentBlock, _nextBlock);
if (sh != null) {
_controllingSignal = sh;
_conSignalProtectedBlock = _nextBlock;
sh.addPropertyChangeListener(_conSignalListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
if (e.getPropertyName().equals("Appearance")) {
// controlling signal has changed appearance
setSpeedBySignal();
if (_stoppingForStopSignal && (_targetSpeed > 0.0)) {
cancelStopInCurrentSection();
_stoppingForStopSignal = false;
}
}
}
});
if (log.isDebugEnabled()) {
log.debug("new current signal = " + sh.getSystemName());
}
setSpeedBySignal();
} else // Note: null signal head will result when exiting throat-to-throat blocks.
if (log.isDebugEnabled()) {
log.debug("new current signal is null - sometimes OK");
}
} else {
//SignalMast
SignalMast sm = null;
Block cB = _currentBlock;
Block nB = _nextBlock;
if (as == null) {
as = _currentAllocatedSection;
}
//}
while (sm == null && nB != null) {
sm = _lbManager.getFacingSignalMast(cB, nB);
if (sm == null) {
cB = nB;
nB = getNextBlock(nB, as);
}
}
if (sm != null) {
_controllingSignalMast = sm;
_conSignalProtectedBlock = nB;
sm.addPropertyChangeListener(_conSignalMastListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
if (e.getPropertyName().equals("Aspect")) {
// controlling signal has changed appearance
if (_stoppingForStopSignal && (_targetSpeed > 0.0)) {
cancelStopInCurrentSection();
_stoppingForStopSignal = false;
}
setSpeedBySignal();
} else if (e.getPropertyName().equals("Held")) {
if (!((Boolean) e.getNewValue())) {
cancelStopInCurrentSection();
_stoppingForStopSignal = false;
}
setSpeedBySignal();
}
}
});
log.debug("{}: new current signalmast {}({}) for section {}", _activeTrain.getTrainName(), sm.getDisplayName(), sm.getAspect(), as.getSectionName());
setSpeedBySignal();
} else // Note: null signal head will result when exiting throat-to-throat blocks.
{
log.debug("{}: new current signalmast is null for section {} - sometimes OK", _activeTrain.getTrainName(), as.getSectionName());
}
}
}
use of jmri.SignalMast in project JMRI by JMRI.
the class TransitCreationTool method createTransit.
public Transit createTransit() throws JmriException {
TransitManager tm = InstanceManager.getDefault(jmri.TransitManager.class);
String transitName = "From " + list.get(0).getDisplayName() + " to " + list.get(list.size() - 1).getDisplayName();
Transit t = tm.createNewTransit(transitName);
if (t == null) {
log.error("Unable to create transit " + transitName);
throw new JmriException(Bundle.getMessage("TCTErrorUnableToCreate", transitName));
}
if (list.get(0) instanceof SignalMast) {
jmri.SignalMastLogicManager smlm = InstanceManager.getDefault(jmri.SignalMastLogicManager.class);
for (int i = 1; i <= list.size() - 1; i++) {
jmri.SignalMastLogic sml = smlm.getSignalMastLogic((SignalMast) list.get(i - 1));
Section sec = sml.getAssociatedSection((SignalMast) list.get(i));
//In theory sec being null would already have been tested when the signal was added.
if (sec == null) {
String error = Bundle.getMessage("TCTErrorMastPairsNoSection", list.get(i - 1).getDisplayName(), list.get(i).getDisplayName());
log.error(error);
tm.deregister(t);
t.dispose();
cancelTransitCreate();
throw new JmriException(error);
}
t.addTransitSection(new jmri.TransitSection(sec, i, Section.FORWARD));
}
}
//Once created clear the list for a fresh start.
list = new ArrayList<NamedBean>();
return t;
}
use of jmri.SignalMast in project JMRI by JMRI.
the class EntryExitPairsXml method store.
/**
* Default implementation for storing the contents of a PositionablePoint.
*
* @param o Object to store, of type PositionablePoint
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
EntryExitPairs p = (EntryExitPairs) o;
Element element = new Element("entryexitpairs");
setStoreElementClass(element);
ArrayList<LayoutEditor> editors = p.getSourcePanelList();
if (editors.size() == 0) {
return element;
}
element.addContent(new Element("cleardown").addContent("" + p.getClearDownOption()));
if (p.getDispatcherIntegration()) {
element.addContent(new Element("dispatcherintegration").addContent("yes"));
}
if (p.useDifferentColorWhenSetting()) {
element.addContent(new Element("colourwhilesetting").addContent(colorToString(p.getSettingRouteColor())));
element.addContent(new Element("settingTimer").addContent("" + p.getSettingTimer()));
}
for (int k = 0; k < editors.size(); k++) {
LayoutEditor panel = editors.get(k);
List<Object> nxpair = p.getSourceList(panel);
Element panelElem = new Element("layoutPanel");
panelElem.setAttribute("name", panel.getLayoutName());
for (int j = 0; j < nxpair.size(); j++) {
Object key = nxpair.get(j);
Element source = new Element("source");
String type = "";
String item = "";
if (key instanceof SignalMast) {
type = "signalMast";
item = ((SignalMast) key).getDisplayName();
} else if (key instanceof Sensor) {
type = "sensor";
item = ((Sensor) key).getDisplayName();
} else if (key instanceof SignalHead) {
type = "signalHead";
item = ((SignalHead) key).getDisplayName();
}
source.setAttribute("type", type);
source.setAttribute("item", item);
ArrayList<Object> a = p.getDestinationList(key, panel);
for (int i = 0; i < a.size(); i++) {
Object keyDest = a.get(i);
String typeDest = "";
String itemDest = "";
if (keyDest instanceof SignalMast) {
typeDest = "signalMast";
itemDest = ((SignalMast) keyDest).getDisplayName();
} else if (keyDest instanceof Sensor) {
typeDest = "sensor";
itemDest = ((Sensor) keyDest).getDisplayName();
} else if (keyDest instanceof SignalHead) {
typeDest = "signalHead";
itemDest = ((SignalHead) keyDest).getDisplayName();
}
Element dest = new Element("destination");
dest.setAttribute("type", typeDest);
dest.setAttribute("item", itemDest);
if (!p.isUniDirection(key, panel, keyDest)) {
dest.setAttribute("uniDirection", "no");
}
if (!p.isEnabled(key, panel, keyDest)) {
dest.setAttribute("enabled", "no");
}
int nxType = p.getEntryExitType(key, panel, keyDest);
switch(nxType) {
case 0x00:
dest.setAttribute("nxType", "turnoutsetting");
break;
case 0x01:
dest.setAttribute("nxType", "signalmastlogic");
break;
case 0x02:
dest.setAttribute("nxType", "fullinterlocking");
break;
default:
dest.setAttribute("nxType", "turnoutsetting");
break;
}
if (p.getUniqueId(key, panel, keyDest) != null) {
dest.setAttribute("uniqueid", p.getUniqueId(key, panel, keyDest));
}
source.addContent(dest);
}
panelElem.addContent(source);
}
element.addContent(panelElem);
}
return element;
}
Aggregations