INET Framework for OMNeT++/OMNEST
inet::visualizer::MobilityCanvasVisualizer Class Reference

#include <MobilityCanvasVisualizer.h>

Inheritance diagram for inet::visualizer::MobilityCanvasVisualizer:
inet::visualizer::MobilityVisualizerBase inet::visualizer::VisualizerBase

Classes

class  MobilityCanvasVisualization
 

Public Member Functions

virtual ~MobilityCanvasVisualizer ()
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, cObject *object, cObject *details) override
 
- Public Member Functions inherited from inet::visualizer::MobilityVisualizerBase
virtual ~MobilityVisualizerBase ()
 

Static Public Member Functions

static void setPosition (cModule *visualRepresentation, cFigure::Point position)
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void refreshDisplay () const override
 
virtual cModule * findVisualRepresentation (cModule *module) const
 
virtual MobilityCanvasVisualizationgetMobilityVisualization (const IMobility *mobility) const
 
virtual void setMobilityVisualization (const IMobility *mobility, MobilityCanvasVisualization *entry)
 
virtual void removeMobilityVisualization (const IMobility *mobility)
 
virtual MobilityCanvasVisualizationensureMobilityVisualization (IMobility *mobility)
 
virtual void extendMovementTrail (const IMobility *mobility, TrailFigure *trailFigure, cFigure::Point position) const
 
- Protected Member Functions inherited from inet::visualizer::MobilityVisualizerBase
virtual void handleParameterChange (const char *name) override
 
virtual void subscribe ()
 
virtual void unsubscribe ()
 
- Protected Member Functions inherited from inet::visualizer::VisualizerBase
virtual int numInitStages () const override
 
virtual Coord getPosition (const cModule *networkNode) const
 
virtual Coord getContactPosition (const cModule *networkNode, const Coord &fromPosition, const char *contactMode, double contactSpacing) const
 
virtual InterfaceEntrygetInterfaceEntry (cModule *networkNode, cModule *module) const
 

Protected Attributes

double zIndex = NaN
 
const CanvasProjectioncanvasProjection = nullptr
 
NetworkNodeCanvasVisualizernetworkNodeVisualizer = nullptr
 
std::map< const IMobility *, MobilityCanvasVisualization * > mobilityVisualizations
 
- Protected Attributes inherited from inet::visualizer::MobilityVisualizerBase
bool displayMovements = false
 
double animationSpeed = NaN
 
ModuleFilter moduleFilter
 
bool displayOrientations = false
 
double orientationArcSize = NaN
 
cFigure::Color orientationLineColor
 
cFigure::LineStyle orientationLineStyle
 
double orientationLineWidth = NaN
 
bool displayVelocities = false
 
double velocityArrowScale = NaN
 
cFigure::Color velocityLineColor
 
cFigure::LineStyle velocityLineStyle
 
double velocityLineWidth = NaN
 
bool displayMovementTrails = false
 
bool autoMovementTrailLineColor = false
 
ColorSet movementTrailLineColorSet
 
cFigure::LineStyle movementTrailLineStyle
 
double movementTrailLineWidth = NaN
 
int trailLength = -1
 
- Protected Attributes inherited from inet::visualizer::VisualizerBase
cModule * visualizerTargetModule = nullptr
 
const char * tags = nullptr
 

Constructor & Destructor Documentation

inet::visualizer::MobilityCanvasVisualizer::~MobilityCanvasVisualizer ( )
virtual
38 {
39  for (auto mobilityVisualization : mobilityVisualizations)
40  delete mobilityVisualization.second;
41 }
std::map< const IMobility *, MobilityCanvasVisualization * > mobilityVisualizations
Definition: MobilityCanvasVisualizer.h:50

Member Function Documentation

MobilityCanvasVisualizer::MobilityCanvasVisualization * inet::visualizer::MobilityCanvasVisualizer::ensureMobilityVisualization ( IMobility mobility)
protectedvirtual

Referenced by receiveSignal().

109 {
110  auto mobilityVisualization = getMobilityVisualization(mobility);
111  if (mobilityVisualization == nullptr) {
112  auto canvas = visualizerTargetModule->getCanvas();
113  auto module = const_cast<cModule *>(dynamic_cast<const cModule *>(mobility));
114  auto visualRepresentation = findVisualRepresentation(module);
116  cArcFigure *orientationFigure = nullptr;
117  if (displayOrientations) {
118  auto rectangle = getSimulation()->getEnvir()->getSubmoduleBounds(visualRepresentation);
119  int radius = rectangle.getSize().getLength() * 1.25 / 2;
120  orientationFigure = new cArcFigure("orientation");
121  orientationFigure->setTags((std::string("orientation ") + tags).c_str());
122  orientationFigure->setTooltip("This arc represents the current orientation of the mobility model");
123  orientationFigure->setZIndex(zIndex);
124  orientationFigure->setBounds(cFigure::Rectangle(-radius, -radius, 2 * radius, 2 * radius));
125  orientationFigure->setLineColor(orientationLineColor);
126  orientationFigure->setLineStyle(orientationLineStyle);
127  orientationFigure->setLineWidth(orientationLineWidth);
128  visualization->addFigure(orientationFigure);
129  }
130  cLineFigure *velocityFigure = nullptr;
131  if (displayVelocities) {
132  velocityFigure = new cLineFigure("velocity");
133  velocityFigure->setTags((std::string("velocity ") + tags).c_str());
134  velocityFigure->setTooltip("This arrow represents the current velocity of the mobility model");
135  velocityFigure->setZIndex(zIndex);
136  velocityFigure->setVisible(false);
137  velocityFigure->setEndArrowhead(cFigure::ARROW_SIMPLE);
138  velocityFigure->setLineColor(velocityLineColor);
139  velocityFigure->setLineStyle(velocityLineStyle);
140  velocityFigure->setLineWidth(velocityLineWidth);
141  visualization->addFigure(velocityFigure);
142  }
143  TrailFigure *trailFigure = nullptr;
144  if (displayMovementTrails) {
145  trailFigure = new TrailFigure(trailLength, true, "movement trail");
146  trailFigure->setTags((std::string("movement_trail recent_history ") + tags).c_str());
147  trailFigure->setZIndex(zIndex);
148  canvas->addFigure(trailFigure);
149  }
150  mobilityVisualization = new MobilityCanvasVisualization(visualization, visualRepresentation, orientationFigure, velocityFigure, trailFigure, mobility);
151  setMobilityVisualization(mobility, mobilityVisualization);
152  }
153  return mobilityVisualization;
154 }
double velocityLineWidth
Definition: MobilityVisualizerBase.h:57
int trailLength
Definition: MobilityVisualizerBase.h:64
const char * tags
Definition: VisualizerBase.h:32
cFigure::Color velocityLineColor
Definition: MobilityVisualizerBase.h:55
bool displayVelocities
Definition: MobilityVisualizerBase.h:53
cFigure::LineStyle velocityLineStyle
Definition: MobilityVisualizerBase.h:56
double zIndex
Definition: MobilityCanvasVisualizer.h:47
virtual NetworkNodeCanvasVisualization * getNetworkNodeVisualization(const cModule *networkNode) const
Definition: NetworkNodeCanvasVisualizer.cc:63
virtual cModule * findVisualRepresentation(cModule *module) const
Definition: MobilityCanvasVisualizer.cc:82
bool displayMovementTrails
Definition: MobilityVisualizerBase.h:59
virtual void setMobilityVisualization(const IMobility *mobility, MobilityCanvasVisualization *entry)
Definition: MobilityCanvasVisualizer.cc:98
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
double orientationLineWidth
Definition: MobilityVisualizerBase.h:51
cFigure::LineStyle orientationLineStyle
Definition: MobilityVisualizerBase.h:50
cModule * visualizerTargetModule
Definition: VisualizerBase.h:31
virtual MobilityCanvasVisualization * getMobilityVisualization(const IMobility *mobility) const
Definition: MobilityCanvasVisualizer.cc:89
cFigure::Color orientationLineColor
Definition: MobilityVisualizerBase.h:49
bool displayOrientations
Definition: MobilityVisualizerBase.h:47
NetworkNodeCanvasVisualizer * networkNodeVisualizer
Definition: MobilityCanvasVisualizer.h:49
void inet::visualizer::MobilityCanvasVisualizer::extendMovementTrail ( const IMobility mobility,
TrailFigure trailFigure,
cFigure::Point  position 
) const
protectedvirtual

Referenced by refreshDisplay().

157 {
158  cFigure::Point startPosition;
159  cFigure::Point endPosition = position;
160  if (trailFigure->getNumFigures() == 0)
161  startPosition = position;
162  else
163  startPosition = static_cast<cLineFigure*>(trailFigure->getFigure(trailFigure->getNumFigures() - 1))->getEnd();
164  double dx = startPosition.x - endPosition.x;
165  double dy = startPosition.y - endPosition.y;
166  // TODO: 1?
167  if (trailFigure->getNumFigures() == 0 || dx * dx + dy * dy > 1) {
168  cLineFigure *movementLine = new cLineFigure("movementTrail");
169  movementLine->setTags((std::string("movement_trail recent_history ") + tags).c_str());
170  movementLine->setTooltip("This line represents the recent movement trail of the mobility model");
171  movementLine->setStart(startPosition);
172  movementLine->setEnd(endPosition);
173  auto module = const_cast<cModule *>(check_and_cast<const cModule *>(mobility));
174  movementLine->setLineColor(movementTrailLineColorSet.getColor(module->getId()));
175  movementLine->setLineStyle(movementTrailLineStyle);
176  movementLine->setLineWidth(movementTrailLineWidth);
177  movementLine->setZoomLineWidth(false);
178  trailFigure->addFigure(movementLine);
179  }
180 }
const char * tags
Definition: VisualizerBase.h:32
ColorSet movementTrailLineColorSet
Definition: MobilityVisualizerBase.h:61
double movementTrailLineWidth
Definition: MobilityVisualizerBase.h:63
cFigure::LineStyle movementTrailLineStyle
Definition: MobilityVisualizerBase.h:62
cFigure::Color getColor(int index) const
Definition: ColorSet.cc:43
cModule * inet::visualizer::MobilityCanvasVisualizer::findVisualRepresentation ( cModule *  module) const
protectedvirtual

Referenced by ensureMobilityVisualization().

83 {
84  while (module != nullptr && module->getParentModule() != visualizerTargetModule)
85  module = module->getParentModule();
86  return module;
87 }
cModule * visualizerTargetModule
Definition: VisualizerBase.h:31
MobilityCanvasVisualizer::MobilityCanvasVisualization * inet::visualizer::MobilityCanvasVisualizer::getMobilityVisualization ( const IMobility mobility) const
protectedvirtual

Referenced by ensureMobilityVisualization().

90 {
91  auto it = mobilityVisualizations.find(mobility);
92  if (it == mobilityVisualizations.end())
93  return nullptr;
94  else
95  return it->second;
96 }
std::map< const IMobility *, MobilityCanvasVisualization * > mobilityVisualizations
Definition: MobilityCanvasVisualizer.h:50
void inet::visualizer::MobilityCanvasVisualizer::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::visualizer::MobilityVisualizerBase.

44 {
46  if (!hasGUI()) return;
47  if (stage == INITSTAGE_PHYSICAL_ENVIRONMENT) {
48  zIndex = par("zIndex");
50  networkNodeVisualizer = getModuleFromPar<NetworkNodeCanvasVisualizer>(par("networkNodeVisualizerModule"), this);
51  }
52 }
double zIndex
Definition: MobilityCanvasVisualizer.h:47
Physical environment initializations (mobility, obstacles, battery, annotations, etc).
Definition: InitStages.h:40
const CanvasProjection * canvasProjection
Definition: MobilityCanvasVisualizer.h:48
virtual void initialize(int stage) override
Definition: MobilityVisualizerBase.cc:36
cModule * visualizerTargetModule
Definition: VisualizerBase.h:31
NetworkNodeCanvasVisualizer * networkNodeVisualizer
Definition: MobilityCanvasVisualizer.h:49
static const CanvasProjection * getCanvasProjection(const cCanvas *canvas)
Definition: CanvasProjection.cc:38
void inet::visualizer::MobilityCanvasVisualizer::receiveSignal ( cComponent *  source,
simsignal_t  signal,
cObject *  object,
cObject *  details 
)
overridevirtual
183 {
184  Enter_Method_Silent();
186  if (moduleFilter.matches(check_and_cast<cModule *>(source)))
187  ensureMobilityVisualization(dynamic_cast<IMobility *>(source));
188  }
189  else
190  throw cRuntimeError("Unknown signal");
191 }
ModuleFilter moduleFilter
Definition: MobilityVisualizerBase.h:45
static simsignal_t mobilityStateChangedSignal
A signal used to publish mobility state changes.
Definition: IMobility.h:42
bool matches(const cModule *module) const
Definition: ModuleFilter.cc:29
virtual MobilityCanvasVisualization * ensureMobilityVisualization(IMobility *mobility)
Definition: MobilityCanvasVisualizer.cc:108
void inet::visualizer::MobilityCanvasVisualizer::refreshDisplay ( ) const
overrideprotectedvirtual
55 {
56  MobilityVisualizerBase::refreshDisplay();
57  for (auto it : mobilityVisualizations) {
58  auto mobilityVisualization = it.second;
59  auto mobility = mobilityVisualization->mobility;
60  auto position = canvasProjection->computeCanvasPoint(mobility->getCurrentPosition());
61  auto orientation = mobility->getCurrentAngularPosition();
62  auto velocity = canvasProjection->computeCanvasPoint(mobility->getCurrentSpeed());
63  mobilityVisualization->networkNodeVisualization->setTransform(cFigure::Transform().translate(position.x, position.y));
64  if (mobilityVisualization->visualRepresentation != nullptr)
65  setPosition(mobilityVisualization->visualRepresentation, position);
66  if (displayOrientations) {
67  // TODO: this doesn't correctly take canvas projection into account
68  double angle = orientation.alpha;
69  mobilityVisualization->orientationFigure->setStartAngle(angle - M_PI * orientationArcSize);
70  mobilityVisualization->orientationFigure->setEndAngle(angle + M_PI * orientationArcSize);
71  }
72  if (displayVelocities) {
73  mobilityVisualization->veloctiyFigure->setEnd(velocity * velocityArrowScale);
74  mobilityVisualization->veloctiyFigure->setVisible(velocity.getLength() != 0);
75  }
77  extendMovementTrail(mobility, mobilityVisualization->trailFigure, position);
78  }
79  visualizerTargetModule->getCanvas()->setAnimationSpeed(mobilityVisualizations.empty() ? 0 : animationSpeed, this);
80 }
std::map< const IMobility *, MobilityCanvasVisualization * > mobilityVisualizations
Definition: MobilityCanvasVisualizer.h:50
bool displayVelocities
Definition: MobilityVisualizerBase.h:53
static void setPosition(cModule *visualRepresentation, cFigure::Point position)
Definition: MobilityCanvasVisualizer.cc:193
virtual void extendMovementTrail(const IMobility *mobility, TrailFigure *trailFigure, cFigure::Point position) const
Definition: MobilityCanvasVisualizer.cc:156
const CanvasProjection * canvasProjection
Definition: MobilityCanvasVisualizer.h:48
double animationSpeed
Definition: MobilityVisualizerBase.h:44
#define M_PI
Definition: PlotFigure.cc:27
bool displayMovementTrails
Definition: MobilityVisualizerBase.h:59
double orientationArcSize
Definition: MobilityVisualizerBase.h:48
double velocityArrowScale
Definition: MobilityVisualizerBase.h:54
cModule * visualizerTargetModule
Definition: VisualizerBase.h:31
bool displayOrientations
Definition: MobilityVisualizerBase.h:47
cFigure::Point computeCanvasPoint(const Coord &point) const
Definition: CanvasProjection.cc:32
void inet::visualizer::MobilityCanvasVisualizer::removeMobilityVisualization ( const IMobility mobility)
protectedvirtual
104 {
105  mobilityVisualizations.erase(mobility);
106 }
std::map< const IMobility *, MobilityCanvasVisualization * > mobilityVisualizations
Definition: MobilityCanvasVisualizer.h:50
void inet::visualizer::MobilityCanvasVisualizer::setMobilityVisualization ( const IMobility mobility,
MobilityCanvasVisualization entry 
)
protectedvirtual

Referenced by ensureMobilityVisualization().

99 {
100  mobilityVisualizations[mobility] = entry;
101 }
std::map< const IMobility *, MobilityCanvasVisualization * > mobilityVisualizations
Definition: MobilityCanvasVisualizer.h:50
void inet::visualizer::MobilityCanvasVisualizer::setPosition ( cModule *  visualRepresentation,
cFigure::Point  position 
)
static

Referenced by refreshDisplay(), and inet::MobilityBase::updateVisualRepresentation().

194 {
195  char buf[32];
196  snprintf(buf, sizeof(buf), "%lf", position.x);
197  buf[sizeof(buf) - 1] = 0;
198  visualRepresentation->getDisplayString().setTagArg("p", 0, buf);
199  snprintf(buf, sizeof(buf), "%lf", position.y);
200  buf[sizeof(buf) - 1] = 0;
201  visualRepresentation->getDisplayString().setTagArg("p", 1, buf);
202 }

Member Data Documentation

const CanvasProjection* inet::visualizer::MobilityCanvasVisualizer::canvasProjection = nullptr
protected

Referenced by initialize(), and refreshDisplay().

std::map<const IMobility *, MobilityCanvasVisualization *> inet::visualizer::MobilityCanvasVisualizer::mobilityVisualizations
protected
NetworkNodeCanvasVisualizer* inet::visualizer::MobilityCanvasVisualizer::networkNodeVisualizer = nullptr
protected
double inet::visualizer::MobilityCanvasVisualizer::zIndex = NaN
protected

The documentation for this class was generated from the following files: