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