[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) {
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;
}
final Position sPos = selectedMote.getInterfaces().getPosition();
/* Paint transmission and interference range for selected mote */
Position motePos = selectedMote.getInterfaces().getPosition();
for (final Mote selectedMote : selectedMotes) {
if (selectedMote.getInterfaces().getRadio() == null) {
continue;
}
final Position sPos = selectedMote.getInterfaces().getPosition();
Point pixelCoord = visualizer.transformPositionToPixel(motePos);
int x = pixelCoord.x;
int y = pixelCoord.y;
/* Paint transmission and interference range for selected mote */
Position motePos = selectedMote.getInterfaces().getPosition();
FontMetrics fm = g.getFontMetrics();
g.setColor(Color.BLACK);
Point pixelCoord = visualizer.transformPositionToPixel(motePos);
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 */
Mote[] dests = simulation.getMotes();
if (dests == null || dests.length == 0) {
String msg = "No edges";
MRM radioMedium = (MRM) simulation.getRadioMedium();
/* Print transmission success probabilities */
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);
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);
g.setColor(Color.BLACK);
g.drawString(msg, x - msgWidth/2, y + 2*Visualizer.MOTE_RADIUS + 3);
}
public void paintAfterMotes(Graphics g) {