Search in sources :

Example 6 with Measurement

use of jmri.jmrix.rps.Measurement in project JMRI by JMRI.

the class DebuggerFrame method doMeasurementFromPositionFields.

void doMeasurementFromPositionFields() {
    // contain dummy Reading
    Reading r = new Reading(id.getText(), new double[] { 0., 0., 0., 0. });
    Measurement m = new Measurement(r, Double.valueOf(x.getText()).doubleValue(), Double.valueOf(y.getText()).doubleValue(), Double.valueOf(z.getText()).doubleValue(), Engine.instance().getVSound(), 0, "Position Data");
    lastPoint = m;
    Distributor.instance().submitMeasurement(m);
}
Also used : Measurement(jmri.jmrix.rps.Measurement) Reading(jmri.jmrix.rps.Reading)

Example 7 with Measurement

use of jmri.jmrix.rps.Measurement in project JMRI by JMRI.

the class RpsTrackingPanel method getToolTipText.

/**
     * Provide tool tip text that depends on what's under the cursor.
     * <p>
     * Names either a measurement point or a region.
     *
     * @return null if no object under mouse; this suppresses ToolTip
     */
@Override
public String getToolTipText(MouseEvent e) {
    // get mouse coordinates
    try {
        Point mouse = e.getPoint();
        Point2D userPt = currentAT.inverseTransform(new Point2D.Double(mouse.x, mouse.y), null);
        // find the path object containing it, if any
        for (int i = measurementRepList.size() - 1; i >= 0; i--) {
            MeasurementRep r = measurementRepList.get(i);
            if (r.contains(userPt)) {
                Measurement m = r.measurement;
                return "ID " + m.getID() + " at " + m.getX() + "," + m.getY();
            }
        }
        // find the region containing it, if any
        // Go through backwards to find the top if overlaps
        List<Region> l = Model.instance().getRegions();
        for (int i = l.size() - 1; i >= 0; i--) {
            Shape s = l.get(i).getPath();
            if (s.contains(userPt)) {
                return "Region: " + l.get(i).toString() + ", at " + userPt.getX() + "," + userPt.getY();
            }
        }
        // found nothing, just display location
        return "" + userPt.getX() + "," + userPt.getY();
    } catch (Exception ex) {
    }
    // or return default
    return null;
}
Also used : Measurement(jmri.jmrix.rps.Measurement) Shape(java.awt.Shape) Point2D(java.awt.geom.Point2D) Region(jmri.jmrix.rps.Region) Point(java.awt.Point) Point(java.awt.Point)

Example 8 with Measurement

use of jmri.jmrix.rps.Measurement in project JMRI by JMRI.

the class PollDataModel method getValueAt.

@Override
public Object getValueAt(int r, int c) {
    // r is row number, from 0
    Measurement m;
    if (Engine.instance() == null) {
        log.warn("returning null because of missing Engine.instance()");
    }
    if (Engine.instance().getTransmitter(r) == null) {
        log.warn("returning null because of missing Engine.instance().getTransmitter(" + r + ")");
    }
    double val;
    switch(c) {
        case NAMECOL:
            return Engine.instance().getTransmitter(r).getRosterName();
        case IDCOL:
            return Engine.instance().getTransmitter(r).getID();
        case ADDRCOL:
            return Integer.valueOf(Engine.instance().getTransmitter(r).getAddress());
        case LONGCOL:
            return Boolean.valueOf(Engine.instance().getTransmitter(r).isLongAddress());
        case POLLCOL:
            return Boolean.valueOf(Engine.instance().getTransmitter(r).isPolled());
        case TYPECOL:
            JComboBox<String> b = new JComboBox<String>(new String[] { "F2", "F3", "BSCI" });
            return b;
        case LASTXCOL:
            m = Engine.instance().getTransmitter(r).getLastMeasurement();
            if (m == null) {
                return null;
            }
            val = m.getX();
            return new Double(val);
        case LASTYCOL:
            m = Engine.instance().getTransmitter(r).getLastMeasurement();
            if (m == null) {
                return null;
            }
            val = m.getY();
            return new Double(val);
        case LASTZCOL:
            m = Engine.instance().getTransmitter(r).getLastMeasurement();
            if (m == null) {
                return null;
            }
            val = m.getZ();
            return new Double(val);
        case LASTTIME:
            m = Engine.instance().getTransmitter(r).getLastMeasurement();
            if (m == null) {
                return null;
            }
            int time = m.getReading().getTime();
            return Integer.valueOf(time);
        default:
            return null;
    }
}
Also used : Measurement(jmri.jmrix.rps.Measurement) JComboBox(javax.swing.JComboBox)

Example 9 with Measurement

use of jmri.jmrix.rps.Measurement in project JMRI by JMRI.

the class RpsTrackingFrameTest method testShow.

@Test
public void testShow() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    new Engine() {

        void reset() {
            _instance = null;
        }
    }.reset();
    Engine.instance().setMaxReceiverNumber(2);
    Engine.instance().setReceiver(1, new Receiver(new Point3d(12., 12., 0.)));
    Engine.instance().setReceiver(2, new Receiver(new Point3d(12., 12., 0.)));
    RpsTrackingFrame f = new RpsTrackingFrame("Test RPS Tracking");
    f.initComponents();
    f.setVisible(true);
    // use local access
    RpsTrackingPanel p = f.panel;
    Reading loco = new Reading("21", null);
    Measurement m = new Measurement(loco, 0.0, 0.0, 0.0, 0.133, 5, "source");
    p.notify(m);
    loco = new Reading("21", null);
    m = new Measurement(loco, 5., 5., 0.0, 0.133, 5, "source");
    p.notify(m);
    loco = new Reading("21", null);
    m = new Measurement(loco, 0., 5., 0.0, 0.133, 5, "source");
    p.notify(m);
    loco = new Reading("21", null);
    m = new Measurement(loco, 5., 0., 0.0, 0.133, 5, "source");
    p.notify(m);
    Assert.assertNotNull("found frame", f);
    f.dispose();
}
Also used : Measurement(jmri.jmrix.rps.Measurement) Reading(jmri.jmrix.rps.Reading) Point3d(javax.vecmath.Point3d) Receiver(jmri.jmrix.rps.Receiver) Engine(jmri.jmrix.rps.Engine) Test(org.junit.Test)

Aggregations

Measurement (jmri.jmrix.rps.Measurement)9 Reading (jmri.jmrix.rps.Reading)5 Point3d (javax.vecmath.Point3d)3 Receiver (jmri.jmrix.rps.Receiver)3 Test (org.junit.Test)3 Engine (jmri.jmrix.rps.Engine)2 Region (jmri.jmrix.rps.Region)2 Point (java.awt.Point)1 Shape (java.awt.Shape)1 Ellipse2D (java.awt.geom.Ellipse2D)1 Line2D (java.awt.geom.Line2D)1 Point2D (java.awt.geom.Point2D)1 BoxLayout (javax.swing.BoxLayout)1 JComboBox (javax.swing.JComboBox)1 JmriJFrame (jmri.util.JmriJFrame)1