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

#include <NetworkNodeCanvasVisualization.h>

Inheritance diagram for inet::visualizer::NetworkNodeCanvasVisualization:

Classes

class  Annotation
 

Public Member Functions

 NetworkNodeCanvasVisualization (cModule *networkNode, double annotationSpacing, double displacementPenalty)
 
virtual void refreshDisplay () override
 
virtual void addAnnotation (cFigure *figure, cFigure::Point size, Displacement displacement=DISPLACEMENT_ANY, double displacementPriority=0)
 
virtual void removeAnnotation (cFigure *figure)
 
virtual void setAnnotationSize (cFigure *figure, cFigure::Point size)
 
virtual void setAnnotationVisible (cFigure *figure, bool visible)
 

Protected Member Functions

virtual void layout ()
 

Protected Attributes

cModule * networkNode = nullptr
 
double annotationSpacing = NaN
 
double displacementPenalty = NaN
 
bool isLayoutInvalid = false
 
cFigure::Rectangle submoduleBounds
 
std::vector< Annotationannotations
 
cPanelFigureannotationFigure = nullptr
 

Constructor & Destructor Documentation

inet::visualizer::NetworkNodeCanvasVisualization::NetworkNodeCanvasVisualization ( cModule *  networkNode,
double  annotationSpacing,
double  displacementPenalty 
)
41  :
42  cGroupFigure(networkNode->getFullName()),
46 {
47  annotationFigure = new cPanelFigure("annotation");
48  addFigure(annotationFigure);
49  submoduleBounds = getEnvir()->getSubmoduleBounds(networkNode);
50  submoduleBounds.x = -submoduleBounds.width / 2;
51  submoduleBounds.y = -submoduleBounds.height / 2;
52 }
double annotationSpacing
Definition: NetworkNodeCanvasVisualization.h:46
double displacementPenalty
Definition: NetworkNodeCanvasVisualization.h:47
cPanelFigure * annotationFigure
Definition: NetworkNodeCanvasVisualization.h:52
cFigure::Rectangle submoduleBounds
Definition: NetworkNodeCanvasVisualization.h:50
cModule * networkNode
Definition: NetworkNodeCanvasVisualization.h:45

Member Function Documentation

void inet::visualizer::NetworkNodeCanvasVisualization::addAnnotation ( cFigure *  figure,
cFigure::Point  size,
Displacement  displacement = DISPLACEMENT_ANY,
double  displacementPriority = 0 
)
virtual

Referenced by inet::visualizer::TransportConnectionCanvasVisualizer::addConnectionVisualization(), inet::visualizer::Ieee80211CanvasVisualizer::addIeee80211Visualization(), inet::visualizer::RadioCanvasVisualizer::addRadioVisualization(), and inet::visualizer::StatisticCanvasVisualizer::addStatisticVisualization().

63 {
64  annotations.push_back(Annotation(figure, size, displacementHint, displacementPriority));
65  annotationFigure->addFigure(figure);
66  isLayoutInvalid = true;
67 }
std::vector< Annotation > annotations
Definition: NetworkNodeCanvasVisualization.h:51
bool isLayoutInvalid
Definition: NetworkNodeCanvasVisualization.h:49
cPanelFigure * annotationFigure
Definition: NetworkNodeCanvasVisualization.h:52
void inet::visualizer::NetworkNodeCanvasVisualization::layout ( )
protectedvirtual

Referenced by refreshDisplay().

209 {
210  std::vector<cFigure::Rectangle> rcs; // rectangles of annotations already positioned
211  std::vector<cFigure::Point> pts; // candidate points where annotations may be positioned
212  cFigure::Rectangle extendendSubmoduleBounds = submoduleBounds;
213  extendendSubmoduleBounds.x -= annotationSpacing / 2;
214  extendendSubmoduleBounds.y -= annotationSpacing / 2;
215  extendendSubmoduleBounds.width += annotationSpacing;
216  extendendSubmoduleBounds.height += annotationSpacing;
217  rcs.push_back(extendendSubmoduleBounds);
218  pts.push_back(getTopLeft(extendendSubmoduleBounds));
219  pts.push_back(getTopCenter(extendendSubmoduleBounds));
220  pts.push_back(getTopRight(extendendSubmoduleBounds));
221  pts.push_back(getCenterLeft(extendendSubmoduleBounds));
222  pts.push_back(getCenterRight(extendendSubmoduleBounds));
223  pts.push_back(getBottomLeft(extendendSubmoduleBounds));
224  pts.push_back(getBottomCenter(extendendSubmoduleBounds));
225  pts.push_back(getBottomRight(extendendSubmoduleBounds));
226 
228 
229  // delete all annotation positions
230  for (auto it = annotations.begin(); it != annotations.end(); it++) {
231  auto& annotation = *it;
232  annotation.bounds.x = NaN;
233  annotation.bounds.y = NaN;
234  }
235 
236  for (auto it = annotations.begin(); it != annotations.end(); it++) {
237  auto& annotation = *it;
238  if (!annotation.figure->isVisible())
239  continue;
240  cFigure::Point rs = cFigure::Point(annotation.bounds.width + annotationSpacing, annotation.bounds.height + annotationSpacing);
241 
242  // find the best minimizing the distance cost function
243  double bestDistance = std::numeric_limits<double>::infinity();
244  cFigure::Rectangle bestRc;
245 
246  // for all candidate points
247  for (int j = 0; j < (int)pts.size(); j++) {
248  cFigure::Point pt = pts[j];
249 
250  // align annotation to candidate points with its various points
251  for (int k = 0; k < 8; k++) {
252  cFigure::Rectangle candidateRc;
253  switch (k) {
254  case 0:
255  // candidate point is top left
256  candidateRc = createRectangle(pt - cFigure::Point(0, 0), rs);
257  break;
258  case 1:
259  // candidate point is top center
260  candidateRc = createRectangle(pt - cFigure::Point(rs.x / 2, 0), rs);
261  break;
262  case 2:
263  // candidate point is top right
264  candidateRc = createRectangle(pt - cFigure::Point(rs.x, 0), rs);
265  break;
266  case 3:
267  // candidate point is center left
268  candidateRc = createRectangle(pt - cFigure::Point(0, rs.y / 2), rs);
269  break;
270  case 4:
271  // candidate point is center right
272  candidateRc = createRectangle(pt - cFigure::Point(rs.x, rs.y / 2), rs);
273  break;
274  case 5:
275  // candidate point is bottom left
276  candidateRc = createRectangle(pt - cFigure::Point(0, rs.y), rs);
277  break;
278  case 6:
279  // candidate point is bottom center
280  candidateRc = createRectangle(pt - cFigure::Point(rs.x / 2, rs.y), rs);
281  break;
282  case 7:
283  // candidate point is bottom right
284  candidateRc = createRectangle(pt - cFigure::Point(rs.x, rs.y), rs);
285  break;
286  }
287 
288  double distance = 0;
289  distance += getClosestDisplacementDistance(submoduleBounds, annotation.displacementHint, getTopLeft(candidateRc)) * displacementPenalty;
290  distance += getClosestDisplacementDistance(submoduleBounds, annotation.displacementHint, getTopRight(candidateRc)) * displacementPenalty;
291  distance += getClosestDisplacementDistance(submoduleBounds, annotation.displacementHint, getBottomLeft(candidateRc)) * displacementPenalty;
292  distance += getClosestDisplacementDistance(submoduleBounds, annotation.displacementHint, getBottomRight(candidateRc)) * displacementPenalty;
293 
294  // find an already positioned annotation which would intersect the candidate rectangle
295  bool intersects = false;
296  for (int l = 0; l < (int)rcs.size(); l++) {
297  cFigure::Rectangle rc = rcs[l];
298  if (intersectsRectangle(candidateRc, rc)) {
299  intersects = true;
300  break;
301  }
302  }
303  if (intersects)
304  continue;
305 
306  // if better than the current best
307  distance += getCenterCenter(submoduleBounds).distanceTo(getCenterCenter(candidateRc));
308  if (distance < bestDistance) {
309  bestRc = candidateRc;
310  bestDistance = distance;
311  if (distance == 0)
312  goto found;
313  }
314  }
315  }
316 
317  found:
318  // store position and rectangle
319  annotation.bounds.x = bestRc.x + annotationSpacing / 2;
320  annotation.bounds.y = bestRc.y + annotationSpacing / 2;
321  annotation.figure->setTransform(cFigure::Transform().translate(annotation.bounds.x, annotation.bounds.y));
322 
323  // delete candidate points covered by best rc
324  for (int j = 0; j < (int)pts.size(); j++) {
325  cFigure::Point pt = pts[j];
326 
327  if (containsPoint(bestRc, pt))
328  pts.erase(pts.begin() + j--);
329  }
330 
331  // push new candidates
332  pushUnlessContains(pts, rcs, getTopLeft(bestRc));
333  pushUnlessContains(pts, rcs, getTopCenter(bestRc));
334  pushUnlessContains(pts, rcs, getTopRight(bestRc));
335  pushUnlessContains(pts, rcs, getCenterLeft(bestRc));
336  pushUnlessContains(pts, rcs, getCenterRight(bestRc));
337  pushUnlessContains(pts, rcs, getBottomLeft(bestRc));
338  pushUnlessContains(pts, rcs, getBottomCenter(bestRc));
339  pushUnlessContains(pts, rcs, getBottomRight(bestRc));
340 
341  rcs.push_back(bestRc);
342  }
343 }
double annotationSpacing
Definition: NetworkNodeCanvasVisualization.h:46
#define NaN
Definition: INETMath.h:103
std::vector< Annotation > annotations
Definition: NetworkNodeCanvasVisualization.h:51
void sort(std::vector< T > &v)
Definition: stlutils.h:112
static bool compareDisplacementPriority(const Annotation &a1, const Annotation &a2)
Definition: NetworkNodeCanvasVisualization.cc:204
double displacementPenalty
Definition: NetworkNodeCanvasVisualization.h:47
cFigure::Rectangle submoduleBounds
Definition: NetworkNodeCanvasVisualization.h:50
const double k
Definition: QAM16Modulation.cc:24
void inet::visualizer::NetworkNodeCanvasVisualization::refreshDisplay ( )
overridevirtual
55 {
56  if (isLayoutInvalid) {
57  layout();
58  isLayoutInvalid = false;
59  }
60 }
virtual void layout()
Definition: NetworkNodeCanvasVisualization.cc:208
bool isLayoutInvalid
Definition: NetworkNodeCanvasVisualization.h:49
void inet::visualizer::NetworkNodeCanvasVisualization::removeAnnotation ( cFigure *  figure)
virtual

Referenced by inet::visualizer::MediumCanvasVisualizer::radioRemoved(), inet::visualizer::TransportConnectionCanvasVisualizer::removeConnectionVisualization(), inet::visualizer::Ieee80211CanvasVisualizer::removeIeee80211Visualization(), inet::visualizer::RadioCanvasVisualizer::removeRadioVisualization(), and inet::visualizer::StatisticCanvasVisualizer::removeStatisticVisualization().

70 {
71  for (auto it = annotations.begin(); it != annotations.end(); it++) {
72  auto& annotation = *it;
73  if (annotation.figure == figure) {
74  annotations.erase(it);
75  break;
76  }
77  }
78  annotationFigure->removeFigure(figure);
79  isLayoutInvalid = true;
80 }
std::vector< Annotation > annotations
Definition: NetworkNodeCanvasVisualization.h:51
bool isLayoutInvalid
Definition: NetworkNodeCanvasVisualization.h:49
cPanelFigure * annotationFigure
Definition: NetworkNodeCanvasVisualization.h:52
void inet::visualizer::NetworkNodeCanvasVisualization::setAnnotationSize ( cFigure *  figure,
cFigure::Point  size 
)
virtual
83 {
84  for (auto it = annotations.begin(); it != annotations.end(); it++) {
85  auto& annotation = *it;
86  if (annotation.figure == figure) {
87  annotation.bounds.width = size.x;
88  annotation.bounds.height = size.y;
89  break;
90  }
91  }
92  isLayoutInvalid = true;
93 }
std::vector< Annotation > annotations
Definition: NetworkNodeCanvasVisualization.h:51
bool isLayoutInvalid
Definition: NetworkNodeCanvasVisualization.h:49
void inet::visualizer::NetworkNodeCanvasVisualization::setAnnotationVisible ( cFigure *  figure,
bool  visible 
)
virtual

Member Data Documentation

cPanelFigure* inet::visualizer::NetworkNodeCanvasVisualization::annotationFigure = nullptr
protected
std::vector<Annotation> inet::visualizer::NetworkNodeCanvasVisualization::annotations
protected
double inet::visualizer::NetworkNodeCanvasVisualization::annotationSpacing = NaN
protected

Referenced by layout().

double inet::visualizer::NetworkNodeCanvasVisualization::displacementPenalty = NaN
protected

Referenced by layout().

bool inet::visualizer::NetworkNodeCanvasVisualization::isLayoutInvalid = false
protected
cModule* inet::visualizer::NetworkNodeCanvasVisualization::networkNode = nullptr
protected
cFigure::Rectangle inet::visualizer::NetworkNodeCanvasVisualization::submoduleBounds
protected

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