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-2020 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>
32 
33 #include "GNEPoly.h"
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 GNEPoly::GNEPoly(GNENet* net, const std::string& id, const std::string& type, const PositionVector& shape, bool geo, bool fill, double lineWidth,
40  const RGBColor& color, double layer, double angle, const std::string& imgFile, bool relativePath, bool movementBlocked, bool shapeBlocked) :
41  SUMOPolygon(id, type, color, shape, geo, fill, lineWidth, layer, angle, imgFile, relativePath),
42  GNEShape(id, net, GLO_POLYGON, SUMO_TAG_POLY, movementBlocked, {}, {}, {}, {}, {}, {}, {}, {}),
43  myBlockShape(shapeBlocked),
44 mySimplifiedShape(false) {
45  // update centering boundary without updating grid
46  updateCenteringBoundary(false);
47  // check if imgFile is valid
48  if (!imgFile.empty() && GUITexturesHelper::getTextureID(imgFile) == -1) {
49  setShapeImgFile("");
50  }
51  // set GEO shape
52  myGeoShape = myShape;
53  for (int i = 0; i < (int) myGeoShape.size(); i++) {
54  GeoConvHelper::getFinal().cartesian2geo(myGeoShape[i]);
55  }
56  // update geometry
57  updateGeometry();
58 }
59 
60 
62 
63 
65 GNEPoly::getMoveOperation(const double shapeOffset) {
66  // edit depending if shape is blocked
67  if (myBlockMovement) {
68  // nothing to move
69  return nullptr;
70  } else if (myBlockShape) {
71  // move entire shape
72  return new GNEMoveOperation(this, myShape);
73  } else {
74  // declare shape to move
75  PositionVector shapeToMove = myShape;
76  // first check if in the given shapeOffset there is a geometry point
77  const Position positionAtOffset = shapeToMove.positionAtOffset2D(shapeOffset);
78  // check if position is valid
79  if (positionAtOffset == Position::INVALID) {
80  return nullptr;
81  } else {
82  // obtain index
83  const int index = myShape.indexOfClosest(positionAtOffset);
84  // declare new index
85  int newIndex = index;
86  // get snap radius
88  // check if we have to create a new index
89  if (positionAtOffset.distanceSquaredTo2D(shapeToMove[index]) > (snap_radius * snap_radius)) {
90  newIndex = shapeToMove.insertAtClosest(positionAtOffset, true);
91  }
92  // get last index
93  const int lastIndex = ((int)shapeToMove.size() - 1);
94  // return move operation for edit shape
95  if (myShape.isClosed() && ((index == 0) || (index == lastIndex))) {
96  return new GNEMoveOperation(this, myShape, {0, lastIndex}, shapeToMove, {0, lastIndex});
97  } else {
98  return new GNEMoveOperation(this, myShape, {index}, shapeToMove, {newIndex});
99  }
100  }
101  }
102 }
103 
104 
105 void
106 GNEPoly::removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) {
107  // get original shape
108  PositionVector shape = myShape;
109  // check shape size
110  if (shape.size() > 2) {
111  // obtain index
112  int index = shape.indexOfClosest(clickedPosition);
113  // get snap radius
115  // check if we have to create a new index
116  if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {
117  // remove geometry point
118  shape.erase(shape.begin() + index);
119  // commit new shape
120  undoList->p_begin("remove geometry point of " + getTagStr());
121  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_SHAPE, toString(shape)));
122  undoList->p_end();
123  }
124  }
125 }
126 
127 
128 std::string
130  int counter = (int)myNet->getAttributeCarriers()->getShapes().at(SUMO_TAG_POLY).size();
131  while (myNet->retrieveShape(SUMO_TAG_POLY, getID() + toString(childTag) + toString(counter), false) != nullptr) {
132  counter++;
133  }
134  return (getID() + toString(childTag) + toString(counter));
135 }
136 
137 
138 void
139 GNEPoly::setParameter(const std::string& key, const std::string& value) {
140  Parameterised::setParameter(key, value);
141 }
142 
143 
144 void
146  // just update geometry
148 }
149 
150 
151 void
152 GNEPoly::updateCenteringBoundary(const bool updateGrid) {
153  // Remove object from net
154  if (updateGrid) {
156  }
157  // use shape as boundary
159  // grow boundary
160  myBoundary.grow(10);
161  // add object into net
162  if (updateGrid) {
163  myNet->addGLObjectIntoGrid(this);
164  }
165 }
166 
167 
168 void
170  writeXML(device, myGEO);
171 }
172 
173 
174 GUIGlID
176  return GUIGlObject::getGlID();
177 }
178 
179 
180 std::string
182  return myNet->getMicrosimID();
183 }
184 
185 
188  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
189  buildPopupHeader(ret, app);
192  // build selection and show parameters menu
195  FXMenuCommand* simplifyShape = GUIDesigns::buildFXMenuCommand(ret, "Simplify Shape\t\tReplace current shape with a rectangle", nullptr, &parent, MID_GNE_POLYGON_SIMPLIFY_SHAPE);
196  // disable simplify shape if polygon was already simplified
197  if (mySimplifiedShape || myShape.size() <= 2) {
198  simplifyShape->disable();
199  }
200  if (myShape.isClosed()) {
201  GUIDesigns::buildFXMenuCommand(ret, "Open shape\t\tOpen polygon's shape", nullptr, &parent, MID_GNE_POLYGON_OPEN);
202  } else {
203  GUIDesigns::buildFXMenuCommand(ret, "Close shape\t\tClose polygon's shape", nullptr, &parent, MID_GNE_POLYGON_CLOSE);
204  }
205  // create a extra FXMenuCommand if mouse is over a vertex
206  int index = getVertexIndex(myNet->getViewNet()->getPositionInformation(), false);
207  if (index != -1) {
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  // Obtain constants
245  const double polyExaggeration = s.polySize.getExaggeration(s, this);
246  const Position mousePosition = myNet->getViewNet()->getPositionInformation();
247  // get colors
249  const RGBColor invertedColor = color.invertedColor();
250  const RGBColor darkerColor = color.changedBrightness(-32);
251  // obtain scaled geometry
252  GNEGeometry::Geometry scaledGeometry = myPolygonGeometry;
253  if (polyExaggeration != 1) {
254  scaledGeometry.scaleGeometry(polyExaggeration);
255  }
256  // push name (needed for getGUIGlObjectsUnderCursor(...)
257  glPushName(getGlID());
258  // push layer matrix
259  glPushMatrix();
260  // translate to front
262  // check if we're drawing a polygon or a polyline
263  if (getFill()) {
264  if (s.drawForPositionSelection) {
265  // check if mouse is within geometry
266  if (scaledGeometry.getShape().around(mousePosition)) {
267  // push matrix
268  glPushMatrix();
269  // move to mouse position
270  glTranslated(mousePosition.x(), mousePosition.y(), 0);
271  // set color
272  GLHelper::setColor(color);
273  // draw circle
275  // pop matrix
276  glPopMatrix();
277  }
278  } else {
279  // draw inner polygon
280  GUIPolygon::drawInnerPolygon(s, this, this, scaledGeometry.getShape(), 0, drawUsingSelectColor());
281  }
282  } else {
283  // push matrix
284  glPushMatrix();
285  // set color
286  GLHelper::setColor(color);
287  // draw geometry (polyline)
288  GNEGeometry::drawGeometry(myNet->getViewNet(), scaledGeometry, s.neteditSizeSettings.polylineWidth * polyExaggeration);
289  // pop matrix
290  glPopMatrix();
291  }
292  // draw contour if shape isn't blocked
293  if (!myBlockShape) {
294  // push contour matrix
295  glPushMatrix();
296  // translate to front
297  glTranslated(0, 0, 0.1);
298  // set color
299  GLHelper::setColor(darkerColor);
300  // draw polygon contour
302  // pop contour matrix
303  glPopMatrix();
304  // draw shape points only in Network supemode
306  // draw geometry points
307  GNEGeometry::drawGeometryPoints(s, myNet->getViewNet(), scaledGeometry.getShape(), darkerColor, invertedColor, s.neteditSizeSettings.polygonGeometryPointRadius, polyExaggeration);
308  // draw moving hint points
309  if (myBlockMovement == false) {
310  GNEGeometry::drawMovingHint(s, myNet->getViewNet(), scaledGeometry.getShape(), invertedColor, s.neteditSizeSettings.polygonGeometryPointRadius, polyExaggeration);
311  }
312  }
313  }
314  // pop layer matrix
315  glPopMatrix();
316  // check if dotted contour has to be drawn
318  // draw depending if is closed
319  if (getFill() || scaledGeometry.getShape().isClosed()) {
321  } else {
323  }
324  }
325  // pop name
326  glPopName();
327  }
328 }
329 
330 
331 int
332 GNEPoly::getVertexIndex(Position pos, bool snapToGrid) {
333  // check if position has to be snapped to grid
334  if (snapToGrid) {
335  pos = myNet->getViewNet()->snapToActiveGrid(pos);
336  }
337  // first check if vertex already exists
338  for (const auto& shapePosition : myShape) {
339  if (shapePosition.distanceTo2D(pos) < myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.polygonGeometryPointRadius) {
340  return myShape.indexOfClosest(shapePosition);
341  }
342  }
343  return -1;
344 }
345 
346 
347 void
348 GNEPoly::deleteGeometryPoint(const Position& pos, bool allowUndo) {
349  if (myShape.size() > 1) {
350  // obtain index
351  PositionVector modifiedShape = myShape;
352  int index = modifiedShape.indexOfClosest(pos);
353  // remove point dependending of
354  if (myShape.isClosed() && (index == 0 || index == (int)modifiedShape.size() - 1) && (myShape.size() > 2)) {
355  modifiedShape.erase(modifiedShape.begin());
356  modifiedShape.erase(modifiedShape.end() - 1);
357  modifiedShape.push_back(modifiedShape.front());
358  } else {
359  modifiedShape.erase(modifiedShape.begin() + index);
360  }
361  // set new shape depending of allowUndo
362  if (allowUndo) {
363  myNet->getViewNet()->getUndoList()->p_begin("delete geometry point");
366  } else {
367  // first remove object from grid due shape is used for boundary
369  // set new shape
370  myShape = modifiedShape;
371  // disable simplified shape flag
372  mySimplifiedShape = false;
373  // add object into grid again
374  myNet->addGLObjectIntoGrid(this);
375  }
376  } else {
377  WRITE_WARNING("Number of remaining points insufficient")
378  }
379 }
380 
381 
382 bool
384  return myBlockShape;
385 }
386 
387 
388 bool
390  return myShape.isClosed();
391 }
392 
393 
394 void
395 GNEPoly::openPolygon(bool allowUndo) {
396  // only open if shape is closed
397  if (myShape.isClosed()) {
398  if (allowUndo) {
399  myNet->getViewNet()->getUndoList()->p_begin("open polygon");
402  } else {
403  myShape.pop_back();
404  // disable simplified shape flag
405  mySimplifiedShape = false;
406  // update geometry to avoid grabbing Problems
407  updateGeometry();
408  }
409  } else {
410  WRITE_WARNING("Polygon already opened")
411  }
412 }
413 
414 
415 void
416 GNEPoly::closePolygon(bool allowUndo) {
417  // only close if shape is opened
418  if (myShape.isClosed() == false) {
419  if (allowUndo) {
420  myNet->getViewNet()->getUndoList()->p_begin("close shape");
423  } else {
425  // disable simplified shape flag
426  mySimplifiedShape = false;
427  // update geometry to avoid grabbing Problems
428  updateGeometry();
429  }
430  } else {
431  WRITE_WARNING("Polygon already closed")
432  }
433 }
434 
435 
436 void
437 GNEPoly::changeFirstGeometryPoint(int oldIndex, bool allowUndo) {
438  // check that old index is correct
439  if (oldIndex >= (int)myShape.size()) {
440  throw InvalidArgument("Invalid old Index");
441  } else if (oldIndex == 0) {
442  WRITE_WARNING("Selected point must be different of the first point")
443  } else {
444  // Configure new shape
445  PositionVector newShape;
446  for (int i = oldIndex; i < (int)myShape.size(); i++) {
447  newShape.push_back(myShape[i]);
448  }
449  if (myShape.isClosed()) {
450  for (int i = 1; i < oldIndex; i++) {
451  newShape.push_back(myShape[i]);
452  }
453  newShape.push_back(newShape.front());
454  } else {
455  for (int i = 0; i < oldIndex; i++) {
456  newShape.push_back(myShape[i]);
457  }
458  }
459  // set new rotated shape
460  if (allowUndo) {
461  myNet->getViewNet()->getUndoList()->p_begin("change first geometry point");
464  } else {
465  // set new shape
466  myShape = newShape;
467  // disable simplified shape flag
468  mySimplifiedShape = false;
469  // update geometry to avoid grabbing Problems
470  updateGeometry();
471  }
472  }
473 }
474 
475 
476 void
477 GNEPoly::simplifyShape(bool allowUndo) {
478  if (!mySimplifiedShape && myShape.size() > 2) {
479  const Boundary b = myShape.getBoxBoundary();
480  PositionVector simplifiedShape;
481  if (myShape.isClosed()) {
482  // create a square as simplified shape
483  simplifiedShape.push_back(Position(b.xmin(), b.ymin()));
484  simplifiedShape.push_back(Position(b.xmin(), b.ymax()));
485  simplifiedShape.push_back(Position(b.xmax(), b.ymax()));
486  simplifiedShape.push_back(Position(b.xmax(), b.ymin()));
487  simplifiedShape.push_back(simplifiedShape[0]);
488  } else {
489  // create a line as simplified shape
490  simplifiedShape.push_back(myShape.front());
491  simplifiedShape.push_back(myShape.back());
492  }
493  // set new shape depending of allowUndo
494  if (allowUndo) {
495  myNet->getViewNet()->getUndoList()->p_begin("simplify shape");
498  } else {
499  // set new shape
500  myShape = simplifiedShape;
501  // update geometry to avoid grabbing Problems
502  updateGeometry();
503  }
504  // change flag after setting simplified shape
505  mySimplifiedShape = true;
506  } else {
507  WRITE_WARNING("Polygon already simplified")
508  }
509 }
510 
511 
512 std::string
514  switch (key) {
515  case SUMO_ATTR_ID:
516  return myID;
517  case SUMO_ATTR_SHAPE:
518  return toString(myShape);
519  case SUMO_ATTR_GEOSHAPE:
521  case SUMO_ATTR_COLOR:
522  return toString(getShapeColor());
523  case SUMO_ATTR_FILL:
524  return toString(myFill);
525  case SUMO_ATTR_LINEWIDTH:
526  return toString(myLineWidth);
527  case SUMO_ATTR_LAYER:
529  return "default";
530  } else {
531  return toString(getShapeLayer());
532  }
533  case SUMO_ATTR_TYPE:
534  return getShapeType();
535  case SUMO_ATTR_IMGFILE:
536  return getShapeImgFile();
538  return toString(getShapeRelativePath());
539  case SUMO_ATTR_ANGLE:
540  return toString(getShapeNaviDegree());
541  case SUMO_ATTR_GEO:
542  return toString(myGEO);
544  return toString(myBlockMovement);
546  return toString(myBlockShape);
548  return toString(myShape.isClosed());
549  case GNE_ATTR_SELECTED:
551  case GNE_ATTR_PARAMETERS:
552  return getParametersStr();
553  default:
554  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
555  }
556 }
557 
558 
559 void
560 GNEPoly::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
561  if (value == getAttribute(key)) {
562  return; //avoid needless changes, later logic relies on the fact that attributes have changed
563  }
564  switch (key) {
565  case SUMO_ATTR_ID:
566  case SUMO_ATTR_SHAPE:
567  case SUMO_ATTR_GEOSHAPE:
568  case SUMO_ATTR_COLOR:
569  case SUMO_ATTR_FILL:
570  case SUMO_ATTR_LINEWIDTH:
571  case SUMO_ATTR_LAYER:
572  case SUMO_ATTR_TYPE:
573  case SUMO_ATTR_IMGFILE:
575  case SUMO_ATTR_ANGLE:
576  case SUMO_ATTR_GEO:
580  case GNE_ATTR_SELECTED:
581  case GNE_ATTR_PARAMETERS:
582  undoList->p_add(new GNEChange_Attribute(this, key, value));
583  break;
584  default:
585  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
586  }
587 }
588 
589 
590 bool
591 GNEPoly::isValid(SumoXMLAttr key, const std::string& value) {
592  switch (key) {
593  case SUMO_ATTR_ID:
594  return SUMOXMLDefinitions::isValidTypeID(value) && (myNet->retrieveShape(SUMO_TAG_POLY, value, false) == nullptr);
595  case SUMO_ATTR_SHAPE:
596  case SUMO_ATTR_GEOSHAPE:
597  // empty shapes AREN'T allowed
598  if (value.empty()) {
599  return false;
600  } else {
601  return canParse<PositionVector>(value);
602  }
603  case SUMO_ATTR_COLOR:
604  return canParse<RGBColor>(value);
605  case SUMO_ATTR_FILL:
606  return canParse<bool>(value);
607  case SUMO_ATTR_LINEWIDTH:
608  return canParse<double>(value) && (parse<double>(value) >= 0);
609  case SUMO_ATTR_LAYER:
610  if (value == "default") {
611  return true;
612  } else {
613  return canParse<double>(value);
614  }
615  case SUMO_ATTR_TYPE:
616  return true;
617  case SUMO_ATTR_IMGFILE:
618  if (value == "") {
619  return true;
620  } else {
621  // check that image can be loaded
622  return GUITexturesHelper::getTextureID(value) != -1;
623  }
625  return canParse<bool>(value);
626  case SUMO_ATTR_ANGLE:
627  return canParse<double>(value);
628  case SUMO_ATTR_GEO:
629  return canParse<bool>(value);
631  return canParse<bool>(value);
633  return canParse<bool>(value);
635  if (canParse<bool>(value)) {
636  bool closePolygon = parse<bool>(value);
637  if (closePolygon && (myShape.begin() == myShape.end())) {
638  // Polygon already closed, then invalid value
639  return false;
640  } else if (!closePolygon && (myShape.begin() != myShape.end())) {
641  // Polygon already open, then invalid value
642  return false;
643  } else {
644  return true;
645  }
646  } else {
647  return false;
648  }
649  case GNE_ATTR_SELECTED:
650  return canParse<bool>(value);
651  case GNE_ATTR_PARAMETERS:
652  return Parameterised::areParametersValid(value);
653  default:
654  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
655  }
656 }
657 
658 bool
660  // check if we're in supermode Network
662  return true;
663  } else {
664  return false;
665  }
666 }
667 
668 
669 const std::map<std::string, std::string>&
671  return getParametersMap();
672 }
673 
674 // ===========================================================================
675 // private
676 // ===========================================================================
677 
678 void
679 GNEPoly::setAttribute(SumoXMLAttr key, const std::string& value) {
680  switch (key) {
681  case SUMO_ATTR_ID: {
682  // note: getAttributeCarriers().updateID doesn't change Microsim ID in GNEShapes
683  myNet->getAttributeCarriers()->updateID(this, value);
684  // set named ID
685  myID = value;
686  break;
687  }
688  case SUMO_ATTR_SHAPE: {
689  // set new shape
690  myShape = parse<PositionVector>(value);
691  // set GEO shape
693  for (int i = 0; i < (int) myGeoShape.size(); i++) {
695  }
696  // disable simplified shape flag
697  mySimplifiedShape = false;
698  // update geometry
699  updateGeometry();
700  // update centering boundary
702  break;
703  }
704  case SUMO_ATTR_GEOSHAPE: {
705  // set new GEO shape
706  myGeoShape = parse<PositionVector>(value);
707  // set shape
708  myShape = myGeoShape ;
709  for (int i = 0; i < (int) myShape.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_COLOR:
721  setShapeColor(parse<RGBColor>(value));
722  break;
723  case SUMO_ATTR_FILL:
724  myFill = parse<bool>(value);
725  break;
726  case SUMO_ATTR_LINEWIDTH:
727  myLineWidth = parse<double>(value);
728  break;
729  case SUMO_ATTR_LAYER:
730  if (value == "default") {
732  } else {
733  setShapeLayer(parse<double>(value));
734  }
735  break;
736  case SUMO_ATTR_TYPE:
737  setShapeType(value);
738  break;
739  case SUMO_ATTR_IMGFILE:
740  setShapeImgFile(value);
741  // all textures must be refresh
743  break;
745  setShapeRelativePath(parse<bool>(value));
746  break;
747  case SUMO_ATTR_ANGLE:
748  setShapeNaviDegree(parse<double>(value));
749  break;
750  case SUMO_ATTR_GEO:
751  myGEO = parse<bool>(value);
752  // update centering boundary
754  break;
756  myBlockMovement = parse<bool>(value);
757  break;
759  myBlockShape = parse<bool>(value);
760  break;
762  if (parse<bool>(value)) {
765  } else {
766  myShape.pop_back();
767  myGeoShape.pop_back();
768  }
769  // disable simplified shape flag
770  mySimplifiedShape = false;
771  // update geometry
772  updateGeometry();
773  // update centering boundary
775  break;
776  case GNE_ATTR_SELECTED:
777  if (parse<bool>(value)) {
779  } else {
781  }
782  break;
783  case GNE_ATTR_PARAMETERS:
784  setParametersStr(value);
785  break;
786  default:
787  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
788  }
789 }
790 
791 
792 void
794  // update new shape
795  myShape = moveResult.shapeToUpdate;
796  // update geometry
798 }
799 
800 
801 void
802 GNEPoly::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
803  // commit new shape
804  undoList->p_begin("moving " + toString(SUMO_ATTR_SHAPE) + " of " + getTagStr());
805  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_SHAPE, toString(moveResult.shapeToUpdate)));
806  undoList->p_end();
807 }
808 
809 /****************************************************************************/
@ MID_GNE_POLYGON_CLOSE
close opened polygon
Definition: GUIAppEnum.h:1025
@ MID_GNE_POLYGON_SET_FIRST_POINT
Set a vertex of polygon as first verte.
Definition: GUIAppEnum.h:1029
@ MID_GNE_POLYGON_DELETE_GEOMETRY_POINT
delete geometry point
Definition: GUIAppEnum.h:1031
@ MID_GNE_POLYGON_OPEN
open closed polygon
Definition: GUIAppEnum.h:1027
@ MID_GNE_POLYGON_SIMPLIFY_SHAPE
simplify polygon geometry
Definition: GUIAppEnum.h:1023
unsigned int GUIGlID
Definition: GUIGlObject.h:40
@ GLO_POLYGON
a polygon
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:276
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_POLY
begin/end of the description of a polygon
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
@ 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_LAYER
A layer number.
@ SUMO_ATTR_ANGLE
@ GNE_ATTR_BLOCK_SHAPE
block shape of a graphic element (Used mainly in GNEShapes)
@ 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:44
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
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:647
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:347
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.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
class for NETEDIT geometries over lanes
Definition: GNEGeometry.h:76
void scaleGeometry(const double scale)
scale geometry
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
const std::map< SumoXMLTag, std::map< std::string, GNEShape * > > & getShapes() const
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1411
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1423
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEShape * retrieveShape(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named shape.
Definition: GNENet.cpp:2944
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
void updateGeometry()
update pre-computed geometry information
Definition: GNEPoly.cpp:145
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:204
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEPoly.cpp:591
bool isPolygonBlocked() const
return true if polygon is blocked
Definition: GNEPoly.cpp:383
~GNEPoly()
Destructor.
Definition: GNEPoly.cpp:61
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEPoly.cpp:513
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
Definition: GNEPoly.cpp:793
bool myBlockShape
flag for block shape
Definition: GNEPoly.h:201
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:332
PositionVector myGeoShape
Latitude of Polygon.
Definition: GNEPoly.h:198
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
Definition: GNEPoly.cpp:65
void closePolygon(bool allowUndo=true)
close polygon
Definition: GNEPoly.cpp:416
void changeFirstGeometryPoint(int oldIndex, bool allowUndo=true)
change first geometry point
Definition: GNEPoly.cpp:437
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position
Definition: GNEPoly.cpp:106
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Definition: GNEPoly.cpp:802
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNEPoly.cpp:187
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
Definition: GNEPoly.cpp:139
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNEPoly.cpp:659
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:348
const std::string & getID() const
needed to avoid diamond problem between SUMOPolygon and GNEShape
Definition: GNEShape.cpp:53
std::string getParentName() const
Returns the name of the parent object.
Definition: GNEPoly.cpp:181
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:560
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
Definition: GNEPoly.cpp:152
void writeShape(OutputDevice &device)
writte shape element into a xml file
Definition: GNEPoly.cpp:169
bool isPolygonClosed() const
check if polygon is closed
Definition: GNEPoly.cpp:389
void simplifyShape(bool allowUndo=true)
replace the current shape with a rectangle
Definition: GNEPoly.cpp:477
GNEGeometry::Geometry myPolygonGeometry
geometry for lenghts/rotations
Definition: GNEPoly.h:207
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
Definition: GNEPoly.cpp:670
GNEPoly(GNENet *net, const std::string &id, const std::string &type, const PositionVector &shape, bool geo, bool fill, double lineWidth, const RGBColor &color, double layer, double angle, const std::string &imgFile, bool relativePath, bool movementBlocked, bool shapeBlocked)
Constructor.
Definition: GNEPoly.cpp:39
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GNEPoly.cpp:175
std::string generateChildID(SumoXMLTag childTag)
gererate a new ID for an element child
Definition: GNEPoly.cpp:129
void openPolygon(bool allowUndo=true)
open polygon
Definition: GNEPoly.cpp:395
Boundary myBoundary
object boundary
Definition: GNEShape.h:204
bool myBlockMovement
flag to block movement
Definition: GNEShape.h:207
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:71
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:78
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:467
GNEUndoList * getUndoList() const
get the undoList object
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
Definition: GNEViewNet.cpp:368
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
Definition: GNEViewNet.cpp:485
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
Definition: GUIDesigns.cpp:40
The popup menu of a globject.
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.
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.
GUIGlID getGlID() const
Returns the numerical id of the object.
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:257
static void drawInnerPolygon(const GUIVisualizationSettings &s, const SUMOPolygon *polygon, const GUIGlObject *o, const PositionVector shape, double layer, bool disableSelectionColor)
draw inner Polygon (before pushName() )
Definition: GUIPolygon.cpp:279
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 drawDottedContour() const
check if dotted contour can be drawn
bool drawMovingGeometryPoint(const double exaggeration, const double radius) const
check if moving geometry point can be draw
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationSizeSettings polySize
int getCircleResolution() const
function to calculate circle resolution for all circles drawn in drawGL(...) functions
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
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:124
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, 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:36
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions)
Definition: Position.h:246
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:282
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
A list of positions.
void closePolygon()
ensures that the last position equals the first
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
int insertAtClosest(const Position &p, bool interpolateZ)
inserts p between the two closest positions
int indexOfClosest(const Position &p) const
index of the closest position to p
bool isClosed() const
check if PositionVector is closed
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
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:134
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:145
PositionVector myShape
The positions of the polygon.
Definition: SUMOPolygon.h:133
double myLineWidth
The line width for drawing an unfilled polygon.
Definition: SUMOPolygon.h:142
bool myGEO
specify if shape is handled as GEO coordinate (Main used in netedit)
Definition: SUMOPolygon.h:136
void writeXML(OutputDevice &out, bool geo=false)
Definition: SUMOPolygon.cpp:49
bool myFill
Information whether the polygon has to be filled.
Definition: SUMOPolygon.h:139
bool getFill() const
Returns whether the polygon is filled.
Definition: SUMOPolygon.h:90
static bool isValidTypeID(const std::string &value)
whether the given string is a valid id for an edge or vehicle type
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition: Shape.h:80
static const double DEFAULT_LAYER
Definition: Shape.h:41
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition: Shape.h:101
void setShapeLayer(const double layer)
Sets a new layer.
Definition: Shape.h:141
bool getShapeRelativePath() const
Returns the relativePath of the Shape.
Definition: Shape.h:108
void setShapeType(const std::string &type)
Sets a new type.
Definition: Shape.h:120
void setShapeRelativePath(bool relativePath)
Sets a new relativePath value.
Definition: Shape.h:162
virtual void setShapeNaviDegree(const double angle)
Sets a new angle in navigational degrees.
Definition: Shape.h:148
void setShapeImgFile(const std::string &imgFile)
Sets a new imgFile.
Definition: Shape.h:155
void setShapeColor(const RGBColor &col)
Sets a new color.
Definition: Shape.h:127
double getShapeLayer() const
Returns the layer of the Shape.
Definition: Shape.h:87
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:94
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:73
static void drawDottedContourClosedShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double exaggeration)
draw dotted contour for the given closed shape (used by Juctions, shapes and TAZs)
static void drawGeometryPoints(const GUIVisualizationSettings &s, const GNEViewNet *viewNet, const PositionVector &shape, const RGBColor &geometryPointColor, const RGBColor &textColor, const double radius, const double exaggeration)
draw geometry points
static void drawDottedContourShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration)
draw dotted contour for the given shape (used by additionals)
static void drawGeometry(const GNEViewNet *viewNet, const Geometry &geometry, const double width)
draw geometry
static void drawMovingHint(const GUIVisualizationSettings &s, const GNEViewNet *viewNet, const PositionVector &shape, const RGBColor &hintColor, const double radius, const double exaggeration)
draw moving hint
bool showShapes() const
check if shapes has to be drawn
bool showShapes() const
check if shapes has to be drawn
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network
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