Eclipse SUMO - Simulation of Urban MObility
GNEPoly.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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 class for visualizing and editing POIS in netedit (adapted from
19// GUIPolygon and NLHandler)
20/****************************************************************************/
21#include <config.h>
22
23#include <string>
26#include <netedit/GNENet.h>
27#include <netedit/GNEUndoList.h>
28#include <netedit/GNEViewNet.h>
35
36#include "GNEPoly.h"
37
38
39// ===========================================================================
40// method definitions
41// ===========================================================================
42
44 TesselatedPolygon("", "", RGBColor::BLACK, {}, false, false, 0, 0, 0, "", false, "", Parameterised::Map()),
45 GNEAdditional("", net, GLO_POLYGON, SUMO_TAG_POLY, GUIIconSubSys::getIcon(GUIIcon::POLY), "", {}, {}, {}, {}, {}, {}),
46mySimplifiedShape(false) {
47 // reset default values
49}
50
51
52GNEPoly::GNEPoly(GNENet* net, const std::string& id, const std::string& type, const PositionVector& shape, bool geo, bool fill, double lineWidth,
53 const RGBColor& color, double layer, double angle, const std::string& imgFile, bool relativePath, const std::string& name,
54 const Parameterised::Map& parameters) :
55 TesselatedPolygon(id, type, color, shape, geo, fill, lineWidth, layer, angle, imgFile, relativePath, name, parameters),
56 GNEAdditional(id, net, GLO_POLYGON, SUMO_TAG_POLY, GUIIconSubSys::getIcon(GUIIcon::POLY), "", {}, {}, {}, {}, {}, {}),
57mySimplifiedShape(false) {
58 // check if imgFile is valid
59 if (!imgFile.empty() && GUITexturesHelper::getTextureID(imgFile) == -1) {
61 }
62 // set GEO shape
64 if (geo) {
65 for (int i = 0; i < (int) myGeoShape.size(); i++) {
67 }
68 } else {
69 for (int i = 0; i < (int) myGeoShape.size(); i++) {
71 }
72 }
73 // update centering boundary without updating grid
75 // update geometry
77}
78
79
81
82
85 // edit depending if shape is blocked
87 // move entire shape
88 return new GNEMoveOperation(this, myShape);
89 } else {
90 // calculate move shape operation
93 }
94}
95
96
97void
98GNEPoly::removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) {
99 // get original shape
100 PositionVector shape = myShape;
101 // check shape size
102 if (shape.size() > 2) {
103 // obtain index
104 int index = shape.indexOfClosest(clickedPosition);
105 // get snap radius
107 // check if we have to create a new index
108 if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {
109 // remove geometry point
110 shape.erase(shape.begin() + index);
111 // commit new shape
112 undoList->begin(GUIIcon::POLY, "remove geometry point of " + getTagStr());
113 undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_SHAPE, toString(shape)));
114 undoList->end();
115 }
116 }
117}
118
119
120std::string
122 return "";
123}
124
125
126void
128 // just update geometry
130 myTesselation.clear();
131}
132
133
137}
138
139
140double
142 return s.polySize.getExaggeration(s, this);
143}
144
145
146void
147GNEPoly::updateCenteringBoundary(const bool updateGrid) {
148 // Remove object from net
149 if (updateGrid) {
151 }
152 // use shape as boundary
154 // grow boundary
156 // add object into net
157 if (updateGrid) {
159 }
160}
161
162
163void
164GNEPoly::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
165 // nothing to split
166}
167
168
169void
171 writeXML(device, myGEO);
172}
173
174
177 return GUIGlObject::getGlID();
178}
179
180
181std::string
183 return myNet->getMicrosimID();
184}
185
186
189 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
190 buildPopupHeader(ret, app);
193 // build selection and show parameters menu
196 FXMenuCommand* simplifyShape = GUIDesigns::buildFXMenuCommand(ret, "Simplify Shape\t\tReplace current shape with a rectangle", nullptr, &parent, MID_GNE_POLYGON_SIMPLIFY_SHAPE);
197 // disable simplify shape if polygon was already simplified
198 if (mySimplifiedShape || myShape.size() <= 2) {
199 simplifyShape->disable();
200 }
201 if (myShape.isClosed()) {
202 GUIDesigns::buildFXMenuCommand(ret, "Open shape\t\tOpen polygon's shape", nullptr, &parent, MID_GNE_POLYGON_OPEN);
203 } else {
204 GUIDesigns::buildFXMenuCommand(ret, "Close shape\t\tClose polygon's shape", nullptr, &parent, MID_GNE_POLYGON_CLOSE);
205 }
206 GUIDesigns::buildFXMenuCommand(ret, "Select elements within polygon\t\tSelect elements within polygon boundary", nullptr, &parent, MID_GNE_POLYGON_SELECT);
207 // add separator
208 new FXMenuSeparator(ret);
209 // create a extra FXMenuCommand if mouse is over a vertex
210 const int index = getVertexIndex(myNet->getViewNet()->getPositionInformation(), false);
211 if (index != -1) {
212 // check if we're in network mode
214 GUIDesigns::buildFXMenuCommand(ret, "Set custom Geometry Point", nullptr, &parent, MID_GNE_CUSTOM_GEOMETRYPOINT);
215 }
216 FXMenuCommand* removeGeometryPoint = GUIDesigns::buildFXMenuCommand(ret, "Remove geometry point\t\tRemove geometry point under mouse", nullptr, &parent, MID_GNE_POLYGON_DELETE_GEOMETRY_POINT);
217 FXMenuCommand* setFirstPoint = GUIDesigns::buildFXMenuCommand(ret, "Set first geometry point\t\tSet", nullptr, &parent, MID_GNE_POLYGON_SET_FIRST_POINT);
218 // disable setFirstPoint if shape only have three points
219 if ((myShape.isClosed() && (myShape.size() <= 4)) || (!myShape.isClosed() && (myShape.size() <= 2))) {
220 removeGeometryPoint->disable();
221 }
222 // disable setFirstPoint if mouse is over first point
223 if (index == 0) {
224 setFirstPoint->disable();
225 }
226 }
227 return ret;
228}
229
230
231void
233 // check if boundary has to be drawn
234 if (s.drawBoundaries) {
236 }
237 // first check if poly can be drawn
240 GUIPolygon::checkDraw(s, this, this)) {
241 // check if draw start und end
242 const bool drawExtremeSymbols = myNet->getViewNet()->getEditModes().isCurrentSupermodeNetwork() &&
244 // Obtain constants
245 const double polyExaggeration = getExaggeration(s);
246 const Position mousePosition = myNet->getViewNet()->getPositionInformation();
247 // get colors
249 const RGBColor invertedColor = color.invertedColor();
250 const RGBColor darkerColor = color.changedBrightness(-32);
251 // push name (needed for getGUIGlObjectsUnderCursor(...)
253 // push layer matrix
255 // translate to front
257 // check if we're drawing a polygon or a polyline
258 if (getFill()) {
260 // check if mouse is within geometry
261 if (myPolygonGeometry.getShape().around(mousePosition)) {
262 // push matrix
264 // move to mouse position
265 glTranslated(mousePosition.x(), mousePosition.y(), 0);
266 // set color
267 GLHelper::setColor(color);
268 // draw circle
270 // pop matrix
272 }
273 } else {
274 // draw inner polygon
276 }
277 } else {
278 // push matrix
280 // set color
281 GLHelper::setColor(color);
282 // draw geometry (polyline)
284 // pop matrix
286 }
287 // draw contour if shape isn't blocked
289 // push contour matrix
291 // translate to front
292 glTranslated(0, 0, 0.1);
293 // set color
294 GLHelper::setColor(darkerColor);
295 // draw polygon contour
297 // pop contour matrix
299 // draw shape points only in Network supemode
301 // check move mode flag
303 // draw geometry points
305 s.neteditSizeSettings.polygonGeometryPointRadius * (moveMode ? 1 : 0.5), polyExaggeration,
306 myNet->getViewNet()->getNetworkViewOptions().editingElevation(), drawExtremeSymbols);
307 // draw moving hint points
311 }
312 }
313 }
314 // check if mouse is over element
317 } else {
319 }
320 // inspect contour
322 // draw depending if is closed
325 } else {
327 polyExaggeration, true, true);
328 }
329 }
330 // dotted contour
331 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
332 // draw depending if is closed
335 } else {
337 polyExaggeration, true, true);
338 }
339 }
340 // delete contour
341 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
342 // draw depending if is closed
345 } else {
347 polyExaggeration, true, true);
348 }
349 }
350 // select contour
351 if (myNet->getViewNet()->drawSelectContour(this, this)) {
352 // draw depending if is closed
355 } else {
357 polyExaggeration, true, true);
358 }
359 }
360 // draw lock icon
362 // pop layer matrix
364 // pop name
366 // get name position
368 // draw name
369 drawName(namePos, s.scale, s.polyName, s.angle);
370 // check if draw poly type
371 if (s.polyType.show(this)) {
372 const Position p = namePos + Position(0, -0.6 * s.polyType.size / s.scale);
374 }
375 }
376}
377
378
379int
380GNEPoly::getVertexIndex(Position pos, bool snapToGrid) {
381 // check if position has to be snapped to grid
382 if (snapToGrid) {
383 pos = myNet->getViewNet()->snapToActiveGrid(pos);
384 }
385 // first check if vertex already exists
386 for (const auto& shapePosition : myShape) {
387 if (shapePosition.distanceTo2D(pos) < myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.polygonGeometryPointRadius) {
388 return myShape.indexOfClosest(shapePosition);
389 }
390 }
391 return -1;
392}
393
394
395void
396GNEPoly::deleteGeometryPoint(const Position& pos, bool allowUndo) {
397 if (myShape.size() > 1) {
398 // obtain index
399 PositionVector modifiedShape = myShape;
400 int index = modifiedShape.indexOfClosest(pos);
401 // remove point dependending of
402 if (myShape.isClosed() && (index == 0 || index == (int)modifiedShape.size() - 1) && (myShape.size() > 2)) {
403 modifiedShape.erase(modifiedShape.begin());
404 modifiedShape.erase(modifiedShape.end() - 1);
405 modifiedShape.push_back(modifiedShape.front());
406 } else {
407 modifiedShape.erase(modifiedShape.begin() + index);
408 }
409 // set new shape depending of allowUndo
410 if (allowUndo) {
411 myNet->getViewNet()->getUndoList()->begin(GUIIcon::POLY, "delete geometry point");
414 } else {
415 // first remove object from grid due shape is used for boundary
417 // set new shape
418 myShape = modifiedShape;
419 // disable simplified shape flag
420 mySimplifiedShape = false;
421 // add object into grid again
423 }
424 myTesselation.clear();
425 } else {
426 WRITE_WARNING(TL("Number of remaining points insufficient"))
427 }
428}
429
430
431bool
433 return myShape.isClosed();
434}
435
436
437void
438GNEPoly::openPolygon(bool allowUndo) {
439 // only open if shape is closed
440 if (myShape.isClosed()) {
441 if (allowUndo) {
442 myNet->getViewNet()->getUndoList()->begin(GUIIcon::POLY, "open polygon");
445 } else {
446 myShape.pop_back();
447 // disable simplified shape flag
448 mySimplifiedShape = false;
449 // update geometry to avoid grabbing Problems
451 }
452 } else {
453 WRITE_WARNING(TL("Polygon already opened"))
454 }
455}
456
457
458void
459GNEPoly::closePolygon(bool allowUndo) {
460 // only close if shape is opened
461 if (myShape.isClosed() == false) {
462 if (allowUndo) {
463 myNet->getViewNet()->getUndoList()->begin(GUIIcon::POLY, "close shape");
466 } else {
468 // disable simplified shape flag
469 mySimplifiedShape = false;
470 // update geometry to avoid grabbing Problems
472 }
473 } else {
474 WRITE_WARNING(TL("Polygon already closed"))
475 }
476}
477
478
479void
480GNEPoly::changeFirstGeometryPoint(int oldIndex, bool allowUndo) {
481 // check that old index is correct
482 if (oldIndex >= (int)myShape.size()) {
483 throw InvalidArgument("Invalid old Index");
484 } else if (oldIndex == 0) {
485 WRITE_WARNING(TL("Selected point must be different of the first point"))
486 } else {
487 // Configure new shape
488 PositionVector newShape;
489 for (int i = oldIndex; i < (int)myShape.size(); i++) {
490 newShape.push_back(myShape[i]);
491 }
492 if (myShape.isClosed()) {
493 for (int i = 1; i < oldIndex; i++) {
494 newShape.push_back(myShape[i]);
495 }
496 newShape.push_back(newShape.front());
497 } else {
498 for (int i = 0; i < oldIndex; i++) {
499 newShape.push_back(myShape[i]);
500 }
501 }
502 // set new rotated shape
503 if (allowUndo) {
504 myNet->getViewNet()->getUndoList()->begin(GUIIcon::POLY, "change first geometry point");
507 } else {
508 // set new shape
509 myShape = newShape;
510 // disable simplified shape flag
511 mySimplifiedShape = false;
512 // update geometry to avoid grabbing Problems
514 }
515 }
516}
517
518
519void
520GNEPoly::simplifyShape(bool allowUndo) {
521 if (!mySimplifiedShape && myShape.size() > 2) {
522 const Boundary b = myShape.getBoxBoundary();
523 PositionVector simplifiedShape;
524 if (myShape.isClosed()) {
525 // create a square as simplified shape
526 simplifiedShape.push_back(Position(b.xmin(), b.ymin()));
527 simplifiedShape.push_back(Position(b.xmin(), b.ymax()));
528 simplifiedShape.push_back(Position(b.xmax(), b.ymax()));
529 simplifiedShape.push_back(Position(b.xmax(), b.ymin()));
530 simplifiedShape.push_back(simplifiedShape[0]);
531 } else {
532 // create a line as simplified shape
533 simplifiedShape.push_back(myShape.front());
534 simplifiedShape.push_back(myShape.back());
535 }
536 // set new shape depending of allowUndo
537 if (allowUndo) {
538 myNet->getViewNet()->getUndoList()->begin(GUIIcon::POLY, "simplify shape");
541 } else {
542 // set new shape
543 myShape = simplifiedShape;
544 // update geometry to avoid grabbing Problems
546 }
547 // change flag after setting simplified shape
548 mySimplifiedShape = true;
549 } else {
550 WRITE_WARNING(TL("Polygon already simplified"))
551 }
552}
553
554
555std::string
557 switch (key) {
558 case SUMO_ATTR_ID:
559 return myID;
560 case SUMO_ATTR_SHAPE:
561 return toString(myShape);
564 case SUMO_ATTR_COLOR:
565 return toString(getShapeColor());
566 case SUMO_ATTR_FILL:
567 return toString(myFill);
569 return toString(myLineWidth);
570 case SUMO_ATTR_LAYER:
572 return "default";
573 } else {
574 return toString(getShapeLayer());
575 }
576 case SUMO_ATTR_TYPE:
577 return getShapeType();
579 return getShapeImgFile();
582 case SUMO_ATTR_ANGLE:
584 case SUMO_ATTR_GEO:
585 return toString(myGEO);
586 case SUMO_ATTR_NAME:
587 return getShapeName();
589 return toString(myShape.isClosed());
594 default:
595 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
596 }
597}
598
599
600double
602 throw InvalidArgument(getTagStr() + " attribute '" + toString(key) + "' not allowed");
603}
604
605
609}
610
611
612void
613GNEPoly::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
614 if (value == getAttribute(key)) {
615 return; //avoid needless changes, later logic relies on the fact that attributes have changed
616 }
617 switch (key) {
618 case SUMO_ATTR_ID:
619 case SUMO_ATTR_SHAPE:
621 case SUMO_ATTR_COLOR:
622 case SUMO_ATTR_FILL:
624 case SUMO_ATTR_LAYER:
625 case SUMO_ATTR_TYPE:
628 case SUMO_ATTR_ANGLE:
629 case SUMO_ATTR_GEO:
630 case SUMO_ATTR_NAME:
634 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
635 break;
636 default:
637 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
638 }
639}
640
641
642bool
643GNEPoly::isValid(SumoXMLAttr key, const std::string& value) {
644 switch (key) {
645 case SUMO_ATTR_ID:
647 (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_TAZ, value, false) == nullptr) &&
648 (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_POLY, value, false) == nullptr);
649 case SUMO_ATTR_SHAPE:
651 // empty shapes AREN'T allowed
652 if (value.empty()) {
653 return false;
654 } else {
655 return canParse<PositionVector>(value);
656 }
657 case SUMO_ATTR_COLOR:
658 return canParse<RGBColor>(value);
659 case SUMO_ATTR_FILL:
660 return canParse<bool>(value);
662 return canParse<double>(value) && (parse<double>(value) >= 0);
663 case SUMO_ATTR_LAYER:
664 if (value == "default") {
665 return true;
666 } else {
667 return canParse<double>(value);
668 }
669 case SUMO_ATTR_TYPE:
670 return true;
672 if (value == "") {
673 return true;
674 } else {
675 // check that image can be loaded
676 return GUITexturesHelper::getTextureID(value) != -1;
677 }
679 return canParse<bool>(value);
680 case SUMO_ATTR_ANGLE:
681 return canParse<double>(value);
682 case SUMO_ATTR_GEO:
683 return canParse<bool>(value);
684 case SUMO_ATTR_NAME:
687 if (canParse<bool>(value)) {
688 bool closePolygon = parse<bool>(value);
689 if (closePolygon && (myShape.begin() == myShape.end())) {
690 // Polygon already closed, then invalid value
691 return false;
692 } else if (!closePolygon && (myShape.begin() != myShape.end())) {
693 // Polygon already open, then invalid value
694 return false;
695 } else {
696 return true;
697 }
698 } else {
699 return false;
700 }
702 return canParse<bool>(value);
704 return areParametersValid(value);
705 default:
706 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
707 }
708}
709
710
711bool
713 // check if we're in supermode Network
715 return true;
716 } else {
717 return false;
718 }
719}
720
721
722std::string
724 return getTagStr() + ": " + getID();
725}
726
727
728std::string
730 return getTagStr();
731}
732
733// ===========================================================================
734// private
735// ===========================================================================
736
737void
738GNEPoly::setAttribute(SumoXMLAttr key, const std::string& value) {
739 switch (key) {
740 case SUMO_ATTR_ID: {
741 // update microsimID
742 setMicrosimID(value);
743 // set named ID
744 myID = value;
745 break;
746 }
747 case SUMO_ATTR_SHAPE: {
748 // set new shape
749 myShape = parse<PositionVector>(value);
750 // set GEO shape
752 for (int i = 0; i < (int) myGeoShape.size(); i++) {
754 }
755 // disable simplified shape flag
756 mySimplifiedShape = false;
757 // update geometry
759 // update centering boundary
761 break;
762 }
763 case SUMO_ATTR_GEOSHAPE: {
764 // set new GEO shape
765 myGeoShape = parse<PositionVector>(value);
766 // set shape
768 for (int i = 0; i < (int) myShape.size(); i++) {
770 }
771 // disable simplified shape flag
772 mySimplifiedShape = false;
773 // update geometry
775 // update centering boundary
777 break;
778 }
779 case SUMO_ATTR_COLOR:
780 setShapeColor(parse<RGBColor>(value));
781 break;
782 case SUMO_ATTR_FILL:
783 myFill = parse<bool>(value);
784 break;
786 myLineWidth = parse<double>(value);
787 break;
788 case SUMO_ATTR_LAYER:
789 if (value == "default") {
791 } else {
792 setShapeLayer(parse<double>(value));
793 }
794 break;
795 case SUMO_ATTR_TYPE:
796 setShapeType(value);
797 break;
799 setShapeImgFile(value);
800 // all textures must be refresh
802 break;
804 setShapeRelativePath(parse<bool>(value));
805 break;
806 case SUMO_ATTR_ANGLE:
807 setShapeNaviDegree(parse<double>(value));
808 break;
809 case SUMO_ATTR_GEO:
810 myGEO = parse<bool>(value);
811 // update centering boundary
813 break;
814 case SUMO_ATTR_NAME:
815 setShapeName(value);
816 break;
818 if (parse<bool>(value)) {
821 } else {
822 myShape.pop_back();
823 myGeoShape.pop_back();
824 }
825 // disable simplified shape flag
826 mySimplifiedShape = false;
827 // update geometry
829 // update centering boundary
831 break;
833 if (parse<bool>(value)) {
835 } else {
837 }
838 break;
841 break;
842 default:
843 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
844 }
845}
846
847
848void
850 // update new shape
851 myShape = moveResult.shapeToUpdate;
852 // update geometry
854}
855
856
857void
859 // commit new shape
860 undoList->begin(GUIIcon::POLY, "moving " + toString(SUMO_ATTR_SHAPE) + " of " + getTagStr());
862 undoList->end();
863}
864
865/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ MID_GNE_POLYGON_CLOSE
close opened polygon
Definition: GUIAppEnum.h:1217
@ MID_GNE_POLYGON_SET_FIRST_POINT
Set a vertex of polygon as first vertex.
Definition: GUIAppEnum.h:1221
@ MID_GNE_POLYGON_SELECT
select elements within polygon boundary
Definition: GUIAppEnum.h:1225
@ MID_GNE_CUSTOM_GEOMETRYPOINT
set custom geometry point
Definition: GUIAppEnum.h:952
@ MID_GNE_POLYGON_DELETE_GEOMETRY_POINT
delete geometry point
Definition: GUIAppEnum.h:1223
@ MID_GNE_POLYGON_OPEN
open closed polygon
Definition: GUIAppEnum.h:1219
@ MID_GNE_POLYGON_SIMPLIFY_SHAPE
simplify polygon geometry
Definition: GUIAppEnum.h:1215
unsigned int GUIGlID
Definition: GUIGlObject.h:43
@ GLO_POLYGON
a polygon
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:265
#define TL(string)
Definition: MsgHandler.h:282
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_TAZ
a traffic assignment zone
@ SUMO_TAG_POLY
begin/end of the description of a polygon
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_LINEWIDTH
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_GEO
@ SUMO_ATTR_GEOSHAPE
@ GNE_ATTR_CLOSE_SHAPE
Close shape of a polygon (Used by GNEPolys)
@ SUMO_ATTR_SHAPE
edge: the shape in xml-definition
@ SUMO_ATTR_FILL
Fill the polygon.
@ SUMO_ATTR_NAME
@ SUMO_ATTR_LAYER
A layer number.
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_IMGFILE
@ SUMO_ATTR_RELATIVEPATH
int gPrecisionGeo
Definition: StdDefs.cpp:26
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
Position getCenter() const
Returns the center of the boundary.
Definition: Boundary.cpp:112
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:130
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:118
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:136
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:124
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:894
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:583
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:498
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void popName()
pop Name
Definition: GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048, const int align=0)
Definition: GLHelper.cpp:716
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
Boundary myAdditionalBoundary
Additional Boundary.
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
GNEMoveOperation * calculateMoveShapeOperation(const PositionVector originalShape, const Position mousePosition, const double snapRadius, const bool onlyContour)
calculate move shape operation
bool getMoveWholePolygons() const
move whole polygons
NetworkModeOptions * getNetworkModeOptions() const
get network mode options
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1245
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1257
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:132
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
bool mySimplifiedShape
flag to indicate if polygon is simplified
Definition: GNEPoly.h:214
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
Definition: GNEPoly.cpp:723
std::string getParentName() const override
Returns the name of the parent object.
Definition: GNEPoly.cpp:182
double getAttributeDouble(SumoXMLAttr key) const override
Definition: GNEPoly.cpp:601
~GNEPoly()
Destructor.
Definition: GNEPoly.cpp:80
bool isValid(SumoXMLAttr key, const std::string &value) override
method for checking if the key and their conrrespond attribute are valids
Definition: GNEPoly.cpp:643
void updateGeometry() override
update pre-computed geometry information
Definition: GNEPoly.cpp:127
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEPoly.cpp:729
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
Definition: GNEPoly.cpp:170
GNEMoveOperation * getMoveOperation() override
get move operation
Definition: GNEPoly.cpp:84
int getVertexIndex(Position pos, bool snapToGrid)
return index of a vertex of shape, or of a new vertex if position is over an shape's edge
Definition: GNEPoly.cpp:380
PositionVector myGeoShape
Latitude of Polygon.
Definition: GNEPoly.h:211
GUIGeometry myPolygonGeometry
geometry for lengths/rotations
Definition: GNEPoly.h:217
GNEPoly(GNENet *net)
default Constructor
Definition: GNEPoly.cpp:43
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
Definition: GNEPoly.cpp:141
void closePolygon(bool allowUndo=true)
close polygon
Definition: GNEPoly.cpp:459
void changeFirstGeometryPoint(int oldIndex, bool allowUndo=true)
change first geometry point
Definition: GNEPoly.cpp:480
std::string getAttribute(SumoXMLAttr key) const override
Definition: GNEPoly.cpp:556
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList) override
commit move shape
Definition: GNEPoly.cpp:858
void setMoveShape(const GNEMoveResult &moveResult) override
set move shape
Definition: GNEPoly.cpp:849
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
method for setting the attribute and letting the object perform additional changes
Definition: GNEPoly.cpp:613
void deleteGeometryPoint(const Position &pos, bool allowUndo=true)
delete the geometry point closest to the given pos
Definition: GNEPoly.cpp:396
Position getPositionInView() const override
Returns position of shape in view.
Definition: GNEPoly.cpp:135
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList) override
remove geometry point in the clicked position
Definition: GNEPoly.cpp:98
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
Definition: GNEPoly.cpp:232
bool isAttributeEnabled(SumoXMLAttr key) const override
Definition: GNEPoly.cpp:712
bool isPolygonClosed() const
check if polygon is closed
Definition: GNEPoly.cpp:432
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own popup-menu.
Definition: GNEPoly.cpp:188
void simplifyShape(bool allowUndo=true)
replace the current shape with a rectangle
Definition: GNEPoly.cpp:520
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
Definition: GNEPoly.cpp:164
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
Definition: GNEPoly.cpp:147
const Parameterised::Map & getACParametersMap() const override
get parameters map
Definition: GNEPoly.cpp:607
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GNEPoly.cpp:176
std::string generateChildID(SumoXMLTag childTag)
gererate a new ID for an element child
Definition: GNEPoly.cpp:121
void openPolygon(bool allowUndo=true)
open polygon
Definition: GNEPoly.cpp:438
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
bool isObjectLocked(GUIGlObjectType objectType, const bool selected) const
check if given GLObject is locked for inspect, select, delete and move
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:656
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:632
bool drawSelectContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw select contour
bool drawDeleteContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw delete contour
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:644
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
GNEViewParent * getViewParent() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
GNEViewNetHelper::LockManager & getLockManager()
get lock manager
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
Definition: GNEViewNet.cpp:474
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
Definition: GNEViewNet.cpp:650
GNEMoveFrame * getMoveFrame() const
get frame for move elements
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
Definition: GUIDesigns.cpp:42
static void drawDottedContourClosedShape(const GUIVisualizationSettings &s, const DottedContourType type, const PositionVector &shape, const double exaggeration, const double customWidth=1)
draw dotted contour for the given closed shape (used by Juctions, shapes and TAZs)
static void drawDottedContourShape(const GUIVisualizationSettings &s, const DottedContourType type, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem)
draw dotted contour for the given shape (used by additionals)
The popup menu of a globject.
static void drawGeometryPoints(const GUIVisualizationSettings &s, const Position &mousePos, const PositionVector &shape, const RGBColor &geometryPointColor, const RGBColor &textColor, const double radius, const double exaggeration, const bool editingElevation, const bool drawExtremeSymbols)
draw geometry points
static void drawGeometry(const GUIVisualizationSettings &s, const Position &mousePos, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
Definition: GUIGeometry.cpp:58
static void drawMovingHint(const GUIVisualizationSettings &s, const Position &mousePos, const PositionVector &shape, const RGBColor &hintColor, const double radius, const double exaggeration)
draw moving hint
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:154
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
static void drawInnerPolygon(const GUIVisualizationSettings &s, const TesselatedPolygon *polygon, const GUIGlObject *o, const PositionVector shape, const double layer, const bool fill, const bool disableSelectionColor=false, const int alphaOverride=-1, const bool disableText=false)
draw inner Polygon (before pushName() )
Definition: GUIPolygon.cpp:329
static bool checkDraw(const GUIVisualizationSettings &s, const SUMOPolygon *polygon, const GUIGlObject *o)
check if Polygon can be drawn
Definition: GUIPolygon.cpp:307
Position snapToActiveGrid(const Position &pos, bool snapXY=true) const
Returns a position that is mapped to the closest grid point if the grid is active.
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
static int getTextureID(const std::string &filename, const bool mirrorX=false)
return texture id for the given filename (initialize on first use)
static void clearTextures()
clears loaded textures
Stores the information about how to visualize structures.
bool drawBoundaries
enable or disable draw boundaries
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
bool drawMovingGeometryPoint(const double exaggeration, const double radius) const
check if moving geometry point can be draw
GUIVisualizationColorSettings colorSettings
color settings
double scale
information about a lane's width (temporary, used for a single view)
GUIVisualizationTextSettings polyName
GUIVisualizationSizeSettings polySize
int getCircleResolution() const
function to calculate circle resolution for all circles drawn in drawGL(...) functions
GUIVisualizationTextSettings polyType
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
double angle
The current view rotation angle.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation.
std::string myID
The name of the object.
Definition: Named.h:125
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double x() const
Returns the x-position.
Definition: Position.h:55
double y() const
Returns the y-position.
Definition: Position.h:60
A list of positions.
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
void closePolygon()
ensures that the last position equals the first
int indexOfClosest(const Position &p, bool twoD=false) const
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
bool isClosed() const
check if PositionVector is closed
bool around(const Position &p, double offset=0) const
Returns the information whether the position vector describes a polygon lying around the given point.
RGBColor invertedColor() const
obtain inverted of current RGBColor
Definition: RGBColor.cpp:183
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:200
PositionVector myShape
The positions of the polygon.
Definition: SUMOPolygon.h:121
double myLineWidth
The line width for drawing an unfilled polygon.
Definition: SUMOPolygon.h:130
bool myGEO
specify if shape is handled as GEO coordinate (Main used in netedit)
Definition: SUMOPolygon.h:124
void writeXML(OutputDevice &out, bool geo=false) const
Definition: SUMOPolygon.cpp:88
bool myFill
Information whether the polygon has to be filled.
Definition: SUMOPolygon.h:127
bool getFill() const
Returns whether the polygon is filled.
Definition: SUMOPolygon.cpp:58
static bool isValidAdditionalID(const std::string &value)
whether the given string is a valid id for an additional object
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
const std::string getShapeName() const
Returns the name of the Shape.
Definition: Shape.h:110
static const double DEFAULT_LAYER
Definition: Shape.h:43
void setShapeName(const std::string &name)
Sets a new shape name.
Definition: Shape.h:169
void setShapeLayer(const double layer)
Sets a new layer.
Definition: Shape.h:150
bool getShapeRelativePath() const
Returns the relativePath of the Shape.
Definition: Shape.h:117
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:77
void setShapeType(const std::string &type)
Sets a new type.
Definition: Shape.h:129
void setShapeRelativePath(bool relativePath)
Sets a new relativePath value.
Definition: Shape.h:176
virtual void setShapeNaviDegree(const double angle)
Sets a new angle in navigational degrees.
Definition: Shape.h:157
void setShapeImgFile(const std::string &imgFile)
Sets a new imgFile.
Definition: Shape.h:164
void setShapeColor(const RGBColor &col)
Sets a new color.
Definition: Shape.h:136
double getShapeLayer() const
Returns the layer of the Shape.
Definition: Shape.h:91
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition: Shape.h:105
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition: Shape.h:84
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:98
std::vector< GLPrimitive > myTesselation
id of the display list for the cached tesselation
Definition: GUIPolygon.h:74
bool showShapes() const
check if shapes has to be drawn
bool showShapes() const
check if shapes has to be drawn
NetworkEditMode networkEditMode
the current Network edit mode
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network
static void drawLockIcon(const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position viewPosition, const double exaggeration, const double size=0.5, const double offsetx=0, const double offsety=0)
draw lock icon
bool editingElevation() const
check if we're editing elevation
RGBColor selectionColor
basic selection color
static const double polygonGeometryPointRadius
moving geometry point radius
static const double polygonContourWidth
polygon contour width
static const double polylineWidth
poly line width
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
bool show(const GUIGlObject *o) const
whether to show the text