[cooja] plugins/skins: Adapted DGRM and UDGM visualizer skins to show
adequate information for multi-selections
This commit is contained in:
parent
ac61c45950
commit
e69b08f5fd
|
@ -83,15 +83,13 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
|
||||||
|
|
||||||
public void paintBeforeMotes(Graphics g) {
|
public void paintBeforeMotes(Graphics g) {
|
||||||
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
|
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
|
||||||
if (simulation == null
|
if (simulation == null || selectedMotes == null) {
|
||||||
|| selectedMotes == null
|
|
||||||
|| selectedMotes.isEmpty()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Mote selectedMote = visualizer.getSelectedMotes().iterator().next();
|
for (final Mote selectedMote : selectedMotes) {
|
||||||
if (selectedMote.getInterfaces().getRadio() == null) {
|
if (selectedMote.getInterfaces().getRadio() == null) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Paint transmission and interference range for selected mote */
|
/* Paint transmission and interference range for selected mote */
|
||||||
|
@ -114,12 +112,13 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
|
||||||
int msgWidth = fm.stringWidth(msg);
|
int msgWidth = fm.stringWidth(msg);
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.drawString(msg, x - msgWidth / 2, y + 2 * Visualizer.MOTE_RADIUS + 3);
|
g.drawString(msg, x - msgWidth / 2, y + 2 * Visualizer.MOTE_RADIUS + 3);
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
String msg = dests.length + " edges";
|
String msg = dests.length + " edges";
|
||||||
int msgWidth = fm.stringWidth(msg);
|
int msgWidth = fm.stringWidth(msg);
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.drawString(msg, x - msgWidth / 2, y + 2 * Visualizer.MOTE_RADIUS + 3);
|
g.drawString(msg, x - msgWidth / 2, y + 2 * Visualizer.MOTE_RADIUS + 3);
|
||||||
|
/* Draw LQI/RSSI edges */
|
||||||
for (DestinationRadio r : dests) {
|
for (DestinationRadio r : dests) {
|
||||||
double prob = ((DGRMDestinationRadio)r).ratio;
|
double prob = ((DGRMDestinationRadio)r).ratio;
|
||||||
double rssi = ((DGRMDestinationRadio)r).signal;
|
double rssi = ((DGRMDestinationRadio)r).signal;
|
||||||
|
@ -134,17 +133,22 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
|
||||||
if (prob == 0.0d) {
|
if (prob == 0.0d) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
msg = String.format("%1.1f%%", 100.0*prob);
|
|
||||||
Position pos = r.radio.getPosition();
|
Position pos = r.radio.getPosition();
|
||||||
Point pixel = visualizer.transformPositionToPixel(pos);
|
Point pixel = visualizer.transformPositionToPixel(pos);
|
||||||
msgWidth = fm.stringWidth(msg);
|
|
||||||
g.setColor(new Color(red, green, 0.0f));
|
g.setColor(new Color(red, green, 0.0f));
|
||||||
g.drawString("LQI: " + lqi + " RSSI: " + rssi,(x + pixel.x)/2,(y + pixel.y)/2);
|
g.drawString("LQI: " + lqi, (x + pixel.x) / 2, (y + pixel.y) / 2);
|
||||||
|
g.drawString("RSSI: " + rssi, (x + pixel.x) / 2, (y + pixel.y) / 2 + g.getFontMetrics().getHeight());
|
||||||
g.drawLine(x, y, pixel.x, pixel.y);
|
g.drawLine(x, y, pixel.x, pixel.y);
|
||||||
|
/* Draw success ratio only if single mote selected */
|
||||||
|
if (selectedMotes.size() == 1) {
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
|
msg = String.format("%1.1f%%", 100.0 * prob);
|
||||||
|
msgWidth = fm.stringWidth(msg);
|
||||||
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
|
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void paintAfterMotes(Graphics g) {
|
public void paintAfterMotes(Graphics g) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,10 @@ import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.geom.Area;
|
||||||
|
import java.awt.geom.Ellipse2D;
|
||||||
import java.beans.PropertyVetoException;
|
import java.beans.PropertyVetoException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -269,15 +272,18 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
@Override
|
@Override
|
||||||
public void paintBeforeMotes(Graphics g) {
|
public void paintBeforeMotes(Graphics g) {
|
||||||
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
|
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
|
||||||
if (simulation == null
|
if (simulation == null || selectedMotes == null) {
|
||||||
|| selectedMotes == null
|
|
||||||
|| selectedMotes.isEmpty()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Mote selectedMote = visualizer.getSelectedMotes().iterator().next();
|
Area intRangeArea = new Area();
|
||||||
|
Area intRangeMaxArea = new Area();
|
||||||
|
Area trxRangeArea = new Area();
|
||||||
|
Area trxRangeMaxArea = new Area();
|
||||||
|
|
||||||
|
for (Mote selectedMote : selectedMotes) {
|
||||||
if (selectedMote.getInterfaces().getRadio() == null) {
|
if (selectedMote.getInterfaces().getRadio() == null) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Paint transmission and interference range for selected mote */
|
/* Paint transmission and interference range for selected mote */
|
||||||
|
@ -289,24 +295,24 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
|
|
||||||
// Fetch current output power indicator (scale with as percent)
|
// Fetch current output power indicator (scale with as percent)
|
||||||
Radio selectedRadio = selectedMote.getInterfaces().getRadio();
|
Radio selectedRadio = selectedMote.getInterfaces().getRadio();
|
||||||
double moteInterferenceRange =
|
double moteInterferenceRange
|
||||||
radioMedium.INTERFERENCE_RANGE
|
= radioMedium.INTERFERENCE_RANGE
|
||||||
* ((double) selectedRadio.getCurrentOutputPowerIndicator()
|
* ((double) selectedRadio.getCurrentOutputPowerIndicator()
|
||||||
/ (double) selectedRadio.getOutputPowerIndicatorMax());
|
/ (double) selectedRadio.getOutputPowerIndicatorMax());
|
||||||
double moteTransmissionRange =
|
double moteTransmissionRange
|
||||||
radioMedium.TRANSMITTING_RANGE
|
= radioMedium.TRANSMITTING_RANGE
|
||||||
* ((double) selectedRadio.getCurrentOutputPowerIndicator()
|
* ((double) selectedRadio.getCurrentOutputPowerIndicator()
|
||||||
/ (double) selectedRadio.getOutputPowerIndicatorMax());
|
/ (double) selectedRadio.getOutputPowerIndicatorMax());
|
||||||
|
|
||||||
Point translatedZero = visualizer.transformPositionToPixel(0.0, 0.0, 0.0);
|
Point translatedZero = visualizer.transformPositionToPixel(0.0, 0.0, 0.0);
|
||||||
Point translatedInterference =
|
Point translatedInterference
|
||||||
visualizer.transformPositionToPixel(moteInterferenceRange, moteInterferenceRange, 0.0);
|
= visualizer.transformPositionToPixel(moteInterferenceRange, moteInterferenceRange, 0.0);
|
||||||
Point translatedTransmission =
|
Point translatedTransmission
|
||||||
visualizer.transformPositionToPixel(moteTransmissionRange, moteTransmissionRange, 0.0);
|
= visualizer.transformPositionToPixel(moteTransmissionRange, moteTransmissionRange, 0.0);
|
||||||
Point translatedInterferenceMax =
|
Point translatedInterferenceMax
|
||||||
visualizer.transformPositionToPixel(radioMedium.INTERFERENCE_RANGE, radioMedium.INTERFERENCE_RANGE, 0.0);
|
= visualizer.transformPositionToPixel(radioMedium.INTERFERENCE_RANGE, radioMedium.INTERFERENCE_RANGE, 0.0);
|
||||||
Point translatedTransmissionMax =
|
Point translatedTransmissionMax
|
||||||
visualizer.transformPositionToPixel(radioMedium.TRANSMITTING_RANGE, radioMedium.TRANSMITTING_RANGE, 0.0);
|
= visualizer.transformPositionToPixel(radioMedium.TRANSMITTING_RANGE, radioMedium.TRANSMITTING_RANGE, 0.0);
|
||||||
|
|
||||||
translatedInterference.x = Math.abs(translatedInterference.x - translatedZero.x);
|
translatedInterference.x = Math.abs(translatedInterference.x - translatedZero.x);
|
||||||
translatedInterference.y = Math.abs(translatedInterference.y - translatedZero.y);
|
translatedInterference.y = Math.abs(translatedInterference.y - translatedZero.y);
|
||||||
|
@ -318,41 +324,53 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
translatedTransmissionMax.y = Math.abs(translatedTransmissionMax.y - translatedZero.y);
|
translatedTransmissionMax.y = Math.abs(translatedTransmissionMax.y - translatedZero.y);
|
||||||
|
|
||||||
/* Interference range */
|
/* Interference range */
|
||||||
g.setColor(COLOR_INT);
|
intRangeArea.add(new Area(new Ellipse2D.Double(
|
||||||
g.fillOval(
|
|
||||||
x - translatedInterference.x,
|
x - translatedInterference.x,
|
||||||
y - translatedInterference.y,
|
y - translatedInterference.y,
|
||||||
2 * translatedInterference.x,
|
2 * translatedInterference.x,
|
||||||
2 * translatedInterference.y);
|
2 * translatedInterference.y)));
|
||||||
|
|
||||||
/* Transmission range */
|
/* Interference range (MAX) */
|
||||||
g.setColor(COLOR_TX);
|
trxRangeArea.add(new Area(new Ellipse2D.Double(
|
||||||
g.fillOval(
|
|
||||||
x - translatedTransmission.x,
|
x - translatedTransmission.x,
|
||||||
y - translatedTransmission.y,
|
y - translatedTransmission.y,
|
||||||
2 * translatedTransmission.x,
|
2 * translatedTransmission.x,
|
||||||
2 * translatedTransmission.y);
|
2 * translatedTransmission.y)));
|
||||||
|
|
||||||
/* Interference range (MAX) */
|
intRangeMaxArea.add(new Area(new Ellipse2D.Double(
|
||||||
g.setColor(Color.GRAY);
|
|
||||||
g.drawOval(
|
|
||||||
x - translatedInterferenceMax.x,
|
x - translatedInterferenceMax.x,
|
||||||
y - translatedInterferenceMax.y,
|
y - translatedInterferenceMax.y,
|
||||||
2 * translatedInterferenceMax.x,
|
2 * translatedInterferenceMax.x,
|
||||||
2 * translatedInterferenceMax.y);
|
2 * translatedInterferenceMax.y)));
|
||||||
|
|
||||||
/* Transmission range (MAX) */
|
/* Transmission range (MAX) */
|
||||||
g.drawOval(
|
trxRangeMaxArea.add(new Area(new Ellipse2D.Double(
|
||||||
x - translatedTransmissionMax.x,
|
x - translatedTransmissionMax.x,
|
||||||
y - translatedTransmissionMax.y,
|
y - translatedTransmissionMax.y,
|
||||||
2 * translatedTransmissionMax.x,
|
2 * translatedTransmissionMax.x,
|
||||||
2 * translatedTransmissionMax.y);
|
2 * translatedTransmissionMax.y)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
g2d.setColor(COLOR_INT);
|
||||||
|
g2d.fill(intRangeArea);
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g2d.draw(intRangeMaxArea);
|
||||||
|
|
||||||
|
g.setColor(COLOR_TX);
|
||||||
|
g2d.fill(trxRangeArea);
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g2d.draw(trxRangeMaxArea);
|
||||||
|
|
||||||
FontMetrics fm = g.getFontMetrics();
|
FontMetrics fm = g.getFontMetrics();
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
|
|
||||||
/* Print transmission success probabilities */
|
/* Print transmission success probabilities only if single mote is selected */
|
||||||
|
if (selectedMotes.size() == 1) {
|
||||||
|
Mote selectedMote = selectedMotes.toArray(new Mote[0])[0];
|
||||||
|
Radio selectedRadio = selectedMote.getInterfaces().getRadio();
|
||||||
for (Mote m: simulation.getMotes()) {
|
for (Mote m: simulation.getMotes()) {
|
||||||
if (m == selectedMote) {
|
if (m == selectedMote) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -368,6 +386,7 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
int msgWidth = fm.stringWidth(msg);
|
int msgWidth = fm.stringWidth(msg);
|
||||||
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
|
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue