use of jmri.Block in project JMRI by JMRI.
the class SectionManagerXmlTest method testLoadCurrent.
public void testLoadCurrent() throws Exception {
// load file
JUnitUtil.resetInstanceManager();
JUnitUtil.initConfigureManager();
JUnitUtil.initInternalTurnoutManager();
JUnitUtil.initInternalLightManager();
JUnitUtil.initInternalSensorManager();
JUnitUtil.initMemoryManager();
JUnitUtil.initLayoutBlockManager();
JUnitUtil.initSectionManager();
InstanceManager.getDefault(ConfigureManager.class).load(new java.io.File("java/test/jmri/configurexml/load/SectionManagerXmlTest.xml"));
// Note: This test assumes that BlockManagerXMLTest passes and more importantly (weakly)
// that LoadSectionManagerFileText.xml and LoadBlockManagerFileText.xml refer to the
// same block / section layout definition.
// check existance of sections
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("IY:AUTO:0001"));
Assert.assertNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("no section"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("IY:AUTO:0002"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("IY:AUTO:0003"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("IY:AUTO:0004"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("IY:AUTO:0005"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("IY:AUTO:0006"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("IY:AUTO:0007"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("IY:AUTO:0008"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("IY:AUTO:0009"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("IY:AUTO:0010"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("IY:AUTO:0011"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("IY:AUTO:0012"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("NorthWest"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("North"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("NorthSiding"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("NorthEast"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("East"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("EastSiding"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("SouthEast"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("South"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("SouthSiding"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("SouthWest"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("West"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.SectionManager.class).getSection("WestSiding"));
// check existance of a couple of blocks just to be sure
// that LoadSectionManagerFileText.xml and LoadBlockManagerFileText.xml refer to the
// same block / section layout definition.
Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("IB1"));
Assert.assertNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("no block"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("IB12"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocknorthwest"));
Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blockwestsiding"));
//Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB1"));
//Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB12"));
//Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blocknorthwest"));
//Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blockwestsiding"));
// check existance of a couple of turmouts just to be sure
// that LoadSectionManagerFileText.xml and LoadBlockManagerFileText.xml refer to the
// same block / section layout definition.
Assert.assertNotNull(InstanceManager.turnoutManagerInstance().getTurnout("IT1"));
Assert.assertNull(InstanceManager.turnoutManagerInstance().getTurnout("no turnout"));
Assert.assertNotNull(InstanceManager.turnoutManagerInstance().getTurnout("IT2"));
Assert.assertNotNull(InstanceManager.turnoutManagerInstance().getTurnout("IT8"));
// check existance of a couple of memories just to be sure
// that LoadSectionManagerFileText.xml and LoadBlockManagerFileText.xml refer to the
// same block / section layout definition.
Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("IM:AUTO:0001"));
Assert.assertNull(InstanceManager.memoryManagerInstance().getMemory("no memory"));
Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("IM:AUTO:0002"));
Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("IM:AUTO:0012"));
Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blocknorthwestmemory"));
Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blockwestsidingmemory"));
// check existance of a couple of sensors just to be sure
// that LoadSectionManagerFileText.xml and LoadBlockManagerFileText.xml refer to the
// same block / section layout definition.
Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO1"));
Assert.assertNull(InstanceManager.sensorManagerInstance().getSensor("no sensor"));
Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO2"));
Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO12"));
Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blocknorthwestoccupied"));
Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blockwestsidingoccupied"));
// check existance of a couple of paths between blocks just to be sure
// that LoadSectionManagerFileText.xml and LoadBlockManagerFileText.xml refer to the
// same block / section layout definition.
Block[] blockstotest;
Sensor[] occupiedsensor;
int[] expectedpreviouspaths;
int[] expectednextpaths;
//Make sure this is bigger than the list below
blockstotest = new Block[12];
//Make sure this is bigger than the list below
occupiedsensor = new Sensor[12];
//Make sure this is bigger than the list below
expectedpreviouspaths = new int[12];
//Make sure this is bigger than the list below
expectednextpaths = new int[12];
Boolean[] passprevioustest;
Boolean[] passnexttest;
//Make sure this is bigger than needed
passprevioustest = new Boolean[4];
//Make sure this is bigger than needed
passnexttest = new Boolean[4];
Block[][] previousblock;
//Make sure this is bigger than the list below
previousblock = new Block[12][4];
Block[][] nextblock;
//Make sure this is bigger than the list below
nextblock = new Block[12][4];
// This matches up with the test file, ..., just be sure
// that LoadSectionManagerFileText.xml and LoadBlockManagerFileText.xml refer to the
// same block / section layout definition.
blockstotest[0] = InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocknorthwest");
Assert.assertNotNull(blockstotest[0]);
occupiedsensor[0] = InstanceManager.sensorManagerInstance().getSensor("blocknorthwestoccupied");
Assert.assertNotNull(occupiedsensor[0]);
blockstotest[1] = InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocknorth");
Assert.assertNotNull(blockstotest[1]);
occupiedsensor[1] = InstanceManager.sensorManagerInstance().getSensor("blocknorthoccupied");
Assert.assertNotNull(occupiedsensor[1]);
blockstotest[2] = InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocknorthsiding");
Assert.assertNotNull(blockstotest[2]);
occupiedsensor[2] = InstanceManager.sensorManagerInstance().getSensor("blocknorthsidingoccupied");
Assert.assertNotNull(occupiedsensor[2]);
blockstotest[3] = InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocknortheast");
Assert.assertNotNull(blockstotest[3]);
occupiedsensor[3] = InstanceManager.sensorManagerInstance().getSensor("blocknortheastoccupied");
Assert.assertNotNull(occupiedsensor[3]);
blockstotest[4] = InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blockeast");
Assert.assertNotNull(blockstotest[4]);
occupiedsensor[4] = InstanceManager.sensorManagerInstance().getSensor("blockeastoccupied");
Assert.assertNotNull(occupiedsensor[4]);
blockstotest[5] = InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blockeastsiding");
Assert.assertNotNull(blockstotest[5]);
occupiedsensor[5] = InstanceManager.sensorManagerInstance().getSensor("blockeastsidingoccupied");
Assert.assertNotNull(occupiedsensor[5]);
blockstotest[6] = InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocksoutheast");
Assert.assertNotNull(blockstotest[6]);
occupiedsensor[6] = InstanceManager.sensorManagerInstance().getSensor("blocksoutheastoccupied");
Assert.assertNotNull(occupiedsensor[6]);
blockstotest[7] = InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocksouth");
Assert.assertNotNull(blockstotest[7]);
occupiedsensor[7] = InstanceManager.sensorManagerInstance().getSensor("blocksouthoccupied");
Assert.assertNotNull(occupiedsensor[7]);
blockstotest[8] = InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocksouthsiding");
Assert.assertNotNull(blockstotest[8]);
occupiedsensor[8] = InstanceManager.sensorManagerInstance().getSensor("blocksouthsidingoccupied");
Assert.assertNotNull(occupiedsensor[8]);
blockstotest[9] = InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocksouthwest");
Assert.assertNotNull(blockstotest[9]);
occupiedsensor[9] = InstanceManager.sensorManagerInstance().getSensor("blocksouthwestoccupied");
Assert.assertNotNull(occupiedsensor[9]);
blockstotest[10] = InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blockwest");
Assert.assertNotNull(blockstotest[10]);
occupiedsensor[10] = InstanceManager.sensorManagerInstance().getSensor("blockwestoccupied");
Assert.assertNotNull(occupiedsensor[10]);
blockstotest[11] = InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blockwestsiding");
Assert.assertNotNull(blockstotest[11]);
occupiedsensor[11] = InstanceManager.sensorManagerInstance().getSensor("blockwestsidingoccupied");
Assert.assertNotNull(occupiedsensor[11]);
// The references are circular so the definitons are split up, ..., just be sure
// that LoadSectionManagerFileText.xml and LoadBlockManagerFileText.xml refer to the
// same block / section layout definition.
expectedpreviouspaths[0] = 2;
previousblock[0][0] = blockstotest[10];
previousblock[0][1] = blockstotest[11];
expectednextpaths[0] = 2;
nextblock[0][0] = blockstotest[1];
nextblock[0][1] = blockstotest[2];
expectedpreviouspaths[1] = 1;
previousblock[1][0] = blockstotest[0];
expectednextpaths[1] = 1;
nextblock[1][0] = blockstotest[3];
expectedpreviouspaths[2] = 1;
previousblock[2][0] = blockstotest[0];
expectednextpaths[2] = 1;
nextblock[2][0] = blockstotest[3];
expectedpreviouspaths[3] = 2;
previousblock[3][0] = blockstotest[1];
previousblock[3][1] = blockstotest[2];
expectednextpaths[3] = 2;
nextblock[3][0] = blockstotest[4];
nextblock[3][1] = blockstotest[5];
expectedpreviouspaths[4] = 1;
previousblock[4][0] = blockstotest[3];
expectednextpaths[4] = 1;
nextblock[4][0] = blockstotest[6];
expectedpreviouspaths[5] = 1;
previousblock[5][0] = blockstotest[3];
expectednextpaths[5] = 1;
nextblock[5][0] = blockstotest[6];
expectedpreviouspaths[6] = 2;
previousblock[6][0] = blockstotest[4];
previousblock[6][1] = blockstotest[5];
expectednextpaths[6] = 2;
nextblock[6][0] = blockstotest[7];
nextblock[6][1] = blockstotest[8];
expectedpreviouspaths[7] = 1;
previousblock[7][0] = blockstotest[6];
expectednextpaths[7] = 1;
nextblock[7][0] = blockstotest[9];
expectedpreviouspaths[8] = 1;
previousblock[8][0] = blockstotest[6];
expectednextpaths[8] = 1;
nextblock[8][0] = blockstotest[9];
expectedpreviouspaths[9] = 2;
previousblock[9][0] = blockstotest[7];
previousblock[9][1] = blockstotest[8];
expectednextpaths[9] = 2;
nextblock[9][0] = blockstotest[10];
nextblock[9][1] = blockstotest[11];
expectedpreviouspaths[10] = 1;
previousblock[10][0] = blockstotest[9];
expectednextpaths[10] = 1;
nextblock[10][0] = blockstotest[0];
expectedpreviouspaths[11] = 1;
previousblock[11][0] = blockstotest[9];
expectednextpaths[11] = 1;
nextblock[11][0] = blockstotest[0];
for (int testblockfocus = 0; testblockfocus < 12; testblockfocus++) {
// Set to one greater than above
int expectedcentrepaths = expectedpreviouspaths[testblockfocus] + expectednextpaths[testblockfocus];
Block focusBlock = blockstotest[testblockfocus];
Memory expectedtestmemory = InstanceManager.memoryManagerInstance().getMemory("blocknorthmemory");
expectedtestmemory.setValue("Memory test: " + testblockfocus);
Assert.assertNotNull(expectedtestmemory);
// TODO: BOB C: Memory Test
// Memory actualtestmemory = (Memory) focusBlock.getValue();
// Assert.assertNotNull(actualtestmemory);
// Assert.assertEquals("Memory where Focus was: " + testblockfocus, expectedtestmemory, actualtestmemory);
Assert.assertEquals("Sensor where Focus was: " + testblockfocus, occupiedsensor[testblockfocus].getSystemName(), focusBlock.getSensor().getSystemName());
List<Path> testpaths = focusBlock.getPaths();
Assert.assertEquals("Block Path size where Block Focus was: " + testblockfocus, expectedcentrepaths, testpaths.size());
for (int p = 0; p < expectedpreviouspaths[testblockfocus]; p++) {
passprevioustest[p] = false;
}
for (int n = 0; n < expectednextpaths[testblockfocus]; n++) {
passnexttest[n] = false;
}
for (int i = 0; i < testpaths.size(); i++) {
Block testblock = testpaths.get(i).getBlock();
Assert.assertNotNull(testblock);
for (int p = 0; p < expectedpreviouspaths[testblockfocus]; p++) {
if (testblock == previousblock[testblockfocus][p]) {
passprevioustest[p] = true;
}
}
for (int n = 0; n < expectednextpaths[testblockfocus]; n++) {
if (testblock == nextblock[testblockfocus][n]) {
passnexttest[n] = true;
}
}
}
for (int p = 0; p < expectedpreviouspaths[testblockfocus]; p++) {
Assert.assertTrue("Block Focus was: " + testblockfocus + " previous path: " + p, passprevioustest[p]);
}
for (int n = 0; n < expectednextpaths[testblockfocus]; n++) {
Assert.assertTrue("Block Focus was: " + testblockfocus + " next path: " + n, passnexttest[n]);
}
}
Section[] sectionstotest;
Block[] expectedsectionentryblock;
Block[][] expectedsectionforwardblock;
Block[][] expectedsectionreverseblock;
Sensor[] expectedForwardBlockingSensors;
Sensor[] expectedReverseBlockingSensors;
Sensor[] expectedForwardStoppingSensors;
Sensor[] expectedReverseStoppingSensors;
int[] expectedsectionblocklistsize;
int[] expectedforwardEntryPointList;
int[] expectedreverseEntryPointList;
// Sensor[] occupiedsensor;
// int[] expectedpreviouspaths;
// int[] expectednextpaths;
//Make sure this is bigger than the list below
sectionstotest = new Section[12];
//Make sure this is bigger than the list below
expectedsectionentryblock = new Block[12];
//Make sure this is bigger than the list below
expectedsectionforwardblock = new Block[12][2];
//Make sure this is bigger than the list below
expectedsectionreverseblock = new Block[12][2];
//Make sure this is bigger than the list below
expectedForwardBlockingSensors = new Sensor[12];
//Make sure this is bigger than the list below
expectedReverseBlockingSensors = new Sensor[12];
//Make sure this is bigger than the list below
expectedForwardStoppingSensors = new Sensor[12];
//Make sure this is bigger than the list below
expectedReverseStoppingSensors = new Sensor[12];
//Make sure this is bigger than the list below
expectedsectionblocklistsize = new int[12];
//Make sure this is bigger than the list below
expectedforwardEntryPointList = new int[12];
//Make sure this is bigger than the list below
expectedreverseEntryPointList = new int[12];
// occupiedsensor = new Sensor[12]; //Make sure this is bigger than the list below
// expectedpreviouspaths = new int[12]; //Make sure this is bigger than the list below
// expectednextpaths = new int[12]; //Make sure this is bigger than the list below
// This matches up with the test file, ...
sectionstotest[0] = InstanceManager.getDefault(jmri.SectionManager.class).getSection("NorthWest");
Assert.assertNotNull(sectionstotest[0]);
expectedsectionblocklistsize[0] = 1;
expectedsectionentryblock[0] = blockstotest[0];
expectedforwardEntryPointList[0] = 2;
expectedsectionforwardblock[0][0] = blockstotest[10];
expectedsectionforwardblock[0][1] = blockstotest[11];
expectedreverseEntryPointList[0] = 2;
expectedsectionreverseblock[0][0] = blockstotest[1];
expectedsectionreverseblock[0][1] = blockstotest[2];
expectedForwardBlockingSensors[0] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRF1");
expectedReverseBlockingSensors[0] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRR1");
expectedForwardStoppingSensors[0] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPF1");
expectedReverseStoppingSensors[0] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPR1");
sectionstotest[1] = InstanceManager.getDefault(jmri.SectionManager.class).getSection("North");
Assert.assertNotNull(sectionstotest[1]);
expectedsectionblocklistsize[1] = 1;
expectedsectionentryblock[1] = blockstotest[1];
expectedforwardEntryPointList[1] = 1;
expectedsectionforwardblock[1][0] = blockstotest[0];
expectedreverseEntryPointList[1] = 1;
expectedsectionreverseblock[1][0] = blockstotest[3];
expectedForwardBlockingSensors[1] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRF2");
expectedReverseBlockingSensors[1] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRR2");
expectedForwardStoppingSensors[1] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPF2");
expectedReverseStoppingSensors[1] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPR2");
sectionstotest[2] = InstanceManager.getDefault(jmri.SectionManager.class).getSection("NorthSiding");
Assert.assertNotNull(sectionstotest[2]);
expectedsectionblocklistsize[2] = 1;
expectedsectionentryblock[2] = blockstotest[2];
expectedforwardEntryPointList[2] = 1;
expectedsectionforwardblock[2][0] = blockstotest[0];
expectedreverseEntryPointList[2] = 1;
expectedsectionreverseblock[2][0] = blockstotest[3];
expectedForwardBlockingSensors[2] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRF3");
expectedReverseBlockingSensors[2] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRR3");
expectedForwardStoppingSensors[2] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPF3");
expectedReverseStoppingSensors[2] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPR3");
sectionstotest[3] = InstanceManager.getDefault(jmri.SectionManager.class).getSection("NorthEast");
Assert.assertNotNull(sectionstotest[3]);
expectedsectionblocklistsize[3] = 1;
expectedsectionentryblock[3] = blockstotest[3];
expectedforwardEntryPointList[3] = 2;
expectedsectionforwardblock[3][0] = blockstotest[1];
expectedsectionforwardblock[3][1] = blockstotest[2];
expectedreverseEntryPointList[3] = 2;
expectedsectionreverseblock[3][0] = blockstotest[4];
expectedsectionreverseblock[3][1] = blockstotest[5];
expectedForwardBlockingSensors[3] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRF4");
expectedReverseBlockingSensors[3] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRR4");
expectedForwardStoppingSensors[3] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPF4");
expectedReverseStoppingSensors[3] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPR4");
sectionstotest[4] = InstanceManager.getDefault(jmri.SectionManager.class).getSection("East");
Assert.assertNotNull(sectionstotest[4]);
expectedsectionblocklistsize[4] = 1;
expectedsectionentryblock[4] = blockstotest[4];
expectedforwardEntryPointList[4] = 1;
expectedsectionforwardblock[4][0] = blockstotest[3];
expectedreverseEntryPointList[4] = 1;
expectedsectionreverseblock[4][0] = blockstotest[6];
expectedForwardBlockingSensors[4] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRF5");
expectedReverseBlockingSensors[4] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRR5");
expectedForwardStoppingSensors[4] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPF5");
expectedReverseStoppingSensors[4] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPR5");
sectionstotest[5] = InstanceManager.getDefault(jmri.SectionManager.class).getSection("EastSiding");
Assert.assertNotNull(sectionstotest[5]);
expectedsectionblocklistsize[5] = 1;
expectedsectionentryblock[5] = blockstotest[5];
expectedforwardEntryPointList[5] = 1;
expectedsectionforwardblock[5][0] = blockstotest[3];
expectedreverseEntryPointList[5] = 1;
expectedsectionreverseblock[5][0] = blockstotest[6];
expectedForwardBlockingSensors[5] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRF6");
expectedReverseBlockingSensors[5] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRR6");
expectedForwardStoppingSensors[5] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPF6");
expectedReverseStoppingSensors[5] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPR6");
sectionstotest[6] = InstanceManager.getDefault(jmri.SectionManager.class).getSection("SouthEast");
Assert.assertNotNull(sectionstotest[6]);
expectedsectionblocklistsize[6] = 1;
expectedsectionentryblock[6] = blockstotest[6];
expectedforwardEntryPointList[6] = 2;
expectedsectionforwardblock[6][0] = blockstotest[4];
expectedsectionforwardblock[6][1] = blockstotest[5];
expectedreverseEntryPointList[6] = 2;
expectedsectionreverseblock[6][0] = blockstotest[7];
expectedsectionreverseblock[6][1] = blockstotest[8];
expectedForwardBlockingSensors[6] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRF7");
expectedReverseBlockingSensors[6] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRR7");
expectedForwardStoppingSensors[6] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPF7");
expectedReverseStoppingSensors[6] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPR7");
sectionstotest[7] = InstanceManager.getDefault(jmri.SectionManager.class).getSection("South");
Assert.assertNotNull(sectionstotest[7]);
expectedsectionblocklistsize[7] = 1;
expectedsectionentryblock[7] = blockstotest[7];
expectedforwardEntryPointList[7] = 1;
expectedsectionforwardblock[7][0] = blockstotest[6];
expectedreverseEntryPointList[7] = 1;
expectedsectionreverseblock[7][0] = blockstotest[9];
expectedForwardBlockingSensors[7] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRF8");
expectedReverseBlockingSensors[7] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRR8");
expectedForwardStoppingSensors[7] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPF8");
expectedReverseStoppingSensors[7] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPR8");
sectionstotest[8] = InstanceManager.getDefault(jmri.SectionManager.class).getSection("SouthSiding");
Assert.assertNotNull(sectionstotest[8]);
expectedsectionblocklistsize[8] = 1;
expectedsectionentryblock[8] = blockstotest[8];
expectedforwardEntryPointList[8] = 1;
expectedsectionforwardblock[8][0] = blockstotest[6];
expectedreverseEntryPointList[8] = 1;
expectedsectionreverseblock[8][0] = blockstotest[9];
expectedForwardBlockingSensors[8] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRF9");
expectedReverseBlockingSensors[8] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRR9");
expectedForwardStoppingSensors[8] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPF9");
expectedReverseStoppingSensors[8] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPR9");
sectionstotest[9] = InstanceManager.getDefault(jmri.SectionManager.class).getSection("SouthWest");
Assert.assertNotNull(sectionstotest[9]);
expectedsectionblocklistsize[9] = 1;
expectedsectionentryblock[9] = blockstotest[9];
expectedforwardEntryPointList[9] = 2;
expectedsectionforwardblock[9][0] = blockstotest[7];
expectedsectionforwardblock[9][1] = blockstotest[8];
expectedreverseEntryPointList[9] = 2;
expectedsectionreverseblock[9][0] = blockstotest[10];
expectedsectionreverseblock[9][1] = blockstotest[11];
expectedForwardBlockingSensors[9] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRF10");
expectedReverseBlockingSensors[9] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRR10");
expectedForwardStoppingSensors[9] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPF10");
expectedReverseStoppingSensors[9] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPR10");
sectionstotest[10] = InstanceManager.getDefault(jmri.SectionManager.class).getSection("West");
Assert.assertNotNull(sectionstotest[10]);
expectedsectionblocklistsize[10] = 1;
expectedsectionentryblock[10] = blockstotest[10];
expectedforwardEntryPointList[10] = 1;
expectedsectionforwardblock[10][0] = blockstotest[9];
expectedreverseEntryPointList[10] = 1;
expectedsectionreverseblock[10][0] = blockstotest[0];
expectedForwardBlockingSensors[10] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRF11");
expectedReverseBlockingSensors[10] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRR11");
expectedForwardStoppingSensors[10] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPF11");
expectedReverseStoppingSensors[10] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPR11");
sectionstotest[11] = InstanceManager.getDefault(jmri.SectionManager.class).getSection("WestSiding");
Assert.assertNotNull(sectionstotest[11]);
expectedsectionblocklistsize[11] = 1;
expectedsectionentryblock[11] = blockstotest[11];
expectedforwardEntryPointList[11] = 1;
expectedsectionforwardblock[11][0] = blockstotest[9];
expectedreverseEntryPointList[11] = 1;
expectedsectionreverseblock[11][0] = blockstotest[0];
expectedForwardBlockingSensors[11] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRF12");
expectedReverseBlockingSensors[11] = InstanceManager.sensorManagerInstance().getSensor("ISSDIRR12");
expectedForwardStoppingSensors[11] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPF12");
expectedReverseStoppingSensors[11] = InstanceManager.sensorManagerInstance().getSensor("ISSSTOPR12");
for (int testsectionfocus = 0; testsectionfocus < 12; testsectionfocus++) {
// Set to one greater than above
// check existance of sections
Section testsection = sectionstotest[testsectionfocus];
ArrayList<Block> blockList = testsection.getBlockList();
Assert.assertEquals("Section size where Focus was: " + testsectionfocus, expectedsectionblocklistsize[testsectionfocus], blockList.size());
Block entryblock = testsection.getEntryBlock();
Assert.assertNotNull(entryblock);
Assert.assertEquals("Section entry block where Focus was: " + testsectionfocus, expectedsectionentryblock[testsectionfocus].getSystemName(), entryblock.getSystemName());
List<EntryPoint> forwardEntryPointList = testsection.getForwardEntryPointList();
Assert.assertEquals("Section forward size where Focus was: " + testsectionfocus, expectedforwardEntryPointList[testsectionfocus], forwardEntryPointList.size());
for (int e = 0; e < forwardEntryPointList.size(); e++) {
EntryPoint get = forwardEntryPointList.get(e);
Assert.assertEquals("Focus was: " + testsectionfocus + " next forward entry point: " + e, expectedsectionentryblock[testsectionfocus].getSystemName(), get.getBlock().getSystemName());
Assert.assertEquals("Focus was: " + testsectionfocus + " next forward from: " + e, expectedsectionforwardblock[testsectionfocus][e].getUserName(), get.getFromBlock().getUserName());
Assert.assertEquals("Focus was: " + testsectionfocus + " next forward dir: " + e, 4, get.getDirection());
}
List<EntryPoint> reverseEntryPointList = testsection.getReverseEntryPointList();
Assert.assertEquals("Section forward size where Focus was: " + testsectionfocus, expectedreverseEntryPointList[testsectionfocus], reverseEntryPointList.size());
for (int e = 0; e < reverseEntryPointList.size(); e++) {
EntryPoint get = reverseEntryPointList.get(e);
Assert.assertEquals("Focus was: " + testsectionfocus + " next reverse entry point: " + e, expectedsectionentryblock[testsectionfocus].getSystemName(), get.getBlock().getSystemName());
Assert.assertEquals("Focus was: " + testsectionfocus + " next reverse from: " + e, expectedsectionreverseblock[testsectionfocus][e].getUserName(), get.getFromBlock().getUserName());
Assert.assertEquals("Focus was: " + testsectionfocus + " next reverse dir: " + e, 8, get.getDirection());
}
Sensor expectedForwardBlockingSensor = expectedForwardBlockingSensors[testsectionfocus];
Sensor actualForwardBlockingSensor = testsection.getForwardBlockingSensor();
Assert.assertNotNull("Focus was: " + testsectionfocus + " expectedForwardBlockingSensor", expectedForwardBlockingSensor);
Assert.assertNotNull("Focus was: " + testsectionfocus + " actualForwardBlockingSensor", actualForwardBlockingSensor);
Assert.assertTrue("Focus was: " + testsectionfocus + " ForwardBlockingSensor", expectedForwardBlockingSensor.getSystemName().equals(actualForwardBlockingSensor.getSystemName()));
Sensor expectedReverseBlockingSensor = expectedReverseBlockingSensors[testsectionfocus];
Sensor actualReverseBlockingSensor = testsection.getReverseBlockingSensor();
Assert.assertNotNull("Focus was: " + testsectionfocus + " expectedReverseBlockingSensor", expectedReverseBlockingSensor);
Assert.assertNotNull("Focus was: " + testsectionfocus + " actualReverseBlockingSensor", actualReverseBlockingSensor);
Assert.assertTrue("Focus was: " + testsectionfocus + " ReverseBlockingSensor", expectedReverseBlockingSensor.getSystemName().equals(actualReverseBlockingSensor.getSystemName()));
Sensor expectedForwardStoppingSensor = expectedForwardStoppingSensors[testsectionfocus];
Sensor actualForwardStoppingSensor = testsection.getForwardStoppingSensor();
Assert.assertNotNull("Focus was: " + testsectionfocus + " expectedForwardStoppingSensor", expectedForwardStoppingSensor);
Assert.assertNotNull("Focus was: " + testsectionfocus + " actualForwardStoppingSensor", actualForwardStoppingSensor);
Assert.assertTrue("Focus was: " + testsectionfocus + " ForwardStoppingSensor", expectedForwardStoppingSensor.getSystemName().equals(actualForwardStoppingSensor.getSystemName()));
Sensor expectedReverseStoppingSensor = expectedReverseStoppingSensors[testsectionfocus];
Sensor actualReverseStoppingSensor = testsection.getReverseStoppingSensor();
Assert.assertNotNull("Focus was: " + testsectionfocus + " expectedReverseStoppingSensor", expectedReverseStoppingSensor);
Assert.assertNotNull("Focus was: " + testsectionfocus + " actualReverseStoppingSensor", actualReverseStoppingSensor);
Assert.assertTrue("Focus was: " + testsectionfocus + " ReverseStoppingSensor", expectedReverseStoppingSensor.getSystemName().equals(actualReverseStoppingSensor.getSystemName()));
}
}
use of jmri.Block in project JMRI by JMRI.
the class LEConnectivityTest method testShowAndClose.
@SuppressWarnings("unchecked")
public void testShowAndClose() throws Exception {
if (GraphicsEnvironment.isHeadless()) {
// Can't Assume in TestCase
return;
}
jmri.configurexml.ConfigXmlManager cm = new jmri.configurexml.ConfigXmlManager() {
};
// load and display test panel file
java.io.File f = new java.io.File("java/test/jmri/jmrit/display/layoutEditor/valid/LEConnectTest.xml");
cm.load(f);
// time for internal listeners to calm down
sleep(100);
// Find new window by name (should be more distinctive, comes from sample file)
LayoutEditor le = (LayoutEditor) jmri.util.JmriJFrame.getFrame("Connectivity Test");
Assert.assertNotNull(le);
// Panel is up, continue set up for tests.
ConnectivityUtil cu = new ConnectivityUtil(le);
Assert.assertNotNull(cu);
BlockManager bm = jmri.InstanceManager.getDefault(jmri.BlockManager.class);
Assert.assertNotNull(bm);
// Test right-handed crossover connectivity turnout settings
Block cBlock = bm.getBlock("4");
Block pBlock = bm.getBlock("6");
Block nBlock = bm.getBlock("5");
cu.getTurnoutList(cBlock, pBlock, nBlock);
ArrayList<Integer> tsList = cu.getTurnoutSettingList();
int setting = tsList.get(0).intValue();
Assert.assertEquals("6_4_5Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("5");
nBlock = bm.getBlock("6");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("5_4_6Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("5");
nBlock = bm.getBlock("2");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("5_4_2Connect", setting, Turnout.THROWN);
cBlock = bm.getBlock("2");
pBlock = bm.getBlock("1");
nBlock = bm.getBlock("3");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("1_2_3Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("3");
nBlock = bm.getBlock("1");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("3_2_1Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("1");
nBlock = bm.getBlock("4");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("1_2_4Connect", setting, Turnout.THROWN);
// Test left-handed crossover connectivity turnout settings
cBlock = bm.getBlock("14");
pBlock = bm.getBlock("13");
nBlock = bm.getBlock("17");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("13_14_17Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("17");
nBlock = bm.getBlock("13");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("17_14_13Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("17");
nBlock = bm.getBlock("12");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("17_14_12Connect", setting, Turnout.THROWN);
cBlock = bm.getBlock("12");
pBlock = bm.getBlock("11");
nBlock = bm.getBlock("15");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("11_12_15Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("15");
nBlock = bm.getBlock("11");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("15_12_11Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("15");
nBlock = bm.getBlock("14");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("15_12_14Connect", setting, Turnout.THROWN);
// Test double crossover connectivity turnout settings
cBlock = bm.getBlock("21");
pBlock = bm.getBlock("20");
nBlock = bm.getBlock("22");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("20_21_22Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("22");
nBlock = bm.getBlock("20");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("22_21_20Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("20");
nBlock = bm.getBlock("26");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("20_21_26Connect", setting, Turnout.THROWN);
cBlock = bm.getBlock("22");
pBlock = bm.getBlock("23");
nBlock = bm.getBlock("21");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("23_22_21Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("21");
nBlock = bm.getBlock("23");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("21_22_23Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("23");
nBlock = bm.getBlock("25");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("23_22_25Connect", setting, Turnout.THROWN);
cBlock = bm.getBlock("26");
pBlock = bm.getBlock("27");
nBlock = bm.getBlock("25");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("27_26_25Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("25");
nBlock = bm.getBlock("27");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("25_26_27Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("27");
nBlock = bm.getBlock("21");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("27_26_21Connect", setting, Turnout.THROWN);
cBlock = bm.getBlock("25");
pBlock = bm.getBlock("24");
nBlock = bm.getBlock("26");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("24_25_26Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("26");
nBlock = bm.getBlock("24");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("26_25_24Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("24");
nBlock = bm.getBlock("22");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("24_25_22Connect", setting, Turnout.THROWN);
// Test right handed turnout (with "wings" in same block) connectivity turnout settings
cBlock = bm.getBlock("62");
pBlock = bm.getBlock("64");
nBlock = bm.getBlock("61");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("64_62_61Connect", setting, Turnout.THROWN);
pBlock = bm.getBlock("61");
nBlock = bm.getBlock("64");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("61_62_64Connect", setting, Turnout.THROWN);
pBlock = bm.getBlock("63");
nBlock = bm.getBlock("61");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("63_62_61Connect", setting, Turnout.CLOSED);
pBlock = bm.getBlock("61");
nBlock = bm.getBlock("63");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("61_62_63Connect", setting, Turnout.CLOSED);
// Test extended track following connectivity turnout settings
// Each path must go through two turnouts, whose settings are tested in order
cBlock = bm.getBlock("32");
pBlock = bm.getBlock("31");
nBlock = bm.getBlock("33");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("31_32_33ConnectA", setting, Turnout.CLOSED);
setting = tsList.get(1).intValue();
Assert.assertEquals("31_32_33ConnectB", setting, Turnout.THROWN);
pBlock = bm.getBlock("33");
nBlock = bm.getBlock("31");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("33_32_31ConnectA", setting, Turnout.THROWN);
setting = tsList.get(1).intValue();
Assert.assertEquals("33_32_31ConnectB", setting, Turnout.CLOSED);
pBlock = bm.getBlock("31");
nBlock = bm.getBlock("34");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("31_32_34ConnectA", setting, Turnout.CLOSED);
setting = tsList.get(1).intValue();
Assert.assertEquals("31_32_34ConnectB", setting, Turnout.CLOSED);
pBlock = bm.getBlock("34");
nBlock = bm.getBlock("31");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("34_32_31ConnectA", setting, Turnout.CLOSED);
setting = tsList.get(1).intValue();
Assert.assertEquals("34_32_31ConnectB", setting, Turnout.CLOSED);
pBlock = bm.getBlock("31");
nBlock = bm.getBlock("35");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("31_32_35ConnectA", setting, Turnout.THROWN);
setting = tsList.get(1).intValue();
Assert.assertEquals("31_32_35ConnectB", setting, Turnout.CLOSED);
pBlock = bm.getBlock("35");
nBlock = bm.getBlock("31");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("35_32_31ConnectA", setting, Turnout.CLOSED);
setting = tsList.get(1).intValue();
Assert.assertEquals("35_32_31ConnectB", setting, Turnout.THROWN);
pBlock = bm.getBlock("31");
nBlock = bm.getBlock("36");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("31_32_36ConnectA", setting, Turnout.THROWN);
setting = tsList.get(1).intValue();
Assert.assertEquals("31_32_36ConnectB", setting, Turnout.THROWN);
pBlock = bm.getBlock("36");
nBlock = bm.getBlock("31");
cu.getTurnoutList(cBlock, pBlock, nBlock);
tsList = cu.getTurnoutSettingList();
setting = tsList.get(0).intValue();
Assert.assertEquals("36_32_31ConnectA", setting, Turnout.THROWN);
setting = tsList.get(1).intValue();
Assert.assertEquals("36_32_31ConnectB", setting, Turnout.THROWN);
// Ask to close window
TestHelper.disposeWindow(le, this);
// Dialog has popped up, so handle that. First, locate it.
List<JDialog> dialogList = new DialogFinder(null).findAll(le);
JDialog d = dialogList.get(0);
// Find the button that deletes the panel
AbstractButtonFinder finder = new AbstractButtonFinder("Delete Panel");
JButton button = (JButton) finder.find(d, 0);
Assert.assertNotNull(button);
// Click button to delete panel and close window
getHelper().enterClickAndLeave(new MouseEventData(this, button));
// another dialog has popped up, so handle that by finding the "Yes - Delete" button.
dialogList = new DialogFinder(null).findAll(le);
d = dialogList.get(0);
finder = new AbstractButtonFinder("Yes - Delete");
button = (JButton) finder.find(d, 0);
Assert.assertNotNull(button);
// Click to say yes, I really mean it.
getHelper().enterClickAndLeave(new MouseEventData(this, button));
le.dispose();
}
use of jmri.Block in project JMRI by JMRI.
the class BlockTableAction method createModel.
/**
* Create the JTable DataModel, along with the changes for the specific case
* of Block objects.
*/
@Override
protected void createModel() {
// load graphic state column display preference
_graphicState = InstanceManager.getDefault(GuiLafPreferencesManager.class).isGraphicTableState();
m = new BeanTableDataModel() {
public static final int EDITCOL = NUMCOLUMN;
public static final int DIRECTIONCOL = EDITCOL + 1;
public static final int LENGTHCOL = DIRECTIONCOL + 1;
public static final int CURVECOL = LENGTHCOL + 1;
public static final int STATECOL = CURVECOL + 1;
public static final int SENSORCOL = STATECOL + 1;
public static final int REPORTERCOL = SENSORCOL + 1;
public static final int CURRENTREPCOL = REPORTERCOL + 1;
public static final int PERMISCOL = CURRENTREPCOL + 1;
public static final int SPEEDCOL = PERMISCOL + 1;
@Override
public String getValue(String name) {
if (name == null) {
log.warn("requested getValue(null)");
return "(no name)";
}
Block b = InstanceManager.getDefault(jmri.BlockManager.class).getBySystemName(name);
if (b == null) {
log.debug("requested getValue(\"" + name + "\"), Block doesn't exist");
return "(no Block)";
}
Object m = b.getValue();
if (m != null) {
return m.toString();
} else {
return "";
}
}
@Override
public Manager getManager() {
return InstanceManager.getDefault(jmri.BlockManager.class);
}
@Override
public NamedBean getBySystemName(String name) {
return InstanceManager.getDefault(jmri.BlockManager.class).getBySystemName(name);
}
@Override
public NamedBean getByUserName(String name) {
return InstanceManager.getDefault(jmri.BlockManager.class).getByUserName(name);
}
@Override
protected String getMasterClassName() {
return getClassName();
}
@Override
public void clickOn(NamedBean t) {
// don't do anything on click; not used in this class, because
// we override setValueAt
}
//Permissive and speed columns are temp disabled
@Override
public int getColumnCount() {
return SPEEDCOL + 1;
}
@Override
public Object getValueAt(int row, int col) {
// some error checking
if (row >= sysNameList.size()) {
log.debug("requested getValueAt(\"" + row + "\"), row outside of range");
return "Error table size";
}
Block b = (Block) getBySystemName(sysNameList.get(row));
if (b == null) {
log.debug("requested getValueAt(\"" + row + "\"), Block doesn't exist");
return "(no Block)";
}
if (col == DIRECTIONCOL) {
return jmri.Path.decodeDirection(b.getDirection());
} else if (col == CURVECOL) {
JComboBox<String> c = new JComboBox<String>(curveOptions);
if (b.getCurvature() == Block.NONE) {
c.setSelectedItem(0);
} else if (b.getCurvature() == Block.GRADUAL) {
c.setSelectedItem(gradualText);
} else if (b.getCurvature() == Block.TIGHT) {
c.setSelectedItem(tightText);
} else if (b.getCurvature() == Block.SEVERE) {
c.setSelectedItem(severeText);
}
return c;
} else if (col == LENGTHCOL) {
double len = 0.0;
if (inchBox.isSelected()) {
len = b.getLengthIn();
} else {
len = b.getLengthCm();
}
return (twoDigit.format(len));
} else if (col == PERMISCOL) {
boolean val = b.getPermissiveWorking();
return Boolean.valueOf(val);
} else if (col == SPEEDCOL) {
String speed = b.getBlockSpeed();
if (!speedList.contains(speed)) {
speedList.add(speed);
}
JComboBox<String> c = new JComboBox<String>(speedList);
c.setEditable(true);
c.setSelectedItem(speed);
return c;
} else if (col == STATECOL) {
switch(b.getState()) {
case (Block.OCCUPIED):
return Bundle.getMessage("BlockOccupied");
case (Block.UNOCCUPIED):
return Bundle.getMessage("BlockUnOccupied");
case (Block.UNKNOWN):
return Bundle.getMessage("BlockUnknown");
default:
return Bundle.getMessage("BlockInconsistent");
}
} else if (col == SENSORCOL) {
Sensor sensor = b.getSensor();
JComboBox<String> c = new JComboBox<String>(sensorList);
String name = "";
if (sensor != null) {
name = sensor.getDisplayName();
}
c.setSelectedItem(name);
return c;
} else if (col == REPORTERCOL) {
Reporter r = b.getReporter();
return (r != null) ? r.getDisplayName() : null;
} else if (col == CURRENTREPCOL) {
return Boolean.valueOf(b.isReportingCurrent());
} else if (col == EDITCOL) {
//
return Bundle.getMessage("ButtonEdit");
} else {
return super.getValueAt(row, col);
}
}
@Override
public void setValueAt(Object value, int row, int col) {
// no setting of block state from table
Block b = (Block) getBySystemName(sysNameList.get(row));
if (col == VALUECOL) {
b.setValue(value);
fireTableRowsUpdated(row, row);
} else if (col == LENGTHCOL) {
float len = 0.0f;
try {
len = jmri.util.IntlUtilities.floatValue(value.toString());
} catch (java.text.ParseException ex2) {
log.error("Error parsing length value of \"{}\"", value);
}
if (inchBox.isSelected()) {
b.setLength(len * 25.4f);
} else {
b.setLength(len * 10.0f);
}
fireTableRowsUpdated(row, row);
} else if (col == CURVECOL) {
@SuppressWarnings("unchecked") String cName = (String) ((JComboBox<String>) value).getSelectedItem();
if (cName.equals(noneText)) {
b.setCurvature(Block.NONE);
} else if (cName.equals(gradualText)) {
b.setCurvature(Block.GRADUAL);
} else if (cName.equals(tightText)) {
b.setCurvature(Block.TIGHT);
} else if (cName.equals(severeText)) {
b.setCurvature(Block.SEVERE);
}
fireTableRowsUpdated(row, row);
} else if (col == PERMISCOL) {
boolean boo = ((Boolean) value).booleanValue();
b.setPermissiveWorking(boo);
fireTableRowsUpdated(row, row);
} else if (col == SPEEDCOL) {
@SuppressWarnings("unchecked") String speed = (String) ((JComboBox<String>) value).getSelectedItem();
try {
b.setBlockSpeed(speed);
} catch (jmri.JmriException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + speed);
return;
}
if (!speedList.contains(speed) && !speed.contains("Global")) {
// NOI18N
speedList.add(speed);
}
fireTableRowsUpdated(row, row);
} else if (col == REPORTERCOL) {
Reporter r = null;
if (value != null && !value.equals("")) {
r = jmri.InstanceManager.getDefault(jmri.ReporterManager.class).provideReporter((String) value);
}
b.setReporter(r);
fireTableRowsUpdated(row, row);
} else if (col == SENSORCOL) {
@SuppressWarnings("unchecked") String strSensor = (String) ((JComboBox<String>) value).getSelectedItem();
b.setSensor(strSensor);
return;
} else if (col == CURRENTREPCOL) {
boolean boo = ((Boolean) value).booleanValue();
b.setReportingCurrent(boo);
fireTableRowsUpdated(row, row);
} else if (col == EDITCOL) {
class WindowMaker implements Runnable {
Block b;
WindowMaker(Block b) {
this.b = b;
}
@Override
public void run() {
// don't really want to stop Route w/o user action
editButton(b);
}
}
WindowMaker t = new WindowMaker(b);
javax.swing.SwingUtilities.invokeLater(t);
//editButton(b);
} else {
super.setValueAt(value, row, col);
}
}
@Override
public String getColumnName(int col) {
if (col == DIRECTIONCOL) {
return Bundle.getMessage("BlockDirection");
}
if (col == VALUECOL) {
return Bundle.getMessage("BlockValue");
}
if (col == CURVECOL) {
return Bundle.getMessage("BlockCurveColName");
}
if (col == LENGTHCOL) {
return Bundle.getMessage("BlockLengthColName");
}
if (col == PERMISCOL) {
return Bundle.getMessage("BlockPermColName");
}
if (col == SPEEDCOL) {
return Bundle.getMessage("BlockSpeedColName");
}
if (col == STATECOL) {
return Bundle.getMessage("BlockState");
}
if (col == REPORTERCOL) {
return Bundle.getMessage("BlockReporter");
}
if (col == SENSORCOL) {
return Bundle.getMessage("BlockSensor");
}
if (col == CURRENTREPCOL) {
return Bundle.getMessage("BlockReporterCurrent");
}
if (col == EDITCOL) {
return Bundle.getMessage("ButtonEdit");
}
return super.getColumnName(col);
}
@Override
public Class<?> getColumnClass(int col) {
if (col == DIRECTIONCOL) {
return String.class;
}
if (col == VALUECOL) {
// not a button
return String.class;
}
if (col == CURVECOL) {
return JComboBox.class;
}
if (col == LENGTHCOL) {
return String.class;
}
if (col == PERMISCOL) {
return Boolean.class;
}
if (col == SPEEDCOL) {
return JComboBox.class;
}
if (col == STATECOL) {
if (_graphicState) {
// use an image to show block state
return JLabel.class;
} else {
return String.class;
}
}
if (col == REPORTERCOL) {
return String.class;
}
if (col == SENSORCOL) {
return JComboBox.class;
}
if (col == CURRENTREPCOL) {
return Boolean.class;
}
if (col == EDITCOL) {
return JButton.class;
} else {
return super.getColumnClass(col);
}
}
@Override
public int getPreferredWidth(int col) {
if (col == DIRECTIONCOL) {
return new JTextField(7).getPreferredSize().width;
}
if (col == CURVECOL) {
return new JTextField(8).getPreferredSize().width;
}
if (col == LENGTHCOL) {
return new JTextField(7).getPreferredSize().width;
}
if (col == PERMISCOL) {
return new JTextField(7).getPreferredSize().width;
}
if (col == SPEEDCOL) {
return new JTextField(7).getPreferredSize().width;
}
if (col == STATECOL) {
return new JTextField(8).getPreferredSize().width;
}
if (col == REPORTERCOL) {
return new JTextField(8).getPreferredSize().width;
}
if (col == SENSORCOL) {
return new JTextField(8).getPreferredSize().width;
}
if (col == CURRENTREPCOL) {
return new JTextField(7).getPreferredSize().width;
}
if (col == EDITCOL) {
return new JTextField(7).getPreferredSize().width;
} else {
return super.getPreferredWidth(col);
}
}
@Override
public void configValueColumn(JTable table) {
// value column isn't button, so config is null
}
@Override
public boolean isCellEditable(int row, int col) {
if (col == CURVECOL) {
return true;
} else if (col == LENGTHCOL) {
return true;
} else if (col == PERMISCOL) {
return true;
} else if (col == SPEEDCOL) {
return true;
} else if (col == STATECOL) {
return false;
} else if (col == REPORTERCOL) {
return true;
} else if (col == SENSORCOL) {
return true;
} else if (col == CURRENTREPCOL) {
return true;
} else if (col == EDITCOL) {
return true;
} else {
return super.isCellEditable(row, col);
}
}
@Override
public void configureTable(JTable table) {
table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
table.setDefaultRenderer(Boolean.class, new EnablingCheckboxRenderer());
jmri.InstanceManager.sensorManagerInstance().addPropertyChangeListener(this);
configStateColumn(table);
super.configureTable(table);
}
@Override
protected boolean matchPropertyName(java.beans.PropertyChangeEvent e) {
return true;
// return (e.getPropertyName().indexOf("alue")>=0);
}
@Override
public JButton configureButton() {
log.error("configureButton should not have been called");
return null;
}
@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
if (e.getSource() instanceof jmri.SensorManager) {
if (e.getPropertyName().equals("length") || e.getPropertyName().equals("DisplayListName")) {
updateSensorList();
}
}
if (e.getPropertyName().equals("DefaultBlockSpeedChange")) {
updateSpeedList();
} else {
super.propertyChange(e);
}
}
@Override
protected String getBeanType() {
return Bundle.getMessage("BeanNameBlock");
}
@Override
public synchronized void dispose() {
super.dispose();
jmri.InstanceManager.sensorManagerInstance().removePropertyChangeListener(this);
}
/**
* Customize the block table State column to show an appropriate graphic for the block occupancy state
* if _graphicState = true, or (default) just show the localized state text
* when the TableDataModel is being called from ListedTableAction.
*
* @param table a JTable of Blocks
*/
protected void configStateColumn(JTable table) {
// have the state column hold a JPanel (icon)
//setColumnToHoldButton(table, VALUECOL, new JLabel("1234")); // for small round icon, but cannot be converted to JButton
// add extras, override BeanTableDataModel
log.debug("Block configStateColumn (I am {})", super.toString());
if (_graphicState) {
// load icons, only once
//table.setDefaultEditor(JLabel.class, new ImageIconRenderer()); // there's no editor for state column in BlockTable
// item class copied from SwitchboardEditor panel
table.setDefaultRenderer(JLabel.class, new ImageIconRenderer());
// else, classic text style state indication, do nothing extra
}
}
/**
* Visualize state in table as a graphic, customized for Blocks (2 states).
* Renderer and Editor are identical, as the cell contents are not actually edited.
* @see jmri.jmrit.beantable.sensor.SensorTableDataModel.ImageIconRenderer
* @see jmri.jmrit.beantable.TurnoutTableAction#createModel()
* @see jmri.jmrit.beantable.LightTableAction#createModel()
*/
class ImageIconRenderer extends AbstractCellEditor implements TableCellEditor, TableCellRenderer {
protected JLabel label;
// also used in display.switchboardEditor
protected String rootPath = "resources/icons/misc/switchboard/";
// reuse Sensor icon for block state
protected char beanTypeChar = 'S';
protected String onIconPath = rootPath + beanTypeChar + "-on-s.png";
protected String offIconPath = rootPath + beanTypeChar + "-off-s.png";
protected BufferedImage onImage;
protected BufferedImage offImage;
protected ImageIcon onIcon;
protected ImageIcon offIcon;
protected int iconHeight = -1;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
log.debug("Renderer Item = {}, State = {}", row, value);
if (iconHeight < 0) {
// load resources only first time, either for renderer or editor
loadIcons();
log.debug("icons loaded");
}
return updateLabel((String) value, row);
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
log.debug("Renderer Item = {}, State = {}", row, value);
if (iconHeight < 0) {
// load resources only first time, either for renderer or editor
loadIcons();
log.debug("icons loaded");
}
return updateLabel((String) value, row);
}
public JLabel updateLabel(String value, int row) {
if (iconHeight > 0) {
// if necessary, increase row height;
//table.setRowHeight(row, Math.max(table.getRowHeight(), iconHeight - 5)); // TODO adjust table row height for Block icons
}
if (value.equals(Bundle.getMessage("BlockUnOccupied")) && offIcon != null) {
label = new JLabel(offIcon);
label.setVerticalAlignment(JLabel.BOTTOM);
log.debug("offIcon set");
} else if (value.equals(Bundle.getMessage("BlockOccupied")) && onIcon != null) {
label = new JLabel(onIcon);
label.setVerticalAlignment(JLabel.BOTTOM);
log.debug("onIcon set");
} else if (value.equals(Bundle.getMessage("BlockInconsistent"))) {
// centered text alignment
label = new JLabel("X", JLabel.CENTER);
label.setForeground(Color.red);
log.debug("Block state inconsistent");
iconHeight = 0;
} else if (value.equals(Bundle.getMessage("BlockUnknown"))) {
// centered text alignment
label = new JLabel("?", JLabel.CENTER);
log.debug("Block state in transition");
iconHeight = 0;
} else {
// failed to load icon
// centered text alignment
label = new JLabel(value, JLabel.CENTER);
log.warn("Error reading icons for BlockTable");
iconHeight = 0;
}
label.setToolTipText(value);
label.addMouseListener(new MouseAdapter() {
@Override
public final void mousePressed(MouseEvent evt) {
log.debug("Clicked on icon in row {}", row);
stopCellEditing();
}
});
return label;
}
@Override
public Object getCellEditorValue() {
log.debug("getCellEditorValue, me = {})", this.toString());
return this.toString();
}
/**
* Read and buffer graphics. Only called once for this table.
* @see #getTableCellEditorComponent(JTable, Object, boolean, int, int)
*/
protected void loadIcons() {
try {
onImage = ImageIO.read(new File(onIconPath));
offImage = ImageIO.read(new File(offIconPath));
} catch (IOException ex) {
log.error("error reading image from {} or {}", onIconPath, offIconPath, ex);
}
log.debug("Success reading images");
int imageWidth = onImage.getWidth();
int imageHeight = onImage.getHeight();
// scale icons 50% to fit in table rows
Image smallOnImage = onImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_DEFAULT);
Image smallOffImage = offImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_DEFAULT);
onIcon = new ImageIcon(smallOnImage);
offIcon = new ImageIcon(smallOffImage);
iconHeight = onIcon.getIconHeight();
}
}
};
// end of custom data model
}
use of jmri.Block in project JMRI by JMRI.
the class Maintenance method search.
/**
* Search if a given string is used as the name of a NamedBean.
*
* @param name the string to look for
* @param text body of the message to be displayed reporting the result
* @return true if name is found at least once as a bean name
*/
static boolean search(String name, JTextArea text) {
String[] names = getTypeAndNames(name);
if (log.isDebugEnabled()) {
log.debug("search for " + name + " as " + names[0] + " \"" + names[1] + "\" (" + names[2] + ")");
}
if (names[0].length() == 0) {
if (text != null) {
text.append(MessageFormat.format(rbm.getString("ElementNotFound"), (Object[]) names));
return false;
}
}
if (text != null) {
text.append(MessageFormat.format(rbm.getString("ReferenceFollows"), (Object[]) names));
}
String sysName = names[2];
String userName = names[1];
int referenceCount = 0;
StringBuilder tempText = new StringBuilder();
boolean found = false;
boolean empty = true;
// search for references among each class known to be listeners
Iterator<String> iter1 = InstanceManager.getDefault(jmri.LogixManager.class).getSystemNameList().iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
Logix x = InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(sName);
if (x == null) {
log.error("Error getting Logix - " + sName);
break;
}
tempText = new StringBuilder();
String uName = x.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "", Bundle.getMessage("BeanNameLogix"), uName, sName });
for (int i = 0; i < x.getNumConditionals(); i++) {
sName = x.getConditionalByNumberOrder(i);
if (sName == null) {
log.error("Null conditional system name");
break;
}
Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).getBySystemName(sName);
if (c == null) {
log.error("Invalid conditional system name - " + sName);
break;
}
uName = c.getUserName();
String line2 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t", Bundle.getMessage("BeanNameConditional"), uName, sName });
String line = MessageFormat.format(rbm.getString("ConditionalReference"), "\t");
if (sysName.equals(sName) || (userName != null && userName.length() > 0 && userName.equals(uName))) {
if (testName(sysName, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
ArrayList<ConditionalVariable> variableList = c.getCopyOfStateVariables();
for (int k = 0; k < variableList.size(); k++) {
ConditionalVariable v = variableList.get(k);
line = MessageFormat.format(rbm.getString("VariableReference"), new Object[] { "\t\t", v.getTestTypeString(), v.getDataString() });
if (testName(v.getName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
}
ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
for (int k = 0; k < actionList.size(); k++) {
ConditionalAction a = actionList.get(k);
line = MessageFormat.format(rbm.getString("ActionReference"), new Object[] { "\t\t", a.getTypeString(), a.getOptionString(false), a.getActionDataString() });
if (testName(a.getDeviceName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
line1 = null;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append("\t" + MessageFormat.format(rbm.getString("NoReference"), "Logix"));
// cannot put escaped tab char at start of getString
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
jmri.jmrit.logix.OBlockManager oBlockManager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
iter1 = oBlockManager.getSystemNameList().iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.jmrit.logix.OBlock block = oBlockManager.getBySystemName(sName);
String uName = block.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameOBlock"), uName, sName });
Sensor sensor = block.getSensor();
if (sensor != null) {
String line = MessageFormat.format(rbm.getString("OBlockSensor"), "\t");
if (testName(sensor.getSystemName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "OBlock"));
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
jmri.RouteManager routeManager = InstanceManager.getDefault(jmri.RouteManager.class);
iter1 = routeManager.getSystemNameList().iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.Route r = routeManager.getBySystemName(sName);
if (r == null) {
log.error("Error getting Route - " + sName);
break;
}
String uName = r.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameRoute"), uName, sName });
for (int i = 0; i < jmri.Route.MAX_CONTROL_SENSORS; i++) {
String line = "\t" + MessageFormat.format(rbm.getString("ControlReference"), Bundle.getMessage("BeanNameSensor"));
if (testName(r.getRouteSensorName(i), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
String line = MessageFormat.format("TurnoutsAlignedSensor", Bundle.getMessage("BeanNameSensor"));
if (testName(r.getTurnoutsAlignedSensor(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = "\t" + MessageFormat.format(rbm.getString("ControlReference"), Bundle.getMessage("BeanNameTurnout"));
if (testName(r.getControlTurnout(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format("LockControlTurnout", Bundle.getMessage("BeanNameTurnout"));
if (testName(r.getLockControlTurnout(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
for (int i = 0; i < r.getNumOutputTurnouts(); i++) {
line = "\t" + MessageFormat.format(rbm.getString("OutputReference"), Bundle.getMessage("BeanNameTurnout"));
if (testName(r.getOutputTurnoutByIndex(i), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
for (int i = 0; i < r.getNumOutputSensors(); i++) {
line = "\t" + MessageFormat.format(rbm.getString("OutputReference"), Bundle.getMessage("BeanNameSensor"));
if (testName(r.getOutputSensorByIndex(i), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "Route"));
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
jmri.TransitManager transitManager = InstanceManager.getDefault(jmri.TransitManager.class);
iter1 = transitManager.getSystemNameList().iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.Transit transit = transitManager.getBySystemName(sName);
if (transit == null) {
log.error("Error getting Transit - " + sName);
break;
}
String uName = transit.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameTransit"), uName, sName });
ArrayList<jmri.TransitSection> sectionList = transit.getTransitSectionList();
for (int i = 0; i < sectionList.size(); i++) {
jmri.TransitSection transitSection = sectionList.get(i);
jmri.Section section = transitSection.getSection();
uName = section.getUserName();
sName = section.getSystemName();
String line2 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t", rbm.getString("TransitSection"), uName, sName });
if (sName.equals(sysName) || uName.equals(userName)) {
tempText.append(line1);
tempText.append(line2);
tempText.append(MessageFormat.format(rbm.getString("SectionReference"), "\t\t"));
found = true;
referenceCount++;
}
String line = MessageFormat.format(rbm.getString("ForwardBlocking"), "\t\t");
if (testName(section.getForwardBlockingSensorName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("ForwardStopping"), "\t\t");
if (testName(section.getForwardStoppingSensorName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("ReverseBlocking"), "\t\t");
if (testName(section.getReverseBlockingSensorName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("ReverseStopping"), "\t\t");
if (testName(section.getReverseStoppingSensorName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
ArrayList<jmri.Block> blockList = section.getBlockList();
for (int k = 0; k < blockList.size(); k++) {
jmri.Block block = blockList.get(k);
sName = block.getSystemName();
uName = block.getUserName();
tempText.append(MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t\t", Bundle.getMessage("BeanNameBlock"), uName, sName }));
if (sName.equals(sysName) || uName.equals(userName)) {
tempText.append(MessageFormat.format(rbm.getString("BlockReference"), "\t\t"));
found = true;
referenceCount++;
}
Sensor sensor = block.getSensor();
if (sensor != null) {
line = MessageFormat.format(rbm.getString("BlockSensor"), "\t\t");
if (testName(sensor.getSystemName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
line1 = null;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "Transit"));
} else {
text.append("\n");
}
}
// if (text != null) {
// text.append(rbm.getString("NestMessage"));
// }
tempText = new StringBuilder();
found = false;
empty = true;
jmri.SectionManager sectionManager = InstanceManager.getDefault(jmri.SectionManager.class);
java.util.List<String> sysNameList = sectionManager.getSystemNameList();
transitManager = InstanceManager.getDefault(jmri.TransitManager.class);
iter1 = transitManager.getSystemNameList().iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.Transit transit = transitManager.getBySystemName(sName);
if (transit != null) {
ArrayList<jmri.TransitSection> sectionList = transit.getTransitSectionList();
for (int i = 0; i < sectionList.size(); i++) {
jmri.TransitSection transitSection = sectionList.get(i);
jmri.Section section = transitSection.getSection();
sysNameList.remove(section.getSystemName());
}
}
}
iter1 = sysNameList.iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.Section section = sectionManager.getBySystemName(sName);
if (section == null) {
log.error("Error getting Section - " + sName);
break;
}
String uName = section.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameSection"), uName, sName });
if (sName.equals(sysName) || uName.equals(userName)) {
tempText.append(MessageFormat.format(rbm.getString("SectionReference"), "\t"));
found = true;
referenceCount++;
}
String line = MessageFormat.format(rbm.getString("ForwardBlocking"), "\t");
if (testName(section.getForwardBlockingSensorName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("ForwardStopping"), "\t");
if (testName(section.getForwardStoppingSensorName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("ReverseBlocking"), "\t");
if (testName(section.getReverseBlockingSensorName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("ReverseStopping"), "\t");
if (testName(section.getReverseStoppingSensorName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
ArrayList<jmri.Block> blockList = section.getBlockList();
for (int k = 0; k < blockList.size(); k++) {
jmri.Block block = blockList.get(k);
sName = block.getSystemName();
uName = block.getUserName();
String line2 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t", Bundle.getMessage("BeanNameBlock"), uName, sName });
if (sName.equals(sysName) || (uName != null && uName.equals(userName))) {
tempText.append(line2);
tempText.append(MessageFormat.format(rbm.getString("BlockReference"), "\t"));
found = true;
referenceCount++;
}
Sensor sensor = block.getSensor();
if (sensor != null) {
line = MessageFormat.format(rbm.getString("BlockSensor"), "\t\t");
if (testName(sensor.getSystemName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "Section"));
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
jmri.BlockManager blockManager = InstanceManager.getDefault(jmri.BlockManager.class);
sysNameList = blockManager.getSystemNameList();
sectionManager = InstanceManager.getDefault(jmri.SectionManager.class);
iter1 = sectionManager.getSystemNameList().iterator();
while (iter1.hasNext()) {
String sName = iter1.next();
jmri.Section section = sectionManager.getBySystemName(sName);
if (section != null) {
for (Block block : section.getBlockList()) {
sysNameList.remove(block.getSystemName());
}
}
}
iter1 = sysNameList.iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.Block b = blockManager.getBySystemName(sName);
String uName = b.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameBlock"), uName, sName });
if (sName.equals(sysName) || (uName != null && uName.equals(userName))) {
tempText.append(line1);
tempText.append(MessageFormat.format(rbm.getString("BlockReference"), "\t"));
found = true;
referenceCount++;
}
jmri.Sensor s = b.getSensor();
if (s != null) {
String line = MessageFormat.format(rbm.getString("BlockSensor"), "\t\t");
if (testName(s.getSystemName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "Block"));
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
jmri.jmrit.display.layoutEditor.LayoutBlockManager lbm = InstanceManager.getDefault(LayoutBlockManager.class);
iter1 = lbm.getSystemNameList().iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.jmrit.display.layoutEditor.LayoutBlock lb = lbm.getBySystemName(sName);
if (lb == null) {
log.error("Error getting LayoutBlock - " + sName);
break;
}
String uName = lb.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", rbm.getString("LayoutBlock"), uName, sName });
jmri.Sensor s = lb.getOccupancySensor();
if (s != null) {
String line = MessageFormat.format(rbm.getString("OccupancySensor"), "\t\t");
if (testName(s.getSystemName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "LayoutBlock"));
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
java.util.Enumeration<BlockBossLogic> enumeration = BlockBossLogic.entries();
while (enumeration.hasMoreElements()) {
// get the next Logix
BlockBossLogic bbl = enumeration.nextElement();
String sName = bbl.getName();
String uName = bbl.getDrivenSignal();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", rbm.getString("BlockBossLogic"), uName, sName });
if (uName.equals(sysName) || uName.equals(userName) || sName.equals(sysName) || sName.equals(userName)) {
tempText.append(line1);
tempText.append(MessageFormat.format(rbm.getString("SignalReference"), "\t"));
found = true;
referenceCount++;
}
String line = MessageFormat.format(rbm.getString("WatchSensorReference"), "1\t");
if (testName(bbl.getSensor1(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "2\t");
if (testName(bbl.getSensor2(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "3\t");
if (testName(bbl.getSensor3(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "4\t");
if (testName(bbl.getSensor4(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "5\t");
if (testName(bbl.getSensor5(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "\t");
if (testName(bbl.getTurnout(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSignalReference"), "1\t");
if (testName(bbl.getWatchedSignal1(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "1Alt\t");
if (testName(bbl.getWatchedSignal1Alt(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "2\t");
if (testName(bbl.getWatchedSignal2(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "2Alt\t");
if (testName(bbl.getWatchedSignal2Alt(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "1\t");
if (testName(bbl.getWatchedSensor1(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "1Alt\t");
if (testName(bbl.getWatchedSensor1Alt(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "2\t");
if (testName(bbl.getWatchedSensor2(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "2Alt\t");
if (testName(bbl.getWatchedSensor2Alt(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "BlockBossLogic"));
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
jmri.ConditionalManager conditionalManager = InstanceManager.getDefault(jmri.ConditionalManager.class);
sysNameList = conditionalManager.getSystemNameList();
iter1 = InstanceManager.getDefault(jmri.LogixManager.class).getSystemNameList().iterator();
while (iter1.hasNext()) {
String sName = iter1.next();
Logix x = InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(sName);
for (int i = 0; i < x.getNumConditionals(); i++) {
sName = x.getConditionalByNumberOrder(i);
sysNameList.remove(sName);
}
}
iter1 = sysNameList.iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.Conditional c = conditionalManager.getBySystemName(sName);
if (c == null) {
log.error("Error getting Condition - " + sName);
break;
}
String uName = c.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameConditional"), uName, sName });
if (sName.equals(sysName) || uName.equals(userName)) {
tempText.append(line1);
tempText.append(MessageFormat.format(rbm.getString("ConditionalReference"), "\t"));
found = true;
//referenceCount++; Don't count, this conditional is orphaned by logix(es)
}
ArrayList<ConditionalVariable> variableList = c.getCopyOfStateVariables();
for (int k = 0; k < variableList.size(); k++) {
ConditionalVariable v = variableList.get(k);
String line = MessageFormat.format(rbm.getString("VariableReference"), new Object[] { "\t\t", v.getTestTypeString(), v.getDataString() });
if (testName(v.getName(), found, names, line1, null, line, tempText)) {
found = true;
//referenceCount++; Don't count, this conditional is orphaned by logix(es)
}
}
ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
for (int k = 0; k < actionList.size(); k++) {
ConditionalAction a = actionList.get(k);
String line = MessageFormat.format(rbm.getString("ActionReference"), new Object[] { "\t\t", a.getTypeString(), a.getOptionString(false), a.getActionDataString() });
if (testName(a.getDeviceName(), found, names, line1, null, line, tempText)) {
found = true;
//referenceCount++; Don't count, this conditional is orphaned by logix(es)
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
line1 = null;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "Conditional"));
}
text.append("\n");
}
found = false;
empty = true;
ArrayList<jmri.jmrit.display.Editor> panelList = jmri.jmrit.display.PanelMenu.instance().getEditorPanelList();
for (int i = 0; i < panelList.size(); i++) {
jmri.jmrit.display.Editor panelEditor = panelList.get(i);
name = panelEditor.getTitle();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", rbm.getString("Panel"), name, name });
List<Positionable> contents = panelEditor.getContents();
for (int k = 0; k < contents.size(); k++) {
Positionable o = contents.get(k);
if (o.getClass().getName().equals("jmri.jmrit.display.SensorIcon")) {
name = ((jmri.jmrit.display.SensorIcon) o).getSensor().getSystemName();
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("BeanNameSensor") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
} else if (o.getClass().getName().equals("jmri.jmrit.display.TurnoutIcon")) {
name = ((jmri.jmrit.display.TurnoutIcon) o).getTurnout().getSystemName();
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("BeanNameTurnout") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
} else if (o.getClass().getName().equals("jmri.jmrit.display.SignalHeadIcon")) {
name = ((jmri.jmrit.display.SignalHeadIcon) o).getSignalHead().getSystemName();
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("BeanNameSignalHead") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
} else if (o.getClass().getName().equals("jmri.jmrit.display.MultiSensorIcon")) {
jmri.jmrit.display.MultiSensorIcon msi = (jmri.jmrit.display.MultiSensorIcon) o;
for (int j = 0; j < msi.getNumEntries(); j++) {
name = msi.getSensorName(j);
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("MultiSensor") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
} else if (o.getClass().getName().equals("jmri.jmrit.display.IndicatorTurnoutIcon")) {
jmri.jmrit.display.IndicatorTurnoutIcon ito = (jmri.jmrit.display.IndicatorTurnoutIcon) o;
name = ito.getTurnout().getSystemName();
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTO") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
Sensor sensor = ito.getOccSensor();
if (sensor != null) {
name = sensor.getSystemName();
line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTO") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
jmri.jmrit.logix.OBlock block = ito.getOccBlock();
if (block != null) {
sensor = block.getSensor();
if (sensor != null) {
name = sensor.getSystemName();
line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTO") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
}
} else if (o.getClass().getName().equals("jmri.jmrit.display.IndicatorTrackIcon")) {
jmri.jmrit.display.IndicatorTrackIcon track = (jmri.jmrit.display.IndicatorTrackIcon) o;
Sensor sensor = track.getOccSensor();
if (sensor != null) {
name = sensor.getSystemName();
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTrack") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
jmri.jmrit.logix.OBlock block = track.getOccBlock();
if (block != null) {
sensor = block.getSensor();
if (sensor != null) {
name = sensor.getSystemName();
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTrack") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
line1 = null;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "Panel"));
}
}
}
if (text != null) {
if (referenceCount == 0) {
text.append(MessageFormat.format(rbm.getString("Orphan"), (Object[]) names));
} else {
text.append(MessageFormat.format(rbm.getString("ReferenceFound"), new Object[] { Integer.valueOf(referenceCount), userName, sysName }));
}
}
if (names[0] != null) {
// The manager is always a listener
int numListeners = Integer.parseInt(names[3]) - 1;
// PickLists are also listeners
numListeners = numListeners - jmri.jmrit.picker.PickListModel.getNumInstances(names[0]);
if (names[0].equals("Sensor")) {
// NOI18N
numListeners = numListeners - jmri.jmrit.picker.PickListModel.getNumInstances("MultiSensor");
}
if (numListeners > referenceCount) {
if (names[0].length() == 0) {
names[0] = "Unknown Type?";
}
/*
JOptionPane.showMessageDialog(null,
MessageFormat.format(rbm.getString("OrphanName"), (Object[])names)+" has "+numListeners+
" listeners installed and only "+referenceCount+
" references found.\n"+names[0]+
" Tables are listeneners. Check that the table is closed.",
rbm.getString("infoTitle"), JOptionPane.INFORMATION_MESSAGE);
*/
if (text != null) {
text.append(MessageFormat.format(rbm.getString("OrphanName"), (Object[]) names) + " has " + numListeners + " listeners installed and only " + referenceCount + " references found.\n" + names[0] + " Tables are listeneners. Check that the table is closed.");
}
}
}
return (referenceCount > 0);
}
use of jmri.Block in project JMRI by JMRI.
the class DispatcherFrame method checkBlocksNotInAllocatedSection.
/*
* This is used to determine if the blocks in a section we want to allocate are already allocated to a section, or if they are now free.
*/
protected Section checkBlocksNotInAllocatedSection(Section s, AllocationRequest ar) {
for (AllocatedSection as : allocatedSections) {
if (as.getSection() != s) {
ArrayList<Block> blas = as.getSection().getBlockList();
//
// When allocating the initial section for an Active Train,
// we need not be concerned with any blocks in the initial section
// which are unoccupied and to the rear of any occupied blocks in
// the section as the train is not expected to enter those blocks.
// When sections include the OS section these blocks prevented
// allocation.
//
// The procedure is to remove those blocks (for the moment) from
// the blocklist for the section during the initial allocation.
//
ArrayList<Block> bls = new ArrayList<>();
if (ar != null && ar.getActiveTrain().getAllocatedSectionList().size() == 0) {
int j;
if (ar.getSectionDirection() == Section.FORWARD) {
j = 0;
for (int i = 0; i < s.getBlockList().size(); i++) {
if (j == 0 && s.getBlockList().get(i).getState() == Block.OCCUPIED) {
j = 1;
}
if (j == 1) {
bls.add(s.getBlockList().get(i));
}
}
} else {
j = 0;
for (int i = s.getBlockList().size() - 1; i >= 0; i--) {
if (j == 0 && s.getBlockList().get(i).getState() == Block.OCCUPIED) {
j = 1;
}
if (j == 1) {
bls.add(s.getBlockList().get(i));
}
}
}
} else {
bls = s.getBlockList();
}
for (Block b : bls) {
if (blas.contains(b)) {
if (as.getSection().getOccupancy() == Block.OCCUPIED) {
//The next check looks to see if the block has already been passed or not and therefore ready for allocation.
if (as.getSection().getState() == Section.FORWARD) {
for (int i = 0; i < blas.size(); i++) {
//The block we get to is occupied therefore the subsequent blocks have not been entered
if (blas.get(i).getState() == Block.OCCUPIED) {
if (ar != null) {
ar.setWaitingOnBlock(b);
}
return as.getSection();
} else if (blas.get(i) == b) {
break;
}
}
} else {
for (int i = blas.size(); i >= 0; i--) {
//The block we get to is occupied therefore the subsequent blocks have not been entered
if (blas.get(i).getState() == Block.OCCUPIED) {
if (ar != null) {
ar.setWaitingOnBlock(b);
}
return as.getSection();
} else if (blas.get(i) == b) {
break;
}
}
}
} else if (as.getSection().getOccupancy() != Section.FREE) {
if (ar != null) {
ar.setWaitingOnBlock(b);
}
return as.getSection();
}
}
}
}
}
return null;
}
Aggregations