Search in sources :

Example 21 with Block

use of jmri.Block in project JMRI by JMRI.

the class AutoAllocate method willLevelXingsBlockTrain.

private boolean willLevelXingsBlockTrain(ActiveTrain at) {
    // returns true if any LevelXings in _levelXingList will block the specified train
    if (at == null) {
        log.error("null argument on entry to 'willLevelXingsBlockTrain'");
        // returns true to be safe
        return true;
    }
    if (_levelXingList.size() <= 0) {
        return false;
    }
    for (int i = 0; i < _levelXingList.size(); i++) {
        LevelXing lx = _levelXingList.get(i);
        Block bAC = lx.getLayoutBlockAC().getBlock();
        Block bBD = lx.getLayoutBlockBD().getBlock();
        if (at.getTransit().containsBlock(bAC) || at.getTransit().containsBlock(bBD)) {
            return true;
        }
    }
    return false;
}
Also used : LevelXing(jmri.jmrit.display.layoutEditor.LevelXing) Block(jmri.Block)

Example 22 with Block

use of jmri.Block in project JMRI by JMRI.

the class BlockContentsIconXml method load.

/**
     * Load, starting with the BlockContentsIcon element, then all the
     * value-icon pairs
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    Editor ed = null;
    BlockContentsIcon l;
    if (o instanceof LayoutEditor) {
        ed = (LayoutEditor) o;
        l = new jmri.jmrit.display.layoutEditor.BlockContentsIcon("   ", (LayoutEditor) ed);
    } else if (o instanceof jmri.jmrit.display.Editor) {
        ed = (Editor) o;
        l = new BlockContentsIcon("", ed);
    } else {
        log.error("Unrecognizable class - " + o.getClass().getName());
        return;
    }
    String name;
    Attribute attr = element.getAttribute("blockcontents");
    if (attr == null) {
        log.error("incorrect information for a block contents; must use block name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    loadTextInfo(l, element);
    Block m = jmri.InstanceManager.getDefault(jmri.BlockManager.class).getBlock(name);
    if (m != null) {
        l.setBlock(name);
    } else {
        log.error("Block named '" + attr.getValue() + "' not found.");
        ed.loadFailed();
    }
    Attribute a = element.getAttribute("selectable");
    if (a != null && a.getValue().equals("yes")) {
        l.setSelectable(true);
    } else {
        l.setSelectable(false);
    }
    // get the icon pairs
    List<Element> items = element.getChildren("blockstate");
    for (int i = 0; i < items.size(); i++) {
        // get the class, hence the adapter object to do loading
        Element item = items.get(i);
        String iconName = item.getAttribute("icon").getValue();
        NamedIcon icon = NamedIcon.getIconByName(iconName);
        if (icon == null) {
            icon = ed.loadFailed("Memory " + name, iconName);
            if (icon == null) {
                log.info("Memory \"" + name + "\" icon removed for url= " + iconName);
            }
        }
        if (icon != null) {
            String keyValue = item.getAttribute("value").getValue();
            l.addKeyAndIcon(icon, keyValue);
        }
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
    int x = 0;
    int y = 0;
    try {
        x = element.getAttribute("x").getIntValue();
        y = element.getAttribute("y").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert positional attribute");
    }
    l.setOriginalLocation(x, y);
    l.displayState();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Attribute(org.jdom2.Attribute) BlockContentsIcon(jmri.jmrit.display.BlockContentsIcon) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) Block(jmri.Block) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Editor(jmri.jmrit.display.Editor)

Example 23 with Block

use of jmri.Block in project JMRI by JMRI.

the class LayoutBlock method addRouteFromNeighbour.

void addRouteFromNeighbour(LayoutBlock src, RoutingPacket update) {
    if (enableAddRouteLogging) {
        //log.info("From " + this.getDisplayName() + " packet to be added from neighbour " + src.getDisplayName());
        log.info("From " + this.getDisplayName() + " src: " + src.getDisplayName() + ", block: " + update.getBlock().getDisplayName() + ", hopCount: " + update.getHopCount() + ", metric: " + update.getMetric() + ", status: " + update.getBlockState() + ", packetID: " + update.getPacketId());
    }
    InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).setLastRoutingChange();
    Block destBlock = update.getBlock();
    Block srcblk = src.getBlock();
    if (destBlock == this.getBlock()) {
        if (enableAddRouteLogging) {
            log.info("Reject packet update as it is to a route advertised by our selves");
        }
        return;
    }
    Adjacencies adj = getAdjacency(srcblk);
    if (adj == null) {
        if (enableAddRouteLogging) {
            log.info("From " + this.getDisplayName() + " packet is from a src that is not registered " + srcblk.getDisplayName());
        }
        //Then we will simply reject it.
        return;
    } else if (adj.getPacketFlow() == TXONLY) {
        if (enableAddRouteLogging) {
            log.info("From " + this.getDisplayName() + " packet is from a src " + src.getDisplayName() + " that is registered as one that we should be transmitting to only");
        }
        //we should only be transmitting routes to this neighbour not receiving them
        return;
    }
    int hopCount = update.getHopCount();
    int updatemetric = update.getMetric();
    float length = update.getLength();
    if (hopCount > 255) {
        if (enableAddRouteLogging) {
            log.info("From " + this.getDisplayName() + " hop count exceeded " + destBlock.getDisplayName());
        }
        return;
    }
    for (Routes ro : routes) {
        if ((ro.getNextBlock() == srcblk) && (ro.getDestBlock() == destBlock)) {
            if (enableAddRouteLogging) {
                log.info("From " + this.getDisplayName() + " Route to " + destBlock.getDisplayName() + " is already configured");
                log.info(ro.getHopCount() + " v " + hopCount);
                log.info(ro.getMetric() + " v " + updatemetric);
            }
            updateRoutingInfo(src, update);
            return;
        }
    }
    if (enableAddRouteLogging) {
        log.info("From " + this.getDisplayName() + " We should be adding route " + destBlock.getDisplayName());
    }
    //We need to propergate out the routes that we have added to our neighbour
    int direction = adj.getDirection();
    Routes route = new Routes(destBlock, srcblk, hopCount, direction, updatemetric, length);
    routes.add(route);
    //Need to propergate the route down to our neighbours
    addRouteToNeighbours(route);
}
Also used : Block(jmri.Block)

Example 24 with Block

use of jmri.Block in project JMRI by JMRI.

the class LayoutBlock method getNextBlock.

/**
     * Used if we already know the block prior to our block, and the destination
     * block. direction, is optional and is used where the previousBlock is
     * equal to our block.
     */
@CheckForNull
public Block getNextBlock(Block previousBlock, Block destBlock) {
    int bestMetric = 965000;
    Block bestBlock = null;
    for (Routes r : routes) {
        if (r.getDestBlock() == destBlock) {
            //Check that the route through from the previous block, to the next hop is valid
            if (validThroughPath(previousBlock, r.getNextBlock())) {
                if (r.getMetric() < bestMetric) {
                    bestMetric = r.getMetric();
                    //bestBlock=r.getDestBlock();
                    bestBlock = r.getNextBlock();
                }
            }
        }
    }
    return bestBlock;
}
Also used : Block(jmri.Block) CheckForNull(javax.annotation.CheckForNull)

Example 25 with Block

use of jmri.Block in project JMRI by JMRI.

the class LayoutBlock method addThroughPath.

void addThroughPath(Adjacencies adj) {
    Block newAdj = adj.getBlock();
    int packetFlow = adj.getPacketFlow();
    if (enableAddRouteLogging) {
        log.debug("From " + this.getDisplayName() + " addThroughPathCalled with adj " + adj.getBlock().getDisplayName());
    }
    for (int i = 0; i < neighbours.size(); i++) {
        //cycle through all the neighbours
        if (neighbours.get(i).getBlock() != newAdj) {
            int neighPacketFlow = neighbours.get(i).getPacketFlow();
            if (enableAddRouteLogging) {
                log.info("From " + this.getDisplayName() + " our direction: " + decodePacketFlow(packetFlow) + ", neighbour direction: " + decodePacketFlow(neighPacketFlow));
            }
            if ((packetFlow == RXTX) && (neighPacketFlow == RXTX)) {
                //if both are RXTX then add flow in both directions
                addThroughPath(neighbours.get(i).getBlock(), newAdj);
                addThroughPath(newAdj, neighbours.get(i).getBlock());
            } else if ((packetFlow == RXONLY) && (neighPacketFlow == TXONLY)) {
                addThroughPath(neighbours.get(i).getBlock(), newAdj);
            } else if ((packetFlow == TXONLY) && (neighPacketFlow == RXONLY)) {
                addThroughPath(newAdj, neighbours.get(i).getBlock());
            } else if ((packetFlow == RXTX) && (neighPacketFlow == TXONLY)) {
                //was RX
                addThroughPath(neighbours.get(i).getBlock(), newAdj);
            } else if ((packetFlow == RXTX) && (neighPacketFlow == RXONLY)) {
                //was TX
                addThroughPath(newAdj, neighbours.get(i).getBlock());
            } else if ((packetFlow == RXONLY) && (neighPacketFlow == RXTX)) {
                addThroughPath(neighbours.get(i).getBlock(), newAdj);
            } else if ((packetFlow == TXONLY) && (neighPacketFlow == RXTX)) {
                addThroughPath(newAdj, neighbours.get(i).getBlock());
            } else {
                if (enableAddRouteLogging) {
                    log.info("Invalid combination " + decodePacketFlow(packetFlow) + " and " + decodePacketFlow(neighPacketFlow));
                }
            }
        }
    }
}
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