[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,15 +83,13 @@ 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();
for (final Mote selectedMote : selectedMotes) {
if (selectedMote.getInterfaces().getRadio() == null) {
return;
continue;
}
/* Paint transmission and interference range for selected mote */
@ -114,12 +112,13 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
int msgWidth = fm.stringWidth(msg);
g.setColor(Color.BLACK);
g.drawString(msg, x - msgWidth / 2, y + 2 * Visualizer.MOTE_RADIUS + 3);
return;
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;
@ -134,17 +133,22 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
if (prob == 0.0d) {
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.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);
}
}
}
}
public void paintAfterMotes(Graphics g) {
}

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,15 +272,18 @@ 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();
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) {
return;
continue;
}
/* 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)
Radio selectedRadio = selectedMote.getInterfaces().getRadio();
double moteInterferenceRange =
radioMedium.INTERFERENCE_RANGE
double moteInterferenceRange
= radioMedium.INTERFERENCE_RANGE
* ((double) selectedRadio.getCurrentOutputPowerIndicator()
/ (double) selectedRadio.getOutputPowerIndicatorMax());
double moteTransmissionRange =
radioMedium.TRANSMITTING_RANGE
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);
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);
@ -318,41 +324,53 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
translatedTransmissionMax.y = Math.abs(translatedTransmissionMax.y - translatedZero.y);
/* Interference range */
g.setColor(COLOR_INT);
g.fillOval(
intRangeArea.add(new Area(new Ellipse2D.Double(
x - translatedInterference.x,
y - translatedInterference.y,
2 * translatedInterference.x,
2 * translatedInterference.y);
2 * translatedInterference.y)));
/* Transmission range */
g.setColor(COLOR_TX);
g.fillOval(
/* Interference range (MAX) */
trxRangeArea.add(new Area(new Ellipse2D.Double(
x - translatedTransmission.x,
y - translatedTransmission.y,
2 * translatedTransmission.x,
2 * translatedTransmission.y);
2 * translatedTransmission.y)));
/* Interference range (MAX) */
g.setColor(Color.GRAY);
g.drawOval(
intRangeMaxArea.add(new Area(new Ellipse2D.Double(
x - translatedInterferenceMax.x,
y - translatedInterferenceMax.y,
2 * translatedInterferenceMax.x,
2 * translatedInterferenceMax.y);
2 * translatedInterferenceMax.y)));
/* Transmission range (MAX) */
g.drawOval(
trxRangeMaxArea.add(new Area(new Ellipse2D.Double(
x - translatedTransmissionMax.x,
y - translatedTransmissionMax.y,
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();
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()) {
if (m == selectedMote) {
continue;
@ -368,6 +386,7 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
int msgWidth = fm.stringWidth(msg);
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
}
}
}