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

#include <SceneCanvasVisualizer.h>

Inheritance diagram for inet::visualizer::SceneCanvasVisualizer:
inet::visualizer::SceneVisualizerBase inet::visualizer::VisualizerBase

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void initializeAxis (double axisLength)
 
virtual void handleParameterChange (const char *name) override
 
virtual EulerAngles computeViewAngle (const char *viewAngle)
 
virtual cFigure::Point parse2D (const char *text)
 
virtual void displayDescription (const char *descriptionFigurePath)
 
- Protected Member Functions inherited from inet::visualizer::SceneVisualizerBase
virtual Box getPlaygroundBounds ()
 
- 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
 
CanvasProjection canvasProjection
 
cGroupFigure * axisLayer = nullptr
 
- Protected Attributes inherited from inet::visualizer::VisualizerBase
cModule * visualizerTargetModule = nullptr
 
const char * tags = nullptr
 

Member Function Documentation

EulerAngles inet::visualizer::SceneCanvasVisualizer::computeViewAngle ( const char *  viewAngle)
protectedvirtual

Referenced by handleParameterChange(), and initialize().

115 {
116  double x, y, z;
117  if (!strcmp(viewAngle, "x"))
118  {
119  x = 0;
120  y = M_PI / 2;
121  z = M_PI / -2;
122  }
123  else if (!strcmp(viewAngle, "y"))
124  {
125  x = M_PI / 2;
126  y = 0;
127  z = 0;
128  }
129  else if (!strcmp(viewAngle, "z"))
130  {
131  x = y = z = 0;
132  }
133  else if (!strncmp(viewAngle, "isometric", 9))
134  {
135  int v;
136  int l = strlen(viewAngle);
137  switch (l) {
138  case 9: v = 0; break;
139  case 10: v = viewAngle[9] - '0'; break;
140  case 11: v = (viewAngle[9] - '0') * 10 + viewAngle[10] - '0'; break;
141  default: throw cRuntimeError("Invalid isometric viewAngle parameter");
142  }
143  // 1st axis can point on the 2d plane in 6 directions
144  // 2nd axis can point on the 2d plane in 4 directions (the opposite direction is forbidden)
145  // 3rd axis can point on the 2d plane in 2 directions
146  // this results in 6 * 4 * 2 = 48 different configurations
147  x = math::deg2rad(45 + v % 4 * 90);
148  y = math::deg2rad(v / 24 % 2 ? 35.27 : -35.27);
149  z = math::deg2rad(30 + v / 4 % 6 * 60);
150  }
151  else if (sscanf(viewAngle, "%lf %lf %lf", &x, &y, &z) == 3)
152  {
153  x = math::deg2rad(x);
154  y = math::deg2rad(y);
155  z = math::deg2rad(z);
156  }
157  else
158  throw cRuntimeError("The viewAngle parameter must be a predefined string or a triplet representing three degrees");
159  return EulerAngles(x, y, z);
160 }
#define M_PI
Definition: PlotFigure.cc:27
double deg2rad(double deg)
Convert a degree value to radian.
Definition: INETMath.h:186
void inet::visualizer::SceneCanvasVisualizer::displayDescription ( const char *  descriptionFigurePath)
protectedvirtual

Referenced by initialize().

171 {
172  cFigure* descriptionFigure = visualizerTargetModule->getCanvas()->getFigureByPath(descriptionFigurePath);
173  if (!descriptionFigure)
174  throw cRuntimeError("Figure \"%s\" not found", descriptionFigurePath);
175  auto descriptionTextFigure = check_and_cast<cAbstractTextFigure*>(descriptionFigure);
176 
177  auto config = getEnvir()->getConfigEx();
178  const char *activeConfig = config->getActiveConfigName();
179  std::string description = std::string(activeConfig) + ": " + config->getConfigDescription(activeConfig);
180  descriptionTextFigure->setText(description.c_str());
181 }
cModule * visualizerTargetModule
Definition: VisualizerBase.h:31
void inet::visualizer::SceneCanvasVisualizer::handleParameterChange ( const char *  name)
overrideprotectedvirtual
99 {
100  if (name && !strcmp(name, "viewAngle")) {
101  canvasProjection.setRotation(Rotation(computeViewAngle(par("viewAngle"))));
102  // TODO: update all visualizers
103  }
104  else if (name && !strcmp(name, "viewScale")) {
105  canvasProjection.setScale(parse2D(par("viewScale")));
106  // TODO: update all visualizers
107  }
108  else if (name && !strcmp(name, "viewTranslation")) {
109  canvasProjection.setTranslation(parse2D(par("viewTranslation")));
110  // TODO: update all visualizers
111  }
112 }
void setScale(const cFigure::Point &scale)
Definition: CanvasProjection.h:43
void setTranslation(const cFigure::Point &translation)
Definition: CanvasProjection.h:46
void setRotation(const Rotation &rotation)
Definition: CanvasProjection.h:40
virtual EulerAngles computeViewAngle(const char *viewAngle)
Definition: SceneCanvasVisualizer.cc:114
virtual cFigure::Point parse2D(const char *text)
Definition: SceneCanvasVisualizer.cc:162
CanvasProjection canvasProjection
Definition: SceneCanvasVisualizer.h:32
void inet::visualizer::SceneCanvasVisualizer::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::visualizer::SceneVisualizerBase.

28 {
30  if (!hasGUI()) return;
31  if (stage == INITSTAGE_LOCAL) {
32  zIndex = par("zIndex");
33  cCanvas *canvas = visualizerTargetModule->getCanvas();
34  canvasProjection.setRotation(Rotation(computeViewAngle(par("viewAngle"))));
35  canvasProjection.setScale(parse2D(par("viewScale")));
36  canvasProjection.setTranslation(parse2D(par("viewTranslation")));
38  axisLayer = new cGroupFigure("axisLayer");
39  axisLayer->setZIndex(zIndex);
40  axisLayer->insertBelow(canvas->getSubmodulesLayer());
41  double axisLength = par("axisLength");
42  if (!std::isnan(axisLength))
43  initializeAxis(axisLength);
44  std::string descriptionFigurePath = par("descriptionFigure");
45  if (!descriptionFigurePath.empty())
46  displayDescription(descriptionFigurePath.c_str());
47  }
48 }
virtual void initializeAxis(double axisLength)
Definition: SceneCanvasVisualizer.cc:50
void setScale(const cFigure::Point &scale)
Definition: CanvasProjection.h:43
virtual void initialize(int stage) override
Definition: SceneVisualizerBase.cc:29
void setTranslation(const cFigure::Point &translation)
Definition: CanvasProjection.h:46
void setRotation(const Rotation &rotation)
Definition: CanvasProjection.h:40
Local initializations.
Definition: InitStages.h:35
static void setCanvasProjection(const cCanvas *canvas, const CanvasProjection *canvasProjection)
Definition: CanvasProjection.cc:47
cModule * visualizerTargetModule
Definition: VisualizerBase.h:31
virtual EulerAngles computeViewAngle(const char *viewAngle)
Definition: SceneCanvasVisualizer.cc:114
virtual void displayDescription(const char *descriptionFigurePath)
Definition: SceneCanvasVisualizer.cc:170
double zIndex
Definition: SceneCanvasVisualizer.h:31
virtual cFigure::Point parse2D(const char *text)
Definition: SceneCanvasVisualizer.cc:162
cGroupFigure * axisLayer
Definition: SceneCanvasVisualizer.h:33
CanvasProjection canvasProjection
Definition: SceneCanvasVisualizer.h:32
void inet::visualizer::SceneCanvasVisualizer::initializeAxis ( double  axisLength)
protectedvirtual

Referenced by initialize().

51 {
52  cLineFigure *xAxis = new cLineFigure("xAxis");
53  cLineFigure *yAxis = new cLineFigure("yAxis");
54  cLineFigure *zAxis = new cLineFigure("zAxis");
55  auto axisTags = std::string("axis ") + tags;
56  xAxis->setTags(axisTags.c_str());
57  yAxis->setTags(axisTags.c_str());
58  zAxis->setTags(axisTags.c_str());
59  xAxis->setTooltip("This arrow represents the X axis of the playground");
60  yAxis->setTooltip("This arrow represents the Y axis of the playground");
61  zAxis->setTooltip("This arrow represents the Z axis of the playground");
62  xAxis->setLineWidth(1);
63  yAxis->setLineWidth(1);
64  zAxis->setLineWidth(1);
65  xAxis->setEndArrowhead(cFigure::ARROW_BARBED);
66  yAxis->setEndArrowhead(cFigure::ARROW_BARBED);
67  zAxis->setEndArrowhead(cFigure::ARROW_BARBED);
68  xAxis->setZoomLineWidth(false);
69  yAxis->setZoomLineWidth(false);
70  zAxis->setZoomLineWidth(false);
74  xAxis->setEnd(canvasProjection.computeCanvasPoint(Coord(axisLength, 0, 0)));
75  yAxis->setEnd(canvasProjection.computeCanvasPoint(Coord(0, axisLength, 0)));
76  zAxis->setEnd(canvasProjection.computeCanvasPoint(Coord(0, 0, axisLength)));
77  axisLayer->addFigure(xAxis);
78  axisLayer->addFigure(yAxis);
79  axisLayer->addFigure(zAxis);
80  cLabelFigure *xLabel = new cLabelFigure("xAxisLabel");
81  cLabelFigure *yLabel = new cLabelFigure("yAxisLabel");
82  cLabelFigure *zLabel = new cLabelFigure("zAxisLabel");
83  auto axisLabelTags = std::string("axis label ") + tags;
84  xLabel->setTags(axisLabelTags.c_str());
85  yLabel->setTags(axisLabelTags.c_str());
86  zLabel->setTags(axisLabelTags.c_str());
87  xLabel->setText("X");
88  yLabel->setText("Y");
89  zLabel->setText("Z");
90  xLabel->setPosition(canvasProjection.computeCanvasPoint(Coord(axisLength, 0, 0)));
91  yLabel->setPosition(canvasProjection.computeCanvasPoint(Coord(0, axisLength, 0)));
92  zLabel->setPosition(canvasProjection.computeCanvasPoint(Coord(0, 0, axisLength)));
93  axisLayer->addFigure(xLabel);
94  axisLayer->addFigure(yLabel);
95  axisLayer->addFigure(zLabel);
96 }
const char * tags
Definition: VisualizerBase.h:32
static const Coord ZERO
Definition: Coord.h:41
cFigure::Point computeCanvasPoint(const Coord &point) const
Definition: CanvasProjection.cc:32
cGroupFigure * axisLayer
Definition: SceneCanvasVisualizer.h:33
CanvasProjection canvasProjection
Definition: SceneCanvasVisualizer.h:32
cFigure::Point inet::visualizer::SceneCanvasVisualizer::parse2D ( const char *  text)
protectedvirtual

Referenced by handleParameterChange(), and initialize().

163 {
164  double x, y;
165  if (sscanf(text, "%lf %lf", &x, &y) != 2)
166  throw cRuntimeError("The parameter must be a pair of doubles: %s", text);
167  return cFigure::Point(x, y);
168 }

Member Data Documentation

cGroupFigure* inet::visualizer::SceneCanvasVisualizer::axisLayer = nullptr
protected

Referenced by initialize(), and initializeAxis().

CanvasProjection inet::visualizer::SceneCanvasVisualizer::canvasProjection
protected
double inet::visualizer::SceneCanvasVisualizer::zIndex = NaN
protected

Referenced by initialize().


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