SUMO - Simulation of Urban MObility
GNEDetectorEntry.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 "GNEDetectorEntry.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 // member method definitions
64 // ===========================================================================
65 
67  GNEDetector(parent->generateEntryID(), viewNet, SUMO_TAG_DET_ENTRY, ICON_E3ENTRY, lane, pos, 0, ""),
68  myE3Parent(parent) {
69  // Update geometry
71  // Set colors
72  myBaseColor = RGBColor(0, 204, 0, 255);
73  myBaseColorSelected = RGBColor(125, 204, 0, 255);
74 }
75 
76 
78 
79 
80 void
83 }
84 
85 
86 void
88  // Clear all containers
89  myShapeRotations.clear();
90  myShapeLengths.clear();
91 
92  // clear Shape
93  myShape.clear();
94 
95  // Get shape of lane parent
97 
98  // Save rotation (angle) of the vector constructed by points f and s
100 
101  // Set block icon position
103 
104  // Set offset of logo
106 
107  // Set block icon rotation, and using their rotation for logo
109 
110  // Refresh element (neccesary to avoid grabbing problems)
112 }
113 
114 Position
117 }
118 
119 
122  return myE3Parent;
123 }
124 
125 
126 void
128  // This additional cannot be writted calling this function because is writted by their E3Parent
129 }
130 
131 
132 void
134  // Start drawing adding gl identificator
135  glPushName(getGlID());
136 
137  // Push detector matrix
138  glPushMatrix();
139  glTranslated(0, 0, getType());
140 
141  // Set initial values
142  if (isAdditionalSelected()) {
144  } else {
145  glColor3d(myBaseColor.red(), myBaseColor.green(), myBaseColor.blue());
146  }
147  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
148  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
149 
150  // Push poligon matrix
151  glPushMatrix();
152  glScaled(exaggeration, exaggeration, 1);
153  glTranslated(myShape[0].x(), myShape[0].y(), 0);
154  glRotated(myShapeRotations[0], 0, 0, 1);
155 
156  // Draw poligon
157  glBegin(GL_LINES);
158  glVertex2d(1.7, 0);
159  glVertex2d(-1.7, 0);
160  glEnd();
161  glBegin(GL_QUADS);
162  glVertex2d(-1.7, .5);
163  glVertex2d(-1.7, -.5);
164  glVertex2d(1.7, -.5);
165  glVertex2d(1.7, .5);
166  glEnd();
167 
168  // first Arrow
169  glTranslated(1.5, 0, 0);
170  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
172 
173  // second Arrow
174  glTranslated(-3, 0, 0);
175  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
177 
178  // Pop poligon matrix
179  glPopMatrix();
180 
181  // Pop detector matrix
182  glPopMatrix();
183 
184  // Check if the distance is enought to draw details
185  if (s.scale * exaggeration >= 10) {
186  // Draw icon
188 
189  // Show Lock icon depending of the Edit mode
190  drawLockIcon(0.4);
191  }
192  // Draw name
193  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
194 
195  // pop gl identificator
196  glPopName();
197 }
198 
199 
200 std::string
202  switch (key) {
203  case SUMO_ATTR_ID:
204  return getAdditionalID();
205  case SUMO_ATTR_LANE:
207  case SUMO_ATTR_POSITION:
208  return toString(myPosition.x());
210  return toString(myBlocked);
211  default:
212  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
213  }
214 }
215 
216 
217 void
218 GNEDetectorEntry::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
219  if (value == getAttribute(key)) {
220  return; //avoid needless changes, later logic relies on the fact that attributes have changed
221  }
222  switch (key) {
223  case SUMO_ATTR_ID:
224  case SUMO_ATTR_LANE:
225  case SUMO_ATTR_POSITION:
227  undoList->p_add(new GNEChange_Attribute(this, key, value));
228  updateGeometry();
229  break;
230  default:
231  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
232  }
233 }
234 
235 
236 bool
237 GNEDetectorEntry::isValid(SumoXMLAttr key, const std::string& value) {
238  switch (key) {
239  case SUMO_ATTR_ID:
240  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
241  return true;
242  } else {
243  return false;
244  }
245  case SUMO_ATTR_LANE:
246  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
247  return true;
248  } else {
249  return false;
250  }
251  case SUMO_ATTR_POSITION:
252  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 0 && parse<SUMOReal>(value) <= (myLane->getLaneParametricLenght()));
254  return canParse<bool>(value);
255  default:
256  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
257  }
258 }
259 
260 void
261 GNEDetectorEntry::setAttribute(SumoXMLAttr key, const std::string& value) {
262  switch (key) {
263  case SUMO_ATTR_ID:
264  setAdditionalID(value);
265  break;
266  case SUMO_ATTR_LANE:
267  changeLane(value);
268  break;
269  case SUMO_ATTR_POSITION:
270  myPosition = Position(parse<SUMOReal>(value), 0);
271  updateGeometry();
272  getViewNet()->update();
273  break;
275  myBlocked = parse<bool>(value);
276  getViewNet()->update();
277  break;
278  default:
279  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
280  }
281 }
282 
283 /****************************************************************************/
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.
Position getPositionInView() const
Returns position of detector Entry in view.
GNEDetectorE3 * myE3Parent
pointer to E3 parent
GUIVisualizationTextSettings addName
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
GNELane * myLane
The lane this additional belongs.
Stores the information about how to visualize structures.
bool isAdditionalSelected() const
GNEDetectorEntry(GNEViewNet *viewNet, GNEDetectorE3 *parent, GNELane *lane, SUMOReal pos)
Constructor.
static void drawBoxLine(const Position &beg, SUMOReal rot, SUMOReal visLength, SUMOReal width, SUMOReal offset=0)
Draws a thick line.
Definition: GLHelper.cpp:130
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
~GNEDetectorEntry()
destructor
void updateGeometry()
update pre-computed geometry information
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
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)
an e3 entry point
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
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.
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
std::string getAttribute(SumoXMLAttr key) const
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
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
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
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
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
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)
GNEDetectorE3 * myE3Parent
pointer to E3 parent (used by Entry/exits)
std::vector< SUMOReal > myShapeRotations
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:989
Position getLineCenter() const
get line center
void updateGeometryByParent()
update pre-computed geometry information called by E3 parent
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.
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
#define SUMOReal
Definition: config.h:208
GNEDetectorE3 * getE3Parent() const
get E3 Detector parent
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
Position myBlockIconPosition
position of the block icon