SUMO - Simulation of Urban MObility
GNEPOI.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A class for visualizing and editing POIS in netedit (adapted from
18 // GUIPointOfInterest and NLHandler)
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <string>
32 #include <utility>
34 #include <utils/geom/Position.h>
38 #include <utils/xml/XMLSubSys.h>
44 #include <utils/gui/div/GLHelper.h>
50 #include <netwrite/NWWriter_SUMO.h>
51 #include "GNENet.h"
52 #include "GNEEdge.h"
53 #include "GNEUndoList.h"
54 #include "GNEViewNet.h"
55 #include "GNEChange_Attribute.h"
56 #include "GNEPOI.h"
57 #include "GNELane.h"
58 
59 
60 // ===========================================================================
61 // method definitions
62 // ===========================================================================
63 
64 GNEPOI::GNEPOI(GNENet* net, const std::string& id, const std::string& type, const RGBColor& color,
65  const Position& pos, bool geo, double layer, double angle, const std::string& imgFile,
66  double width, double height, bool movementBlocked) :
67  GUIPointOfInterest(id, type, color, pos, geo, "", 0, 0, layer, angle, imgFile, width, height),
68  GNEShape(net, SUMO_TAG_POI, ICON_LOCATEPOI, movementBlocked, false) {
69  // set GEO Position
70  myGEOPosition = pos;
72 }
73 
74 
76 
77 
79  writeXML(device, myGeo);
80 }
81 
82 
83 void
84 GNEPOI::moveGeometry(const Position& oldPos, const Position& offset) {
85  if (!myBlockMovement) {
86  // restore old position, apply offset and refresh element
87  set(oldPos);
88  add(offset);
89  myNet->refreshElement(this);
90  }
91 }
92 
93 
94 void
96  if (!myBlockMovement) {
97  undoList->p_begin("position of " + toString(getTag()));
98  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(getPositionInView()), true, toString(oldPos)));
99  undoList->p_end();
100  }
101 }
102 
103 
104 void
106  // simply refresh element in net
107  myNet->refreshElement(this);
108 }
109 
110 
111 Position
113  return (*this);
114 }
115 
116 
117 GUIGlID
120 }
121 
122 
123 const std::string&
125  return myNet->getMicrosimID();
126 }
127 
128 
131  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
132  // build shape header
133  buildShapePopupOptions(app, ret, myType);
134  // add option for convert to GNEPOI
135  new FXMenuCommand(ret, ("Attach to nearest " + toString(SUMO_TAG_LANE)).c_str(), GUIIconSubSys::getIcon(ICON_LANE), &parent, MID_GNE_POI_TRANSFORM);
136  return ret;
137 }
138 
139 
142  return GUIPointOfInterest::getParameterWindow(app, parent);
143 }
144 
145 
146 Boundary
149 }
150 
151 
152 void
155  // draw a label with the type of POI
156  GLHelper::drawText("POI", *this, myLayer + .1, 0.6, myColor.invertedColor());
157  // draw lock icon
158  drawLockIcon(*this + Position(0, -0.5), GLO_POI, 0.2);
159 }
160 
161 
162 std::string
164  switch (key) {
165  case SUMO_ATTR_ID:
166  return myID;
167  case SUMO_ATTR_COLOR:
168  return toString(myColor);
169  case SUMO_ATTR_POSITION:
170  return toString(*this);
172  return toString(myGEOPosition);
173  case SUMO_ATTR_GEO:
174  return toString(myGeo);
175  case SUMO_ATTR_TYPE:
176  return myType;
177  case SUMO_ATTR_LAYER:
178  return toString(myLayer);
179  case SUMO_ATTR_IMGFILE:
180  return myImgFile;
181  case SUMO_ATTR_WIDTH:
182  return toString(getWidth());
183  case SUMO_ATTR_HEIGHT:
184  return toString(getHeight());
185  case SUMO_ATTR_ANGLE:
186  return toString(getNaviDegree());
188  return toString(myBlockMovement);
189  default:
190  throw InvalidArgument(toString(getTag()) + " attribute '" + toString(key) + "' not allowed");
191  }
192 }
193 
194 
195 void
196 GNEPOI::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
197  if (value == getAttribute(key)) {
198  return; //avoid needless changes, later logic relies on the fact that attributes have changed
199  }
200  switch (key) {
201  case SUMO_ATTR_ID:
202  case SUMO_ATTR_COLOR:
203  case SUMO_ATTR_POSITION:
205  case SUMO_ATTR_GEO:
206  case SUMO_ATTR_TYPE:
207  case SUMO_ATTR_LAYER:
208  case SUMO_ATTR_IMGFILE:
209  case SUMO_ATTR_WIDTH:
210  case SUMO_ATTR_HEIGHT:
211  case SUMO_ATTR_ANGLE:
213  undoList->p_add(new GNEChange_Attribute(this, key, value));
214  break;
215  default:
216  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
217  }
218 }
219 
220 
221 bool
222 GNEPOI::isValid(SumoXMLAttr key, const std::string& value) {
223  switch (key) {
224  case SUMO_ATTR_ID:
225  return isValidID(value) && (myNet->retrievePOI(value, false) == 0);
226  case SUMO_ATTR_COLOR:
227  return canParse<RGBColor>(value);
228  case SUMO_ATTR_POSITION: {
229  bool ok;
230  return GeomConvHelper::parseShapeReporting(value, "user-supplied position", 0, ok, false).size() == 1;
231  }
232  case SUMO_ATTR_GEOPOSITION: {
233  bool ok;
234  return GeomConvHelper::parseShapeReporting(value, "user-supplied GEO position", 0, ok, false).size() == 1;
235  }
236  case SUMO_ATTR_GEO:
237  return canParse<bool>(value);
238  case SUMO_ATTR_TYPE:
239  return true;
240  case SUMO_ATTR_LAYER:
241  return canParse<double>(value);
242  case SUMO_ATTR_IMGFILE:
243  if (value == "") {
244  return true;
245  } else if (isValidFilename(value)) {
246  // check that image can be loaded
247  return GUITexturesHelper::getTextureID(value) != -1;
248  } else {
249  return false;
250  }
251  case SUMO_ATTR_WIDTH:
252  return canParse<double>(value);
253  case SUMO_ATTR_HEIGHT:
254  return canParse<double>(value);
255  case SUMO_ATTR_ANGLE:
256  return canParse<double>(value);
258  return canParse<bool>(value);
259  default:
260  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
261  }
262 }
263 
264 
265 // ===========================================================================
266 // private
267 // ===========================================================================
268 
269 void
270 GNEPOI::setAttribute(SumoXMLAttr key, const std::string& value) {
271  switch (key) {
272  case SUMO_ATTR_ID: {
273  std::string oldID = myID;
274  myID = value;
275  myNet->changeShapeID(this, oldID);
276  break;
277  }
278  case SUMO_ATTR_COLOR:
279  myColor = parse<RGBColor>(value);
280  break;
281  case SUMO_ATTR_POSITION: {
282  bool ok = true;
283  set(GeomConvHelper::parseShapeReporting(value, "netedit-given", 0, ok, false)[0]);
284  // set GEO Position
285  myGEOPosition = *this;
287  break;
288  }
289  case SUMO_ATTR_GEOPOSITION: {
290  bool ok = true;
291  myGEOPosition = GeomConvHelper::parseShapeReporting(value, "netedit-given", 0, ok, false)[0];
292  // set cartesian Position
293  set(myGEOPosition);
295  break;
296  }
297  case SUMO_ATTR_GEO:
298  myGeo = parse<bool>(value);
299  break;
300  case SUMO_ATTR_TYPE:
301  myType = value;
302  break;
303  case SUMO_ATTR_LAYER:
304  myLayer = parse<double>(value);
305  break;
306  case SUMO_ATTR_IMGFILE:
307  myImgFile = value;
308  break;
309  case SUMO_ATTR_WIDTH:
310  setWidth(parse<double>(value));
311  break;
312  case SUMO_ATTR_HEIGHT:
313  setHeight(parse<double>(value));
314  break;
315  case SUMO_ATTR_ANGLE:
316  setNaviDegree(parse<double>(value));
317  break;
319  myBlockMovement = parse<bool>(value);
320  break;
321  default:
322  throw InvalidArgument(toString(getTag()) + " attribute '" + toString(key) + "' not allowed");
323  }
324  // Update geometry after every change
325  updateGeometry();
326 }
327 
328 /****************************************************************************/
GNEPOI(GNENet *net, const std::string &id, const std::string &type, const RGBColor &color, const Position &pos, bool geo, double layer, double angle, const std::string &imgFile, double width, double height, bool movementBlocked)
Constructor.
Definition: GNEPOI.cpp:64
Transform POI to POILane, and viceversa.
Definition: GUIAppEnum.h:761
const std::string & getParentName() const
Returns the name of the parent object.
Definition: GNEPOI.cpp:124
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEPOI.cpp:112
void buildShapePopupOptions(GUIMainWindow &app, GUIGLObjectPopupMenu *ret, const std::string &type)
build basic shape popup options. Used to unify pop-ups menu in netedit and SUMO-GUI ...
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEPOI.cpp:84
begin/end of the description of a single lane
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:132
void refreshElement(GUIGlObject *o)
refreshes boundary information for o and update
Definition: GNENet.cpp:1082
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEPOI.cpp:153
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GNEPOI.cpp:118
A layer number.
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:196
GNEPOI * retrievePOI(const std::string &id, bool failHard=true) const
get POI by id
Definition: GNENet.cpp:948
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, int align=0, double width=-1)
Definition: GLHelper.cpp:487
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNEPOI.cpp:130
~GNEPOI()
Destructor.
Definition: GNEPOI.cpp:75
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:91
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:84
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
begin/end of the description of a Point of interest
double getHeight() const
Returns the image height of the POI.
RGBColor invertedColor() const
obtain inverted of current RGBColor
Definition: RGBColor.cpp:145
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:157
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:47
std::string myType
The type of the Shape.
Definition: Shape.h:157
void drawLockIcon(const Position &pos, double layer, double size=0.5) const
draw lock icon
Definition: GNEShape.cpp:74
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
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.)
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
Definition: GNEPOI.cpp:95
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
double getNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:93
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspond attribute are valids
Definition: GNEPOI.cpp:222
bool myBlockMovement
flag to block movement
Definition: GNEShape.h:160
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:91
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
friend class GNEChange_Attribute
declare friend class
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEPOI.cpp:147
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
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void changeShapeID(GNEShape *s, const std::string &OldID)
change Shape ID
Definition: GNENet.cpp:1964
double getWidth() const
Returns the image width of the POI.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
unsigned int GUIGlID
Definition: GUIGlObject.h:49
std::string myID
The name of the object.
Definition: Named.h:126
Position myGEOPosition
Position of POI in GEO coordinates.
Definition: GNEPOI.h:162
void setHeight(double height)
set the image height of the POI
void updateGeometry()
update pre-computed geometry information
Definition: GNEPOI.cpp:105
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:136
std::string myImgFile
The angle of the Shape.
Definition: Shape.h:169
The popup menu of a globject.
RGBColor myColor
The color of the Shape.
Definition: Shape.h:160
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
std::string getAttribute(SumoXMLAttr key) const
method for getting the Attribute of an XML key
Definition: GNEPOI.cpp:163
double myLayer
The layer of the Shape.
Definition: Shape.h:163
GUIGlID getGlID() const
Returns the numerical id of the object.
void writeShape(OutputDevice &device)
writte shape element into a xml file
Definition: GNEPOI.cpp:78
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation. ...
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GNEPOI.cpp:141
bool myGeo
flag to check if POI was loaded as GEO Position (main used by netedit)
Position()
default constructor
Definition: Position.h:48
A color information.
A window containing a gl-object&#39;s parameter.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
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.
SumoXMLTag getTag() const
get XML Tag assigned to this object