Search in sources :

Example 66 with Block

use of jmri.Block in project JMRI by JMRI.

the class DispatcherFrame method createActiveTrain.

/**
     * Creates a new ActiveTrain, and registers it with Dispatcher.
     *
     * @param transitID                       system or user name of a Transit
     *                                        in the Transit Table
     * @param trainID                         any text that identifies the train
     * @param tSource                         either ROSTER, OPERATIONS, or USER
     *                                        (see ActiveTrain.java)
     * @param startBlockName                  system or user name of Block where
     *                                        train currently resides
     * @param startBlockSectionSequenceNumber sequence number in the Transit of
     *                                        the Section containing the
     *                                        startBlock (if the startBlock is
     *                                        within the Transit), or of the
     *                                        Section the train will enter from
     *                                        the startBlock (if the startBlock
     *                                        is outside the Transit)
     * @param endBlockName                    system or user name of Block where
     *                                        train will end up after its
     *                                        transit
     * @param endBlockSectionSequenceNumber   sequence number in the Transit of
     *                                        the Section containing the
     *                                        endBlock.
     * @param autoRun                         set to "true" if computer is to
     *                                        run the train automatically,
     *                                        otherwise "false"
     * @param dccAddress                      required if "autoRun" is "true",
     *                                        set to null otherwise
     * @param priority                        any integer, higher number is
     *                                        higher priority. Used to arbitrate
     *                                        allocation request conflicts
     * @param resetWhenDone                   set to "true" if the Active Train
     *                                        is capable of continuous running
     *                                        and the user has requested that it
     *                                        be automatically reset for another
     *                                        run thru its Transit each time it
     *                                        completes running through its
     *                                        Transit.
     * @param reverseAtEnd                    true if train should automatically
     *                                        reverse at end of transit; false
     *                                        otherwise
     * @param allocateAllTheWay               set to "true" to allow Auto
     *                                        Allocate to allocate as many
     *                                        sections as possible between the
     *                                        start section and the end section.
     *                                        Set to false Auto Allocate
     *                                        allocates no more than three
     *                                        sections ahead.
     * @param showErrorMessages               "true" if error message dialogs
     *                                        are to be displayed for detected
     *                                        errors Set to "false" to suppress
     *                                        error message dialogs from this
     *                                        method.
     * @param frame                           window request is from, or "null"
     *                                        if not from a window
     * <P>
     * @return a new ActiveTrain or null on failure
     */
public ActiveTrain createActiveTrain(String transitID, String trainID, int tSource, String startBlockName, int startBlockSectionSequenceNumber, String endBlockName, int endBlockSectionSequenceNumber, boolean autoRun, String dccAddress, int priority, boolean resetWhenDone, boolean reverseAtEnd, boolean allocateAllTheWay, boolean showErrorMessages, JmriJFrame frame) {
    //        log.debug("trainID:{}, tSource:{}, startBlockName:{}, startBlockSectionSequenceNumber:{}, endBlockName:{}, endBlockSectionSequenceNumber:{}",
    //                trainID,tSource,startBlockName,startBlockSectionSequenceNumber,endBlockName,endBlockSectionSequenceNumber);
    // validate input
    Transit t = transitManager.getTransit(transitID);
    if (t == null) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(Bundle.getMessage("Error1"), new Object[] { transitID }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        log.error("Bad Transit name '" + transitID + "' when attempting to create an Active Train");
        return null;
    }
    if (t.getState() != Transit.IDLE) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(Bundle.getMessage("Error2"), new Object[] { transitID }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        log.error("Transit '" + transitID + "' not IDLE, cannot create an Active Train");
        return null;
    }
    if ((trainID == null) || trainID.equals("")) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, Bundle.getMessage("Error3"), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        log.error("TrainID string not provided, cannot create an Active Train");
        return null;
    }
    if ((tSource != ActiveTrain.ROSTER) && (tSource != ActiveTrain.OPERATIONS) && (tSource != ActiveTrain.USER)) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, Bundle.getMessage("Error21"), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        log.error("Train source is invalid - " + tSource + " - cannot create an Active Train");
        return null;
    }
    Block startBlock = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(startBlockName);
    if (startBlock == null) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(Bundle.getMessage("Error4"), new Object[] { startBlockName }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        log.error("Bad startBlockName '" + startBlockName + "' when attempting to create an Active Train");
        return null;
    }
    if (isInAllocatedSection(startBlock)) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(Bundle.getMessage("Error5"), new Object[] { startBlock.getDisplayName() }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        log.error("Start block '" + startBlockName + "' in allocated Section, cannot create an Active Train");
        return null;
    }
    if (_HasOccupancyDetection && (!(startBlock.getState() == Block.OCCUPIED))) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(Bundle.getMessage("Error6"), new Object[] { startBlock.getDisplayName() }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        log.error("No train in start block '" + startBlockName + "', cannot create an Active Train");
        return null;
    }
    if (startBlockSectionSequenceNumber <= 0) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, Bundle.getMessage("Error12"), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
    } else if (startBlockSectionSequenceNumber > t.getMaxSequence()) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(Bundle.getMessage("Error13"), new Object[] { "" + startBlockSectionSequenceNumber }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        log.error("Invalid sequence number '" + startBlockSectionSequenceNumber + "' when attempting to create an Active Train");
        return null;
    }
    Block endBlock = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(endBlockName);
    if ((endBlock == null) || (!t.containsBlock(endBlock))) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(Bundle.getMessage("Error7"), new Object[] { endBlockName }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        log.error("Bad endBlockName '" + endBlockName + "' when attempting to create an Active Train");
        return null;
    }
    if ((endBlockSectionSequenceNumber <= 0) && (t.getBlockCount(endBlock) > 1)) {
        JOptionPane.showMessageDialog(frame, Bundle.getMessage("Error8"), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
    } else if (endBlockSectionSequenceNumber > t.getMaxSequence()) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(Bundle.getMessage("Error9"), new Object[] { "" + endBlockSectionSequenceNumber }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        log.error("Invalid sequence number '" + endBlockSectionSequenceNumber + "' when attempting to create an Active Train");
        return null;
    }
    if ((!reverseAtEnd) && resetWhenDone && (!t.canBeResetWhenDone())) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(Bundle.getMessage("Error26"), new Object[] { (t.getSystemName() + "(" + t.getUserName() + ")") }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        log.error("Incompatible Transit set up and request to Reset When Done when attempting to create an Active Train");
        return null;
    }
    if (autoRun && ((dccAddress == null) || dccAddress.equals(""))) {
        if (showErrorMessages) {
            JOptionPane.showMessageDialog(frame, Bundle.getMessage("Error10"), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        log.error("AutoRun requested without a dccAddress when attempting to create an Active Train");
        return null;
    }
    if (autoRun) {
        if (_autoTrainsFrame == null) {
            //   for automatic running.  First check for layout editor panel
            if (!_UseConnectivity || (_LE == null)) {
                if (showErrorMessages) {
                    JOptionPane.showMessageDialog(frame, Bundle.getMessage("Error33"), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
                    log.error("AutoRun requested without a LayoutEditor panel for connectivity.");
                    return null;
                }
            }
            if (!_HasOccupancyDetection) {
                if (showErrorMessages) {
                    JOptionPane.showMessageDialog(frame, Bundle.getMessage("Error35"), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
                    log.error("AutoRun requested without occupancy detection.");
                    return null;
                }
            }
        }
        // check/set Transit specific items for automatic running    
        // validate connectivity for all Sections in this transit            
        int numErrors = t.validateConnectivity(_LE);
        if (numErrors != 0) {
            if (showErrorMessages) {
                JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(Bundle.getMessage("Error34"), new Object[] { ("" + numErrors) }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
            }
            return null;
        }
        // check/set direction sensors in signal logic for all Sections in this Transit.
        if (getSignalType() == SIGNALHEAD) {
            numErrors = t.checkSignals(_LE);
            if (numErrors == 0) {
                t.initializeBlockingSensors();
            }
            if (numErrors != 0) {
                if (showErrorMessages) {
                    JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(Bundle.getMessage("Error36"), new Object[] { ("" + numErrors) }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
                }
                return null;
            }
        }
        // this train is OK, activate the AutoTrains window, if needed
        if (_autoTrainsFrame == null) {
            _autoTrainsFrame = new AutoTrainsFrame(_instance);
        } else {
            _autoTrainsFrame.setVisible(true);
        }
    } else if (_UseConnectivity && (_LE != null)) {
        // not auto run, set up direction sensors in signals since use connectivity was requested
        if (getSignalType() == SIGNALHEAD) {
            int numErrors = t.checkSignals(_LE);
            if (numErrors == 0) {
                t.initializeBlockingSensors();
            }
            if (numErrors != 0) {
                if (showErrorMessages) {
                    JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(Bundle.getMessage("Error36"), new Object[] { ("" + numErrors) }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
                }
                return null;
            }
        }
    }
    // all information checks out - create 
    ActiveTrain at = new ActiveTrain(t, trainID, tSource);
    //if (at==null) {
    // if (showErrorMessages) {
    //  JOptionPane.showMessageDialog(frame,java.text.MessageFormat.format(Bundle.getMessage(
    //    "Error11"),new Object[] { transitID, trainID }), Bundle.getMessage("ErrorTitle"),
    //     JOptionPane.ERROR_MESSAGE);
    // }
    // log.error("Creating Active Train failed, Transit - "+transitID+", train - "+trainID);
    // return null;
    //}
    activeTrainsList.add(at);
    java.beans.PropertyChangeListener listener = null;
    at.addPropertyChangeListener(listener = new java.beans.PropertyChangeListener() {

        @Override
        public void propertyChange(java.beans.PropertyChangeEvent e) {
            handleActiveTrainChange(e);
        }
    });
    _atListeners.add(listener);
    t.setState(Transit.ASSIGNED);
    at.setStartBlock(startBlock);
    at.setStartBlockSectionSequenceNumber(startBlockSectionSequenceNumber);
    at.setEndBlock(endBlock);
    at.setEndBlockSection(t.getSectionFromBlockAndSeq(endBlock, endBlockSectionSequenceNumber));
    at.setEndBlockSectionSequenceNumber(endBlockSectionSequenceNumber);
    at.setResetWhenDone(resetWhenDone);
    if (resetWhenDone) {
        restartingTrainsList.add(at);
    }
    at.setReverseAtEnd(reverseAtEnd);
    at.setAllocateAllTheWay(allocateAllTheWay);
    at.setPriority(priority);
    at.setDccAddress(dccAddress);
    at.setAutoRun(autoRun);
    return at;
}
Also used : Block(jmri.Block) Transit(jmri.Transit) EntryPoint(jmri.EntryPoint)

Example 67 with Block

use of jmri.Block in project JMRI by JMRI.

the class BlockContentsIcon method setBlock.

/**
     * Attached a named Block to this display item
     *
     * @param pName Used as a system/user name to lookup the Block object
     */
public void setBlock(String pName) {
    if (InstanceManager.getNullableDefault(jmri.BlockManager.class) != null) {
        Block block = InstanceManager.getDefault(jmri.BlockManager.class).provideBlock(pName);
        setBlock(jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(pName, block));
    } else {
        log.error("No Block Manager for this protocol, icon won't see changes");
    }
    updateSize();
}
Also used : Block(jmri.Block)

Example 68 with Block

use of jmri.Block in project JMRI by JMRI.

the class BlockManagerXmlTest method testStore.

/**
     * This test checks that the store operation runs, but doesn't check the
     * output for correctness.
     */
public void testStore() throws jmri.JmriException {
    JUnitUtil.resetInstanceManager();
    JUnitUtil.initConfigureManager();
    JUnitUtil.initInternalTurnoutManager();
    JUnitUtil.initInternalLightManager();
    JUnitUtil.initInternalSensorManager();
    JUnitUtil.initMemoryManager();
    JUnitUtil.initLayoutBlockManager();
    Block b1 = InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock("SystemNameb1", "");
    Block b2 = InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock("SystemNameb2", "");
    Sensor s2 = new AbstractSensor("IS2") {

        @Override
        public void requestUpdateFromLayout() {
        }
    };
    b2.setSensor("IS2");
    s2.setState(Sensor.ACTIVE);
    b2.setValue("b2 contents");
    Path p21 = new Path();
    p21.setBlock(b1);
    p21.setFromBlockDirection(Path.RIGHT);
    p21.setToBlockDirection(Path.LEFT);
    p21.addSetting(new BeanSetting(new jmri.implementation.AbstractTurnout("IT1") {

        @Override
        public void turnoutPushbuttonLockout(boolean b) {
        }

        @Override
        public void forwardCommandChangeToLayout(int i) {
        }
    }, jmri.Turnout.THROWN));
    b2.addPath(p21);
//BlockManagerXml tb = new BlockManagerXml();
}
Also used : Path(jmri.Path) BeanSetting(jmri.BeanSetting) Block(jmri.Block) AbstractSensor(jmri.implementation.AbstractSensor) Sensor(jmri.Sensor) AbstractSensor(jmri.implementation.AbstractSensor)

Example 69 with Block

use of jmri.Block in project JMRI by JMRI.

the class BlockManagerXmlTest method testLoadCurrent.

public void testLoadCurrent() throws Exception {
    JUnitUtil.resetInstanceManager();
    JUnitUtil.initConfigureManager();
    JUnitUtil.initInternalTurnoutManager();
    JUnitUtil.initInternalLightManager();
    JUnitUtil.initInternalSensorManager();
    JUnitUtil.initMemoryManager();
    JUnitUtil.initLayoutBlockManager();
    // load file
    InstanceManager.getDefault(ConfigureManager.class).load(new java.io.File("java/test/jmri/configurexml/load/BlockManagerXmlTest.xml"));
    // check existance of blocks
    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("IB2"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("IB3"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("IB4"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("IB5"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("IB6"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("IB7"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("IB8"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("IB9"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("IB10"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("IB11"));
    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("blocknorth"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocknorthsiding"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocknortheast"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blockeast"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blockeastsiding"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocksoutheast"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocksouth"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocksouthsiding"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blocksouthwest"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blockwest"));
    Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("blockwestsiding"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB1"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB2"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB3"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB4"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB5"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB6"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB7"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB8"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB9"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB10"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB11"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("ILB12"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blocknorthwest"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blocknorth"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blocknorthsiding"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blocknortheast"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blockeast"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blockeastsiding"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blocksoutheast"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blocksouth"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blocksouthsiding"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blocksouthwest"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blockwest"));
    //         Assert.assertNotNull(InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlock("blockwestsiding"));
    // check existance of turmouts
    Assert.assertNotNull(InstanceManager.turnoutManagerInstance().getTurnout("IT1"));
    Assert.assertNull(InstanceManager.turnoutManagerInstance().getTurnout("no turnout"));
    Assert.assertNotNull(InstanceManager.turnoutManagerInstance().getTurnout("IT2"));
    Assert.assertNotNull(InstanceManager.turnoutManagerInstance().getTurnout("IT3"));
    Assert.assertNotNull(InstanceManager.turnoutManagerInstance().getTurnout("IT4"));
    Assert.assertNotNull(InstanceManager.turnoutManagerInstance().getTurnout("IT5"));
    Assert.assertNotNull(InstanceManager.turnoutManagerInstance().getTurnout("IT6"));
    Assert.assertNotNull(InstanceManager.turnoutManagerInstance().getTurnout("IT7"));
    Assert.assertNotNull(InstanceManager.turnoutManagerInstance().getTurnout("IT8"));
    // check existance of memories        
    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:0003"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("IM:AUTO:0004"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("IM:AUTO:0005"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("IM:AUTO:0006"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("IM:AUTO:0007"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("IM:AUTO:0008"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("IM:AUTO:0009"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("IM:AUTO:0010"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("IM:AUTO:0011"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("IM:AUTO:0012"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blocknorthwestmemory"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blocknorthmemory"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blocknorthsidingmemory"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blocknortheastmemory"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blockeastmemory"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blockeastsidingmemory"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blocksoutheastmemory"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blocksouthmemory"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blocksouthsidingmemory"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blocksouthwestmemory"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blockwestmemory"));
    Assert.assertNotNull(InstanceManager.memoryManagerInstance().getMemory("blockwestsidingmemory"));
    // check existance of sensors
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO1"));
    Assert.assertNull(InstanceManager.sensorManagerInstance().getSensor("no sensor"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO2"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO3"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO4"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO5"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO6"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO7"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO8"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO9"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO10"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO11"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("ISBO12"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blocknorthwestoccupied"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blocknorthoccupied"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blocknorthsidingoccupied"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blocknortheastoccupied"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blockeastoccupied"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blockeastsidingoccupied"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blocksoutheastoccupied"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blocksouthoccupied"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blocksouthsidingoccupied"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blocksouthwestoccupied"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blockwestoccupied"));
    Assert.assertNotNull(InstanceManager.sensorManagerInstance().getSensor("blockwestsidingoccupied"));
    // check existance of paths between blocks
    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, ...
    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, ...
    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]);
        }
    }
}
Also used : Path(jmri.Path) Memory(jmri.Memory) ConfigureManager(jmri.ConfigureManager) Block(jmri.Block) Sensor(jmri.Sensor) AbstractSensor(jmri.implementation.AbstractSensor)

Example 70 with Block

use of jmri.Block in project JMRI by JMRI.

the class BlockTableActionTest method testInvoke.

@Test
public void testInvoke() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    a.actionPerformed(null);
    JFrame f = JFrameOperator.waitJFrame(Bundle.getMessage("TitleBlockTable"), true, true);
    Assert.assertNotNull(f);
    // create a couple of blocks, and see if they show
    InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock("IB1", "block 1");
    Block b2 = InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock("IB2", "block 2");
    Assert.assertNotNull(b2);
    b2.setDirection(jmri.Path.EAST);
    // set graphic state column display preference to false, read by createModel()
    InstanceManager.getDefault(GuiLafPreferencesManager.class).setGraphicTableState(false);
    BlockTableAction _bTable;
    _bTable = new BlockTableAction();
    Assert.assertNotNull("found BlockTable frame", _bTable);
    // assert blocks show in table
    //Assert.assertEquals("Block1 getValue","(no name)",_bTable.getValue(null)); // taken out for now, returns null on CI?
    //Assert.assertEquals("Block1 getValue","(no Block)",_bTable.getValue("nonsenseBlock"));
    //Assert.assertEquals("Block1 getValue","IB1",_bTable.getValue("block 1"));
    // set to true, use icons
    InstanceManager.getDefault(GuiLafPreferencesManager.class).setGraphicTableState(true);
    BlockTableAction _b1Table;
    _b1Table = new BlockTableAction();
    Assert.assertNotNull("found BlockTable1 frame", _b1Table);
    _b1Table.addPressed(null);
    JFrame af = JFrameOperator.waitJFrame(Bundle.getMessage("TitleAddBlock"), true, true);
    Assert.assertNotNull("found Add frame", af);
    // Cancel & close AddPane
    _b1Table.cancelPressed(null);
    // clean up
    af.dispose();
    b2 = null;
    _bTable.dispose();
    _b1Table.dispose();
    f.dispose();
}
Also used : GuiLafPreferencesManager(apps.gui.GuiLafPreferencesManager) JFrame(javax.swing.JFrame) Block(jmri.Block) Test(org.junit.Test)

Aggregations

Block (jmri.Block)84 ArrayList (java.util.ArrayList)19 EntryPoint (jmri.EntryPoint)16 Sensor (jmri.Sensor)10 Element (org.jdom2.Element)9 BlockManager (jmri.BlockManager)8 SignalMast (jmri.SignalMast)8 Turnout (jmri.Turnout)8 Test (org.junit.Test)7 Path (jmri.Path)6 Reporter (jmri.Reporter)6 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 Section (jmri.Section)5 Hashtable (java.util.Hashtable)4 NamedBean (jmri.NamedBean)4 SignalHead (jmri.SignalHead)4 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyChangeListener (java.beans.PropertyChangeListener)3