SUMO - Simulation of Urban MObility
GNEDetectorExit.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>
45 #include <utils/gui/div/GLHelper.h>
49 
50 #include "GNEDetectorExit.h"
51 #include "GNEDetectorE3.h"
52 #include "GNELane.h"
53 #include "GNEViewNet.h"
54 #include "GNEUndoList.h"
55 #include "GNENet.h"
56 #include "GNEChange_Attribute.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 
68  GNEDetector(parent->generateExitID(), viewNet, SUMO_TAG_DET_EXIT, ICON_E3EXIT, lane, pos, 0, ""),
69  myE3Parent(parent) {
70  // Update geometry
72  // Set colors
73  myBaseColor = RGBColor(204, 0, 0, 255);
74  myBaseColorSelected = RGBColor(204, 125, 0, 255);
75 }
76 
77 
79 
80 
81 void
84 }
85 
86 
87 void
89  // Clear all containers
90  myShapeRotations.clear();
91  myShapeLengths.clear();
92 
93  // clear Shape
94  myShape.clear();
95 
96  // Get shape of lane parent
98 
99  // Save rotation (angle) of the vector constructed by points f and s
101 
102  // Set offset of logo
104 
105  // Set block icon position
107 
108  // Set block icon rotation, and using their rotation for logo
110 
111  // Refresh element (neccesary to avoid grabbing problems)
113 }
114 
115 
116 Position
119 }
120 
121 
124  return myE3Parent;
125 }
126 
127 
128 void
130  // This additional cannot be writted calling this function because is writted by their E3Parent
131 }
132 
133 
134 void
136  // Start drawing adding gl identificator
137  glPushName(getGlID());
138 
139  // Push detector matrix
140  glPushMatrix();
141  glTranslated(0, 0, getType());
142 
143  // Set initial values
144  if (isAdditionalSelected()) {
146  } else {
147  glColor3d(myBaseColor.red(), myBaseColor.green(), myBaseColor.blue());
148  }
149  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
150  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
151 
152  // Push poligon matrix
153  glPushMatrix();
154  glScaled(exaggeration, exaggeration, 1);
155  glTranslated(myShape[0].x(), myShape[0].y(), 0);
156  glRotated(myShapeRotations[0], 0, 0, 1);
157 
158  // Draw poligon
159  glBegin(GL_LINES);
160  glVertex2d(1.7, 0);
161  glVertex2d(-1.7, 0);
162  glEnd();
163  glBegin(GL_QUADS);
164  glVertex2d(-1.7, .5);
165  glVertex2d(-1.7, -.5);
166  glVertex2d(1.7, -.5);
167  glVertex2d(1.7, .5);
168  glEnd();
169 
170  // first Arrow
171  glTranslated(1.5, 0, 0);
172  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
174 
175  // second Arrow
176  glTranslated(-3, 0, 0);
177  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
179 
180  // Pop poligon matrix
181  glPopMatrix();
182 
183  // Pop detector matrix
184  glPopMatrix();
185 
186  // Check if the distance is enought to draw details
187  if (s.scale * exaggeration >= 10) {
188  // Draw icon
190 
191  // Show Lock icon depending of the Edit mode
192  drawLockIcon(0.4);
193  }
194  // Draw name
195  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
196 
197  // pop gl identificator
198  glPopName();
199 }
200 
201 
202 std::string
204  switch (key) {
205  case SUMO_ATTR_ID:
206  return getAdditionalID();
207  case SUMO_ATTR_LANE:
209  case SUMO_ATTR_POSITION:
210  return toString(myPosition.x());
212  return toString(myBlocked);
213  default:
214  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
215  }
216 }
217 
218 
219 void
220 GNEDetectorExit::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
221  if (value == getAttribute(key)) {
222  return; //avoid needless changes, later logic relies on the fact that attributes have changed
223  }
224  switch (key) {
225  case SUMO_ATTR_ID:
226  case SUMO_ATTR_LANE:
227  case SUMO_ATTR_POSITION:
229  undoList->p_add(new GNEChange_Attribute(this, key, value));
230  updateGeometry();
231  break;
232  default:
233  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
234  }
235 
236 }
237 
238 
239 bool
240 GNEDetectorExit::isValid(SumoXMLAttr key, const std::string& value) {
241  switch (key) {
242  case SUMO_ATTR_ID:
243  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
244  return true;
245  } else {
246  return false;
247  }
248  case SUMO_ATTR_LANE:
249  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
250  return true;
251  } else {
252  return false;
253  }
254  case SUMO_ATTR_POSITION:
255  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 0 && parse<SUMOReal>(value) <= (myLane->getLaneParametricLenght()));
257  return canParse<bool>(value);
258  default:
259  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
260  }
261 }
262 
263 void
264 GNEDetectorExit::setAttribute(SumoXMLAttr key, const std::string& value) {
265  switch (key) {
266  case SUMO_ATTR_ID:
267  setAdditionalID(value);
268  break;
269  case SUMO_ATTR_LANE:
270  changeLane(value);
271  break;
272  case SUMO_ATTR_POSITION:
273  myPosition = Position(parse<SUMOReal>(value), 0);
274  updateGeometry();
275  getViewNet()->update();
276  break;
278  myBlocked = parse<bool>(value);
279  getViewNet()->update();
280  break;
281  default:
282  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
283  }
284 }
285 
286 /****************************************************************************/
SUMOReal getExaggeration(const GUIVisualizationSettings &s, SUMOReal factor=20) const
return the drawing size including exaggeration and constantSize values
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GUIVisualizationTextSettings addName
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
GNELane * myLane
The lane this additional belongs.
Stores the information about how to visualize structures.
bool isAdditionalSelected() const
GNEDetectorE3 * getE3Parent() const
get E3 Detector parent
static void drawBoxLine(const Position &beg, SUMOReal rot, SUMOReal visLength, SUMOReal width, SUMOReal offset=0)
Draws a thick line.
Definition: GLHelper.cpp:130
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
void updateGeometryByParent()
update pre-computed geometry information called by E3 parent
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
GUIGlID getGlID() const
Returns the numerical id of the object.
static void drawTriangleAtEnd(const Position &p1, const Position &p2, SUMOReal tLength, SUMOReal tWidth)
Draws a triangle at the end of the given line.
Definition: GLHelper.cpp:422
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
RGBColor myBaseColorSelected
base color selected (Default blue)
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
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
std::vector< SUMOReal > myShapeLengths
The lengths of the shape parts.
const std::string & getAdditionalID() const
returns the ID of additional
void updateGeometry()
update pre-computed geometry information
void drawDetectorIcon(const int GNELogoID, SUMOReal sizex=0.5, SUMOReal sizey=0.5) const
SUMOReal getLaneParametricLenght() const
returns the parameteric length of the lane
Definition: GNELane.cpp:677
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
~GNEDetectorExit()
destructor
an e3 exit point
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
Position myDetectorLogoOffset
The position of detector.
Definition: GNEDetector.h:158
friend class GNEChange_Attribute
declare friend class
GNEDetectorExit(GNEViewNet *viewNet, GNEDetectorE3 *parent, GNELane *lane, SUMOReal pos)
Constructor.
Position getPositionInView() const
Returns position of detector Exit in view.
block movement of a graphic element
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
void drawLockIcon(SUMOReal size=0.5) const
draw lock icon
void setAdditionalID(const std::string &id)
set the ID of additional
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
void changeLane(const std::string &laneID)
change lane of additional
std::string getAttribute(SumoXMLAttr key) const
Definition: GNELane.cpp:742
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1265
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) ...
RGBColor myBaseColor
base color (Default green)
std::vector< SUMOReal > myShapeRotations
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:989
Position getLineCenter() const
get line center
SumoXMLTag getTag() const
get XML Tag assigned to this object
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
Position myPosition
The position in which this additional element is located.
std::string getAttribute(SumoXMLAttr key) const
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
#define SUMOReal
Definition: config.h:208
GNEDetectorE3 * myE3Parent
pointer to E3 parent
void updateGeometry()
update pre-computed geometry information
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
Position myBlockIconPosition
position of the block icon