use of jmri.jmrix.rps.Measurement in project JMRI by JMRI.
the class RpsTrackingPanelTest 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(13., 13., 0.)));
JmriJFrame f = new JmriJFrame("Test Tracking Panel");
f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
RpsTrackingPanel p = new RpsTrackingPanel();
p.setSize(400, 400);
p.setOrigin(0, 0);
p.setCoordMax(30., 30.);
f.getContentPane().add(p);
f.pack();
// add some regions to probe corners
Region r = new Region("(4,4,0);(10,16,0);(18,10,0);(4,4,0)");
Model.instance().addRegion(r);
r = new Region("(30,15,0);(25,15,0);(25,20,0);(30,15,0)");
Model.instance().addRegion(r);
r = new Region("(15,30,0);(15,25,0);(20,25,0);(15,30,0)");
Model.instance().addRegion(r);
r = new Region("(25,25,0);(25,28,0);(30,30,1);(29,25,0);(25,25,0)");
Model.instance().addRegion(r);
// show overlap
r = new Region("(20,20,0);(22,20,0);(22,22,1);(20,22,0)");
Model.instance().addRegion(r);
r = new Region("(19,19,0);(21,19,0);(21,21,1);(19,21,0)");
Model.instance().addRegion(r);
// show panel
f.setSize(400, 400);
f.setVisible(true);
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);
// check separate locos
int NUM_LOCO = 64;
for (int i = 0; i < NUM_LOCO; i++) {
loco = new Reading("" + i, null);
m = new Measurement(loco, 6. + 1. * i, 0., 0.0, 0.133, 5, "source");
p.notify(m);
m = new Measurement(loco, 6. + 1. * i, 12., 0.0, 0.133, 5, "source");
p.notify(m);
}
Assert.assertNotNull("found frame", f);
f.dispose();
}
use of jmri.jmrix.rps.Measurement in project JMRI by JMRI.
the class DebuggerTest method testCtor.
@Test
public void testCtor() throws Exception {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
// create a context
Engine.instance().setMaxReceiverNumber(2);
Engine.instance().setReceiver(1, new Receiver(new Point3d(1, 2, 3)));
Engine.instance().setReceiver(2, new Receiver(new Point3d(1, 2, 3)));
Reading r = new Reading("21", new double[] { 11, 12, 13, 14 });
Measurement m = new Measurement(r, -0.5, 0.5, 0.0, 0.133, 3, "source");
// show frame
DebuggerFrame f = new DebuggerFrame();
f.initComponents();
f.setVisible(true);
// data
f.notify(r);
f.notify(m);
// close
f.dispose();
}
use of jmri.jmrix.rps.Measurement in project JMRI by JMRI.
the class RpsTrackingPanel method notify.
@Override
public void notify(Measurement m) {
String id = m.getID();
TransmitterStatus transmitter = transmitters.get(id);
double xend = m.getX();
double yend = m.getY();
if (log.isDebugEnabled()) {
log.debug("notify " + xend + "," + yend);
}
if (transmitter == null) {
// create Transmitter status with current measurement
// so we can draw line next time
log.debug("create new TransmitterStatus for " + m.getID());
transmitter = new TransmitterStatus();
transmitter.measurement = m;
transmitter.color = nextColor();
transmitters.put(id, transmitter);
// display just the point
MeasurementRep r = new MeasurementRep();
r.color = transmitter.color;
r.rep1 = new Ellipse2D.Double(xend - MEASUREMENT_ACCURACY / 2, yend - MEASUREMENT_ACCURACY / 2, MEASUREMENT_ACCURACY, MEASUREMENT_ACCURACY);
r.measurement = m;
measurementRepList.add(r);
pruneMeasurementRepList();
return;
}
Measurement lastMessage = transmitter.measurement;
MeasurementRep r = new MeasurementRep();
r.color = transmitter.color;
r.rep2 = new Ellipse2D.Double(xend - MEASUREMENT_ACCURACY / 2, yend - MEASUREMENT_ACCURACY / 2, MEASUREMENT_ACCURACY, MEASUREMENT_ACCURACY);
if (showErrors || (lastMessage.isOkPoint() && m.isOkPoint())) {
// also draw line
double xinit = lastMessage.getX();
double yinit = lastMessage.getY();
r.rep1 = new Line2D.Double(xinit, yinit, xend, yend);
r.measurement = m;
measurementRepList.add(r);
pruneMeasurementRepList();
// cause repaint of whole thing for now
repaint(getBounds());
}
// remember where now
transmitter.measurement = m;
}
use of jmri.jmrix.rps.Measurement in project JMRI by JMRI.
the class RpsPositionIconTest method measButtonPushed.
// animate the visible frame
public void measButtonPushed(double x, double y, RpsPositionIcon rpsIcon) {
Reading loco = new Reading(id, null);
Measurement m = new Measurement(loco, x, y, 0.0, 0.133, 0, "source");
rpsIcon.notify(m);
}
use of jmri.jmrix.rps.Measurement in project JMRI by JMRI.
the class DebuggerFrame method doLoadMeasurementFromFile.
void doLoadMeasurementFromFile() throws java.io.IOException {
if (measurementInput == null) {
setupMeasurementFile();
}
// get and load a line
if (!measurementInput.readRecord()) {
// read failed, try once to get another file
setupMeasurementFile();
if (!measurementInput.readRecord()) {
throw new java.io.IOException("no valid file");
}
}
// item 0 is the ID, not used right now
Measurement m = new Measurement(null, Double.valueOf(measurementInput.get(1)).doubleValue(), Double.valueOf(measurementInput.get(2)).doubleValue(), Double.valueOf(measurementInput.get(3)).doubleValue(), Engine.instance().getVSound(), 0, "Data File");
lastPoint = m;
Distributor.instance().submitMeasurement(m);
}
Aggregations