SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GNEAdditional.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <string>
31 #include <iostream>
32 #include <utility>
37 #include <utils/common/ToString.h>
38 #include <utils/geom/GeomHelper.h>
46 #include <utils/gui/div/GLHelper.h>
50 
51 #include "GNEAdditional.h"
52 #include "GNELane.h"
53 #include "GNEEdge.h"
54 #include "GNENet.h"
55 #include "GNEUndoList.h"
56 #include "GNEViewNet.h"
57 
58 #ifdef CHECK_MEMORY_LEAKS
59 #include <foreign/nvwa/debug_new.h>
60 #endif
61 
62 
63 // ===========================================================================
64 // member method definitions
65 // ===========================================================================
66 
67 GNEAdditional::GNEAdditional(const std::string& id, GNEViewNet* viewNet, Position pos, SumoXMLTag tag, GNEAdditionalSet* additionalSetParent, bool blocked) :
70  myViewNet(viewNet),
71  myEdge(NULL),
72  myLane(NULL),
73  myPosition(pos),
74  myAdditionalSetParent(additionalSetParent),
75  myBlockIconRotation(0),
76  myBlocked(blocked),
77  myInspectionable(true),
78  mySelectable(true),
79  myMovable(true),
80  myBaseColor(RGBColor::GREEN),
81  myBaseColorSelected(RGBColor::BLUE),
82  myAdditionalDialog(NULL) {
83  // Set rotation left hand
85  // If this additional belongs to a set, add it.
88  }
89 }
90 
91 
93  // If this additional belongs to a set, remove it.
96  }
97 }
98 
99 
100 void
102  moveAdditionalGeometry(offset.x(), offset.y());
103 }
104 
105 
106 void
108  commmitAdditionalGeometryMoved(oldPos.x(), oldPos.y(), undoList);
109  // Refresh element
111 }
112 
113 
114 void
116 
117 
118 const std::string&
120  return getMicrosimID();
121 }
122 
123 
124 GNEViewNet*
126  return myViewNet;
127 }
128 
129 
132  return myShape;
133 }
134 
135 
136 bool
138  return myBlocked;
139 }
140 
141 
142 bool
144  return myInspectionable;
145 }
146 
147 
148 bool
150  return mySelectable;
151 }
152 
153 
154 bool
156  return myMovable;
157 }
158 
159 
160 bool
162  return gSelected.isSelected(getType(), getGlID());
163 }
164 
165 
168  return myAdditionalSetParent;
169 }
170 
171 
172 void
173 GNEAdditional::setAdditionalID(const std::string& id) {
174  // Save old ID
175  std::string oldID = getMicrosimID();
176  // set New ID
177  setMicrosimID(id);
178  // update additional ID in the container of net
179  myViewNet->getNet()->updateAdditionalID(oldID, this);
180 }
181 
182 void
184  myPosition = pos;
185 }
186 
187 
188 GNEEdge*
190  return myEdge;
191 }
192 
193 
194 GNELane*
196  return myLane;
197 }
198 
199 const std::string&
201  return myViewNet->getNet()->getMicrosimID();
202 }
203 
204 
207  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
208  // build header
209  buildPopupHeader(ret, app);
210  // build menu command for center button
212  // buld menu commands for names
213  new FXMenuCommand(ret, ("Copy " + toString(getTag()) + " name to clipboard").c_str(), 0, ret, MID_COPY_NAME);
214  new FXMenuCommand(ret, ("Copy " + toString(getTag()) + " typed name to clipboard").c_str(), 0, ret, MID_COPY_TYPED_NAME);
215  // build menu command selection
217  // build menu command copy cursor position to clipboard
218  buildPositionCopyEntry(ret, false);
219  buildShowParamsPopupEntry(ret, false);
220  // get attributes
221  std::vector<SumoXMLAttr> attributes = getAttrs();
222  // Show position parameters
223  if (std::find(attributes.begin(), attributes.end(), SUMO_ATTR_LANE) != attributes.end()) {
224  // If additional own an lane as attribute, get lane
225  GNELane* lane = myViewNet->getNet()->retrieveLane(getParentName(), false);
226  if (lane) {
227  // Show menu command inner position
229  new FXMenuCommand(ret, ("inner position: " + toString(innerPos)).c_str(), 0, 0, 0);
230  // If shape isn't empty, show menu command lane position
231  if (myShape.size() > 0) {
232  const SUMOReal lanePos = lane->getShape().nearest_offset_to_point2D(myShape[0]);
233  new FXMenuCommand(ret, ("lane position: " + toString(innerPos + lanePos)).c_str(), 0, 0, 0);
234  }
235  } else {
236  throw InvalidArgument("Additional with id = '" + getMicrosimID() + "' don't have their lane as a ParentName()");
237  }
238  } else if (std::find(attributes.begin(), attributes.end(), SUMO_ATTR_EDGE) != attributes.end()) {
239  // If additional own an edge as attribute, get lane
240  GNEEdge* edge = myViewNet->getNet()->retrieveEdge(getParentName(), false);
241  if (edge) {
242  // Show menu command inner position
244  new FXMenuCommand(ret, ("inner position: " + toString(innerPos)).c_str(), 0, 0, 0);
245  // If shape isn't empty, show menu command edge position
246  if (myShape.size() > 0) {
247  const SUMOReal edgePos = edge->getLanes().at(0)->getShape().nearest_offset_to_point2D(myShape[0]);
248  new FXMenuCommand(ret, ("edge position: " + toString(innerPos + edgePos)).c_str(), 0, 0, 0);
249  }
250  } else {
251  throw InvalidArgument("Additional with id = '" + getMicrosimID() + "' don't have their edge as a ParentName()");
252  }
253  } else {
254  new FXMenuCommand(ret, ("position in view: " + toString(myPosition.x()) + "," + toString(myPosition.y())).c_str(), 0, 0, 0);
255  }
256  // Show childs if this is is an additionalSet
257  GNEAdditionalSet* additionalSet = dynamic_cast<GNEAdditionalSet*>(this);
258  if (additionalSet) {
259  new FXMenuSeparator(ret);
260  if (additionalSet->getNumberOfAdditionalChilds() > 0) {
261  new FXMenuCommand(ret, ("number of additional childs: " + toString(additionalSet->getNumberOfAdditionalChilds())).c_str(), 0, 0, 0);
262  } else if (additionalSet->getNumberOfEdgeChilds() > 0) {
263  new FXMenuCommand(ret, ("number of edge childs: " + toString(additionalSet->getNumberOfEdgeChilds())).c_str(), 0, 0, 0);
264  } else if (additionalSet->getNumberOfLaneChilds() > 0) {
265  new FXMenuCommand(ret, ("number of lane childs: " + toString(additionalSet->getNumberOfLaneChilds())).c_str(), 0, 0, 0);
266  }
267  }
268  new FXMenuSeparator(ret);
269  // let the GNEViewNet store the popup position
270  dynamic_cast<GNEViewNet&>(parent).markPopupPosition();
271  return ret;
272 }
273 
274 
277  // Ignore Warning
278  UNUSED_PARAMETER(parent);
279  // get attributes
280  std::vector<SumoXMLAttr> attributes = getAttrs();
281  // Create tanñe
282  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, (int)attributes.size());
283  // Iterate over attributes
284  for (std::vector<SumoXMLAttr>::iterator i = attributes.begin(); i != attributes.end(); i++) {
285  // Add attribute and set it dynamic if aren't unique
287  ret->mkItem(toString(*i).c_str(), false, getAttribute(*i));
288  } else {
289  ret->mkItem(toString(*i).c_str(), true, getAttribute(*i));
290  }
291  }
293  // close building
294  ret->closeBuilding();
295  return ret;
296 }
297 
298 
299 Boundary
302  b.grow(20);
303  return b;
304 }
305 
306 
307 void
309  if (myShape.size() > 0 && myShape.length() != 0) {
310  // If lenght of the shape is distint to 0, Obtain rotation of center of shape
312  } else if (lane != NULL) {
313  // If additional is over a lane, set rotation in the position over lane
315  } else {
316  // In other case, rotation is 0
318  }
319 }
320 
321 
322 void
324  if (myViewNet->showLockIcon()) {
325  // Start pushing matrix
326  glPushMatrix();
327  // Traslate to middle of shape
328  glTranslated(myBlockIconPosition.x(), myBlockIconPosition.y(), getType() + 0.1);
329  // Set draw color
330  glColor3d(1, 1, 1);
331  // Rotate depending of myBlockIconRotation
332  glRotated(myBlockIconRotation, 0, 0, -1);
333  // Rotate 180º
334  glRotated(180, 0, 0, 1);
335  // Traslate depending of the offset
336  glTranslated(myBlockIconOffset.x(), myBlockIconOffset.y(), 0);
337  // Draw icon depending of the state of additional
338  if (isAdditionalSelected()) {
339  if (myMovable == false) {
340  // Draw not movable texture if additional isn't movable and is selected
342  } else if (myBlocked) {
343  // Draw lock texture if additional is movable, is blocked and is selected
345  } else {
346  // Draw empty texture if additional is movable, isn't blocked and is selected
348  }
349  } else {
350  if (myMovable == false) {
351  // Draw not movable texture if additional isn't movable
353  } else if (myBlocked) {
354  // Draw lock texture if additional is movable and is blocked
356  } else {
357  // Draw empty texture if additional is movable and isn't blocked
359  }
360  }
361  // Pop matrix
362  glPopMatrix();
363  }
364 }
365 
366 
367 void
368 GNEAdditional::changeEdge(const std::string& edgeID) {
369  if (myEdge == NULL) {
370  throw InvalidArgument("Additional with id = '" + getMicrosimID() + "' doesn't belong to a edge");
371  } else {
373  myEdge = getViewNet()->getNet()->retrieveEdge(edgeID);
374  myEdge->addAdditionalChild(this);
375  updateGeometry();
376  getViewNet()->update();
377  }
378 }
379 
380 
381 void
382 GNEAdditional::changeLane(const std::string& laneID) {
383  if (myLane == NULL) {
384  throw InvalidArgument("Additional with id = '" + getMicrosimID() + "' doesn't belong to a lane");
385  } else {
387  myLane = getViewNet()->getNet()->retrieveLane(laneID);
388  myLane->addAdditionalChild(this);
389  updateGeometry();
390  getViewNet()->update();
391  }
392 }
393 
394 /****************************************************************************/
virtual void openAdditionalDialog()
open Additional Dialog
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
bool showLockIcon() const
check if lock icon should be visible
Definition: GNEViewNet.cpp:930
SumoXMLTag
Numbers representing SUMO-XML - element names.
GNEAdditionalSet * getAdditionalSetParent() const
get additionalSet parent, or NULL if don't belongs to an additionalSet
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:702
int getNumberOfAdditionalChilds() const
get number of additional childs of this additionalSet
SUMOReal nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
std::vector< SumoXMLAttr > getAttrs() const
get vector of attributes
PositionVector getShape() const
Returns additional element's shape.
GNELane * myLane
The lane this additional belongs NULL if additional doesnt' belongs to a lane.
bool myRotationLefthand
rotation depending of the option "Lefthand"
virtual const std::string & getParentName() const =0
Returns the name of the parent object (if any)
void removeAdditionalChild(GNEAdditional *additional)
remove additional child to this lane
Definition: GNELane.cpp:717
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
bool isAdditionalSelected() const
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:55
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:233
void commmitAdditionalGeometryMoved(const Position &oldPos, GNEUndoList *undoList)
updated geometry changes in the attributes of additional
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
An Element wich group additionalSet elements.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used, also builds an entry for copying the geo-position.
GUIGlID getGlID() const
Returns the numerical id of the object.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
virtual std::string getAttribute(SumoXMLAttr key) const =0
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void addAdditionalChild(GNEAdditional *additional)
add additional child to this edge
Definition: GNEEdge.cpp:926
void updateAdditionalID(const std::string &oldID, GNEAdditional *additional)
update additional ID in container
Definition: GNENet.cpp:1239
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
void changeEdge(const std::string &edgeID)
change edge of additional
GNEEdge * getEdge() const
get edge of additional, or NULL if additional isn't placed over an edge
SUMOReal myBlockIconRotation
The rotation of the block icon.
GNELane * getLane() const
get lane of additional, or NULL if additional isn't placed over a Lane
bool myMovable
boolean to check if additional element is movable (with the mouse). By default true ...
const std::string & getAdditionalID() const
returns the ID of additional
GNEAdditional(const std::string &id, GNEViewNet *viewNet, Position pos, SumoXMLTag tag, GNEAdditionalSet *additionalSetParent=NULL, bool blocked=false)
Constructor.
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:784
Copy object name - popup entry.
Definition: GUIAppEnum.h:231
SUMOReal getPositionRelativeToParametricLenght(SUMOReal position) const
Definition: GNELane.cpp:693
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
void addAdditionalChild(GNEAdditional *additional)
add additional child to this lane
Definition: GNELane.cpp:705
bool removeAdditionalGeometryChild(GNEAdditional *additional)
remove additional element to this set
A list of positions.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:744
void setBlockIconRotation(GNELane *lane=NULL)
bool addAdditionalChild(GNEAdditional *additional)
add additional element to this set
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
void drawLockIcon(SUMOReal size=0.5) const
draw lock icon
void setAdditionalID(const std::string &id)
set the ID of additional
~GNEAdditional()
Destructor.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
void changeLane(const std::string &laneID)
change lane of additional
Position myBlockIconOffset
The offSet of the block icon.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:55
compound additional
SUMOReal length() const
Returns the length.
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:232
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:583
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:485
void moveAdditionalGeometry(const Position &offset)
change the position of the additional geometry
int getNumberOfEdgeChilds() const
get number of edge childs of this additionalSet
GNEAdditionalSet * myAdditionalSetParent
pointer to additional set parent, if belong to set
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
int getNumberOfLaneChilds() const
get number of lane childs of this additionalSet
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
The popup menu of a globject.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:912
bool isAdditionalBlocked() const
Check if additional item is currently blocked (i.e. cannot be moved with mouse)
bool mySelectable
boolean to check if additional element is selectable (With GNESelectorFrame). By default true ...
SumoXMLTag getTag() const
get Tag assigned to this object
Position myPosition
The position in which this additional element is located.
#define SUMOReal
Definition: config.h:214
void setPositionInView(const Position &pos)
set new position in the view
static bool isUnique(SumoXMLAttr attr)
whether an attribute is unique (may not be edited for a multi-selection)
virtual void updateGeometry()=0
update pre-computed geometry information
void removeAdditionalChild(GNEAdditional *additional)
remove additional child from this edge
Definition: GNEEdge.cpp:938
bool myInspectionable
boolean to check if additional element is inspectionable (With GNEInspectorFrame). By default true
bool isAdditionalSelectable() const
check if additional element is selectable (With GNESelectorFrame)
Position getPositionInformation() const
Returns the cursor's x/y position within the network.
bool isAdditionalInspectionable() const
check if additional element is inspectionable (With GNEInspectorFrame)
GNEEdge * myEdge
The edge this additional belongs NULL if additional doesnt' belongs to a edge.
static GUIGlID getGif(GUITexture which)
returns a texture Gif previously defined in the enum GUITexture
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
GUISelectedStorage gSelected
A global holder of selected objects.
void closeBuilding()
Closes the building of the table.
A window containing a gl-object's parameter.
static void drawTexturedBox(int which, SUMOReal size)
Draws a named texture as a box with the given size.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
Position myBlockIconPosition
position of the block icon
bool isAdditionalMovable() const
check if additional element is movable