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

#include <StatisticVisualizerBase.h>

Inheritance diagram for inet::visualizer::StatisticVisualizerBase:
inet::visualizer::VisualizerBase inet::visualizer::StatisticCanvasVisualizer inet::visualizer::StatisticOsgVisualizer

Classes

class  DirectiveResolver
 
class  LastValueRecorder
 
class  StatisticVisualization
 

Public Member Functions

virtual ~StatisticVisualizerBase ()
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, bool b, cObject *details) override
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, long l, cObject *details) override
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, unsigned long l, cObject *details) override
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, double d, cObject *details) override
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, const SimTime &t, cObject *details) override
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, const char *s, cObject *details) override
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, cObject *obj, cObject *details) override
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void handleParameterChange (const char *name) override
 
virtual void subscribe ()
 
virtual void unsubscribe ()
 
virtual cResultFilter * findResultFilter (cComponent *source, simsignal_t signal)
 
virtual cResultFilter * findResultFilter (cResultFilter *parentResultFilter, cResultListener *resultListener)
 
virtual std::string getText (const StatisticVisualization *statisticVisualization)
 
virtual const char * getUnit (cComponent *source)
 
virtual StatisticVisualizationcreateStatisticVisualization (cComponent *source, simsignal_t signal)=0
 
virtual const StatisticVisualizationgetStatisticVisualization (cComponent *source, simsignal_t signal)
 
virtual void addStatisticVisualization (const StatisticVisualization *statisticVisualization)
 
virtual void removeStatisticVisualization (const StatisticVisualization *statisticVisualization)
 
virtual void removeAllStatisticVisualizations ()
 
virtual void refreshStatisticVisualization (const StatisticVisualization *statisticVisualization)
 
virtual void processSignal (cComponent *source, simsignal_t signal, double value)
 
- 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

std::map< std::pair< int, simsignal_t >, const StatisticVisualization * > statisticVisualizations
 
Parameters
bool displayStatistics = false
 
ModuleFilter sourceFilter
 
const char * signalName = nullptr
 
const char * statisticName = nullptr
 
StringFormat format
 
std::vector< std::string > units
 
cFigure::Font font
 
cFigure::Color textColor
 
cFigure::Color backgroundColor
 
double opacity = NaN
 
Displacement displacementHint
 
double displacementPriority
 
- Protected Attributes inherited from inet::visualizer::VisualizerBase
cModule * visualizerTargetModule = nullptr
 
const char * tags = nullptr
 

Constructor & Destructor Documentation

inet::visualizer::StatisticVisualizerBase::~StatisticVisualizerBase ( )
virtual
34 {
36  unsubscribe();
37 }
bool displayStatistics
Definition: StatisticVisualizerBase.h:74
virtual void unsubscribe()
Definition: StatisticVisualizerBase.cc:108

Member Function Documentation

void inet::visualizer::StatisticVisualizerBase::addStatisticVisualization ( const StatisticVisualization statisticVisualization)
protectedvirtual

Reimplemented in inet::visualizer::StatisticCanvasVisualizer.

Referenced by inet::visualizer::StatisticCanvasVisualizer::addStatisticVisualization(), and processSignal().

176 {
177  auto key = std::pair<int, simsignal_t>(statisticVisualization->moduleId, statisticVisualization->signal);
178  statisticVisualizations[key] = statisticVisualization;
179 }
std::map< std::pair< int, simsignal_t >, const StatisticVisualization * > statisticVisualizations
Definition: StatisticVisualizerBase.h:88
virtual StatisticVisualization* inet::visualizer::StatisticVisualizerBase::createStatisticVisualization ( cComponent *  source,
simsignal_t  signal 
)
protectedpure virtual
cResultFilter * inet::visualizer::StatisticVisualizerBase::findResultFilter ( cComponent *  source,
simsignal_t  signal 
)
protectedvirtual

Referenced by findResultFilter(), and processSignal().

119 {
120  auto listeners = source->getLocalSignalListeners(signal);
121  for (auto listener : listeners) {
122  if (auto resultListener = dynamic_cast<cResultListener *>(listener)) {
123  auto foundResultFilter = findResultFilter(nullptr, resultListener);
124  if (foundResultFilter != nullptr)
125  return foundResultFilter;
126  }
127  }
128  return nullptr;
129 }
virtual cResultFilter * findResultFilter(cComponent *source, simsignal_t signal)
Definition: StatisticVisualizerBase.cc:118
cResultFilter * inet::visualizer::StatisticVisualizerBase::findResultFilter ( cResultFilter *  parentResultFilter,
cResultListener *  resultListener 
)
protectedvirtual
132 {
133  if (auto resultRecorder = dynamic_cast<cResultRecorder *>(resultListener)) {
134  if (resultRecorder->getStatisticName() == nullptr || !strcmp(statisticName, resultRecorder->getStatisticName()))
135  return parentResultFilter;
136  }
137  else if (auto resultFilter = dynamic_cast<cResultFilter *>(resultListener)) {
138  auto delegates = resultFilter->getDelegates();
139  for (auto delegate : delegates) {
140  auto foundResultFilter = findResultFilter(resultFilter, delegate);
141  if (foundResultFilter != nullptr)
142  return foundResultFilter;
143  }
144  }
145  return nullptr;
146 }
virtual cResultFilter * findResultFilter(cComponent *source, simsignal_t signal)
Definition: StatisticVisualizerBase.cc:118
const char * statisticName
Definition: StatisticVisualizerBase.h:77
const StatisticVisualizerBase::StatisticVisualization * inet::visualizer::StatisticVisualizerBase::getStatisticVisualization ( cComponent *  source,
simsignal_t  signal 
)
protectedvirtual

Referenced by processSignal().

166 {
167  auto key = std::pair<int, simsignal_t>(source->getId(), signal);
168  auto it = statisticVisualizations.find(key);
169  if (it == statisticVisualizations.end())
170  return nullptr;
171  else
172  return it->second;
173 }
std::map< std::pair< int, simsignal_t >, const StatisticVisualization * > statisticVisualizations
Definition: StatisticVisualizerBase.h:88
std::string inet::visualizer::StatisticVisualizerBase::getText ( const StatisticVisualization statisticVisualization)
protectedvirtual

Referenced by inet::visualizer::StatisticCanvasVisualizer::refreshStatisticVisualization().

149 {
150  DirectiveResolver directiveResolver(this, statisticVisualization);
151  return format.formatString(&directiveResolver);
152 }
StringFormat format
Definition: StatisticVisualizerBase.h:78
const char * formatString(IDirectiveResolver *resolver) const
Definition: StringFormat.cc:29
const char * inet::visualizer::StatisticVisualizerBase::getUnit ( cComponent *  source)
protectedvirtual

Referenced by inet::visualizer::StatisticCanvasVisualizer::createStatisticVisualization().

155 {
156  auto properties = source->getProperties();
157  for (int i = 0; i < properties->getNumProperties(); i++) {
158  auto property = properties->get(i);
159  if (!strcmp(property->getName(), "statistic") && !strcmp(property->getIndex(), statisticName))
160  return property->getValue("unit", 0);
161  }
162  return nullptr;
163 }
const char * statisticName
Definition: StatisticVisualizerBase.h:77
void inet::visualizer::StatisticVisualizerBase::handleParameterChange ( const char *  name)
overrideprotectedvirtual
91 {
92  if (name != nullptr) {
93  if (!strcmp(name, "sourceFilter"))
94  sourceFilter.setPattern(par("sourceFilter"));
95  else if (!strcmp(name, "format"))
96  format.parseFormat(par("format"));
98  }
99 }
virtual void removeAllStatisticVisualizations()
Definition: StatisticVisualizerBase.cc:187
StringFormat format
Definition: StatisticVisualizerBase.h:78
void setPattern(const char *pattern)
Definition: ModuleFilter.cc:24
void parseFormat(const char *format)
Definition: StringFormat.cc:24
ModuleFilter sourceFilter
Definition: StatisticVisualizerBase.h:75
void inet::visualizer::StatisticVisualizerBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::visualizer::VisualizerBase.

Reimplemented in inet::visualizer::StatisticOsgVisualizer, and inet::visualizer::StatisticCanvasVisualizer.

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

67 {
69  if (!hasGUI()) return;
70  if (stage == INITSTAGE_LOCAL) {
71  displayStatistics = par("displayStatistics");
72  sourceFilter.setPattern(par("sourceFilter"));
73  signalName = par("signalName");
74  statisticName = par("statisticName");
75  format.parseFormat(par("format"));
76  cStringTokenizer tokenizer(par("unit"));
77  while (tokenizer.hasMoreTokens())
78  units.push_back(tokenizer.nextToken());
79  font = cFigure::parseFont(par("font"));
80  textColor = cFigure::Color(par("textColor"));
81  backgroundColor = cFigure::Color(par("backgroundColor"));
82  opacity = par("opacity");
83  displacementHint = parseDisplacement(par("displacementHint"));
84  displacementPriority = par("displacementPriority");
86  subscribe();
87  }
88 }
const char * signalName
Definition: StatisticVisualizerBase.h:76
double opacity
Definition: StatisticVisualizerBase.h:83
bool displayStatistics
Definition: StatisticVisualizerBase.h:74
StringFormat format
Definition: StatisticVisualizerBase.h:78
void setPattern(const char *pattern)
Definition: ModuleFilter.cc:24
cFigure::Color textColor
Definition: StatisticVisualizerBase.h:81
virtual void initialize(int stage) override
Definition: VisualizerBase.cc:29
Displacement parseDisplacement(const char *s)
Definition: Displacement.cc:24
Local initializations.
Definition: InitStages.h:35
Color
Definition: DiffservUtil.h:30
void parseFormat(const char *format)
Definition: StringFormat.cc:24
double displacementPriority
Definition: StatisticVisualizerBase.h:85
cFigure::Font font
Definition: StatisticVisualizerBase.h:80
cFigure::Color backgroundColor
Definition: StatisticVisualizerBase.h:82
ModuleFilter sourceFilter
Definition: StatisticVisualizerBase.h:75
Displacement displacementHint
Definition: StatisticVisualizerBase.h:84
virtual void subscribe()
Definition: StatisticVisualizerBase.cc:101
const char * statisticName
Definition: StatisticVisualizerBase.h:77
std::vector< std::string > units
Definition: StatisticVisualizerBase.h:79
void inet::visualizer::StatisticVisualizerBase::processSignal ( cComponent *  source,
simsignal_t  signal,
double  value 
)
protectedvirtual
199 {
200  auto statisticVisualization = getStatisticVisualization(source, signal);
201  if (statisticVisualization != nullptr)
202  refreshStatisticVisualization(statisticVisualization);
203  else {
204  if (sourceFilter.matches(check_and_cast<cModule *>(source))) {
205  statisticVisualization = createStatisticVisualization(source, signal);
206  auto resultFilter = findResultFilter(source, signal);
207  statisticVisualization->recorder->setLastValue(value);
208  if (resultFilter == nullptr)
209  source->subscribe(registerSignal(signalName), statisticVisualization->recorder);
210  else
211  resultFilter->addDelegate(statisticVisualization->recorder);
212  addStatisticVisualization(statisticVisualization);
213  refreshStatisticVisualization(statisticVisualization);
214  }
215  }
216 }
virtual StatisticVisualization * createStatisticVisualization(cComponent *source, simsignal_t signal)=0
virtual void refreshStatisticVisualization(const StatisticVisualization *statisticVisualization)
Definition: StatisticVisualizerBase.cc:218
const char * signalName
Definition: StatisticVisualizerBase.h:76
virtual cResultFilter * findResultFilter(cComponent *source, simsignal_t signal)
Definition: StatisticVisualizerBase.cc:118
virtual const StatisticVisualization * getStatisticVisualization(cComponent *source, simsignal_t signal)
Definition: StatisticVisualizerBase.cc:165
virtual void addStatisticVisualization(const StatisticVisualization *statisticVisualization)
Definition: StatisticVisualizerBase.cc:175
bool matches(const cModule *module) const
Definition: ModuleFilter.cc:29
ModuleFilter sourceFilter
Definition: StatisticVisualizerBase.h:75
virtual void inet::visualizer::StatisticVisualizerBase::receiveSignal ( cComponent *  source,
simsignal_t  signal,
bool  b,
cObject *  details 
)
inlineoverridevirtual
114 { processSignal(source, signal, NaN); }
#define NaN
Definition: INETMath.h:103
virtual void processSignal(cComponent *source, simsignal_t signal, double value)
Definition: StatisticVisualizerBase.cc:198
virtual void inet::visualizer::StatisticVisualizerBase::receiveSignal ( cComponent *  source,
simsignal_t  signal,
long  l,
cObject *  details 
)
inlineoverridevirtual
115 { processSignal(source, signal, l); }
virtual void processSignal(cComponent *source, simsignal_t signal, double value)
Definition: StatisticVisualizerBase.cc:198
virtual void inet::visualizer::StatisticVisualizerBase::receiveSignal ( cComponent *  source,
simsignal_t  signal,
unsigned long  l,
cObject *  details 
)
inlineoverridevirtual
116 { processSignal(source, signal, l); }
virtual void processSignal(cComponent *source, simsignal_t signal, double value)
Definition: StatisticVisualizerBase.cc:198
virtual void inet::visualizer::StatisticVisualizerBase::receiveSignal ( cComponent *  source,
simsignal_t  signal,
double  d,
cObject *  details 
)
inlineoverridevirtual
117 { processSignal(source, signal, d); }
virtual void processSignal(cComponent *source, simsignal_t signal, double value)
Definition: StatisticVisualizerBase.cc:198
virtual void inet::visualizer::StatisticVisualizerBase::receiveSignal ( cComponent *  source,
simsignal_t  signal,
const SimTime &  t,
cObject *  details 
)
inlineoverridevirtual
118 { processSignal(source, signal, t.dbl()); }
virtual void processSignal(cComponent *source, simsignal_t signal, double value)
Definition: StatisticVisualizerBase.cc:198
virtual void inet::visualizer::StatisticVisualizerBase::receiveSignal ( cComponent *  source,
simsignal_t  signal,
const char *  s,
cObject *  details 
)
inlineoverridevirtual
119 { processSignal(source, signal, NaN); }
#define NaN
Definition: INETMath.h:103
virtual void processSignal(cComponent *source, simsignal_t signal, double value)
Definition: StatisticVisualizerBase.cc:198
virtual void inet::visualizer::StatisticVisualizerBase::receiveSignal ( cComponent *  source,
simsignal_t  signal,
cObject *  obj,
cObject *  details 
)
inlineoverridevirtual
120 { processSignal(source, signal, NaN); }
#define NaN
Definition: INETMath.h:103
virtual void processSignal(cComponent *source, simsignal_t signal, double value)
Definition: StatisticVisualizerBase.cc:198
void inet::visualizer::StatisticVisualizerBase::refreshStatisticVisualization ( const StatisticVisualization statisticVisualization)
protectedvirtual

Reimplemented in inet::visualizer::StatisticOsgVisualizer, and inet::visualizer::StatisticCanvasVisualizer.

Referenced by processSignal(), and inet::visualizer::StatisticCanvasVisualizer::refreshStatisticVisualization().

219 {
220  double value = statisticVisualization->recorder->getLastValue();
221  if (std::isnan(value) || units.empty()) {
222  statisticVisualization->printValue = value;
223  statisticVisualization->printUnit = statisticVisualization->unit == nullptr ? "" : statisticVisualization->unit;
224  }
225  else {
226  for (auto& unit : units) {
227  statisticVisualization->printUnit = unit.c_str();
228  statisticVisualization->printValue = cNEDValue::convertUnit(value, statisticVisualization->unit, statisticVisualization->printUnit);
229  if (statisticVisualization->printValue > 1)
230  break;
231  }
232  }
233 }
pow< internal::none, 0 > unit
Definition: Units.h:60
std::vector< std::string > units
Definition: StatisticVisualizerBase.h:79
void inet::visualizer::StatisticVisualizerBase::removeAllStatisticVisualizations ( )
protectedvirtual

Referenced by handleParameterChange().

188 {
189  std::vector<const StatisticVisualization *> removedStatisticVisualizations;
190  for (auto it : statisticVisualizations)
191  removedStatisticVisualizations.push_back(it.second);
192  for (auto it : removedStatisticVisualizations) {
194  delete it;
195  }
196 }
virtual void removeStatisticVisualization(const StatisticVisualization *statisticVisualization)
Definition: StatisticVisualizerBase.cc:181
std::map< std::pair< int, simsignal_t >, const StatisticVisualization * > statisticVisualizations
Definition: StatisticVisualizerBase.h:88
void inet::visualizer::StatisticVisualizerBase::removeStatisticVisualization ( const StatisticVisualization statisticVisualization)
protectedvirtual

Reimplemented in inet::visualizer::StatisticCanvasVisualizer.

Referenced by removeAllStatisticVisualizations(), and inet::visualizer::StatisticCanvasVisualizer::removeStatisticVisualization().

182 {
183  auto key = std::pair<int, simsignal_t>(statisticVisualization->moduleId, statisticVisualization->signal);
185 }
std::map< std::pair< int, simsignal_t >, const StatisticVisualization * > statisticVisualizations
Definition: StatisticVisualizerBase.h:88
void inet::visualizer::StatisticVisualizerBase::subscribe ( )
protectedvirtual

Referenced by initialize().

102 {
103  auto subscriptionModule = getModuleFromPar<cModule>(par("subscriptionModule"), this);
104  if (*signalName != '\0')
105  subscriptionModule->subscribe(registerSignal(signalName), this);
106 }
const char * signalName
Definition: StatisticVisualizerBase.h:76
void inet::visualizer::StatisticVisualizerBase::unsubscribe ( )
protectedvirtual

Referenced by ~StatisticVisualizerBase().

109 {
110  // NOTE: lookup the module again because it may have been deleted first
111  auto subscriptionModule = getModuleFromPar<cModule>(par("subscriptionModule"), this, false);
112  if (subscriptionModule != nullptr) {
113  if (*signalName != '\0')
114  subscriptionModule->unsubscribe(registerSignal(signalName), this);
115  }
116 }
const char * signalName
Definition: StatisticVisualizerBase.h:76

Member Data Documentation

cFigure::Color inet::visualizer::StatisticVisualizerBase::backgroundColor
protected
Displacement inet::visualizer::StatisticVisualizerBase::displacementHint
protected
double inet::visualizer::StatisticVisualizerBase::displacementPriority
protected
bool inet::visualizer::StatisticVisualizerBase::displayStatistics = false
protected
cFigure::Font inet::visualizer::StatisticVisualizerBase::font
protected
StringFormat inet::visualizer::StatisticVisualizerBase::format
protected
double inet::visualizer::StatisticVisualizerBase::opacity = NaN
protected
const char* inet::visualizer::StatisticVisualizerBase::signalName = nullptr
protected
ModuleFilter inet::visualizer::StatisticVisualizerBase::sourceFilter
protected
const char* inet::visualizer::StatisticVisualizerBase::statisticName = nullptr
protected
std::map<std::pair<int, simsignal_t>, const StatisticVisualization *> inet::visualizer::StatisticVisualizerBase::statisticVisualizations
protected
cFigure::Color inet::visualizer::StatisticVisualizerBase::textColor
protected
std::vector<std::string> inet::visualizer::StatisticVisualizerBase::units
protected

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