Eclipse SUMO - Simulation of Urban MObility
GNEContourElement.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2023 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // A abstract class contour elements
19 /****************************************************************************/
20 
21 #include <netedit/GNENet.h>
22 #include <netedit/GNEViewNet.h>
23 #include <utils/geom/GeomHelper.h>
24 #include <utils/gui/div/GLHelper.h>
28 
29 #include "GNEContourElement.h"
30 #include "GNEAttributeCarrier.h"
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
35 
37  myAC(AC),
38  myCachedPosition(new Position()),
39  myCachedShape(new PositionVector()),
40  myCachedWidth(new double(0)),
41  myCachedHeight(new double(0)),
42  myCachedRot(new double(0)),
43  myCachedScale(new double(0)),
44  myDottedGeometryColor(new GUIDottedGeometry::DottedGeometryColor()),
45  myDottedGeometryA(new GUIDottedGeometry()),
46  myDottedGeometryB(new GUIDottedGeometry()),
47  myDottedGeometryC(new GUIDottedGeometry()) {
48 }
49 
50 
52  delete myCachedPosition;
53  delete myCachedShape;
54  delete myCachedWidth;
55  delete myCachedHeight;
56  delete myCachedRot;
57  delete myCachedScale;
58  delete myDottedGeometryColor;
59  delete myDottedGeometryA;
60  delete myDottedGeometryB;
61  delete myDottedGeometryC;
62 }
63 
64 
65 void
67  const double scale, const double lineWidth) const {
68  // first check if draw dotted contour
69  if (s.drawDottedContour(scale)) {
70  // basic contours
71  if (myAC->checkDrawFromContour()) {
73  }
74  if (myAC->checkDrawToContour()) {
76  }
79  }
80  if (myAC->checkDrawOverContour()) {
82  }
83  // inspect contour
86  }
87  // front contour
88  if (myAC->checkDrawFrontContour()) {
90  }
91  // delete contour
94  }
95  // select contour
98  }
99  }
100 }
101 
102 
103 void
105  const double extrusionWidth, const double scale, const bool drawFirstExtrem,
106  const bool drawLastExtrem, const double lineWidth) const {
107  // first check if draw dotted contour
108  if (s.drawDottedContour(scale)) {
109  // basic contours
110  if (myAC->checkDrawFromContour()) {
112  scale, drawFirstExtrem, drawLastExtrem, lineWidth);
113  }
114  if (myAC->checkDrawToContour()) {
116  scale, drawFirstExtrem, drawLastExtrem, lineWidth);
117  }
118  if (myAC->checkDrawRelatedContour()) {
120  scale, drawFirstExtrem, drawLastExtrem, lineWidth);
121  }
122  if (myAC->checkDrawOverContour()) {
124  scale, drawFirstExtrem, drawLastExtrem, lineWidth);
125  }
126  // inspect contour
127  if (myAC->checkDrawInspectContour()) {
129  scale, drawFirstExtrem, drawLastExtrem, lineWidth);
130  }
131  // front contour
132  if (myAC->checkDrawFrontContour()) {
134  scale, drawFirstExtrem, drawLastExtrem, lineWidth);
135  }
136  // delete contour
137  if (myAC->checkDrawDeleteContour()) {
139  scale, drawFirstExtrem, drawLastExtrem, lineWidth);
140  }
141  // select contour
142  if (myAC->checkDrawSelectContour()) {
144  scale, drawFirstExtrem, drawLastExtrem, lineWidth);
145  }
146  }
147 }
148 
149 
150 void
152  const double height, const double offsetX, const double offsetY, const double rot,
153  const double scale, const double lineWidth) const {
154  // first check if draw dotted contour
155  if (s.drawDottedContour(scale)) {
156  // basic contours
157  if (myAC->checkDrawFromContour()) {
159  width, height, offsetX, offsetY, rot, scale, lineWidth);
160  }
161  if (myAC->checkDrawToContour()) {
163  width, height, offsetX, offsetY, rot, scale, lineWidth);
164  }
165  if (myAC->checkDrawRelatedContour()) {
167  width, height, offsetX, offsetY, rot, scale, lineWidth);
168  }
169  if (myAC->checkDrawOverContour()) {
171  width, height, offsetX, offsetY, rot, scale, lineWidth);
172  }
173  // inspect contour
174  if (myAC->checkDrawInspectContour()) {
176  width, height, offsetX, offsetY, rot, scale, lineWidth);
177  }
178  // front contour
179  if (myAC->checkDrawFrontContour()) {
181  width, height, offsetX, offsetY, rot, scale, lineWidth);
182  }
183  // delete contour
184  if (myAC->checkDrawDeleteContour()) {
186  width, height, offsetX, offsetY, rot, scale, lineWidth);
187  }
188  // select contour
189  if (myAC->checkDrawSelectContour()) {
191  width, height, offsetX, offsetY, rot, scale, lineWidth);
192  }
193  }
194 }
195 
196 
197 void
199  const double scale, const double lineWidth) const {
200  // first check if draw dotted contour
201  if (s.drawDottedContour(scale)) {
202  // basic contours
203  if (myAC->checkDrawFromContour()) {
205  }
206  if (myAC->checkDrawToContour()) {
208  }
209  if (myAC->checkDrawRelatedContour()) {
211  }
212  if (myAC->checkDrawOverContour()) {
214  }
215  // inspect contour
216  if (myAC->checkDrawInspectContour()) {
218  }
219  // front contour
220  if (myAC->checkDrawFrontContour()) {
222  }
223  // delete contour
224  if (myAC->checkDrawDeleteContour()) {
226  }
227  // select contour
228  if (myAC->checkDrawSelectContour()) {
230  }
231  }
232 }
233 
234 
235 void
236 GNEContourElement::drawDottedContourEdge(const GUIVisualizationSettings& s, const GNEEdge* edge, const bool drawFirstExtrem,
237  const bool drawLastExtrem, const double lineWidth) const {
238  // first check if draw dotted contour
239  if (s.drawDottedContour(1)) {
240  // basic contours
241  if (myAC->checkDrawFromContour()) {
243  drawFirstExtrem, drawLastExtrem, lineWidth);
244  }
245  if (myAC->checkDrawToContour()) {
247  drawFirstExtrem, drawLastExtrem, lineWidth);
248  }
249  if (myAC->checkDrawRelatedContour()) {
251  drawFirstExtrem, drawLastExtrem, lineWidth);
252  }
253  if (myAC->checkDrawOverContour()) {
255  drawFirstExtrem, drawLastExtrem, lineWidth);
256  }
257  // inspect contour
258  if (myAC->checkDrawInspectContour()) {
260  drawFirstExtrem, drawLastExtrem, lineWidth);
261  }
262  // front contour
263  if (myAC->checkDrawFrontContour()) {
265  drawFirstExtrem, drawLastExtrem, lineWidth);
266  }
267  // delete contour
268  if (myAC->checkDrawDeleteContour()) {
270  drawFirstExtrem, drawLastExtrem, lineWidth);
271  }
272  // select contour
273  if (myAC->checkDrawSelectContour()) {
275  drawFirstExtrem, drawLastExtrem, lineWidth);
276  }
277  }
278 }
279 
280 
281 void
283  const PositionVector &shape, const double scale, const double lineWidth) const {
284  // check if dotted geometry has to be updated
285  if ((*myCachedShape != shape) || (*myCachedScale != scale)) {
286  // declare scaled shape
287  PositionVector scaledShape = shape;
288  // scale shape
289  scaledShape.scaleRelative(scale);
290  // calculate dotted geometry
291  *myDottedGeometryA = GUIDottedGeometry(s, scaledShape, true);
292  // finally update cached shape
293  *myCachedShape = shape;
294  *myCachedScale = scale;
295  }
296  // reset dotted geometry color
298  // Push draw matrix
300  // translate to front
301  glTranslated(0, 0, GLO_DOTTEDCONTOUR);
302  // draw top dotted geometry
304  // pop matrix
306 }
307 
308 
309 void
311  const PositionVector &shape, const double extrusionWidth, const double scale,
312  const bool drawFirstExtrem, const bool drawLastExtrem, const double lineWidth) const {
313  // check if dotted geometry has to be updated
314  if ((*myCachedShape != shape) || (*myCachedScale != scale)) {
315  // calculate center dotted geometry
316  GUIDottedGeometry dottedGeometry(s, shape, false);
317  // make a copy of dotted geometry
318  *myDottedGeometryA = dottedGeometry;
319  *myDottedGeometryB = dottedGeometry;
320  // move geometries top and bot
321  myDottedGeometryA->moveShapeToSide(extrusionWidth * scale);
322  myDottedGeometryB->moveShapeToSide(extrusionWidth * scale * -1);
323  // invert offset of top dotted geometry
325  // calculate extremes
326  *myDottedGeometryC = GUIDottedGeometry(s, *myDottedGeometryA, drawFirstExtrem, *myDottedGeometryB, drawLastExtrem);
327  // finally update cached shape
328  *myCachedShape = shape;
329  // update scale
330  *myCachedScale = scale;
331  }
332  // reset dotted geometry color
334  // Push draw matrix
336  // translate to front
337  glTranslated(0, 0, GLO_DOTTEDCONTOUR);
338  // draw top dotted geometry
340  // reset color
342  // draw top dotted geometry
344  // change color
346  // draw extrem dotted geometry
348  // pop matrix
350 }
351 
352 
353 void
355  const Position &pos, const double width, const double height,
356  const double offsetX, const double offsetY, const double rot,
357  const double scale, const double lineWidth) const {
358  // continue depending of cached positiosn
359  if ((*myCachedPosition != pos) || (*myCachedWidth != width) || (*myCachedHeight != height) || (*myCachedRot != rot) || (*myCachedScale != scale)) {
360  // create shape
361  PositionVector rectangleShape;
362  // make rectangle
363  rectangleShape.push_back(Position(0 + width, 0 + height));
364  rectangleShape.push_back(Position(0 + width, 0 - height));
365  rectangleShape.push_back(Position(0 - width, 0 - height));
366  rectangleShape.push_back(Position(0 - width, 0 + height));
367  // move shape
368  rectangleShape.add(offsetX, offsetY, 0);
369  // rotate shape
370  rectangleShape.rotate2D(DEG2RAD((rot * -1) + 90));
371  // move to position
372  rectangleShape.add(pos);
373  // calculate dotted geometry
374  *myDottedGeometryA = GUIDottedGeometry(s, rectangleShape, true);
375  // update cached position
376  *myCachedPosition = pos;
377  // updated values
378  *myCachedWidth = width;
379  *myCachedHeight = height;
380  *myCachedRot = rot;
381  *myCachedScale = scale;
382  }
383  // reset dotted geometry color
385  // Push draw matrix
387  // translate to front
388  glTranslated(0, 0, GLO_DOTTEDCONTOUR);
389  // draw top dotted geometry
391  // pop matrix
393 }
394 
395 
396 void
398  const Position &pos, double radius, const double scale, const double lineWidth) const {
399  // continue depending of radius and scale
400  if ((*myCachedPosition != pos) || (*myCachedScale != (radius * scale))) {
401  // calculate dotted geometry
402  *myDottedGeometryA = GUIDottedGeometry(s, GUIGeometry::getVertexCircleAroundPosition(pos, radius * scale, (radius * scale) < 2? 8 : 16), true);
403  // update cached position
404  *myCachedPosition = pos;
405  // update cached scale
406  *myCachedScale = radius * scale;
407  }
408  // draw cached shape
410  // Push draw matrix
412  // translate to front
413  glTranslated(0, 0, GLO_DOTTEDCONTOUR);
414  // draw top dotted geometry
416  // pop matrix
418 }
419 
420 
421 void
423  const GNEEdge* edge, const bool drawFirstExtrem, const bool drawLastExtrem,
424  const double lineWidth) const {
425  // continue depending of lanes
426  if (edge->getLanes().size() == 1) {
427  // get lane constants
428  GNELane::LaneDrawingConstants laneDrawingConstants(s, edge->getLanes().front());
429  // draw dottes contours
430  buildAndDrawDottedContourExtruded(s, type, edge->getLanes().front()->getLaneShape(),
431  laneDrawingConstants.halfWidth, laneDrawingConstants.exaggeration,
432  drawFirstExtrem, drawLastExtrem, lineWidth);
433  } else {
434  // set left hand flag
435  const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
436  // obtain lanes
437  const GNELane* topLane = lefthand ? edge->getLanes().back() : edge->getLanes().front();
438  const GNELane* botLane = lefthand ? edge->getLanes().front() : edge->getLanes().back();
439  // create a temporal shape
440  PositionVector edgeShape = topLane->getLaneGeometry().getShape();
441  edgeShape.append(botLane->getLaneGeometry().getShape());
442  // check if recalculate dotted geometries
443  if (*myCachedShape != edgeShape) {
444  // obtain a copy of both geometries
445  *myDottedGeometryA = GUIDottedGeometry(s, topLane->getLaneGeometry().getShape(), false);
446  *myDottedGeometryB = GUIDottedGeometry(s, botLane->getLaneGeometry().getShape(), false);
447  // obtain both LaneDrawingConstants
448  GNELane::LaneDrawingConstants laneDrawingConstantsFront(s, topLane);
449  GNELane::LaneDrawingConstants laneDrawingConstantsBack(s, botLane);
450  // move shapes to side
451  myDottedGeometryA->moveShapeToSide(laneDrawingConstantsFront.halfWidth * laneDrawingConstantsFront.exaggeration);
452  myDottedGeometryB->moveShapeToSide(laneDrawingConstantsBack.halfWidth * laneDrawingConstantsBack.exaggeration * -1);
453  // invert offset of top dotted geometry
455  // calculate extremes
456  *myDottedGeometryC = GUIDottedGeometry(s, *myDottedGeometryA, drawFirstExtrem, *myDottedGeometryB, drawLastExtrem);
457  // update cached shape
458  *myCachedShape = edgeShape;
459  }
460  // reset dotted geometry color
462  // Push draw matrix
464  // translate to front
465  glTranslated(0, 0, GLO_DOTTEDCONTOUR);
466  // draw top dotted geometry
468  // reset color
470  // draw top dotted geometry
472  // change color
474  // draw extrem dotted geometry
476  // pop matrix
478  }
479 }
480 
481 /****************************************************************************/
@ GLO_DOTTEDCONTOUR
dotted contour (used in netedit)
#define DEG2RAD(x)
Definition: GeomHelper.h:35
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
virtual bool checkDrawToContour() const
check if draw from contour (magenta)
virtual bool checkDrawOverContour() const
check if draw over contour (orange)
virtual bool checkDrawRelatedContour() const
check if draw related contour (cyan)
bool checkDrawFrontContour() const
check if draw front contour (green/blue)
virtual bool checkDrawFromContour() const
check if draw from contour (green)
virtual bool checkDrawSelectContour() const =0
check if draw select contour (blue)
bool checkDrawInspectContour() const
check if draw inspect contour (black/white)
virtual bool checkDrawDeleteContour() const =0
check if draw delete contour (pink/white)
double * myCachedScale
pointer to cached scale
void buildAndDrawDottedContourExtruded(const GUIVisualizationSettings &s, GUIDottedGeometry::DottedContourType type, const PositionVector &shape, const double extrusionWidth, const double scale, const bool drawFirstExtrem, const bool drawLastExtrem, const double lineWidth) const
build and draw dotted contour extruded
GNEAttributeCarrier * myAC
pointer to AC
void drawDottedContourEdge(const GUIVisualizationSettings &s, const GNEEdge *edge, const bool drawFirstExtrem, const bool drawLastExtrem, const double lineWidth) const
draw dotted contour edge
PositionVector * myCachedShape
pointer to cached shape
void buildAndDrawDottedContourCircle(const GUIVisualizationSettings &s, GUIDottedGeometry::DottedContourType type, const Position &pos, double radius, const double scale, const double lineWidth) const
draw dotted contour circle
void drawDottedContourExtruded(const GUIVisualizationSettings &s, const PositionVector &shape, const double extrusionWidth, const double scale, const bool drawFirstExtrem, const bool drawLastExtrem, const double lineWidth) const
draw dotted contour extruded (used in elements formed by a central shape)
GUIDottedGeometry::DottedGeometryColor * myDottedGeometryColor
dotted geometry color
GUIDottedGeometry * myDottedGeometryB
pointer to dotted geometry B
void buildAndDrawDottedContourEdge(const GUIVisualizationSettings &s, GUIDottedGeometry::DottedContourType type, const GNEEdge *edge, const bool drawFirstExtrem, const bool drawLastExtrem, const double lineWidth) const
draw dotted contour edge
void buildAndDrawDottedContourClosed(const GUIVisualizationSettings &s, const GUIDottedGeometry::DottedContourType type, const PositionVector &shape, const double scale, const double lineWidth) const
draw dotted contour shape
void drawDottedContourRectangle(const GUIVisualizationSettings &s, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double scale, const double lineWidth) const
draw dotted contour (for rectangled elements)
double * myCachedRot
pointer to cached rotation
void drawDottedContourCircle(const GUIVisualizationSettings &s, const Position &pos, double radius, const double scale, const double lineWidth) const
draw dotted contour (circle)
void drawDottedContourClosed(const GUIVisualizationSettings &s, const PositionVector &shape, const double scale, const double lineWidth) const
draw dotted contour (for closed shapes)
~GNEContourElement()
destructor
GNEContourElement(GNEAttributeCarrier *AC)
Constructor.
Position * myCachedPosition
pointer to cached position
GUIDottedGeometry * myDottedGeometryC
pointer to dotted geometry C
double * myCachedWidth
pointer to cached width
void buildAndDrawDottedContourRectangle(const GUIVisualizationSettings &s, GUIDottedGeometry::DottedContourType type, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double scale, const double lineWidth) const
draw dotted contour rectangle
double * myCachedHeight
pointer to cached height
GUIDottedGeometry * myDottedGeometryA
pointer to dotted geometry A
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
const std::vector< GNELane * > & getLanes() const
returns a reference to the lane vector
Definition: GNEEdge.cpp:850
FOX-declaration.
Definition: GNELane.h:52
const double exaggeration
exaggeration
Definition: GNELane.h:62
const double halfWidth
Draw as a normal lane, and reduce width to make sure that a selected edge can still be seen.
Definition: GNELane.h:68
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
const GUIGeometry & getLaneGeometry() const
get lane geometry
Definition: GNELane.cpp:130
void reset()
rest Dotted Geometry Color
void drawDottedGeometry(const GUIVisualizationSettings &s, GUIDottedGeometry::DottedContourType type, DottedGeometryColor *dottedGeometryColor, const double lineWidth) const
draw inspected dottedShape
void moveShapeToSide(const double value)
move shape to side
void invertOffset()
invert offset of all segments
static PositionVector getVertexCircleAroundPosition(const Position &pos, const double width, const int steps=8)
get a circle around the given position
const PositionVector & getShape() const
The shape of the additional element.
Stores the information about how to visualize structures.
bool drawDottedContour(const double exaggeration) const
check if dotted contour can be drawn
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.
void append(const PositionVector &v, double sameThreshold=2.0)
void rotate2D(double angle)
void add(double xoff, double yoff, double zoff)
void scaleRelative(double factor)
enlarges/shrinks the polygon by a factor based at the centroid