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 #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, GUIIcon icon) :
69  GNEAttributeCarrier(tag, icon),
70  myViewNet(viewNet),
71  myEdge(NULL),
72  myLane(NULL),
73  myPosition(pos),
74  myBlockIconRotation(0),
75  myBlocked(false),
76  myInspectionable(true),
77  mySelectable(true),
78  myMovable(true),
79  myBaseColor(RGBColor::GREEN),
80  myBaseColorSelected(RGBColor::BLUE),
81  myAdditionalDialog(NULL) {
82  // Set rotation left hand
84 }
85 
86 
88 
89 
90 void
92  moveAdditionalGeometry(offset.x(), offset.y());
93 }
94 
95 
96 void
98  commmitAdditionalGeometryMoved(oldPos.x(), oldPos.y(), undoList);
99  // Refresh element
101 }
102 
103 
104 void
106 
107 
108 const std::string&
110  return getMicrosimID();
111 }
112 
113 
114 GNEViewNet*
116  return myViewNet;
117 }
118 
119 
122  return myShape;
123 }
124 
125 
126 bool
128  return myBlocked;
129 }
130 
131 
132 bool
134  return myInspectionable;
135 }
136 
137 
138 bool
140  return mySelectable;
141 }
142 
143 
144 bool
146  return myMovable;
147 }
148 
149 
150 bool
152  return gSelected.isSelected(getType(), getGlID());
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 void
168  myPosition = pos;
169 }
170 
171 
172 GNEEdge*
174  return myEdge;
175 }
176 
177 
178 GNELane*
180  return myLane;
181 }
182 
183 const std::string&
185  return myViewNet->getNet()->getMicrosimID();
186 }
187 
188 
191  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
192  // build header
193  buildPopupHeader(ret, app);
194  // build menu command for center button
196  // buld menu commands for names
197  new FXMenuCommand(ret, ("Copy " + toString(getTag()) + " name to clipboard").c_str(), 0, ret, MID_COPY_NAME);
198  new FXMenuCommand(ret, ("Copy " + toString(getTag()) + " typed name to clipboard").c_str(), 0, ret, MID_COPY_TYPED_NAME);
199  // build menu command selection
201  // build menu command copy cursor position to clipboard
202  buildPositionCopyEntry(ret, false);
203  buildShowParamsPopupEntry(ret, false);
204  // get attributes
205  std::vector<SumoXMLAttr> attributes = getAttrs();
206  // Show position parameters
207  if (std::find(attributes.begin(), attributes.end(), SUMO_ATTR_LANE) != attributes.end()) {
208  // If additional own an lane as attribute, get lane
209  GNELane* lane = myViewNet->getNet()->retrieveLane(getParentName(), false);
210  if (lane) {
211  // Show menu command inner position
213  new FXMenuCommand(ret, ("inner position: " + toString(innerPos)).c_str(), 0, 0, 0);
214  // If shape isn't empty, show menu command lane position
215  if (myShape.size() > 0) {
216  const SUMOReal lanePos = lane->getShape().nearest_offset_to_point2D(myShape[0]);
217  new FXMenuCommand(ret, ("position over " + toString(SUMO_TAG_LANE) + ": " + toString(innerPos + lanePos)).c_str(), 0, 0, 0);
218  }
219  } else {
220  throw InvalidArgument(toString(getTag()) + " with ID '" + getMicrosimID() + "' doesn't have their lane as a ParentName()");
221  }
222  } else if (std::find(attributes.begin(), attributes.end(), SUMO_ATTR_EDGE) != attributes.end()) {
223  // If additional own an edge as attribute, get lane
224  GNEEdge* edge = myViewNet->getNet()->retrieveEdge(getParentName(), false);
225  if (edge) {
226  // Show menu command inner position
228  new FXMenuCommand(ret, ("inner position: " + toString(innerPos)).c_str(), 0, 0, 0);
229  // If shape isn't empty, show menu command edge position
230  if (myShape.size() > 0) {
231  const SUMOReal edgePos = edge->getLanes().at(0)->getShape().nearest_offset_to_point2D(myShape[0]);
232  new FXMenuCommand(ret, ("position over " + toString(SUMO_TAG_LANE) + ": " + toString(innerPos + edgePos)).c_str(), 0, 0, 0);
233  }
234  } else {
235  throw InvalidArgument(toString(getTag()) + " with ID '" + getMicrosimID() + "' don't have their edge as a ParentName()");
236  }
237  } else {
238  new FXMenuCommand(ret, ("position in view: " + toString(myPosition.x()) + "," + toString(myPosition.y())).c_str(), 0, 0, 0);
239  }
240  new FXMenuSeparator(ret);
241  // let the GNEViewNet store the popup position
242  dynamic_cast<GNEViewNet&>(parent).markPopupPosition();
243  return ret;
244 }
245 
246 
249  // Ignore Warning
250  UNUSED_PARAMETER(parent);
251  // get attributes
252  std::vector<SumoXMLAttr> attributes = getAttrs();
253  // Create table
254  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, (int)attributes.size());
255  // Iterate over attributes
256  for (std::vector<SumoXMLAttr>::iterator i = attributes.begin(); i != attributes.end(); i++) {
257  // Add attribute and set it dynamic if aren't unique
259  ret->mkItem(toString(*i).c_str(), false, getAttribute(*i));
260  } else {
261  ret->mkItem(toString(*i).c_str(), true, getAttribute(*i));
262  }
263  }
265  // close building
266  ret->closeBuilding();
267  return ret;
268 }
269 
270 
271 Boundary
274  b.grow(20);
275  return b;
276 }
277 
278 
279 void
281  if (myShape.size() > 0 && myShape.length() != 0) {
282  // If lenght of the shape is distint to 0, Obtain rotation of center of shape
284  } else if (lane != NULL) {
285  // If additional is over a lane, set rotation in the position over lane
287  } else {
288  // In other case, rotation is 0
290  }
291 }
292 
293 
294 void
296  if (myViewNet->showLockIcon()) {
297  // Start pushing matrix
298  glPushMatrix();
299  // Traslate to middle of shape
300  glTranslated(myBlockIconPosition.x(), myBlockIconPosition.y(), getType() + 0.1);
301  // Set draw color
302  glColor3d(1, 1, 1);
303  // Rotate depending of myBlockIconRotation
304  glRotated(myBlockIconRotation, 0, 0, -1);
305  // Rotate 180º
306  glRotated(180, 0, 0, 1);
307  // Traslate depending of the offset
308  glTranslated(myBlockIconOffset.x(), myBlockIconOffset.y(), 0);
309  // Draw icon depending of the state of additional
310  if (isAdditionalSelected()) {
311  if (myMovable == false) {
312  // Draw not movable texture if additional isn't movable and is selected
314  } else if (myBlocked) {
315  // Draw lock texture if additional is movable, is blocked and is selected
317  } else {
318  // Draw empty texture if additional is movable, isn't blocked and is selected
320  }
321  } else {
322  if (myMovable == false) {
323  // Draw not movable texture if additional isn't movable
325  } else if (myBlocked) {
326  // Draw lock texture if additional is movable and is blocked
328  } else {
329  // Draw empty texture if additional is movable and isn't blocked
331  }
332  }
333  // Pop matrix
334  glPopMatrix();
335  }
336 }
337 
338 
339 void
341  // Iterate over myConnectionPositions
342  for (std::vector<std::vector<Position> >::const_iterator i = myConnectionPositions.begin(); i != myConnectionPositions.end(); i++) {
343  // Add a draw matrix
344  glPushMatrix();
345  // traslate in the Z axis
346  glTranslated(0, 0, getType() - 0.01);
347  // Set color of the base
348  GLHelper::setColor(RGBColor(255, 235, 0, 255));
349  for (std::vector<Position>::const_iterator j = (*i).begin(); (j + 1) != (*i).end(); j++) {
350  // Draw Lines
351  GLHelper::drawLine((*j), (*(j + 1)));
352  }
353  // Pop draw matrix
354  glPopMatrix();
355  }
356 }
357 
358 
359 void
360 GNEAdditional::changeEdge(const std::string& edgeID) {
361  if (myEdge == NULL) {
362  throw InvalidArgument(toString(getTag()) + " with ID '" + getMicrosimID() + "' doesn't belong to an " + toString(SUMO_TAG_EDGE));
363  } else {
365  myEdge = getViewNet()->getNet()->retrieveEdge(edgeID);
366  myEdge->addAdditionalChild(this);
367  updateGeometry();
368  getViewNet()->update();
369  }
370 }
371 
372 
373 void
374 GNEAdditional::changeLane(const std::string& laneID) {
375  if (myLane == NULL) {
376  throw InvalidArgument(toString(getTag()) + " with ID '" + getMicrosimID() + "' doesn't belong to a " + toString(SUMO_TAG_LANE));
377  } else {
379  myLane = getViewNet()->getNet()->retrieveLane(laneID);
380  myLane->addAdditionalChild(this);
381  updateGeometry();
382  getViewNet()->update();
383  }
384 }
385 
386 /****************************************************************************/
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
SumoXMLTag
Numbers representing SUMO-XML - element names.
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:732
Copy object name - popup entry.
Definition: GUIAppEnum.h:233
SUMOReal nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
begin/end of the description of a single lane
std::vector< SumoXMLAttr > getAttrs() const
get vector of attributes
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:235
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
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:713
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
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.
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:38
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
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:945
void updateAdditionalID(const std::string &oldID, GNEAdditional *additional)
update additional ID in container
Definition: GNENet.cpp:1237
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:55
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
SUMOReal myBlockIconRotation
The rotation of the block icon.
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:443
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
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:814
SUMOReal getPositionRelativeToParametricLenght(SUMOReal position) const
Definition: GNELane.cpp:689
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:701
A list of positions.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:774
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.
void drawLockIcon(SUMOReal size=0.5) const
draw lock icon
void setAdditionalID(const std::string &id)
set the ID of additional
~GNEAdditional()
Destructor.
virtual std::string getAttribute(SumoXMLAttr key) const =0
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:54
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
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:238
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:479
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.
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:989
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 ...
static void drawLine(const Position &beg, SUMOReal rot, SUMOReal visLength)
Draws a thin line.
Definition: GLHelper.cpp:269
SumoXMLTag getTag() const
get XML Tag assigned to this object
Position myPosition
The position in which this additional element is located.
#define SUMOReal
Definition: config.h:208
void setPositionInView(const Position &pos)
set new position in the view
virtual void updateGeometry()=0
update pre-computed geometry information
void removeAdditionalChild(GNEAdditional *additional)
remove additional child from this edge
Definition: GNEEdge.cpp:956
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.
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