Search in sources :

Example 56 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class IconEditorWindowTest method testSignalHeadEditor.

public void testSignalHeadEditor() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // can't Assume in TestCase
        return;
    }
    Editor.JFrameItem iconEditorFrame = _editor.getIconFrame("SignalHead");
    IconAdder iconEditor = iconEditorFrame.getEditor();
    Assert.assertNotNull(iconEditor);
    SignalHead signalHead = new jmri.implementation.VirtualSignalHead("IH0");
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(signalHead);
    iconEditor.setSelection(signalHead);
    SignalHeadIcon icon = _editor.putSignalHead();
    Assert.assertNotNull(icon);
    SignalHead sh = icon.getSignalHead();
    Assert.assertEquals("SignalHead==sh", signalHead, sh);
    int x = 30;
    int y = 10;
    icon.setLocation(x, y);
    _panel.repaint();
    java.awt.Point location = new java.awt.Point(x + icon.getSize().width / 2, y + icon.getSize().height / 2);
    int[] states = signalHead.getValidStates();
    Assert.assertEquals("initial state", states[0], signalHead.getState());
    getHelper().enterClickAndLeave(new MouseEventData(this, // component
    _panel, // number clicks
    1, // modifiers
    EventDataConstants.DEFAULT_MOUSE_MODIFIERS, // isPopUpTrigger
    false, // sleeptime
    10, // position
    EventDataConstants.CUSTOM, location));
    for (int i = 1; i < states.length; i++) {
        Assert.assertEquals("state after " + i + " click", states[i], signalHead.getState());
        getHelper().enterClickAndLeave(new MouseEventData(this, icon));
    }
    TestHelper.disposeWindow(iconEditorFrame, this);
}
Also used : SignalHead(jmri.SignalHead) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) PanelEditor(jmri.jmrit.display.panelEditor.PanelEditor)

Example 57 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class LogixActionTest method testLogixAction.

@Test
public void testLogixAction() throws Exception {
    jmri.configurexml.ConfigXmlManager cm = new jmri.configurexml.ConfigXmlManager() {
    };
    // load and display sample file. Panel file does not display screen
    java.io.File f = new java.io.File("java/test/jmri/jmrit/logix/valid/LogixActionTest.xml");
    cm.load(f);
    InstanceManager.getDefault(jmri.LogixManager.class).activateAllLogixs();
    Memory im6 = InstanceManager.memoryManagerInstance().getMemory("IM6");
    Assert.assertNotNull("Memory IM6", im6);
    Assert.assertEquals("Contents IM6", "EastToWestOnSiding", im6.getValue());
    /* Find Enable Logix button  <<< I'd like to use jfcunit but can't figure out the usage
         AbstractButtonFinder finder = new AbstractButtonFinder("Enable/Disable Tests" );
         JButton button = ( JButton ) finder.find();
         Assert.assertNotNull(button);   // Fails here after long wait. stack overflow?
         // Click button
         getHelper().enterClickAndLeave( new MouseEventData( this, button ) );
         */
    // OK, do it this way
    Sensor sensor = InstanceManager.sensorManagerInstance().getSensor("enableButton");
    Assert.assertNotNull("Sensor IS5", sensor);
    sensor.setState(Sensor.ACTIVE);
    sensor.setState(Sensor.INACTIVE);
    sensor.setState(Sensor.ACTIVE);
    SignalHead sh1 = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead("IH1");
    Assert.assertNotNull("shi null", sh1);
    Assert.assertEquals("SignalHead IH1", SignalHead.RED, sh1.getAppearance());
    // do some buttons -Sensors
    sensor = InstanceManager.sensorManagerInstance().getSensor("ISLITERAL");
    Assert.assertNotNull("sensor null", sensor);
    // activate direct logix action
    sensor.setState(Sensor.ACTIVE);
    Sensor is1 = InstanceManager.sensorManagerInstance().getSensor("sensor1");
    Assert.assertNotNull("is1 null", is1);
    // action
    Assert.assertEquals("direct set Sensor IS1 active", Sensor.ACTIVE, is1.getState());
    sensor = InstanceManager.sensorManagerInstance().getSensor("ISINDIRECT");
    Assert.assertNotNull("sensor null", sensor);
    // activate Indirect logix action
    sensor.setState(Sensor.ACTIVE);
    // action
    Assert.assertEquals("Indirect set Sensor IS1 inactive", Sensor.INACTIVE, is1.getState());
    // SignalHead buttons
    Sensor is4 = InstanceManager.sensorManagerInstance().getSensor("IS4");
    Assert.assertNotNull("is4 null", is4);
    // activate direct logix action
    is4.setState(Sensor.ACTIVE);
    Assert.assertEquals("direct set SignalHead IH1 to Green", SignalHead.GREEN, sh1.getAppearance());
    // activate direct logix action
    is4.setState(Sensor.INACTIVE);
    Assert.assertEquals("direct set SignalHead IH1 to Red", SignalHead.RED, sh1.getAppearance());
    Memory im3 = InstanceManager.memoryManagerInstance().getMemory("IM3");
    Assert.assertNotNull("Memory IM3", im3);
    Assert.assertEquals("Contents IM3", "IH1", im3.getValue());
    Sensor is3 = InstanceManager.sensorManagerInstance().getSensor("IS3");
    Assert.assertNotNull("is3 null", is3);
    // activate indirect logix action
    is3.setState(Sensor.ACTIVE);
    Assert.assertEquals("Indirect set SignalHead IH1 to Green", SignalHead.GREEN, sh1.getAppearance());
    // activate indirect logix action
    is3.setState(Sensor.INACTIVE);
    Assert.assertEquals("Indirect set SignalHead IH1 to Red", SignalHead.RED, sh1.getAppearance());
    // change memory value
    im3.setValue("IH2");
    // activate logix action
    is3.setState(Sensor.ACTIVE);
    Assert.assertEquals("Contents IM3", "IH2", im3.getValue());
    SignalHead sh2 = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead("IH2");
    Assert.assertNotNull("sh2 null", sh2);
    Assert.assertEquals("Indirect SignalHead IH2", SignalHead.GREEN, sh2.getAppearance());
    // Turnout Buttons
    Sensor is6 = InstanceManager.sensorManagerInstance().getSensor("IS6");
    Assert.assertNotNull("is6 null", is6);
    // activate direct logix action
    is6.setState(Sensor.ACTIVE);
    Turnout it2 = InstanceManager.turnoutManagerInstance().getTurnout("IT2");
    Assert.assertNotNull("it2 null", it2);
    Assert.assertEquals("direct set Turnout IT2 to Closed", Turnout.CLOSED, it2.getState());
    Memory im4 = InstanceManager.memoryManagerInstance().getMemory("IM4");
    Assert.assertNotNull("im4 null", im4);
    Assert.assertEquals("Contents IM4", "IT3", im4.getValue());
    Sensor is7 = InstanceManager.sensorManagerInstance().getSensor("IS7");
    Assert.assertNotNull("is7 null", is7);
    // activate indirect logix action
    is7.setState(Sensor.INACTIVE);
    Turnout it3 = InstanceManager.turnoutManagerInstance().getTurnout("IT3");
    Assert.assertNotNull("it3 null", it3);
    Assert.assertEquals("Indirect set Turnout IT2 to Thrown", Turnout.THROWN, it3.getState());
    // activate indirect logix action
    is7.setState(Sensor.ACTIVE);
    Assert.assertEquals("Indirect set Turnout IT2 to Closed", Turnout.CLOSED, it3.getState());
    // change memory value
    im4.setValue("IT2");
    Assert.assertEquals("Contents IM4", "IT2", im4.getValue());
    // activate indirect logix action
    is7.setState(Sensor.INACTIVE);
    Assert.assertEquals("Indirect set Turnout IT2 to Thrown", Turnout.THROWN, it2.getState());
    // activate indirect logix action
    is7.setState(Sensor.ACTIVE);
    Assert.assertEquals("Indirect set Turnout IT2 to Closed", Turnout.CLOSED, it2.getState());
    // OBlock Buttons
    OBlock ob1 = InstanceManager.getDefault(OBlockManager.class).getOBlock("Left");
    Assert.assertEquals("OBlock OB1", (OBlock.OUT_OF_SERVICE | Sensor.INACTIVE), ob1.getState());
    OBlock ob2 = InstanceManager.getDefault(OBlockManager.class).getOBlock("Right");
    Assert.assertEquals("OBlock OB2", (OBlock.TRACK_ERROR | Sensor.INACTIVE), ob2.getState());
    Sensor is8 = InstanceManager.sensorManagerInstance().getSensor("IS8");
    Assert.assertNotNull("is8 null", is8);
    // direct action
    is8.setState(Sensor.ACTIVE);
    Assert.assertEquals("Direct set OBlock OB1 to normal", Sensor.INACTIVE, ob1.getState());
    // direct action
    is8.setState(Sensor.INACTIVE);
    Assert.assertEquals("Direct set OBlock OB1 to OOS", (OBlock.OUT_OF_SERVICE | Sensor.INACTIVE), ob1.getState());
    Sensor is9 = InstanceManager.sensorManagerInstance().getSensor("IS9");
    Assert.assertNotNull("is9 null", is9);
    // indirect action
    is9.setState(Sensor.ACTIVE);
    Assert.assertEquals("Indirect set OBlock OB2 to normal", Sensor.INACTIVE, ob2.getState());
    // change memory value
    Memory im5 = InstanceManager.memoryManagerInstance().getMemory("IM5");
    Assert.assertNotNull("im5 null", im5);
    im5.setValue("OB1");
    // indirect action
    is9.setState(Sensor.INACTIVE);
    Assert.assertEquals("Indirect set OBlock OB1 to normal", (OBlock.TRACK_ERROR | OBlock.OUT_OF_SERVICE | Sensor.INACTIVE), ob1.getState());
    // indirect action
    is9.setState(Sensor.ACTIVE);
    // indirect action
    is8.setState(Sensor.ACTIVE);
    Assert.assertEquals("Direct set OBlock OB1 to normal", Sensor.INACTIVE, ob1.getState());
    // Warrant buttons
    Sensor is14 = InstanceManager.sensorManagerInstance().getSensor("IS14");
    Assert.assertNotNull("is14 null", is14);
    // indirect action
    is14.setState(Sensor.ACTIVE);
    Warrant w = InstanceManager.getDefault(WarrantManager.class).getWarrant("EastToWestOnSiding");
    Assert.assertTrue("warrant EastToWestOnSiding allocated", w.isAllocated());
    Sensor is15 = InstanceManager.sensorManagerInstance().getSensor("IS15");
    Assert.assertNotNull("is15 null", is15);
    // indirect action
    is15.setState(Sensor.ACTIVE);
    Assert.assertFalse("warrant EastToWestOnSiding deallocated", w.isAllocated());
    // change memory value
    im6.setValue("WestToEastOnMain");
    // toggle
    is14.setState(Sensor.INACTIVE);
    // indirect action
    is14.setState(Sensor.ACTIVE);
    Warrant w2 = InstanceManager.getDefault(WarrantManager.class).getWarrant("WestToEastOnMain");
    Assert.assertTrue("warrant WestToEastOnMain allocated", w2.isAllocated());
    im6.setValue("LeftToRightOnPath");
    // toggle
    is14.setState(Sensor.INACTIVE);
    // indirect action
    is14.setState(Sensor.ACTIVE);
    w = InstanceManager.getDefault(WarrantManager.class).getWarrant("LeftToRightOnPath");
    Assert.assertTrue("warrant LeftToRightOnPath allocated", w.isAllocated());
}
Also used : Memory(jmri.Memory) SignalHead(jmri.SignalHead) Turnout(jmri.Turnout) Sensor(jmri.Sensor) Test(org.junit.Test)

Example 58 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class PointDetails method getSensor.

Sensor getSensor() {
    if (getRefObject() == null) {
        return null;
    }
    if ((getPanel() != null) && (!getPanel().isEditable()) && (sensor != null)) {
        return sensor;
    }
    if (getRefObject() instanceof Sensor) {
        setSensor((Sensor) getRefObject());
        return (Sensor) getRefObject();
    }
    Object objLoc = getRefLocation();
    Object objRef = getRefObject();
    SignalHead head = null;
    SignalMast mast = null;
    String username = "";
    String systemname = "";
    Sensor foundSensor = null;
    if (objRef instanceof SignalMast) {
        mast = (SignalMast) objRef;
    }
    if (objRef instanceof SignalHead) {
        head = (SignalHead) objRef;
        username = head.getUserName();
        systemname = head.getSystemName();
    }
    jmri.SensorManager sm = InstanceManager.sensorManagerInstance();
    if (objLoc instanceof PositionablePoint) {
        PositionablePoint p = (PositionablePoint) objLoc;
        if (mast != null) {
            if (p.getEastBoundSignalMast() == objRef) {
                foundSensor = p.getEastBoundSensor();
            } else if (p.getWestBoundSignalMast() == objRef) {
                foundSensor = p.getWestBoundSensor();
            }
        } else if (head != null) {
            if ((p.getEastBoundSignal().equals(username)) || p.getEastBoundSignal().equals(systemname)) {
                foundSensor = p.getEastBoundSensor();
            } else if ((p.getWestBoundSignal().equals(username)) || p.getWestBoundSignal().equals(systemname)) {
                foundSensor = p.getWestBoundSensor();
            }
        }
    } else if (objLoc instanceof LayoutTurnout) {
        LayoutTurnout t = (LayoutTurnout) objLoc;
        if (mast != null) {
            if (t.getSignalAMast() == objRef) {
                foundSensor = t.getSensorA();
            } else if (t.getSignalBMast() == objRef) {
                foundSensor = t.getSensorB();
            } else if (t.getSignalCMast() == objRef) {
                foundSensor = t.getSensorC();
            } else if (t.getSignalDMast() == objRef) {
                foundSensor = t.getSensorD();
            }
        }
        if (head != null) {
            if ((t.getSignalA1Name().equals(username)) || (t.getSignalA1Name().equals(systemname))) {
                foundSensor = t.getSensorA();
            } else if ((t.getSignalA2Name().equals(username)) || (t.getSignalA2Name().equals(systemname))) {
                foundSensor = t.getSensorA();
            } else if ((t.getSignalA3Name().equals(username)) || (t.getSignalA3Name().equals(systemname))) {
                foundSensor = t.getSensorA();
            } else if ((t.getSignalB1Name().equals(username)) || (t.getSignalB1Name().equals(systemname))) {
                foundSensor = t.getSensorB();
            } else if ((t.getSignalB2Name().equals(username)) || (t.getSignalB2Name().equals(systemname))) {
                foundSensor = t.getSensorB();
            } else if ((t.getSignalC1Name().equals(username)) || (t.getSignalC1Name().equals(systemname))) {
                foundSensor = t.getSensorC();
            } else if ((t.getSignalC2Name().equals(username)) || (t.getSignalC2Name().equals(systemname))) {
                foundSensor = t.getSensorC();
            } else if ((t.getSignalD1Name().equals(username)) || (t.getSignalD1Name().equals(systemname))) {
                foundSensor = t.getSensorD();
            } else if ((t.getSignalD2Name().equals(username)) || (t.getSignalD2Name().equals(systemname))) {
                foundSensor = t.getSensorD();
            }
        }
    } else if (objLoc instanceof LevelXing) {
        LevelXing x = (LevelXing) objLoc;
        if (mast != null) {
            if (x.getSignalAMast() == objRef) {
                foundSensor = x.getSensorA();
            } else if (x.getSignalBMast() == objRef) {
                foundSensor = x.getSensorB();
            } else if (x.getSignalCMast() == objRef) {
                foundSensor = x.getSensorC();
            } else if (x.getSignalDMast() == objRef) {
                foundSensor = x.getSensorD();
            }
        }
        if (head != null) {
            if ((x.getSignalAName().equals(username)) || (x.getSignalAName().equals(systemname))) {
                foundSensor = x.getSensorA();
            } else if ((x.getSignalBName().equals(username)) || (x.getSignalBName().equals(systemname))) {
                foundSensor = x.getSensorB();
            } else if ((x.getSignalCName().equals(username)) || (x.getSignalCName().equals(systemname))) {
                foundSensor = x.getSensorC();
            } else if ((x.getSignalDName().equals(username)) || (x.getSignalDName().equals(systemname))) {
                foundSensor = x.getSensorD();
            }
        }
    } else if (objLoc instanceof LayoutSlip) {
        LayoutSlip sl = (LayoutSlip) objLoc;
        if (mast != null) {
            if (sl.getSignalAMast() == objRef) {
                foundSensor = sl.getSensorA();
            } else if (sl.getSignalBMast() == objRef) {
                foundSensor = sl.getSensorB();
            } else if (sl.getSignalCMast() == objRef) {
                foundSensor = sl.getSensorC();
            } else if (sl.getSignalDMast() == objRef) {
                foundSensor = sl.getSensorD();
            }
        }
        if (head != null) {
            if ((sl.getSignalA1Name().equals(username)) || (sl.getSignalA1Name().equals(systemname))) {
                foundSensor = sm.getSensor(sl.getSensorAName());
            } else if ((sl.getSignalB1Name().equals(username)) || (sl.getSignalB1Name().equals(systemname))) {
                foundSensor = sm.getSensor(sl.getSensorBName());
            } else if ((sl.getSignalC1Name().equals(username)) || (sl.getSignalC1Name().equals(systemname))) {
                foundSensor = sm.getSensor(sl.getSensorCName());
            } else if ((sl.getSignalD1Name().equals(username)) || (sl.getSignalD1Name().equals(systemname))) {
                foundSensor = sm.getSensor(sl.getSensorDName());
            }
        }
    }
    setSensor(foundSensor);
    return foundSensor;
}
Also used : LayoutSlip(jmri.jmrit.display.layoutEditor.LayoutSlip) LevelXing(jmri.jmrit.display.layoutEditor.LevelXing) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) SignalHead(jmri.SignalHead) SignalMast(jmri.SignalMast) PositionablePoint(jmri.jmrit.display.layoutEditor.PositionablePoint) Sensor(jmri.Sensor)

Example 59 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class SerialSignalHeadXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    String sys = shared.getAttribute("systemName").getValue();
    Attribute a = shared.getAttribute("userName");
    SignalHead h;
    if (a == null) {
        h = new SerialSignalHead(sys);
    } else {
        h = new SerialSignalHead(sys, a.getValue());
    }
    loadCommon(h, shared);
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
    return true;
}
Also used : Attribute(org.jdom2.Attribute) SerialSignalHead(jmri.jmrix.grapevine.SerialSignalHead) SignalHead(jmri.SignalHead) SerialSignalHead(jmri.jmrix.grapevine.SerialSignalHead)

Example 60 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class LayoutTurnout method setSignalB2Name.

public void setSignalB2Name(String signalHead) {
    if (signalHead == null || signalHead.equals("")) {
        signalB2HeadNamed = null;
        return;
    }
    SignalHead head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(signalHead);
    if (head != null) {
        signalB2HeadNamed = InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(signalHead, head);
    } else {
        signalB2HeadNamed = null;
        log.error("Signal Head " + signalHead + " Not found for turnout " + getTurnoutName());
    }
}
Also used : SignalHead(jmri.SignalHead)

Aggregations

SignalHead (jmri.SignalHead)73 Turnout (jmri.Turnout)20 Element (org.jdom2.Element)13 SignalMast (jmri.SignalMast)12 Sensor (jmri.Sensor)11 JsonException (jmri.server.json.JsonException)8 Test (org.junit.Test)7 NamedBean (jmri.NamedBean)6 DoubleTurnoutSignalHead (jmri.implementation.DoubleTurnoutSignalHead)6 QuadOutputSignalHead (jmri.implementation.QuadOutputSignalHead)6 SingleTurnoutSignalHead (jmri.implementation.SingleTurnoutSignalHead)6 TripleOutputSignalHead (jmri.implementation.TripleOutputSignalHead)6 TripleTurnoutSignalHead (jmri.implementation.TripleTurnoutSignalHead)6 SignalHeadManager (jmri.SignalHeadManager)5 DccSignalHead (jmri.implementation.DccSignalHead)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 JmriException (jmri.JmriException)4 Light (jmri.Light)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 ActionEvent (java.awt.event.ActionEvent)3