SUMO - Simulation of Urban MObility
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  myPosition(pos),
72  myAdditionalSetParent(additionalSetParent),
73  myBlocked(blocked),
74  myInspectionable(true),
75  mySelectable(true),
76  myMovable(true),
77  myBlockIconRotation(0),
78  myBaseColor(RGBColor::GREEN),
79  myBaseColorSelected(RGBColor::BLUE),
80  myAdditionalDialog(NULL) {
81  // Set rotation left hand
83  // If this additional belongs to a set, add it.
86  }
87 }
88 
89 
91  // If this additional belongs to a set, remove it.
94  }
95 }
96 
97 
98 void
100 
101 
102 const std::string&
104  return getMicrosimID();
105 }
106 
107 
108 GNEViewNet*
110  return myViewNet;
111 }
112 
113 
116  return myShape;
117 }
118 
119 
120 bool
122  return myBlocked;
123 }
124 
125 
126 bool
128  return myInspectionable;
129 }
130 
131 
132 bool
134  return mySelectable;
135 }
136 
137 
138 bool
140  return myMovable;
141 }
142 
143 
144 bool
146  return gSelected.isSelected(getType(), getGlID());
147 }
148 
149 
152  return myAdditionalSetParent;
153 }
154 
155 
156 void
157 GNEAdditional::setAdditionalID(const std::string& id) {
158  // Save old ID
159  std::string oldID = getMicrosimID();
160  // set New ID
161  setMicrosimID(id);
162  // update additional ID in the container of net
163  myViewNet->getNet()->updateAdditionalID(oldID, this);
164 }
165 
166 
167 void
169  myBlocked = value;
170 }
171 
172 
173 void
175  myPosition = pos;
176 }
177 
178 
179 GNEEdge*
181  return NULL;
182 }
183 
184 
185 GNELane*
187  return NULL;
188 }
189 
190 
191 void
193  throw InvalidArgument("Calling virtual function removeEdgeReference() of class GNEAdditional. Implement removeEdgeReference() in additional child to avoid this exception");
194 }
195 
196 
197 void
199  throw InvalidArgument("Calling virtual function removeLaneReference() of class GNEAdditional. Implement removeLaneReference() in additional child to avoid this exception");
200 }
201 
202 
203 const std::string&
205  return myViewNet->getNet()->getMicrosimID();
206 }
207 
208 
211  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
212  // build header
213  buildPopupHeader(ret, app);
214  // build menu command for center button
216  // buld menu commands for names
217  new FXMenuCommand(ret, ("Copy " + toString(getTag()) + " name to clipboard").c_str(), 0, ret, MID_COPY_NAME);
218  new FXMenuCommand(ret, ("Copy " + toString(getTag()) + " typed name to clipboard").c_str(), 0, ret, MID_COPY_TYPED_NAME);
219  // build menu command selection
221  // build menu command copy cursor position to clipboard
222  buildPositionCopyEntry(ret, false);
223  buildShowParamsPopupEntry(ret, false);
224  // get attributes
225  std::vector<SumoXMLAttr> attributes = getAttrs();
226  // Show position parameters
227  if (std::find(attributes.begin(), attributes.end(), SUMO_ATTR_LANE) != attributes.end()) {
228  // If additional own an lane as attribute, get lane
229  GNELane* lane = myViewNet->getNet()->retrieveLane(getParentName(), false);
230  if (lane) {
231  // Show menu command inner position
233  new FXMenuCommand(ret, ("inner position: " + toString(innerPos)).c_str(), 0, 0, 0);
234  // If shape isn't empty, show menu command lane position
235  if (myShape.size() > 0) {
236  const SUMOReal lanePos = lane->getShape().nearest_offset_to_point2D(myShape[0]);
237  new FXMenuCommand(ret, ("lane position: " + toString(innerPos + lanePos)).c_str(), 0, 0, 0);
238  }
239  } else {
240  throw InvalidArgument("Additional with id = '" + getMicrosimID() + "' don't have their lane as a ParentName()");
241  }
242  } else if (std::find(attributes.begin(), attributes.end(), SUMO_ATTR_EDGE) != attributes.end()) {
243  // If additional own an edge as attribute, get lane
244  GNEEdge* edge = myViewNet->getNet()->retrieveEdge(getParentName(), false);
245  if (edge) {
246  // Show menu command inner position
248  new FXMenuCommand(ret, ("inner position: " + toString(innerPos)).c_str(), 0, 0, 0);
249  // If shape isn't empty, show menu command edge position
250  if (myShape.size() > 0) {
251  const SUMOReal edgePos = edge->getLanes().at(0)->getShape().nearest_offset_to_point2D(myShape[0]);
252  new FXMenuCommand(ret, ("edge position: " + toString(innerPos + edgePos)).c_str(), 0, 0, 0);
253  }
254  } else {
255  throw InvalidArgument("Additional with id = '" + getMicrosimID() + "' don't have their edge as a ParentName()");
256  }
257  } else {
258  new FXMenuCommand(ret, ("position in view: " + toString(myPosition.x()) + "," + toString(myPosition.y())).c_str(), 0, 0, 0);
259  }
260  // Show childs if this is is an additionalSet
261  GNEAdditionalSet* additionalSet = dynamic_cast<GNEAdditionalSet*>(this);
262  if (additionalSet) {
263  new FXMenuSeparator(ret);
264  if (additionalSet->getNumberOfAdditionalChilds() > 0) {
265  new FXMenuCommand(ret, ("number of additional childs: " + toString(additionalSet->getNumberOfAdditionalChilds())).c_str(), 0, 0, 0);
266  } else if (additionalSet->getNumberOfEdgeChilds() > 0) {
267  new FXMenuCommand(ret, ("number of edge childs: " + toString(additionalSet->getNumberOfEdgeChilds())).c_str(), 0, 0, 0);
268  } else if (additionalSet->getNumberOfLaneChilds() > 0) {
269  new FXMenuCommand(ret, ("number of lane childs: " + toString(additionalSet->getNumberOfLaneChilds())).c_str(), 0, 0, 0);
270  }
271  }
272  new FXMenuSeparator(ret);
273  // let the GNEViewNet store the popup position
274  dynamic_cast<GNEViewNet&>(parent).markPopupPosition();
275  return ret;
276 }
277 
278 
281  // Ignore Warning
282  UNUSED_PARAMETER(parent);
283  // get attributes
284  std::vector<SumoXMLAttr> attributes = getAttrs();
285  // Create tanñe
286  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, (int)attributes.size());
287  // Iterate over attributes
288  for (std::vector<SumoXMLAttr>::iterator i = attributes.begin(); i != attributes.end(); i++) {
289  // Add attribute and set it dynamic if aren't unique
291  ret->mkItem(toString(*i).c_str(), false, getAttribute(*i));
292  } else {
293  ret->mkItem(toString(*i).c_str(), true, getAttribute(*i));
294  }
295  }
297  // close building
298  ret->closeBuilding();
299  return ret;
300 }
301 
302 
303 Boundary
306  b.grow(20);
307  return b;
308 }
309 
310 
311 void
313  if (myShape.size() > 0 && myShape.length() != 0) {
314  // If lenght of the shape is distint to 0, Obtain rotation of center of shape
316  } else if (lane != NULL) {
317  // If additional is over a lane, set rotation in the position over lane
319  } else {
320  // In other case, rotation is 0
322  }
323 }
324 
325 
326 void
328  // Start pushing matrix
329  glPushMatrix();
330  // Traslate to middle of shape
331  glTranslated(myBlockIconPosition.x(), myBlockIconPosition.y(), getType() + 0.1);
332  // Set draw color
333  glColor3d(1, 1, 1);
334  // Rotate depending of myBlockIconRotation
335  glRotated(myBlockIconRotation, 0, 0, -1);
336  // Rotate 180º
337  glRotated(180, 0, 0, 1);
338  // Traslate depending of the offset
339  glTranslated(myBlockIconOffset.x(), myBlockIconOffset.y(), 0);
340  // Draw icon depending of the state of additional
341  if (isAdditionalSelected()) {
342  if (myMovable == false) {
343  // Draw not movable texture if additional isn't movable and is selected
345  } else if (myBlocked) {
346  // Draw lock texture if additional is movable, is blocked and is selected
348  } else {
349  // Draw empty texture if additional is movable, isn't blocked and is selected
351  }
352  } else {
353  if (myMovable == false) {
354  // Draw not movable texture if additional isn't movable
356  } else if (myBlocked) {
357  // Draw lock texture if additional is movable and is blocked
359  } else {
360  // Draw empty texture if additional is movable and isn't blocked
362  }
363  }
364  // Pop matrix
365  glPopMatrix();
366 }
367 
368 
369 /****************************************************************************/
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.
SumoXMLTag
Numbers representing SUMO-XML - element names.
GNEAdditionalSet * getAdditionalSetParent() const
get additionalSet parent, or NULL if don&#39;t belongs to an additionalSet
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:616
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&#39;s shape.
bool myRotationLefthand
rotation depending of the option "Lefthand"
virtual const std::string & getParentName() const =0
Returns the name of the parent object (if any)
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:54
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:233
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.
void setBlocked(bool value)
Block or unblock additional element(i.e. cannot be moved with mouse)
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 updateAdditionalID(const std::string &oldID, GNEAdditional *additional)
update additional ID in container
Definition: GNENet.cpp:1082
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
virtual GNEEdge * getEdge() const
get edge of additional, or NULL if additional isn&#39;t placed over an edge
SUMOReal myBlockIconRotation
The rotation of the block icon.
virtual GNELane * getLane() const
get lane of additional, or NULL if additional isn&#39;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.
Copy object name - popup entry.
Definition: GUIAppEnum.h:231
SUMOReal getPositionRelativeToParametricLenght(SUMOReal position) const
Definition: GNELane.cpp:530
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:658
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
bool removeAdditionalChild(GNEAdditional *additional)
remove additional element to this set
~GNEAdditional()
Destructor.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
Position myBlockIconOffset
The offSet of the block icon.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:54
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:201
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:456
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:424
GNEAdditionalSet * myAdditionalSetParent
pointer to additional set parent, if belong to set
virtual void removeLaneReference()
if additional is placed over a lane, remove it reference
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
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:845
bool isAdditionalBlocked() const
Check if additional item is currently blocked (i.e. cannot be moved with mouse)
virtual void removeEdgeReference()
if additional is placed over an edge, remove it reference
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:213
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)
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&#39;s x/y position within the network.
bool isAdditionalInspectionable() const
check if additional element is inspectionable (With GNEInspectorFrame)
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&#39;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