[cooja] apps/mrm: Adapted MRM visualizer skin to show adequate

information for multi-selections
This commit is contained in:
Enrico Joerns 2014-04-10 18:33:26 +02:00
parent e69b08f5fd
commit 8e648bcece

View File

@ -81,77 +81,77 @@ public class MRMVisualizerSkin 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 || selectedMotes == null || selectedMotes.isEmpty()) { if (simulation == null || selectedMotes == null) {
return; return;
} }
final Mote selectedMote = visualizer.getSelectedMotes().iterator().next();
if (selectedMote.getInterfaces().getRadio() == null) {
return;
}
final Position sPos = selectedMote.getInterfaces().getPosition();
/* Paint transmission and interference range for selected mote */ for (final Mote selectedMote : selectedMotes) {
Position motePos = selectedMote.getInterfaces().getPosition(); if (selectedMote.getInterfaces().getRadio() == null) {
continue;
}
final Position sPos = selectedMote.getInterfaces().getPosition();
Point pixelCoord = visualizer.transformPositionToPixel(motePos); /* Paint transmission and interference range for selected mote */
int x = pixelCoord.x; Position motePos = selectedMote.getInterfaces().getPosition();
int y = pixelCoord.y;
FontMetrics fm = g.getFontMetrics(); Point pixelCoord = visualizer.transformPositionToPixel(motePos);
g.setColor(Color.BLACK); int x = pixelCoord.x;
int y = pixelCoord.y;
MRM radioMedium = (MRM) simulation.getRadioMedium(); FontMetrics fm = g.getFontMetrics();
g.setColor(Color.BLACK);
/* Print transmission success probabilities */ MRM radioMedium = (MRM) simulation.getRadioMedium();
Mote[] dests = simulation.getMotes();
if (dests == null || dests.length == 0) { /* Print transmission success probabilities */
String msg = "No edges"; Mote[] dests = simulation.getMotes();
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;
}
g.setColor(Color.BLACK);
int edges = 0;
for (Mote d : dests) {
if (d == selectedMote) {
continue;
}
final Radio dRadio = d.getInterfaces().getRadio();
TxPair txPair = new RadioPair() {
public Radio getFromRadio() {
return selectedMote.getInterfaces().getRadio();
}
public Radio getToRadio() {
return dRadio;
}
};
double probArr[] = radioMedium.getChannelModel().getProbability(
txPair,
Double.NEGATIVE_INFINITY
);
double prob = probArr[0];
double ss = probArr[1];
if (prob == 0.0d) {
continue;
}
edges++;
String msg = String.format("%1.1f%%, %1.2fdB", 100.0*prob, ss);
Point pixel = visualizer.transformPositionToPixel(d.getInterfaces().getPosition());
int msgWidth = fm.stringWidth(msg);
g.setColor(new Color(1-(float)prob, (float)prob, 0.0f));
g.drawLine(x, y, pixel.x, pixel.y);
g.setColor(Color.BLACK);
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
}
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);
return;
} }
g.setColor(Color.BLACK);
int edges = 0;
for (Mote d: dests) {
if (d == selectedMote) {
continue;
}
final Radio dRadio = d.getInterfaces().getRadio();
TxPair txPair = new RadioPair() {
public Radio getFromRadio() {
return selectedMote.getInterfaces().getRadio();
}
public Radio getToRadio() {
return dRadio;
}
};
double probArr[] = radioMedium.getChannelModel().getProbability(
txPair,
Double.NEGATIVE_INFINITY
);
double prob = probArr[0];
double ss = probArr[1];
if (prob == 0.0d) {
continue;
}
edges++;
String msg = String.format("%1.1f%%, %1.2fdB", 100.0*prob, ss);
Point pixel = visualizer.transformPositionToPixel(d.getInterfaces().getPosition());
int msgWidth = fm.stringWidth(msg);
g.setColor(new Color(1-(float)prob, (float)prob, 0.0f));
g.drawLine(x, y, pixel.x, pixel.y);
g.setColor(Color.BLACK);
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
}
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);
} }
public void paintAfterMotes(Graphics g) { public void paintAfterMotes(Graphics g) {