Skip to content

Commit 88462be

Browse files
committed
NetworkNodeCanvasVisualization: also store the top-left coordinates of annotations for calculate correct offsets at transformation
1 parent 6746836 commit 88462be

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/inet/visualizer/canvas/scene/NetworkNodeCanvasVisualization.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ namespace visualizer {
1919
NetworkNodeCanvasVisualization::Annotation::Annotation(cFigure *figure, const cFigure::Point& size, Placement placementHint, double placementPriority) :
2020
figure(figure),
2121
bounds(cFigure::Rectangle(NaN, NaN, size.x, size.y)),
22+
topLeft(0.0, 0.0),
23+
placementHint(placementHint),
24+
placementPriority(placementPriority)
25+
{
26+
}
27+
28+
NetworkNodeCanvasVisualization::Annotation::Annotation(cFigure *figure, const cFigure::Point& topLeft, const cFigure::Point& size, Placement placementHint, double placementPriority) :
29+
figure(figure),
30+
bounds(cFigure::Rectangle(NaN, NaN, size.x, size.y)),
31+
topLeft(topLeft),
2232
placementHint(placementHint),
2333
placementPriority(placementPriority)
2434
{
@@ -56,9 +66,9 @@ void NetworkNodeCanvasVisualization::refreshDisplay()
5666
}
5767
}
5868

59-
void NetworkNodeCanvasVisualization::addAnnotation(cFigure *figure, cFigure::Point size, Placement placementHint, double placementPriority)
69+
void NetworkNodeCanvasVisualization::addAnnotation(cFigure *figure, cFigure::Rectangle bounds, Placement placementHint, double placementPriority)
6070
{
61-
annotations.push_back(Annotation(figure, size, placementHint, placementPriority));
71+
annotations.push_back(Annotation(figure, cFigure::Point(bounds.x, bounds.y), bounds.getSize(), placementHint, placementPriority));
6272
annotationFigure->addFigure(figure);
6373
isLayoutInvalid = true;
6474
}
@@ -327,7 +337,7 @@ void NetworkNodeCanvasVisualization::layout()
327337
// store position and rectangle
328338
annotation.bounds.x = bestRc.x + annotationSpacing / 2;
329339
annotation.bounds.y = bestRc.y + annotationSpacing / 2;
330-
annotation.figure->setTransform(cFigure::Transform().translate(annotation.bounds.x, annotation.bounds.y));
340+
annotation.figure->setTransform(cFigure::Transform().translate(annotation.bounds.x - annotation.topLeft.x, annotation.bounds.y - annotation.topLeft.y));
331341

332342
// delete candidate points covered by best rc
333343
for (auto j = pts.begin(); j != pts.end();) {

src/inet/visualizer/canvas/scene/NetworkNodeCanvasVisualization.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ class INET_API NetworkNodeCanvasVisualization : public NetworkNodeVisualizerBase
2222
public:
2323
cFigure *figure;
2424
cFigure::Rectangle bounds;
25+
cFigure::Point topLeft;
2526
Placement placementHint;
2627
double placementPriority;
2728

2829
public:
2930
Annotation(cFigure *figure, const cFigure::Point& size, Placement placement, double placementPriority);
31+
Annotation(cFigure *figure, const cFigure::Point& topLeft, const cFigure::Point& size, Placement placement, double placementPriority);
3032

3133
static bool comparePlacementPriority(const Annotation& a1, const Annotation& a2);
3234
};
@@ -52,7 +54,7 @@ class INET_API NetworkNodeCanvasVisualization : public NetworkNodeVisualizerBase
5254
virtual cImageFigure *getImageFigure() { return imageFigure; }
5355

5456
virtual int getNumAnnotations() const { return annotations.size(); }
55-
virtual void addAnnotation(cFigure *figure, cFigure::Point size, Placement placement = PLACEMENT_ANY, double placementPriority = 0);
57+
virtual void addAnnotation(cFigure *figure, cFigure::Rectangle bounds, Placement placement = PLACEMENT_ANY, double placementPriority = 0);
5658
virtual void removeAnnotation(cFigure *figure);
5759
virtual void removeAnnotation(int index);
5860
virtual void setAnnotationSize(cFigure *figure, cFigure::Point size);

0 commit comments

Comments
 (0)