Search in sources :

Example 1 with EntryPoint

use of jmri.EntryPoint 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()));
    }
}
Also used : Path(jmri.Path) Memory(jmri.Memory) EntryPoint(jmri.EntryPoint) Section(jmri.Section) EntryPoint(jmri.EntryPoint) ConfigureManager(jmri.ConfigureManager) Block(jmri.Block) Sensor(jmri.Sensor)

Example 2 with EntryPoint

use of jmri.EntryPoint in project JMRI by JMRI.

the class AutoTurnouts method turnoutUtil.

/**
     * Internal method implementing the above two methods Returns 'true' if
     * turnouts are set correctly, 'false' otherwise If 'set' is 'true' this
     * routine will attempt to set the turnouts, if 'false' it reports what it
     * finds.
     */
private boolean turnoutUtil(Section s, int seqNum, Section nextSection, ActiveTrain at, LayoutEditor le, boolean trustKnownTurnouts, boolean set, Section prevSection) {
    // validate input and initialize
    Transit tran = at.getTransit();
    if ((s == null) || (seqNum > tran.getMaxSequence()) || (!tran.containsSection(s)) || (le == null)) {
        log.error("Invalid argument when checking or setting turnouts in Section.");
        return false;
    }
    int direction = at.getAllocationDirectionFromSectionAndSeq(s, seqNum);
    if (direction == 0) {
        log.error("Invalid Section/sequence arguments when checking or setting turnouts");
        return false;
    }
    // check for no turnouts in this section
    if (_dispatcher.getSignalType() == DispatcherFrame.SIGNALHEAD && (s.getForwardEntryPointList().size() <= 1) && (s.getReverseEntryPointList().size() <= 1)) {
        log.debug("No entry points lists");
        // no possibility of turnouts
        return true;
    }
    // initialize connectivity utilities and beginning block pointers
    ConnectivityUtil ct = le.getConnectivityUtil();
    EntryPoint entryPt = null;
    if (prevSection != null) {
        entryPt = s.getEntryPointFromSection(prevSection, direction);
    } else if (!s.containsBlock(at.getStartBlock())) {
        entryPt = s.getEntryPointFromBlock(at.getStartBlock(), direction);
    }
    EntryPoint exitPt = null;
    if (nextSection != null) {
        exitPt = s.getExitPointToSection(nextSection, direction);
    }
    // must be in the section
    Block curBlock = null;
    // must start outside the section or be null
    Block prevBlock = null;
    // sequence number of curBlock in Section
    int curBlockSeqNum = -1;
    if (entryPt != null) {
        curBlock = entryPt.getBlock();
        prevBlock = entryPt.getFromBlock();
        curBlockSeqNum = s.getBlockSequenceNumber(curBlock);
    } else if (!at.isAllocationReversed() && s.containsBlock(at.getStartBlock())) {
        curBlock = at.getStartBlock();
        curBlockSeqNum = s.getBlockSequenceNumber(curBlock);
        //Get the previous block so that we can set the turnouts in the current block correctly.
        if (direction == Section.FORWARD) {
            prevBlock = s.getBlockBySequenceNumber(curBlockSeqNum - 1);
        } else if (direction == Section.REVERSE) {
            prevBlock = s.getBlockBySequenceNumber(curBlockSeqNum + 1);
        }
    } else if (at.isAllocationReversed() && s.containsBlock(at.getEndBlock())) {
        curBlock = at.getEndBlock();
        curBlockSeqNum = s.getBlockSequenceNumber(curBlock);
        //Get the previous block so that we can set the turnouts in the current block correctly.
        if (direction == Section.REVERSE) {
            prevBlock = s.getBlockBySequenceNumber(curBlockSeqNum + 1);
        } else if (direction == Section.FORWARD) {
            prevBlock = s.getBlockBySequenceNumber(curBlockSeqNum - 1);
        }
    } else {
        if (_dispatcher.getSignalType() == DispatcherFrame.SIGNALMAST) {
            //This can be considered normal where SignalMast Logic is used.
            return true;
        }
        log.error("Error in turnout check/set request - initial Block and Section mismatch");
        return false;
    }
    Block nextBlock = null;
    // may be either in the section or the first block in the next section
    // sequence number of nextBlock in Section (-1 indicates outside Section)
    int nextBlockSeqNum = -1;
    if (exitPt != null && curBlock == exitPt.getBlock()) {
        // next Block is outside of the Section
        nextBlock = exitPt.getFromBlock();
    } else {
        // next Block is inside the Section
        if (direction == Section.FORWARD) {
            nextBlock = s.getBlockBySequenceNumber(curBlockSeqNum + 1);
            nextBlockSeqNum = curBlockSeqNum + 1;
        } else if (direction == Section.REVERSE) {
            nextBlock = s.getBlockBySequenceNumber(curBlockSeqNum - 1);
            nextBlockSeqNum = curBlockSeqNum - 1;
        }
        if ((nextBlock == null) && (curBlock != at.getEndBlock())) {
            log.error("Error in block sequence numbers when setting/checking turnouts");
            return false;
        }
    }
    ArrayList<LayoutTurnout> turnoutList = new ArrayList<LayoutTurnout>();
    ArrayList<Integer> settingsList = new ArrayList<Integer>();
    // get turnouts by Block
    boolean turnoutsOK = true;
    while (curBlock != null) {
        /*No point in getting the list if the previous block is null as it will return empty and generate an error, 
             this will only happen on the first run.  Plus working on the basis that the turnouts in the current block would have already of 
             been set correctly for the train to have arrived in the first place.
             */
        if (prevBlock != null) {
            turnoutList = ct.getTurnoutList(curBlock, prevBlock, nextBlock);
            settingsList = ct.getTurnoutSettingList();
        }
        // loop over turnouts checking and optionally setting turnouts
        for (int i = 0; i < turnoutList.size(); i++) {
            Turnout to = turnoutList.get(i).getTurnout();
            int setting = settingsList.get(i).intValue();
            if (turnoutList.get(i) instanceof LayoutSlip) {
                setting = ((LayoutSlip) turnoutList.get(i)).getTurnoutState(settingsList.get(i));
            }
            // check or ignore current setting based on flag, set in Options
            if (!trustKnownTurnouts) {
                log.debug("{}: setting turnout {} to {}", at.getTrainName(), to.getFullyFormattedDisplayName(), (setting == Turnout.CLOSED ? closedText : thrownText));
                to.setCommandedState(setting);
                try {
                    Thread.sleep(100);
                } catch (Exception ex) {
                }
            //TODO: move this to separate thread
            } else {
                if (to.getKnownState() != setting) {
                    // turnout is not set correctly
                    if (set) {
                        // setting has been requested, is Section free and Block unoccupied
                        if ((s.getState() == Section.FREE) && (curBlock.getState() != Block.OCCUPIED)) {
                            // send setting command
                            log.debug("{}: turnout {} commanded to {}", at.getTrainName(), to.getFullyFormattedDisplayName(), (setting == Turnout.CLOSED ? closedText : thrownText));
                            to.setCommandedState(setting);
                            try {
                                Thread.sleep(100);
                            } catch (Exception ex) {
                            }
                        //TODO: move this to separate thread
                        } else {
                            turnoutsOK = false;
                        }
                    } else {
                        turnoutsOK = false;
                    }
                } else {
                    log.debug("{}: turnout {} already {}, skipping", at.getTrainName(), to.getFullyFormattedDisplayName(), (setting == Turnout.CLOSED ? closedText : thrownText));
                }
            }
            if (turnoutList.get(i) instanceof LayoutSlip) {
                //Look at the state of the second turnout in the slip
                setting = ((LayoutSlip) turnoutList.get(i)).getTurnoutBState(settingsList.get(i));
                to = ((LayoutSlip) turnoutList.get(i)).getTurnoutB();
                if (!trustKnownTurnouts) {
                    to.setCommandedState(setting);
                } else if (to.getKnownState() != setting) {
                    // turnout is not set correctly
                    if (set) {
                        // setting has been requested, is Section free and Block unoccupied
                        if ((s.getState() == Section.FREE) && (curBlock.getState() != Block.OCCUPIED)) {
                            // send setting command
                            to.setCommandedState(setting);
                        } else {
                            turnoutsOK = false;
                        }
                    } else {
                        turnoutsOK = false;
                    }
                }
            }
        }
        if (turnoutsOK) {
            // move to next Block if any
            if (nextBlockSeqNum >= 0) {
                prevBlock = curBlock;
                curBlock = nextBlock;
                curBlockSeqNum = nextBlockSeqNum;
                if ((exitPt != null) && (curBlock == exitPt.getBlock())) {
                    // next block is outside of the Section
                    nextBlock = exitPt.getFromBlock();
                    nextBlockSeqNum = -1;
                } else {
                    if (direction == Section.FORWARD) {
                        nextBlockSeqNum++;
                    } else {
                        nextBlockSeqNum--;
                    }
                    nextBlock = s.getBlockBySequenceNumber(nextBlockSeqNum);
                    if (nextBlock == null) {
                        // there is no next Block
                        nextBlockSeqNum = -1;
                    }
                }
            } else {
                curBlock = null;
            }
        } else {
            curBlock = null;
        }
    }
    return turnoutsOK;
}
Also used : LayoutSlip(jmri.jmrit.display.layoutEditor.LayoutSlip) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) ArrayList(java.util.ArrayList) EntryPoint(jmri.EntryPoint) Transit(jmri.Transit) EntryPoint(jmri.EntryPoint) Block(jmri.Block) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) Turnout(jmri.Turnout) ConnectivityUtil(jmri.jmrit.display.layoutEditor.ConnectivityUtil)

Example 3 with EntryPoint

use of jmri.EntryPoint in project JMRI by JMRI.

the class SectionManagerXml method loadSections.

/**
     * Utility method to load the individual Section objects. If there's no
     * additional info needed for a specific Section type, invoke this with the
     * parent of the set of Section elements.
     *
     * @param sharedSections  Element containing the Section elements to load.
     * @param perNodeSections Per-node Element containing the Section elements
     *                        to load.
     */
public void loadSections(Element sharedSections, Element perNodeSections) {
    List<Element> sectionList = sharedSections.getChildren("section");
    if (log.isDebugEnabled()) {
        log.debug("Found " + sectionList.size() + " sections");
    }
    SectionManager tm = InstanceManager.getDefault(jmri.SectionManager.class);
    for (int i = 0; i < sectionList.size(); i++) {
        String sysName = getSystemName(sectionList.get(i));
        String userName = getUserName(sectionList.get(i));
        Section x = tm.createNewSection(sysName, userName);
        if (x != null) {
            // load common part
            loadCommon(x, (sectionList.get(i)));
            if (sectionList.get(i).getAttribute("creationtype") != null) {
                String creationType = sectionList.get(i).getAttribute("creationtype").getValue();
                if (creationType.equals("userdefined")) {
                    x.setSectionType(Section.USERDEFINED);
                } else if (creationType.equals("signalmastlogic")) {
                    x.setSectionType(Section.SIGNALMASTLOGIC);
                }
            }
            if (sectionList.get(i).getAttribute("fsensorname") != null) {
                String forName = (sectionList.get(i)).getAttribute("fsensorname").getValue();
                x.delayedSetForwardBlockingSensorName(forName);
            }
            if (sectionList.get(i).getAttribute("rsensorname") != null) {
                String revName = sectionList.get(i).getAttribute("rsensorname").getValue();
                x.delayedSetReverseBlockingSensorName(revName);
            }
            if (sectionList.get(i).getAttribute("fstopsensorname") != null) {
                String forName = sectionList.get(i).getAttribute("fstopsensorname").getValue();
                x.delayedSetForwardStoppingSensorName(forName);
            }
            if (sectionList.get(i).getAttribute("rstopsensorname") != null) {
                String revName = sectionList.get(i).getAttribute("rstopsensorname").getValue();
                x.delayedSetReverseStoppingSensorName(revName);
            }
            // load block entry children
            List<Element> sectionBlockList = sectionList.get(i).getChildren("blockentry");
            for (int n = 0; n < sectionBlockList.size(); n++) {
                Element elem = sectionBlockList.get(n);
                x.delayedAddBlock(elem.getAttribute("sName").getValue());
            // insert code here to verify sequence number if needed in the future
            }
            // load entry point children
            List<Element> sectionEntryPointList = sectionList.get(i).getChildren("entrypoint");
            for (int n = 0; n < sectionEntryPointList.size(); n++) {
                Element elem = sectionEntryPointList.get(n);
                String blockName = elem.getAttribute("toblock").getValue();
                String fromBlockName = elem.getAttribute("fromblock").getValue();
                String fromBlockDirection = "";
                if (elem.getAttribute("fromblockdirection") != null) {
                    fromBlockDirection = elem.getAttribute("fromblockdirection").getValue();
                }
                EntryPoint ep = new EntryPoint(blockName, fromBlockName, fromBlockDirection);
                //if (ep!=null) {
                try {
                    ep.setDirection(elem.getAttribute("direction").getIntValue());
                } catch (Exception e) {
                    log.error("Data Conversion Exception when loading direction of entry point - " + e);
                }
                boolean fixed = true;
                if (elem.getAttribute("fixed").getValue().equals("no")) {
                    fixed = false;
                }
                ep.setFixed(fixed);
                if (ep.isForwardType()) {
                    x.addToForwardList(ep);
                } else if (ep.isReverseType()) {
                    x.addToReverseList(ep);
                }
            //}
            }
        }
    }
}
Also used : SectionManager(jmri.SectionManager) Element(org.jdom2.Element) EntryPoint(jmri.EntryPoint) Section(jmri.Section) EntryPoint(jmri.EntryPoint)

Example 4 with EntryPoint

use of jmri.EntryPoint in project JMRI by JMRI.

the class SectionManagerXml method store.

/**
     * Implementation for storing the contents of a SectionManager
     *
     * @param o Object to store, of type SectionManager
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Element sections = new Element("sections");
    setStoreElementClass(sections);
    SectionManager tm = (SectionManager) o;
    if (tm != null) {
        java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
        // don't return an element if there are not Sections to include
        if (!iter.hasNext()) {
            return null;
        }
        // store the Section
        while (iter.hasNext()) {
            String sname = iter.next();
            if (sname == null) {
                log.error("System name null during store");
            } else {
                log.debug("Section system name is " + sname);
                Section x = tm.getBySystemName(sname);
                if (x.getSectionType() != Section.DYNAMICADHOC) {
                    Element elem = new Element("section");
                    elem.addContent(new Element("systemName").addContent(sname));
                    // store common part
                    storeCommon(x, elem);
                    String txt = "userdefined";
                    if (x.getSectionType() == Section.SIGNALMASTLOGIC) {
                        txt = "signalmastlogic";
                    }
                    elem.setAttribute("creationtype", txt);
                    txt = x.getForwardStoppingSensorName();
                    if ((txt != null) && (!txt.equals(""))) {
                        elem.setAttribute("fstopsensorname", txt);
                    }
                    txt = x.getReverseStoppingSensorName();
                    if ((txt != null) && (!txt.equals(""))) {
                        elem.setAttribute("rstopsensorname", txt);
                    }
                    txt = x.getForwardBlockingSensorName();
                    if ((txt != null) && (!txt.equals(""))) {
                        elem.setAttribute("fsensorname", txt);
                    }
                    txt = x.getReverseBlockingSensorName();
                    if ((txt != null) && (!txt.equals(""))) {
                        elem.setAttribute("rsensorname", txt);
                    }
                    if (x.getSectionType() == Section.USERDEFINED) {
                        // save child block entries
                        int index = 0;
                        Block b = x.getBlockBySequenceNumber(index);
                        Element bElem = null;
                        while (b != null) {
                            bElem = new Element("blockentry");
                            bElem.setAttribute("sName", b.getSystemName());
                            bElem.setAttribute("order", Integer.toString(index));
                            elem.addContent(bElem);
                            index++;
                            b = x.getBlockBySequenceNumber(index);
                        }
                        // save child entry points
                        List<EntryPoint> epList = x.getEntryPointList();
                        Element epElem = null;
                        EntryPoint ep = null;
                        for (int i = 0; i < epList.size(); i++) {
                            ep = epList.get(i);
                            if (ep != null) {
                                epElem = new Element("entrypoint");
                                // add some protection against a reading problem
                                if (ep.getFromBlock() == null) {
                                    log.error("Unexpected null getFromBlock while storing ep " + i + " in Section " + sname + ", skipped");
                                    break;
                                }
                                epElem.setAttribute("fromblock", ep.getFromBlock().getSystemName());
                                if (ep.getBlock() == null) {
                                    log.error("Unexpected null getBlock while storing ep " + i + " in Section " + sname + ", skipped");
                                    break;
                                }
                                epElem.setAttribute("toblock", ep.getBlock().getSystemName());
                                epElem.setAttribute("direction", Integer.toString(ep.getDirection()));
                                epElem.setAttribute("fixed", "" + (ep.isFixed() ? "yes" : "no"));
                                epElem.setAttribute("fromblockdirection", "" + ep.getFromBlockDirection());
                                elem.addContent(epElem);
                            }
                        }
                    }
                    sections.addContent(elem);
                }
            }
        }
    }
    return (sections);
}
Also used : SectionManager(jmri.SectionManager) Element(org.jdom2.Element) Block(jmri.Block) EntryPoint(jmri.EntryPoint) Section(jmri.Section) EntryPoint(jmri.EntryPoint)

Example 5 with EntryPoint

use of jmri.EntryPoint in project JMRI by JMRI.

the class TransitTableAction method connected.

@SuppressWarnings("unused")
private boolean connected(Section s1, Section s2) {
    if ((s1 != null) && (s2 != null)) {
        List<EntryPoint> s1Entries = s1.getEntryPointList();
        List<EntryPoint> s2Entries = s2.getEntryPointList();
        for (int i = 0; i < s1Entries.size(); i++) {
            Block b = s1Entries.get(i).getFromBlock();
            for (int j = 0; j < s2Entries.size(); j++) {
                if (b == s2Entries.get(j).getBlock()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : EntryPoint(jmri.EntryPoint) Block(jmri.Block) EntryPoint(jmri.EntryPoint)

Aggregations

EntryPoint (jmri.EntryPoint)13 Block (jmri.Block)10 ArrayList (java.util.ArrayList)5 Section (jmri.Section)4 Path (jmri.Path)2 SectionManager (jmri.SectionManager)2 Element (org.jdom2.Element)2 ConfigureManager (jmri.ConfigureManager)1 Memory (jmri.Memory)1 Sensor (jmri.Sensor)1 Transit (jmri.Transit)1 Turnout (jmri.Turnout)1 ConnectivityUtil (jmri.jmrit.display.layoutEditor.ConnectivityUtil)1 LayoutSlip (jmri.jmrit.display.layoutEditor.LayoutSlip)1 LayoutTurnout (jmri.jmrit.display.layoutEditor.LayoutTurnout)1