[cooja] plugins/skins: Adapted DGRM and UDGM visualizer skins to show

adequate information for multi-selections
This commit is contained in:
Enrico Joerns 2014-04-10 18:32:23 +02:00
parent ac61c45950
commit e69b08f5fd
2 changed files with 166 additions and 143 deletions

View file

@ -83,66 +83,70 @@ 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;
}
/* Paint transmission and interference range for selected mote */
Position motePos = selectedMote.getInterfaces().getPosition();
Point pixelCoord = visualizer.transformPositionToPixel(motePos);
int x = pixelCoord.x;
int y = pixelCoord.y;
Radio selectedRadio = selectedMote.getInterfaces().getRadio();
FontMetrics fm = g.getFontMetrics();
g.setColor(Color.BLACK);
DirectedGraphMedium radioMedium = (DirectedGraphMedium) simulation.getRadioMedium();
/* Print transmission success probabilities */
DestinationRadio[] dests = radioMedium.getPotentialDestinations(selectedRadio);
if (dests == null || dests.length == 0) {
String msg = "No edges";
int msgWidth = fm.stringWidth(msg);
g.setColor(Color.BLACK);
g.drawString(msg, x - msgWidth/2, y + 2*Visualizer.MOTE_RADIUS + 3);
return;
}
String msg = dests.length + " edges";
int msgWidth = fm.stringWidth(msg);
g.setColor(Color.BLACK);
g.drawString(msg, x - msgWidth/2, y + 2*Visualizer.MOTE_RADIUS + 3);
for (DestinationRadio r: dests) {
double prob = ((DGRMDestinationRadio)r).ratio;
double rssi = ((DGRMDestinationRadio)r).signal;
double pos_rssi = rssi + 100;
int lqi = ((DGRMDestinationRadio)r).lqi;
float red = (float)(1 - prob*pos_rssi/90*lqi/100);
if(red > 1) red = 1;
if(red < 0) red = 0;
float green = (float)(prob*pos_rssi/90*lqi/100);
if(green > 1) green = 1;
if(green < 0) green = 0;
if (prob == 0.0d) {
continue; continue;
} }
msg = String.format("%1.1f%%", 100.0*prob);
Position pos = r.radio.getPosition(); /* Paint transmission and interference range for selected mote */
Point pixel = visualizer.transformPositionToPixel(pos); Position motePos = selectedMote.getInterfaces().getPosition();
msgWidth = fm.stringWidth(msg);
g.setColor(new Color(red, green, 0.0f)); Point pixelCoord = visualizer.transformPositionToPixel(motePos);
g.drawString("LQI: " + lqi + " RSSI: " + rssi,(x + pixel.x)/2,(y + pixel.y)/2); int x = pixelCoord.x;
g.drawLine(x, y, pixel.x, pixel.y); int y = pixelCoord.y;
Radio selectedRadio = selectedMote.getInterfaces().getRadio();
FontMetrics fm = g.getFontMetrics();
g.setColor(Color.BLACK); g.setColor(Color.BLACK);
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
DirectedGraphMedium radioMedium = (DirectedGraphMedium) simulation.getRadioMedium();
/* Print transmission success probabilities */
DestinationRadio[] dests = radioMedium.getPotentialDestinations(selectedRadio);
if (dests == null || dests.length == 0) {
String msg = "No edges";
int msgWidth = fm.stringWidth(msg);
g.setColor(Color.BLACK);
g.drawString(msg, x - msgWidth / 2, y + 2 * Visualizer.MOTE_RADIUS + 3);
continue;
}
String msg = dests.length + " edges";
int msgWidth = fm.stringWidth(msg);
g.setColor(Color.BLACK);
g.drawString(msg, x - msgWidth / 2, y + 2 * Visualizer.MOTE_RADIUS + 3);
/* Draw LQI/RSSI edges */
for (DestinationRadio r : dests) {
double prob = ((DGRMDestinationRadio)r).ratio;
double rssi = ((DGRMDestinationRadio)r).signal;
double pos_rssi = rssi + 100;
int lqi = ((DGRMDestinationRadio)r).lqi;
float red = (float)(1 - prob*pos_rssi/90*lqi/100);
if(red > 1) red = 1;
if(red < 0) red = 0;
float green = (float)(prob*pos_rssi/90*lqi/100);
if(green > 1) green = 1;
if(green < 0) green = 0;
if (prob == 0.0d) {
continue;
}
Position pos = r.radio.getPosition();
Point pixel = visualizer.transformPositionToPixel(pos);
g.setColor(new Color(red, green, 0.0f));
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);
/* Draw success ratio only if single mote selected */
if (selectedMotes.size() == 1) {
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);
}
}
} }
} }

View file

@ -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,104 +272,120 @@ 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();
if (selectedMote.getInterfaces().getRadio() == null) { Area intRangeMaxArea = new Area();
return; Area trxRangeArea = new Area();
Area trxRangeMaxArea = new Area();
for (Mote selectedMote : selectedMotes) {
if (selectedMote.getInterfaces().getRadio() == null) {
continue;
}
/* Paint transmission and interference range for selected mote */
Position motePos = selectedMote.getInterfaces().getPosition();
Point pixelCoord = visualizer.transformPositionToPixel(motePos);
int x = pixelCoord.x;
int y = pixelCoord.y;
// Fetch current output power indicator (scale with as percent)
Radio selectedRadio = selectedMote.getInterfaces().getRadio();
double moteInterferenceRange
= radioMedium.INTERFERENCE_RANGE
* ((double) selectedRadio.getCurrentOutputPowerIndicator()
/ (double) selectedRadio.getOutputPowerIndicatorMax());
double moteTransmissionRange
= radioMedium.TRANSMITTING_RANGE
* ((double) selectedRadio.getCurrentOutputPowerIndicator()
/ (double) selectedRadio.getOutputPowerIndicatorMax());
Point translatedZero = visualizer.transformPositionToPixel(0.0, 0.0, 0.0);
Point translatedInterference
= visualizer.transformPositionToPixel(moteInterferenceRange, moteInterferenceRange, 0.0);
Point translatedTransmission
= visualizer.transformPositionToPixel(moteTransmissionRange, moteTransmissionRange, 0.0);
Point translatedInterferenceMax
= visualizer.transformPositionToPixel(radioMedium.INTERFERENCE_RANGE, radioMedium.INTERFERENCE_RANGE, 0.0);
Point translatedTransmissionMax
= visualizer.transformPositionToPixel(radioMedium.TRANSMITTING_RANGE, radioMedium.TRANSMITTING_RANGE, 0.0);
translatedInterference.x = Math.abs(translatedInterference.x - translatedZero.x);
translatedInterference.y = Math.abs(translatedInterference.y - translatedZero.y);
translatedTransmission.x = Math.abs(translatedTransmission.x - translatedZero.x);
translatedTransmission.y = Math.abs(translatedTransmission.y - translatedZero.y);
translatedInterferenceMax.x = Math.abs(translatedInterferenceMax.x - translatedZero.x);
translatedInterferenceMax.y = Math.abs(translatedInterferenceMax.y - translatedZero.y);
translatedTransmissionMax.x = Math.abs(translatedTransmissionMax.x - translatedZero.x);
translatedTransmissionMax.y = Math.abs(translatedTransmissionMax.y - translatedZero.y);
/* Interference range */
intRangeArea.add(new Area(new Ellipse2D.Double(
x - translatedInterference.x,
y - translatedInterference.y,
2 * translatedInterference.x,
2 * translatedInterference.y)));
/* Interference range (MAX) */
trxRangeArea.add(new Area(new Ellipse2D.Double(
x - translatedTransmission.x,
y - translatedTransmission.y,
2 * translatedTransmission.x,
2 * translatedTransmission.y)));
intRangeMaxArea.add(new Area(new Ellipse2D.Double(
x - translatedInterferenceMax.x,
y - translatedInterferenceMax.y,
2 * translatedInterferenceMax.x,
2 * translatedInterferenceMax.y)));
/* Transmission range (MAX) */
trxRangeMaxArea.add(new Area(new Ellipse2D.Double(
x - translatedTransmissionMax.x,
y - translatedTransmissionMax.y,
2 * translatedTransmissionMax.x,
2 * translatedTransmissionMax.y)));
} }
/* Paint transmission and interference range for selected mote */ Graphics2D g2d = (Graphics2D) g;
Position motePos = selectedMote.getInterfaces().getPosition();
g2d.setColor(COLOR_INT);
Point pixelCoord = visualizer.transformPositionToPixel(motePos); g2d.fill(intRangeArea);
int x = pixelCoord.x;
int y = pixelCoord.y;
// Fetch current output power indicator (scale with as percent)
Radio selectedRadio = selectedMote.getInterfaces().getRadio();
double moteInterferenceRange =
radioMedium.INTERFERENCE_RANGE
* ((double) selectedRadio.getCurrentOutputPowerIndicator()
/ (double) selectedRadio.getOutputPowerIndicatorMax());
double moteTransmissionRange =
radioMedium.TRANSMITTING_RANGE
* ((double) selectedRadio.getCurrentOutputPowerIndicator()
/ (double) selectedRadio.getOutputPowerIndicatorMax());
Point translatedZero = visualizer.transformPositionToPixel(0.0, 0.0, 0.0);
Point translatedInterference =
visualizer.transformPositionToPixel(moteInterferenceRange, moteInterferenceRange, 0.0);
Point translatedTransmission =
visualizer.transformPositionToPixel(moteTransmissionRange, moteTransmissionRange, 0.0);
Point translatedInterferenceMax =
visualizer.transformPositionToPixel(radioMedium.INTERFERENCE_RANGE, radioMedium.INTERFERENCE_RANGE, 0.0);
Point translatedTransmissionMax =
visualizer.transformPositionToPixel(radioMedium.TRANSMITTING_RANGE, radioMedium.TRANSMITTING_RANGE, 0.0);
translatedInterference.x = Math.abs(translatedInterference.x - translatedZero.x);
translatedInterference.y = Math.abs(translatedInterference.y - translatedZero.y);
translatedTransmission.x = Math.abs(translatedTransmission.x - translatedZero.x);
translatedTransmission.y = Math.abs(translatedTransmission.y - translatedZero.y);
translatedInterferenceMax.x = Math.abs(translatedInterferenceMax.x - translatedZero.x);
translatedInterferenceMax.y = Math.abs(translatedInterferenceMax.y - translatedZero.y);
translatedTransmissionMax.x = Math.abs(translatedTransmissionMax.x - translatedZero.x);
translatedTransmissionMax.y = Math.abs(translatedTransmissionMax.y - translatedZero.y);
/* Interference range */
g.setColor(COLOR_INT);
g.fillOval(
x - translatedInterference.x,
y - translatedInterference.y,
2 * translatedInterference.x,
2 * translatedInterference.y);
/* Transmission range */
g.setColor(COLOR_TX);
g.fillOval(
x - translatedTransmission.x,
y - translatedTransmission.y,
2 * translatedTransmission.x,
2 * translatedTransmission.y);
/* Interference range (MAX) */
g.setColor(Color.GRAY); g.setColor(Color.GRAY);
g.drawOval( g2d.draw(intRangeMaxArea);
x - translatedInterferenceMax.x,
y - translatedInterferenceMax.y, g.setColor(COLOR_TX);
2 * translatedInterferenceMax.x, g2d.fill(trxRangeArea);
2 * translatedInterferenceMax.y); g.setColor(Color.GRAY);
g2d.draw(trxRangeMaxArea);
/* Transmission range (MAX) */
g.drawOval(
x - translatedTransmissionMax.x,
y - translatedTransmissionMax.y,
2 * translatedTransmissionMax.x,
2 * translatedTransmissionMax.y);
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 */
for (Mote m: simulation.getMotes()) { if (selectedMotes.size() == 1) {
if (m == selectedMote) { Mote selectedMote = selectedMotes.toArray(new Mote[0])[0];
continue; Radio selectedRadio = selectedMote.getInterfaces().getRadio();
} for (Mote m: simulation.getMotes()) {
double prob = if (m == selectedMote) {
((UDGM) simulation.getRadioMedium()).getSuccessProbability(selectedRadio, m.getInterfaces().getRadio()); continue;
if (prob == 0.0d) { }
continue; double prob =
} ((UDGM) simulation.getRadioMedium()).getSuccessProbability(selectedRadio, m.getInterfaces().getRadio());
String msg = (((int)(1000*prob))/10.0) + "%"; if (prob == 0.0d) {
Position pos = m.getInterfaces().getPosition(); continue;
Point pixel = visualizer.transformPositionToPixel(pos); }
int msgWidth = fm.stringWidth(msg); String msg = (((int)(1000*prob))/10.0) + "%";
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3); Position pos = m.getInterfaces().getPosition();
Point pixel = visualizer.transformPositionToPixel(pos);
int msgWidth = fm.stringWidth(msg);
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
}
} }
} }