use of jmri.SignalHead 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;
}
use of jmri.SignalHead in project JMRI by JMRI.
the class DestinationPoints method setRoute.
//For a clear down we need to add a message, if it is a cancel, manual clear down or I didn't mean it.
void setRoute(boolean state) {
if (log.isDebugEnabled()) {
log.debug("Set route " + src.getPoint().getDisplayName());
}
if (disposed) {
log.error("Set route called even though interlock has been disposed of");
return;
}
if (routeDetails == null) {
log.error("No route to set or clear down");
setActiveEntryExit(false);
setRouteTo(false);
setRouteFrom(false);
if ((getSignal() instanceof SignalMast) && (getEntryExitType() != EntryExitPairs.FULLINTERLOCK)) {
SignalMast mast = (SignalMast) getSignal();
mast.setHeld(false);
}
synchronized (this) {
destination = null;
}
return;
}
if (!state) {
switch(manager.getClearDownOption()) {
case EntryExitPairs.PROMPTUSER:
cancelClearOptionBox();
break;
case EntryExitPairs.AUTOCANCEL:
cancelClearInterlock(EntryExitPairs.CANCELROUTE);
break;
case EntryExitPairs.AUTOCLEAR:
cancelClearInterlock(EntryExitPairs.CLEARROUTE);
break;
default:
cancelClearOptionBox();
break;
}
if (log.isDebugEnabled()) {
log.debug("Exit " + src.getPoint().getDisplayName());
}
return;
}
if (manager.isRouteStacked(this, false)) {
manager.cancelStackedRoute(this, false);
}
/* We put the setting of the route into a seperate thread and put a glass pane in front of the layout editor.
The swing thread for flashing the icons will carry on without interuption. */
final ArrayList<Color> realColorStd = new ArrayList<Color>();
final ArrayList<Color> realColorXtra = new ArrayList<Color>();
final ArrayList<LayoutBlock> routeBlocks = new ArrayList<LayoutBlock>();
if (manager.useDifferentColorWhenSetting()) {
for (LayoutBlock lbk : routeDetails) {
routeBlocks.add(lbk);
realColorXtra.add(lbk.getBlockExtraColor());
realColorStd.add(lbk.getBlockTrackColor());
lbk.setBlockExtraColor(manager.getSettingRouteColor());
lbk.setBlockTrackColor(manager.getSettingRouteColor());
}
//Force a redraw, to reflect color change
src.getPoint().getPanel().redrawPanel();
}
ActiveTrain tmpat = null;
if (manager.getDispatcherIntegration() && jmri.InstanceManager.getNullableDefault(jmri.jmrit.dispatcher.DispatcherFrame.class) != null) {
jmri.jmrit.dispatcher.DispatcherFrame df = jmri.InstanceManager.getDefault(jmri.jmrit.dispatcher.DispatcherFrame.class);
for (ActiveTrain atl : df.getActiveTrainsList()) {
if (atl.getEndBlock() == src.getStart().getBlock()) {
if (atl.getLastAllocatedSection() == atl.getEndBlockSection()) {
if (!atl.getReverseAtEnd() && !atl.getResetWhenDone()) {
tmpat = atl;
break;
}
log.warn("Interlock will not be added to existing Active Train as it is set for back and forth operation");
}
}
}
}
final ActiveTrain at = tmpat;
Runnable setRouteRun = new Runnable() {
@Override
public void run() {
src.getPoint().getPanel().getGlassPane().setVisible(true);
try {
Hashtable<Turnout, Integer> turnoutSettings = new Hashtable<Turnout, Integer>();
ConnectivityUtil connection = new ConnectivityUtil(point.getPanel());
// Last block in the route is the one that we are protecting at the last sensor/signalmast
for (int i = 0; i < routeDetails.size(); i++) {
//if we are not using the dispatcher and the signal logic is dynamic, then set the turnouts
if (at == null && isSignalLogicDynamic()) {
if (i > 0) {
ArrayList<LayoutTurnout> turnoutlist;
int nxtBlk = i + 1;
int preBlk = i - 1;
if (i < routeDetails.size() - 1) {
turnoutlist = connection.getTurnoutList(routeDetails.get(i).getBlock(), routeDetails.get(preBlk).getBlock(), routeDetails.get(nxtBlk).getBlock());
ArrayList<Integer> throwlist = connection.getTurnoutSettingList();
for (int x = 0; x < turnoutlist.size(); x++) {
if (turnoutlist.get(x) instanceof LayoutSlip) {
int slipState = throwlist.get(x);
LayoutSlip ls = (LayoutSlip) turnoutlist.get(x);
int taState = ls.getTurnoutState(slipState);
turnoutSettings.put(ls.getTurnout(), taState);
int tbState = ls.getTurnoutBState(slipState);
ls.getTurnoutB().setCommandedState(tbState);
turnoutSettings.put(ls.getTurnoutB(), tbState);
} else {
String t = turnoutlist.get(x).getTurnoutName();
Turnout turnout = InstanceManager.turnoutManagerInstance().getTurnout(t);
turnoutSettings.put(turnout, throwlist.get(x));
if (turnoutlist.get(x).getSecondTurnout() != null) {
turnoutSettings.put(turnoutlist.get(x).getSecondTurnout(), throwlist.get(x));
}
}
}
}
}
}
if ((getEntryExitType() == EntryExitPairs.FULLINTERLOCK)) {
// was set against occupancy sensor
routeDetails.get(i).getBlock().addPropertyChangeListener(propertyBlockListener);
if (i > 0) {
routeDetails.get(i).setUseExtraColor(true);
}
} else {
// was set against occupancy sensor
routeDetails.get(i).getBlock().removePropertyChangeListener(propertyBlockListener);
}
}
if (at == null) {
if (!isSignalLogicDynamic()) {
jmri.SignalMastLogic tmSml = InstanceManager.getDefault(jmri.SignalMastLogicManager.class).getSignalMastLogic((SignalMast) src.sourceSignal);
for (Turnout t : tmSml.getAutoTurnouts((SignalMast) getSignal())) {
turnoutSettings.put(t, tmSml.getAutoTurnoutState(t, (SignalMast) getSignal()));
}
}
for (Map.Entry<Turnout, Integer> entry : turnoutSettings.entrySet()) {
entry.getKey().setCommandedState(entry.getValue());
Runnable r = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(250 + manager.turnoutSetDelay);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
};
Thread thr = new Thread(r, "Entry Exit Route, turnout setting");
thr.start();
try {
thr.join();
} catch (InterruptedException ex) {
// log.info("interrupted at join " + ex);
}
}
}
src.getPoint().getPanel().redrawPanel();
if (getEntryExitType() != EntryExitPairs.SETUPTURNOUTSONLY) {
if (getEntryExitType() == EntryExitPairs.FULLINTERLOCK) {
//If our start block is already active we will set it as our lastSeenActiveBlock.
if (src.getStart().getState() == Block.OCCUPIED) {
src.getStart().removePropertyChangeListener(propertyBlockListener);
lastSeenActiveBlockObject = src.getStart().getBlock().getValue();
log.debug("Last seen value " + lastSeenActiveBlockObject);
}
}
if ((src.sourceSignal instanceof SignalMast) && (getSignal() instanceof SignalMast)) {
SignalMast smSource = (SignalMast) src.sourceSignal;
SignalMast smDest = (SignalMast) getSignal();
synchronized (this) {
sml = InstanceManager.getDefault(jmri.SignalMastLogicManager.class).newSignalMastLogic(smSource);
if (!sml.isDestinationValid(smDest)) {
//if no signalmastlogic existed then created it, but set it not to be stored.
sml.setDestinationMast(smDest);
sml.setStore(jmri.SignalMastLogic.STORENONE, smDest);
}
}
//Remove the first block as it is our start block
routeDetails.remove(0);
synchronized (this) {
smSource.setHeld(false);
//Only change the block and turnout details if this a temp signalmast logic
if (sml.getStoreState(smDest) == jmri.SignalMastLogic.STORENONE) {
LinkedHashMap<Block, Integer> blks = new LinkedHashMap<Block, Integer>();
for (int i = 0; i < routeDetails.size(); i++) {
if (routeDetails.get(i).getBlock().getState() == Block.UNKNOWN) {
routeDetails.get(i).getBlock().setState(Block.UNOCCUPIED);
}
blks.put(routeDetails.get(i).getBlock(), Block.UNOCCUPIED);
}
sml.setAutoBlocks(blks, smDest);
sml.setAutoTurnouts(turnoutSettings, smDest);
sml.initialise(smDest);
}
}
smSource.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
SignalMast source = (SignalMast) e.getSource();
source.removePropertyChangeListener(this);
setRouteFrom(true);
setRouteTo(true);
}
});
src.pd.extendedtime = true;
point.extendedtime = true;
} else {
if (src.sourceSignal instanceof SignalMast) {
SignalMast mast = (SignalMast) src.sourceSignal;
mast.setHeld(false);
} else if (src.sourceSignal instanceof SignalHead) {
SignalHead head = (SignalHead) src.sourceSignal;
head.setHeld(false);
}
setRouteFrom(true);
setRouteTo(true);
}
}
if (manager.useDifferentColorWhenSetting()) {
//final ArrayList<Color> realColorXtra = realColorXtra;
javax.swing.Timer resetColorBack = new javax.swing.Timer(manager.getSettingTimer(), new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
for (int i = 0; i < routeBlocks.size(); i++) {
LayoutBlock lbk = routeBlocks.get(i);
lbk.setBlockExtraColor(realColorXtra.get(i));
lbk.setBlockTrackColor(realColorStd.get(i));
}
src.getPoint().getPanel().redrawPanel();
}
});
resetColorBack.setRepeats(false);
resetColorBack.start();
}
if (at != null) {
jmri.Section sec = null;
if (sml != null && sml.getAssociatedSection((SignalMast) getSignal()) != null) {
sec = sml.getAssociatedSection((SignalMast) getSignal());
} else {
sec = InstanceManager.getDefault(jmri.SectionManager.class).createNewSection(src.getPoint().getDisplayName() + ":" + point.getDisplayName());
if (sec == null) {
//A Section already exists, lets grab it and check that it is one used with the Interlocking, if so carry on using that.
sec = InstanceManager.getDefault(jmri.SectionManager.class).getSection(src.getPoint().getDisplayName() + ":" + point.getDisplayName());
} else {
sec.setSectionType(jmri.Section.DYNAMICADHOC);
}
if (sec.getSectionType() == jmri.Section.DYNAMICADHOC) {
sec.removeAllBlocksFromSection();
for (LayoutBlock key : routeDetails) {
if (key != src.getStart()) {
sec.addBlock(key.getBlock());
}
}
String dir = jmri.Path.decodeDirection(src.getStart().getNeighbourDirection(routeDetails.get(0).getBlock()));
jmri.EntryPoint ep = new jmri.EntryPoint(routeDetails.get(0).getBlock(), src.getStart().getBlock(), dir);
ep.setTypeForward();
sec.addToForwardList(ep);
LayoutBlock proDestLBlock = point.getProtecting().get(0);
if (proDestLBlock != null) {
dir = jmri.Path.decodeDirection(proDestLBlock.getNeighbourDirection(point.getFacing()));
ep = new jmri.EntryPoint(point.getFacing().getBlock(), proDestLBlock.getBlock(), dir);
ep.setTypeReverse();
sec.addToReverseList(ep);
}
}
}
jmri.InstanceManager.getDefault(jmri.jmrit.dispatcher.DispatcherFrame.class).extendActiveTrainsPath(sec, at, src.getPoint().getPanel());
}
src.pd.setNXButtonState(EntryExitPairs.NXBUTTONINACTIVE);
point.setNXButtonState(EntryExitPairs.NXBUTTONINACTIVE);
} catch (RuntimeException ex) {
log.error("An error occured while setting the route");
ex.printStackTrace();
src.pd.setNXButtonState(EntryExitPairs.NXBUTTONINACTIVE);
point.setNXButtonState(EntryExitPairs.NXBUTTONINACTIVE);
if (manager.useDifferentColorWhenSetting()) {
for (int i = 0; i < routeBlocks.size(); i++) {
LayoutBlock lbk = routeBlocks.get(i);
lbk.setBlockExtraColor(realColorXtra.get(i));
lbk.setBlockTrackColor(realColorStd.get(i));
}
}
src.getPoint().getPanel().redrawPanel();
}
src.getPoint().getPanel().getGlassPane().setVisible(false);
//src.setMenuEnabled(true);
}
};
Thread thrMain = new Thread(setRouteRun, "Entry Exit Set Route");
thrMain.start();
try {
thrMain.join();
} catch (InterruptedException e) {
log.error("Interuption exception " + e.toString());
}
if (log.isDebugEnabled()) {
log.debug("finish route " + src.getPoint().getDisplayName());
}
}
use of jmri.SignalHead in project JMRI by JMRI.
the class PointDetails method getSignal.
NamedBean getSignal() {
if ((getPanel() != null) && (!getPanel().isEditable()) && (getSignalMast() != null)) {
return getSignalMast();
}
if ((getPanel() != null) && (!getPanel().isEditable()) && (getSignalHead() != null)) {
return getSignalHead();
}
jmri.SignalHeadManager sh = InstanceManager.getDefault(jmri.SignalHeadManager.class);
NamedBean signal = null;
if (getRefObject() == null) {
log.error("Signal not found at point");
return null;
} else if (getRefObject() instanceof SignalMast) {
signal = getRefObject();
setSignalMast(((SignalMast) getRefObject()));
return signal;
} else if (getRefObject() instanceof SignalHead) {
signal = getRefObject();
setSignalHead(((SignalHead) getRefObject()));
return signal;
}
Sensor sen = (Sensor) getRefObject();
log.debug("looking at Sensor " + sen.getDisplayName());
if (getRefLocation() instanceof PositionablePoint) {
PositionablePoint p = (PositionablePoint) getRefLocation();
if (p.getEastBoundSensor() == sen) {
if (p.getEastBoundSignalMast() != null) {
signal = p.getEastBoundSignalMast();
} else if (!p.getEastBoundSignal().equals("")) {
signal = sh.getSignalHead(p.getEastBoundSignal());
}
} else if (p.getWestBoundSensor() == sen) {
if (p.getWestBoundSignalMast() != null) {
signal = p.getWestBoundSignalMast();
} else if (!p.getWestBoundSignal().equals("")) {
signal = sh.getSignalHead(p.getWestBoundSignal());
}
}
} else if (getRefLocation() instanceof LayoutTurnout) {
LayoutTurnout t = (LayoutTurnout) getRefLocation();
if (t.getSensorA() == sen) {
if (t.getSignalAMast() != null) {
signal = t.getSignalAMast();
} else if (!t.getSignalA1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalA1Name());
}
} else if (t.getSensorB() == sen) {
if (t.getSignalBMast() != null) {
signal = t.getSignalBMast();
} else if (!t.getSignalB1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalB1Name());
}
} else if (t.getSensorC() == sen) {
if (t.getSignalCMast() != null) {
signal = t.getSignalCMast();
} else if (!t.getSignalC1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalC1Name());
}
} else if (t.getSensorD() == sen) {
if (t.getSignalDMast() != null) {
signal = t.getSignalDMast();
} else if (!t.getSignalD1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalD1Name());
}
}
} else if (getRefLocation() instanceof LevelXing) {
LevelXing x = (LevelXing) getRefLocation();
if (x.getSensorA() == sen) {
if (x.getSignalAMast() != null) {
signal = x.getSignalAMast();
} else if (!x.getSignalAName().equals("")) {
signal = sh.getSignalHead(x.getSignalAName());
}
} else if (x.getSensorB() == sen) {
if (x.getSignalBMast() != null) {
signal = x.getSignalBMast();
} else if (!x.getSignalBName().equals("")) {
signal = sh.getSignalHead(x.getSignalBName());
}
} else if (x.getSensorC() == sen) {
if (x.getSignalCMast() != null) {
signal = x.getSignalCMast();
} else if (!x.getSignalCName().equals("")) {
signal = sh.getSignalHead(x.getSignalCName());
}
} else if (x.getSensorD() == sen) {
if (x.getSignalDMast() != null) {
signal = x.getSignalDMast();
} else if (!x.getSignalDName().equals("")) {
signal = sh.getSignalHead(x.getSignalDName());
}
}
} else if (getRefLocation() instanceof LayoutSlip) {
LayoutSlip t = (LayoutSlip) getRefLocation();
if (t.getSensorA() == sen) {
if (t.getSignalAMast() != null) {
signal = t.getSignalAMast();
} else if (!t.getSignalA1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalA1Name());
}
} else if (t.getSensorB() == sen) {
if (t.getSignalBMast() != null) {
signal = t.getSignalBMast();
} else if (!t.getSignalB1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalB1Name());
}
} else if (t.getSensorC() == sen) {
if (t.getSignalCMast() != null) {
signal = t.getSignalCMast();
} else if (!t.getSignalC1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalC1Name());
}
} else if (t.getSensorD() == sen) {
if (t.getSignalDMast() != null) {
signal = t.getSignalDMast();
} else if (!t.getSignalD1Name().equals("")) {
signal = sh.getSignalHead(t.getSignalD1Name());
}
}
}
if (signal instanceof SignalMast) {
setSignalMast(((SignalMast) signal));
} else if (signal instanceof SignalHead) {
setSignalHead(((SignalHead) signal));
}
return signal;
}
use of jmri.SignalHead in project JMRI by JMRI.
the class DestinationPoints method cancelClearInterlock.
void cancelClearInterlock(int cancelClear) {
if ((cancelClear == EntryExitPairs.EXITROUTE) || (cancelClear == EntryExitPairs.STACKROUTE)) {
src.pd.setNXButtonState(EntryExitPairs.NXBUTTONINACTIVE);
point.setNXButtonState(EntryExitPairs.NXBUTTONINACTIVE);
src.getPoint().getPanel().getGlassPane().setVisible(false);
if (cancelClear == EntryExitPairs.STACKROUTE) {
manager.stackNXRoute(this, false);
}
return;
}
if (cancelClear == EntryExitPairs.CANCELROUTE) {
if (manager.getDispatcherIntegration() && jmri.InstanceManager.getNullableDefault(jmri.jmrit.dispatcher.DispatcherFrame.class) != null) {
jmri.jmrit.dispatcher.DispatcherFrame df = jmri.InstanceManager.getDefault(jmri.jmrit.dispatcher.DispatcherFrame.class);
ActiveTrain at = null;
for (ActiveTrain atl : df.getActiveTrainsList()) {
if (atl.getEndBlock() == point.getFacing().getBlock()) {
if (atl.getLastAllocatedSection() == atl.getEndBlockSection()) {
at = atl;
break;
}
}
}
if (at != null) {
jmri.Section sec = null;
synchronized (this) {
if (sml != null && sml.getAssociatedSection((SignalMast) getSignal()) != null) {
sec = sml.getAssociatedSection((SignalMast) getSignal());
} else {
sec = InstanceManager.getDefault(jmri.SectionManager.class).getSection(src.getPoint().getDisplayName() + ":" + point.getDisplayName());
}
}
if (sec != null) {
if (!df.removeFromActiveTrainPath(sec, at, src.getPoint().getPanel())) {
log.error("Unable to remove allocation from dispathcer, leave interlock in place");
src.pd.cancelNXButtonTimeOut();
point.cancelNXButtonTimeOut();
src.getPoint().getPanel().getGlassPane().setVisible(false);
return;
}
if (sec.getSectionType() == jmri.Section.DYNAMICADHOC) {
sec.removeAllBlocksFromSection();
}
}
}
}
}
src.setMenuEnabled(false);
if (src.sourceSignal instanceof SignalMast) {
SignalMast mast = (SignalMast) src.sourceSignal;
mast.setAspect(mast.getAppearanceMap().getSpecificAppearance(jmri.SignalAppearanceMap.DANGER));
mast.setHeld(true);
} else if (src.sourceSignal instanceof SignalHead) {
SignalHead head = (SignalHead) src.sourceSignal;
head.setHeld(true);
} else {
log.debug("No signal found");
}
//Get rid of the signal mast logic to the destination mast.
synchronized (this) {
if ((getSignal() instanceof SignalMast) && (sml != null)) {
SignalMast mast = (SignalMast) getSignal();
if (sml.getStoreState(mast) == jmri.SignalMastLogic.STORENONE) {
sml.removeDestination(mast);
}
}
sml = null;
}
if (routeDetails == null) {
return;
}
for (LayoutBlock blk : routeDetails) {
if ((getEntryExitType() == EntryExitPairs.FULLINTERLOCK)) {
blk.setUseExtraColor(false);
}
// was set against occupancy sensor
blk.getBlock().removePropertyChangeListener(propertyBlockListener);
}
if (cancelClear == EntryExitPairs.CLEARROUTE) {
if (routeDetails.size() == 0) {
if (log.isDebugEnabled()) {
log.debug(mUserName + " all blocks have automatically been cleared down");
}
} else {
if (log.isDebugEnabled()) {
log.debug(mUserName + " No blocks were cleared down " + routeDetails.size());
}
try {
if (log.isDebugEnabled()) {
log.debug(mUserName + " set first block as active so that we can manually clear this down " + routeDetails.get(0).getBlock().getUserName());
}
if (routeDetails.get(0).getOccupancySensor() != null) {
routeDetails.get(0).getOccupancySensor().setState(Sensor.ACTIVE);
} else {
routeDetails.get(0).getBlock().goingActive();
}
if (src.getStart().getOccupancySensor() != null) {
src.getStart().getOccupancySensor().setState(Sensor.INACTIVE);
} else {
src.getStart().getBlock().goingInactive();
}
} catch (java.lang.NullPointerException e) {
log.error("error in clear route A " + e);
} catch (JmriException e) {
log.error("error in clear route A " + e);
}
if (log.isDebugEnabled()) {
log.debug(mUserName + " Going to clear routeDetails down " + routeDetails.size());
for (int i = 0; i < routeDetails.size(); i++) {
log.debug("Block at " + i + " " + routeDetails.get(i).getDisplayName());
}
}
if (routeDetails.size() > 1) {
//Should we just be usrc.pdating the block status and not the sensor
for (int i = 1; i < routeDetails.size() - 1; i++) {
if (log.isDebugEnabled()) {
log.debug(mUserName + " in loop Set active " + routeDetails.get(i).getDisplayName() + " " + routeDetails.get(i).getBlock().getSystemName());
}
try {
if (routeDetails.get(i).getOccupancySensor() != null) {
routeDetails.get(i).getOccupancySensor().setState(Sensor.ACTIVE);
} else {
routeDetails.get(i).getBlock().goingActive();
}
if (log.isDebugEnabled()) {
log.debug(mUserName + " in loop Set inactive " + routeDetails.get(i - 1).getDisplayName() + " " + routeDetails.get(i - 1).getBlock().getSystemName());
}
if (routeDetails.get(i - 1).getOccupancySensor() != null) {
routeDetails.get(i - 1).getOccupancySensor().setState(Sensor.INACTIVE);
} else {
routeDetails.get(i - 1).getBlock().goingInactive();
}
} catch (java.lang.NullPointerException e) {
log.error("error in clear route b " + e);
e.printStackTrace();
} catch (JmriException e) {
log.error("error in clear route b " + e);
}
}
try {
if (log.isDebugEnabled()) {
log.debug(mUserName + " out of loop Set active " + routeDetails.get(routeDetails.size() - 1).getDisplayName() + " " + routeDetails.get(routeDetails.size() - 1).getBlock().getSystemName());
}
//Get the last block an set it active.
if (routeDetails.get(routeDetails.size() - 1).getOccupancySensor() != null) {
routeDetails.get(routeDetails.size() - 1).getOccupancySensor().setState(Sensor.ACTIVE);
} else {
routeDetails.get(routeDetails.size() - 1).getBlock().goingActive();
}
if (log.isDebugEnabled()) {
log.debug(mUserName + " out of loop Set inactive " + routeDetails.get(routeDetails.size() - 2).getUserName() + " " + routeDetails.get(routeDetails.size() - 2).getBlock().getSystemName());
}
if (routeDetails.get(routeDetails.size() - 2).getOccupancySensor() != null) {
routeDetails.get(routeDetails.size() - 2).getOccupancySensor().setState(Sensor.INACTIVE);
} else {
routeDetails.get(routeDetails.size() - 2).getBlock().goingInactive();
}
} catch (java.lang.NullPointerException e) {
log.error("error in clear route c " + e);
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
log.error("error in clear route c " + e);
} catch (JmriException e) {
log.error("error in clear route c " + e);
}
}
}
}
setActiveEntryExit(false);
setRouteFrom(false);
setRouteTo(false);
routeDetails = null;
synchronized (this) {
lastSeenActiveBlockObject = null;
}
src.pd.cancelNXButtonTimeOut();
point.cancelNXButtonTimeOut();
src.getPoint().getPanel().getGlassPane().setVisible(false);
}
use of jmri.SignalHead in project JMRI by JMRI.
the class SE8cSignalHeadXml method load.
@Override
public boolean load(Element shared, Element perNode) {
// NOI18N
List<Element> l = shared.getChildren("turnout");
int turnout = loadTurnout(l.get(0));
// put it together
String uname = getUserName(shared);
SignalHead h;
if (uname == null) {
h = new jmri.implementation.SE8cSignalHead(turnout);
} else {
h = new jmri.implementation.SE8cSignalHead(turnout, uname);
}
loadCommon(h, shared);
InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
return true;
}
Aggregations