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-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/****************************************************************************/
18// A class for visualizing and editing POIS in netedit (adapted from
19// GUIPolygon and NLHandler)
20/****************************************************************************/
21
23
27#include <netedit/GNENet.h>
29#include <netedit/GNEUndoList.h>
37
38#include "GNEPoly.h"
39
40// ===========================================================================
41// method definitions
42// ===========================================================================
43
44#ifdef _MSC_VER
45#pragma warning(push)
46#pragma warning(disable: 4355) // mask warning about "this" in initializers
47#endif
49 TesselatedPolygon("", "", RGBColor::BLACK, {}, false, false, DEFAULT_LINEWIDTH, DEFAULT_LAYER,
50DEFAULT_ANGLE, DEFAULT_IMG_FILE, DEFAULT_NAME, DEFAULT_HEIGHT, DEFAULT_PARAMETERS),
51 GNEAdditional(net, tag),
52myMoveElementShape(new GNEMoveElementShape(this)) {
53}
54
55
56GNEPoly::GNEPoly(const std::string& id, GNENet* net, FileBucket* fileBucket, const std::string& type, const PositionVector& shape,
57 const bool geo, const bool fill, const double lineWidth, const RGBColor& color, const double layer, const double angle,
58 const std::string& imgFile, const std::string& name, const double height, const Parameterised::Map& parameters) :
59 TesselatedPolygon(id, type, color, shape, geo, fill, lineWidth, layer, angle, imgFile, "", height, parameters),
60 GNEAdditional(id, net, SUMO_TAG_POLY, fileBucket, name),
61 myMoveElementShape(new GNEMoveElementShape(this, myShape, false)),
62 myClosedShape(shape.isClosed()) {
63 // check if imgFile is valid
64 if (!imgFile.empty() && GUITexturesHelper::getTextureID(imgFile) == -1) {
66 }
67 // set GEO shape
69 if (geo) {
70 for (int i = 0; i < (int) myGeoShape.size(); i++) {
72 }
73 } else {
74 for (int i = 0; i < (int) myGeoShape.size(); i++) {
76 }
77 }
78 // update centering boundary without updating grid
80 // update geometry
82}
83
84
85GNEPoly::GNEPoly(SumoXMLTag tag, const std::string& id, GNENet* net, FileBucket* fileBucket, const PositionVector& shape,
86 const bool geo, const std::string& name, const Parameterised::Map& parameters) :
87 TesselatedPolygon(id, getJuPedSimType(tag), getJuPedSimColor(tag), shape, geo, getJuPedSimFill(tag), DEFAULT_LINEWIDTH,
88 getJuPedSimLayer(tag), DEFAULT_ANGLE, DEFAULT_IMG_FILE, DEFAULT_NAME, DEFAULT_HEIGHT, parameters),
89 GNEAdditional(id, net, tag, fileBucket, name),
90 myMoveElementShape(new GNEMoveElementShape(this, myShape, (tag == GNE_TAG_JPS_WALKABLEAREA) || (tag == GNE_TAG_JPS_OBSTACLE))),
91 myClosedShape(shape.isClosed()),
92 mySimplifiedShape(false) {
93 // set GEO shape
95 if (geo) {
96 for (int i = 0; i < (int) myGeoShape.size(); i++) {
98 }
99 } else {
100 for (int i = 0; i < (int) myGeoShape.size(); i++) {
102 }
103 }
104 // update centering boundary without updating grid
106 // update geometry
108}
109#ifdef _MSC_VER
110#pragma warning(pop)
111#endif
112
113
117
118
123
124
127 return this;
128}
129
130
131const Parameterised*
133 return this;
134}
135
136
137std::string
139 return "";
140}
141
142
143void
145 // just update polygon geometry
147 myTesselation.clear();
148}
149
150
155
156
157double
159 return s.polySize.getExaggeration(s, this);
160}
161
162
163void
164GNEPoly::updateCenteringBoundary(const bool updateGrid) {
165 // Remove object from net
166 if (updateGrid) {
168 }
169 // use shape as boundary
171 // grow boundary
173 // add object into net
174 if (updateGrid) {
176 }
177}
178
179
180void
181GNEPoly::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
182 // nothing to split
183}
184
185
186void
188 device.openTag(SUMO_TAG_POLY);
189 // write common additional attributes
191 // write specific attributes
192 PositionVector shape = getShape();
193 if (myGEO) {
194 device.writeAttr(SUMO_ATTR_GEO, true);
195 for (int i = 0; i < (int) shape.size(); i++) {
197 }
198 }
199 if (getShapeType().size() > 0) {
201 }
206 }
207 if (getHeight() != DEFAULT_HEIGHT) {
209 }
211
213 device.writeAttr(SUMO_ATTR_SHAPE, shape);
214 device.setPrecision();
217 }
220 }
221
222 XMLHelpers::writeParams(device, *this);
223 device.closeTag();
224}
225
226
227bool
229 return true;
230}
231
232
233std::string
235 return "";
236}
237
238
239void
241 // nothing to fix
242}
243
244
247 return GUIGlObject::getGlID();
248}
249
250
251bool
253 // get edit modes
254 const auto& editModes = myNet->getViewNet()->getEditModes();
255 // check if we're in move mode
256 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
258 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
259 // only move the first element
261 } else {
262 return false;
263 }
264}
265
266
267std::string
269 return myNet->getMicrosimID();
270}
271
272
275 // create popup
276 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
277 // build common options
279 FXMenuCommand* simplifyShape = GUIDesigns::buildFXMenuCommand(ret, TL("Simplify Shape"), TL("Replace current shape with a rectangle"), nullptr, &parent, MID_GNE_POLYGON_SIMPLIFY_SHAPE);
280 // disable simplify shape if polygon was already simplified
281 if (mySimplifiedShape || myShape.size() <= 2) {
282 simplifyShape->disable();
283 }
284 // only allow open/close for non juPedSim polygons
286 if (myShape.isClosed()) {
287 GUIDesigns::buildFXMenuCommand(ret, TL("Open shape"), TL("Open polygon's shape"), nullptr, &parent, MID_GNE_POLYGON_OPEN);
288 } else {
289 GUIDesigns::buildFXMenuCommand(ret, TL("Close shape"), TL("Close polygon's shape"), nullptr, &parent, MID_GNE_POLYGON_CLOSE);
290 }
291 }
292 GUIDesigns::buildFXMenuCommand(ret, TL("Select elements within polygon"), TL("Select elements within polygon boundary"), nullptr, &parent, MID_GNE_POLYGON_SELECT);
293 if (myShape.size() > 3) {
294 GUIDesigns::buildFXMenuCommand(ret, TL("Triangulate polygon"), TL("Convert the current polygon in triangles"), nullptr, &parent, MID_GNE_POLYGON_TRIANGULATE);
295 }
296 // create a extra FXMenuCommand if mouse is over a vertex
297 const int index = getVertexIndex(myNet->getViewNet()->getPositionInformation(), false);
298 if (index != -1) {
299 // add separator
300 new FXMenuSeparator(ret);
301 // check if we're in network mode
303 GUIDesigns::buildFXMenuCommand(ret, "Set custom Geometry Point", nullptr, &parent, MID_GNE_CUSTOM_GEOMETRYPOINT);
304 }
305 FXMenuCommand* removeGeometryPoint = GUIDesigns::buildFXMenuCommand(ret, TL("Remove geometry point"), TL("Remove geometry point under mouse"), nullptr, &parent, MID_GNE_POLYGON_DELETE_GEOMETRY_POINT);
306 FXMenuCommand* setFirstPoint = GUIDesigns::buildFXMenuCommand(ret, TL("Set first geometry point"), TL("Set first geometry point"), nullptr, &parent, MID_GNE_POLYGON_SET_FIRST_POINT);
307 // disable setFirstPoint if shape only have three points
308 if ((myShape.isClosed() && (myShape.size() <= 4)) || (!myShape.isClosed() && (myShape.size() <= 2))) {
309 removeGeometryPoint->disable();
310 }
311 // disable setFirstPoint if mouse is over first point
312 if (index == 0) {
313 setFirstPoint->disable();
314 }
315 }
316 return ret;
317}
318
319
320void
322 // first check if poly can be drawn
325 GUIPolygon::checkDraw(s, this, this)) {
326 // draw boundary
327 const auto boundary = getCenteringBoundary();
329 // get exaggeration
330 const double polyExaggeration = getExaggeration(s);
331 // get detail level
332 const auto d = s.getDetailLevel(polyExaggeration);
333 // draw geometry only if we'rent in drawForObjectUnderCursor mode
334 if (s.checkDrawPoly(boundary, isAttributeCarrierSelected())) {
335 // get colors
337 // push layer matrix
339 // translate to front
341 // draw polygon
342 drawPolygon(s, d, color, polyExaggeration);
343 // draw contour if don't move whole polygon
345 // get darker color
346 const RGBColor darkerColor = color.changedBrightness(-32);
347 // draw contour
348 drawPolygonContour(s, d, darkerColor, polyExaggeration);
349 // draw geometry points
350 drawGeometryPoints(s, d, darkerColor, polyExaggeration);
351 }
352 // pop layer matrix
354 // draw name and type
356 // draw lock icon
358 // draw dotted contour
360 }
361 // calculate contour
362 calculateContourPolygons(s, d, getShapeLayer(), polyExaggeration, getFill());
363 }
364}
365
366
367int
368GNEPoly::getVertexIndex(Position pos, bool snapToGrid) {
369 // check if position has to be snapped to grid
370 if (snapToGrid) {
371 pos = myNet->getViewNet()->snapToActiveGrid(pos);
372 }
373 // first check if vertex already exists
374 for (const auto& shapePosition : myShape) {
375 if (shapePosition.distanceTo2D(pos) < myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.polygonGeometryPointRadius) {
376 return myShape.indexOfClosest(shapePosition);
377 }
378 }
379 return -1;
380}
381
382
383void
384GNEPoly::deleteGeometryPoint(const Position& pos, bool allowUndo) {
385 if (myShape.size() > 1) {
386 // obtain index
387 PositionVector modifiedShape = myShape;
388 int index = modifiedShape.indexOfClosest(pos);
389 // remove point dependending of
390 if (myShape.isClosed() && (index == 0 || index == (int)modifiedShape.size() - 1) && (myShape.size() > 2)) {
391 modifiedShape.erase(modifiedShape.begin());
392 modifiedShape.erase(modifiedShape.end() - 1);
393 modifiedShape.push_back(modifiedShape.front());
394 } else {
395 modifiedShape.erase(modifiedShape.begin() + index);
396 }
397 // set new shape depending of allowUndo
398 if (allowUndo) {
399 myNet->getUndoList()->begin(this, "delete geometry point");
401 myNet->getUndoList()->end();
402 } else {
403 // first remove object from grid due shape is used for boundary
405 // set new shape
406 myShape = modifiedShape;
407 // disable simplified shape flag
408 mySimplifiedShape = false;
409 // add object into grid again
411 }
412 myTesselation.clear();
413 } else {
414 WRITE_WARNING(TL("Number of remaining points insufficient"))
415 }
416}
417
418
419bool
421 return myShape.isClosed();
422}
423
424
425void
426GNEPoly::openPolygon(bool allowUndo) {
427 // only open if shape is closed
428 if (myShape.isClosed()) {
429 if (allowUndo) {
430 myNet->getUndoList()->begin(this, "open polygon");
432 myNet->getUndoList()->end();
433 } else {
434 myShape.pop_back();
435 // disable simplified shape flag
436 mySimplifiedShape = false;
437 // update geometry to avoid grabbing Problems
439 }
440 } else {
441 WRITE_WARNING(TL("Polygon already opened"))
442 }
443}
444
445
446void
447GNEPoly::closePolygon(bool allowUndo) {
448 // only close if shape is opened
449 if (!myShape.isClosed()) {
450 if (allowUndo) {
451 myNet->getUndoList()->begin(this, "close shape");
453 myNet->getUndoList()->end();
454 } else {
456 // disable simplified shape flag
457 mySimplifiedShape = false;
458 // update geometry to avoid grabbing Problems
460 }
461 } else {
462 WRITE_WARNING(TL("Polygon already closed"))
463 }
464}
465
466
467void
468GNEPoly::changeFirstGeometryPoint(int oldIndex, bool allowUndo) {
469 // check that old index is correct
470 if (oldIndex >= (int)myShape.size()) {
471 throw InvalidArgument("Invalid old Index");
472 } else if (oldIndex == 0) {
473 WRITE_WARNING(TL("Selected point must be different of the first point"))
474 } else {
475 // Configure new shape
476 PositionVector newShape;
477 for (int i = oldIndex; i < (int)myShape.size(); i++) {
478 newShape.push_back(myShape[i]);
479 }
480 if (myShape.isClosed()) {
481 for (int i = 1; i < oldIndex; i++) {
482 newShape.push_back(myShape[i]);
483 }
484 newShape.push_back(newShape.front());
485 } else {
486 for (int i = 0; i < oldIndex; i++) {
487 newShape.push_back(myShape[i]);
488 }
489 }
490 // set new rotated shape
491 if (allowUndo) {
492 myNet->getUndoList()->begin(this, "change first geometry point");
494 myNet->getUndoList()->end();
495 } else {
496 // set new shape
497 myShape = newShape;
498 // disable simplified shape flag
499 mySimplifiedShape = false;
500 // update geometry to avoid grabbing Problems
502 }
503 }
504}
505
506
507void
508GNEPoly::simplifyShape(bool allowUndo) {
509 if (!mySimplifiedShape && myShape.size() > 2) {
510 const Boundary b = myShape.getBoxBoundary();
511 // create a square as simplified shape
512 PositionVector simplifiedShape;
513 simplifiedShape.push_back(Position(b.xmin(), b.ymin()));
514 simplifiedShape.push_back(Position(b.xmin(), b.ymax()));
515 simplifiedShape.push_back(Position(b.xmax(), b.ymax()));
516 simplifiedShape.push_back(Position(b.xmax(), b.ymin()));
517 if (myShape.isClosed()) {
518 simplifiedShape.push_back(simplifiedShape[0]);
519 }
520 // set new shape depending of allowUndo
521 if (allowUndo) {
522 myNet->getUndoList()->begin(this, "simplify shape");
524 myNet->getUndoList()->end();
525 } else {
526 // set new shape
527 myShape = simplifiedShape;
528 // update geometry to avoid grabbing Problems
530 }
531 // change flag after setting simplified shape
532 mySimplifiedShape = true;
533 } else {
534 WRITE_WARNING(TL("Polygon already simplified"))
535 }
536}
537
538
542 polygonBaseObject->setTag(myTagProperty->getTag());
543 // fill attributes
544 polygonBaseObject->addStringAttribute(SUMO_ATTR_ID, myID);
546 polygonBaseObject->addBoolAttribute(SUMO_ATTR_GEO, myGEO);
547 polygonBaseObject->addBoolAttribute(SUMO_ATTR_FILL, myFill);
549 polygonBaseObject->addColorAttribute(SUMO_ATTR_COLOR, getShapeColor());
550 polygonBaseObject->addStringAttribute(SUMO_ATTR_TYPE, getShapeType());
551 polygonBaseObject->addDoubleAttribute(SUMO_ATTR_LAYER, getShapeLayer());
555 polygonBaseObject->addDoubleAttribute(SUMO_ATTR_HEIGHT, myHeight);
556 return polygonBaseObject;
557}
558
559
560std::string
562 switch (key) {
563 case SUMO_ATTR_ID:
564 return myID;
565 case SUMO_ATTR_SHAPE:
566 if ((GeoConvHelper::getFinal().getProjString() != "!") && myGEO) {
567 return TL("Using GEO Shape");
568 } else {
569 return toString(myShape);
570 }
572 if (GeoConvHelper::getFinal().getProjString() != "!") {
574 } else {
575 return TL("No geo-conversion defined");
576 }
577 case SUMO_ATTR_COLOR:
578 return toString(getShapeColor());
579 case SUMO_ATTR_FILL:
580 return toString(myFill);
582 return toString(myLineWidth);
583 case SUMO_ATTR_LAYER:
584 return toString(getShapeLayer());
585 case SUMO_ATTR_TYPE:
586 return getShapeType();
588 return getShapeImgFile();
589 case SUMO_ATTR_ANGLE:
591 case SUMO_ATTR_GEO:
592 return toString(myGEO);
593 case SUMO_ATTR_NAME:
594 return myAdditionalName;
596 return toString(myClosedShape);
597 case SUMO_ATTR_HEIGHT:
598 return toString(myHeight);
599 default:
600 return getCommonAttribute(key);
601 }
602}
603
604
605double
609
610
615
616
621
622
623void
624GNEPoly::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
625 if (value == getAttribute(key)) {
626 return; //avoid needless changes, later logic relies on the fact that attributes have changed
627 }
628 switch (key) {
629 case SUMO_ATTR_ID:
630 case SUMO_ATTR_SHAPE:
632 case SUMO_ATTR_COLOR:
633 case SUMO_ATTR_FILL:
635 case SUMO_ATTR_LAYER:
636 case SUMO_ATTR_TYPE:
638 case SUMO_ATTR_ANGLE:
639 case SUMO_ATTR_GEO:
640 case SUMO_ATTR_NAME:
641 case SUMO_ATTR_HEIGHT:
643 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
644 break;
645 default:
646 setCommonAttribute(key, value, undoList);
647 break;
648 }
649}
650
651
652bool
653GNEPoly::isValid(SumoXMLAttr key, const std::string& value) {
654 switch (key) {
655 case SUMO_ATTR_ID:
657 case SUMO_ATTR_SHAPE:
659 // empty shapes AREN'T allowed
660 if (value.empty()) {
661 return false;
662 } else {
663 return canParse<PositionVector>(value);
664 }
665 case SUMO_ATTR_COLOR:
666 return canParse<RGBColor>(value);
667 case SUMO_ATTR_FILL:
668 return canParse<bool>(value);
670 return canParse<double>(value) && (parse<double>(value) >= 0);
671 case SUMO_ATTR_LAYER:
672 if (value.empty()) {
673 return true;
674 } else {
675 return canParse<double>(value);
676 }
677 case SUMO_ATTR_TYPE:
678 return true;
680 if (value == "") {
681 return true;
682 } else {
683 // check that image can be loaded
684 return GUITexturesHelper::getTextureID(value) != -1;
685 }
686 case SUMO_ATTR_ANGLE:
687 return canParse<double>(value);
688 case SUMO_ATTR_GEO:
689 return canParse<bool>(value);
690 case SUMO_ATTR_NAME:
691 return StringUtils::isValidAttribute(value);
692 case SUMO_ATTR_HEIGHT:
693 return canParse<double>(value) && (parse<double>(value) >= 0);
695 return canParse<bool>(value);
696 default:
697 return isCommonAttributeValid(key, value);
698 }
699}
700
701
702bool
704 switch (key) {
705 case SUMO_ATTR_SHAPE:
706 if (GeoConvHelper::getFinal().getProjString() != "!") {
707 return myGEO == false;
708 } else {
709 return true;
710 }
711 case SUMO_ATTR_GEO:
712 return GeoConvHelper::getFinal().getProjString() != "!";
714 if (GeoConvHelper::getFinal().getProjString() != "!") {
715 return myGEO == true;
716 } else {
717 return false;
718 }
720 if (isTemplate()) {
721 return true;
722 } else {
723 return myShape.size() > 1;
724 }
725 default:
726 return true;
727 }
728}
729
730
731std::string
733 return getTagStr() + ": " + getID();
734}
735
736
737std::string
739 return getTagStr();
740}
741
742// ===========================================================================
743// private
744// ===========================================================================
745
746void
747GNEPoly::setAttribute(SumoXMLAttr key, const std::string& value) {
748 switch (key) {
749 case SUMO_ATTR_ID: {
750 // update microsimID
751 setAdditionalID(value);
752 // set named ID
753 myID = value;
754 break;
755 }
756 case SUMO_ATTR_SHAPE: {
757 // set new shape
758 myShape = parse<PositionVector>(value);
759 // set GEO shape
761 for (int i = 0; i < (int) myGeoShape.size(); i++) {
763 }
764 // disable simplified shape flag
765 mySimplifiedShape = false;
766 // update geometry
768 // update centering boundary
770 break;
771 }
772 case SUMO_ATTR_GEOSHAPE: {
773 // set new GEO shape
774 myGeoShape = parse<PositionVector>(value);
775 // set shape
777 for (int i = 0; i < (int) myShape.size(); i++) {
779 }
780 // disable simplified shape flag
781 mySimplifiedShape = false;
782 // update geometry
784 // update centering boundary
786 break;
787 }
788 case SUMO_ATTR_COLOR:
789 setShapeColor(parse<RGBColor>(value));
790 break;
791 case SUMO_ATTR_FILL:
792 myFill = parse<bool>(value);
794 break;
796 myLineWidth = parse<double>(value);
797 break;
798 case SUMO_ATTR_LAYER:
799 if (value.empty()) {
801 } else {
802 setShapeLayer(parse<double>(value));
803 }
804 break;
805 case SUMO_ATTR_TYPE:
806 setShapeType(value);
807 break;
809 setShapeImgFile(value);
810 // all textures must be refresh
812 break;
813 case SUMO_ATTR_ANGLE:
814 setShapeNaviDegree(parse<double>(value));
815 break;
816 case SUMO_ATTR_GEO:
817 myGEO = parse<bool>(value);
818 // update centering boundary
820 break;
821 case SUMO_ATTR_NAME:
822 myAdditionalName = value;
823 break;
824 case SUMO_ATTR_HEIGHT:
825 myHeight = parse<double>(value);
826 break;
828 myClosedShape = parse<bool>(value);
829 if (!isTemplate()) {
830 if (myClosedShape) {
833
834 } else {
837 }
838 // disable simplified shape flag
839 mySimplifiedShape = false;
840 // update geometry
842 // update centering boundary
844 }
845 break;
846 default:
847 setCommonAttribute(key, value);
848 break;
849 }
850}
851
852
853void
855 const RGBColor& color, const double exaggeration) const {
856 // check if we're drawing a polygon or a polyline
857 if (getFill()) {
858 // draw inner polygon
860 } else {
861 // push matrix
863 // set color
864 GLHelper::setColor(color);
865 // draw geometry (polyline)
867 // pop matrix
869 }
870}
871
872
873void
875 const RGBColor& color, const double exaggeration) const {
876 // push contour matrix
878 // translate to front
879 glTranslated(0, 0, 0.1);
880 // set color
881 GLHelper::setColor(color);
882 // draw polygon contour
884 // pop contour matrix
886}
887
888
889void
891 const RGBColor& color, const double exaggeration) const {
892 // draw shape points only in supermode network
894 // check if we're in move mode
896 // get geometry point sizes
897 const double geometryPointSize = s.neteditSizeSettings.polygonGeometryPointRadius * (moveMode ? 1 : 0.5);
898 // draw geometry points
899 GUIGeometry::drawGeometryPoints(d, myAdditionalGeometry.getShape(), color, geometryPointSize, exaggeration,
902 // draw dotted contours for geometry points if we're in move mode
903 if (moveMode) {
906 }
907 }
908}
909
910
911void
913 // get name position
915 // draw name
916 drawName(namePos, s.scale, s.polyName, s.angle);
917 // check if draw poly type
918 if (s.polyType.show(this)) {
919 const Position p = namePos + Position(0, -0.6 * s.polyType.size / s.scale);
921 }
922}
923
924/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ MID_GNE_POLYGON_TRIANGULATE
triangulate polygon
@ 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:44
#define WRITE_WARNING(msg)
Definition MsgHandler.h:298
#define TL(string)
Definition MsgHandler.h:316
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
@ 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_HEIGHT
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_IMGFILE
int gPrecisionGeo
Definition StdDefs.cpp:29
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
Position getCenter() const
Returns the center of the boundary.
Definition Boundary.cpp:109
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:127
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:115
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:340
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:133
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:121
void setTag(const SumoXMLTag tag)
set SumoBaseObject tag
void addPositionVectorAttribute(const SumoXMLAttr attr, const PositionVector &value)
add PositionVector attribute into current SumoBaseObject node
void addBoolAttribute(const SumoXMLAttr attr, const bool value)
add bool attribute into current SumoBaseObject node
void addDoubleAttribute(const SumoXMLAttr attr, const double value)
add double attribute into current SumoBaseObject node
void addStringAttribute(const SumoXMLAttr attr, const std::string &value)
add string attribute into current SumoBaseObject node
void addColorAttribute(const SumoXMLAttr attr, const RGBColor &value)
add color attribute into current SumoBaseObject node
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:952
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:773
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(...)
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
std::string myAdditionalName
name of additional
void calculateContourPolygons(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double layer, const double exaggeration, const bool filledShape) const
calculate contour for polygons
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
Boundary myAdditionalBoundary
Additional Boundary (used only by additionals placed over grid)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
const std::string getID() const override
get ID (all Attribute Carriers have one)
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
bool isTemplate() const
check if this AC is template
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
GNENet * myNet
pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
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...)
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
Position getMovingAttributePosition(SumoXMLAttr key) const override
get moving attribute position
bool getMoveWholePolygons() const
check if option "move whole polygons" is enabled
NetworkMoveOptions * getNetworkMoveOptions() const
get network mode options
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1476
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1486
GNEViewParent * getViewParent() const
get view parent (used for simplify code)
Definition GNENet.cpp:150
GNEUndoList * getUndoList() const
get undo list(used for simplify code)
Definition GNENet.cpp:156
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
Parameterised * getParameters() override
get parameters associated with this poly
Definition GNEPoly.cpp:126
bool mySimplifiedShape
flag to indicate if polygon is simplified
Definition GNEPoly.h:262
std::string getAdditionalProblem() const override
return a string with the current additional problem (must be reimplemented in all detector children)
Definition GNEPoly.cpp:234
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
Definition GNEPoly.cpp:732
std::string getParentName() const override
Returns the name of the parent object.
Definition GNEPoly.cpp:268
double getAttributeDouble(SumoXMLAttr key) const override
Definition GNEPoly.cpp:606
~GNEPoly()
Destructor.
Definition GNEPoly.cpp:114
bool isValid(SumoXMLAttr key, const std::string &value) override
method for checking if the key and their conrrespond attribute are valids
Definition GNEPoly.cpp:653
void updateGeometry() override
update pre-computed geometry information
Definition GNEPoly.cpp:144
GNEMoveElementShape * myMoveElementShape
move element shape
Definition GNEPoly.h:253
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
Definition GNEPoly.cpp:738
void fixAdditionalProblem() override
fix additional problem (must be reimplemented in all detector children)
Definition GNEPoly.cpp:240
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
Definition GNEPoly.cpp:187
void drawPolygonNameAndType(const GUIVisualizationSettings &s) const
draw polygon name and type
Definition GNEPoly.cpp:912
GNEPoly(SumoXMLTag tag, GNENet *net)
default Constructor
Definition GNEPoly.cpp:48
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this poly
Definition GNEPoly.cpp:120
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:368
PositionVector myGeoShape
Latitude of Polygon.
Definition GNEPoly.h:256
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
Definition GNEPoly.cpp:158
void closePolygon(bool allowUndo=true)
close polygon
Definition GNEPoly.cpp:447
void changeFirstGeometryPoint(int oldIndex, bool allowUndo=true)
change first geometry point
Definition GNEPoly.cpp:468
std::string getAttribute(SumoXMLAttr key) const override
Definition GNEPoly.cpp:561
bool checkDrawMoveContour() const override
check if draw move contour (red)
Definition GNEPoly.cpp:252
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:228
Position getAttributePosition(SumoXMLAttr key) const override
Definition GNEPoly.cpp:612
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:624
void deleteGeometryPoint(const Position &pos, bool allowUndo=true)
delete the geometry point closest to the given pos
Definition GNEPoly.cpp:384
Position getPositionInView() const override
Returns position of shape in view.
Definition GNEPoly.cpp:152
void drawGeometryPoints(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw geometry points
Definition GNEPoly.cpp:890
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
Definition GNEPoly.cpp:321
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
Definition GNEPoly.cpp:618
void drawPolygon(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw polygon
Definition GNEPoly.cpp:854
bool isAttributeEnabled(SumoXMLAttr key) const override
Definition GNEPoly.cpp:703
void drawPolygonContour(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw contour
Definition GNEPoly.cpp:874
CommonXMLStructure::SumoBaseObject * getSumoBaseObject() const
get SUMOBaseObject with all polygon attributes
Definition GNEPoly.cpp:540
bool isPolygonClosed() const
check if polygon is closed
Definition GNEPoly.cpp:420
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own popup-menu.
Definition GNEPoly.cpp:274
void simplifyShape(bool allowUndo=true)
replace the current shape with a rectangle
Definition GNEPoly.cpp:508
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
Definition GNEPoly.cpp:181
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
Definition GNEPoly.cpp:164
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition GNEPoly.cpp:246
std::string generateChildID(SumoXMLTag childTag)
gererate a new ID for an element child
Definition GNEPoly.cpp:138
void openPolygon(bool allowUndo=true)
open polygon
Definition GNEPoly.cpp:426
bool myClosedShape
flag to indicate if polygon is closed
Definition GNEPoly.h:259
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
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
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
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 drawSymbols, 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.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GUIGlID getGlID() const
Returns the numerical id of the object.
void buildPopUpMenuCommonOptions(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, GUISUMOAbstractView *parent, const SumoXMLTag tag, const bool selected, const bool allowDelete, const bool addSeparator)
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
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:124
static const std::vector< SumoXMLTag > polygons
polygon namespace
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
An upper class for objects with additional parameters.
std::map< std::string, std::string > Map
parameters map
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
void openPolygon()
open polygon
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:228
const PositionVector & getShape() const
Returns the shape of the polygon.
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)
double myHeight
The line width for drawing an unfilled polygon.
double getLineWidth() const
Returns the line width.
double getHeight() const
Returns the polygon height.
bool myFill
Information whether the polygon has to be filled.
bool getFill() const
Returns whether the polygon is filled.
static const double DEFAULT_HEIGHT
Definition Shape.h:56
void setShapeLayer(const double layer)
Sets a new layer.
Definition Shape.cpp:153
static const std::string DEFAULT_IMG_FILE
Definition Shape.h:53
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition Shape.cpp:99
static const double DEFAULT_LINEWIDTH
Definition Shape.h:50
void setShapeType(const std::string &type)
Sets a new type.
Definition Shape.cpp:135
static const double DEFAULT_ANGLE
Definition Shape.h:52
virtual void setShapeNaviDegree(const double angle)
Sets a new angle in navigational degrees.
Definition Shape.cpp:159
void setShapeImgFile(const std::string &imgFile)
Sets a new imgFile.
Definition Shape.cpp:165
void setShapeColor(const RGBColor &col)
Sets a new color.
Definition Shape.cpp:141
double getShapeLayer() const
Returns the layer of the Shape.
Definition Shape.cpp:111
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition Shape.cpp:123
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition Shape.cpp:105
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition Shape.cpp:117
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
std::vector< GLPrimitive > myTesselation
id of the display list for the cached tesselation
Definition GUIPolygon.h:79
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags
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
bool showPolygonSymbols() const
check if draw polygon symbols
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