SUMO - Simulation of Urban MObility
GNEPoly.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A class for visualizing and editing POIS in netedit (adapted from
8 // GUIPolygon and NLHandler)
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <utility>
36 #include <utils/geom/Position.h>
40 #include <utils/xml/XMLSubSys.h>
47 #include <utils/gui/div/GLHelper.h>
53 #include <netwrite/NWWriter_SUMO.h>
54 
55 #include "GNENet.h"
56 #include "GNEEdge.h"
57 #include "GNEUndoList.h"
58 #include "GNEViewNet.h"
59 #include "GNEChange_Attribute.h"
60 #include "GNEPoly.h"
61 #include "GNEJunction.h"
62 
63 // ===========================================================================
64 // static members
65 // ===========================================================================
66 const double GNEPoly::myHintSize = 0.8;
67 
68 // ===========================================================================
69 // method definitions
70 // ===========================================================================
71 GNEPoly::GNEPoly(GNENet* net, const std::string& id, const std::string& type, const PositionVector& shape, bool fill,
72  const RGBColor& color, double layer, double angle, const std::string& imgFile, bool movementBlocked, bool shapeBlocked) :
73  GUIPolygon(id, type, color, shape, fill, layer, angle, imgFile),
74  GNEShape(net, SUMO_TAG_POLY, ICON_LOCATEPOLY, movementBlocked, shapeBlocked),
75  myShapeEditedJunction(NULL),
76  myClosedShape(shape.front() == shape.back()),
77  mySimplifiedShape(false),
78  myCurrentMovingVertexIndex(-1) {
79  // check if imgFile is valid
80  if(!imgFile.empty() && GUITexturesHelper::getTextureID(imgFile) == -1) {
81  setImgFile("");
82  }
83 }
84 
85 
87 
88 
89 int
90 GNEPoly::moveVertexShape(int index, const Position& newPos) {
91  // only move shape if block movement block shape are disabled
92  if (!myBlockMovement && !myBlockShape && (index != -1)) {
93  // check that index is correct before change position
94  if (index < (int)myShape.size()) {
95  // save current moving vertex
97  // if closed shape and cliked is first or last, move both giving more priority to first always
98  if (myClosedShape && (index == 0 || index == (int)myShape.size() - 1)) {
99  myShape.front() = newPos;
100  myShape.back() = newPos;
101  return 0;
102  } else {
103  // change position of vertex
104  myShape[index] = newPos;
105  return index;
106  }
107  } else {
108  throw InvalidArgument("Index greater than shape size");
109  }
110  } else {
111  return index;
112  }
113 }
114 
115 
116 void
117 GNEPoly::moveEntireShape(const PositionVector& oldShape, const Position& offset) {
118  // only move shape if block movement is disabled and block shape is enabled
119  if (!myBlockMovement && myBlockShape) {
120  // restore original shape
121  myShape = oldShape;
122  // change all points of the shape shape using noffset
123  for (auto i = myShape.begin(); i != myShape.end(); i++) {
124  i->setx(i->x() - offset.x());
125  i->sety(i->y() - offset.y());
126  }
127  // refresh element
128  myNet->refreshPolygon(this);
129  }
130 }
131 
132 
133 void
135  if (!myBlockMovement) {
136  // disable current moving vertex
138  // restore original shape into shapeToCommit
139  PositionVector shapeToCommit = myShape;
140  // first check if double points has to be removed
141  shapeToCommit.removeDoublePoints(myHintSize);
142  if (shapeToCommit.size() != myShape.size()) {
143  WRITE_WARNING("Merged shape's point")
144  }
145  // check if polygon has to be closed
146  if (shapeToCommit.front().distanceTo2D(shapeToCommit.back()) < (2 * myHintSize)) {
147  shapeToCommit.pop_back();
148  shapeToCommit.push_back(shapeToCommit.front());
149  }
150  // only use GNEChange_Attribute if we aren't editing a junction's shape
151  if (myShapeEditedJunction == NULL) {
152  myShape = oldShape;
153  // commit new shape
154  undoList->p_begin("moving " + toString(SUMO_ATTR_SHAPE) + " of " + toString(getTag()));
155  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_SHAPE, toString(shapeToCommit)));
156  undoList->p_end();
157  } else {
158  setAttribute(SUMO_ATTR_SHAPE, toString(shapeToCommit));
159  }
160  }
161 }
162 
163 
165  writeXML(device);
166 }
167 
168 
169 Position
171  return myShape.getPolygonCenter();
172 }
173 
174 
175 const std::string&
177  if (myShapeEditedJunction != NULL) {
179  } else {
180  return myNet->getMicrosimID();
181  }
182 }
183 
184 
187  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
188  buildPopupHeader(ret, app);
192  FXMenuCommand* simplifyShape = new FXMenuCommand(ret, "Simplify Shape\t\tReplace current shape with a rectangle", 0, &parent, MID_GNE_POLYGON_SIMPLIFY_SHAPE);
193  // disable simplify shape if polygon was already simplified
194  if (mySimplifiedShape) {
195  simplifyShape->disable();
196  }
197  // create open or close polygon's shape only if myShapeEditedJunction is NULL
198  if (myShapeEditedJunction == NULL) {
199  if (myClosedShape) {
200  new FXMenuCommand(ret, "Open shape\t\tOpen polygon's shape", 0, &parent, MID_GNE_POLYGON_OPEN);
201  } else {
202  new FXMenuCommand(ret, "Close shape\t\tClose polygon's shape", 0, &parent, MID_GNE_POLYGON_CLOSE);
203  }
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 = new FXMenuCommand(ret, "Remove geometry point\t\tRemove geometry point under mouse", 0, &parent, MID_GNE_VIEWNET_DELETE_GEOMETRY_POINT);
209  FXMenuCommand* setFirstPoint = new FXMenuCommand(ret, "Set first geometry point\t\tSet", 0, &parent, MID_GNE_POLYGON_SET_FIRST_POINT);
210  // disable setFirstPoint if shape only have three points
211  if ((myClosedShape && (myShape.size() <= 4)) || (!myClosedShape && (myShape.size() <= 3))) {
212  removeGeometryPoint->disable();
213  }
214  // disable setFirstPoint if mouse is over first point
215  if (index == 0) {
216  setFirstPoint->disable();
217  }
218  }
219  // let the GNEViewNet store the popup position
220  (dynamic_cast<GNEViewNet&>(parent)).markPopupPosition();
221  return ret;
222 }
223 
224 
227  return GUIPolygon::getParameterWindow(app, parent);
228 }
229 
230 
231 Boundary
234 }
235 
236 
237 void
239  // change temporally attribute color if polygon is selected
240  bool selected = gSelected.isSelected(GLO_POLYGON, getGlID());
241  // simply use GUIPolygon::drawGL
243  // draw geometry details hints if is not too small
244  if (s.scale * myHintSize > 1.) {
245  // set values relative to mouse position regarding to shape
246  bool mouseOverVertex = false;
247  bool modeMove = myNet->getViewNet()->getCurrentEditMode() == GNE_MODE_MOVE;
248  Position mousePosition = myNet->getViewNet()->getPositionInformation();
249  double distanceToShape = myShape.distance2D(mousePosition);
250  Position PostionOverShapeLine = myShape.positionAtOffset2D(myShape.nearest_offset_to_point2D(mousePosition));
251  // set colors
252  RGBColor invertedColor, darkerColor;
253  if (selected) {
254  invertedColor = myNet->selectionColor.invertedColor();
255  darkerColor = myNet->selectedLaneColor;
256  } else {
257  invertedColor = GLHelper::getColor().invertedColor();
258  darkerColor = GLHelper::getColor().changedBrightness(-32);
259  }
260  // push matrix
261  glPushName(getGlID());
262  // Draw geometry hints if polygon's shape isn't blocked
263  if (myBlockShape == false) {
264  // draw a boundary for moving using darkerColor
265  glPushMatrix();
266  glTranslated(0, 0, GLO_POLYGON + 0.01);
267  GLHelper::setColor(darkerColor);
269  glPopMatrix();
270  // draw points of shape
271  for (auto i : myShape) {
272  glPushMatrix();
273  glTranslated(i.x(), i.y(), GLO_POLYGON + 0.02);
274  // Change color of vertex and flag mouseOverVertex if mouse is over vertex
275  if (modeMove && (i.distanceTo(mousePosition) < myHintSize)) {
276  mouseOverVertex = true;
277  GLHelper::setColor(invertedColor);
278  } else {
279  GLHelper::setColor(darkerColor);
280  }
282  glPopMatrix();
283  // draw special symbols (Start, End and Block)
284  if (i == myShape.front()) {
285  // draw a "s" over first point
286  glPushMatrix();
287  glTranslated(i.x(), i.y(), GLO_POLYGON + 0.03);
288  GLHelper::drawText("S", Position(), .1, 2 * myHintSize, invertedColor);
289  glPopMatrix();
290  } else if ((i == myShape.back()) && (myClosedShape == false)) {
291  // draw a "e" over last point if polygon isn't closed
292  glPushMatrix();
293  glTranslated(i.x(), i.y(), GLO_POLYGON + 0.03);
294  GLHelper::drawText("E", Position(), .1, 2 * myHintSize, invertedColor);
295  glPopMatrix();
296  }
297  }
298  // check if draw moving hint has to be drawed
299  if (modeMove && (mouseOverVertex == false) && (myBlockMovement == false) && (distanceToShape < myHintSize)) {
300  // push matrix
301  glPushMatrix();
302  glTranslated(PostionOverShapeLine.x(), PostionOverShapeLine.y(), GLO_POLYGON + 0.04);
303  GLHelper::setColor(invertedColor);
305  glPopMatrix();
306  }
307  }
308  // pop name
309  glPopName();
310  }
311 }
312 
313 
314 int GNEPoly::getVertexIndex(const Position& pos, bool createIfNoExist) {
315  // first check if vertex already exists
316  for (auto i : myShape) {
317  if (i.distanceTo2D(pos) < myHintSize) {
318  return myShape.indexOfClosest(i);
319  }
320  }
321  // if vertex doesn't exist, insert it
322  if (createIfNoExist && (myShape.distance2D(pos) < myHintSize)) {
323  return myShape.insertAtClosest(pos);
324  } else {
325  return -1;
326  }
327 }
328 
329 
330 bool
332  return myClosedShape;
333 }
334 
335 
337  if (junction) {
338  myShapeEditedJunction = junction;
339  } else {
340  throw InvalidArgument("Junction cannot be NULL");
341  }
342 }
343 
344 
346  return myShapeEditedJunction;
347 }
348 
349 
350 void
351 GNEPoly::openPolygon(bool allowUndo) {
352  // only open if shape is closed
353  if (myClosedShape) {
354  if (allowUndo) {
355  myNet->getViewNet()->getUndoList()->p_begin("open polygon");
358  } else {
359  myClosedShape = false;
360  myShape.pop_back();
361  // refresh polygon in net to avoid grabbing problems
362  myNet->refreshPolygon(this);
363  // disable simplified shape flag
364  mySimplifiedShape = false;
365  }
366  } else {
367  WRITE_WARNING("Polygon already opened")
368  }
369 }
370 
371 
372 void
373 GNEPoly::closePolygon(bool allowUndo) {
374  // only close if shape is opened
375  if (myClosedShape == false) {
376  if (allowUndo) {
377  myNet->getViewNet()->getUndoList()->p_begin("close shape");
380  } else {
381  myClosedShape = true;
383  // refresh polygon in net to avoid grabbing problems
384  myNet->refreshPolygon(this);
385  // disable simplified shape flag
386  mySimplifiedShape = false;
387  }
388  } else {
389  WRITE_WARNING("Polygon already closed")
390  }
391 }
392 
393 
394 void
395 GNEPoly::changeFirstGeometryPoint(int oldIndex, bool allowUndo) {
396  // check that old index is correct
397  if (oldIndex >= (int)myShape.size()) {
398  throw InvalidArgument("Invalid old Index");
399  } else if (oldIndex == 0) {
400  WRITE_WARNING("Selected point must be different of the first point")
401  } else {
402  // Configure new shape
403  PositionVector newShape;
404  for (int i = oldIndex; i < (int)myShape.size(); i++) {
405  newShape.push_back(myShape[i]);
406  }
407  if (myClosedShape) {
408  for (int i = 1; i < oldIndex; i++) {
409  newShape.push_back(myShape[i]);
410  }
411  newShape.push_back(newShape.front());
412  } else {
413  for (int i = 0; i < oldIndex; i++) {
414  newShape.push_back(myShape[i]);
415  }
416  }
417  // set new rotated shape
418  if (allowUndo) {
419  myNet->getViewNet()->getUndoList()->p_begin("change first geometry point");
422  } else {
423  // set new shape
424  myShape = newShape;
425  // Check if new shape is closed
426  myClosedShape = (myShape.front() == myShape.back());
427  // refresh polygon in net to avoid grabbing problems
428  myNet->refreshPolygon(this);
429  // disable simplified shape flag
430  mySimplifiedShape = false;
431  }
432  }
433 }
434 
435 
436 void
437 GNEPoly::simplifyShape(bool allowUndo) {
438  if (!mySimplifiedShape) {
439  const Boundary b = myShape.getBoxBoundary();
440  PositionVector simplifiedShape;
441  // create a square as simplified shape
442  simplifiedShape.push_back(Position(b.xmin(), b.ymin()));
443  simplifiedShape.push_back(Position(b.xmin(), b.ymax()));
444  simplifiedShape.push_back(Position(b.xmax(), b.ymax()));
445  simplifiedShape.push_back(Position(b.xmax(), b.ymin()));
446  simplifiedShape.push_back(simplifiedShape[0]);
447  // set new shape depending of allowUndo
448  if (allowUndo) {
449  myNet->getViewNet()->getUndoList()->p_begin("simplify shape");
452  } else {
453  // set new shape
454  myShape = simplifiedShape;
455  // Check if new shape is closed
456  myClosedShape = (myShape.front() == myShape.back());
457  // refresh polygon in net to avoid grabbing problems
458  myNet->refreshPolygon(this);
459  }
460  // change flag after setting simplified shape
461  mySimplifiedShape = true;
462  } else {
463  WRITE_WARNING("Polygon already simplified")
464  }
465 }
466 
467 
468 void
469 GNEPoly::deleteGeometryNear(const Position& pos, bool allowUndo) {
470  if ((myClosedShape && (myShape.size() > 4)) || (!myClosedShape && (myShape.size() > 3))) {
471  // obtain index
472  PositionVector modifiedShape = myShape;
473  int index = modifiedShape.indexOfClosest(pos);
474  // remove point dependending of
475  if (myClosedShape && (index == 0 || index == (int)modifiedShape.size() - 1)) {
476  modifiedShape.erase(modifiedShape.begin());
477  modifiedShape.erase(modifiedShape.end() - 1);
478  myShape.push_back(modifiedShape.front());
479  } else {
480  modifiedShape.erase(modifiedShape.begin() + index);
481  }
482  // set new shape depending of allowUndo
483  if (allowUndo) {
484  myNet->getViewNet()->getUndoList()->p_begin("delete geometry point");
487  } else {
488  // set new shape
489  myShape = modifiedShape;
490  // Check if new shape is closed
491  myClosedShape = (myShape.front() == myShape.back());
492  // refresh polygon in net to avoid grabbing problems
493  myNet->refreshPolygon(this);
494  // disable simplified shape flag
495  mySimplifiedShape = false;
496  }
497  } else {
498  WRITE_WARNING("Number of remaining points insufficient")
499  }
500 }
501 
502 
503 std::string
505  switch (key) {
506  case SUMO_ATTR_ID:
507  return myID;
508  case SUMO_ATTR_SHAPE:
509  return toString(myShape);
510  case SUMO_ATTR_COLOR:
511  return toString(myColor);
512  case SUMO_ATTR_FILL:
513  return toString(myFill);
514  case SUMO_ATTR_LAYER:
515  return toString(myLayer);
516  case SUMO_ATTR_TYPE:
517  return myType;
518  case SUMO_ATTR_IMGFILE:
519  return myImgFile;
520  case SUMO_ATTR_ANGLE:
521  return toString(getNaviDegree());
523  return toString(myBlockMovement);
525  return toString(myBlockShape);
527  return toString(myClosedShape);
528  default:
529  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
530  }
531 }
532 
533 
534 void
535 GNEPoly::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
536  if (value == getAttribute(key)) {
537  return; //avoid needless changes, later logic relies on the fact that attributes have changed
538  }
539  switch (key) {
540  case SUMO_ATTR_ID:
541  case SUMO_ATTR_SHAPE:
542  case SUMO_ATTR_COLOR:
543  case SUMO_ATTR_FILL:
544  case SUMO_ATTR_LAYER:
545  case SUMO_ATTR_TYPE:
546  case SUMO_ATTR_IMGFILE:
547  case SUMO_ATTR_ANGLE:
551  undoList->p_add(new GNEChange_Attribute(this, key, value));
552  break;
553  default:
554  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
555  }
556 }
557 
558 
559 bool
560 GNEPoly::isValid(SumoXMLAttr key, const std::string& value) {
561  switch (key) {
562  case SUMO_ATTR_ID:
563  return isValidID(value) && (myNet->retrievePolygon(value, false) == 0);
564  case SUMO_ATTR_SHAPE: {
565  bool ok = true;
566  // check if shape can be parsed
567  PositionVector shape = GeomConvHelper::parseShapeReporting(value, "user-supplied position", 0, ok, true);
568  return (shape.size() > 0);
569  }
570  case SUMO_ATTR_COLOR:
571  return canParse<RGBColor>(value);
572  case SUMO_ATTR_FILL:
573  return canParse<bool>(value);
574  case SUMO_ATTR_LAYER:
575  return canParse<double>(value);
576  case SUMO_ATTR_TYPE:
577  return true;
578  case SUMO_ATTR_IMGFILE:
579  if (value == "") {
580  return true;
581  } else if (isValidFilename(value)) {
582  // check that image can be loaded
583  return GUITexturesHelper::getTextureID(value) != -1;
584  } else {
585  return false;
586  }
587  case SUMO_ATTR_ANGLE:
588  return canParse<double>(value);
590  return canParse<bool>(value);
592  return canParse<bool>(value);
594  if (canParse<bool>(value)) {
595  bool closePolygon = parse<bool>(value);
596  if (closePolygon && (myShape.begin() == myShape.end())) {
597  // Polygon already closed, then invalid value
598  return false;
599  } else if (!closePolygon && (myShape.begin() != myShape.end())) {
600  // Polygon already open, then invalid value
601  return false;
602  } else {
603  return true;
604  }
605  } else {
606  return false;
607  }
608  default:
609  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
610  }
611 }
612 
613 // ===========================================================================
614 // private
615 // ===========================================================================
616 
617 void
618 GNEPoly::setAttribute(SumoXMLAttr key, const std::string& value) {
619  switch (key) {
620  case SUMO_ATTR_ID: {
621  std::string oldID = myID;
622  myID = value;
623  myNet->changePolygonID(this, oldID);
624  break;
625  }
626  case SUMO_ATTR_SHAPE: {
627  bool ok = true;
628  // set new shape
629  myShape = GeomConvHelper::parseShapeReporting(value, "netedit-given", 0, ok, true);
630  // Check if new shape is closed
631  myClosedShape = (myShape.front() == myShape.back());
632  // refresh polygon in net to avoid grabbing problems
633  myNet->refreshPolygon(this);
634  // disable simplified shape flag
635  mySimplifiedShape = false;
636  break;
637  }
638  case SUMO_ATTR_COLOR:
639  myColor = parse<RGBColor>(value);
640  break;
641  case SUMO_ATTR_FILL:
642  myFill = parse<bool>(value);
643  break;
644  case SUMO_ATTR_LAYER:
645  myLayer = parse<double>(value);
646  break;
647  case SUMO_ATTR_TYPE:
648  myType = value;
649  break;
650  case SUMO_ATTR_IMGFILE:
651  myType = value;
652  break;
653  case SUMO_ATTR_ANGLE:
654  setNaviDegree(parse<double>(value));
655  break;
657  myBlockMovement = parse<bool>(value);
658  break;
660  myBlockShape = parse<bool>(value);
661  break;
663  myClosedShape = parse<bool>(value);
664  if (myClosedShape) {
666  } else {
667  myShape.pop_back();
668  }
669  // refresh polygon in net to avoid grabbing problems
670  myNet->refreshPolygon(this);
671  // disable simplified shape flag
672  mySimplifiedShape = false;
673  break;
674  default:
675  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
676  }
677  // update view after every change
678  myNet->getViewNet()->update();
679 }
680 
681 
682 /****************************************************************************/
EditMode getCurrentEditMode() const
get the current edit mode
PositionVector myShape
The positions of the polygon.
Definition: SUMOPolygon.h:125
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:132
void openPolygon(bool allowUndo=true)
open polygon
Definition: GNEPoly.cpp:351
double scale
information about a lane&#39;s width (temporary, used for a single view)
a polygon
mode for moving things
Definition: GNEViewNet.h:53
bool myFill
Information whether the polygon has to be filled.
Definition: SUMOPolygon.h:128
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition: GLHelper.cpp:172
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
GNEPoly(GNENet *net, const std::string &id, const std::string &type, const PositionVector &shape, bool fill, const RGBColor &color, double layer, double angle, const std::string &imgFile, bool movementBlocked, bool shapeBlocked)
Constructor.
Definition: GNEPoly.cpp:71
block shape of a graphic element (Used mainly in GNEShapes)
static const RGBColor selectedLaneColor
color of selected lane
Definition: GNENet.h:106
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
virtual void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIPolygon.cpp:144
Set a vertex of polygon as first verte.
Definition: GUIAppEnum.h:664
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:144
A layer number.
double x() const
Returns the x-position.
Definition: Position.h:63
Stores the information about how to visualize structures.
void commitShapeChange(const PositionVector &oldShape, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of changeShapeGeometry(...)
Definition: GNEPoly.cpp:134
simplify polygon geometry
Definition: GUIAppEnum.h:656
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEPoly.cpp:238
Close shape of a polygon (Used by GNEPolys)
int getVertexIndex(const Position &pos, bool createIfNoExist=true)
return index of a vertex of shape, or of a new vertex if position is over an shape&#39;s edge ...
Definition: GNEPoly.cpp:314
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector) ...
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:92
bool mySimplifiedShape
flag to indicate if polygon is simplified
Definition: GNEPoly.h:204
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:85
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNEJunction * myShapeEditedJunction
junction of which the shape is being edited (optional)
Definition: GNEPoly.h:198
static bool isValidFilename(const std::string &value)
true if value is a valid file value
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:339
GNENet * myNet
the net to inform about updates
Definition: GNEShape.h:156
GUIGlID getGlID() const
Returns the numerical id of the object.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
void closePolygon(bool allowUndo=true)
close polygon
Definition: GNEPoly.cpp:373
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
GNEUndoList * getUndoList() const
get the undoList object
std::string myType
The type of the Shape.
Definition: Shape.h:158
GUIVisualizationSizeSettings polySize
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
void refreshPolygon(GNEPoly *p)
refresh polygon in view net
Definition: GNENet.cpp:1886
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUIPolygon.cpp:95
void removeDoublePoints(double minDist=POSITION_EPS, bool assertLength=false)
Removes positions if too near.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
bool myBlockShape
flag for block shape
Definition: GNEShape.h:162
close opened polygon
Definition: GUIAppEnum.h:660
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:438
bool myBlockMovement
flag to block movement
Definition: GNEShape.h:159
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEPoly.cpp:170
void writeShape(OutputDevice &device)
writte shape element into a xml file
Definition: GNEPoly.cpp:164
int moveVertexShape(int index, const Position &newPos)
change position of a vertex of shape without commiting change
Definition: GNEPoly.cpp:90
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:92
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
RGBColor invertedColor() const
obtain inverted of current RGBColor
Definition: RGBColor.cpp:146
A list of positions.
int indexOfClosest(const Position &p) const
index of the closest position to p
static const double myHintSize
hint size of vertex
Definition: GNEPoly.h:211
friend class GNEChange_Attribute
declare friend class
open closed polygon
Definition: GUIAppEnum.h:662
double y() const
Returns the y-position.
Definition: Position.h:68
void changePolygonID(GNEPoly *poly, const std::string &OldID)
change Polygon ID
Definition: GNENet.cpp:1924
int myCurrentMovingVertexIndex
index of vertex that is been moved (-1 means that none vertex is been moved)
Definition: GNEPoly.h:207
GNEPoly * retrievePolygon(const std::string &id, bool failHard=true) const
get Polygon by id
Definition: GNENet.cpp:1911
static int getTextureID(const std::string &filename, const bool mirrorX=false)
return texture id for the given filename (initialize on first use)
block movement of a graphic element
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIPolygon.cpp:82
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:157
edge: the shape in xml-definition
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEPoly.cpp:560
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:535
GNEJunction * getShapeEditedJunction() const
retrieve the junction of which the shape is being edited
Definition: GNEPoly.cpp:345
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEPoly.cpp:232
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNEPoly.cpp:186
void deleteGeometryNear(const Position &pos, bool allowUndo=true)
delete the geometry point closest to the given pos
Definition: GNEPoly.cpp:469
bool isPolygonClosed() const
check if polygon is closed
Definition: GNEPoly.cpp:331
std::string myID
The name of the object.
Definition: Named.h:136
void simplifyShape(bool allowUndo=true)
replace the current shape with a rectangle
Definition: GNEPoly.cpp:437
const std::string & getParentName() const
Returns the name of the parent object.
Definition: GNEPoly.cpp:176
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:126
void setNaviDegree(const double angle)
Sets a new angle in navigational degrees.
Definition: Shape.h:137
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GNEPoly.cpp:226
std::string myImgFile
The angle of the Shape.
Definition: Shape.h:170
The popup menu of a globject.
RGBColor myColor
The color of the Shape.
Definition: Shape.h:161
void setImgFile(const std::string &imgFile)
Sets a new imgFile.
Definition: Shape.h:144
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:138
double myLayer
The layer of the Shape.
Definition: Shape.h:164
void writeXML(OutputDevice &out, bool geo=false)
Definition: SUMOPolygon.cpp:55
SumoXMLTag getTag() const
get XML Tag assigned to this object
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
~GNEPoly()
Destructor.
Definition: GNEPoly.cpp:86
static const RGBColor selectionColor
Definition: GNENet.h:103
void setShapeEditedJunction(GNEJunction *junction)
retrieve the junction of which the shape is being edited
Definition: GNEPoly.cpp:336
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
bool myClosedShape
flag to indicate if polygon is open or closed
Definition: GNEPoly.h:201
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0)
draw Text with given parameters
Definition: GLHelper.cpp:455
Position getPositionInformation() const
Returns the cursor&#39;s x/y position within the network.
void closePolygon()
ensures that the last position equals the first
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
GUISelectedStorage gSelected
A global holder of selected objects.
double getNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:94
A color information.
A window containing a gl-object&#39;s parameter.
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in allGNEAttributeCarrier.
Definition: GNEPoly.cpp:504
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1519
void changeFirstGeometryPoint(int oldIndex, bool allowUndo=true)
change first geometry point
Definition: GNEPoly.cpp:395
static PositionVector parseShapeReporting(const std::string &shpdef, const std::string &objecttype, const char *objectid, bool &ok, bool allowEmpty, bool report=true)
Builds a PositionVector from a string representation, reporting occured errors.
Fill the polygon.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
begin/end of the description of a polygon
void moveEntireShape(const PositionVector &oldShape, const Position &offset)
move entire shape without commiting change
Definition: GNEPoly.cpp:117
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:444