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

#include <PathCanvasVisualizerBase.h>

Inheritance diagram for inet::visualizer::PathCanvasVisualizerBase:
inet::visualizer::PathVisualizerBase inet::visualizer::VisualizerBase inet::visualizer::NetworkRouteCanvasVisualizer inet::visualizer::TransportRouteCanvasVisualizer

Classes

class  PathCanvasVisualization
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void refreshDisplay () const override
 
virtual const PathVisualizationcreatePathVisualization (const std::vector< int > &path, cPacket *packet) const override
 
virtual void addPathVisualization (const PathVisualization *pathVisualization) override
 
virtual void removePathVisualization (const PathVisualization *pathVisualization) override
 
virtual void setAlpha (const PathVisualization *pathVisualization, double alpha) const override
 
virtual void refreshPathVisualization (const PathVisualization *pathVisualization, cPacket *packet) override
 
- Protected Member Functions inherited from inet::visualizer::PathVisualizerBase
virtual void handleParameterChange (const char *name) override
 
virtual void subscribe ()
 
virtual void unsubscribe ()
 
virtual bool isPathStart (cModule *module) const =0
 
virtual bool isPathEnd (cModule *module) const =0
 
virtual bool isPathElement (cModule *module) const =0
 
virtual const PathVisualizationgetPathVisualization (const std::vector< int > &path)
 
virtual void removeAllPathVisualizations ()
 
virtual const std::vector< int > * getIncompletePath (int treeId)
 
virtual void addToIncompletePath (int treeId, cModule *module)
 
virtual void removeIncompletePath (int treeId)
 
virtual std::string getPathVisualizationText (cPacket *packet) const
 
virtual void updatePathVisualization (const std::vector< int > &path, cPacket *packet)
 
- 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
 
cGroupFigure * pathGroup = nullptr
 
- Protected Attributes inherited from inet::visualizer::PathVisualizerBase
LineManagerlineManager = nullptr
 
std::map< int, std::vector< int > > incompletePaths
 Maps packet to module vector. More...
 
std::map< int, int > numPaths
 Maps nodes to the number of paths that go through it. More...
 
std::multimap< std::pair< int, int >, const PathVisualization * > pathVisualizations
 Maps source/destination modules to multiple paths between them. More...
 
bool displayRoutes = false
 
NetworkNodeFilter nodeFilter
 
PacketFilter packetFilter
 
ColorSet lineColorSet
 
cFigure::LineStyle lineStyle
 
double lineWidth = NaN
 
bool lineSmooth = false
 
double lineShift = NaN
 
const char * lineShiftMode = nullptr
 
double lineContactSpacing = NaN
 
const char * lineContactMode = nullptr
 
StringFormat labelFormat
 
cFigure::Font labelFont
 
const char * labelColorAsString = nullptr
 
cFigure::Color labelColor
 
const char * fadeOutMode = nullptr
 
double fadeOutTime = NaN
 
double fadeOutAnimationSpeed = NaN
 
- Protected Attributes inherited from inet::visualizer::VisualizerBase
cModule * visualizerTargetModule = nullptr
 
const char * tags = nullptr
 

Additional Inherited Members

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

Member Function Documentation

void inet::visualizer::PathCanvasVisualizerBase::addPathVisualization ( const PathVisualization pathVisualization)
overrideprotectedvirtual

Reimplemented from inet::visualizer::PathVisualizerBase.

161 {
162  PathVisualizerBase::addPathVisualization(pathVisualization);
163  auto pathCanvasVisualization = static_cast<const PathCanvasVisualization *>(pathVisualization);
164  lineManager->addModulePath(pathVisualization);
165  pathGroup->addFigure(pathCanvasVisualization->figure);
166 }
virtual void addPathVisualization(const PathVisualization *pathVisualization)
Definition: PathVisualizerBase.cc:160
cGroupFigure * pathGroup
Definition: PathCanvasVisualizerBase.h:44
LineManager * lineManager
Definition: PathVisualizerBase.h:84
void addModulePath(const ModulePath *modulePath)
Definition: LineManager.cc:86
const PathVisualizerBase::PathVisualization * inet::visualizer::PathCanvasVisualizerBase::createPathVisualization ( const std::vector< int > &  path,
cPacket *  packet 
) const
overrideprotectedvirtual

Implements inet::visualizer::PathVisualizerBase.

Reimplemented in inet::visualizer::NetworkRouteCanvasVisualizer, and inet::visualizer::TransportRouteCanvasVisualizer.

Referenced by inet::visualizer::NetworkRouteCanvasVisualizer::createPathVisualization(), and inet::visualizer::TransportRouteCanvasVisualizer::createPathVisualization().

143 {
144  auto figure = new LabeledPolylineFigure("path");
145  auto polylineFigure = figure->getPolylineFigure();
146  polylineFigure->setSmooth(lineSmooth);
147  polylineFigure->setLineWidth(lineWidth);
148  polylineFigure->setLineStyle(lineStyle);
149  polylineFigure->setEndArrowhead(cFigure::ARROW_BARBED);
150  auto lineColor = lineColorSet.getColor(pathVisualizations.size());
151  polylineFigure->setLineColor(lineColor);
152  auto labelFigure = figure->getLabelFigure();
153  labelFigure->setFont(labelFont);
154  labelFigure->setColor(isEmpty(labelColorAsString) ? lineColor : labelColor);
155  auto text = getPathVisualizationText(packet);
156  labelFigure->setText(text.c_str());
157  return new PathCanvasVisualization(path, figure);
158 }
double lineWidth
Definition: PathVisualizerBase.h:69
bool lineSmooth
Definition: PathVisualizerBase.h:70
cFigure::Font labelFont
Definition: PathVisualizerBase.h:76
bool isEmpty(const char *s)
Definition: PathVisualizerBase.h:35
std::multimap< std::pair< int, int >, const PathVisualization * > pathVisualizations
Maps source/destination modules to multiple paths between them.
Definition: PathVisualizerBase.h:96
const char * labelColorAsString
Definition: PathVisualizerBase.h:77
virtual std::string getPathVisualizationText(cPacket *packet) const
Definition: PathVisualizerBase.cc:139
cFigure::LineStyle lineStyle
Definition: PathVisualizerBase.h:68
ColorSet lineColorSet
Definition: PathVisualizerBase.h:67
cFigure::Color labelColor
Definition: PathVisualizerBase.h:78
cFigure::Color getColor(int index) const
Definition: ColorSet.cc:43
void inet::visualizer::PathCanvasVisualizerBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::visualizer::PathVisualizerBase.

74 {
76  if (!hasGUI()) return;
77  if (stage == INITSTAGE_LOCAL) {
78  zIndex = par("zIndex");
79  auto canvas = visualizerTargetModule->getCanvas();
81  pathGroup = new cGroupFigure("paths");
82  pathGroup->setZIndex(zIndex);
83  canvas->addFigure(pathGroup);
84  }
85 }
double zIndex
Definition: PathCanvasVisualizerBase.h:42
Local initializations.
Definition: InitStages.h:35
virtual void initialize(int stage) override
Definition: PathVisualizerBase.cc:53
cGroupFigure * pathGroup
Definition: PathCanvasVisualizerBase.h:44
const CanvasProjection * canvasProjection
Definition: PathCanvasVisualizerBase.h:43
cModule * visualizerTargetModule
Definition: VisualizerBase.h:31
static const CanvasProjection * getCanvasProjection(const cCanvas *canvas)
Definition: CanvasProjection.cc:38
void inet::visualizer::PathCanvasVisualizerBase::refreshDisplay ( ) const
overrideprotectedvirtual

Reimplemented from inet::visualizer::PathVisualizerBase.

88 {
90  auto simulation = getSimulation();
91  for (auto it : pathVisualizations) {
92  auto pathVisualization = it.second;
93  auto pathCanvasVisualization = static_cast<const PathCanvasVisualization *>(pathVisualization);
94  auto moduleIds = pathCanvasVisualization->moduleIds;
95  std::vector<LineSegment> segments;
96  for (int index = 1; index < moduleIds.size(); index++) {
97  auto fromModuleId = moduleIds[index - 1];
98  auto toModuleId = moduleIds[index];
99  auto fromModule = simulation->getModule(fromModuleId);
100  auto toModule = simulation->getModule(toModuleId);
101  auto fromPosition = getContactPosition(fromModule, getPosition(toModule), lineContactMode, lineContactSpacing);
102  auto toPosition = getContactPosition(toModule, getPosition(fromModule), lineContactMode, lineContactSpacing);
103  auto shift = lineManager->getLineShift(fromModuleId, toModuleId, fromPosition, toPosition, lineShiftMode, pathVisualization->shiftOffsets[index - 1]) * lineShift;
104  segments.push_back(LineSegment(fromPosition + shift, toPosition + shift));
105  }
106  std::vector<cFigure::Point> points;
107  for (int index = 0; index < segments.size(); index++) {
108  if (index == 0)
109  points.push_back(canvasProjection->computeCanvasPoint(segments[index].getPoint1()));
110  if (index > 0) {
111  auto& segment1 = segments[index - 1];
112  auto& segment2 = segments[index];
113  Coord intersection = intersectLines(segment1, segment2);
114  if (std::isfinite(intersection.x) && std::isfinite(intersection.y)) {
115  if (isPointOnSegment(segment1, intersection) && isPointOnSegment(segment2, intersection))
116  points.push_back(canvasProjection->computeCanvasPoint(intersection));
117  else {
118  double distance = segment1.getPoint2().distance(segment2.getPoint1());
119  double distance1 = intersection.distance(segment1.getPoint2());
120  double distance2 = intersection.distance(segment2.getPoint1());
121  if (distance1 + distance2 < 4 * distance)
122  points.push_back(canvasProjection->computeCanvasPoint(intersection));
123  else {
124  points.push_back(canvasProjection->computeCanvasPoint(segment1.getPoint2()));
125  points.push_back(canvasProjection->computeCanvasPoint(segment2.getPoint1()));
126  }
127  }
128  }
129  else {
130  points.push_back(canvasProjection->computeCanvasPoint(segment1.getPoint2()));
131  points.push_back(canvasProjection->computeCanvasPoint(segment2.getPoint1()));
132  }
133  }
134  if (index == segments.size() - 1)
135  points.push_back(canvasProjection->computeCanvasPoint(segments[index].getPoint2()));
136  }
137  pathCanvasVisualization->figure->setPoints(points);
138  }
139  visualizerTargetModule->getCanvas()->setAnimationSpeed(pathVisualizations.empty() ? 0 : fadeOutAnimationSpeed, this);
140 }
double fadeOutAnimationSpeed
Definition: PathVisualizerBase.h:81
double lineShift
Definition: PathVisualizerBase.h:71
const char * lineContactMode
Definition: PathVisualizerBase.h:74
const char * lineShiftMode
Definition: PathVisualizerBase.h:72
virtual Coord getContactPosition(const cModule *networkNode, const Coord &fromPosition, const char *contactMode, double contactSpacing) const
Definition: VisualizerBase.cc:54
virtual Coord getPosition(const cModule *networkNode) const
Definition: VisualizerBase.cc:42
virtual void refreshDisplay() const override
Definition: PathVisualizerBase.cc:94
Coord getLineShift(int sourceModuleId, int destinationModuleId, const Coord &sourcePosition, const Coord &destinationPosition, const char *shiftMode, int shiftOffset)
Definition: LineManager.cc:108
std::multimap< std::pair< int, int >, const PathVisualization * > pathVisualizations
Maps source/destination modules to multiple paths between them.
Definition: PathVisualizerBase.h:96
const CanvasProjection * canvasProjection
Definition: PathCanvasVisualizerBase.h:43
cModule * visualizerTargetModule
Definition: VisualizerBase.h:31
LineManager * lineManager
Definition: PathVisualizerBase.h:84
double lineContactSpacing
Definition: PathVisualizerBase.h:73
bool isPointOnSegment(const LineSegment &segment, const Coord &point)
Definition: PathCanvasVisualizerBase.cc:54
cFigure::Point computeCanvasPoint(const Coord &point) const
Definition: CanvasProjection.cc:32
void inet::visualizer::PathCanvasVisualizerBase::refreshPathVisualization ( const PathVisualization pathVisualization,
cPacket *  packet 
)
overrideprotectedvirtual

Reimplemented from inet::visualizer::PathVisualizerBase.

183 {
184  PathVisualizerBase::refreshPathVisualization(pathVisualization, packet);
185  auto pathCanvasVisualization = static_cast<const PathCanvasVisualization *>(pathVisualization);
186  auto text = getPathVisualizationText(packet);
187  pathCanvasVisualization->figure->getLabelFigure()->setText(text.c_str());
188 }
virtual void refreshPathVisualization(const PathVisualization *pathVisualization, cPacket *packet)
Definition: PathVisualizerBase.cc:224
virtual std::string getPathVisualizationText(cPacket *packet) const
Definition: PathVisualizerBase.cc:139
void inet::visualizer::PathCanvasVisualizerBase::removePathVisualization ( const PathVisualization pathVisualization)
overrideprotectedvirtual

Reimplemented from inet::visualizer::PathVisualizerBase.

169 {
171  auto pathCanvasVisualization = static_cast<const PathCanvasVisualization *>(pathVisualization);
172  lineManager->removeModulePath(pathVisualization);
173  pathGroup->removeFigure(pathCanvasVisualization->figure);
174 }
void removeModulePath(const ModulePath *modulePath)
Definition: LineManager.cc:97
cGroupFigure * pathGroup
Definition: PathCanvasVisualizerBase.h:44
LineManager * lineManager
Definition: PathVisualizerBase.h:84
virtual void removePathVisualization(const PathVisualization *pathVisualization)
Definition: PathVisualizerBase.cc:166
void inet::visualizer::PathCanvasVisualizerBase::setAlpha ( const PathVisualization pathVisualization,
double  alpha 
) const
overrideprotectedvirtual

Implements inet::visualizer::PathVisualizerBase.

177 {
178  auto pathCanvasVisualization = static_cast<const PathCanvasVisualization *>(path);
179  pathCanvasVisualization->figure->getPolylineFigure()->setLineOpacity(alpha);
180 }
const value< double, units::unit > alpha(7.2973525376e-3)

Member Data Documentation

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

Referenced by initialize(), and refreshDisplay().

cGroupFigure* inet::visualizer::PathCanvasVisualizerBase::pathGroup = nullptr
protected
double inet::visualizer::PathCanvasVisualizerBase::zIndex = NaN
protected

Referenced by initialize().


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