SUMO - Simulation of Urban MObility
GNEAdditional.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A abstract class for representation of additional elements
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 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 
59 // ===========================================================================
60 // member method definitions
61 // ===========================================================================
62 
63 GNEAdditional::GNEAdditional(const std::string& id, GNEViewNet* viewNet, SumoXMLTag tag, GUIIcon icon) :
65  GNEAttributeCarrier(tag, icon),
66  myViewNet(viewNet),
67  myEdge(NULL),
68  myLane(NULL),
69  myBlockIconRotation(0),
70  myBlocked(false),
71  myInspectionable(true),
72  mySelectable(true),
73  myMovable(true),
74  myAdditionalDialog(NULL) {
75  // Set rotation left hand
77 }
78 
79 
81 
82 
83 void
85 
86 
87 const std::string&
89  return getMicrosimID();
90 }
91 
92 
95  return myViewNet;
96 }
97 
98 
101  return myShape;
102 }
103 
104 
105 bool
107  return myBlocked;
108 }
109 
110 
111 bool
113  return myInspectionable;
114 }
115 
116 
117 bool
119  return mySelectable;
120 }
121 
122 
123 bool
125  return myMovable;
126 }
127 
128 
129 bool
131  return gSelected.isSelected(getType(), getGlID());
132 }
133 
134 
135 void
136 GNEAdditional::setAdditionalID(const std::string& id) {
137  // Save old ID
138  std::string oldID = getMicrosimID();
139  // set New ID
140  setMicrosimID(id);
141  // update additional ID in the container of net
142  myViewNet->getNet()->updateAdditionalID(oldID, this);
143 }
144 
145 
146 GNEEdge*
148  return myEdge;
149 }
150 
151 
152 GNELane*
154  return myLane;
155 }
156 
157 const std::string&
159  return myViewNet->getNet()->getMicrosimID();
160 }
161 
162 
165  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
166  // build header
167  buildPopupHeader(ret, app);
168  // build menu command for center button
170  // buld menu commands for names
171  new FXMenuCommand(ret, ("Copy " + toString(getTag()) + " name to clipboard").c_str(), 0, ret, MID_COPY_NAME);
172  new FXMenuCommand(ret, ("Copy " + toString(getTag()) + " typed name to clipboard").c_str(), 0, ret, MID_COPY_TYPED_NAME);
173  // build menu command selection
175  // build menu command copy cursor position to clipboard
176  buildPositionCopyEntry(ret, false);
177  buildShowParamsPopupEntry(ret, false);
178  // get attributes
179  std::vector<SumoXMLAttr> attributes = getAttrs();
180  // Show position parameters
181  if (std::find(attributes.begin(), attributes.end(), SUMO_ATTR_LANE) != attributes.end()) {
182  // If additional own an lane as attribute, get lane
183  GNELane* lane = myViewNet->getNet()->retrieveLane(getParentName(), false);
184  if (lane) {
185  // Show menu command inner position
186  const double innerPos = myShape.nearest_offset_to_point2D(parent.getPositionInformation());
187  new FXMenuCommand(ret, ("inner position: " + toString(innerPos)).c_str(), 0, 0, 0);
188  // If shape isn't empty, show menu command lane position
189  if (myShape.size() > 0) {
190  const double lanePos = lane->getShape().nearest_offset_to_point2D(myShape[0]);
191  new FXMenuCommand(ret, ("position over " + toString(SUMO_TAG_LANE) + ": " + toString(innerPos + lanePos)).c_str(), 0, 0, 0);
192  }
193  } else {
194  throw InvalidArgument(toString(getTag()) + " with ID '" + getMicrosimID() + "' doesn't have their lane as a ParentName()");
195  }
196  } else if (std::find(attributes.begin(), attributes.end(), SUMO_ATTR_EDGE) != attributes.end()) {
197  // If additional own an edge as attribute, get lane
198  GNEEdge* edge = myViewNet->getNet()->retrieveEdge(getParentName(), false);
199  if (edge) {
200  // Show menu command inner position
201  const double innerPos = myShape.nearest_offset_to_point2D(parent.getPositionInformation());
202  new FXMenuCommand(ret, ("inner position: " + toString(innerPos)).c_str(), 0, 0, 0);
203  // If shape isn't empty, show menu command edge position
204  if (myShape.size() > 0) {
205  const double edgePos = edge->getLanes().at(0)->getShape().nearest_offset_to_point2D(myShape[0]);
206  new FXMenuCommand(ret, ("position over " + toString(SUMO_TAG_LANE) + ": " + toString(innerPos + edgePos)).c_str(), 0, 0, 0);
207  }
208  } else {
209  throw InvalidArgument(toString(getTag()) + " with ID '" + getMicrosimID() + "' don't have their edge as a ParentName()");
210  }
211  } else {
212  new FXMenuCommand(ret, ("position in view: " + toString(getPositionInView().x()) + "," + toString(getPositionInView().y())).c_str(), 0, 0, 0);
213  }
214  new FXMenuSeparator(ret);
215  // let the GNEViewNet store the popup position
216  dynamic_cast<GNEViewNet&>(parent).markPopupPosition();
217  return ret;
218 }
219 
220 
223  // Ignore Warning
224  UNUSED_PARAMETER(parent);
225  // get attributes
226  std::vector<SumoXMLAttr> attributes = getAttrs();
227  // Create table
228  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, (int)attributes.size());
229  // Iterate over attributes
230  for (std::vector<SumoXMLAttr>::iterator i = attributes.begin(); i != attributes.end(); i++) {
231  // Add attribute and set it dynamic if aren't unique
233  ret->mkItem(toString(*i).c_str(), false, getAttribute(*i));
234  } else {
235  ret->mkItem(toString(*i).c_str(), true, getAttribute(*i));
236  }
237  }
239  // close building
240  ret->closeBuilding();
241  return ret;
242 }
243 
244 
245 Boundary
248  b.grow(20);
249  return b;
250 }
251 
252 
253 void
255  if (myShape.size() > 0 && myShape.length() != 0) {
256  // If length of the shape is distint to 0, Obtain rotation of center of shape
258  } else if (myLane != NULL) {
259  // If additional is over a lane, set rotation in the position over lane
260  double posOverLane = myLane->getShape().nearest_offset_to_point2D(getPositionInView());
262  } else {
263  // In other case, rotation is 0
265  }
266 }
267 
268 
269 void
270 GNEAdditional::drawLockIcon(double size) const {
271  if (myViewNet->showLockIcon()) {
272  // Start pushing matrix
273  glPushMatrix();
274  // Traslate to middle of shape
275  glTranslated(myBlockIconPosition.x(), myBlockIconPosition.y(), getType() + 0.1);
276  // Set draw color
277  glColor3d(1, 1, 1);
278  // Rotate depending of myBlockIconRotation
279  glRotated(myBlockIconRotation, 0, 0, -1);
280  // Rotate 180 degrees
281  glRotated(180, 0, 0, 1);
282  // Traslate depending of the offset
283  glTranslated(myBlockIconOffset.x(), myBlockIconOffset.y(), 0);
284  // Draw icon depending of the state of additional
285  if (isAdditionalSelected()) {
286  if (myMovable == false) {
287  // Draw not movable texture if additional isn't movable and is selected
289  } else if (myBlocked) {
290  // Draw lock texture if additional is movable, is blocked and is selected
292  } else {
293  // Draw empty texture if additional is movable, isn't blocked and is selected
295  }
296  } else {
297  if (myMovable == false) {
298  // Draw not movable texture if additional isn't movable
300  } else if (myBlocked) {
301  // Draw lock texture if additional is movable and is blocked
303  } else {
304  // Draw empty texture if additional is movable and isn't blocked
306  }
307  }
308  // Pop matrix
309  glPopMatrix();
310  }
311 }
312 
313 
314 void
316  // Iterate over myConnectionPositions
317  for (std::vector<std::vector<Position> >::const_iterator i = myConnectionPositions.begin(); i != myConnectionPositions.end(); i++) {
318  // Add a draw matrix
319  glPushMatrix();
320  // traslate in the Z axis
321  glTranslated(0, 0, getType() - 0.01);
322  // Set color of the base
323  GLHelper::setColor(RGBColor(255, 235, 0));
324  for (std::vector<Position>::const_iterator j = (*i).begin(); (j + 1) != (*i).end(); j++) {
325  // Draw Lines
326  GLHelper::drawLine((*j), (*(j + 1)));
327  }
328  // Pop draw matrix
329  glPopMatrix();
330  }
331 }
332 
333 
334 void
335 GNEAdditional::changeEdge(const std::string& edgeID) {
336  if (myEdge == NULL) {
337  throw InvalidArgument(toString(getTag()) + " with ID '" + getMicrosimID() + "' doesn't belong to an " + toString(SUMO_TAG_EDGE));
338  } else {
340  myEdge = getViewNet()->getNet()->retrieveEdge(edgeID);
341  myEdge->addAdditionalChild(this);
342  updateGeometry();
343  getViewNet()->update();
344  }
345 }
346 
347 
348 void
349 GNEAdditional::changeLane(const std::string& laneID) {
350  if (myLane == NULL) {
351  throw InvalidArgument(toString(getTag()) + " with ID '" + getMicrosimID() + "' doesn't belong to a " + toString(SUMO_TAG_LANE));
352  } else {
354  myLane = getViewNet()->getNet()->retrieveLane(laneID);
355  myLane->addAdditionalChild(this);
356  updateGeometry();
357  getViewNet()->update();
358  }
359 }
360 
361 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
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.
virtual const std::string & getParentName() const =0
Returns the name of the parent object (if any)
bool showLockIcon() const
check if lock icon should be visible
void setBlockIconRotation()
SumoXMLTag
Numbers representing SUMO-XML - element names.
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:899
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
begin/end of the description of a single lane
std::vector< SumoXMLAttr > getAttrs() const
get vector of attributes
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
PositionVector getShape() const
Returns additional element&#39;s shape.
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
double x() const
Returns the x-position.
Definition: Position.h:63
GNELane * myLane
The lane this additional belongs.
bool myRotationLefthand
rotation depending of the option "Lefthand"
void removeAdditionalChild(GNEAdditional *additional)
remove additional child to this lane
Definition: GNELane.cpp:746
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.
virtual Position getPositionInView() const =0
Returns position of additional in view.
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:235
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 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:40
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
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:1185
void updateAdditionalID(const std::string &oldID, GNEAdditional *additional)
update additional ID in container
Definition: GNENet.cpp:1638
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void changeEdge(const std::string &edgeID)
change edge of additional
GNEEdge * getEdge() const
get edge of additional, or NULL if additional isn&#39;t placed over an edge
GNELane * getLane() const
get lane of additional, or NULL if additional isn&#39;t placed over a Lane
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:438
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
Copy object name - popup entry.
Definition: GUIAppEnum.h:233
PositionVector myShape
The shape of the additional element.
void addAdditionalChild(GNEAdditional *additional)
add additional child to this lane
Definition: GNELane.cpp:735
A list of positions.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:958
std::vector< std::vector< Position > > myConnectionPositions
Matrix with the Vertex&#39;s positions of connections between Additional Parent an their childs...
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
double y() const
Returns the y-position.
Definition: Position.h:68
double length() const
Returns the length.
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:302
void setAdditionalID(const std::string &id)
set the ID of additional
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:265
void drawLockIcon(double size=0.5) const
draw lock icon
~GNEAdditional()
Destructor.
virtual std::string getAttribute(SumoXMLAttr key) const =0
This functions has to be implemented in allGNEAttributeCarrier.
void changeLane(const std::string &laneID)
change lane of additional
Position myBlockIconOffset
The offSet of the block icon.
begin/end of the description of an edge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:58
static bool isUnique(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is unique (may not be edited for a multi-selection and don&#39;t have a default valu...
compound additional
void drawParentAndChildrenConnections() const
draw connections between Parent and childrens
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:625
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:599
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
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
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 XML Tag assigned to this object
virtual void updateGeometry()=0
update pre-computed geometry information
void removeAdditionalChild(GNEAdditional *additional)
remove additional child from this edge
Definition: GNEEdge.cpp:1198
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)
GNEEdge * myEdge
The edge this additional belongs.
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.
A window containing a gl-object&#39;s parameter.
double myBlockIconRotation
The rotation of the block icon.
GNEAdditional(const std::string &id, GNEViewNet *viewNet, SumoXMLTag tag, GUIIcon icon)
Constructor.
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