Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/GNEContour.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file GNEContour.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Aug 2023
17
///
18
// class used for show 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>
25
#include <utils/gui/globjects/GLIncludes.h>
26
#include <utils/gui/globjects/GUIGlObjectTypes.h>
27
#include <utils/options/OptionsCont.h>
28
#include <utils/gui/div/GUIGlobalViewObjectsHandler.h>
29
30
#include "GNEContour.h"
31
#include "GNEAttributeCarrier.h"
32
33
// ===========================================================================
34
// static members
35
// ===========================================================================
36
37
GUIDottedGeometry::DottedGeometryColor GNEContour::myDottedGeometryColor;
38
39
// ===========================================================================
40
// member method definitions
41
// ===========================================================================
42
43
GNEContour::GNEContour() :
44
myDottedGeometries(new std::vector<GUIDottedGeometry>(4)),
45
myContourBoundary(new Boundary),
46
myCalculatedShape(new PositionVector) {
47
}
48
49
50
GNEContour::~GNEContour() {
51
delete myDottedGeometries;
52
delete myContourBoundary;
53
delete myCalculatedShape;
54
}
55
56
57
Boundary
58
GNEContour::getContourBoundary() const {
59
return *myContourBoundary;
60
}
61
62
63
void
64
GNEContour::clearContour() const {
65
for (int i = 0; i < 3; i++) {
66
myDottedGeometries->at(i).clearDottedGeometry();
67
}
68
myContourBoundary->reset();
69
myCalculatedShape->clear();
70
}
71
72
73
void
74
GNEContour::calculateContourClosedShape(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
75
const GUIGlObject* glObject, const PositionVector& shape, const double layer,
76
const double scale, const GUIGlObject* boundaryParent, const bool addToSelectedObjects) const {
77
// check if we're in drawForObjectUnderCursor
78
if (s.drawForViewObjectsHandler && !gViewObjectsHandler.checkRectangleSelection(s, glObject, layer, boundaryParent)) {
79
// calculate closed shape contour
80
buildContourClosedShape(s, d, shape, scale);
81
// check if position or bondary is within closed shape
82
if (addToSelectedObjects) {
83
gViewObjectsHandler.checkShapeObject(glObject, *myCalculatedShape, *myContourBoundary, layer, nullptr);
84
}
85
}
86
}
87
88
89
void
90
GNEContour::calculateContourExtrudedShape(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
91
const GUIGlObject* glObject, const PositionVector& shape, const double layer, const double extrusionWidth,
92
const double scale, const bool closeFirstExtrem, const bool closeLastExtrem, const double offset,
93
const GNESegment* segment, const GUIGlObject* boundaryParent, const bool addToSelectedObjects) const {
94
// check if we're in drawForObjectUnderCursor
95
if (s.drawForViewObjectsHandler && !gViewObjectsHandler.checkRectangleSelection(s, glObject, layer, boundaryParent)) {
96
// calculate extruded shape
97
buildContourExtrudedShape(s, d, shape, extrusionWidth, scale, closeFirstExtrem, closeLastExtrem, offset);
98
// check if position or bondary is within extruded shape
99
if (addToSelectedObjects) {
100
gViewObjectsHandler.checkShapeObject(glObject, *myCalculatedShape, *myContourBoundary, layer, segment);
101
}
102
}
103
}
104
105
106
void
107
GNEContour::calculateContourRectangleShape(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
108
const GUIGlObject* glObject, const Position& pos, const double width, const double height, const double layer,
109
const double offsetX, const double offsetY, const double rot, const double scale, const GUIGlObject* boundaryParent) const {
110
// check if we're in drawForObjectUnderCursor
111
if (s.drawForViewObjectsHandler && !gViewObjectsHandler.checkRectangleSelection(s, glObject, layer, boundaryParent)) {
112
// calculate rectangle shape
113
buildContourRectangle(s, d, pos, width, height, offsetX, offsetY, rot, scale);
114
// check if position or bondary is within rectangle shape
115
gViewObjectsHandler.checkShapeObject(glObject, *myCalculatedShape, *myContourBoundary, layer, nullptr);
116
}
117
}
118
119
120
void
121
GNEContour::calculateContourCircleShape(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
122
const GUIGlObject* glObject, const Position& pos, double radius, const double layer,
123
const double scale, const GUIGlObject* boundaryParent) const {
124
// check if we're in drawForObjectUnderCursor
125
if (s.drawForViewObjectsHandler && !gViewObjectsHandler.checkRectangleSelection(s, glObject, layer, boundaryParent)) {
126
// calculate circle shape
127
buildContourCircle(s, d, pos, radius, scale);
128
// check if position or bondary is within circle shape
129
gViewObjectsHandler.checkCircleObject(d, glObject, pos, (radius * scale), layer);
130
}
131
}
132
133
134
void
135
GNEContour::calculateContourEdge(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
136
const GNEEdge* edge, const GUIGlObject* elementToRegister, const double layer,
137
const bool closeFirstExtrem, const bool closeLastExtrem) const {
138
// check if mouse is within two lines (only in rectangle selection mode)
139
if (s.drawForViewObjectsHandler) {
140
// calculate contour edge shape
141
buildContourEdge(s, d, edge, closeFirstExtrem, closeLastExtrem);
142
// check if position or bondary is within contour shape
143
gViewObjectsHandler.checkShapeObject(elementToRegister, *myCalculatedShape, *myContourBoundary, layer, nullptr);
144
}
145
}
146
147
148
void
149
GNEContour::calculateContourEdges(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
150
const GNEEdge* fromEdge, const GNEEdge* toEdge) const {
151
// calculate contour edges shape
152
buildContourEdges(s, d, fromEdge, toEdge);
153
}
154
155
156
void
157
GNEContour::calculateContourFirstGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
158
const GUIGlObject* glObject, const PositionVector& shape, const double layer, double radius, const double scale) const {
159
// check if we're in drawForObjectUnderCursor
160
if (s.drawForViewObjectsHandler && (shape.size() > 0)) {
161
// check position within geometry of first geometry point
162
gViewObjectsHandler.checkGeometryPoint(d, glObject, shape, 0, layer, (radius * scale));
163
}
164
}
165
166
167
void
168
GNEContour::calculateContourLastGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
169
const GUIGlObject* glObject, const PositionVector& shape, const double layer, double radius, const double scale) const {
170
// check if we're in drawForObjectUnderCursor
171
if (s.drawForViewObjectsHandler && (shape.size() > 0)) {
172
// check position within geometry of last geometry point
173
gViewObjectsHandler.checkGeometryPoint(d, glObject, shape, (int)shape.size() - 1, layer, (radius * scale));
174
}
175
}
176
177
178
void
179
GNEContour::calculateContourMiddleGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
180
const GUIGlObject* glObject, const PositionVector& shape, const double layer, double radius, const double scale) const {
181
// check if we're in drawForObjectUnderCursor
182
if (s.drawForViewObjectsHandler) {
183
// check position within geometry of middle geometry points
184
for (int i = 1; i < (int)shape.size() - 1; i++) {
185
gViewObjectsHandler.checkGeometryPoint(d, glObject, shape, i, layer, (radius * scale));
186
}
187
// also calculate position over shape
188
gViewObjectsHandler.checkPositionOverShape(d, glObject, shape, layer, (radius * scale));
189
}
190
}
191
192
193
void
194
GNEContour::calculateContourAllGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
195
const GUIGlObject* glObject, const PositionVector& shape, const double layer, double radius, const double scale,
196
const bool calculatePosOverShape) const {
197
// check if we're in drawForObjectUnderCursor
198
if (s.drawForViewObjectsHandler) {
199
// check position within geometry of middle geometry points
200
for (int i = 0; i < (int)shape.size(); i++) {
201
gViewObjectsHandler.checkGeometryPoint(d, glObject, shape, i, layer, (radius * scale));
202
}
203
// check if calculate position over shape
204
if (calculatePosOverShape) {
205
gViewObjectsHandler.checkPositionOverShape(d, glObject, shape, layer, (radius * scale));
206
}
207
}
208
}
209
210
211
void
212
GNEContour::calculateContourEdgeGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
213
const GNEEdge* edge, const double radius, const bool calculatePosOverShape, const bool firstExtrem, const bool lastExtrem) const {
214
// first check if we're in drawForObjectUnderCursor
215
if (s.drawForViewObjectsHandler && (gViewObjectsHandler.getSelectionPosition() != Position::INVALID)) {
216
// get edge geometry
217
const auto& edgeGeometry = edge->getNBEdge()->getGeometry();
218
// calculate last geometry point index
219
const int lastGeometryPointIndex = (int)edgeGeometry.size() - 1;
220
// we have two cases: if cursor is within geometry, or cursor is outher geometry
221
if (myCalculatedShape->around(gViewObjectsHandler.getSelectionPosition())) {
222
// get squared radius
223
const auto squaredRadius = (radius * radius);
224
// obtain nearest position and offset over shape
225
const auto nearestOffset = edgeGeometry.nearest_offset_to_point2D(gViewObjectsHandler.getSelectionPosition());
226
const auto nearestPos = edgeGeometry.positionAtOffset2D(nearestOffset);
227
// check position within geometry of middle geometry points
228
for (int i = 1; i < lastGeometryPointIndex; i++) {
229
if (edgeGeometry[i].distanceSquaredTo2D(nearestPos) <= squaredRadius) {
230
gViewObjectsHandler.checkGeometryPoint(d, edge, edgeGeometry, i, edge->getType(), radius);
231
}
232
}
233
// check extrems
234
if (firstExtrem) {
235
if (edgeGeometry[0].distanceSquaredTo2D(nearestPos) <= squaredRadius) {
236
gViewObjectsHandler.checkGeometryPoint(d, edge, edgeGeometry, 0, edge->getType(), radius);
237
}
238
}
239
if (lastExtrem) {
240
if (edgeGeometry[lastGeometryPointIndex].distanceSquaredTo2D(nearestPos) <= squaredRadius) {
241
gViewObjectsHandler.checkGeometryPoint(d, edge, edgeGeometry, lastGeometryPointIndex, edge->getType(), radius);
242
}
243
}
244
// if list of index is emprt, use nearestPos as pos over shape
245
if (calculatePosOverShape && gViewObjectsHandler.getSelectedGeometryPoints(edge).empty()) {
246
gViewObjectsHandler.selectPositionOverShape(edge, nearestPos, edge->getType(), nearestOffset);
247
}
248
} else {
249
// check position within geometry of middle geometry points
250
for (int i = 1; i < lastGeometryPointIndex; i++) {
251
gViewObjectsHandler.checkGeometryPoint(d, edge, edgeGeometry, i, edge->getType(), radius);
252
}
253
// check extrems
254
if (firstExtrem) {
255
gViewObjectsHandler.checkGeometryPoint(d, edge, edgeGeometry, 0, edge->getType(), radius);
256
}
257
if (lastExtrem) {
258
gViewObjectsHandler.checkGeometryPoint(d, edge, edgeGeometry, lastGeometryPointIndex, edge->getType(), radius);
259
}
260
}
261
}
262
}
263
264
265
bool
266
GNEContour::checkDrawPathContour(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
267
const GNEAttributeCarrier* AC) const {
268
// first check if draw dotted contour
269
if (s.drawForViewObjectsHandler && !s.disableDottedContours && (d <= GUIVisualizationSettings::Detail::DottedContours)) {
270
// basic contours
271
if (AC->checkDrawFromContour()) {
272
return true;
273
}
274
if (AC->checkDrawToContour()) {
275
return true;
276
}
277
if (AC->checkDrawRelatedContour()) {
278
return true;
279
}
280
if (AC->checkDrawOverContour()) {
281
return true;
282
}
283
// inspect contour
284
if (AC->checkDrawInspectContour()) {
285
return true;
286
}
287
// front contour
288
if (AC->checkDrawFrontContour()) {
289
return true;
290
}
291
// delete contour
292
if (AC->checkDrawDeleteContour()) {
293
return true;
294
}
295
// delete contour (small)
296
if (AC->checkDrawDeleteContourSmall()) {
297
return true;
298
}
299
// select contour
300
if (AC->checkDrawSelectContour()) {
301
return true;
302
}
303
// move contour
304
if (AC->checkDrawMoveContour()) {
305
return true;
306
}
307
}
308
// nothing to draw
309
return false;
310
}
311
312
313
bool
314
GNEContour::drawDottedContours(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
315
const GNEAttributeCarrier* AC, const double lineWidth, const bool addOffset) const {
316
// first check if draw dotted contour
317
if (!s.disableDottedContours && (d <= GUIVisualizationSettings::Detail::DottedContours)) {
318
// basic contours
319
if (AC->checkDrawFromContour()) {
320
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::FROM, lineWidth, addOffset);
321
}
322
if (AC->checkDrawToContour()) {
323
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::TO, lineWidth, addOffset);
324
}
325
if (AC->checkDrawRelatedContour()) {
326
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::RELATED, lineWidth, addOffset);
327
}
328
if (AC->checkDrawOverContour()) {
329
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::OVER, lineWidth, addOffset);
330
}
331
// inspect contour
332
if (AC->checkDrawInspectContour()) {
333
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::INSPECT, lineWidth, addOffset);
334
}
335
// front contour
336
if (AC->checkDrawFrontContour()) {
337
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::FRONT, lineWidth, addOffset);
338
}
339
// delete contour
340
if (AC->checkDrawDeleteContour()) {
341
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::REMOVE, lineWidth, addOffset);
342
} else if (AC->checkDrawDeleteContourSmall()) {
343
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::REMOVE, s.dottedContourSettings.segmentWidthSmall, addOffset);
344
}
345
// select contour
346
if (AC->checkDrawSelectContour()) {
347
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::SELECT, lineWidth, addOffset);
348
}
349
// move contour
350
if (AC->checkDrawMoveContour()) {
351
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::MOVE, lineWidth, addOffset);
352
}
353
return false;
354
}
355
return false;
356
}
357
358
359
void
360
GNEContour::drawDottedContourGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
361
const GNEAttributeCarrier* AC, const PositionVector& shape, const double radius,
362
const double scale, const double lineWidth) const {
363
// first check if draw dotted contour
364
if (!s.disableDottedContours && (d <= GUIVisualizationSettings::Detail::DottedContours) && AC->checkDrawMoveContour()) {
365
// get gl object
366
const auto glObject = AC->getGUIGlObject();
367
// get geometry points
368
const auto& geometryPoints = gViewObjectsHandler.getSelectedGeometryPoints(glObject);
369
// get temporal position over shape
370
const auto& posOverShape = gViewObjectsHandler.getSelectedPositionOverShape(glObject);
371
// either draw geometry points or position over shape
372
if (geometryPoints.size() > 0) {
373
// draw every geometry point
374
for (const auto& geometryPoint : geometryPoints) {
375
// create circle shape
376
const auto circleShape = GUIGeometry::getVertexCircleAroundPosition(shape[geometryPoint], radius * scale, 16);
377
// calculate dotted geometry
378
const auto dottedGeometry = GUIDottedGeometry(s, d, circleShape, true);
379
// reset dotted geometry color
380
myDottedGeometryColor.reset();
381
// Push draw matrix
382
GLHelper::pushMatrix();
383
// translate to front
384
glTranslated(0, 0, GLO_DOTTEDCONTOUR);
385
// draw dotted geometries
386
dottedGeometry.drawDottedGeometry(s, GUIDottedGeometry::DottedContourType::MOVE, myDottedGeometryColor, lineWidth, 0);
387
// pop matrix
388
GLHelper::popMatrix();
389
}
390
} else if (posOverShape != Position::INVALID) {
391
// create circle shape
392
const auto circleShape = GUIGeometry::getVertexCircleAroundPosition(posOverShape, radius * scale, 16);
393
// calculate dotted geometry
394
const auto dottedGeometry = GUIDottedGeometry(s, d, circleShape, true);
395
// reset dotted geometry color
396
myDottedGeometryColor.reset();
397
// Push draw matrix
398
GLHelper::pushMatrix();
399
// translate to front
400
glTranslated(0, 0, GLO_DOTTEDCONTOUR);
401
// draw dotted geometries
402
dottedGeometry.drawDottedGeometry(s, GUIDottedGeometry::DottedContourType::MOVE, myDottedGeometryColor, lineWidth, 0);
403
// pop matrix
404
GLHelper::popMatrix();
405
}
406
}
407
}
408
409
410
void
411
GNEContour::drawInnenContourClosed(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
412
const PositionVector& shape, const double scale, const double lineWidth) const {
413
// set calculated shape
414
*myCalculatedShape = shape;
415
// continue only if shape has at least three elements and scale isn't 0
416
if ((myCalculatedShape->size() > 2) && (scale > 0)) {
417
// scale shape
418
myCalculatedShape->scaleRelative(scale);
419
// close
420
myCalculatedShape->closePolygon();
421
// calculate geometry without resampling
422
myDottedGeometries->at(0) = GUIDottedGeometry(s, d, *myCalculatedShape, true);
423
// reset dotted geometry color
424
myDottedGeometryColor.reset();
425
// Push draw matrix
426
GLHelper::pushMatrix();
427
// draw dotted
428
myDottedGeometries->at(0).drawInnenGeometry(lineWidth);
429
// pop matrix
430
GLHelper::popMatrix();
431
}
432
}
433
434
435
bool
436
GNEContour::drawDottedContour(const GUIVisualizationSettings& s, GUIDottedGeometry::DottedContourType type,
437
const double lineWidth, const bool addOffset) const {
438
// reset dotted geometry color
439
myDottedGeometryColor.reset();
440
// Push draw matrix
441
GLHelper::pushMatrix();
442
// translate to front
443
glTranslated(0, 0, GLO_DOTTEDCONTOUR);
444
// draw dotted geometries
445
for (const auto& dottedGeometry : *myDottedGeometries) {
446
dottedGeometry.drawDottedGeometry(s, type, myDottedGeometryColor, lineWidth, addOffset);
447
}
448
// pop matrix
449
GLHelper::popMatrix();
450
return true;
451
}
452
453
454
void
455
GNEContour::buildContourClosedShape(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
456
const PositionVector& shape, const double scale) const {
457
// set calculated shape
458
*myCalculatedShape = shape;
459
// continue only if shape has at least three elements and scale isn't 0
460
if ((myCalculatedShape->size() > 2) && (scale > 0)) {
461
// scale shape
462
myCalculatedShape->scaleRelative(scale);
463
// close
464
myCalculatedShape->closePolygon();
465
// calculate dotted geometry
466
myDottedGeometries->at(0) = GUIDottedGeometry(s, d, *myCalculatedShape, true);
467
// update contour boundary
468
*myContourBoundary = myCalculatedShape->getBoxBoundary();
469
} else {
470
myContourBoundary->reset();
471
}
472
}
473
474
475
void
476
GNEContour::buildContourExtrudedShape(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
477
const PositionVector& shape, const double extrusionWidth, const double scale,
478
const bool closeFirstExtrem, const bool closeLastExtrem, const double offset) const {
479
// reset calculated shape
480
myCalculatedShape->clear();
481
// avoid empty shapes
482
if (shape.size() > 1 && (extrusionWidth > 0)) {
483
// create top and bot geometries
484
myDottedGeometries->at(0) = GUIDottedGeometry(s, d, shape, false);
485
myDottedGeometries->at(2) = GUIDottedGeometry(s, d, shape.reverse(), false);
486
// move geometries top and bot
487
myDottedGeometries->at(0).moveShapeToSide((extrusionWidth * scale * -1) + offset);
488
myDottedGeometries->at(2).moveShapeToSide((extrusionWidth * scale * -1) - offset);
489
// create left and right geometries
490
if (closeFirstExtrem) {
491
myDottedGeometries->at(3) = GUIDottedGeometry(s, d, {
492
myDottedGeometries->at(2).getBackPosition(),
493
myDottedGeometries->at(0).getFrontPosition()
494
}, false);
495
}
496
if (closeLastExtrem) {
497
myDottedGeometries->at(1) = GUIDottedGeometry(s, d, {
498
myDottedGeometries->at(0).getBackPosition(),
499
myDottedGeometries->at(2).getFrontPosition()
500
}, false);
501
}
502
for (const auto& position : myDottedGeometries->at(0).getUnresampledShape()) {
503
myCalculatedShape->push_back(position);
504
}
505
for (const auto& position : myDottedGeometries->at(2).getUnresampledShape()) {
506
myCalculatedShape->push_back(position);
507
}
508
// update contour boundary
509
*myContourBoundary = myCalculatedShape->getBoxBoundary();
510
} else {
511
myContourBoundary->reset();
512
}
513
}
514
515
516
void
517
GNEContour::buildContourRectangle(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
518
const Position& pos, const double width, const double height, const double offsetX,
519
const double offsetY, const double rot, const double scale) const {
520
// reset calculated shape
521
myCalculatedShape->clear();
522
// check sizes
523
if (((width + height) > 0) && (scale > 0)) {
524
// make rectangle
525
myCalculatedShape->push_back(Position(0 + width, 0 + height));
526
myCalculatedShape->push_back(Position(0 + width, 0 - height));
527
myCalculatedShape->push_back(Position(0 - width, 0 - height));
528
myCalculatedShape->push_back(Position(0 - width, 0 + height));
529
// move shape
530
myCalculatedShape->add(offsetX, offsetY, 0);
531
// scale
532
myCalculatedShape->scaleRelative(scale);
533
// rotate shape
534
myCalculatedShape->rotate2D(DEG2RAD((rot * -1) + 90));
535
// move to position
536
myCalculatedShape->add(pos);
537
// calculate dotted geometry
538
myDottedGeometries->at(0) = GUIDottedGeometry(s, d, *myCalculatedShape, true);
539
// update contour boundary
540
*myContourBoundary = myCalculatedShape->getBoxBoundary();
541
} else {
542
myContourBoundary->reset();
543
}
544
}
545
546
547
void
548
GNEContour::buildContourCircle(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
549
const Position& pos, double radius, const double scale) const {
550
// reset calculated shape
551
myCalculatedShape->clear();
552
// get scaled radius
553
const double scaledRadius = radius * scale;
554
// check scaled radius
555
if (scaledRadius > POSITION_EPS) {
556
// continue depending of resolution
557
if (d <= GUIVisualizationSettings::Detail::CircleResolution32) {
558
*myCalculatedShape = GUIGeometry::getVertexCircleAroundPosition(pos, scaledRadius, 16);
559
} else if (d <= GUIVisualizationSettings::Detail::CircleResolution16) {
560
*myCalculatedShape = GUIGeometry::getVertexCircleAroundPosition(pos, scaledRadius, 8);
561
} else {
562
myCalculatedShape->push_back(Position(pos.x() - radius, pos.y() - radius));
563
myCalculatedShape->push_back(Position(pos.x() - radius, pos.y() + radius));
564
myCalculatedShape->push_back(Position(pos.x() + radius, pos.y() + radius));
565
myCalculatedShape->push_back(Position(pos.x() + radius, pos.y() - radius));
566
}
567
// calculate dotted geometry
568
myDottedGeometries->at(0) = GUIDottedGeometry(s, d, *myCalculatedShape, true);
569
// update contour boundary
570
*myContourBoundary = myCalculatedShape->getBoxBoundary();
571
} else {
572
myContourBoundary->reset();
573
}
574
}
575
576
577
void
578
GNEContour::buildContourEdge(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
579
const GNEEdge* edge, const bool closeFirstExtrem, const bool closeLastExtrem) const {
580
// reset calculated shape
581
myCalculatedShape->clear();
582
// set left hand flag
583
const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
584
// obtain lanes
585
const GNELane* topLane = lefthand ? edge->getChildLanes().front() : edge->getChildLanes().back();
586
const GNELane* botLane = lefthand ? edge->getChildLanes().back() : edge->getChildLanes().front();
587
// create top and bot geometries
588
myDottedGeometries->at(0) = GUIDottedGeometry(s, d, topLane->getLaneGeometry().getShape(), false);
589
myDottedGeometries->at(2) = GUIDottedGeometry(s, d, botLane->getLaneGeometry().getShape().reverse(), false);
590
// move geometries top and bot
591
myDottedGeometries->at(0).moveShapeToSide((topLane->getDrawingConstants()->getDrawingWidth() * -1) + topLane->getDrawingConstants()->getOffset());
592
myDottedGeometries->at(2).moveShapeToSide((botLane->getDrawingConstants()->getDrawingWidth() * -1) - botLane->getDrawingConstants()->getOffset());
593
// create left and right geometries
594
if (closeFirstExtrem) {
595
myDottedGeometries->at(3) = GUIDottedGeometry(s, d, {
596
myDottedGeometries->at(2).getBackPosition(),
597
myDottedGeometries->at(0).getFrontPosition()
598
}, false);
599
}
600
if (closeLastExtrem) {
601
myDottedGeometries->at(1) = GUIDottedGeometry(s, d, {
602
myDottedGeometries->at(0).getBackPosition(),
603
myDottedGeometries->at(2).getFrontPosition()
604
}, false);
605
}
606
// update calculated shape
607
for (const auto& position : myDottedGeometries->at(0).getUnresampledShape()) {
608
myCalculatedShape->push_back(position);
609
}
610
for (const auto& position : myDottedGeometries->at(2).getUnresampledShape()) {
611
myCalculatedShape->push_back(position);
612
}
613
// update contour boundary
614
*myContourBoundary = myCalculatedShape->getBoxBoundary();
615
}
616
617
618
void
619
GNEContour::buildContourEdges(const GUIVisualizationSettings& /*s*/, const GUIVisualizationSettings::Detail /*d*/,
620
const GNEEdge* /* fromEdge */, const GNEEdge* /* toEdge */) const {
621
622
// finish
623
}
624
625
/****************************************************************************/
626
627