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.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, Position pos, SumoXMLTag tag, GUIIcon icon) :
65  GNEAttributeCarrier(tag, icon),
66  myViewNet(viewNet),
67  myEdge(NULL),
68  myLane(NULL),
69  myPosition(pos),
70  myBlockIconRotation(0),
71  myBlocked(false),
72  myInspectionable(true),
73  mySelectable(true),
74  myMovable(true),
75  myBaseColor(RGBColor::GREEN),
76  myBaseColorSelected(RGBColor::BLUE),
77  myAdditionalDialog(NULL) {
78  // Set rotation left hand
80 }
81 
82 
84 
85 
86 void
88  moveAdditionalGeometry(offset.x(), offset.y());
89 }
90 
91 
92 void
94  commmitAdditionalGeometryMoved(oldPos.x(), oldPos.y(), undoList);
95  // Refresh element
97 }
98 
99 
100 void
102 
103 
104 const std::string&
106  return getMicrosimID();
107 }
108 
109 
110 GNEViewNet*
112  return myViewNet;
113 }
114 
115 
118  return myShape;
119 }
120 
121 
122 bool
124  return myBlocked;
125 }
126 
127 
128 bool
130  return myInspectionable;
131 }
132 
133 
134 bool
136  return mySelectable;
137 }
138 
139 
140 bool
142  return myMovable;
143 }
144 
145 
146 bool
148  return gSelected.isSelected(getType(), getGlID());
149 }
150 
151 
152 void
153 GNEAdditional::setAdditionalID(const std::string& id) {
154  // Save old ID
155  std::string oldID = getMicrosimID();
156  // set New ID
157  setMicrosimID(id);
158  // update additional ID in the container of net
159  myViewNet->getNet()->updateAdditionalID(oldID, this);
160 }
161 
162 void
164  myPosition = pos;
165 }
166 
167 
168 GNEEdge*
170  return myEdge;
171 }
172 
173 
174 GNELane*
176  return myLane;
177 }
178 
179 const std::string&
181  return myViewNet->getNet()->getMicrosimID();
182 }
183 
184 
187  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
188  // build header
189  buildPopupHeader(ret, app);
190  // build menu command for center button
192  // buld menu commands for names
193  new FXMenuCommand(ret, ("Copy " + toString(getTag()) + " name to clipboard").c_str(), 0, ret, MID_COPY_NAME);
194  new FXMenuCommand(ret, ("Copy " + toString(getTag()) + " typed name to clipboard").c_str(), 0, ret, MID_COPY_TYPED_NAME);
195  // build menu command selection
197  // build menu command copy cursor position to clipboard
198  buildPositionCopyEntry(ret, false);
199  buildShowParamsPopupEntry(ret, false);
200  // get attributes
201  std::vector<SumoXMLAttr> attributes = getAttrs();
202  // Show position parameters
203  if (std::find(attributes.begin(), attributes.end(), SUMO_ATTR_LANE) != attributes.end()) {
204  // If additional own an lane as attribute, get lane
205  GNELane* lane = myViewNet->getNet()->retrieveLane(getParentName(), false);
206  if (lane) {
207  // Show menu command inner position
208  const double innerPos = myShape.nearest_offset_to_point2D(parent.getPositionInformation());
209  new FXMenuCommand(ret, ("inner position: " + toString(innerPos)).c_str(), 0, 0, 0);
210  // If shape isn't empty, show menu command lane position
211  if (myShape.size() > 0) {
212  const double lanePos = lane->getShape().nearest_offset_to_point2D(myShape[0]);
213  new FXMenuCommand(ret, ("position over " + toString(SUMO_TAG_LANE) + ": " + toString(innerPos + lanePos)).c_str(), 0, 0, 0);
214  }
215  } else {
216  throw InvalidArgument(toString(getTag()) + " with ID '" + getMicrosimID() + "' doesn't have their lane as a ParentName()");
217  }
218  } else if (std::find(attributes.begin(), attributes.end(), SUMO_ATTR_EDGE) != attributes.end()) {
219  // If additional own an edge as attribute, get lane
220  GNEEdge* edge = myViewNet->getNet()->retrieveEdge(getParentName(), false);
221  if (edge) {
222  // Show menu command inner position
223  const double innerPos = myShape.nearest_offset_to_point2D(parent.getPositionInformation());
224  new FXMenuCommand(ret, ("inner position: " + toString(innerPos)).c_str(), 0, 0, 0);
225  // If shape isn't empty, show menu command edge position
226  if (myShape.size() > 0) {
227  const double edgePos = edge->getLanes().at(0)->getShape().nearest_offset_to_point2D(myShape[0]);
228  new FXMenuCommand(ret, ("position over " + toString(SUMO_TAG_LANE) + ": " + toString(innerPos + edgePos)).c_str(), 0, 0, 0);
229  }
230  } else {
231  throw InvalidArgument(toString(getTag()) + " with ID '" + getMicrosimID() + "' don't have their edge as a ParentName()");
232  }
233  } else {
234  new FXMenuCommand(ret, ("position in view: " + toString(myPosition.x()) + "," + toString(myPosition.y())).c_str(), 0, 0, 0);
235  }
236  new FXMenuSeparator(ret);
237  // let the GNEViewNet store the popup position
238  dynamic_cast<GNEViewNet&>(parent).markPopupPosition();
239  return ret;
240 }
241 
242 
245  // Ignore Warning
246  UNUSED_PARAMETER(parent);
247  // get attributes
248  std::vector<SumoXMLAttr> attributes = getAttrs();
249  // Create table
250  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, (int)attributes.size());
251  // Iterate over attributes
252  for (std::vector<SumoXMLAttr>::iterator i = attributes.begin(); i != attributes.end(); i++) {
253  // Add attribute and set it dynamic if aren't unique
255  ret->mkItem(toString(*i).c_str(), false, getAttribute(*i));
256  } else {
257  ret->mkItem(toString(*i).c_str(), true, getAttribute(*i));
258  }
259  }
261  // close building
262  ret->closeBuilding();
263  return ret;
264 }
265 
266 
267 Boundary
270  b.grow(20);
271  return b;
272 }
273 
274 
275 void
277  if (myShape.size() > 0 && myShape.length() != 0) {
278  // If length of the shape is distint to 0, Obtain rotation of center of shape
280  } else if (lane != NULL) {
281  // If additional is over a lane, set rotation in the position over lane
283  } else {
284  // In other case, rotation is 0
286  }
287 }
288 
289 
290 void
291 GNEAdditional::drawLockIcon(double size) const {
292  if (myViewNet->showLockIcon()) {
293  // Start pushing matrix
294  glPushMatrix();
295  // Traslate to middle of shape
296  glTranslated(myBlockIconPosition.x(), myBlockIconPosition.y(), getType() + 0.1);
297  // Set draw color
298  glColor3d(1, 1, 1);
299  // Rotate depending of myBlockIconRotation
300  glRotated(myBlockIconRotation, 0, 0, -1);
301  // Rotate 180 degrees
302  glRotated(180, 0, 0, 1);
303  // Traslate depending of the offset
304  glTranslated(myBlockIconOffset.x(), myBlockIconOffset.y(), 0);
305  // Draw icon depending of the state of additional
306  if (isAdditionalSelected()) {
307  if (myMovable == false) {
308  // Draw not movable texture if additional isn't movable and is selected
310  } else if (myBlocked) {
311  // Draw lock texture if additional is movable, is blocked and is selected
313  } else {
314  // Draw empty texture if additional is movable, isn't blocked and is selected
316  }
317  } else {
318  if (myMovable == false) {
319  // Draw not movable texture if additional isn't movable
321  } else if (myBlocked) {
322  // Draw lock texture if additional is movable and is blocked
324  } else {
325  // Draw empty texture if additional is movable and isn't blocked
327  }
328  }
329  // Pop matrix
330  glPopMatrix();
331  }
332 }
333 
334 
335 void
337  // Iterate over myConnectionPositions
338  for (std::vector<std::vector<Position> >::const_iterator i = myConnectionPositions.begin(); i != myConnectionPositions.end(); i++) {
339  // Add a draw matrix
340  glPushMatrix();
341  // traslate in the Z axis
342  glTranslated(0, 0, getType() - 0.01);
343  // Set color of the base
344  GLHelper::setColor(RGBColor(255, 235, 0, 255));
345  for (std::vector<Position>::const_iterator j = (*i).begin(); (j + 1) != (*i).end(); j++) {
346  // Draw Lines
347  GLHelper::drawLine((*j), (*(j + 1)));
348  }
349  // Pop draw matrix
350  glPopMatrix();
351  }
352 }
353 
354 
355 void
356 GNEAdditional::changeEdge(const std::string& edgeID) {
357  if (myEdge == NULL) {
358  throw InvalidArgument(toString(getTag()) + " with ID '" + getMicrosimID() + "' doesn't belong to an " + toString(SUMO_TAG_EDGE));
359  } else {
361  myEdge = getViewNet()->getNet()->retrieveEdge(edgeID);
362  myEdge->addAdditionalChild(this);
363  updateGeometry();
364  getViewNet()->update();
365  }
366 }
367 
368 
369 void
370 GNEAdditional::changeLane(const std::string& laneID) {
371  if (myLane == NULL) {
372  throw InvalidArgument(toString(getTag()) + " with ID '" + getMicrosimID() + "' doesn't belong to a " + toString(SUMO_TAG_LANE));
373  } else {
375  myLane = getViewNet()->getNet()->retrieveLane(laneID);
376  myLane->addAdditionalChild(this);
377  updateGeometry();
378  getViewNet()->update();
379  }
380 }
381 
382 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
virtual void openAdditionalDialog()
open Additional Dialog
GNELane * getLane() const
get lane of additional, or NULL if additional isn&#39;t placed over a Lane
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
SumoXMLTag
Numbers representing SUMO-XML - element names.
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:743
bool isAdditionalBlocked() const
Check if additional item is currently blocked (i.e. cannot be moved with mouse)
begin/end of the description of a single lane
const std::string & getAdditionalID() const
returns the ID of additional
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
GNELane * myLane
The lane this additional belongs.
bool myRotationLefthand
rotation depending of the option "Lefthand"
virtual const std::string & getParentName() const =0
Returns the name of the parent object (if any)
double y() const
Returns the y-position.
Definition: Position.h:68
void removeAdditionalChild(GNEAdditional *additional)
remove additional child to this lane
Definition: GNELane.cpp:751
PositionVector getShape() const
Returns additional element&#39;s shape.
double getPositionRelativeToParametricLength(double position) const
Definition: GNELane.cpp:727
double x() const
Returns the x-position.
Definition: Position.h:63
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
Copy object name - popup entry.
Definition: GUIAppEnum.h:233
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
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.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
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.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:38
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
virtual std::string getAttribute(SumoXMLAttr key) const =0
bool isAdditionalInspectionable() const
check if additional element is inspectionable (With GNEInspectorFrame)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void drawParentAndChildrenConnections() const
draw connections between Parent and childrens
void addAdditionalChild(GNEAdditional *additional)
add additional child to this edge
Definition: GNEEdge.cpp:1035
bool showLockIcon() const
check if lock icon should be visible
void updateAdditionalID(const std::string &oldID, GNEAdditional *additional)
update additional ID in container
Definition: GNENet.cpp:1290
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void drawLockIcon(double size=0.5) const
draw lock icon
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void changeEdge(const std::string &edgeID)
change edge of additional
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:439
bool myMovable
boolean to check if additional element is movable (with the mouse). By default true ...
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:825
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
GNEAdditional(const std::string &id, GNEViewNet *viewNet, Position pos, SumoXMLTag tag, GUIIcon icon)
Constructor.
void addAdditionalChild(GNEAdditional *additional)
add additional child to this lane
Definition: GNELane.cpp:739
A list of positions.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:785
void setBlockIconRotation(GNELane *lane=NULL)
set Rotation of block Icon
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.
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:234
void setAdditionalID(const std::string &id)
set the ID of additional
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
std::vector< SumoXMLAttr > getAttrs() const
get vector of attributes
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:265
~GNEAdditional()
Destructor.
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:57
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
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:621
bool isAdditionalSelectable() const
check if additional element is selectable (With GNESelectorFrame)
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:543
double length() const
Returns the length.
void moveAdditionalGeometry(const Position &offset)
change the position of the additional geometry
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
bool isAdditionalMovable() const
check if additional element is movable
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
GUIGlID getGlID() const
Returns the numerical id of the object.
bool mySelectable
boolean to check if additional element is selectable (With GNESelectorFrame). By default true ...
Position myPosition
The position in which this additional element is located.
void setPositionInView(const Position &pos)
set new position in the view
Position getPositionInformation() const
Returns the cursor&#39;s x/y position within the network.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
bool isAdditionalSelected() const
virtual void updateGeometry()=0
update pre-computed geometry information
void removeAdditionalChild(GNEAdditional *additional)
remove additional child from this edge
Definition: GNEEdge.cpp:1048
bool myInspectionable
boolean to check if additional element is inspectionable (With GNEInspectorFrame). By default true
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:235
GNEEdge * myEdge
The edge this additional belongs.
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
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.
double myBlockIconRotation
The rotation of the block icon.
GNEEdge * getEdge() const
get edge of additional, or NULL if additional isn&#39;t placed over an edge
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get XML Tag assigned to this object