SUMO - Simulation of Urban MObility
GNEPOILane.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 "GNEPOILane.h"
57 #include "GNELane.h"
58 
59 
60 // ===========================================================================
61 // method definitions
62 // ===========================================================================
63 
64 GNEPOILane::GNEPOILane(GNENet* net, const std::string& id, const std::string& type, const RGBColor& color,
65  double layer, double angle, const std::string& imgFile, GNELane* lane, double posOverLane, double posLat,
66  double width, double height, bool movementBlocked) :
67  GUIPointOfInterest(id, type, color, Position(), false, lane->getID(), posOverLane / lane->getLaneParametricLength(), posLat, layer, angle, imgFile, width, height),
68  GNEShape(net, SUMO_TAG_POILANE, ICON_LOCATEPOI, movementBlocked, false),
69  myGNELane(lane) {
70 }
71 
72 
74 
75 
76 void
78  // obtain fixed position over lane
79  double fixedPositionOverLane = myPosOverLane > 1 ? 1 : myPosOverLane < 0 ? 0 : myPosOverLane;
80  // write POILane using POI::writeXML
81  writeXML(device, false, 0, myGNELane->getID(), fixedPositionOverLane * myGNELane->getShape().length(), myPosLat);
82 }
83 
84 
85 void
86 GNEPOILane::moveGeometry(const Position& oldPos, const Position& offset) {
87  // Calculate new position using old position
88  Position newPosition = oldPos;
89  newPosition.add(offset);
91  // Update geometry
93 }
94 
95 
96 void
98  if (!myBlockMovement) {
99  // restore old position before commit new position
100  double originalPosOverLane = myGNELane->getShape().nearest_offset_to_point2D(oldPos, false);
101  undoList->p_begin("position of " + toString(getTag()));
102  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(myPosOverLane * myGNELane->getLaneParametricLength()), true, toString(originalPosOverLane)));
103  undoList->p_end();
104  }
105 }
106 
107 
108 GNELane*
110  return myGNELane;
111 }
112 
113 
114 void
116  // obtain fixed position over lane
117  double fixedPositionOverLane = myPosOverLane > 1 ? 1 : myPosOverLane < 0 ? 0 : myPosOverLane;
118  // set new position regarding to lane
119  set(myGNELane->getShape().positionAtOffset(fixedPositionOverLane * myGNELane->getLaneShapeLength(), myPosLat));
120  // refresh element to avoid grabbings problem
121  myNet->refreshElement(this);
122 }
123 
124 
125 Position
127  return Position(x(), y());
128 }
129 
130 
131 GUIGlID
134 }
135 
136 
137 const std::string&
139  return myNet->getMicrosimID();
140 }
141 
142 
145  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
146  // build shape header
147  buildShapePopupOptions(app, ret, myType);
148  // add option for convert to GNEPOI
149  new FXMenuCommand(ret, ("Release from " + toString(SUMO_TAG_LANE)).c_str(), GUIIconSubSys::getIcon(ICON_LANE), &parent, MID_GNE_POI_TRANSFORM);
150  return ret;
151 }
152 
153 
156  return GUIPointOfInterest::getParameterWindow(app, parent);
157 }
158 
159 
160 Boundary
163 }
164 
165 
166 void
169  // draw a label with the type of POI
170  GLHelper::drawText("POI Lane", *this, myLayer + .1, 0.6, myColor.invertedColor());
171  // draw lock icon
172  drawLockIcon(*this + Position(0, -0.5), GLO_POI, 0.2);
173 }
174 
175 
176 std::string
178  switch (key) {
179  case SUMO_ATTR_ID:
180  return myID;
181  case SUMO_ATTR_COLOR:
182  return toString(myColor);
183  case SUMO_ATTR_LANE:
184  return myLane;
185  case SUMO_ATTR_POSITION:
188  return toString(myPosLat);
189  case SUMO_ATTR_TYPE:
190  return myType;
191  case SUMO_ATTR_LAYER:
192  return toString(myLayer);
193  case SUMO_ATTR_IMGFILE:
194  return myImgFile;
195  case SUMO_ATTR_WIDTH:
196  return toString(getWidth());
197  case SUMO_ATTR_HEIGHT:
198  return toString(getHeight());
199  case SUMO_ATTR_ANGLE:
200  return toString(getNaviDegree());
202  return toString(myBlockMovement);
203  default:
204  throw InvalidArgument(toString(getTag()) + " attribute '" + toString(key) + "' not allowed");
205  }
206 }
207 
208 
209 void
210 GNEPOILane::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
211  if (value == getAttribute(key)) {
212  return; //avoid needless changes, later logic relies on the fact that attributes have changed
213  }
214  switch (key) {
215  case SUMO_ATTR_ID:
216  case SUMO_ATTR_COLOR:
217  case SUMO_ATTR_LANE:
218  case SUMO_ATTR_POSITION:
220  case SUMO_ATTR_TYPE:
221  case SUMO_ATTR_LAYER:
222  case SUMO_ATTR_IMGFILE:
223  case SUMO_ATTR_WIDTH:
224  case SUMO_ATTR_HEIGHT:
225  case SUMO_ATTR_ANGLE:
227  undoList->p_add(new GNEChange_Attribute(this, key, value));
228  break;
229  default:
230  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
231  }
232 }
233 
234 
235 bool
236 GNEPOILane::isValid(SumoXMLAttr key, const std::string& value) {
237  switch (key) {
238  case SUMO_ATTR_ID:
239  return isValidID(value) && (myNet->retrievePOI(value, false) == 0);
240  case SUMO_ATTR_COLOR:
241  return canParse<RGBColor>(value);
242  case SUMO_ATTR_LANE:
243  return (myNet->retrieveLane(value, false) != NULL);
244  case SUMO_ATTR_POSITION:
245  return canParse<double>(value);
247  return canParse<double>(value);
248  case SUMO_ATTR_TYPE:
249  return true;
250  case SUMO_ATTR_LAYER:
251  return canParse<double>(value);
252  case SUMO_ATTR_IMGFILE:
253  if (value == "") {
254  return true;
255  } else if (isValidFilename(value)) {
256  // check that image can be loaded
257  return GUITexturesHelper::getTextureID(value) != -1;
258  } else {
259  return false;
260  }
261  case SUMO_ATTR_WIDTH:
262  return canParse<double>(value);
263  case SUMO_ATTR_HEIGHT:
264  return canParse<double>(value);
265  case SUMO_ATTR_ANGLE:
266  return canParse<double>(value);
268  return canParse<bool>(value);
269  default:
270  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
271  }
272 }
273 
274 // ===========================================================================
275 // private
276 // ===========================================================================
277 
278 void
279 GNEPOILane::setAttribute(SumoXMLAttr key, const std::string& value) {
280  switch (key) {
281  case SUMO_ATTR_ID: {
282  std::string oldID = myID;
283  myID = value;
284  myNet->changeShapeID(this, oldID);
285  break;
286  }
287  case SUMO_ATTR_COLOR:
288  myColor = parse<RGBColor>(value);
289  break;
290  case SUMO_ATTR_LANE:
291  myLane = value;
293  myGNELane = myNet->retrieveLane(value);
294  myGNELane->addShapeChild(this);
295  updateGeometry();
296  break;
297  case SUMO_ATTR_POSITION:
298  myPosOverLane = parse<double>(value) / myGNELane->getLaneParametricLength();
299  break;
301  myPosLat = parse<double>(value);
302  break;
303  case SUMO_ATTR_TYPE:
304  myType = value;
305  break;
306  case SUMO_ATTR_LAYER:
307  myLayer = parse<double>(value);
308  break;
309  case SUMO_ATTR_IMGFILE:
310  myImgFile = value;
311  break;
312  case SUMO_ATTR_WIDTH:
313  setWidth(parse<double>(value));
314  break;
315  case SUMO_ATTR_HEIGHT:
316  setHeight(parse<double>(value));
317  break;
318  case SUMO_ATTR_ANGLE:
319  setNaviDegree(parse<double>(value));
320  break;
322  myBlockMovement = parse<bool>(value);
323  break;
324  default:
325  throw InvalidArgument(toString(getTag()) + " attribute '" + toString(key) + "' not allowed");
326  }
327  // update Geometry after every change
328  updateGeometry();
329 }
330 
331 /****************************************************************************/
Transform POI to POILane, and viceversa.
Definition: GUIAppEnum.h:761
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GNEPOILane.cpp:132
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 writeShape(OutputDevice &device)
writte shape element into a xml file
Definition: GNEPOILane.cpp:77
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GNEPOILane.cpp:155
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
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEPOILane.cpp:161
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEPOILane.cpp:167
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
Definition: GNEPOILane.cpp:97
A layer number.
double myPosOverLane
position over lane in which this POI is placed (main used by netedit)
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:67
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspond attribute are valids
Definition: GNEPOILane.cpp:236
GNEPOI * retrievePOI(const std::string &id, bool failHard=true) const
get POI by id
Definition: GNENet.cpp:948
double x() const
Returns the x-position.
Definition: Position.h:62
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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:91
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:53
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.
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
double myPosLat
latereal position over lane in which this POI is placed (main used by netedit)
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
std::string myLane
ID of lane in which this POI is placed (main used by netedit)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
Definition: GNEPOILane.cpp:210
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:701
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEPOILane.cpp:86
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 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
void addShapeChild(GNEShape *shape)
add shape child to this lane
Definition: GNELane.cpp:718
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
GNELane * getLane() const
get GNELane
Definition: GNEPOILane.cpp:109
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
const std::string getID() const
function to support debugging
void changeShapeID(GNEShape *s, const std::string &OldID)
change Shape ID
Definition: GNENet.cpp:1964
double getLaneShapeLength() const
returns the length of the lane&#39;s shape
Definition: GNELane.cpp:712
double getWidth() const
Returns the image width of the POI.
const std::string & getParentName() const
Returns the name of the parent object.
Definition: GNEPOILane.cpp:138
GNELane * myGNELane
GNElane in which this POILane is placed.
Definition: GNEPOILane.h:171
std::string getAttribute(SumoXMLAttr key) const
method for getting the Attribute of an XML key
Definition: GNEPOILane.cpp:177
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:135
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:599
double length() const
Returns the length.
void setHeight(double height)
set the image height of the POI
void updateGeometry()
update pre-computed geometry information
Definition: GNEPOILane.cpp:115
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
~GNEPOILane()
Destructor.
Definition: GNEPOILane.cpp:73
double myLayer
The layer of the Shape.
Definition: Shape.h:163
GUIGlID getGlID() const
Returns the numerical id of the object.
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEPOILane.cpp:126
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
void removeShapeChild(GNEShape *shape)
remove shape child of this lane
Definition: GNELane.cpp:731
begin/end of the description of a Point of interest over Lane (used by Netedit)
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNEPOILane.cpp:144
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
Position()
default constructor
Definition: Position.h:48
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1000
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
GNEPOILane(GNENet *net, const std::string &id, const std::string &type, const RGBColor &color, double layer, double angle, const std::string &imgFile, GNELane *lane, double posOverLane, double posLat, double width, double height, bool movementBlocked)
Constructor.
Definition: GNEPOILane.cpp:64
SumoXMLTag getTag() const
get XML Tag assigned to this object