Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/GNEContour.cpp
193723 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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,
159
const bool forceCalculation) const {
160
// check if we're in drawForObjectUnderCursor
161
if ((s.drawForViewObjectsHandler || forceCalculation) && (shape.size() > 0)) {
162
// check position within geometry of first geometry point
163
gViewObjectsHandler.checkGeometryPoint(d, glObject, shape, 0, layer, (radius * scale));
164
}
165
}
166
167
168
void
169
GNEContour::calculateContourLastGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
170
const GUIGlObject* glObject, const PositionVector& shape, const double layer, double radius, const double scale,
171
const bool forceCalculation) const {
172
// check if we're in drawForObjectUnderCursor
173
if ((s.drawForViewObjectsHandler || forceCalculation) && (shape.size() > 0)) {
174
// check position within geometry of last geometry point
175
gViewObjectsHandler.checkGeometryPoint(d, glObject, shape, (int)shape.size() - 1, layer, (radius * scale));
176
}
177
}
178
179
180
void
181
GNEContour::calculateContourMiddleGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
182
const GUIGlObject* glObject, const PositionVector& shape, const double layer, double radius, const double scale) const {
183
// check if we're in drawForObjectUnderCursor
184
if (s.drawForViewObjectsHandler) {
185
// check position within geometry of middle geometry points
186
for (int i = 1; i < (int)shape.size() - 1; i++) {
187
gViewObjectsHandler.checkGeometryPoint(d, glObject, shape, i, layer, (radius * scale));
188
}
189
// also calculate position over shape
190
gViewObjectsHandler.checkPositionOverShape(d, glObject, shape, layer, (radius * scale));
191
}
192
}
193
194
195
void
196
GNEContour::calculateContourAllGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
197
const GUIGlObject* glObject, const PositionVector& shape, const double layer, double radius, const double scale,
198
const bool calculatePosOverShape) const {
199
// check if we're in drawForObjectUnderCursor
200
if (s.drawForViewObjectsHandler) {
201
// check position within geometry of middle geometry points
202
for (int i = 0; i < (int)shape.size(); i++) {
203
gViewObjectsHandler.checkGeometryPoint(d, glObject, shape, i, layer, (radius * scale));
204
}
205
// check if calculate position over shape
206
if (calculatePosOverShape) {
207
gViewObjectsHandler.checkPositionOverShape(d, glObject, shape, layer, (radius * scale));
208
}
209
}
210
}
211
212
213
void
214
GNEContour::calculateContourEdgeGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
215
const GNEEdge* edge, const double radius, const bool calculatePosOverShape, const bool firstExtrem, const bool lastExtrem) const {
216
// first check if we're in drawForObjectUnderCursor
217
if (s.drawForViewObjectsHandler && (gViewObjectsHandler.getSelectionPosition() != Position::INVALID)) {
218
// get edge geometry
219
const auto& edgeGeometry = edge->getNBEdge()->getGeometry();
220
// calculate last geometry point index
221
const int lastGeometryPointIndex = (int)edgeGeometry.size() - 1;
222
// we have two cases: if cursor is within geometry, or cursor is outher geometry
223
if (myCalculatedShape->around(gViewObjectsHandler.getSelectionPosition())) {
224
// get squared radius
225
const auto squaredRadius = (radius * radius);
226
// obtain nearest position and offset over shape
227
const auto nearestOffset = edgeGeometry.nearest_offset_to_point2D(gViewObjectsHandler.getSelectionPosition());
228
const auto nearestPos = edgeGeometry.positionAtOffset2D(nearestOffset);
229
// check position within geometry of middle geometry points
230
for (int i = 1; i < lastGeometryPointIndex; i++) {
231
if (edgeGeometry[i].distanceSquaredTo2D(nearestPos) <= squaredRadius) {
232
gViewObjectsHandler.checkGeometryPoint(d, edge, edgeGeometry, i, edge->getType(), radius);
233
}
234
}
235
// check extrems
236
if (firstExtrem) {
237
if (edgeGeometry[0].distanceSquaredTo2D(nearestPos) <= squaredRadius) {
238
gViewObjectsHandler.checkGeometryPoint(d, edge, edgeGeometry, 0, edge->getType(), radius);
239
}
240
}
241
if (lastExtrem) {
242
if (edgeGeometry[lastGeometryPointIndex].distanceSquaredTo2D(nearestPos) <= squaredRadius) {
243
gViewObjectsHandler.checkGeometryPoint(d, edge, edgeGeometry, lastGeometryPointIndex, edge->getType(), radius);
244
}
245
}
246
// if list of index is emprt, use nearestPos as pos over shape
247
if (calculatePosOverShape && gViewObjectsHandler.getSelectedGeometryPoints(edge).empty()) {
248
gViewObjectsHandler.selectPositionOverShape(edge, nearestPos, edge->getType(), nearestOffset);
249
}
250
} else {
251
// check position within geometry of middle geometry points
252
for (int i = 1; i < lastGeometryPointIndex; i++) {
253
gViewObjectsHandler.checkGeometryPoint(d, edge, edgeGeometry, i, edge->getType(), radius);
254
}
255
// check extrems
256
if (firstExtrem) {
257
gViewObjectsHandler.checkGeometryPoint(d, edge, edgeGeometry, 0, edge->getType(), radius);
258
}
259
if (lastExtrem) {
260
gViewObjectsHandler.checkGeometryPoint(d, edge, edgeGeometry, lastGeometryPointIndex, edge->getType(), radius);
261
}
262
}
263
}
264
}
265
266
267
bool
268
GNEContour::checkDrawPathContour(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
269
const GNEAttributeCarrier* AC) const {
270
// first check if draw dotted contour
271
if (s.drawForViewObjectsHandler && !s.disableDottedContours && (d <= GUIVisualizationSettings::Detail::DottedContours)) {
272
// basic contours
273
if (AC->checkDrawFromContour()) {
274
return true;
275
}
276
if (AC->checkDrawToContour()) {
277
return true;
278
}
279
if (AC->checkDrawRelatedContour()) {
280
return true;
281
}
282
if (AC->checkDrawOverContour()) {
283
return true;
284
}
285
// inspect contour
286
if (AC->checkDrawInspectContour()) {
287
return true;
288
}
289
// front contour
290
if (AC->checkDrawFrontContour()) {
291
return true;
292
}
293
// delete contour
294
if (AC->checkDrawDeleteContour()) {
295
return true;
296
}
297
// delete contour (small)
298
if (AC->checkDrawDeleteContourSmall()) {
299
return true;
300
}
301
// select contour
302
if (AC->checkDrawSelectContour()) {
303
return true;
304
}
305
// move contour
306
if (AC->checkDrawMoveContour()) {
307
return true;
308
}
309
}
310
// nothing to draw
311
return false;
312
}
313
314
315
bool
316
GNEContour::drawDottedContours(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
317
const GNEAttributeCarrier* AC, const double lineWidth, const bool addOffset) const {
318
// first check if draw dotted contour
319
if (!s.disableDottedContours && (d <= GUIVisualizationSettings::Detail::DottedContours)) {
320
// basic contours
321
if (AC->checkDrawFromContour()) {
322
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::FROM, lineWidth, addOffset);
323
}
324
if (AC->checkDrawToContour()) {
325
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::TO, lineWidth, addOffset);
326
}
327
if (AC->checkDrawRelatedContour()) {
328
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::RELATED, lineWidth, addOffset);
329
}
330
if (AC->checkDrawOverContour()) {
331
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::OVER, lineWidth, addOffset);
332
}
333
// inspect contour
334
if (AC->checkDrawInspectContour()) {
335
drawDottedContour(s, GUIDottedGeometry::DottedContourType::INSPECT, lineWidth, addOffset);
336
if (AC->checkDrawFrontContour()) {
337
drawDottedContour(s, GUIDottedGeometry::DottedContourType::FRONT, s.dottedContourSettings.segmentWidthSmall * 0.5, addOffset, 0.1);
338
}
339
return true;
340
}
341
// front contour
342
if (AC->checkDrawFrontContour()) {
343
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::FRONT, lineWidth, addOffset);
344
}
345
// delete contour
346
if (AC->checkDrawDeleteContour()) {
347
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::REMOVE, lineWidth, addOffset);
348
} else if (AC->checkDrawDeleteContourSmall()) {
349
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::REMOVE, s.dottedContourSettings.segmentWidthSmall, addOffset);
350
}
351
// select contour
352
if (AC->checkDrawSelectContour()) {
353
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::SELECT, lineWidth, addOffset);
354
}
355
// move contour
356
if (AC->checkDrawMoveContour()) {
357
return drawDottedContour(s, GUIDottedGeometry::DottedContourType::MOVE, lineWidth, addOffset);
358
}
359
return false;
360
}
361
return false;
362
}
363
364
365
void
366
GNEContour::drawDottedContourGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
367
const GNEAttributeCarrier* AC, const PositionVector& shape, const double radius,
368
const double scale, const double lineWidth) const {
369
// first check if draw dotted contour
370
if (!s.disableDottedContours && (d <= GUIVisualizationSettings::Detail::DottedContours) && AC->checkDrawMoveContour()) {
371
// get gl object
372
const auto glObject = AC->getGUIGlObject();
373
// get geometry points
374
const auto& geometryPoints = gViewObjectsHandler.getSelectedGeometryPoints(glObject);
375
// get temporal position over shape
376
const auto& posOverShape = gViewObjectsHandler.getSelectedPositionOverShape(glObject);
377
// either draw geometry points or position over shape
378
if (geometryPoints.size() > 0) {
379
// draw every geometry point
380
for (const auto& geometryPoint : geometryPoints) {
381
// create circle shape
382
const auto circleShape = GUIGeometry::getVertexCircleAroundPosition(shape[geometryPoint], radius * scale, 16);
383
// calculate dotted geometry
384
const auto dottedGeometry = GUIDottedGeometry(s, d, circleShape, true);
385
// reset dotted geometry color
386
myDottedGeometryColor.reset();
387
// Push draw matrix
388
GLHelper::pushMatrix();
389
// translate to front
390
glTranslated(0, 0, GLO_DOTTEDCONTOUR);
391
// draw dotted geometries
392
dottedGeometry.drawDottedGeometry(s, GUIDottedGeometry::DottedContourType::MOVE, myDottedGeometryColor, lineWidth, 0);
393
// pop matrix
394
GLHelper::popMatrix();
395
}
396
} else if (posOverShape != Position::INVALID) {
397
// create circle shape
398
const auto circleShape = GUIGeometry::getVertexCircleAroundPosition(posOverShape, radius * scale, 16);
399
// calculate dotted geometry
400
const auto dottedGeometry = GUIDottedGeometry(s, d, circleShape, true);
401
// reset dotted geometry color
402
myDottedGeometryColor.reset();
403
// Push draw matrix
404
GLHelper::pushMatrix();
405
// translate to front
406
glTranslated(0, 0, GLO_DOTTEDCONTOUR);
407
// draw dotted geometries
408
dottedGeometry.drawDottedGeometry(s, GUIDottedGeometry::DottedContourType::MOVE, myDottedGeometryColor, lineWidth, 0);
409
// pop matrix
410
GLHelper::popMatrix();
411
}
412
}
413
}
414
415
416
void
417
GNEContour::drawInnenContourClosed(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
418
const PositionVector& shape, const double scale, const double lineWidth) const {
419
// set calculated shape
420
*myCalculatedShape = shape;
421
// continue only if shape has at least three elements and scale isn't 0
422
if ((myCalculatedShape->size() > 2) && (scale > 0)) {
423
// scale shape
424
myCalculatedShape->scaleRelative(scale);
425
// close
426
myCalculatedShape->closePolygon();
427
// calculate geometry without resampling
428
myDottedGeometries->at(0) = GUIDottedGeometry(s, d, *myCalculatedShape, true);
429
// reset dotted geometry color
430
myDottedGeometryColor.reset();
431
// Push draw matrix
432
GLHelper::pushMatrix();
433
// draw dotted
434
myDottedGeometries->at(0).drawInnenGeometry(lineWidth);
435
// pop matrix
436
GLHelper::popMatrix();
437
}
438
}
439
440
441
bool
442
GNEContour::drawDottedContour(const GUIVisualizationSettings& s, GUIDottedGeometry::DottedContourType type,
443
const double lineWidth, const bool addOffset, double extraZOffset) const {
444
// reset dotted geometry color
445
myDottedGeometryColor.reset();
446
// Push draw matrix
447
GLHelper::pushMatrix();
448
// translate to front
449
glTranslated(0, 0, GLO_DOTTEDCONTOUR + extraZOffset);
450
// draw dotted geometries
451
for (const auto& dottedGeometry : *myDottedGeometries) {
452
dottedGeometry.drawDottedGeometry(s, type, myDottedGeometryColor, lineWidth, addOffset);
453
}
454
// pop matrix
455
GLHelper::popMatrix();
456
return true;
457
}
458
459
460
void
461
GNEContour::buildContourClosedShape(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
462
const PositionVector& shape, const double scale) const {
463
// set calculated shape
464
*myCalculatedShape = shape;
465
// continue only if shape has at least three elements and scale isn't 0
466
if ((myCalculatedShape->size() > 2) && (scale > 0)) {
467
// scale shape
468
myCalculatedShape->scaleRelative(scale);
469
// close
470
myCalculatedShape->closePolygon();
471
// calculate dotted geometry
472
myDottedGeometries->at(0) = GUIDottedGeometry(s, d, *myCalculatedShape, true);
473
// update contour boundary
474
*myContourBoundary = myCalculatedShape->getBoxBoundary();
475
} else {
476
myContourBoundary->reset();
477
}
478
}
479
480
481
void
482
GNEContour::buildContourExtrudedShape(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
483
const PositionVector& shape, const double extrusionWidth, const double scale,
484
const bool closeFirstExtrem, const bool closeLastExtrem, const double offset) const {
485
// reset calculated shape
486
myCalculatedShape->clear();
487
// avoid empty shapes
488
if (shape.size() > 1 && (extrusionWidth > 0)) {
489
// create top and bot geometries
490
myDottedGeometries->at(0) = GUIDottedGeometry(s, d, shape, false);
491
myDottedGeometries->at(2) = GUIDottedGeometry(s, d, shape.reverse(), false);
492
// move geometries top and bot
493
myDottedGeometries->at(0).moveShapeToSide((extrusionWidth * scale * -1) + offset);
494
myDottedGeometries->at(2).moveShapeToSide((extrusionWidth * scale * -1) - offset);
495
// create left and right geometries
496
if (closeFirstExtrem) {
497
myDottedGeometries->at(3) = GUIDottedGeometry(s, d, {
498
myDottedGeometries->at(2).getBackPosition(),
499
myDottedGeometries->at(0).getFrontPosition()
500
}, false);
501
}
502
if (closeLastExtrem) {
503
myDottedGeometries->at(1) = GUIDottedGeometry(s, d, {
504
myDottedGeometries->at(0).getBackPosition(),
505
myDottedGeometries->at(2).getFrontPosition()
506
}, false);
507
}
508
for (const auto& position : myDottedGeometries->at(0).getUnresampledShape()) {
509
myCalculatedShape->push_back(position);
510
}
511
for (const auto& position : myDottedGeometries->at(2).getUnresampledShape()) {
512
myCalculatedShape->push_back(position);
513
}
514
// update contour boundary
515
*myContourBoundary = myCalculatedShape->getBoxBoundary();
516
} else {
517
myContourBoundary->reset();
518
}
519
}
520
521
522
void
523
GNEContour::buildContourRectangle(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
524
const Position& pos, const double width, const double height, const double offsetX,
525
const double offsetY, const double rot, const double scale) const {
526
// reset calculated shape
527
myCalculatedShape->clear();
528
// check sizes
529
if (((width + height) > 0) && (scale > 0)) {
530
// make rectangle
531
myCalculatedShape->push_back(Position(0 + width, 0 + height));
532
myCalculatedShape->push_back(Position(0 + width, 0 - height));
533
myCalculatedShape->push_back(Position(0 - width, 0 - height));
534
myCalculatedShape->push_back(Position(0 - width, 0 + height));
535
// move shape
536
myCalculatedShape->add(offsetX, offsetY, 0);
537
// scale
538
myCalculatedShape->scaleRelative(scale);
539
// rotate shape
540
myCalculatedShape->rotate2D(DEG2RAD((rot * -1) + 90));
541
// move to position
542
myCalculatedShape->add(pos);
543
// calculate dotted geometry
544
myDottedGeometries->at(0) = GUIDottedGeometry(s, d, *myCalculatedShape, true);
545
// update contour boundary
546
*myContourBoundary = myCalculatedShape->getBoxBoundary();
547
} else {
548
myContourBoundary->reset();
549
}
550
}
551
552
553
void
554
GNEContour::buildContourCircle(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
555
const Position& pos, double radius, const double scale) const {
556
// reset calculated shape
557
myCalculatedShape->clear();
558
// get scaled radius
559
const double scaledRadius = radius * scale;
560
// check scaled radius
561
if (scaledRadius > POSITION_EPS) {
562
// continue depending of resolution
563
if (d <= GUIVisualizationSettings::Detail::CircleResolution32) {
564
*myCalculatedShape = GUIGeometry::getVertexCircleAroundPosition(pos, scaledRadius, 16);
565
} else if (d <= GUIVisualizationSettings::Detail::CircleResolution16) {
566
*myCalculatedShape = GUIGeometry::getVertexCircleAroundPosition(pos, scaledRadius, 8);
567
} else {
568
myCalculatedShape->push_back(Position(pos.x() - radius, pos.y() - radius));
569
myCalculatedShape->push_back(Position(pos.x() - radius, pos.y() + radius));
570
myCalculatedShape->push_back(Position(pos.x() + radius, pos.y() + radius));
571
myCalculatedShape->push_back(Position(pos.x() + radius, pos.y() - radius));
572
}
573
// calculate dotted geometry
574
myDottedGeometries->at(0) = GUIDottedGeometry(s, d, *myCalculatedShape, true);
575
// update contour boundary
576
*myContourBoundary = myCalculatedShape->getBoxBoundary();
577
} else {
578
myContourBoundary->reset();
579
}
580
}
581
582
583
void
584
GNEContour::buildContourEdge(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
585
const GNEEdge* edge, const bool closeFirstExtrem, const bool closeLastExtrem) const {
586
// reset calculated shape
587
myCalculatedShape->clear();
588
// set left hand flag
589
const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
590
// obtain lanes
591
const GNELane* topLane = lefthand ? edge->getChildLanes().front() : edge->getChildLanes().back();
592
const GNELane* botLane = lefthand ? edge->getChildLanes().back() : edge->getChildLanes().front();
593
// create top and bot geometries
594
myDottedGeometries->at(0) = GUIDottedGeometry(s, d, topLane->getLaneGeometry().getShape(), false);
595
myDottedGeometries->at(2) = GUIDottedGeometry(s, d, botLane->getLaneGeometry().getShape().reverse(), false);
596
// move geometries top and bot
597
myDottedGeometries->at(0).moveShapeToSide((topLane->getDrawingConstants()->getDrawingWidth() * -1) + topLane->getDrawingConstants()->getOffset());
598
myDottedGeometries->at(2).moveShapeToSide((botLane->getDrawingConstants()->getDrawingWidth() * -1) - botLane->getDrawingConstants()->getOffset());
599
// create left and right geometries
600
if (closeFirstExtrem) {
601
myDottedGeometries->at(3) = GUIDottedGeometry(s, d, {
602
myDottedGeometries->at(2).getBackPosition(),
603
myDottedGeometries->at(0).getFrontPosition()
604
}, false);
605
}
606
if (closeLastExtrem) {
607
myDottedGeometries->at(1) = GUIDottedGeometry(s, d, {
608
myDottedGeometries->at(0).getBackPosition(),
609
myDottedGeometries->at(2).getFrontPosition()
610
}, false);
611
}
612
// update calculated shape
613
for (const auto& position : myDottedGeometries->at(0).getUnresampledShape()) {
614
myCalculatedShape->push_back(position);
615
}
616
for (const auto& position : myDottedGeometries->at(2).getUnresampledShape()) {
617
myCalculatedShape->push_back(position);
618
}
619
// update contour boundary
620
*myContourBoundary = myCalculatedShape->getBoxBoundary();
621
}
622
623
624
void
625
GNEContour::buildContourEdges(const GUIVisualizationSettings& /*s*/, const GUIVisualizationSettings::Detail /*d*/,
626
const GNEEdge* /* fromEdge */, const GNEEdge* /* toEdge */) const {
627
628
// finish
629
}
630
631
/****************************************************************************/
632
633