SUMO - Simulation of Urban MObility
GNEPOI.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A class for visualizing and editing POIS in netedit (adapted from
8 // GUIPointOfInterest 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>
46 #include <utils/gui/div/GLHelper.h>
52 #include <netwrite/NWWriter_SUMO.h>
53 #include "GNENet.h"
54 #include "GNEEdge.h"
55 #include "GNEUndoList.h"
56 #include "GNEViewNet.h"
57 #include "GNEChange_Attribute.h"
58 #include "GNEPOI.h"
59 #include "GNELane.h"
60 
61 
62 // ===========================================================================
63 // method definitions
64 // ===========================================================================
65 GNEPOI::GNEPOI(GNENet* net, const std::string& id, const std::string& type, const RGBColor& color,
66  double layer, double angle, const std::string& imgFile, const Position& pos,
67  double width, double height, bool movementBlocked) :
68  GUIPointOfInterest(id, type, color, pos, layer, angle, imgFile, width, height),
69  GNEShape(net, SUMO_TAG_POI, ICON_LOCATEPOI, movementBlocked, false),
70  myLane(NULL),
71  myPositionOverLane(0) {
72 }
73 
74 
76 
77 
79  writeXML(device);
80 }
81 
82 
83 void
84 GNEPOI::moveGeometry(const Position& newPosition) {
85  if (!myBlockMovement) {
86  set(newPosition);
87  myNet->refreshElement(this);
88  }
89 }
90 
91 
92 void
94  if (!myBlockMovement) {
95  undoList->p_begin("position of " + toString(getTag()));
96  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(getPositionInView()), true, toString(oldPos)));
97  undoList->p_end();
98  // Refresh element
99  myNet->refreshPOI(this);
100  }
101 }
102 
103 
104 Position
106  return Position(x(), y());
107 }
108 
109 
110 const std::string&
112  return myNet->getMicrosimID();
113 }
114 
115 
118  return GUIPointOfInterest::getPopUpMenu(app, parent);
119 }
120 
121 
124  return GUIPointOfInterest::getParameterWindow(app, parent);
125 }
126 
127 
128 Boundary
131 }
132 
133 
134 void
137  // draw lock icon
138  drawLockIcon(*this, GLO_POI);
139 }
140 
141 
142 std::string
144  switch (key) {
145  case SUMO_ATTR_ID:
146  return myID;
147  case SUMO_ATTR_COLOR:
148  return toString(myColor);
149  case SUMO_ATTR_LANE:
150  if (myLane) {
151  return myLane->getID();
152  } else {
153  return "";
154  }
155  case SUMO_ATTR_POSITION:
156  if (myLane) {
158  } else {
159  return toString(*this);
160  }
161  case SUMO_ATTR_TYPE:
162  return myType;
163  case SUMO_ATTR_LAYER:
164  return toString(myLayer);
165  case SUMO_ATTR_IMGFILE:
166  return myImgFile;
167  case SUMO_ATTR_WIDTH:
168  return toString(getWidth());
169  case SUMO_ATTR_HEIGHT:
170  return toString(getHeight());
171  case SUMO_ATTR_ANGLE:
172  return toString(getNaviDegree());
174  return toString(myBlockMovement);
175  default:
176  throw InvalidArgument("POI attribute '" + toString(key) + "' not allowed");
177  }
178 }
179 
180 
181 void
182 GNEPOI::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
183  if (value == getAttribute(key)) {
184  return; //avoid needless changes, later logic relies on the fact that attributes have changed
185  }
186  switch (key) {
187  case SUMO_ATTR_ID:
188  case SUMO_ATTR_COLOR:
189  case SUMO_ATTR_LANE:
190  case SUMO_ATTR_POSITION:
191  case SUMO_ATTR_TYPE:
192  case SUMO_ATTR_LAYER:
193  case SUMO_ATTR_IMGFILE:
194  case SUMO_ATTR_WIDTH:
195  case SUMO_ATTR_HEIGHT:
196  case SUMO_ATTR_ANGLE:
198  undoList->p_add(new GNEChange_Attribute(this, key, value));
199  break;
200  default:
201  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
202  }
203 }
204 
205 
206 bool
207 GNEPOI::isValid(SumoXMLAttr key, const std::string& value) {
208  switch (key) {
209  case SUMO_ATTR_ID:
210  return isValidID(value) && (myNet->retrievePOI(value, false) == 0);
211  case SUMO_ATTR_COLOR:
212  return canParse<RGBColor>(value);
213  case SUMO_ATTR_LANE:
214  if (value == "") {
215  return true;
216  } else {
217  return (myNet->retrieveLane(value, false) != NULL);
218  }
219  case SUMO_ATTR_POSITION:
220  if (myLane != NULL) {
221  return canParse<double>(value);
222  } else {
223  bool ok;
224  return GeomConvHelper::parseShapeReporting(value, "user-supplied position", 0, ok, false).size() == 1;
225  }
226  case SUMO_ATTR_TYPE:
227  return true;
228  case SUMO_ATTR_LAYER:
229  return canParse<double>(value);
230  case SUMO_ATTR_IMGFILE:
231  if (value == "") {
232  return true;
233  } else if (isValidFilename(value)) {
234  // check that image can be loaded
235  return GUITexturesHelper::getTextureID(value) != -1;
236  } else {
237  return false;
238  }
239  case SUMO_ATTR_WIDTH:
240  return canParse<double>(value);
241  case SUMO_ATTR_HEIGHT:
242  return canParse<double>(value);
243  case SUMO_ATTR_ANGLE:
244  return canParse<double>(value);
246  return canParse<bool>(value);
247  default:
248  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
249  }
250 }
251 
252 
253 // ===========================================================================
254 // private
255 // ===========================================================================
256 
257 void
258 GNEPOI::setAttribute(SumoXMLAttr key, const std::string& value) {
259  switch (key) {
260  case SUMO_ATTR_ID: {
261  std::string oldID = myID;
262  myID = value;
263  myNet->changePOIID(this, oldID);
264  break;
265  }
266  case SUMO_ATTR_COLOR:
267  myColor = parse<RGBColor>(value);
268  break;
269  case SUMO_ATTR_LANE:
270  myLane = myNet->retrieveLane(value, false);
271  break;
272  case SUMO_ATTR_POSITION:
273  if (myLane) {
274  myPositionOverLane = parse<double>(value);
275  } else {
276  bool ok = true;
277  set(GeomConvHelper::parseShapeReporting(value, "netedit-given", 0, ok, false)[0]);
278  }
279  myNet->refreshPOI(this);
280  break;
281  case SUMO_ATTR_TYPE:
282  myType = value;
283  break;
284  case SUMO_ATTR_LAYER:
285  myLayer = parse<double>(value);
286  break;
287  case SUMO_ATTR_IMGFILE:
288  myImgFile = value;
289  break;
290  case SUMO_ATTR_WIDTH:
291  setWidth(parse<double>(value));
292  break;
293  case SUMO_ATTR_HEIGHT:
294  setHeight(parse<double>(value));
295  break;
296  case SUMO_ATTR_ANGLE:
297  setNaviDegree(parse<double>(value));
298  break;
300  myBlockMovement = parse<bool>(value);
301  break;
302  default:
303  throw InvalidArgument("POI attribute '" + toString(key) + "' not allowed");
304  }
305  // update view after every change
306  myNet->getViewNet()->update();
307 }
308 
309 /****************************************************************************/
void refreshElement(GUIGlObject *o)
refreshes boundary information for o and update
Definition: GNENet.cpp:990
void refreshPOI(GNEPOI *p)
refresh shape in view net
Definition: GNENet.cpp:1995
A layer number.
double x() const
Returns the x-position.
Definition: Position.h:63
Stores the information about how to visualize structures.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
Definition: GNEPOI.cpp:182
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNEPOI.cpp:117
~GNEPOI()
Destructor.
Definition: GNEPOI.cpp:75
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:92
GNEPOI(GNENet *net, const std::string &id, const std::string &type, const RGBColor &color, double layer, double angle, const std::string &imgFile, const Position &pos, double width, double height, bool movementBlocked)
Constructor.
Definition: GNEPOI.cpp:65
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
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEPOI.cpp:135
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
begin/end of the description of a polygon
std::string getAttribute(SumoXMLAttr key) const
method for getting the Attribute of an XML key
Definition: GNEPOI.cpp:143
static bool isValidFilename(const std::string &value)
true if value is a valid file value
GNENet * myNet
the net to inform about updates
Definition: GNEShape.h:156
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string myType
The type of the Shape.
Definition: Shape.h:158
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void moveGeometry(const Position &newPosition)
change the position of the element geometry without saving in undoList
Definition: GNEPOI.cpp:84
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
void writeXML(OutputDevice &out, const bool geo=false, const double zOffset=0., const std::string laneID="", const double pos=0., const double posLat=0.)
void drawLockIcon(const Position &pos, double layer, double size=0.5) const
draw lock icon
Definition: GNEShape.cpp:87
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
void changePOIID(GNEPOI *POI, const std::string &OldID)
change POI ID
Definition: GNENet.cpp:2033
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
Definition: GNEPOI.cpp:93
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspond attribute are valids
Definition: GNEPOI.cpp:207
double myPositionOverLane
position over lane
Definition: GNEPOI.h:164
bool myBlockMovement
flag to block movement
Definition: GNEShape.h:159
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
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:958
GNELane * myLane
lane in which this POI can be placed
Definition: GNEPOI.h:161
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEPOI.cpp:129
const std::string & getParentName() const
Returns the name of the parent object.
Definition: GNEPOI.cpp:111
friend class GNEChange_Attribute
declare friend class
double y() const
Returns the y-position.
Definition: Position.h:68
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
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
double getWidth() const
Returns the image width of the POI.
const std::string getID() const
function to support debugging
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEPOI.cpp:105
std::string myID
The name of the object.
Definition: Named.h:136
void setHeight(double height)
set the image height of the POI
void setWidth(double width)
set the image width of the POI
void setNaviDegree(const double angle)
Sets a new angle in navigational degrees.
Definition: Shape.h:137
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
double myLayer
The layer of the Shape.
Definition: Shape.h:164
void writeShape(OutputDevice &device)
writte shape element into a xml file
Definition: GNEPOI.cpp:78
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
GNEPOI * retrievePOI(const std::string &id, bool failHard=true) const
get POI by id
Definition: GNENet.cpp:2020
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GNEPOI.cpp:123
Position()
default constructor
Definition: Position.h:49
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.
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1519
double getHeight() const
Returns the image height of the POI.
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.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.