use of jmri.jmrix.rps.Receiver 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.Receiver 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.Receiver in project JMRI by JMRI.
the class RpsTrackingPanel method paint.
@Override
public void paint(Graphics g) {
// draw everything else
super.paint(g);
log.debug("paint invoked");
// Now show regions
// First, Graphics2D setup
Graphics2D g2 = (Graphics2D) g;
double xscale = this.getWidth() / (xmax - xorigin);
double yscale = this.getHeight() / (ymax - yorigin);
Stroke stroke = new BasicStroke((float) (2. / xscale), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
g2.setStroke(stroke);
// Save the current transform
AffineTransform saveAT = g2.getTransform();
// Install the new one
currentAT = new AffineTransform();
currentAT.translate(0, this.getHeight());
currentAT.scale(xscale, -yscale);
// put origin in bottom corner
currentAT.translate(-xorigin, -yorigin);
g2.setTransform(currentAT);
if (showRegions) {
// Draw the regions
List<Region> l = Model.instance().getRegions();
for (int i = 0; i < l.size(); i++) {
g2.setPaint(regionOutlineColor);
// border (same color)
g2.draw(l.get(i).getPath());
g2.setPaint(regionFillColor);
g2.fill(l.get(i).getPath());
}
}
// Draw the measurements; changes graphics
for (int i = 0; i < measurementRepList.size(); i++) {
measurementRepList.get(i).draw(g2);
}
if (showReceivers) {
// draw receivers
for (int i = 1; i < Engine.instance().getMaxReceiverNumber() + 1; i++) {
// indexed from 1
Receiver r = Engine.instance().getReceiver(i);
Point3d p = Engine.instance().getReceiverPosition(i);
if (p != null && r != null) {
if (r.isActive()) {
g2.setPaint(Color.BLACK);
} else {
g2.setPaint(Color.GRAY);
}
Shape s = new Ellipse2D.Double(p.x - RECEIVER_SIZE / 2, p.y - RECEIVER_SIZE / 2, RECEIVER_SIZE, RECEIVER_SIZE);
g2.draw(s);
g2.fill(s);
}
}
}
// restore original transform
g2.setTransform(saveAT);
}
use of jmri.jmrix.rps.Receiver 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();
}
Aggregations