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 <string>
23 #include <utils/gui/div/GLHelper.h>
25 #include <netedit/GNENet.h>
26 #include <netedit/GNEUndoList.h>
27 #include <netedit/GNEViewNet.h>
28 #include <netedit/GNEViewParent.h>
34 
35 #include "GNEPoly.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 
43  SUMOPolygon("", "", RGBColor::BLACK, {}, false, false, 0, 0, 0, "", false, "", std::map<std::string, std::string>()),
44  GNEShape("", net, GLO_POLYGON, SUMO_TAG_POLY, {}, {}, {}, {}, {}, {}, {}, {}),
45 mySimplifiedShape(false) {
46  // reset default values
48 }
49 
50 
51 GNEPoly::GNEPoly(GNENet* net, const std::string& id, const std::string& type, const PositionVector& shape, bool geo, bool fill, double lineWidth,
52  const RGBColor& color, double layer, double angle, const std::string& imgFile, bool relativePath, const std::string& name,
53  const std::map<std::string, std::string>& parameters) :
54  SUMOPolygon(id, type, color, shape, geo, fill, lineWidth, layer, angle, imgFile, relativePath, name, parameters),
55  GNEShape(id, net, GLO_POLYGON, SUMO_TAG_POLY, {}, {}, {}, {}, {}, {}, {}, {}),
56 mySimplifiedShape(false) {
57  // update centering boundary without updating grid
59  // check if imgFile is valid
60  if (!imgFile.empty() && GUITexturesHelper::getTextureID(imgFile) == -1) {
61  setShapeImgFile("");
62  }
63  // set GEO shape
65  for (int i = 0; i < (int) myGeoShape.size(); i++) {
67  }
68  // update geometry
70 }
71 
72 
74 
75 
78  // edit depending if shape is blocked
80  // move entire shape
81  return new GNEMoveOperation(this, myShape);
82  } else {
83  // calculate move shape operation
86  }
87 }
88 
89 
90 void
91 GNEPoly::removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) {
92  // get original shape
93  PositionVector shape = myShape;
94  // check shape size
95  if (shape.size() > 2) {
96  // obtain index
97  int index = shape.indexOfClosest(clickedPosition);
98  // get snap radius
100  // check if we have to create a new index
101  if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {
102  // remove geometry point
103  shape.erase(shape.begin() + index);
104  // commit new shape
105  undoList->begin(GUIIcon::POLY, "remove geometry point of " + getTagStr());
106  undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_SHAPE, toString(shape)));
107  undoList->end();
108  }
109  }
110 }
111 
112 
113 std::string
115  return "";
116 }
117 
118 
119 void
120 GNEPoly::setParameter(const std::string& key, const std::string& value) {
121  Parameterised::setParameter(key, value);
122 }
123 
124 
125 void
127  // just update geometry
129 }
130 
131 
132 Position
134  return myBoundary.getCenter();
135 }
136 
137 
138 double
140  return s.polySize.getExaggeration(s, this);
141 }
142 
143 
144 void
145 GNEPoly::updateCenteringBoundary(const bool updateGrid) {
146  // Remove object from net
147  if (updateGrid) {
149  }
150  // use shape as boundary
152  // grow boundary
153  myBoundary.grow(10);
154  // add object into net
155  if (updateGrid) {
156  myNet->addGLObjectIntoGrid(this);
157  }
158 }
159 
160 
161 void
163  writeXML(device, myGEO);
164 }
165 
166 
167 GUIGlID
169  return GUIGlObject::getGlID();
170 }
171 
172 
173 std::string
175  return myNet->getMicrosimID();
176 }
177 
178 
181  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
182  buildPopupHeader(ret, app);
185  // build selection and show parameters menu
188  FXMenuCommand* simplifyShape = GUIDesigns::buildFXMenuCommand(ret, "Simplify Shape\t\tReplace current shape with a rectangle", nullptr, &parent, MID_GNE_POLYGON_SIMPLIFY_SHAPE);
189  // disable simplify shape if polygon was already simplified
190  if (mySimplifiedShape || myShape.size() <= 2) {
191  simplifyShape->disable();
192  }
193  if (myShape.isClosed()) {
194  GUIDesigns::buildFXMenuCommand(ret, "Open shape\t\tOpen polygon's shape", nullptr, &parent, MID_GNE_POLYGON_OPEN);
195  } else {
196  GUIDesigns::buildFXMenuCommand(ret, "Close shape\t\tClose polygon's shape", nullptr, &parent, MID_GNE_POLYGON_CLOSE);
197  }
198  GUIDesigns::buildFXMenuCommand(ret, "Select elements within polygon\t\tSelect elements within polygon boundary", nullptr, &parent, MID_GNE_POLYGON_SELECT);
199  // add separator
200  new FXMenuSeparator(ret);
201  // create a extra FXMenuCommand if mouse is over a vertex
202  const int index = getVertexIndex(myNet->getViewNet()->getPositionInformation(), false);
203  if (index != -1) {
204  // check if we're in network mode
206  GUIDesigns::buildFXMenuCommand(ret, "Set custom Geometry Point", nullptr, &parent, MID_GNE_CUSTOM_GEOMETRYPOINT);
207  }
208  FXMenuCommand* removeGeometryPoint = GUIDesigns::buildFXMenuCommand(ret, "Remove geometry point\t\tRemove geometry point under mouse", nullptr, &parent, MID_GNE_POLYGON_DELETE_GEOMETRY_POINT);
209  FXMenuCommand* setFirstPoint = GUIDesigns::buildFXMenuCommand(ret, "Set first geometry point\t\tSet", nullptr, &parent, MID_GNE_POLYGON_SET_FIRST_POINT);
210  // disable setFirstPoint if shape only have three points
211  if ((myShape.isClosed() && (myShape.size() <= 4)) || (!myShape.isClosed() && (myShape.size() <= 2))) {
212  removeGeometryPoint->disable();
213  }
214  // disable setFirstPoint if mouse is over first point
215  if (index == 0) {
216  setFirstPoint->disable();
217  }
218  }
219  return ret;
220 }
221 
222 
225  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
226  // add items
227  ret->mkItem("type", false, getShapeType());
228  ret->mkItem("layer", false, toString(getShapeLayer()));
229  ret->closeBuilding(this);
230  return ret;
231 }
232 
233 
234 void
236  // check if boundary has to be drawn
237  if (s.drawBoundaries) {
239  }
240  // first check if poly can be drawn
243  GUIPolygon::checkDraw(s, this, this)) {
244  // check if draw start und end
245  const bool drawExtremeSymbols = myNet->getViewNet()->getEditModes().isCurrentSupermodeNetwork() &&
247  // Obtain constants
248  const double polyExaggeration = getExaggeration(s);
249  const Position mousePosition = myNet->getViewNet()->getPositionInformation();
250  // get colors
252  const RGBColor invertedColor = color.invertedColor();
253  const RGBColor darkerColor = color.changedBrightness(-32);
254  // push name (needed for getGUIGlObjectsUnderCursor(...)
256  // push layer matrix
258  // translate to front
260  // check if we're drawing a polygon or a polyline
261  if (getFill()) {
262  if (s.drawForPositionSelection) {
263  // check if mouse is within geometry
264  if (myPolygonGeometry.getShape().around(mousePosition)) {
265  // push matrix
267  // move to mouse position
268  glTranslated(mousePosition.x(), mousePosition.y(), 0);
269  // set color
270  GLHelper::setColor(color);
271  // draw circle
273  // pop matrix
275  }
276  } else {
277  // draw inner polygon
279  }
280  } else {
281  // push matrix
283  // set color
284  GLHelper::setColor(color);
285  // draw geometry (polyline)
287  // pop matrix
289  }
290  // draw contour if shape isn't blocked
292  // push contour matrix
294  // translate to front
295  glTranslated(0, 0, 0.1);
296  // set color
297  GLHelper::setColor(darkerColor);
298  // draw polygon contour
300  // pop contour matrix
302  // draw shape points only in Network supemode
304  // check move mode flag
306  // draw geometry points
308  s.neteditSizeSettings.polygonGeometryPointRadius * (moveMode ? 1 : 0.5), polyExaggeration,
309  myNet->getViewNet()->getNetworkViewOptions().editingElevation(), drawExtremeSymbols);
310  // draw moving hint points
313  s.neteditSizeSettings.polygonGeometryPointRadius, polyExaggeration);
314  }
315  }
316  }
317  // check if dotted contour has to be drawn
319  // draw depending if is closed
322  } else {
324  polyExaggeration, 1, 1);
325  }
326  }
327  // check if front dotted contour has to be drawn
328  if ((myNet->getViewNet()->getFrontAttributeCarrier() == this)) {
329  // draw depending if is closed
332  } else {
334  polyExaggeration, 1, 1);
335  }
336  }
337  // draw lock icon
339  // pop layer matrix
341  // pop name
343  // get name position
345  // draw name
346  drawName(namePos, s.scale, s.polyName, s.angle);
347  // check if draw poly type
348  if (s.polyType.show(this)) {
349  const Position p = namePos + Position(0, -0.6 * s.polyType.size / s.scale);
351  }
352  }
353 }
354 
355 
356 int
357 GNEPoly::getVertexIndex(Position pos, bool snapToGrid) {
358  // check if position has to be snapped to grid
359  if (snapToGrid) {
360  pos = myNet->getViewNet()->snapToActiveGrid(pos);
361  }
362  // first check if vertex already exists
363  for (const auto& shapePosition : myShape) {
364  if (shapePosition.distanceTo2D(pos) < myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.polygonGeometryPointRadius) {
365  return myShape.indexOfClosest(shapePosition);
366  }
367  }
368  return -1;
369 }
370 
371 
372 void
373 GNEPoly::deleteGeometryPoint(const Position& pos, bool allowUndo) {
374  if (myShape.size() > 1) {
375  // obtain index
376  PositionVector modifiedShape = myShape;
377  int index = modifiedShape.indexOfClosest(pos);
378  // remove point dependending of
379  if (myShape.isClosed() && (index == 0 || index == (int)modifiedShape.size() - 1) && (myShape.size() > 2)) {
380  modifiedShape.erase(modifiedShape.begin());
381  modifiedShape.erase(modifiedShape.end() - 1);
382  modifiedShape.push_back(modifiedShape.front());
383  } else {
384  modifiedShape.erase(modifiedShape.begin() + index);
385  }
386  // set new shape depending of allowUndo
387  if (allowUndo) {
388  myNet->getViewNet()->getUndoList()->begin(GUIIcon::POLY, "delete geometry point");
390  myNet->getViewNet()->getUndoList()->end();
391  } else {
392  // first remove object from grid due shape is used for boundary
394  // set new shape
395  myShape = modifiedShape;
396  // disable simplified shape flag
397  mySimplifiedShape = false;
398  // add object into grid again
399  myNet->addGLObjectIntoGrid(this);
400  }
401  } else {
402  WRITE_WARNING("Number of remaining points insufficient")
403  }
404 }
405 
406 
407 bool
409  return myShape.isClosed();
410 }
411 
412 
413 void
414 GNEPoly::openPolygon(bool allowUndo) {
415  // only open if shape is closed
416  if (myShape.isClosed()) {
417  if (allowUndo) {
418  myNet->getViewNet()->getUndoList()->begin(GUIIcon::POLY, "open polygon");
420  myNet->getViewNet()->getUndoList()->end();
421  } else {
422  myShape.pop_back();
423  // disable simplified shape flag
424  mySimplifiedShape = false;
425  // update geometry to avoid grabbing Problems
426  updateGeometry();
427  }
428  } else {
429  WRITE_WARNING("Polygon already opened")
430  }
431 }
432 
433 
434 void
435 GNEPoly::closePolygon(bool allowUndo) {
436  // only close if shape is opened
437  if (myShape.isClosed() == false) {
438  if (allowUndo) {
439  myNet->getViewNet()->getUndoList()->begin(GUIIcon::POLY, "close shape");
441  myNet->getViewNet()->getUndoList()->end();
442  } else {
444  // disable simplified shape flag
445  mySimplifiedShape = false;
446  // update geometry to avoid grabbing Problems
447  updateGeometry();
448  }
449  } else {
450  WRITE_WARNING("Polygon already closed")
451  }
452 }
453 
454 
455 void
456 GNEPoly::changeFirstGeometryPoint(int oldIndex, bool allowUndo) {
457  // check that old index is correct
458  if (oldIndex >= (int)myShape.size()) {
459  throw InvalidArgument("Invalid old Index");
460  } else if (oldIndex == 0) {
461  WRITE_WARNING("Selected point must be different of the first point")
462  } else {
463  // Configure new shape
464  PositionVector newShape;
465  for (int i = oldIndex; i < (int)myShape.size(); i++) {
466  newShape.push_back(myShape[i]);
467  }
468  if (myShape.isClosed()) {
469  for (int i = 1; i < oldIndex; i++) {
470  newShape.push_back(myShape[i]);
471  }
472  newShape.push_back(newShape.front());
473  } else {
474  for (int i = 0; i < oldIndex; i++) {
475  newShape.push_back(myShape[i]);
476  }
477  }
478  // set new rotated shape
479  if (allowUndo) {
480  myNet->getViewNet()->getUndoList()->begin(GUIIcon::POLY, "change first geometry point");
482  myNet->getViewNet()->getUndoList()->end();
483  } else {
484  // set new shape
485  myShape = newShape;
486  // disable simplified shape flag
487  mySimplifiedShape = false;
488  // update geometry to avoid grabbing Problems
489  updateGeometry();
490  }
491  }
492 }
493 
494 
495 void
496 GNEPoly::simplifyShape(bool allowUndo) {
497  if (!mySimplifiedShape && myShape.size() > 2) {
498  const Boundary b = myShape.getBoxBoundary();
499  PositionVector simplifiedShape;
500  if (myShape.isClosed()) {
501  // create a square as simplified shape
502  simplifiedShape.push_back(Position(b.xmin(), b.ymin()));
503  simplifiedShape.push_back(Position(b.xmin(), b.ymax()));
504  simplifiedShape.push_back(Position(b.xmax(), b.ymax()));
505  simplifiedShape.push_back(Position(b.xmax(), b.ymin()));
506  simplifiedShape.push_back(simplifiedShape[0]);
507  } else {
508  // create a line as simplified shape
509  simplifiedShape.push_back(myShape.front());
510  simplifiedShape.push_back(myShape.back());
511  }
512  // set new shape depending of allowUndo
513  if (allowUndo) {
514  myNet->getViewNet()->getUndoList()->begin(GUIIcon::POLY, "simplify shape");
516  myNet->getViewNet()->getUndoList()->end();
517  } else {
518  // set new shape
519  myShape = simplifiedShape;
520  // update geometry to avoid grabbing Problems
521  updateGeometry();
522  }
523  // change flag after setting simplified shape
524  mySimplifiedShape = true;
525  } else {
526  WRITE_WARNING("Polygon already simplified")
527  }
528 }
529 
530 
531 std::string
533  switch (key) {
534  case SUMO_ATTR_ID:
535  return myID;
536  case SUMO_ATTR_SHAPE:
537  return toString(myShape);
538  case SUMO_ATTR_GEOSHAPE:
540  case SUMO_ATTR_COLOR:
541  return toString(getShapeColor());
542  case SUMO_ATTR_FILL:
543  return toString(myFill);
544  case SUMO_ATTR_LINEWIDTH:
545  return toString(myLineWidth);
546  case SUMO_ATTR_LAYER:
548  return "default";
549  } else {
550  return toString(getShapeLayer());
551  }
552  case SUMO_ATTR_TYPE:
553  return getShapeType();
554  case SUMO_ATTR_IMGFILE:
555  return getShapeImgFile();
557  return toString(getShapeRelativePath());
558  case SUMO_ATTR_ANGLE:
559  return toString(getShapeNaviDegree());
560  case SUMO_ATTR_GEO:
561  return toString(myGEO);
562  case SUMO_ATTR_NAME:
563  return getShapeName();
565  return toString(myShape.isClosed());
566  case GNE_ATTR_SELECTED:
568  case GNE_ATTR_PARAMETERS:
569  return getParametersStr();
570  default:
571  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
572  }
573 }
574 
575 
576 void
577 GNEPoly::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
578  if (value == getAttribute(key)) {
579  return; //avoid needless changes, later logic relies on the fact that attributes have changed
580  }
581  switch (key) {
582  case SUMO_ATTR_ID:
583  case SUMO_ATTR_SHAPE:
584  case SUMO_ATTR_GEOSHAPE:
585  case SUMO_ATTR_COLOR:
586  case SUMO_ATTR_FILL:
587  case SUMO_ATTR_LINEWIDTH:
588  case SUMO_ATTR_LAYER:
589  case SUMO_ATTR_TYPE:
590  case SUMO_ATTR_IMGFILE:
592  case SUMO_ATTR_ANGLE:
593  case SUMO_ATTR_GEO:
594  case SUMO_ATTR_NAME:
596  case GNE_ATTR_SELECTED:
597  case GNE_ATTR_PARAMETERS:
598  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
599  break;
600  default:
601  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
602  }
603 }
604 
605 
606 bool
607 GNEPoly::isValid(SumoXMLAttr key, const std::string& value) {
608  switch (key) {
609  case SUMO_ATTR_ID:
611  (myNet->getAttributeCarriers()->retrieveTAZElement(SUMO_TAG_TAZ, value, false) == nullptr) &&
612  (myNet->getAttributeCarriers()->retrieveShape(SUMO_TAG_POLY, value, false) == nullptr);
613  case SUMO_ATTR_SHAPE:
614  case SUMO_ATTR_GEOSHAPE:
615  // empty shapes AREN'T allowed
616  if (value.empty()) {
617  return false;
618  } else {
619  return canParse<PositionVector>(value);
620  }
621  case SUMO_ATTR_COLOR:
622  return canParse<RGBColor>(value);
623  case SUMO_ATTR_FILL:
624  return canParse<bool>(value);
625  case SUMO_ATTR_LINEWIDTH:
626  return canParse<double>(value) && (parse<double>(value) >= 0);
627  case SUMO_ATTR_LAYER:
628  if (value == "default") {
629  return true;
630  } else {
631  return canParse<double>(value);
632  }
633  case SUMO_ATTR_TYPE:
634  return true;
635  case SUMO_ATTR_IMGFILE:
636  if (value == "") {
637  return true;
638  } else {
639  // check that image can be loaded
640  return GUITexturesHelper::getTextureID(value) != -1;
641  }
643  return canParse<bool>(value);
644  case SUMO_ATTR_ANGLE:
645  return canParse<double>(value);
646  case SUMO_ATTR_GEO:
647  return canParse<bool>(value);
648  case SUMO_ATTR_NAME:
651  if (canParse<bool>(value)) {
652  bool closePolygon = parse<bool>(value);
653  if (closePolygon && (myShape.begin() == myShape.end())) {
654  // Polygon already closed, then invalid value
655  return false;
656  } else if (!closePolygon && (myShape.begin() != myShape.end())) {
657  // Polygon already open, then invalid value
658  return false;
659  } else {
660  return true;
661  }
662  } else {
663  return false;
664  }
665  case GNE_ATTR_SELECTED:
666  return canParse<bool>(value);
667  case GNE_ATTR_PARAMETERS:
668  return Parameterised::areParametersValid(value);
669  default:
670  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
671  }
672 }
673 
674 bool
676  // check if we're in supermode Network
678  return true;
679  } else {
680  return false;
681  }
682 }
683 
684 
685 const std::map<std::string, std::string>&
687  return getParametersMap();
688 }
689 
690 // ===========================================================================
691 // private
692 // ===========================================================================
693 
694 void
695 GNEPoly::setAttribute(SumoXMLAttr key, const std::string& value) {
696  switch (key) {
697  case SUMO_ATTR_ID: {
698  // update microsimID
699  setMicrosimID(value);
700  // set named ID
701  myID = value;
702  break;
703  }
704  case SUMO_ATTR_SHAPE: {
705  // set new shape
706  myShape = parse<PositionVector>(value);
707  // set GEO shape
709  for (int i = 0; i < (int) myGeoShape.size(); i++) {
711  }
712  // disable simplified shape flag
713  mySimplifiedShape = false;
714  // update geometry
715  updateGeometry();
716  // update centering boundary
718  break;
719  }
720  case SUMO_ATTR_GEOSHAPE: {
721  // set new GEO shape
722  myGeoShape = parse<PositionVector>(value);
723  // set shape
724  myShape = myGeoShape ;
725  for (int i = 0; i < (int) myShape.size(); i++) {
727  }
728  // disable simplified shape flag
729  mySimplifiedShape = false;
730  // update geometry
731  updateGeometry();
732  // update centering boundary
734  break;
735  }
736  case SUMO_ATTR_COLOR:
737  setShapeColor(parse<RGBColor>(value));
738  break;
739  case SUMO_ATTR_FILL:
740  myFill = parse<bool>(value);
741  break;
742  case SUMO_ATTR_LINEWIDTH:
743  myLineWidth = parse<double>(value);
744  break;
745  case SUMO_ATTR_LAYER:
746  if (value == "default") {
748  } else {
749  setShapeLayer(parse<double>(value));
750  }
751  break;
752  case SUMO_ATTR_TYPE:
753  setShapeType(value);
754  break;
755  case SUMO_ATTR_IMGFILE:
756  setShapeImgFile(value);
757  // all textures must be refresh
759  break;
761  setShapeRelativePath(parse<bool>(value));
762  break;
763  case SUMO_ATTR_ANGLE:
764  setShapeNaviDegree(parse<double>(value));
765  break;
766  case SUMO_ATTR_GEO:
767  myGEO = parse<bool>(value);
768  // update centering boundary
770  break;
771  case SUMO_ATTR_NAME:
772  setShapeName(value);
773  break;
775  if (parse<bool>(value)) {
778  } else {
779  myShape.pop_back();
780  myGeoShape.pop_back();
781  }
782  // disable simplified shape flag
783  mySimplifiedShape = false;
784  // update geometry
785  updateGeometry();
786  // update centering boundary
788  break;
789  case GNE_ATTR_SELECTED:
790  if (parse<bool>(value)) {
792  } else {
794  }
795  break;
796  case GNE_ATTR_PARAMETERS:
797  setParametersStr(value);
798  break;
799  default:
800  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
801  }
802 }
803 
804 
805 void
807  // update new shape
808  myShape = moveResult.shapeToUpdate;
809  // update geometry
811 }
812 
813 
814 void
815 GNEPoly::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
816  // commit new shape
817  undoList->begin(GUIIcon::POLY, "moving " + toString(SUMO_ATTR_SHAPE) + " of " + getTagStr());
818  undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_SHAPE, toString(moveResult.shapeToUpdate)));
819  undoList->end();
820 }
821 
822 /****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ MID_GNE_POLYGON_CLOSE
close opened polygon
Definition: GUIAppEnum.h:1114
@ MID_GNE_POLYGON_SET_FIRST_POINT
Set a vertex of polygon as first verte.
Definition: GUIAppEnum.h:1118
@ MID_GNE_POLYGON_SELECT
select elements within polygon boundary
Definition: GUIAppEnum.h:1122
@ MID_GNE_CUSTOM_GEOMETRYPOINT
set custom geometry point
Definition: GUIAppEnum.h:875
@ MID_GNE_POLYGON_DELETE_GEOMETRY_POINT
delete geometry point
Definition: GUIAppEnum.h:1120
@ MID_GNE_POLYGON_OPEN
open closed polygon
Definition: GUIAppEnum.h:1116
@ MID_GNE_POLYGON_SIMPLIFY_SHAPE
simplify polygon geometry
Definition: GUIAppEnum.h:1112
unsigned int GUIGlID
Definition: GUIGlObject.h:40
@ GLO_POLYGON
a polygon
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
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:111
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:129
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:117
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:135
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:123
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:801
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:431
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
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:640
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)
GNETAZElement * retrieveTAZElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named TAZElement.
GNEShape * retrieveShape(SumoXMLTag, const std::string &id, bool hardFail=true) const
Returns the named shape.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1210
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1222
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:125
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
void updateGeometry()
update pre-computed geometry information
Definition: GNEPoly.cpp:126
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEPoly.cpp:235
bool mySimplifiedShape
flag to indicate if polygon is simplified
Definition: GNEPoly.h:209
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEPoly.cpp:607
~GNEPoly()
Destructor.
Definition: GNEPoly.cpp:73
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEPoly.cpp:532
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
Definition: GNEPoly.cpp:806
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:357
PositionVector myGeoShape
Latitude of Polygon.
Definition: GNEPoly.h:206
GUIGeometry myPolygonGeometry
geometry for lenghts/rotations
Definition: GNEPoly.h:212
GNEPoly(GNENet *net)
default Constructor
Definition: GNEPoly.cpp:42
void closePolygon(bool allowUndo=true)
close polygon
Definition: GNEPoly.cpp:435
void changeFirstGeometryPoint(int oldIndex, bool allowUndo=true)
change first geometry point
Definition: GNEPoly.cpp:456
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position
Definition: GNEPoly.cpp:91
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Definition: GNEPoly.cpp:815
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNEPoly.cpp:180
GNEMoveOperation * getMoveOperation()
get move operation
Definition: GNEPoly.cpp:77
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
Definition: GNEPoly.cpp:120
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNEPoly.cpp:675
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration asociated with this GLObject
Definition: GNEPoly.cpp:139
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GNEPoly.cpp:224
void deleteGeometryPoint(const Position &pos, bool allowUndo=true)
delete the geometry point closest to the given pos
Definition: GNEPoly.cpp:373
std::string getParentName() const
Returns the name of the parent object.
Definition: GNEPoly.cpp:174
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNEPoly.cpp:577
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
Definition: GNEPoly.cpp:145
void writeShape(OutputDevice &device)
writte shape element into a xml file
Definition: GNEPoly.cpp:162
bool isPolygonClosed() const
check if polygon is closed
Definition: GNEPoly.cpp:408
void simplifyShape(bool allowUndo=true)
replace the current shape with a rectangle
Definition: GNEPoly.cpp:496
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
Definition: GNEPoly.cpp:686
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GNEPoly.cpp:168
std::string generateChildID(SumoXMLTag childTag)
gererate a new ID for an element child
Definition: GNEPoly.cpp:114
Position getPositionInView() const
Returns position of shape in view.
Definition: GNEPoly.cpp:133
void openPolygon(bool allowUndo=true)
open polygon
Definition: GNEPoly.cpp:414
Boundary myBoundary
object boundary
Definition: GNEShape.h:207
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:537
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:513
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:525
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:432
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:531
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 drawDottedContourShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem, const double lineWidth=-1)
draw dotted contour for the given shape (used by additionals)
static void drawDottedContourClosedShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double exaggeration, const double lineWidth=-1)
draw dotted contour for the given closed shape (used by Juctions, shapes and TAZs)
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
virtual 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.
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 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.
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
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
static bool checkDraw(const GUIVisualizationSettings &s, const SUMOPolygon *polygon, const GUIGlObject *o)
check if Polygon can be drawn
Definition: GUIPolygon.cpp:280
static void drawInnerPolygon(const GUIVisualizationSettings &s, const SUMOPolygon *polygon, const GUIGlObject *o, const PositionVector shape, const bool drawFill, double layer, bool disableSelectionColor, int alphaOverride=-1)
draw inner Polygon (before pushName() )
Definition: GUIPolygon.cpp:302
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.
GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings
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.
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
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|....
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"
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
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".
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
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:180
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:197
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)
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:109
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition: Shape.h:83
static const double DEFAULT_LAYER
Definition: Shape.h:42
void setShapeName(const std::string &name)
Sets a new shape name.
Definition: Shape.h:168
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition: Shape.h:104
void setShapeLayer(const double layer)
Sets a new layer.
Definition: Shape.h:149
bool getShapeRelativePath() const
Returns the relativePath of the Shape.
Definition: Shape.h:116
void setShapeType(const std::string &type)
Sets a new type.
Definition: Shape.h:128
void setShapeRelativePath(bool relativePath)
Sets a new relativePath value.
Definition: Shape.h:175
virtual void setShapeNaviDegree(const double angle)
Sets a new angle in navigational degrees.
Definition: Shape.h:156
void setShapeImgFile(const std::string &imgFile)
Sets a new imgFile.
Definition: Shape.h:163
void setShapeColor(const RGBColor &col)
Sets a new color.
Definition: Shape.h:135
double getShapeLayer() const
Returns the layer of the Shape.
Definition: Shape.h:90
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:97
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:76
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