Search in sources :

Example 16 with Block

use of jmri.Block in project JMRI by JMRI.

the class AutoActiveTrain method setupNewCurrentSignal.

protected synchronized void setupNewCurrentSignal(AllocatedSection as) {
    removeCurrentSignal();
    if (DispatcherFrame.instance().getSignalType() == DispatcherFrame.SIGNALHEAD) {
        SignalHead sh = _lbManager.getFacingSignalHead(_currentBlock, _nextBlock);
        if (sh != null) {
            _controllingSignal = sh;
            _conSignalProtectedBlock = _nextBlock;
            sh.addPropertyChangeListener(_conSignalListener = new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent e) {
                    if (e.getPropertyName().equals("Appearance")) {
                        // controlling signal has changed appearance
                        setSpeedBySignal();
                        if (_stoppingForStopSignal && (_targetSpeed > 0.0)) {
                            cancelStopInCurrentSection();
                            _stoppingForStopSignal = false;
                        }
                    }
                }
            });
            if (log.isDebugEnabled()) {
                log.debug("new current signal = " + sh.getSystemName());
            }
            setSpeedBySignal();
        } else // Note: null signal head will result when exiting throat-to-throat blocks.
        if (log.isDebugEnabled()) {
            log.debug("new current signal is null - sometimes OK");
        }
    } else {
        //SignalMast
        SignalMast sm = null;
        Block cB = _currentBlock;
        Block nB = _nextBlock;
        if (as == null) {
            as = _currentAllocatedSection;
        }
        //}
        while (sm == null && nB != null) {
            sm = _lbManager.getFacingSignalMast(cB, nB);
            if (sm == null) {
                cB = nB;
                nB = getNextBlock(nB, as);
            }
        }
        if (sm != null) {
            _controllingSignalMast = sm;
            _conSignalProtectedBlock = nB;
            sm.addPropertyChangeListener(_conSignalMastListener = new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent e) {
                    if (e.getPropertyName().equals("Aspect")) {
                        // controlling signal has changed appearance
                        if (_stoppingForStopSignal && (_targetSpeed > 0.0)) {
                            cancelStopInCurrentSection();
                            _stoppingForStopSignal = false;
                        }
                        setSpeedBySignal();
                    } else if (e.getPropertyName().equals("Held")) {
                        if (!((Boolean) e.getNewValue())) {
                            cancelStopInCurrentSection();
                            _stoppingForStopSignal = false;
                        }
                        setSpeedBySignal();
                    }
                }
            });
            log.debug("{}: new current signalmast {}({}) for section {}", _activeTrain.getTrainName(), sm.getDisplayName(), sm.getAspect(), as.getSectionName());
            setSpeedBySignal();
        } else // Note: null signal head will result when exiting throat-to-throat blocks.
        {
            log.debug("{}: new current signalmast is null for section {} - sometimes OK", _activeTrain.getTrainName(), as.getSectionName());
        }
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) SignalHead(jmri.SignalHead) SignalMast(jmri.SignalMast) Block(jmri.Block)

Example 17 with Block

use of jmri.Block in project JMRI by JMRI.

the class ActiveTrain method getBlockList.

/**
     * Returns list of all Blocks occupied by or allocated to this train. They
     * are in order from the tail of the train to the head of the train then on
     * to the forward-most allocated block. Note that unoccupied blocks can
     * exist before and after the occupied blocks.
     *
     * TODO: doesn't handle reversing of adjacent multi-block sections well
     *
     * @return the list of blocks order of occupation
     */
public ArrayList<Block> getBlockList() {
    ArrayList<Block> list = new ArrayList<>();
    for (int i = 0; i < mAllocatedSections.size(); i++) {
        // loop thru allocated sections, then all blocks for each section
        Section s = mAllocatedSections.get(i).getSection();
        ArrayList<Block> bl = s.getBlockList();
        if (bl.size() > 1) {
            //sections with multiple blocks need extra logic
            boolean blocksConnected = true;
            //determine if blocks should be added in forward or reverse order based on connectivity
            if (i == 0) {
                //for first section, compare last block to first of next section
                if (mAllocatedSections.size() > 1 && //only one section, assume forward
                !connected(bl.get(bl.size() - 1), mAllocatedSections.get(i + 1).getSection().getBlockList().get(0))) {
                    blocksConnected = false;
                }
            } else {
                //not first section, check for connectivity between last block in list, and first block in this section
                if (!connected(list.get(list.size() - 1), bl.get(0))) {
                    //last block is not connected to first block, add reverse
                    blocksConnected = false;
                }
            }
            if (blocksConnected) {
                //blocks were connected, so add to outgoing in forward order
                for (int j = 0; j < bl.size(); j++) {
                    Block b = bl.get(j);
                    list.add(b);
                    log.trace("block {} ({}) added to list for Section {} (fwd)", b.getDisplayName(), (b.getState() == Block.OCCUPIED ? "OCCUPIED" : "UNOCCUPIED"), s.getDisplayName());
                }
            } else {
                //not connected, add in reverse order
                for (int j = bl.size() - 1; j >= 0; j--) {
                    Block b = bl.get(j);
                    list.add(b);
                    log.trace("block {} ({}) added to list for Section {} (rev)", b.getDisplayName(), (b.getState() == Block.OCCUPIED ? "OCCUPIED" : "UNOCCUPIED"), s.getDisplayName());
                }
            }
        } else {
            //single block sections are simply added to the outgoing list 
            Block b = bl.get(0);
            list.add(b);
            log.trace("block {} ({}) added to list for Section {} (one)", b.getDisplayName(), (b.getState() == Block.OCCUPIED ? "OCCUPIED" : "UNOCCUPIED"), s.getDisplayName());
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) Block(jmri.Block) Section(jmri.Section)

Example 18 with Block

use of jmri.Block in project JMRI by JMRI.

the class ActivateTrainFrame method initializeStartingBlockCombo.

private void initializeStartingBlockCombo() {
    startingBlockBox.removeAllItems();
    startingBlockBoxList.clear();
    if (!inTransitBox.isSelected() && selectedTransit.getEntryBlocksList().isEmpty()) {
        inTransitBox.setSelected(true);
    }
    if (inTransitBox.isSelected()) {
        startingBlockBoxList = selectedTransit.getInternalBlocksList();
    } else {
        startingBlockBoxList = selectedTransit.getEntryBlocksList();
    }
    startingBlockSeqList = selectedTransit.getBlockSeqList();
    boolean found = false;
    for (int i = 0; i < startingBlockBoxList.size(); i++) {
        Block b = startingBlockBoxList.get(i);
        int seq = startingBlockSeqList.get(i).intValue();
        startingBlockBox.addItem(getBlockName(b) + "-" + seq);
        if (!found && b.getState() == Block.OCCUPIED) {
            startingBlockBox.setSelectedItem(getBlockName(b) + "-" + seq);
            found = true;
        }
    }
}
Also used : Block(jmri.Block)

Example 19 with Block

use of jmri.Block in project JMRI by JMRI.

the class ActivateTrainFrame method initiateTrain.

/**
     * Open up a new train window for a given roster entry located in a
     * specific block.
     * 
     * @param e the action event triggering the new window
     * @param re the roster entry to open the new window for
     * @param b the block where the train is located
     */
public void initiateTrain(ActionEvent e, RosterEntry re, Block b) {
    initiateTrain(e);
    if (_TrainsFromRoster && re != null) {
        setComboBox(trainSelectBox, re.getId());
    //Add in some bits of code as some point to filter down the transits that can be used.
    }
    if (b != null && selectedTransit != null) {
        ArrayList<Transit> transitList = _TransitManager.getListUsingBlock(b);
        ArrayList<Transit> transitEntryList = _TransitManager.getListEntryBlock(b);
        for (Transit t : transitEntryList) {
            if (!transitList.contains(t)) {
                transitList.add(t);
            }
        }
        transitsFromSpecificBlock = true;
        initializeFreeTransitsCombo(transitList);
        ArrayList<Block> tmpBlkList = new ArrayList<Block>();
        if (selectedTransit.getEntryBlocksList().contains(b)) {
            tmpBlkList = selectedTransit.getEntryBlocksList();
            inTransitBox.setSelected(false);
        } else if (selectedTransit.containsBlock(b)) {
            tmpBlkList = selectedTransit.getInternalBlocksList();
            inTransitBox.setSelected(true);
        }
        ArrayList<Integer> tmpSeqList = selectedTransit.getBlockSeqList();
        for (int i = 0; i < tmpBlkList.size(); i++) {
            if (tmpBlkList.get(i) == b) {
                setComboBox(startingBlockBox, getBlockName(b) + "-" + tmpSeqList.get(i));
                break;
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Block(jmri.Block) Transit(jmri.Transit)

Example 20 with Block

use of jmri.Block in project JMRI by JMRI.

the class ActivateTrainFrame method initializeDestinationBlockCombo.

private void initializeDestinationBlockCombo() {
    destinationBlockBox.removeAllItems();
    destinationBlockBoxList.clear();
    int index = startingBlockBox.getSelectedIndex();
    if (index < 0) {
        return;
    }
    Block startBlock = startingBlockBoxList.get(index);
    destinationBlockBoxList = selectedTransit.getDestinationBlocksList(startBlock, inTransitBox.isSelected());
    destinationBlockSeqList = selectedTransit.getDestBlocksSeqList();
    for (int i = 0; i < destinationBlockBoxList.size(); i++) {
        Block b = destinationBlockBoxList.get(i);
        String bName = getBlockName(b);
        if (selectedTransit.getBlockCount(b) > 1) {
            int seq = destinationBlockSeqList.get(i).intValue();
            bName = bName + "-" + seq;
        }
        destinationBlockBox.addItem(bName);
    }
}
Also used : Block(jmri.Block)

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