use of jmri.SignalMast in project JMRI by JMRI.
the class SignallingPanel method editDetails.
/**
* Fill in existing SML configuration on the edit panel
*/
void editDetails() {
int setRow = 0;
for (int i = _manualBlockList.size() - 1; i >= 0; i--) {
ManualBlockList block = _manualBlockList.get(i);
String tSysName = block.getSysName();
Block blk = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(tSysName);
if (sml.isBlockIncluded(blk, destMast)) {
block.setIncluded(true);
block.setState(sml.getBlockState(blk, destMast));
setRow = i;
} else {
block.setIncluded(false);
block.setState(Block.UNOCCUPIED);
}
}
setRow -= 1;
if (setRow < 0) {
setRow = 0;
}
_manualBlockScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
_blockModel.fireTableDataChanged();
setRow = 0;
for (int i = _manualTurnoutList.size() - 1; i >= 0; i--) {
ManualTurnoutList turnout = _manualTurnoutList.get(i);
String tSysName = turnout.getSysName();
Turnout turn = InstanceManager.turnoutManagerInstance().getTurnout(tSysName);
if (sml.isTurnoutIncluded(turn, destMast)) {
turnout.setIncluded(true);
turnout.setState(sml.getTurnoutState(turn, destMast));
setRow = i;
} else {
turnout.setIncluded(false);
turnout.setState(Turnout.CLOSED);
}
}
setRow -= 1;
if (setRow < 0) {
setRow = 0;
}
_manualSensorScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
_sensorModel.fireTableDataChanged();
setRow = 0;
for (int i = _manualSensorList.size() - 1; i >= 0; i--) {
ManualSensorList sensor = _manualSensorList.get(i);
String tSysName = sensor.getSysName();
Sensor sen = InstanceManager.sensorManagerInstance().getSensor(tSysName);
if (sml.isSensorIncluded(sen, destMast)) {
sensor.setIncluded(true);
sensor.setState(sml.getSensorState(sen, destMast));
setRow = i;
} else {
sensor.setIncluded(false);
sensor.setState(Sensor.INACTIVE);
}
}
setRow -= 1;
if (setRow < 0) {
setRow = 0;
}
_manualSensorScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
_sensorModel.fireTableDataChanged();
setRow = 0;
for (int i = _manualSignalMastList.size() - 1; i >= 0; i--) {
ManualSignalMastList mast = _manualSignalMastList.get(i);
SignalMast sigMast = _manualSignalMastList.get(i).getMast();
if (sml.isSignalMastIncluded(sigMast, destMast)) {
mast.setIncluded(true);
mast.setSetToState(sml.getSignalMastState(sigMast, destMast));
setRow = i;
} else {
mast.setIncluded(false);
}
}
setRow -= 1;
if (setRow < 0) {
setRow = 0;
}
_manualSignalMastScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
_signalMastModel.fireTableDataChanged();
}
use of jmri.SignalMast 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.SignalMast 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.SignalMast in project JMRI by JMRI.
the class DestinationPoints method isSignalLogicDynamic.
private boolean isSignalLogicDynamic() {
if ((src.sourceSignal instanceof SignalMast) && (getSignal() instanceof SignalMast)) {
SignalMast smSource = (SignalMast) src.sourceSignal;
SignalMast smDest = (SignalMast) getSignal();
if (InstanceManager.getDefault(jmri.SignalMastLogicManager.class).getSignalMastLogic(smSource) != null && InstanceManager.getDefault(jmri.SignalMastLogicManager.class).getSignalMastLogic(smSource).getStoreState(smDest) != jmri.SignalMastLogic.STORENONE) {
return false;
}
}
return true;
}
use of jmri.SignalMast in project JMRI by JMRI.
the class DestinationPoints method removeBlockFromRoute.
synchronized void removeBlockFromRoute(LayoutBlock lBlock) {
if (routeDetails != null) {
if (routeDetails.indexOf(lBlock) == -1) {
if (src.getStart() == lBlock) {
log.debug("Start block went active");
lastSeenActiveBlockObject = src.getStart().getBlock().getValue();
lBlock.getBlock().removePropertyChangeListener(propertyBlockListener);
return;
} else {
log.error("Block " + lBlock.getDisplayName() + " went active but it is not part of our NX path");
}
}
if (routeDetails.indexOf(lBlock) != 0) {
log.debug("A block has been skipped will set the value of the active block to that of the original one");
lBlock.getBlock().setValue(lastSeenActiveBlockObject);
if (routeDetails.indexOf(lBlock) != -1) {
while (routeDetails.indexOf(lBlock) != 0) {
LayoutBlock tbr = routeDetails.get(0);
log.debug("Block skipped " + tbr.getDisplayName() + " and removed from list");
tbr.getBlock().removePropertyChangeListener(propertyBlockListener);
tbr.setUseExtraColor(false);
routeDetails.remove(0);
}
}
}
if (routeDetails.contains(lBlock)) {
routeDetails.remove(lBlock);
setRouteFrom(false);
src.pd.setNXButtonState(EntryExitPairs.NXBUTTONINACTIVE);
if (sml != null && getEntryExitType() == EntryExitPairs.FULLINTERLOCK) {
sml.getSourceMast().setHeld(true);
SignalMast mast = (SignalMast) getSignal();
if (sml.getStoreState(mast) == jmri.SignalMastLogic.STORENONE) {
sml.removeDestination(mast);
}
}
} else {
log.error("Block " + lBlock.getDisplayName() + " that went Occupied was not in the routeDetails list");
}
if (log.isDebugEnabled()) {
log.debug("Route details contents " + routeDetails);
for (int i = 0; i < routeDetails.size(); i++) {
log.debug(" " + routeDetails.get(i).getDisplayName());
}
}
if ((routeDetails.size() == 1) && (routeDetails.contains(destination))) {
// was set against block sensor
routeDetails.get(0).getBlock().removePropertyChangeListener(propertyBlockListener);
routeDetails.remove(destination);
}
}
lastSeenActiveBlockObject = lBlock.getBlock().getValue();
if ((routeDetails == null) || (routeDetails.size() == 0)) {
//At this point the route has cleared down/the last remaining block are now active.
routeDetails = null;
setRouteTo(false);
setRouteFrom(false);
setActiveEntryExit(false);
lastSeenActiveBlockObject = null;
}
}
Aggregations