use of jmri.Turnout in project JMRI by JMRI.
the class SerialTurnoutManagerTest method testUpperLower.
@Override
@Test
public void testUpperLower() {
Turnout t = l.provideTurnout("PTB" + getNumToTest2());
Assert.assertNull(l.getTurnout(t.getSystemName().toLowerCase()));
}
use of jmri.Turnout in project JMRI by JMRI.
the class RaspberryPiTurnoutManagerTest method testDefaultSystemName.
@Override
@Test
public void testDefaultSystemName() {
// create
Turnout t = l.provideTurnout("PIT" + getNumToTest1());
// check
Assert.assertTrue("real object returned ", t != null);
Assert.assertTrue("system name correct ", t == l.getBySystemName(getSystemName(getNumToTest1())));
}
use of jmri.Turnout in project JMRI by JMRI.
the class RaspberryPiTurnoutManagerTest method testRename.
@Override
@Test
public void testRename() {
// get turnout
Turnout t1 = l.newTurnout(getSystemName(15), "before");
Assert.assertNotNull("t1 real object ", t1);
t1.setUserName("after");
Turnout t2 = l.getByUserName("after");
Assert.assertEquals("same object", t1, t2);
Assert.assertEquals("no old object", null, l.getByUserName("before"));
}
use of jmri.Turnout in project JMRI by JMRI.
the class RaspberryPiTurnoutManagerTest method testSingleObject.
@Override
@Test
public void testSingleObject() {
// test that you always get the same representation
Turnout t1 = l.newTurnout(getSystemName(16), "mine");
Assert.assertTrue("t1 real object returned ", t1 != null);
Assert.assertTrue("same by user ", t1 == l.getByUserName("mine"));
Assert.assertTrue("same by system ", t1 == l.getBySystemName(getSystemName(16)));
Turnout t2 = l.newTurnout(getSystemName(16), "mine");
Assert.assertTrue("t2 real object returned ", t2 != null);
// check
Assert.assertTrue("same new ", t1 == t2);
}
use of jmri.Turnout 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());
}
}
Aggregations