[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) {
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
if (simulation == null
|| selectedMotes == null
|| selectedMotes.isEmpty()) {
if (simulation == null || selectedMotes == null) {
return;
}
final Mote selectedMote = visualizer.getSelectedMotes().iterator().next();
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) {
for (final Mote selectedMote : selectedMotes) {
if (selectedMote.getInterfaces().getRadio() == null) {
continue;
}
msg = String.format("%1.1f%%", 100.0*prob);
Position pos = r.radio.getPosition();
Point pixel = visualizer.transformPositionToPixel(pos);
msgWidth = fm.stringWidth(msg);
g.setColor(new Color(red, green, 0.0f));
g.drawString("LQI: " + lqi + " RSSI: " + rssi,(x + pixel.x)/2,(y + pixel.y)/2);
g.drawLine(x, y, pixel.x, pixel.y);
/* 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);
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.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.beans.PropertyVetoException;
import java.util.Set;
@ -269,104 +272,120 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
@Override
public void paintBeforeMotes(Graphics g) {
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
if (simulation == null
|| selectedMotes == null
|| selectedMotes.isEmpty()) {
if (simulation == null || selectedMotes == null) {
return;
}
final Mote selectedMote = visualizer.getSelectedMotes().iterator().next();
if (selectedMote.getInterfaces().getRadio() == null) {
return;
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) {
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 */
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 */
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) */
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(COLOR_INT);
g2d.fill(intRangeArea);
g.setColor(Color.GRAY);
g.drawOval(
x - translatedInterferenceMax.x,
y - translatedInterferenceMax.y,
2 * translatedInterferenceMax.x,
2 * translatedInterferenceMax.y);
/* Transmission range (MAX) */
g.drawOval(
x - translatedTransmissionMax.x,
y - translatedTransmissionMax.y,
2 * translatedTransmissionMax.x,
2 * translatedTransmissionMax.y);
g2d.draw(intRangeMaxArea);
g.setColor(COLOR_TX);
g2d.fill(trxRangeArea);
g.setColor(Color.GRAY);
g2d.draw(trxRangeMaxArea);
FontMetrics fm = g.getFontMetrics();
g.setColor(Color.BLACK);
/* Print transmission success probabilities */
for (Mote m: simulation.getMotes()) {
if (m == selectedMote) {
continue;
}
double prob =
((UDGM) simulation.getRadioMedium()).getSuccessProbability(selectedRadio, m.getInterfaces().getRadio());
if (prob == 0.0d) {
continue;
}
String msg = (((int)(1000*prob))/10.0) + "%";
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);
/* 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()) {
if (m == selectedMote) {
continue;
}
double prob =
((UDGM) simulation.getRadioMedium()).getSuccessProbability(selectedRadio, m.getInterfaces().getRadio());
if (prob == 0.0d) {
continue;
}
String msg = (((int)(1000*prob))/10.0) + "%";
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);
}
}
}