Search in sources :

Example 1 with BeanSetting

use of jmri.BeanSetting in project JMRI by JMRI.

the class PathTurnoutTableModel method setValueAt.

@Override
public void setValueAt(Object value, int row, int col) {
    if (_path.getSettings().size() == row) {
        switch(col) {
            case TURNOUT_NAME_COL:
                tempRow[TURNOUT_NAME_COL] = (String) value;
                if (tempRow[SETTINGCOLUMN] == null) {
                    return;
                }
                break;
            case SETTINGCOLUMN:
                tempRow[SETTINGCOLUMN] = (String) value;
                if (tempRow[TURNOUT_NAME_COL] == null) {
                    return;
                }
                break;
            case DELETE_COL:
                initTempRow();
                fireTableRowsUpdated(row, row);
                return;
            default:
                // fall through
                break;
        }
        Turnout t = InstanceManager.turnoutManagerInstance().getTurnout(tempRow[TURNOUT_NAME_COL]);
        if (t != null) {
            int s = Turnout.UNKNOWN;
            if (tempRow[SETTINGCOLUMN].equals(closed)) {
                s = Turnout.CLOSED;
            } else if (tempRow[SETTINGCOLUMN].equals(thrown)) {
                s = Turnout.THROWN;
            } else {
                JOptionPane.showMessageDialog(null, Bundle.getMessage("TurnoutMustBeSet", closed, thrown), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                return;
            }
            BeanSetting bs = new BeanSetting(t, tempRow[TURNOUT_NAME_COL], s);
            _path.addSetting(bs);
            fireTableRowsUpdated(row, row);
        } else {
            JOptionPane.showMessageDialog(null, Bundle.getMessage("NoSuchTurnout", tempRow[TURNOUT_NAME_COL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
            return;
        }
        initTempRow();
        return;
    }
    BeanSetting bs = _path.getSettings().get(row);
    switch(col) {
        case TURNOUT_NAME_COL:
            Turnout t = InstanceManager.turnoutManagerInstance().getTurnout((String) value);
            if (t != null) {
                if (!t.equals(bs.getBean())) {
                    _path.removeSetting(bs);
                    _path.addSetting(new BeanSetting(t, (String) value, bs.getSetting()));
                }
            } else {
                JOptionPane.showMessageDialog(null, Bundle.getMessage("NoSuchTurnout", (String) value), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                return;
            }
            fireTableDataChanged();
            break;
        case SETTINGCOLUMN:
            String setting = (String) value;
            if (setting.equals(closed)) {
                //bs.setSetting(Turnout.CLOSED);  - This was the form before BeanSetting was returned to Immutable
                _path.getSettings().set(row, new BeanSetting(bs.getBean(), bs.getBeanName(), Turnout.CLOSED));
            } else if (setting.equals(thrown)) {
                //bs.setSetting(Turnout.THROWN); 
                _path.getSettings().set(row, new BeanSetting(bs.getBean(), bs.getBeanName(), Turnout.THROWN));
            } else {
                JOptionPane.showMessageDialog(null, Bundle.getMessage("TurnoutMustBeSet", closed, thrown), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                return;
            }
            fireTableRowsUpdated(row, row);
            break;
        case DELETE_COL:
            if (JOptionPane.showConfirmDialog(null, Bundle.getMessage("DeleteTurnoutConfirm"), Bundle.getMessage("WarningTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
                _path.removeSetting(bs);
                fireTableDataChanged();
            }
            break;
        default:
            log.warn("Unhandled col: {}", col);
            break;
    }
}
Also used : BeanSetting(jmri.BeanSetting) Turnout(jmri.Turnout)

Example 2 with BeanSetting

use of jmri.BeanSetting in project JMRI by JMRI.

the class LayoutEditorAuxTools method addBeanSettings.

/**
     * Searches for and adds BeanSetting's to a Path as needed.
     * <P>
     * This method starts at the entry point to the LayoutBlock given in the
     * Path at the block boundary specified in the LayoutConnectivity. It
     * follows the track looking for turnout settings that are required for a
     * train entering on this block boundary point to exit the block. If a
     * required turnout setting is found, the turnout and its required state are
     * used to create a BeanSetting, which is added to the Path. Such a setting
     * can occur, for example, if a track enters a right-handed turnout from
     * either the diverging track or the continuing track.
     * <P>
     * If the track branches into two tracks (for example, by entering a
     * right-handed turnout via the throat track), the search is stopped. The
     * search is also stopped when the track reaches a different block (or an
     * undefined block), or reaches an end bumper.
     */
public void addBeanSettings(Path p, LayoutConnectivity lc, LayoutBlock layoutBlock) {
    p.clearSettings();
    Object curConnection = null;
    Object prevConnection = null;
    int typeCurConnection = 0;
    BeanSetting bs = null;
    LayoutTurnout lt = null;
    // process object at block boundary
    if (lc.getBlock1() == layoutBlock) {
        // block1 is this LayoutBlock
        curConnection = lc.getTrackSegment();
        if (curConnection != null) {
            // connected object in this block is a track segment
            prevConnection = lc.getConnectedObject();
            typeCurConnection = LayoutTrack.TRACK;
            // is this Track Segment connected to a RH, LH, or WYE turnout at the continuing or diverging track
            if (((lc.getConnectedType() == LayoutTrack.TURNOUT_B) || (lc.getConnectedType() == LayoutTrack.TURNOUT_C)) && ((((LayoutTurnout) prevConnection).getTurnoutType() >= LayoutTurnout.RH_TURNOUT) && (((LayoutTurnout) prevConnection).getTurnoutType() <= LayoutTurnout.WYE_TURNOUT))) {
                LayoutTurnout ltx = (LayoutTurnout) prevConnection;
                if (lc.getConnectedType() == LayoutTrack.TURNOUT_B) {
                    // Track Segment connected to continuing track of turnout
                    bs = new BeanSetting(ltx.getTurnout(), ltx.getTurnoutName(), ltx.getContinuingSense());
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (A): " + ltx.getName() + " " + ltx.getLayoutBlock().getDisplayName() + " ltx.getContinuingSense(): " + ltx.getContinuingSense());
                    }
                } else if (lc.getConnectedType() == LayoutTrack.TURNOUT_C) {
                    // Track Segment connected to diverging track of turnout
                    if (ltx.getContinuingSense() == Turnout.CLOSED) {
                        bs = new BeanSetting(ltx.getTurnout(), ltx.getTurnoutName(), Turnout.THROWN);
                    } else {
                        bs = new BeanSetting(ltx.getTurnout(), ltx.getTurnoutName(), Turnout.CLOSED);
                    }
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (B): " + ltx.getName() + " " + ltx.getLayoutBlock().getDisplayName() + " ltx.getContinuingSense(): " + ltx.getContinuingSense());
                    }
                } else {
                    log.warn("Did not decode lc.getConnectedType() of {}", lc.getConnectedType());
                }
            } else // is this Track Segment connected to the continuing track of a RH_XOVER or LH_XOVER
            if (((lc.getConnectedType() >= LayoutTrack.TURNOUT_A) && (lc.getConnectedType() <= LayoutTrack.TURNOUT_D)) && ((((LayoutTurnout) prevConnection).getTurnoutType() == LayoutTurnout.RH_XOVER) || (((LayoutTurnout) prevConnection).getTurnoutType() == LayoutTurnout.LH_XOVER))) {
                LayoutTurnout ltz = (LayoutTurnout) prevConnection;
                if (((ltz.getTurnoutType() == LayoutTurnout.RH_XOVER) && ((lc.getConnectedType() == LayoutTrack.TURNOUT_B) || (lc.getConnectedType() == LayoutTrack.TURNOUT_D))) || ((ltz.getTurnoutType() == LayoutTurnout.LH_XOVER) && ((lc.getConnectedType() == LayoutTrack.TURNOUT_A) || (lc.getConnectedType() == LayoutTrack.TURNOUT_C)))) {
                    bs = new BeanSetting(ltz.getTurnout(), ltz.getTurnoutName(), Turnout.CLOSED);
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (C): " + ltz.getName() + " " + ltz.getLayoutBlock().getDisplayName() + " ltz.getTurnoutType(): " + ltz.getTurnoutType() + " lc.getConnectedType(): " + lc.getConnectedType());
                    }
                }
            } else //This track section is connected to a slip
            if (lc.getConnectedType() >= LayoutTrack.SLIP_A && lc.getConnectedType() <= LayoutTrack.SLIP_D) {
                LayoutSlip lsz = (LayoutSlip) prevConnection;
                if (lsz.getSlipType() == LayoutSlip.SINGLE_SLIP) {
                    if (lc.getConnectedType() == LayoutTrack.SLIP_C) {
                        bs = new BeanSetting(lsz.getTurnout(), lsz.getTurnoutName(), lsz.getTurnoutState(LayoutTurnout.STATE_AC));
                        if (bs.getBean() != null) {
                            p.addSetting(bs);
                        } else {
                            InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                            log.error("BadBeanError (D): " + lsz.getName() + " " + lsz.getLayoutBlock().getDisplayName());
                        }
                        bs = new BeanSetting(lsz.getTurnoutB(), lsz.getTurnoutBName(), lsz.getTurnoutBState(LayoutTurnout.STATE_AC));
                        if (bs.getBean() != null) {
                            p.addSetting(bs);
                        } else {
                            InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                            log.error("BadBeanError (E): " + lsz.getName() + " " + lsz.getLayoutBlock().getDisplayName());
                        }
                    } else if (lc.getConnectedType() == LayoutTrack.SLIP_B) {
                        bs = new BeanSetting(lsz.getTurnout(), lsz.getTurnoutName(), lsz.getTurnoutState(LayoutTurnout.STATE_BD));
                        if (bs.getBean() != null) {
                            p.addSetting(bs);
                        } else {
                            InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                            log.error("BadBeanError (F): " + lsz.getName() + " " + lsz.getLayoutBlock().getDisplayName() + " " + lsz.getTurnout() + " " + lsz.getTurnoutName() + " " + lsz.getTurnoutState(LayoutTurnout.STATE_BD));
                        }
                        bs = new BeanSetting(lsz.getTurnoutB(), lsz.getTurnoutBName(), lsz.getTurnoutBState(LayoutTurnout.STATE_BD));
                        if (bs.getBean() != null) {
                            p.addSetting(bs);
                        } else {
                            InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                            log.error("BadBeanError (G): " + lsz.getName() + " " + lsz.getLayoutBlock().getDisplayName() + " " + lsz.getTurnoutB() + " " + lsz.getTurnoutBName() + " " + lsz.getTurnoutBState(LayoutTurnout.STATE_BD));
                        }
                    } else if (lc.getConnectedType() == LayoutTrack.SLIP_A) {
                        log.debug("At connection A of a single slip which could go in two different directions");
                    } else if (lc.getConnectedType() == LayoutTrack.SLIP_D) {
                        log.debug("At connection D of a single slip which could go in two different directions");
                    }
                } else {
                    //note: I'm adding these logs as a prequel to adding the correct code for (single &double) slips
                    if (lc.getConnectedType() == LayoutTrack.SLIP_A) {
                        log.info("At connection A of a double slip which could go in two different directions");
                    } else if (lc.getConnectedType() == LayoutTrack.SLIP_B) {
                        log.info("At connection B of a double slip which could go in two different directions");
                    } else if (lc.getConnectedType() == LayoutTrack.SLIP_C) {
                        log.info("At connection C of a double slip which could go in two different directions");
                    } else if (lc.getConnectedType() == LayoutTrack.SLIP_D) {
                        log.info("At connection D of a double slip which could go in two different directions");
                    } else {
                        // this should NEVER happen (it should always be SLIP_A, _B, _C or _D.
                        log.info("At a double slip we could go in two different directions");
                    }
                }
            }
        } else {
            // block boundary is internal to a crossover turnout
            lt = lc.getXover();
            prevConnection = lt;
            if ((lt != null) && (lt.getTurnout() != null)) {
                int type = lc.getXoverBoundaryType();
                if (type == LayoutConnectivity.XOVER_BOUNDARY_AB) {
                    bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
                    curConnection = lt.getConnectA();
                } else if (type == LayoutConnectivity.XOVER_BOUNDARY_CD) {
                    bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
                    curConnection = lt.getConnectC();
                } else if (type == LayoutConnectivity.XOVER_BOUNDARY_AC) {
                    bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.THROWN);
                    curConnection = lt.getConnectA();
                } else if (type == LayoutConnectivity.XOVER_BOUNDARY_BD) {
                    bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.THROWN);
                    curConnection = lt.getConnectB();
                } else {
                    log.warn("failed to decode lc.getXoverBoundaryType() of {} (A)", lc.getXoverBoundaryType());
                }
                typeCurConnection = LayoutTrack.TRACK;
                if ((bs != null) && (bs.getBean() != null)) {
                    p.addSetting(bs);
                } else {
                    InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                    log.error("BadBeanError (H): " + lt.getName() + " " + lt.getLayoutBlock().getDisplayName() + " " + type);
                }
            }
        }
    } else if (lc.getXover() != null) {
        // first Block is not in a Track Segment, must be block boundary internal to a crossover turnout
        lt = lc.getXover();
        if ((lt != null) && (lt.getTurnout() != null)) {
            int type = lc.getXoverBoundaryType();
            if (type == LayoutConnectivity.XOVER_BOUNDARY_AB) {
                bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
                curConnection = lt.getConnectB();
            } else if (type == LayoutConnectivity.XOVER_BOUNDARY_CD) {
                bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
                curConnection = lt.getConnectD();
            } else if (type == LayoutConnectivity.XOVER_BOUNDARY_AC) {
                bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.THROWN);
                curConnection = lt.getConnectC();
            } else if (type == LayoutConnectivity.XOVER_BOUNDARY_BD) {
                bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.THROWN);
                curConnection = lt.getConnectD();
            } else {
                log.warn("failed to decode lc.getXoverBoundaryType() of {} (B)", lc.getXoverBoundaryType());
            }
            typeCurConnection = LayoutTrack.TRACK;
            if ((bs != null) && (bs.getBean() != null)) {
                p.addSetting(bs);
            } else {
                InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                log.error("BadBeanError (I): " + lt.getName() + " " + lt.getLayoutBlock().getDisplayName() + " " + type);
            }
        }
    } else {
        // block2 is this LayoutBlock, and block1 is in a track segment
        if (lc.getConnectedObject() != null) {
            // connected object in this block is a turnout or levelxing
            curConnection = lc.getConnectedObject();
            prevConnection = lc.getTrackSegment();
            typeCurConnection = lc.getConnectedType();
            if ((typeCurConnection >= LayoutTrack.TURNOUT_A) && (typeCurConnection <= LayoutTrack.TURNOUT_D)) {
                // connected object is a turnout
                int turnoutType = ((LayoutTurnout) curConnection).getTurnoutType();
                if (turnoutType > LayoutTurnout.WYE_TURNOUT) {
                    // have crossover turnout
                    if ((turnoutType == LayoutTurnout.DOUBLE_XOVER) || ((turnoutType == LayoutTurnout.RH_XOVER) && ((typeCurConnection == LayoutTrack.TURNOUT_A) || (typeCurConnection == LayoutTrack.TURNOUT_C))) || ((turnoutType == LayoutTurnout.LH_XOVER) && ((typeCurConnection == LayoutTrack.TURNOUT_B) || (typeCurConnection == LayoutTrack.TURNOUT_D)))) {
                        // entering turnout at a throat, cannot follow path any further
                        curConnection = null;
                    } else {
                        // entering turnout at continuing track
                        bs = new BeanSetting(((LayoutTurnout) curConnection).getTurnout(), ((LayoutTurnout) curConnection).getTurnoutName(), Turnout.CLOSED);
                        if (bs.getBean() != null) {
                            p.addSetting(bs);
                        } else {
                            InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                            log.error("BadBeanError (J): " + ((LayoutTurnout) curConnection).getName() + " " + ((LayoutTurnout) curConnection).getLayoutBlock().getDisplayName());
                        }
                        prevConnection = curConnection;
                        if (typeCurConnection == LayoutTrack.TURNOUT_A) {
                            curConnection = ((LayoutTurnout) curConnection).getConnectB();
                        } else if (typeCurConnection == LayoutTrack.TURNOUT_B) {
                            curConnection = ((LayoutTurnout) curConnection).getConnectA();
                        } else if (typeCurConnection == LayoutTrack.TURNOUT_C) {
                            curConnection = ((LayoutTurnout) curConnection).getConnectD();
                        } else {
                            // typeCurConnection == LayoutTrack.TURNOUT_D per if statement 3 levels up
                            curConnection = ((LayoutTurnout) curConnection).getConnectC();
                        }
                        typeCurConnection = LayoutTrack.TRACK;
                    }
                } else // must be RH, LH, or WYE turnout
                if (typeCurConnection == LayoutTrack.TURNOUT_A) {
                    // turnout throat, no bean setting needed and cannot follow Path any further
                    curConnection = null;
                } else if (typeCurConnection == LayoutTrack.TURNOUT_B) {
                    // continuing track of turnout
                    if (((LayoutTurnout) curConnection).getContinuingSense() == Turnout.CLOSED) {
                        bs = new BeanSetting(((LayoutTurnout) curConnection).getTurnout(), ((LayoutTurnout) curConnection).getTurnoutName(), Turnout.CLOSED);
                    } else {
                        bs = new BeanSetting(((LayoutTurnout) curConnection).getTurnout(), ((LayoutTurnout) curConnection).getTurnoutName(), Turnout.THROWN);
                    }
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (K): " + ((LayoutTurnout) curConnection).getName() + " " + ((LayoutTurnout) curConnection).getLayoutBlock().getDisplayName());
                    }
                    prevConnection = curConnection;
                    curConnection = ((LayoutTurnout) curConnection).getConnectA();
                    typeCurConnection = LayoutTrack.TRACK;
                } else if (typeCurConnection == LayoutTrack.TURNOUT_C) {
                    // diverging track of turnout
                    if (((LayoutTurnout) curConnection).getContinuingSense() == Turnout.CLOSED) {
                        bs = new BeanSetting(((LayoutTurnout) curConnection).getTurnout(), ((LayoutTurnout) curConnection).getTurnoutName(), Turnout.THROWN);
                    } else {
                        bs = new BeanSetting(((LayoutTurnout) curConnection).getTurnout(), ((LayoutTurnout) curConnection).getTurnoutName(), Turnout.CLOSED);
                    }
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (L): " + ((LayoutTurnout) curConnection).getName() + " " + ((LayoutTurnout) curConnection).getLayoutBlock().getDisplayName());
                    }
                    prevConnection = curConnection;
                    curConnection = ((LayoutTurnout) curConnection).getConnectA();
                    typeCurConnection = LayoutTrack.TRACK;
                }
            } else // if level crossing, skip to the connected track segment on opposite side
            if (typeCurConnection == LayoutTrack.LEVEL_XING_A) {
                prevConnection = curConnection;
                curConnection = ((LevelXing) curConnection).getConnectC();
                typeCurConnection = LayoutTrack.TRACK;
            } else if (typeCurConnection == LayoutTrack.LEVEL_XING_C) {
                prevConnection = curConnection;
                curConnection = ((LevelXing) curConnection).getConnectA();
                typeCurConnection = LayoutTrack.TRACK;
            } else if (typeCurConnection == LayoutTrack.LEVEL_XING_B) {
                prevConnection = curConnection;
                curConnection = ((LevelXing) curConnection).getConnectD();
                typeCurConnection = LayoutTrack.TRACK;
            } else if (typeCurConnection == LayoutTrack.LEVEL_XING_D) {
                prevConnection = curConnection;
                curConnection = ((LevelXing) curConnection).getConnectB();
                typeCurConnection = LayoutTrack.TRACK;
            } else if (typeCurConnection == LayoutTrack.SLIP_D) {
                LayoutSlip lsz = (LayoutSlip) curConnection;
                curConnection = null;
            }
        } else {
            // block boundary is internal to a crossover turnout
            lt = lc.getXover();
            prevConnection = lt;
            if ((lt != null) && (lt.getTurnout() != null)) {
                int type = lc.getXoverBoundaryType();
                if (type == LayoutConnectivity.XOVER_BOUNDARY_AB) {
                    bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
                    curConnection = lt.getConnectB();
                } else if (type == LayoutConnectivity.XOVER_BOUNDARY_CD) {
                    bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
                    curConnection = lt.getConnectD();
                } else if (type == LayoutConnectivity.XOVER_BOUNDARY_AC) {
                    bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.THROWN);
                    curConnection = lt.getConnectC();
                } else if (type == LayoutConnectivity.XOVER_BOUNDARY_BD) {
                    bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.THROWN);
                    curConnection = lt.getConnectD();
                }
                typeCurConnection = LayoutTrack.TRACK;
                if ((bs != null) && (bs.getBean() != null)) {
                    p.addSetting(bs);
                } else {
                    InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                    log.error("BadBeanError (Q): " + lt.getName() + " " + lt.getLayoutBlock().getDisplayName());
                }
            }
        }
    }
    // follow path through this block - done when reaching another block, or a branching of Path
    while (curConnection != null) {
        if (typeCurConnection == LayoutTrack.TRACK) {
            // track segment is current connection
            if (((TrackSegment) curConnection).getLayoutBlock() != layoutBlock) {
                curConnection = null;
            } else {
                // skip over to other end of Track Segment
                if (((TrackSegment) curConnection).getConnect1() == prevConnection) {
                    prevConnection = curConnection;
                    typeCurConnection = ((TrackSegment) curConnection).getType2();
                    curConnection = ((TrackSegment) curConnection).getConnect2();
                } else {
                    prevConnection = curConnection;
                    typeCurConnection = ((TrackSegment) curConnection).getType1();
                    curConnection = ((TrackSegment) curConnection).getConnect1();
                }
                // skip further if positionable point (possible anchor point)
                if (typeCurConnection == LayoutTrack.POS_POINT) {
                    PositionablePoint pt = (PositionablePoint) curConnection;
                    if (pt.getType() == PositionablePoint.END_BUMPER) {
                        // reached end of track
                        curConnection = null;
                    } else {
                        // at an anchor point, find track segment on other side
                        TrackSegment track = null;
                        if (pt.getConnect1() == prevConnection) {
                            track = pt.getConnect2();
                        } else {
                            track = pt.getConnect1();
                        }
                        // check for block boundary
                        if ((track == null) || (track.getLayoutBlock() != layoutBlock)) {
                            // moved outside of block - anchor point was a block boundary -OR-
                            //  reached the end of the defined track
                            curConnection = null;
                        } else {
                            prevConnection = curConnection;
                            curConnection = track;
                            typeCurConnection = LayoutTrack.TRACK;
                        }
                    }
                }
            }
        } else if ((typeCurConnection >= LayoutTrack.TURNOUT_A) && (typeCurConnection <= LayoutTrack.TURNOUT_D)) {
            lt = (LayoutTurnout) curConnection;
            // test for crossover turnout
            if (lt.getTurnoutType() <= LayoutTurnout.WYE_TURNOUT) {
                if (lt.getLayoutBlock() != layoutBlock) {
                    curConnection = null;
                } else {
                    // turnout is in current block, test connection point
                    if (typeCurConnection == LayoutTrack.TURNOUT_A) {
                        // turnout throat, no bean setting needed and cannot follow possible path any further
                        curConnection = null;
                    } else if (typeCurConnection == LayoutTrack.TURNOUT_B) {
                        // continuing track of turnout, add a bean setting
                        if (lt.getContinuingSense() == Turnout.CLOSED) {
                            bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
                        } else {
                            bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.THROWN);
                        }
                        if (bs.getBean() != null) {
                            p.addSetting(bs);
                        } else {
                            InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                            log.error("BadBeanError (R): " + lt.getName() + " " + lt.getLayoutBlock().getDisplayName());
                        }
                        if (lt.getLayoutBlock() != layoutBlock) {
                            curConnection = null;
                        } else {
                            prevConnection = curConnection;
                            curConnection = lt.getConnectA();
                            typeCurConnection = LayoutTrack.TRACK;
                        }
                    } else if (typeCurConnection == LayoutTrack.TURNOUT_C) {
                        // diverging track of turnout
                        if (lt.getContinuingSense() == Turnout.CLOSED) {
                            bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.THROWN);
                        } else {
                            bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
                        }
                        if (bs.getBean() != null) {
                            p.addSetting(bs);
                        } else {
                            InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                            log.error("BadBeanError (S) LayoutTurnout " + lt.getName() + " has Turnout: " + lt.getTurnout() + " turnoutName: " + lt.getTurnoutName());
                        }
                        if (lt.getLayoutBlock() != layoutBlock) {
                            curConnection = null;
                        } else {
                            prevConnection = curConnection;
                            curConnection = lt.getConnectA();
                            typeCurConnection = LayoutTrack.TRACK;
                        }
                    }
                }
            } else if (lt.getTurnoutType() == LayoutTurnout.DOUBLE_XOVER) {
                // have a double crossover turnout, cannot follow possible path any further
                curConnection = null;
            } else if (lt.getTurnoutType() == LayoutTurnout.RH_XOVER) {
                // have a right-handed crossover turnout
                if ((typeCurConnection == LayoutTrack.TURNOUT_A) || (typeCurConnection == LayoutTrack.TURNOUT_C)) {
                    // entry is at turnout throat, cannot follow possible path any further
                    curConnection = null;
                } else if (typeCurConnection == LayoutTrack.TURNOUT_B) {
                    // entry is at continuing track of turnout
                    bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (T) LayoutTurnout " + lt.getName() + " has Turnout: " + lt.getTurnout() + " turnoutName: " + lt.getTurnoutName());
                    }
                    if (lt.getLayoutBlock() != layoutBlock) {
                        // left current block
                        curConnection = null;
                    } else {
                        prevConnection = curConnection;
                        curConnection = lt.getConnectA();
                        typeCurConnection = LayoutTrack.TRACK;
                    }
                } else if (typeCurConnection == LayoutTrack.TURNOUT_D) {
                    // entry is at continuing track of turnout
                    bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (U) LayoutTurnout " + lt.getName() + " has Turnout: " + lt.getTurnout() + " turnoutName: " + lt.getTurnoutName());
                    }
                    if (lt.getLayoutBlockC() != layoutBlock) {
                        // left current block
                        curConnection = null;
                    } else {
                        prevConnection = curConnection;
                        curConnection = lt.getConnectC();
                        typeCurConnection = LayoutTrack.TRACK;
                    }
                }
            } else if (lt.getTurnoutType() == LayoutTurnout.LH_XOVER) {
                // have a left-handed crossover turnout
                if ((typeCurConnection == LayoutTrack.TURNOUT_B) || (typeCurConnection == LayoutTrack.TURNOUT_D)) {
                    // entry is at turnout throat, cannot follow possible path any further
                    curConnection = null;
                } else if (typeCurConnection == LayoutTrack.TURNOUT_A) {
                    // entry is at continuing track of turnout
                    bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (V) LayoutTurnout " + lt.getName() + " has Turnout: " + lt.getTurnout() + " turnoutName: " + lt.getTurnoutName());
                    }
                    if (lt.getLayoutBlockB() != layoutBlock) {
                        // left current block
                        curConnection = null;
                    } else {
                        prevConnection = curConnection;
                        curConnection = lt.getConnectB();
                        typeCurConnection = LayoutTrack.TRACK;
                    }
                } else {
                    // typeCurConnection == LayoutTrack.TURNOUT_C per if statement 2 levels up
                    // entry is at continuing track of turnout
                    bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (W) LayoutTurnout " + lt.getName() + " has Turnout: " + lt.getTurnout() + " turnoutName: " + lt.getTurnoutName());
                    }
                    if (lt.getLayoutBlockD() != layoutBlock) {
                        // left current block
                        curConnection = null;
                    } else {
                        prevConnection = curConnection;
                        curConnection = lt.getConnectD();
                        typeCurConnection = LayoutTrack.TRACK;
                    }
                }
            }
        } else if (typeCurConnection == LayoutTrack.LEVEL_XING_A) {
            // have a level crossing connected at A
            if (((LevelXing) curConnection).getLayoutBlockAC() != layoutBlock) {
                // moved outside of this block
                curConnection = null;
            } else {
                // move to other end of this section of this level crossing track
                prevConnection = curConnection;
                curConnection = ((LevelXing) curConnection).getConnectC();
                typeCurConnection = LayoutTrack.TRACK;
            }
        } else if (typeCurConnection == LayoutTrack.LEVEL_XING_B) {
            // have a level crossing connected at B
            if (((LevelXing) curConnection).getLayoutBlockBD() != layoutBlock) {
                // moved outside of this block
                curConnection = null;
            } else {
                // move to other end of this section of this level crossing track
                prevConnection = curConnection;
                curConnection = ((LevelXing) curConnection).getConnectD();
                typeCurConnection = LayoutTrack.TRACK;
            }
        } else if (typeCurConnection == LayoutTrack.LEVEL_XING_C) {
            // have a level crossing connected at C
            if (((LevelXing) curConnection).getLayoutBlockAC() != layoutBlock) {
                // moved outside of this block
                curConnection = null;
            } else {
                // move to other end of this section of this level crossing track
                prevConnection = curConnection;
                curConnection = ((LevelXing) curConnection).getConnectA();
                typeCurConnection = LayoutTrack.TRACK;
            }
        } else if (typeCurConnection == LayoutTrack.LEVEL_XING_D) {
            // have a level crossing connected at D
            if (((LevelXing) curConnection).getLayoutBlockBD() != layoutBlock) {
                // moved outside of this block
                curConnection = null;
            } else {
                // move to other end of this section of this level crossing track
                prevConnection = curConnection;
                curConnection = ((LevelXing) curConnection).getConnectB();
                typeCurConnection = LayoutTrack.TRACK;
            }
        } else if (typeCurConnection >= LayoutTrack.SLIP_A && typeCurConnection <= LayoutTrack.SLIP_D) {
            LayoutSlip ls = (LayoutSlip) curConnection;
            if (ls.getLayoutBlock() != layoutBlock) {
                curConnection = null;
            } else if (ls.getSlipType() == LayoutSlip.SINGLE_SLIP) {
                if (typeCurConnection == LayoutTrack.SLIP_C) {
                    bs = new BeanSetting(ls.getTurnout(), ls.getTurnoutName(), ls.getTurnoutState(LayoutTurnout.STATE_AC));
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (X): " + ls.getName() + " " + ls.getLayoutBlock().getDisplayName());
                    }
                    bs = new BeanSetting(ls.getTurnoutB(), ls.getTurnoutBName(), ls.getTurnoutBState(LayoutTurnout.STATE_AC));
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (Y): " + ls.getName() + " " + ls.getLayoutBlock().getDisplayName());
                    }
                    prevConnection = curConnection;
                    curConnection = ((LayoutSlip) curConnection).getConnectC();
                    typeCurConnection = LayoutTrack.TRACK;
                } else if (typeCurConnection == LayoutTrack.SLIP_B) {
                    bs = new BeanSetting(ls.getTurnout(), ls.getTurnoutName(), ls.getTurnoutState(LayoutTurnout.STATE_BD));
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (Z): " + ls.getName() + " " + ls.getLayoutBlock().getDisplayName());
                    }
                    bs = new BeanSetting(ls.getTurnoutB(), ls.getTurnoutBName(), ls.getTurnoutBState(LayoutTurnout.STATE_BD));
                    if (bs.getBean() != null) {
                        p.addSetting(bs);
                    } else {
                        InstanceManager.getDefault(LayoutBlockManager.class).addBadBeanError();
                        log.error("BadBeanError (1): " + ls.getName() + " " + ls.getLayoutBlock().getDisplayName());
                    }
                    prevConnection = curConnection;
                    curConnection = ((LayoutSlip) curConnection).getConnectB();
                    typeCurConnection = LayoutTrack.TRACK;
                } else {
                    //Else could be going in the slip direction
                    curConnection = null;
                }
            } else {
                //At double slip, can not follow any further
                curConnection = null;
            }
        } else if (typeCurConnection >= 50) {
            if (log.isDebugEnabled()) {
                log.debug("Layout Block: " + layoutBlock.getDisplayName() + " found track type: " + typeCurConnection + " to Block: " + p.getBlock().getDisplayName() + " Is potentially assigned to turntable ray");
            }
            curConnection = null;
        } else {
            // catch when some new type got added
            log.error("Layout Block: " + layoutBlock.getDisplayName() + " found unknown track type: " + typeCurConnection + " to Block: " + p.getBlock().getDisplayName());
            break;
        }
    }
}
Also used : BeanSetting(jmri.BeanSetting)

Example 3 with BeanSetting

use of jmri.BeanSetting in project JMRI by JMRI.

the class OPath method fireTurnouts.

void fireTurnouts(List<BeanSetting> list, boolean set, int lockState, boolean lock) {
    for (int i = 0; i < list.size(); i++) {
        BeanSetting bs = list.get(i);
        Turnout t = (Turnout) bs.getBean();
        if (t == null) {
            log.error("Invalid turnout on path {}", toString());
        } else {
            if (set) {
                t.setCommandedState(bs.getSetting());
            }
            if (lockState > 0) {
                t.setLocked(lockState, lock);
            }
        }
    }
}
Also used : BeanSetting(jmri.BeanSetting) Turnout(jmri.Turnout)

Example 4 with BeanSetting

use of jmri.BeanSetting in project JMRI by JMRI.

the class OPath method addSetting.

/**
     * {@inheritDoc} Does not allow duplicate settings.
     */
@Override
public void addSetting(BeanSetting t) {
    Iterator<BeanSetting> iter = getSettings().iterator();
    while (iter.hasNext()) {
        BeanSetting bs = iter.next();
        if (bs.getBeanName().equals(t.getBeanName())) {
            log.error("TO setting for \"{}\" already set to {}", t.getBeanName(), bs.getSetting());
            return;
        }
    }
    super.addSetting(t);
}
Also used : BeanSetting(jmri.BeanSetting)

Example 5 with BeanSetting

use of jmri.BeanSetting in project JMRI by JMRI.

the class OBlockManagerXml method storePath.

private static Element storePath(OPath path) {
    Element elem = new Element("path");
    elem.setAttribute("pathName", path.getName());
    elem.setAttribute("blockName", "" + path.getBlock().getSystemName());
    Portal portal = path.getFromPortal();
    if (portal != null) {
        elem.setAttribute("fromPortal", portal.getName());
    }
    portal = path.getToPortal();
    if (portal != null) {
        elem.setAttribute("toPortal", portal.getName());
    }
    List<BeanSetting> list = path.getSettings();
    for (int i = 0; i < list.size(); i++) {
        BeanSetting bs = list.get(i);
        Element e = new Element("setting");
        //Turnout to = (Turnout)bs.getBean();
        e.setAttribute("turnout", bs.getBeanName());
        e.setAttribute("set", "" + bs.getSetting());
        elem.addContent(e);
    }
    elem.setAttribute("fromDirection", "" + path.getFromBlockDirection());
    elem.setAttribute("toDirection", "" + path.getToBlockDirection());
    // get actual object stored length.
    elem.setAttribute("length", "" + path.getLength());
    return elem;
}
Also used : BeanSetting(jmri.BeanSetting) Element(org.jdom2.Element) Portal(jmri.jmrit.logix.Portal)

Aggregations

BeanSetting (jmri.BeanSetting)15 Turnout (jmri.Turnout)6 Portal (jmri.jmrit.logix.Portal)5 Element (org.jdom2.Element)4 OPath (jmri.jmrit.logix.OPath)3 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)2 Path (jmri.Path)2 Sensor (jmri.Sensor)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 Block (jmri.Block)1 JmriException (jmri.JmriException)1 NamedBean (jmri.NamedBean)1 SensorManager (jmri.SensorManager)1 AbstractSensor (jmri.implementation.AbstractSensor)1 IndicatorTrack (jmri.jmrit.display.IndicatorTrack)1 IndicatorTurnoutIcon (jmri.jmrit.display.IndicatorTurnoutIcon)1 Positionable (jmri.jmrit.display.Positionable)1 Attribute (org.jdom2.Attribute)1