Search in sources :

Example 6 with SignalGroup

use of jmri.SignalGroup in project JMRI by JMRI.

the class DefaultSignalGroupManagerXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    // loop over contained signalgroup elements
    List<Element> list = shared.getChildren("signalgroup");
    SignalGroupManager sgm = InstanceManager.getDefault(jmri.SignalGroupManager.class);
    for (int i = 0; i < list.size(); i++) {
        SignalGroup m;
        Element e = list.get(i);
        String primary;
        String yesno;
        boolean inverse = false;
        int state = 0x00;
        String sys = getSystemName(e);
        m = sgm.newSignalGroup(sys);
        if (getUserName(e) != null) {
            m.setUserName(getUserName(e));
        }
        //loadCommon(m, e); // would store comment, now a separate element
        loadComment(m, e);
        primary = e.getAttribute("signalMast").getValue();
        m.setSignalMast(primary);
        // deprecated 4.7.2 for aspect
        List<Element> appList = e.getChildren("appearance");
        for (int y = 0; y < appList.size(); y++) {
            String value = appList.get(y).getAttribute("valid").getValue();
            m.addSignalMastAspect(value);
        }
        List<Element> aspList = e.getChildren("aspect");
        for (int y = 0; y < aspList.size(); y++) {
            String value = aspList.get(y).getAttribute("valid").getValue();
            m.addSignalMastAspect(value);
        }
        List<Element> signalHeadList = list.get(i).getChildren("signalHead");
        if (signalHeadList.size() > 0) {
            for (int y = 0; y < signalHeadList.size(); y++) {
                String head = signalHeadList.get(y).getAttribute("name").getValue();
                SignalHead sigHead = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(head);
                m.addSignalHead(sigHead);
                yesno = signalHeadList.get(y).getAttribute("sensorTurnoutLogic").getValue();
                inverse = false;
                if ((yesno != null) && (!yesno.equals(""))) {
                    if (yesno.equals("AND")) {
                        inverse = true;
                    } else if (yesno.equals("OR")) {
                        inverse = false;
                    }
                }
                m.setSensorTurnoutOper(sigHead, inverse);
                try {
                    m.setHeadOnState(sigHead, getIntFromColour(signalHeadList.get(y).getAttribute("onAppearance").getValue()));
                } catch (NullPointerException ex) {
                // considered normal if the attributes are not present
                }
                try {
                    m.setHeadOffState(sigHead, getIntFromColour(signalHeadList.get(y).getAttribute("offAppearance").getValue()));
                } catch (NullPointerException ex) {
                // considered normal if the attributes are not present
                }
                List<Element> signalTurnoutList = signalHeadList.get(y).getChildren("turnout");
                if (signalTurnoutList.size() > 0) {
                    for (int k = 0; k < signalTurnoutList.size(); k++) {
                        String tName = signalTurnoutList.get(k).getAttribute("name").getValue();
                        jmri.Turnout turnout = jmri.InstanceManager.turnoutManagerInstance().getTurnout(tName);
                        state = 0;
                        try {
                            state = signalTurnoutList.get(k).getAttribute("state").getIntValue();
                        } catch (org.jdom2.DataConversionException ex) {
                            log.warn("invalid state attribute value");
                        }
                        m.setHeadAlignTurnout(sigHead, turnout, state);
                    }
                }
                List<Element> signalSensorList = signalHeadList.get(y).getChildren("sensor");
                if (signalSensorList.size() > 0) {
                    for (int k = 0; k < signalSensorList.size(); k++) {
                        String sName = signalSensorList.get(k).getAttribute("name").getValue();
                        jmri.Sensor sensor = jmri.InstanceManager.sensorManagerInstance().getSensor(sName);
                        state = 0;
                        try {
                            state = signalSensorList.get(k).getAttribute("state").getIntValue();
                        } catch (org.jdom2.DataConversionException ex) {
                            log.warn("invalid style attribute value");
                        }
                        m.setHeadAlignSensor(sigHead, sensor, state);
                    }
                }
            }
        }
    }
    return true;
}
Also used : SignalGroup(jmri.SignalGroup) Element(org.jdom2.Element) SignalHead(jmri.SignalHead) SignalGroupManager(jmri.SignalGroupManager)

Example 7 with SignalGroup

use of jmri.SignalGroup in project JMRI by JMRI.

the class DefaultSignalGroupManagerXml method store.

/**
     * Default implementation for storing the contents of a
     * DefaultSignalGroupManager
     *
     * @param o Object to store, of type TripleTurnoutSignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    SignalGroupManager m = (SignalGroupManager) o;
    Element element = new Element("signalgroups");
    element.setAttribute("class", this.getClass().getName());
    // include contents
    List<String> names = m.getSystemNameList();
    for (int i = 0; i < names.size(); i++) {
        Element e = new Element("signalgroup");
        SignalGroup p = m.getSignalGroup(names.get(i));
        e.addContent(new Element("systemName").addContent(p.getSystemName()));
        e.addContent(new Element("userName").addContent(p.getUserName()));
        //storeCommon(p, e); would store comment, now a separate element
        storeComment(p, e);
        element.addContent(e);
        for (int x = 0; x < p.getNumSignalMastAspects(); x++) {
            Element app = new Element("aspect").setAttribute("valid", p.getSignalMastAspectByIndex(x));
            e.addContent(app);
        }
        e.setAttribute("signalMast", p.getSignalMastName());
        for (int x = 0; x < p.getNumHeadItems(); x++) {
            storeSignalHead(e, p, x);
        }
    }
    return element;
}
Also used : SignalGroup(jmri.SignalGroup) SignalGroupManager(jmri.SignalGroupManager) Element(org.jdom2.Element)

Example 8 with SignalGroup

use of jmri.SignalGroup in project JMRI by JMRI.

the class SignalGroupTableAction method checkNamesOK.

/**
     * Check name and return a new or existing SignalGroup object
     * with the name as entered in the _systemName field on the addFrame pane.
     * @return The new/updated SignalGroup object
     */
SignalGroup checkNamesOK() {
    // Get system name and user name
    String sName = _systemName.getText().toUpperCase();
    String uName = _userName.getText();
    if (sName.length() == 0) {
        javax.swing.JOptionPane.showMessageDialog(null, Bundle.getMessage("RouteAddStatusEnter"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.WARNING_MESSAGE);
        // Reuse a key with general wording
        return null;
    }
    try {
        SignalGroup g = jmri.InstanceManager.getDefault(jmri.SignalGroupManager.class).provideSignalGroup(sName, uName);
        return g;
    } catch (IllegalArgumentException ex) {
        // should never get here
        log.error("checkNamesOK; Unknown failure to create Signal Group with System Name: {}", sName);
        throw ex;
    }
}
Also used : SignalGroup(jmri.SignalGroup)

Example 9 with SignalGroup

use of jmri.SignalGroup in project JMRI by JMRI.

the class SignalGroupTableAction method createModel.

/**
     * Create the JTable DataModel, along with the changes for the specific case
     * of SignalGroups.
     */
@Override
protected void createModel() {
    m = new BeanTableDataModel() {

        public static final int COMMENTCOL = 2;

        public static final int DELETECOL = 3;

        public static final int ENABLECOL = 4;

        // default name: SETCOL
        public static final int EDITCOL = 5;

        @Override
        public int getColumnCount() {
            return 6;
        }

        @Override
        public String getColumnName(int col) {
            if (col == EDITCOL) {
                // no heading on "Edit" column
                return "";
            }
            if (col == ENABLECOL) {
                return Bundle.getMessage("ColumnHeadEnabled");
            }
            if (col == COMMENTCOL) {
                return Bundle.getMessage("ColumnComment");
            }
            if (col == DELETECOL) {
                return "";
            } else {
                return super.getColumnName(col);
            }
        }

        @Override
        public Class<?> getColumnClass(int col) {
            if (col == EDITCOL) {
                return JButton.class;
            }
            if (col == ENABLECOL) {
                return Boolean.class;
            }
            if (col == DELETECOL) {
                return JButton.class;
            }
            if (col == COMMENTCOL) {
                return String.class;
            } else {
                return super.getColumnClass(col);
            }
        }

        @Override
        public int getPreferredWidth(int col) {
            if (col == EDITCOL) {
                return new JTextField(Bundle.getMessage("ButtonEdit")).getPreferredSize().width;
            }
            if (col == ENABLECOL) {
                return new JTextField(6).getPreferredSize().width;
            }
            if (col == COMMENTCOL) {
                return new JTextField(30).getPreferredSize().width;
            }
            if (col == DELETECOL) {
                return new JTextField(Bundle.getMessage("ButtonDelete")).getPreferredSize().width;
            } else {
                return super.getPreferredWidth(col);
            }
        }

        @Override
        public boolean isCellEditable(int row, int col) {
            if (col == COMMENTCOL) {
                return true;
            }
            if (col == EDITCOL) {
                return true;
            }
            if (col == ENABLECOL) {
                return true;
            }
            if (col == DELETECOL) {
                return true;
            } else {
                return super.isCellEditable(row, col);
            }
        }

        @Override
        public Object getValueAt(int row, int col) {
            NamedBean b;
            if (col == EDITCOL) {
                return Bundle.getMessage("ButtonEdit");
            } else if (col == ENABLECOL) {
                return Boolean.valueOf(((SignalGroup) getBySystemName((String) getValueAt(row, SYSNAMECOL))).getEnabled());
            //return true;
            } else if (col == COMMENTCOL) {
                b = getBySystemName(sysNameList.get(row));
                return (b != null) ? b.getComment() : null;
            } else if (//
            col == DELETECOL) {
                return Bundle.getMessage("ButtonDelete");
            } else {
                return super.getValueAt(row, col);
            }
        }

        @Override
        public void setValueAt(Object value, int row, int col) {
            if (col == EDITCOL) {
                // set up to Edit. Use separate Runnable so window is created on top
                class WindowMaker implements Runnable {

                    int row;

                    WindowMaker(int r) {
                        row = r;
                    }

                    @Override
                    public void run() {
                        // set up add/edit panel addFrame (starts as Add pane)
                        addPressed(null);
                        _systemName.setText((String) getValueAt(row, SYSNAMECOL));
                        // adjust addFrame for Edit
                        editPressed(null);
                    }
                }
                WindowMaker t = new WindowMaker(row);
                javax.swing.SwingUtilities.invokeLater(t);
            } else if (col == ENABLECOL) {
                // alternate
                SignalGroup r = (SignalGroup) getBySystemName((String) getValueAt(row, SYSNAMECOL));
                boolean v = r.getEnabled();
                r.setEnabled(!v);
            } else if (col == COMMENTCOL) {
                getBySystemName(sysNameList.get(row)).setComment((String) value);
                fireTableRowsUpdated(row, row);
            } else if (col == DELETECOL) {
                // button fired, delete Bean
                deleteBean(row, col);
            } else {
                super.setValueAt(value, row, col);
            }
        }

        @Override
        public void configureTable(JTable table) {
            table.setDefaultRenderer(Boolean.class, new EnablingCheckboxRenderer());
            table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
            table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
            super.configureTable(table);
        }

        @Override
        protected void configDeleteColumn(JTable table) {
            // have the delete column hold a button
            SignalGroupTableAction.this.setColumnToHoldButton(table, DELETECOL, new JButton(Bundle.getMessage("ButtonDelete")));
        }

        /**
             * Delete the bean after all the checking has been done.
             * <P>
             * (Deactivate the Signal Group), then use the superclass to delete it.
             */
        @Override
        void doDelete(NamedBean bean) {
            //((SignalGroup)bean).deActivateSignalGroup();
            super.doDelete(bean);
        }

        // want to update when enabled parameter changes
        @Override
        protected boolean matchPropertyName(java.beans.PropertyChangeEvent e) {
            if (e.getPropertyName().equals("Enabled")) {
                return true;
            } else {
                return super.matchPropertyName(e);
            }
        }

        @Override
        public Manager getManager() {
            return jmri.InstanceManager.getDefault(jmri.SignalGroupManager.class);
        }

        @Override
        public NamedBean getBySystemName(String name) {
            return jmri.InstanceManager.getDefault(jmri.SignalGroupManager.class).getBySystemName(name);
        }

        @Override
        public NamedBean getByUserName(String name) {
            return jmri.InstanceManager.getDefault(jmri.SignalGroupManager.class).getByUserName(name);
        }

        @Override
        public int getDisplayDeleteMsg() {
            return 0x00;
        /*return InstanceManager.getDefault(jmri.UserPreferencesManager.class).getWarnDeleteSignalGroup();*/
        }

        @Override
        public void setDisplayDeleteMsg(int boo) {
        /*InstanceManager.getDefault(jmri.UserPreferencesManager.class).setWarnDeleteSignalGroup(boo); */
        }

        @Override
        protected String getMasterClassName() {
            return getClassName();
        }

        @Override
        public void clickOn(NamedBean t) {
        // mute action
        //((SignalGroup)t).setSignalGroup();
        }

        @Override
        public String getValue(String s) {
            // not directly used but should be present to implement abstract class
            return "Set";
        }

        /*            public JButton configureButton() {
                return new JButton(" Set ");
            }*/
        @Override
        protected String getBeanType() {
            return "Signal Group";
        }
    };
}
Also used : SignalGroup(jmri.SignalGroup) NamedBean(jmri.NamedBean) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) InstanceManager(jmri.InstanceManager) Manager(jmri.Manager) JTable(javax.swing.JTable)

Example 10 with SignalGroup

use of jmri.SignalGroup in project JMRI by JMRI.

the class SignalGroupTest method testSetup.

@Test
public void testSetup() {
    //apps.tests.Log4JFixture.initLogging();
    // provide 2 turnouts:
    Turnout it1 = InstanceManager.turnoutManagerInstance().provideTurnout("IT1");
    Turnout it2 = InstanceManager.turnoutManagerInstance().provideTurnout("IT2");
    Assert.assertEquals("it before", Turnout.UNKNOWN, it1.getCommandedState());
    Assert.assertEquals("it before", Turnout.UNKNOWN, it2.getCommandedState());
    // provide a single output signal head with IT1 as the output:
    jmri.implementation.SingleTurnoutSignalHead sh = new jmri.implementation.SingleTurnoutSignalHead("IH1", new jmri.NamedBeanHandle<Turnout>("IT1", it1), SignalHead.GREEN, // on state + off state
    SignalHead.DARK);
    Assert.assertNotNull("SignalHead is null!", sh);
    // provide a virtual signal mast:
    SignalMast sm = new jmri.implementation.VirtualSignalMast("IF$vsm:AAR-1946:CPL($0002)");
    Assert.assertNotNull("SignalMast is null!", sm);
    // provide a signal group:
    SignalGroup sg = InstanceManager.getDefault(jmri.SignalGroupManager.class).provideSignalGroup("R12", "SignalGroup12");
    Assert.assertNotNull("SignalGroup is null!", sg);
    // add the head to the group:
    sg.addSignalHead(sh);
    // check value of OnState
    Assert.assertEquals("initial On state", SignalHead.GREEN, sg.getHeadOnState(sh));
    // set On state of IH1 from GREEN to LUNAR:
    sg.setHeadOnState(sh, SignalHead.LUNAR);
    Assert.assertEquals("new On state", SignalHead.LUNAR, sg.getHeadOnState(sh));
    // set IT1 to Closed to end Unknown state:
    // Off = IH1 Dark
    it1.setCommandedState(Turnout.CLOSED);
    // set the control turnout Off
    it2.setCommandedState(Turnout.CLOSED);
    // add IT2 as a control turnout to sh with conditional state Thrown:
    sg.setHeadAlignTurnout(sh, it2, Turnout.THROWN);
    Assert.assertEquals("group align turnout", "IT2", sg.getTurnoutNameByIndex(0, 0));
    // OR
    sg.setSensorTurnoutOper(sh, false);
    Assert.assertEquals("group logic oper", false, sg.getSensorTurnoutOperByIndex(0));
    // attach aspect Clear on mast sm to group
    // condition 1
    sg.addSignalMastAspect("Clear");
    // set sm to Stop
    sm.setAspect("Stop");
    // Debug states
    //        System.out.println("Before:");
    //        System.out.println("IT1 =" + it1.getCommandedState());
    //        System.out.println("IH1 =" + sh.getAppearanceName());
    //        System.out.println("SM =" + sm.getAspect());
    //        System.out.println("IT2 =" + it2.getCommandedState());
    // check state of member head sh
    Assert.assertEquals("sh before", Bundle.getMessage("SignalHeadStateDark"), sh.getAppearanceName());
    // now set conditional turnout
    // set the control turnout On = condition 2
    it2.setCommandedState(Turnout.THROWN);
    // set incuded aspect and check state of member head sh when conditional is met:
    sm.setAspect("Clear");
    //        System.out.println("After:");
    //        System.out.println("IT1 =" + it1.getCommandedState());
    //        System.out.println("IH1 =" + sh.getAppearanceName());
    //        System.out.println("SM =" + sm.getAspect());
    //        System.out.println("IT2 =" + it2.getCommandedState());
    Assert.assertEquals("sh after", Bundle.getMessage("SignalHeadStateDark"), sh.getAppearanceName());
// TODO would expect LUNAR instead, working on SignalGroup code
}
Also used : SignalGroup(jmri.SignalGroup) SignalMast(jmri.SignalMast) Turnout(jmri.Turnout) Test(org.junit.Test)

Aggregations

SignalGroup (jmri.SignalGroup)11 SignalHead (jmri.SignalHead)3 SignalMast (jmri.SignalMast)3 SignalGroupManager (jmri.SignalGroupManager)2 Turnout (jmri.Turnout)2 DefaultSignalGroup (jmri.implementation.DefaultSignalGroup)2 Element (org.jdom2.Element)2 Test (org.junit.Test)2 JButton (javax.swing.JButton)1 JComboBox (javax.swing.JComboBox)1 JFrame (javax.swing.JFrame)1 JTable (javax.swing.JTable)1 JTextField (javax.swing.JTextField)1 InstanceManager (jmri.InstanceManager)1 Manager (jmri.Manager)1 NamedBean (jmri.NamedBean)1