INET Framework for OMNeT++/OMNEST
inet::visualizer::LinkVisualizerBase Class Referenceabstract

#include <LinkVisualizerBase.h>

Inheritance diagram for inet::visualizer::LinkVisualizerBase:
inet::visualizer::VisualizerBase inet::visualizer::LinkCanvasVisualizerBase inet::visualizer::LinkOsgVisualizerBase inet::visualizer::DataLinkCanvasVisualizer inet::visualizer::PhysicalLinkCanvasVisualizer inet::visualizer::DataLinkOsgVisualizer inet::visualizer::PhysicalLinkOsgVisualizer

Classes

class  DirectiveResolver
 
class  LinkVisualization
 

Public Member Functions

virtual ~LinkVisualizerBase ()
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, cObject *object, cObject *details) override
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void handleParameterChange (const char *name) override
 
virtual void refreshDisplay () const override
 
virtual void subscribe ()
 
virtual void unsubscribe ()
 
virtual bool isLinkStart (cModule *module) const =0
 
virtual bool isLinkEnd (cModule *module) const =0
 
virtual const LinkVisualizationcreateLinkVisualization (cModule *source, cModule *destination, cPacket *packet) const =0
 
virtual const LinkVisualizationgetLinkVisualization (std::pair< int, int > linkVisualization)
 
virtual void addLinkVisualization (std::pair< int, int > sourceAndDestination, const LinkVisualization *linkVisualization)
 
virtual void removeLinkVisualization (const LinkVisualization *linkVisualization)
 
virtual void removeAllLinkVisualizations ()
 
virtual void setAlpha (const LinkVisualization *linkVisualization, double alpha) const =0
 
virtual cModule * getLastModule (int treeId)
 
virtual void setLastModule (int treeId, cModule *lastModule)
 
virtual void removeLastModule (int treeId)
 
virtual std::string getLinkVisualizationText (cPacket *packet) const
 
virtual void refreshLinkVisualization (const LinkVisualization *linkVisualization, cPacket *packet)
 
virtual void updateLinkVisualization (cModule *source, cModule *destination, 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

LineManagerlineManager = nullptr
 
std::map< int, int > lastModules
 Maps packet to last module. More...
 
std::map< std::pair< int, int >, const LinkVisualization * > linkVisualizations
 Maps source/destination module ids to link visualizations. More...
 
Parameters
bool displayLinks = false
 
NetworkNodeFilter nodeFilter
 
InterfaceFilter interfaceFilter
 
PacketFilter packetFilter
 
cFigure::Color lineColor
 
cFigure::LineStyle lineStyle
 
double lineWidth = NaN
 
double lineShift = NaN
 
const char * lineShiftMode = nullptr
 
double lineContactSpacing = NaN
 
const char * lineContactMode = nullptr
 
StringFormat labelFormat
 
cFigure::Font labelFont
 
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
 

Constructor & Destructor Documentation

inet::visualizer::LinkVisualizerBase::~LinkVisualizerBase ( )
virtual
48 {
49  if (displayLinks)
50  unsubscribe();
51 }

Member Function Documentation

void inet::visualizer::LinkVisualizerBase::addLinkVisualization ( std::pair< int, int >  sourceAndDestination,
const LinkVisualization linkVisualization 
)
protectedvirtual

Reimplemented in inet::visualizer::LinkCanvasVisualizerBase.

Referenced by inet::visualizer::LinkCanvasVisualizerBase::addLinkVisualization(), and updateLinkVisualization().

152 {
153  linkVisualizations[sourceAndDestination] = linkVisualization;
154 }
virtual const LinkVisualization* inet::visualizer::LinkVisualizerBase::createLinkVisualization ( cModule *  source,
cModule *  destination,
cPacket *  packet 
) const
protectedpure virtual
cModule * inet::visualizer::LinkVisualizerBase::getLastModule ( int  treeId)
protectedvirtual

Referenced by receiveSignal().

174 {
175  auto it = lastModules.find(treeId);
176  if (it == lastModules.end())
177  return nullptr;
178  else
179  return getSimulation()->getModule(it->second);
180 }
const LinkVisualizerBase::LinkVisualization * inet::visualizer::LinkVisualizerBase::getLinkVisualization ( std::pair< int, int >  linkVisualization)
protectedvirtual

Referenced by updateLinkVisualization().

146 {
147  auto it = linkVisualizations.find(linkVisualization);
148  return it == linkVisualizations.end() ? nullptr : it->second;
149 }
std::string inet::visualizer::LinkVisualizerBase::getLinkVisualizationText ( cPacket *  packet) const
protectedvirtual

Referenced by inet::visualizer::LinkCanvasVisualizerBase::createLinkVisualization(), and inet::visualizer::LinkCanvasVisualizerBase::refreshLinkVisualization().

140 {
141  DirectiveResolver directiveResolver(packet);
142  return labelFormat.formatString(&directiveResolver);
143 }
const char * formatString(IDirectiveResolver *resolver) const
Definition: StringFormat.cc:29
void inet::visualizer::LinkVisualizerBase::handleParameterChange ( const char *  name)
overrideprotectedvirtual
82 {
83  if (name != nullptr) {
84  if (!strcmp(name, "nodeFilter"))
85  nodeFilter.setPattern(par("nodeFilter"));
86  else if (!strcmp(name, "interfaceFilter"))
87  interfaceFilter.setPattern(par("interfaceFilter"));
88  else if (!strcmp(name, "packetFilter"))
89  packetFilter.setPattern(par("packetFilter"));
91  }
92 }
void setPattern(const char *pattern)
Definition: NetworkNodeFilter.cc:24
void setPattern(const char *pattern)
Definition: InterfaceFilter.cc:24
void setPattern(const char *pattern)
Definition: PacketFilter.cc:24
void inet::visualizer::LinkVisualizerBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::visualizer::VisualizerBase.

Reimplemented in inet::visualizer::LinkOsgVisualizerBase, and inet::visualizer::LinkCanvasVisualizerBase.

Referenced by inet::visualizer::LinkCanvasVisualizerBase::initialize().

54 {
56  if (!hasGUI()) return;
57  if (stage == INITSTAGE_LOCAL) {
58  displayLinks = par("displayLinks");
59  nodeFilter.setPattern(par("nodeFilter"));
60  interfaceFilter.setPattern(par("interfaceFilter"));
61  packetFilter.setPattern(par("packetFilter"));
62  lineColor = cFigure::Color(par("lineColor"));
63  lineStyle = cFigure::parseLineStyle(par("lineStyle"));
64  lineWidth = par("lineWidth");
65  lineShift = par("lineShift");
66  lineShiftMode = par("lineShiftMode");
67  lineContactSpacing = par("lineContactSpacing");
68  lineContactMode = par("lineContactMode");
69  labelFormat.parseFormat(par("labelFormat"));
70  labelFont = cFigure::parseFont(par("labelFont"));
71  labelColor = cFigure::Color(par("labelColor"));
72  fadeOutMode = par("fadeOutMode");
73  fadeOutTime = par("fadeOutTime");
74  fadeOutAnimationSpeed = par("fadeOutAnimationSpeed");
76  if (displayLinks)
77  subscribe();
78  }
79 }
void setPattern(const char *pattern)
Definition: NetworkNodeFilter.cc:24
static LineManager * getLineManager(const cCanvas *canvas)
Definition: LineManager.cc:27
void setPattern(const char *pattern)
Definition: InterfaceFilter.cc:24
virtual void initialize(int stage) override
Definition: VisualizerBase.cc:29
Local initializations.
Definition: InitStages.h:35
void setPattern(const char *pattern)
Definition: PacketFilter.cc:24
Color
Definition: DiffservUtil.h:30
void parseFormat(const char *format)
Definition: StringFormat.cc:24
cModule * visualizerTargetModule
Definition: VisualizerBase.h:31
virtual bool inet::visualizer::LinkVisualizerBase::isLinkEnd ( cModule *  module) const
protectedpure virtual
virtual bool inet::visualizer::LinkVisualizerBase::isLinkStart ( cModule *  module) const
protectedpure virtual
void inet::visualizer::LinkVisualizerBase::receiveSignal ( cComponent *  source,
simsignal_t  signal,
cObject *  object,
cObject *  details 
)
overridevirtual
210 {
211  Enter_Method_Silent();
213  if (isLinkStart(static_cast<cModule *>(source))) {
214  auto module = check_and_cast<cModule *>(source);
215  auto packet = check_and_cast<cPacket *>(object);
216  auto treeId = packet->getTreeId();
217  auto lastModule = getLastModule(treeId);
218  if (lastModule != nullptr)
219  removeLastModule(treeId);
220  auto networkNode = getContainingNode(module);
221  auto interfaceEntry = getInterfaceEntry(networkNode, module);
222  if (nodeFilter.matches(networkNode) && interfaceFilter.matches(interfaceEntry) && packetFilter.matches(packet))
223  setLastModule(treeId, module);
224  }
225  }
227  if (isLinkEnd(static_cast<cModule *>(source))) {
228  auto module = check_and_cast<cModule *>(source);
229  auto packet = check_and_cast<cPacket *>(object);
230  auto treeId = packet->getTreeId();
231  auto lastModule = getLastModule(treeId);
232  if (lastModule != nullptr) {
233  auto networkNode = getContainingNode(module);
234  auto interfaceEntry = getInterfaceEntry(networkNode, module);
235  if (nodeFilter.matches(networkNode) && interfaceFilter.matches(interfaceEntry) && packetFilter.matches(packet))
236  updateLinkVisualization(getContainingNode(lastModule), networkNode, packet);
237  // NOTE: don't call removeLastModule(treeId) because other network nodes may still receive this packet
238  }
239  }
240  }
241  else
242  throw cRuntimeError("Unknown signal");
243 }
bool matches(const cModule *module) const
Definition: NetworkNodeFilter.cc:29
virtual InterfaceEntry * getInterfaceEntry(cModule *networkNode, cModule *module) const
Definition: VisualizerBase.cc:79
static simsignal_t packetReceivedFromUpperSignal
Definition: LayeredProtocolBase.h:29
bool matches(const cPacket *packet) const
Definition: PacketFilter.cc:29
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
bool matches(const InterfaceEntry *interfaceEntry) const
Definition: InterfaceFilter.cc:29
static simsignal_t packetSentToUpperSignal
Definition: LayeredProtocolBase.h:28
void inet::visualizer::LinkVisualizerBase::refreshDisplay ( ) const
overrideprotectedvirtual

Reimplemented in inet::visualizer::LinkCanvasVisualizerBase.

Referenced by inet::visualizer::LinkCanvasVisualizerBase::refreshDisplay().

95 {
96  if (displayLinks) {
97  AnimationPosition currentAnimationPosition;
98  std::vector<const LinkVisualization *> removedLinkVisualizations;
99  for (auto it : linkVisualizations) {
100  auto linkVisualization = it.second;
101  double delta;
102  if (!strcmp(fadeOutMode, "simulationTime"))
103  delta = (currentAnimationPosition.getSimulationTime() - linkVisualization->lastUsageAnimationPosition.getSimulationTime()).dbl();
104  else if (!strcmp(fadeOutMode, "animationTime"))
105  delta = currentAnimationPosition.getAnimationTime() - linkVisualization->lastUsageAnimationPosition.getAnimationTime();
106  else if (!strcmp(fadeOutMode, "realTime"))
107  delta = currentAnimationPosition.getRealTime() - linkVisualization->lastUsageAnimationPosition.getRealTime();
108  else
109  throw cRuntimeError("Unknown fadeOutMode: %s", fadeOutMode);
110  if (delta > fadeOutTime)
111  removedLinkVisualizations.push_back(linkVisualization);
112  else
113  setAlpha(linkVisualization, 1 - delta / fadeOutTime);
114  }
115  for (auto linkVisualization : removedLinkVisualizations) {
116  const_cast<LinkVisualizerBase *>(this)->removeLinkVisualization(linkVisualization);
117  delete linkVisualization;
118  }
119  }
120 }
void inet::visualizer::LinkVisualizerBase::refreshLinkVisualization ( const LinkVisualization linkVisualization,
cPacket *  packet 
)
protectedvirtual

Reimplemented in inet::visualizer::LinkCanvasVisualizerBase.

Referenced by inet::visualizer::LinkCanvasVisualizerBase::refreshLinkVisualization(), and updateLinkVisualization().

193 {
194  linkVisualization->lastUsageAnimationPosition = AnimationPosition();
195 }
void inet::visualizer::LinkVisualizerBase::removeAllLinkVisualizations ( )
protectedvirtual

Referenced by handleParameterChange().

162 {
163  lastModules.clear();
164  std::vector<const LinkVisualization *> removedLinkVisualizations;
165  for (auto it : linkVisualizations)
166  removedLinkVisualizations.push_back(it.second);
167  for (auto it : removedLinkVisualizations) {
169  delete it;
170  }
171 }
void inet::visualizer::LinkVisualizerBase::removeLastModule ( int  treeId)
protectedvirtual

Referenced by receiveSignal().

188 {
189  lastModules.erase(lastModules.find(treeId));
190 }
void inet::visualizer::LinkVisualizerBase::removeLinkVisualization ( const LinkVisualization linkVisualization)
protectedvirtual

Reimplemented in inet::visualizer::LinkCanvasVisualizerBase.

Referenced by refreshDisplay(), removeAllLinkVisualizations(), and inet::visualizer::LinkCanvasVisualizerBase::removeLinkVisualization().

157 {
158  linkVisualizations.erase(linkVisualizations.find(std::pair<int, int>(linkVisualization->sourceModuleId, linkVisualization->destinationModuleId)));
159 }
virtual void inet::visualizer::LinkVisualizerBase::setAlpha ( const LinkVisualization linkVisualization,
double  alpha 
) const
protectedpure virtual
void inet::visualizer::LinkVisualizerBase::setLastModule ( int  treeId,
cModule *  lastModule 
)
protectedvirtual

Referenced by receiveSignal().

183 {
184  lastModules[treeId] = module->getId();
185 }
void inet::visualizer::LinkVisualizerBase::subscribe ( )
protectedvirtual

Referenced by initialize().

123 {
124  auto subscriptionModule = getModuleFromPar<cModule>(par("subscriptionModule"), this);
125  subscriptionModule->subscribe(LayeredProtocolBase::packetSentToUpperSignal, this);
126  subscriptionModule->subscribe(LayeredProtocolBase::packetReceivedFromUpperSignal, this);
127 }
static simsignal_t packetReceivedFromUpperSignal
Definition: LayeredProtocolBase.h:29
static simsignal_t packetSentToUpperSignal
Definition: LayeredProtocolBase.h:28
void inet::visualizer::LinkVisualizerBase::unsubscribe ( )
protectedvirtual

Referenced by ~LinkVisualizerBase().

130 {
131  // NOTE: lookup the module again because it may have been deleted first
132  auto subscriptionModule = getModuleFromPar<cModule>(par("subscriptionModule"), this, false);
133  if (subscriptionModule != nullptr) {
134  subscriptionModule->unsubscribe(LayeredProtocolBase::packetSentToUpperSignal, this);
135  subscriptionModule->unsubscribe(LayeredProtocolBase::packetReceivedFromUpperSignal, this);
136  }
137 }
static simsignal_t packetReceivedFromUpperSignal
Definition: LayeredProtocolBase.h:29
static simsignal_t packetSentToUpperSignal
Definition: LayeredProtocolBase.h:28
void inet::visualizer::LinkVisualizerBase::updateLinkVisualization ( cModule *  source,
cModule *  destination,
cPacket *  packet 
)
protectedvirtual

Referenced by receiveSignal().

198 {
199  auto key = std::pair<int, int>(source->getId(), destination->getId());
200  auto linkVisualization = getLinkVisualization(key);
201  if (linkVisualization == nullptr) {
202  linkVisualization = createLinkVisualization(source, destination, packet);
203  addLinkVisualization(key, linkVisualization);
204  }
205  else
206  refreshLinkVisualization(linkVisualization, packet);
207 }

Member Data Documentation

bool inet::visualizer::LinkVisualizerBase::displayLinks = false
protected
double inet::visualizer::LinkVisualizerBase::fadeOutAnimationSpeed = NaN
protected
const char* inet::visualizer::LinkVisualizerBase::fadeOutMode = nullptr
protected

Referenced by initialize(), and refreshDisplay().

double inet::visualizer::LinkVisualizerBase::fadeOutTime = NaN
protected

Referenced by initialize(), and refreshDisplay().

InterfaceFilter inet::visualizer::LinkVisualizerBase::interfaceFilter
protected
cFigure::Color inet::visualizer::LinkVisualizerBase::labelColor
protected
cFigure::Font inet::visualizer::LinkVisualizerBase::labelFont
protected
StringFormat inet::visualizer::LinkVisualizerBase::labelFormat
protected
std::map<int, int> inet::visualizer::LinkVisualizerBase::lastModules
protected

Maps packet to last module.

Referenced by getLastModule(), removeAllLinkVisualizations(), removeLastModule(), and setLastModule().

cFigure::Color inet::visualizer::LinkVisualizerBase::lineColor
protected
const char* inet::visualizer::LinkVisualizerBase::lineContactMode = nullptr
protected
double inet::visualizer::LinkVisualizerBase::lineContactSpacing = NaN
protected
double inet::visualizer::LinkVisualizerBase::lineShift = NaN
protected
const char* inet::visualizer::LinkVisualizerBase::lineShiftMode = nullptr
protected
cFigure::LineStyle inet::visualizer::LinkVisualizerBase::lineStyle
protected
double inet::visualizer::LinkVisualizerBase::lineWidth = NaN
protected
std::map<std::pair<int, int>, const LinkVisualization *> inet::visualizer::LinkVisualizerBase::linkVisualizations
protected
NetworkNodeFilter inet::visualizer::LinkVisualizerBase::nodeFilter
protected
PacketFilter inet::visualizer::LinkVisualizerBase::packetFilter
protected

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