Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEPoly.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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>
36
37#include "GNEPoly.h"
38
39
40// ===========================================================================
41// method definitions
42// ===========================================================================
43
45 TesselatedPolygon("", "", RGBColor::BLACK, {}, false, false, 0, 0, 0, "", false, "", Parameterised::Map()),
46 GNEAdditional("", net, GLO_POLYGON, tag, GUIIconSubSys::getIcon(GUIIcon::POLY), "", {}, {}, {}, {}, {}, {}),
47mySimplifiedShape(false) {
48 // reset default values
50}
51
52
53GNEPoly::GNEPoly(GNENet* net, const std::string& id, const std::string& type, const PositionVector& shape, bool geo, bool fill, double lineWidth,
54 const RGBColor& color, double layer, double angle, const std::string& imgFile, bool relativePath, const std::string& name,
55 const Parameterised::Map& parameters) :
56 TesselatedPolygon(id, type, color, shape, geo, fill, lineWidth, layer, angle, imgFile, relativePath, name, parameters),
57 GNEAdditional(id, net, GLO_POLYGON, SUMO_TAG_POLY, GUIIconSubSys::getIcon(GUIIcon::POLY), "", {}, {}, {}, {}, {}, {}),
58mySimplifiedShape(false) {
59 // check if imgFile is valid
60 if (!imgFile.empty() && GUITexturesHelper::getTextureID(imgFile) == -1) {
62 }
63 // set GEO shape
65 if (geo) {
66 for (int i = 0; i < (int) myGeoShape.size(); i++) {
68 }
69 } else {
70 for (int i = 0; i < (int) myGeoShape.size(); i++) {
72 }
73 }
74 // update centering boundary without updating grid
76 // update geometry
78}
79
80
81GNEPoly::GNEPoly(SumoXMLTag tag, GNENet* net, const std::string& id, const PositionVector& shape, bool geo, const std::string& name,
82 const Parameterised::Map& parameters) :
83 TesselatedPolygon(id, getJuPedSimType(tag), getJuPedSimColor(tag), shape, geo, getJuPedSimFill(tag), 1,
84 getJuPedSimLayer(tag), 0, "", false, name, parameters),
85 GNEAdditional(id, net, getJuPedSimGLO(tag), tag, getJuPedSimIcon(tag), "", {}, {}, {}, {}, {}, {}),
86mySimplifiedShape(false) {
87 // set GEO shape
89 if (geo) {
90 for (int i = 0; i < (int) myGeoShape.size(); i++) {
92 }
93 } else {
94 for (int i = 0; i < (int) myGeoShape.size(); i++) {
96 }
97 }
98 // update centering boundary without updating grid
100 // update geometry
102}
103
104
106
107
110 // edit depending if shape is blocked
112 // move entire shape
113 return new GNEMoveOperation(this, myShape);
114 } else {
115 // continue depending of tag
116 switch (getTagProperty().getTag()) {
119 // calculate move shape operation maintain shape closed
120 return calculateMoveShapeOperation(this, myShape, true);
121 default:
122 // calculate move shape operation
123 return calculateMoveShapeOperation(this, myShape, false);
124 }
125 }
126}
127
128
129void
130GNEPoly::removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) {
131 // get original shape
132 PositionVector shape = myShape;
133 // check shape size
134 if (shape.size() > 2) {
135 // obtain index
136 int index = shape.indexOfClosest(clickedPosition);
137 // get snap radius
139 // check if we have to create a new index
140 if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {
141 // remove geometry point
142 shape.erase(shape.begin() + index);
143 // commit new shape
144 undoList->begin(this, "remove geometry point of " + getTagStr());
146 undoList->end();
147 }
148 }
149}
150
151
152std::string
154 return "";
155}
156
157
158void
160 // just update polygon geometry
162 myTesselation.clear();
163}
164
165
170
171
172double
174 return s.polySize.getExaggeration(s, this);
175}
176
177
178void
179GNEPoly::updateCenteringBoundary(const bool updateGrid) {
180 // Remove object from net
181 if (updateGrid) {
183 }
184 // use shape as boundary
186 // grow boundary
188 // add object into net
189 if (updateGrid) {
191 }
192}
193
194
195void
196GNEPoly::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
197 // nothing to split
198}
199
200
201void
203 writeXML(device, myGEO);
204}
205
206
207bool
209 return true;
210}
211
212
213std::string
215 return "";
216}
217
218
219void
221 // nothing to fix
222}
223
224
227 return GUIGlObject::getGlID();
228}
229
230
231bool
233 // get edit modes
234 const auto& editModes = myNet->getViewNet()->getEditModes();
235 // check if we're in move mode
236 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
238 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
239 // only move the first element
241 } else {
242 return false;
243 }
244}
245
246
247std::string
249 return myNet->getMicrosimID();
250}
251
252
255 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
256 buildPopupHeader(ret, app);
259 // build selection and show parameters menu
262 buildPositionCopyEntry(ret, app);
263 new FXMenuSeparator(ret);
264 FXMenuCommand* simplifyShape = GUIDesigns::buildFXMenuCommand(ret, TL("Simplify Shape"), TL("Replace current shape with a rectangle"), nullptr, &parent, MID_GNE_POLYGON_SIMPLIFY_SHAPE);
265 // disable simplify shape if polygon was already simplified
266 if (mySimplifiedShape || myShape.size() <= 2) {
267 simplifyShape->disable();
268 }
269 // only allow open/close for non juPedSim polygons
271 if (myShape.isClosed()) {
272 GUIDesigns::buildFXMenuCommand(ret, TL("Open shape"), TL("Open polygon's shape"), nullptr, &parent, MID_GNE_POLYGON_OPEN);
273 } else {
274 GUIDesigns::buildFXMenuCommand(ret, TL("Close shape"), TL("Close polygon's shape"), nullptr, &parent, MID_GNE_POLYGON_CLOSE);
275 }
276 }
277 GUIDesigns::buildFXMenuCommand(ret, TL("Select elements within polygon"), TL("Select elements within polygon boundary"), nullptr, &parent, MID_GNE_POLYGON_SELECT);
278 // add separator
279 new FXMenuSeparator(ret);
280 // create a extra FXMenuCommand if mouse is over a vertex
281 const int index = getVertexIndex(myNet->getViewNet()->getPositionInformation(), false);
282 if (index != -1) {
283 // check if we're in network mode
285 GUIDesigns::buildFXMenuCommand(ret, "Set custom Geometry Point", nullptr, &parent, MID_GNE_CUSTOM_GEOMETRYPOINT);
286 }
287 FXMenuCommand* removeGeometryPoint = GUIDesigns::buildFXMenuCommand(ret, TL("Remove geometry point"), TL("Remove geometry point under mouse"), nullptr, &parent, MID_GNE_POLYGON_DELETE_GEOMETRY_POINT);
288 FXMenuCommand* setFirstPoint = GUIDesigns::buildFXMenuCommand(ret, TL("Set first geometry point"), TL("Set first geometry point"), nullptr, &parent, MID_GNE_POLYGON_SET_FIRST_POINT);
289 // disable setFirstPoint if shape only have three points
290 if ((myShape.isClosed() && (myShape.size() <= 4)) || (!myShape.isClosed() && (myShape.size() <= 2))) {
291 removeGeometryPoint->disable();
292 }
293 // disable setFirstPoint if mouse is over first point
294 if (index == 0) {
295 setFirstPoint->disable();
296 }
297 }
298 return ret;
299}
300
301
302void
304 // first check if poly can be drawn
307 GUIPolygon::checkDraw(s, this, this)) {
308 // draw boundary
309 const auto boundary = getCenteringBoundary();
311 // get exaggeration
312 const double polyExaggeration = getExaggeration(s);
313 // get detail level
314 const auto d = s.getDetailLevel(polyExaggeration);
315 // draw geometry only if we'rent in drawForObjectUnderCursor mode
316 if (s.checkDrawPoly(boundary, isAttributeCarrierSelected())) {
317 // get colors
319 // push layer matrix
321 // translate to front
323 // draw polygon
324 drawPolygon(s, d, color, polyExaggeration);
325 // draw contour if don't move whole polygon
327 // get darker color
328 const RGBColor darkerColor = color.changedBrightness(-32);
329 // draw contour
330 drawPolygonContour(s, d, darkerColor, polyExaggeration);
331 // draw geometry points
332 drawGeometryPoints(s, d, darkerColor, polyExaggeration);
333 }
334 // pop layer matrix
336 // draw name and type
338 // draw lock icon
340 // draw dotted contour
342 }
343 // calculate contour
344 calculateContourPolygons(s, d, getShapeLayer(), polyExaggeration, getFill());
345 }
346}
347
348
349int
350GNEPoly::getVertexIndex(Position pos, bool snapToGrid) {
351 // check if position has to be snapped to grid
352 if (snapToGrid) {
353 pos = myNet->getViewNet()->snapToActiveGrid(pos);
354 }
355 // first check if vertex already exists
356 for (const auto& shapePosition : myShape) {
357 if (shapePosition.distanceTo2D(pos) < myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.polygonGeometryPointRadius) {
358 return myShape.indexOfClosest(shapePosition);
359 }
360 }
361 return -1;
362}
363
364
365void
366GNEPoly::deleteGeometryPoint(const Position& pos, bool allowUndo) {
367 if (myShape.size() > 1) {
368 // obtain index
369 PositionVector modifiedShape = myShape;
370 int index = modifiedShape.indexOfClosest(pos);
371 // remove point dependending of
372 if (myShape.isClosed() && (index == 0 || index == (int)modifiedShape.size() - 1) && (myShape.size() > 2)) {
373 modifiedShape.erase(modifiedShape.begin());
374 modifiedShape.erase(modifiedShape.end() - 1);
375 modifiedShape.push_back(modifiedShape.front());
376 } else {
377 modifiedShape.erase(modifiedShape.begin() + index);
378 }
379 // set new shape depending of allowUndo
380 if (allowUndo) {
381 myNet->getViewNet()->getUndoList()->begin(this, "delete geometry point");
384 } else {
385 // first remove object from grid due shape is used for boundary
387 // set new shape
388 myShape = modifiedShape;
389 // disable simplified shape flag
390 mySimplifiedShape = false;
391 // add object into grid again
393 }
394 myTesselation.clear();
395 } else {
396 WRITE_WARNING(TL("Number of remaining points insufficient"))
397 }
398}
399
400
401bool
403 return myShape.isClosed();
404}
405
406
407void
408GNEPoly::openPolygon(bool allowUndo) {
409 // only open if shape is closed
410 if (myShape.isClosed()) {
411 if (allowUndo) {
412 myNet->getViewNet()->getUndoList()->begin(this, "open polygon");
415 } else {
416 myShape.pop_back();
417 // disable simplified shape flag
418 mySimplifiedShape = false;
419 // update geometry to avoid grabbing Problems
421 }
422 } else {
423 WRITE_WARNING(TL("Polygon already opened"))
424 }
425}
426
427
428void
429GNEPoly::closePolygon(bool allowUndo) {
430 // only close if shape is opened
431 if (!myShape.isClosed()) {
432 if (allowUndo) {
433 myNet->getViewNet()->getUndoList()->begin(this, "close shape");
436 } else {
438 // disable simplified shape flag
439 mySimplifiedShape = false;
440 // update geometry to avoid grabbing Problems
442 }
443 } else {
444 WRITE_WARNING(TL("Polygon already closed"))
445 }
446}
447
448
449void
450GNEPoly::changeFirstGeometryPoint(int oldIndex, bool allowUndo) {
451 // check that old index is correct
452 if (oldIndex >= (int)myShape.size()) {
453 throw InvalidArgument("Invalid old Index");
454 } else if (oldIndex == 0) {
455 WRITE_WARNING(TL("Selected point must be different of the first point"))
456 } else {
457 // Configure new shape
458 PositionVector newShape;
459 for (int i = oldIndex; i < (int)myShape.size(); i++) {
460 newShape.push_back(myShape[i]);
461 }
462 if (myShape.isClosed()) {
463 for (int i = 1; i < oldIndex; i++) {
464 newShape.push_back(myShape[i]);
465 }
466 newShape.push_back(newShape.front());
467 } else {
468 for (int i = 0; i < oldIndex; i++) {
469 newShape.push_back(myShape[i]);
470 }
471 }
472 // set new rotated shape
473 if (allowUndo) {
474 myNet->getViewNet()->getUndoList()->begin(this, "change first geometry point");
477 } else {
478 // set new shape
479 myShape = newShape;
480 // disable simplified shape flag
481 mySimplifiedShape = false;
482 // update geometry to avoid grabbing Problems
484 }
485 }
486}
487
488
489void
490GNEPoly::simplifyShape(bool allowUndo) {
491 if (!mySimplifiedShape && myShape.size() > 2) {
492 const Boundary b = myShape.getBoxBoundary();
493 // create a square as simplified shape
494 PositionVector simplifiedShape;
495 simplifiedShape.push_back(Position(b.xmin(), b.ymin()));
496 simplifiedShape.push_back(Position(b.xmin(), b.ymax()));
497 simplifiedShape.push_back(Position(b.xmax(), b.ymax()));
498 simplifiedShape.push_back(Position(b.xmax(), b.ymin()));
499 if (myShape.isClosed()) {
500 simplifiedShape.push_back(simplifiedShape[0]);
501 }
502 // set new shape depending of allowUndo
503 if (allowUndo) {
504 myNet->getViewNet()->getUndoList()->begin(this, "simplify shape");
507 } else {
508 // set new shape
509 myShape = simplifiedShape;
510 // update geometry to avoid grabbing Problems
512 }
513 // change flag after setting simplified shape
514 mySimplifiedShape = true;
515 } else {
516 WRITE_WARNING(TL("Polygon already simplified"))
517 }
518}
519
520
521std::string
523 switch (key) {
524 case SUMO_ATTR_ID:
525 return myID;
526 case SUMO_ATTR_SHAPE:
527 if ((GeoConvHelper::getFinal().getProjString() != "!") && myGEO) {
528 return TL("Using GEO Shape");
529 } else {
530 return toString(myShape);
531 }
533 if (GeoConvHelper::getFinal().getProjString() != "!") {
535 } else {
536 return TL("No geo-conversion defined");
537 }
539 if ((myShape.size() > 1) && (myShape.front() == myShape.back())) {
540 return True;
541 } else {
542 return False;
543 }
544 case SUMO_ATTR_COLOR:
545 return toString(getShapeColor());
546 case SUMO_ATTR_FILL:
547 return toString(myFill);
549 return toString(myLineWidth);
550 case SUMO_ATTR_LAYER:
552 return "default";
553 } else {
554 return toString(getShapeLayer());
555 }
556 case SUMO_ATTR_TYPE:
557 return getShapeType();
559 return getShapeImgFile();
562 case SUMO_ATTR_ANGLE:
564 case SUMO_ATTR_GEO:
565 return toString(myGEO);
566 case SUMO_ATTR_NAME:
567 return getShapeName();
569 return toString(myShape.isClosed());
572 default:
573 return getCommonAttribute(key);
574 }
575}
576
577
578double
580 throw InvalidArgument(getTagStr() + " attribute '" + toString(key) + "' not allowed");
581}
582
583
588
589
590void
591GNEPoly::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
592 if (value == getAttribute(key)) {
593 return; //avoid needless changes, later logic relies on the fact that attributes have changed
594 }
595 switch (key) {
596 case SUMO_ATTR_ID:
597 case SUMO_ATTR_SHAPE:
600 case SUMO_ATTR_COLOR:
601 case SUMO_ATTR_FILL:
603 case SUMO_ATTR_LAYER:
604 case SUMO_ATTR_TYPE:
607 case SUMO_ATTR_ANGLE:
608 case SUMO_ATTR_GEO:
609 case SUMO_ATTR_NAME:
612 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
613 break;
614 default:
615 setCommonAttribute(key, value, undoList);
616 break;
617 }
618}
619
620
621bool
622GNEPoly::isValid(SumoXMLAttr key, const std::string& value) {
623 switch (key) {
624 case SUMO_ATTR_ID:
626 case SUMO_ATTR_SHAPE:
628 // empty shapes AREN'T allowed
629 if (value.empty()) {
630 return false;
631 } else {
632 return canParse<PositionVector>(value);
633 }
635 return canParse<bool>(value);
636 case SUMO_ATTR_COLOR:
637 return canParse<RGBColor>(value);
638 case SUMO_ATTR_FILL:
639 return canParse<bool>(value);
641 return canParse<double>(value) && (parse<double>(value) >= 0);
642 case SUMO_ATTR_LAYER:
643 if (value == "default") {
644 return true;
645 } else {
646 return canParse<double>(value);
647 }
648 case SUMO_ATTR_TYPE:
649 return true;
651 if (value == "") {
652 return true;
653 } else {
654 // check that image can be loaded
655 return GUITexturesHelper::getTextureID(value) != -1;
656 }
658 return canParse<bool>(value);
659 case SUMO_ATTR_ANGLE:
660 return canParse<double>(value);
661 case SUMO_ATTR_GEO:
662 return canParse<bool>(value);
663 case SUMO_ATTR_NAME:
666 if (canParse<bool>(value)) {
667 bool closePolygon = parse<bool>(value);
668 if (closePolygon && (myShape.begin() == myShape.end())) {
669 // Polygon already closed, then invalid value
670 return false;
671 } else if (!closePolygon && (myShape.begin() != myShape.end())) {
672 // Polygon already open, then invalid value
673 return false;
674 } else {
675 return true;
676 }
677 } else {
678 return false;
679 }
681 return areParametersValid(value);
682 default:
683 return isCommonValid(key, value);
684 }
685}
686
687
688bool
690 switch (key) {
691 case SUMO_ATTR_SHAPE:
692 if (GeoConvHelper::getFinal().getProjString() != "!") {
693 return myGEO == false;
694 } else {
695 return true;
696 }
697 case SUMO_ATTR_GEO:
698 return GeoConvHelper::getFinal().getProjString() != "!";
700 if (GeoConvHelper::getFinal().getProjString() != "!") {
701 return myGEO == true;
702 } else {
703 return false;
704 }
706 return myShape.size() > 1;
707 default:
708 return true;
709 }
710}
711
712
713std::string
715 return getTagStr() + ": " + getID();
716}
717
718
719std::string
721 return getTagStr();
722}
723
724// ===========================================================================
725// private
726// ===========================================================================
727
728void
729GNEPoly::setAttribute(SumoXMLAttr key, const std::string& value) {
730 switch (key) {
731 case SUMO_ATTR_ID: {
732 // update microsimID
733 setAdditionalID(value);
734 // set named ID
735 myID = value;
736 break;
737 }
738 case SUMO_ATTR_SHAPE: {
739 // set new shape
740 myShape = parse<PositionVector>(value);
741 // set GEO shape
743 for (int i = 0; i < (int) myGeoShape.size(); i++) {
745 }
746 // disable simplified shape flag
747 mySimplifiedShape = false;
748 // update geometry
750 // update centering boundary
752 break;
753 }
754 case SUMO_ATTR_GEOSHAPE: {
755 // set new GEO shape
756 myGeoShape = parse<PositionVector>(value);
757 // set shape
759 for (int i = 0; i < (int) myShape.size(); i++) {
761 }
762 // disable simplified shape flag
763 mySimplifiedShape = false;
764 // update geometry
766 // update centering boundary
768 break;
769 }
770 case GNE_ATTR_CLOSESHAPE: {
771 auto shape = myShape;
772 if (parse<bool>(value)) {
773 shape.push_back(shape.front());
774 } else {
775 shape.pop_back();
776 }
778 break;
779 }
780 case SUMO_ATTR_COLOR:
781 setShapeColor(parse<RGBColor>(value));
782 break;
783 case SUMO_ATTR_FILL:
784 myFill = parse<bool>(value);
786 break;
788 myLineWidth = parse<double>(value);
789 break;
790 case SUMO_ATTR_LAYER:
791 if (value == "default") {
793 } else {
794 setShapeLayer(parse<double>(value));
795 }
796 break;
797 case SUMO_ATTR_TYPE:
798 setShapeType(value);
799 break;
801 setShapeImgFile(value);
802 // all textures must be refresh
804 break;
806 setShapeRelativePath(parse<bool>(value));
807 break;
808 case SUMO_ATTR_ANGLE:
809 setShapeNaviDegree(parse<double>(value));
810 break;
811 case SUMO_ATTR_GEO:
812 myGEO = parse<bool>(value);
813 // update centering boundary
815 break;
816 case SUMO_ATTR_NAME:
817 setShapeName(value);
818 break;
820 if (parse<bool>(value)) {
823 } else {
824 myShape.pop_back();
825 myGeoShape.pop_back();
826 }
827 // disable simplified shape flag
828 mySimplifiedShape = false;
829 // update geometry
831 // update centering boundary
833 break;
836 break;
837 default:
838 setCommonAttribute(key, value);
839 break;
840 }
841}
842
843
844void
846 // update new shape
847 myShape = moveResult.shapeToUpdate;
848 // update geometry
850}
851
852
853void
855 // commit new shape
856 undoList->begin(this, "moving " + toString(SUMO_ATTR_SHAPE) + " of " + getTagStr());
858 undoList->end();
859}
860
861
862void
864 const RGBColor& color, const double exaggeration) const {
865 // check if we're drawing a polygon or a polyline
866 if (getFill()) {
867 // draw inner polygon
869 } else {
870 // push matrix
872 // set color
873 GLHelper::setColor(color);
874 // draw geometry (polyline)
876 // pop matrix
878 }
879}
880
881
882void
884 const RGBColor& color, const double exaggeration) const {
885 // push contour matrix
887 // translate to front
888 glTranslated(0, 0, 0.1);
889 // set color
890 GLHelper::setColor(color);
891 // draw polygon contour
893 // pop contour matrix
895}
896
897
898void
900 const RGBColor& color, const double exaggeration) const {
901 // draw shape points only in supermode network
903 // check if we're in move mode
905 // get geometry point sizes
906 const double geometryPointSize = s.neteditSizeSettings.polygonGeometryPointRadius * (moveMode ? 1 : 0.5);
907 // draw geometry points
908 GUIGeometry::drawGeometryPoints(d, myAdditionalGeometry.getShape(), color, geometryPointSize, exaggeration,
910 // draw dotted contours for geometry points if we're in move mode
911 if (moveMode) {
914 }
915 }
916}
917
918
919void
921 // get name position
923 // draw name
924 drawName(namePos, s.scale, s.polyName, s.angle);
925 // check if draw poly type
926 if (s.polyType.show(this)) {
927 const Position p = namePos + Position(0, -0.6 * s.polyType.size / s.scale);
929 }
930}
931
932/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ MID_GNE_POLYGON_CLOSE
close opened polygon
@ MID_GNE_POLYGON_SET_FIRST_POINT
Set a vertex of polygon as first vertex.
@ MID_GNE_POLYGON_SELECT
select elements within polygon boundary
@ MID_GNE_CUSTOM_GEOMETRYPOINT
set custom geometry point
@ MID_GNE_POLYGON_DELETE_GEOMETRY_POINT
delete geometry point
@ MID_GNE_POLYGON_OPEN
open closed polygon
@ MID_GNE_POLYGON_SIMPLIFY_SHAPE
simplify polygon geometry
unsigned int GUIGlID
Definition GUIGlObject.h:43
@ GLO_POLYGON
polygon
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:315
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_POLY
begin/end of the description of a polygon
@ GNE_TAG_JPS_OBSTACLE
polygon used for draw juPedSim obstacles
@ GNE_TAG_JPS_WALKABLEAREA
polygon used for draw juPedSim walkable areas
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LINEWIDTH
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ GNE_ATTR_CLOSESHAPE
@ 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:27
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:343
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:136
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:124
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void drawBoundary(const GUIVisualizationSettings &s, const Boundary &b)
Draw a boundary (used for debugging)
Definition GLHelper.cpp:961
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
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:782
An Element which don't belong to GNENet but has influence in the simulation.
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void setAdditionalID(const std::string &newID)
set additional ID
GNEContour myAdditionalContour
variable used for draw additional contours
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void calculateContourPolygons(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double layer, const double exaggeration, const bool filledShape) const
calculate contour for polygons
Boundary myAdditionalBoundary
Additional Boundary (used only by additionals placed over grid)
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
static const std::string True
true value in string format (used for comparing boolean values in getAttribute(......
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
bool isCommonValid(SumoXMLAttr key, const std::string &value)
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
static const std::string False
true value in string format(used for comparing boolean values in getAttribute(...))
std::string getCommonAttribute(SumoXMLAttr key) const
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void clearContour() const
void clear contour
void drawDottedContourGeometryPoints(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const PositionVector &shape, const double radius, const double scale, const double lineWidth) const
draw dotted contour for geometry points
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
GNEMoveOperation * calculateMoveShapeOperation(const GUIGlObject *obj, const PositionVector originalShape, const bool maintainShapeClosed)
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)
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1390
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1400
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
bool mySimplifiedShape
flag to indicate if polygon is simplified
Definition GNEPoly.h:239
std::string getAdditionalProblem() const override
return a string with the current additional problem (must be reimplemented in all detector children)
Definition GNEPoly.cpp:214
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
Definition GNEPoly.cpp:714
std::string getParentName() const override
Returns the name of the parent object.
Definition GNEPoly.cpp:248
double getAttributeDouble(SumoXMLAttr key) const override
Definition GNEPoly.cpp:579
~GNEPoly()
Destructor.
Definition GNEPoly.cpp:105
bool isValid(SumoXMLAttr key, const std::string &value) override
method for checking if the key and their conrrespond attribute are valids
Definition GNEPoly.cpp:622
void updateGeometry() override
update pre-computed geometry information
Definition GNEPoly.cpp:159
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
Definition GNEPoly.cpp:720
void fixAdditionalProblem() override
fix additional problem (must be reimplemented in all detector children)
Definition GNEPoly.cpp:220
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
Definition GNEPoly.cpp:202
void drawPolygonNameAndType(const GUIVisualizationSettings &s) const
draw polygon name and type
Definition GNEPoly.cpp:920
GNEPoly(SumoXMLTag tag, GNENet *net)
default Constructor
Definition GNEPoly.cpp:44
GNEMoveOperation * getMoveOperation() override
get move operation
Definition GNEPoly.cpp:109
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:350
PositionVector myGeoShape
Latitude of Polygon.
Definition GNEPoly.h:236
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
Definition GNEPoly.cpp:173
void closePolygon(bool allowUndo=true)
close polygon
Definition GNEPoly.cpp:429
void changeFirstGeometryPoint(int oldIndex, bool allowUndo=true)
change first geometry point
Definition GNEPoly.cpp:450
std::string getAttribute(SumoXMLAttr key) const override
Definition GNEPoly.cpp:522
bool checkDrawMoveContour() const override
check if draw move contour (red)
Definition GNEPoly.cpp:232
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList) override
commit move shape
Definition GNEPoly.cpp:854
bool isAdditionalValid() const override
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
Definition GNEPoly.cpp:208
void setMoveShape(const GNEMoveResult &moveResult) override
set move shape
Definition GNEPoly.cpp:845
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:591
void deleteGeometryPoint(const Position &pos, bool allowUndo=true)
delete the geometry point closest to the given pos
Definition GNEPoly.cpp:366
Position getPositionInView() const override
Returns position of shape in view.
Definition GNEPoly.cpp:167
void drawGeometryPoints(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw geometry points
Definition GNEPoly.cpp:899
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList) override
remove geometry point in the clicked position
Definition GNEPoly.cpp:130
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
Definition GNEPoly.cpp:303
void drawPolygon(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw polygon
Definition GNEPoly.cpp:863
bool isAttributeEnabled(SumoXMLAttr key) const override
Definition GNEPoly.cpp:689
void drawPolygonContour(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw contour
Definition GNEPoly.cpp:883
bool isPolygonClosed() const
check if polygon is closed
Definition GNEPoly.cpp:402
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own popup-menu.
Definition GNEPoly.cpp:254
void simplifyShape(bool allowUndo=true)
replace the current shape with a rectangle
Definition GNEPoly.cpp:490
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
Definition GNEPoly.cpp:196
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
Definition GNEPoly.cpp:179
const Parameterised::Map & getACParametersMap() const override
get parameters map
Definition GNEPoly.cpp:585
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition GNEPoly.cpp:226
std::string generateChildID(SumoXMLTag childTag)
gererate a new ID for an element child
Definition GNEPoly.cpp:153
void openPolygon(bool allowUndo=true)
open polygon
Definition GNEPoly.cpp:408
bool isJuPedSimElement() const
return true if tag correspond to a JuPedSim element
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...
const GUIGlObject * getGUIGlObjectFront() const
get front GUIGLObject or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
const GNEViewNetHelper::EditNetworkElementShapes & getEditNetworkElementShapes() const
get Edit Shape module
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
GNEViewParent * getViewParent() const
get the net object
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
GNEUndoList * getUndoList() const
get the undoList object
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
GNEMoveFrame * getMoveFrame() const
get frame for move elements
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel, const bool disable=false)
build menu command
The popup menu of a globject.
static void drawGeometryPoints(const GUIVisualizationSettings::Detail d, const PositionVector &shape, const RGBColor &color, const double radius, const double exaggeration, const bool editingElevation)
draw geometry points
static void drawGeometry(const GUIVisualizationSettings::Detail d, 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
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
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.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
GUIGlID getGlID() const
Returns the numerical id of the object.
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() )
static bool checkDraw(const GUIVisualizationSettings &s, const SUMOPolygon *polygon, const GUIGlObject *o)
check if Polygon can be drawn
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.
double polyCustomLayer
the custom layer for polygons
bool checkDrawPoly(const Boundary &b, const bool selected) const
check if draw polygon
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
bool polyUseCustomLayer
whether the rendering layer of polygons should be overriden
double scale
information about a lane's width (temporary, used for a single view)
GUIVisualizationTextSettings polyName
GUIVisualizationSizeSettings polySize
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.
const std::string & getProjString() const
Returns the original projection definition.
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 const std::vector< SumoXMLTag > polygons
polygon namespace
Static storage of an output device and its base (abstract) implementation.
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
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
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
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.
double myLineWidth
The line width for drawing an unfilled polygon.
bool myGEO
specify if shape is handled as GEO coordinate (Main used in netedit)
void writeXML(OutputDevice &out, bool geo=false) const
bool myFill
Information whether the polygon has to be filled.
bool getFill() const
Returns whether the polygon is filled.
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
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
static void drawLockIcon(const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position position, 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 segmentWidthSmall
width of small dotted contour segments
static const double segmentWidth
width of dotted contour segments
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