Merge pull request #626 from ejoerns/pull-req/cooja-vis-advanced
[Cooja] plugins/Visualizer: Multi-mote selection functionality
This commit is contained in:
commit
dbb8f3ec13
|
@ -26,13 +26,13 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.contikios.mrm;
|
package org.contikios.mrm;
|
||||||
|
|
||||||
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.Point;
|
import java.awt.Point;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
@ -50,11 +50,13 @@ import org.contikios.mrm.ChannelModel.TxPair;
|
||||||
@ClassDescription("Radio environment (MRM)")
|
@ClassDescription("Radio environment (MRM)")
|
||||||
@SupportedArguments(radioMediums = {MRM.class})
|
@SupportedArguments(radioMediums = {MRM.class})
|
||||||
public class MRMVisualizerSkin implements VisualizerSkin {
|
public class MRMVisualizerSkin implements VisualizerSkin {
|
||||||
private static Logger logger = Logger.getLogger(MRMVisualizerSkin.class);
|
|
||||||
|
private static final Logger logger = Logger.getLogger(MRMVisualizerSkin.class);
|
||||||
|
|
||||||
private Simulation simulation = null;
|
private Simulation simulation = null;
|
||||||
private Visualizer visualizer = null;
|
private Visualizer visualizer = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setActive(Simulation simulation, Visualizer vis) {
|
public void setActive(Simulation simulation, Visualizer vis) {
|
||||||
if (!(simulation.getRadioMedium() instanceof MRM)) {
|
if (!(simulation.getRadioMedium() instanceof MRM)) {
|
||||||
logger.fatal("Cannot activate MRM skin for unknown radio medium: " + simulation.getRadioMedium());
|
logger.fatal("Cannot activate MRM skin for unknown radio medium: " + simulation.getRadioMedium());
|
||||||
|
@ -64,6 +66,7 @@ public class MRMVisualizerSkin implements VisualizerSkin {
|
||||||
this.visualizer = vis;
|
this.visualizer = vis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setInactive() {
|
public void setInactive() {
|
||||||
if (simulation == null) {
|
if (simulation == null) {
|
||||||
/* Skin was never activated */
|
/* Skin was never activated */
|
||||||
|
@ -71,88 +74,98 @@ public class MRMVisualizerSkin implements VisualizerSkin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Color[] getColorOf(Mote mote) {
|
public Color[] getColorOf(Mote mote) {
|
||||||
Mote selectedMote = visualizer.getSelectedMote();
|
if (visualizer.getSelectedMotes().contains(mote)) {
|
||||||
if (mote == selectedMote) {
|
return new Color[]{Color.CYAN};
|
||||||
return new Color[] { Color.CYAN };
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void paintBeforeMotes(Graphics g) {
|
public void paintBeforeMotes(Graphics g) {
|
||||||
final Mote selectedMote = visualizer.getSelectedMote();
|
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
|
||||||
if (simulation == null
|
if (simulation == null || selectedMotes == null) {
|
||||||
|| selectedMote == null
|
|
||||||
|| selectedMote.getInterfaces().getRadio() == null) {
|
|
||||||
return;
|
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) {
|
||||||
|
|
||||||
Point pixelCoord = visualizer.transformPositionToPixel(motePos);
|
|
||||||
int x = pixelCoord.x;
|
|
||||||
int y = pixelCoord.y;
|
|
||||||
|
|
||||||
FontMetrics fm = g.getFontMetrics();
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
|
|
||||||
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;
|
continue;
|
||||||
}
|
}
|
||||||
final Radio dRadio = d.getInterfaces().getRadio();
|
final Position sPos = selectedMote.getInterfaces().getPosition();
|
||||||
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) {
|
/* Paint transmission and interference range for selected mote */
|
||||||
continue;
|
Position motePos = selectedMote.getInterfaces().getPosition();
|
||||||
}
|
|
||||||
edges++;
|
Point pixelCoord = visualizer.transformPositionToPixel(motePos);
|
||||||
String msg = String.format("%1.1f%%, %1.2fdB", 100.0*prob, ss);
|
int x = pixelCoord.x;
|
||||||
Point pixel = visualizer.transformPositionToPixel(d.getInterfaces().getPosition());
|
int y = pixelCoord.y;
|
||||||
int msgWidth = fm.stringWidth(msg);
|
|
||||||
g.setColor(new Color(1-(float)prob, (float)prob, 0.0f));
|
FontMetrics fm = g.getFontMetrics();
|
||||||
g.drawLine(x, y, pixel.x, pixel.y);
|
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
String msg = dests.length + " edges";
|
MRM radioMedium = (MRM) simulation.getRadioMedium();
|
||||||
int msgWidth = fm.stringWidth(msg);
|
|
||||||
g.setColor(Color.BLACK);
|
/* Print transmission success probabilities */
|
||||||
g.drawString(msg, x - msgWidth/2, y + 2*Visualizer.MOTE_RADIUS + 3);
|
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() {
|
||||||
|
@Override
|
||||||
|
public Radio getFromRadio() {
|
||||||
|
return selectedMote.getInterfaces().getRadio();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void paintAfterMotes(Graphics g) {
|
public void paintAfterMotes(Graphics g) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Visualizer getVisualizer() {
|
public Visualizer getVisualizer() {
|
||||||
return visualizer;
|
return visualizer;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -27,13 +27,13 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.contikios.cooja.plugins.skins;
|
package org.contikios.cooja.plugins.skins;
|
||||||
|
|
||||||
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.Point;
|
import java.awt.Point;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
@ -52,99 +52,122 @@ import org.contikios.cooja.radiomediums.DirectedGraphMedium;
|
||||||
@ClassDescription("Radio environment (DGRM)")
|
@ClassDescription("Radio environment (DGRM)")
|
||||||
@SupportedArguments(radioMediums = {DirectedGraphMedium.class})
|
@SupportedArguments(radioMediums = {DirectedGraphMedium.class})
|
||||||
public class DGRMVisualizerSkin implements VisualizerSkin {
|
public class DGRMVisualizerSkin implements VisualizerSkin {
|
||||||
private static Logger logger = Logger.getLogger(DGRMVisualizerSkin.class);
|
|
||||||
|
|
||||||
private Simulation simulation = null;
|
private static final Logger logger = Logger.getLogger(DGRMVisualizerSkin.class);
|
||||||
private Visualizer visualizer = null;
|
|
||||||
|
|
||||||
public void setActive(Simulation simulation, Visualizer vis) {
|
private Simulation simulation = null;
|
||||||
if (!(simulation.getRadioMedium() instanceof DirectedGraphMedium)) {
|
private Visualizer visualizer = null;
|
||||||
logger.fatal("Cannot activate DGRM skin for unknown radio medium: " + simulation.getRadioMedium());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.simulation = simulation;
|
|
||||||
this.visualizer = vis;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInactive() {
|
@Override
|
||||||
if (simulation == null) {
|
public void setActive(Simulation simulation, Visualizer vis) {
|
||||||
/* Skin was never activated */
|
if (!(simulation.getRadioMedium() instanceof DirectedGraphMedium)) {
|
||||||
return;
|
logger.fatal("Cannot activate DGRM skin for unknown radio medium: " + simulation.getRadioMedium());
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
this.simulation = simulation;
|
||||||
|
this.visualizer = vis;
|
||||||
|
}
|
||||||
|
|
||||||
public Color[] getColorOf(Mote mote) {
|
@Override
|
||||||
Mote selectedMote = visualizer.getSelectedMote();
|
public void setInactive() {
|
||||||
if (mote == selectedMote) {
|
if (simulation == null) {
|
||||||
return new Color[] { Color.CYAN };
|
/* Skin was never activated */
|
||||||
}
|
return;
|
||||||
return null;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintBeforeMotes(Graphics g) {
|
@Override
|
||||||
Mote selectedMote = visualizer.getSelectedMote();
|
public Color[] getColorOf(Mote mote) {
|
||||||
if (simulation == null
|
if (visualizer.getSelectedMotes().contains(mote)) {
|
||||||
|| selectedMote == null
|
return new Color[]{Color.CYAN};
|
||||||
|| selectedMote.getInterfaces().getRadio() == null) {
|
}
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Paint transmission and interference range for selected mote */
|
@Override
|
||||||
Position motePos = selectedMote.getInterfaces().getPosition();
|
public void paintBeforeMotes(Graphics g) {
|
||||||
|
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
|
||||||
|
if (simulation == null || selectedMotes == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Point pixelCoord = visualizer.transformPositionToPixel(motePos);
|
for (final Mote selectedMote : selectedMotes) {
|
||||||
int x = pixelCoord.x;
|
if (selectedMote.getInterfaces().getRadio() == null) {
|
||||||
int y = pixelCoord.y;
|
continue;
|
||||||
Radio selectedRadio = selectedMote.getInterfaces().getRadio();
|
}
|
||||||
|
|
||||||
FontMetrics fm = g.getFontMetrics();
|
/* Paint transmission and interference range for selected mote */
|
||||||
g.setColor(Color.BLACK);
|
Position motePos = selectedMote.getInterfaces().getPosition();
|
||||||
|
|
||||||
DirectedGraphMedium radioMedium = (DirectedGraphMedium) simulation.getRadioMedium();
|
Point pixelCoord = visualizer.transformPositionToPixel(motePos);
|
||||||
|
int x = pixelCoord.x;
|
||||||
|
int y = pixelCoord.y;
|
||||||
|
Radio selectedRadio = selectedMote.getInterfaces().getRadio();
|
||||||
|
|
||||||
/* Print transmission success probabilities */
|
FontMetrics fm = g.getFontMetrics();
|
||||||
DestinationRadio[] dests = radioMedium.getPotentialDestinations(selectedRadio);
|
g.setColor(Color.BLACK);
|
||||||
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;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void paintAfterMotes(Graphics g) {
|
DirectedGraphMedium radioMedium = (DirectedGraphMedium) simulation.getRadioMedium();
|
||||||
}
|
|
||||||
|
|
||||||
public Visualizer getVisualizer() {
|
/* Print transmission success probabilities */
|
||||||
return visualizer;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintAfterMotes(Graphics g) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Visualizer getVisualizer() {
|
||||||
|
return visualizer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,15 +27,18 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.contikios.cooja.plugins.skins;
|
package org.contikios.cooja.plugins.skins;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
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 javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
|
@ -83,6 +86,7 @@ import org.contikios.cooja.radiomediums.UDGM;
|
||||||
@ClassDescription("Radio environment (UDGM)")
|
@ClassDescription("Radio environment (UDGM)")
|
||||||
@SupportedArguments(radioMediums = {UDGM.class})
|
@SupportedArguments(radioMediums = {UDGM.class})
|
||||||
public class UDGMVisualizerSkin implements VisualizerSkin {
|
public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(UDGMVisualizerSkin.class);
|
private static final Logger logger = Logger.getLogger(UDGMVisualizerSkin.class);
|
||||||
|
|
||||||
private static final Color COLOR_TX = new Color(0, 255, 0, 100);
|
private static final Color COLOR_TX = new Color(0, 255, 0, 100);
|
||||||
|
@ -154,8 +158,8 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
txRangeSpinner.addChangeListener(new ChangeListener() {
|
txRangeSpinner.addChangeListener(new ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
radioMedium.setTxRange(((SpinnerNumberModel)
|
radioMedium.setTxRange(((SpinnerNumberModel) txRangeSpinner.getModel())
|
||||||
txRangeSpinner.getModel()).getNumber().doubleValue());
|
.getNumber().doubleValue());
|
||||||
visualizer.repaint();
|
visualizer.repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -163,8 +167,8 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
interferenceRangeSpinner.addChangeListener(new ChangeListener() {
|
interferenceRangeSpinner.addChangeListener(new ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
radioMedium.setInterferenceRange(((SpinnerNumberModel)
|
radioMedium.setInterferenceRange(((SpinnerNumberModel) interferenceRangeSpinner.getModel())
|
||||||
interferenceRangeSpinner.getModel()).getNumber().doubleValue());
|
.getNumber().doubleValue());
|
||||||
visualizer.repaint();
|
visualizer.repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -172,8 +176,8 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
successRatioTxSpinner.addChangeListener(new ChangeListener() {
|
successRatioTxSpinner.addChangeListener(new ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
radioMedium.SUCCESS_RATIO_TX = ((SpinnerNumberModel)
|
radioMedium.SUCCESS_RATIO_TX = ((SpinnerNumberModel) successRatioTxSpinner.getModel())
|
||||||
successRatioTxSpinner.getModel()).getNumber().doubleValue();
|
.getNumber().doubleValue();
|
||||||
visualizer.repaint();
|
visualizer.repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -181,8 +185,8 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
successRatioRxSpinner.addChangeListener(new ChangeListener() {
|
successRatioRxSpinner.addChangeListener(new ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
radioMedium.SUCCESS_RATIO_RX = ((SpinnerNumberModel)
|
radioMedium.SUCCESS_RATIO_RX = ((SpinnerNumberModel) successRatioRxSpinner.getModel())
|
||||||
successRatioRxSpinner.getModel()).getNumber().doubleValue();
|
.getNumber().doubleValue();
|
||||||
visualizer.repaint();
|
visualizer.repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -195,7 +199,7 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
JPanel main = new JPanel();
|
JPanel main = new JPanel();
|
||||||
main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
|
main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
|
||||||
main.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
main.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||||
|
|
||||||
rangeTX = Box.createHorizontalBox();
|
rangeTX = Box.createHorizontalBox();
|
||||||
rangeTX.add(new JLabel("TX range:"));
|
rangeTX.add(new JLabel("TX range:"));
|
||||||
rangeTX.add(Box.createHorizontalStrut(5));
|
rangeTX.add(Box.createHorizontalStrut(5));
|
||||||
|
@ -217,12 +221,12 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
rangeINT.setVisible(false);
|
rangeINT.setVisible(false);
|
||||||
ratioTX.setVisible(false);
|
ratioTX.setVisible(false);
|
||||||
ratioRX.setVisible(false);
|
ratioRX.setVisible(false);
|
||||||
|
|
||||||
main.add(rangeTX);
|
main.add(rangeTX);
|
||||||
main.add(rangeINT);
|
main.add(rangeINT);
|
||||||
main.add(ratioTX);
|
main.add(ratioTX);
|
||||||
main.add(ratioRX);
|
main.add(ratioRX);
|
||||||
|
|
||||||
rrFrame = new JInternalFrame("UDGM", false, true);
|
rrFrame = new JInternalFrame("UDGM", false, true);
|
||||||
rrFrame.setVisible(false);
|
rrFrame.setVisible(false);
|
||||||
rrFrame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
rrFrame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||||
|
@ -259,109 +263,129 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Color[] getColorOf(Mote mote) {
|
public Color[] getColorOf(Mote mote) {
|
||||||
Mote selectedMote = visualizer.getSelectedMote();
|
if (visualizer.getSelectedMotes().contains(mote)) {
|
||||||
if (mote == selectedMote) {
|
return new Color[]{Color.CYAN};
|
||||||
return new Color[] { Color.CYAN };
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintBeforeMotes(Graphics g) {
|
public void paintBeforeMotes(Graphics g) {
|
||||||
Mote selectedMote = visualizer.getSelectedMote();
|
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
|
||||||
if (simulation == null
|
if (simulation == null || selectedMotes == null) {
|
||||||
|| selectedMote == null
|
|
||||||
|| selectedMote.getInterfaces().getRadio() == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Paint transmission and interference range for selected mote */
|
Area intRangeArea = new Area();
|
||||||
Position motePos = selectedMote.getInterfaces().getPosition();
|
Area intRangeMaxArea = new Area();
|
||||||
|
Area trxRangeArea = new Area();
|
||||||
|
Area trxRangeMaxArea = new Area();
|
||||||
|
|
||||||
Point pixelCoord = visualizer.transformPositionToPixel(motePos);
|
for (Mote selectedMote : selectedMotes) {
|
||||||
int x = pixelCoord.x;
|
if (selectedMote.getInterfaces().getRadio() == null) {
|
||||||
int y = pixelCoord.y;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch current output power indicator (scale with as percent)
|
/* Paint transmission and interference range for selected mote */
|
||||||
Radio selectedRadio = selectedMote.getInterfaces().getRadio();
|
Position motePos = selectedMote.getInterfaces().getPosition();
|
||||||
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 pixelCoord = visualizer.transformPositionToPixel(motePos);
|
||||||
Point translatedInterference =
|
int x = pixelCoord.x;
|
||||||
visualizer.transformPositionToPixel(moteInterferenceRange, moteInterferenceRange, 0.0);
|
int y = pixelCoord.y;
|
||||||
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);
|
// Fetch current output power indicator (scale with as percent)
|
||||||
translatedInterference.y = Math.abs(translatedInterference.y - translatedZero.y);
|
Radio selectedRadio = selectedMote.getInterfaces().getRadio();
|
||||||
translatedTransmission.x = Math.abs(translatedTransmission.x - translatedZero.x);
|
double moteInterferenceRange
|
||||||
translatedTransmission.y = Math.abs(translatedTransmission.y - translatedZero.y);
|
= radioMedium.INTERFERENCE_RANGE
|
||||||
translatedInterferenceMax.x = Math.abs(translatedInterferenceMax.x - translatedZero.x);
|
* ((double) selectedRadio.getCurrentOutputPowerIndicator()
|
||||||
translatedInterferenceMax.y = Math.abs(translatedInterferenceMax.y - translatedZero.y);
|
/ (double) selectedRadio.getOutputPowerIndicatorMax());
|
||||||
translatedTransmissionMax.x = Math.abs(translatedTransmissionMax.x - translatedZero.x);
|
double moteTransmissionRange
|
||||||
translatedTransmissionMax.y = Math.abs(translatedTransmissionMax.y - translatedZero.y);
|
= radioMedium.TRANSMITTING_RANGE
|
||||||
|
* ((double) selectedRadio.getCurrentOutputPowerIndicator()
|
||||||
|
/ (double) selectedRadio.getOutputPowerIndicatorMax());
|
||||||
|
|
||||||
/* Interference range */
|
Point translatedZero = visualizer.transformPositionToPixel(0.0, 0.0, 0.0);
|
||||||
g.setColor(COLOR_INT);
|
Point translatedInterference
|
||||||
g.fillOval(
|
= visualizer.transformPositionToPixel(moteInterferenceRange, moteInterferenceRange, 0.0);
|
||||||
x - translatedInterference.x,
|
Point translatedTransmission
|
||||||
y - translatedInterference.y,
|
= visualizer.transformPositionToPixel(moteTransmissionRange, moteTransmissionRange, 0.0);
|
||||||
2 * translatedInterference.x,
|
Point translatedInterferenceMax
|
||||||
2 * translatedInterference.y);
|
= visualizer.transformPositionToPixel(radioMedium.INTERFERENCE_RANGE, radioMedium.INTERFERENCE_RANGE, 0.0);
|
||||||
|
Point translatedTransmissionMax
|
||||||
|
= visualizer.transformPositionToPixel(radioMedium.TRANSMITTING_RANGE, radioMedium.TRANSMITTING_RANGE, 0.0);
|
||||||
|
|
||||||
/* Transmission range */
|
translatedInterference.x = Math.abs(translatedInterference.x - translatedZero.x);
|
||||||
g.setColor(COLOR_TX);
|
translatedInterference.y = Math.abs(translatedInterference.y - translatedZero.y);
|
||||||
g.fillOval(
|
translatedTransmission.x = Math.abs(translatedTransmission.x - translatedZero.x);
|
||||||
x - translatedTransmission.x,
|
translatedTransmission.y = Math.abs(translatedTransmission.y - translatedZero.y);
|
||||||
y - translatedTransmission.y,
|
translatedInterferenceMax.x = Math.abs(translatedInterferenceMax.x - translatedZero.x);
|
||||||
2 * translatedTransmission.x,
|
translatedInterferenceMax.y = Math.abs(translatedInterferenceMax.y - translatedZero.y);
|
||||||
2 * translatedTransmission.y);
|
translatedTransmissionMax.x = Math.abs(translatedTransmissionMax.x - translatedZero.x);
|
||||||
|
translatedTransmissionMax.y = Math.abs(translatedTransmissionMax.y - translatedZero.y);
|
||||||
|
|
||||||
/* Interference range (MAX) */
|
/* 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)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
g2d.setColor(COLOR_INT);
|
||||||
|
g2d.fill(intRangeArea);
|
||||||
g.setColor(Color.GRAY);
|
g.setColor(Color.GRAY);
|
||||||
g.drawOval(
|
g2d.draw(intRangeMaxArea);
|
||||||
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);
|
|
||||||
|
|
||||||
|
g.setColor(COLOR_TX);
|
||||||
|
g2d.fill(trxRangeArea);
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g2d.draw(trxRangeMaxArea);
|
||||||
|
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -371,6 +395,7 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RangeMenuAction implements SimulationMenuAction {
|
public static class RangeMenuAction implements SimulationMenuAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(Visualizer visualizer, Simulation simulation) {
|
public boolean isEnabled(Visualizer visualizer, Simulation simulation) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -396,6 +421,7 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
};
|
};
|
||||||
|
|
||||||
public static class SuccessRatioMenuAction implements SimulationMenuAction {
|
public static class SuccessRatioMenuAction implements SimulationMenuAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(Visualizer visualizer, Simulation simulation) {
|
public boolean isEnabled(Visualizer visualizer, Simulation simulation) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -409,7 +435,7 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(Visualizer visualizer, Simulation simulation) {
|
public void doAction(Visualizer visualizer, Simulation simulation) {
|
||||||
VisualizerSkin[] skins = visualizer.getCurrentSkins();
|
VisualizerSkin[] skins = visualizer.getCurrentSkins();
|
||||||
for (VisualizerSkin skin: skins) {
|
for (VisualizerSkin skin : skins) {
|
||||||
if (skin instanceof UDGMVisualizerSkin) {
|
if (skin instanceof UDGMVisualizerSkin) {
|
||||||
UDGMVisualizerSkin vskin = ((UDGMVisualizerSkin) skin);
|
UDGMVisualizerSkin vskin = ((UDGMVisualizerSkin) skin);
|
||||||
vskin.ratioTX.setVisible(true);
|
vskin.ratioTX.setVisible(true);
|
||||||
|
|
Loading…
Reference in a new issue