Search in sources :

Example 21 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class CircuitBuilder method setIconGroup.

/**
     * Edit frame closing, set block's icons
     */
private void setIconGroup(OBlock block, java.util.List<Positionable> selections) {
    java.util.List<Positionable> oldIcons = _circuitMap.get(block);
    if (oldIcons != null) {
        for (int i = 0; i < oldIcons.size(); i++) {
            Positionable pos = oldIcons.get(i);
            if (pos instanceof IndicatorTrack) {
                ((IndicatorTrack) pos).setOccBlockHandle(null);
            }
            _iconMap.remove(pos);
        }
    }
    // the selectionGroup for all edit frames is full collection of icons
    // comprising the block.  Gather them and store in the block's hashMap
    ArrayList<Positionable> icons = new ArrayList<Positionable>();
    if (selections != null) {
        if (log.isDebugEnabled()) {
            log.debug("setIconGroup: selectionGroup has " + selections.size() + " icons.");
        }
        NamedBeanHandle<OBlock> handle = InstanceManager.getDefault(NamedBeanHandleManager.class).getNamedBeanHandle(block.getSystemName(), block);
        for (int i = 0; i < selections.size(); i++) {
            Positionable pos = selections.get(i);
            if (pos instanceof IndicatorTrack) {
                ((IndicatorTrack) pos).setOccBlockHandle(handle);
            }
            icons.add(pos);
            _iconMap.put(pos, block);
        }
        java.util.List<Portal> portals = block.getPortals();
        for (int i = 0; i < portals.size(); i++) {
            PortalIcon icon = _portalIconMap.get(portals.get(i).getName());
            if (icon != null) {
                _iconMap.put(icon, block);
            }
        }
    }
    _circuitMap.put(block, icons);
    if (log.isDebugEnabled()) {
        log.debug("setIconGroup: block " + block.getDisplayName() + " has " + icons.size() + " icons.");
    }
}
Also used : ArrayList(java.util.ArrayList) NamedBeanHandleManager(jmri.NamedBeanHandleManager) IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Portal(jmri.jmrit.logix.Portal) Positionable(jmri.jmrit.display.Positionable) OBlock(jmri.jmrit.logix.OBlock)

Example 22 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class EditPortalDirection method setPortalIcon.

protected void setPortalIcon(PortalIcon icon, boolean setValue) {
    _parent._editor.highlight(icon);
    if (_icon != null) {
        _icon.setStatus(PortalIcon.VISIBLE);
    }
    _icon = icon;
    if (_icon != null) {
        if (_icon.getArrowHide()) {
            _icon.setStatus(PortalIcon.HIDDEN);
        } else {
            OBlock toBlock = _icon.getPortal().getToBlock();
            if (_homeBlock.equals(toBlock)) {
                _icon.setStatus(PortalIcon.TO_ARROW);
            } else {
                _icon.setStatus(PortalIcon.FROM_ARROW);
            }
        }
        _toButton.setIcon(_icon.getIcon(PortalIcon.TO_ARROW));
        _fromButton.setIcon(_icon.getIcon(PortalIcon.FROM_ARROW));
        if (setValue) {
            _portalList.setSelectedValue(_icon.getPortal(), true);
        }
    }
}
Also used : OBlock(jmri.jmrit.logix.OBlock)

Example 23 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class ConditionalVariable method evaluate.

/**
     * Evaluates this State Variable.
     *
     * @return true if variable evaluates true, otherwise false.
     */
// Date.getMinutes, Date.getHours
@SuppressWarnings("deprecation")
public boolean evaluate() {
    boolean result = true;
    // evaluate according to state variable type
    int itemType = Conditional.TEST_TO_ITEM[_type];
    log.debug("evaluate: \"{}\" type= {} itemType= {}", getName(), _type, itemType);
    switch(itemType) {
        case Conditional.ITEM_TYPE_SENSOR:
            //Sensor sn = InstanceManager.sensorManagerInstance().provideSensor(getName());
            Sensor sn = (Sensor) getBean();
            if (sn == null) {
                log.error("invalid sensor name= \"" + getName() + "\" in state variable");
                return false;
            }
            if (_type == Conditional.TYPE_SENSOR_ACTIVE) {
                result = sn.getState() == Sensor.ACTIVE;
            } else {
                result = sn.getState() == Sensor.INACTIVE;
            }
            break;
        case Conditional.ITEM_TYPE_TURNOUT:
            Turnout t = (Turnout) getBean();
            if (t == null) {
                log.error("invalid turnout name= \"" + getName() + "\" in state variable");
                return false;
            }
            if (_type == Conditional.TYPE_TURNOUT_THROWN) {
                result = t.getKnownState() == Turnout.THROWN;
            } else {
                result = t.getKnownState() == Turnout.CLOSED;
            }
            break;
        case Conditional.ITEM_TYPE_LIGHT:
            Light lgt = (Light) getBean();
            if (lgt == null) {
                log.error("invalid light name= \"" + getName() + "\" in state variable");
                return false;
            }
            if (_type == Conditional.TYPE_LIGHT_ON) {
                result = lgt.getState() == Light.ON;
            } else {
                result = lgt.getState() == Light.OFF;
            }
            break;
        case Conditional.ITEM_TYPE_SIGNALMAST:
            SignalMast f = (SignalMast) getBean();
            if (f == null) {
                log.error("invalid signal mast name= \"" + getName() + "\" in state variable");
                return false;
            }
            switch(_type) {
                case Conditional.TYPE_SIGNAL_MAST_LIT:
                    result = f.getLit();
                    break;
                case Conditional.TYPE_SIGNAL_MAST_HELD:
                    result = f.getHeld();
                    break;
                case Conditional.TYPE_SIGNAL_MAST_ASPECT_EQUALS:
                    if (f.getAspect() == null) {
                        result = false;
                    } else {
                        result = f.getAspect().equals(_dataString);
                    }
                    break;
                default:
                    log.warn("unexpected type {} in ITEM_TYPE_SIGNALMAST", _type);
            }
            break;
        case Conditional.ITEM_TYPE_SIGNALHEAD:
            SignalHead h = (SignalHead) getBean();
            if (h == null) {
                log.error("invalid signal head name= \"" + getName() + "\" in state variable");
                return false;
            }
            switch(_type) {
                case Conditional.TYPE_SIGNAL_HEAD_RED:
                    result = h.getAppearance() == SignalHead.RED;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_YELLOW:
                    result = h.getAppearance() == SignalHead.YELLOW;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_GREEN:
                    result = h.getAppearance() == SignalHead.GREEN;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_DARK:
                    result = h.getAppearance() == SignalHead.DARK;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_FLASHRED:
                    result = h.getAppearance() == SignalHead.FLASHRED;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_FLASHYELLOW:
                    result = h.getAppearance() == SignalHead.FLASHYELLOW;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_FLASHGREEN:
                    result = h.getAppearance() == SignalHead.FLASHGREEN;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_LUNAR:
                    result = h.getAppearance() == SignalHead.LUNAR;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_FLASHLUNAR:
                    result = h.getAppearance() == SignalHead.FLASHLUNAR;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_LIT:
                    result = h.getLit();
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_HELD:
                    result = h.getHeld();
                    break;
                default:
                    result = false;
            }
            break;
        case Conditional.ITEM_TYPE_MEMORY:
            Memory m = (Memory) getBean();
            if (m == null) {
                log.error("invalid memory name= \"" + getName() + "\" in state variable");
                return false;
            }
            String value1 = null;
            String value2 = null;
            if (m.getValue() != null) {
                value1 = m.getValue().toString();
            }
            boolean caseInsensitive = ((_type == Conditional.TYPE_MEMORY_EQUALS_INSENSITIVE) || (_type == Conditional.TYPE_MEMORY_COMPARE_INSENSITIVE));
            if ((_type == Conditional.TYPE_MEMORY_COMPARE) || (_type == Conditional.TYPE_MEMORY_COMPARE_INSENSITIVE)) {
                Memory m2;
                if (_namedBeanData != null) {
                    m2 = (Memory) _namedBeanData.getBean();
                } else {
                    try {
                        m2 = InstanceManager.memoryManagerInstance().provideMemory(_dataString);
                    } catch (IllegalArgumentException ex) {
                        log.error("invalid data memory name= \"" + _dataString + "\" in state variable");
                        return false;
                    }
                }
                if (m2.getValue() != null) {
                    value2 = m2.getValue().toString();
                }
            } else {
                value2 = _dataString;
            }
            result = compare(value1, value2, caseInsensitive);
            break;
        case Conditional.ITEM_TYPE_CONDITIONAL:
            Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).getBySystemName(getName());
            if (c == null) {
                c = InstanceManager.getDefault(jmri.ConditionalManager.class).getByUserName(getName());
                if (c == null) {
                    log.error("invalid conditional name= \"" + getName() + "\" in state variable");
                    return false;
                }
            }
            if (_type == Conditional.TYPE_CONDITIONAL_TRUE) {
                result = c.getState() == Conditional.TRUE;
            } else {
                result = c.getState() == Conditional.FALSE;
            }
            break;
        case Conditional.ITEM_TYPE_WARRANT:
            Warrant w = InstanceManager.getDefault(WarrantManager.class).getWarrant(getName());
            if (w == null) {
                log.error("invalid Warrant name= \"" + getName() + "\" in state variable");
                return false;
            }
            switch(_type) {
                case Conditional.TYPE_ROUTE_FREE:
                    result = w.routeIsFree();
                    break;
                case Conditional.TYPE_ROUTE_OCCUPIED:
                    result = w.routeIsOccupied();
                    break;
                case Conditional.TYPE_ROUTE_ALLOCATED:
                    result = w.isAllocated();
                    break;
                case Conditional.TYPE_ROUTE_SET:
                    result = w.hasRouteSet();
                    break;
                case Conditional.TYPE_TRAIN_RUNNING:
                    // not in either RUN or LEARN state
                    result = !(w.getRunMode() == Warrant.MODE_NONE);
                    break;
                default:
                    result = false;
            }
            break;
        case Conditional.ITEM_TYPE_CLOCK:
            Timebase fastClock = InstanceManager.getDefault(jmri.Timebase.class);
            Date currentTime = fastClock.getTime();
            int currentMinutes = (currentTime.getHours() * 60) + currentTime.getMinutes();
            int beginTime = fixMidnight(_num1);
            int endTime = fixMidnight(_num2);
            // check if current time is within range specified
            if (beginTime <= endTime) {
                // range is entirely within one day
                result = (beginTime <= currentMinutes) && (currentMinutes <= endTime);
            } else {
                // range includes midnight
                result = beginTime <= currentMinutes || currentMinutes <= endTime;
            }
            break;
        case Conditional.ITEM_TYPE_OBLOCK:
            OBlock b = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class).getOBlock(getName());
            if (b == null) {
                log.error("invalid OBlock name= \"" + getName() + "\" in state variable");
                return false;
            }
            result = b.statusIs(_dataString);
            break;
        case Conditional.ITEM_TYPE_ENTRYEXIT:
            NamedBean e = getBean();
            if (_type == Conditional.TYPE_ENTRYEXIT_ACTIVE) {
                result = e.getState() == 0x02;
            } else {
                result = e.getState() == 0x04;
            }
            break;
        default:
            break;
    }
    // apply NOT if specified
    if (_not) {
        result = !result;
    }
    if (result) {
        setState(Conditional.TRUE);
    } else {
        setState(Conditional.FALSE);
    }
    return (result);
}
Also used : Warrant(jmri.jmrit.logix.Warrant) WarrantManager(jmri.jmrit.logix.WarrantManager) Date(java.util.Date) OBlock(jmri.jmrit.logix.OBlock)

Example 24 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class TableFrames method openPathTurnoutFrame.

protected void openPathTurnoutFrame(String pathTurnoutName) {
    JInternalFrame frame = _PathTurnoutMap.get(pathTurnoutName);
    log.debug("openPathTurnoutFrame for " + pathTurnoutName);
    if (frame == null) {
        int index = pathTurnoutName.indexOf('&');
        String pathName = pathTurnoutName.substring(1, index);
        String sysName = pathTurnoutName.substring(index + 1);
        OBlock block = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class).getBySystemName(sysName);
        if (block == null) {
            return;
        }
        frame = makePathTurnoutFrame(block, pathName);
        if (frame == null) {
            return;
        }
        _PathTurnoutMap.put(pathTurnoutName, frame);
        frame.setVisible(true);
        _desktop.add(frame);
        frame.moveToFront();
    } else {
        frame.setVisible(true);
        try {
            frame.setIcon(false);
        } catch (PropertyVetoException pve) {
            log.warn("PathTurnout Table Frame for \"" + pathTurnoutName + "\" vetoed setIcon " + pve.toString());
        }
        frame.moveToFront();
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) OBlockManager(jmri.jmrit.logix.OBlockManager) JInternalFrame(javax.swing.JInternalFrame) OBlock(jmri.jmrit.logix.OBlock) Point(java.awt.Point)

Example 25 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class IndicatorTrackIcon method setOccBlockHandle.

@Override
public void setOccBlockHandle(NamedBeanHandle<OBlock> blockHandle) {
    if (namedOccBlock != null) {
        getOccBlock().removePropertyChangeListener(this);
    }
    namedOccBlock = blockHandle;
    if (namedOccBlock != null) {
        if (_iconMap == null) {
            _iconMap = new HashMap<String, NamedIcon>();
        }
        OBlock block = getOccBlock();
        block.addPropertyChangeListener(this, namedOccBlock.getName(), "Indicator Track");
        setStatus(block, block.getState());
        displayState(_status);
        setTooltip(new ToolTip(block.getDescription(), 0, 0));
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) OBlock(jmri.jmrit.logix.OBlock)

Aggregations

OBlock (jmri.jmrit.logix.OBlock)40 Portal (jmri.jmrit.logix.Portal)13 OBlockManager (jmri.jmrit.logix.OBlockManager)10 Element (org.jdom2.Element)10 ArrayList (java.util.ArrayList)6 Positionable (jmri.jmrit.display.Positionable)6 NamedBean (jmri.NamedBean)5 Sensor (jmri.Sensor)5 Point (java.awt.Point)4 OPath (jmri.jmrit.logix.OPath)4 PropertyVetoException (java.beans.PropertyVetoException)3 Entry (java.util.Map.Entry)3 JMenu (javax.swing.JMenu)3 Reporter (jmri.Reporter)3 Attribute (org.jdom2.Attribute)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 JInternalFrame (javax.swing.JInternalFrame)2