SUMO - Simulation of Urban MObility
GNEDetectorEntry.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 //
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, bool friendlyPos) :
64  GNEDetector(parent->generateEntryID(), viewNet, SUMO_TAG_DET_ENTRY, ICON_E3ENTRY, lane, pos, 0, "", friendlyPos),
65  myE3Parent(parent) {
66  // Update geometry
68 }
69 
70 
72 
73 
74 void
77 }
78 
79 
80 void
82  // Clear all containers
83  myShapeRotations.clear();
84  myShapeLengths.clear();
85 
86  // clear Shape
87  myShape.clear();
88 
89  // obtain position over lane
90  double fixedPositionOverLane = myPositionOverLane > 1 ? 1 : myPositionOverLane < 0 ? 0 : myPositionOverLane;
91  myShape.push_back(myLane->getShape().positionAtOffset(fixedPositionOverLane * myLane->getShape().length()));
92 
93  // Save rotation (angle) of the vector constructed by points f and s
94  myShapeRotations.push_back(myLane->getShape().rotationDegreeAtOffset(fixedPositionOverLane * myLane->getShape().length()) * -1);
95 
96  // Set block icon position
98 
99  // Set block icon rotation, and using their rotation for logo
101 
102  // Refresh element (neccesary to avoid grabbing problems)
104 }
105 
106 
109  return myE3Parent;
110 }
111 
112 
113 void
115  // This additional cannot be writted calling this function because is writted by their E3Parent
116 }
117 
118 
120  // with friendly position enabled position are "always fixed"
121  if (myFriendlyPosition) {
122  return true;
123  } else {
124  // floors are needed to avoid precision problems
125  return ((floor(myPositionOverLane * 1000) / 1000) >= 0) && ((floor(myPositionOverLane * 1000) / 1000) <= 1);
126  }
127 }
128 
129 
130 void
132  // Start drawing adding gl identificator
133  glPushName(getGlID());
134 
135  // Push detector matrix
136  glPushMatrix();
137  glTranslated(0, 0, getType());
138 
139  // Set initial values
140  if (isAdditionalSelected()) {
142  } else {
143  GLHelper::setColor(RGBColor(0, 204, 0));
144  }
145  const double exaggeration = s.addSize.getExaggeration(s);
146  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
147 
148  // Push polygon matrix
149  glPushMatrix();
150  glScaled(exaggeration, exaggeration, 1);
151  glTranslated(myShape[0].x(), myShape[0].y(), 0);
152  glRotated(myShapeRotations[0], 0, 0, 1);
153 
154  // Draw polygon
155  glBegin(GL_LINES);
156  glVertex2d(1.7, 0);
157  glVertex2d(-1.7, 0);
158  glEnd();
159  glBegin(GL_QUADS);
160  glVertex2d(-1.7, .5);
161  glVertex2d(-1.7, -.5);
162  glVertex2d(1.7, -.5);
163  glVertex2d(1.7, .5);
164  glEnd();
165 
166  // first Arrow
167  glTranslated(1.5, 0, 0);
168  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
169  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
170 
171  // second Arrow
172  glTranslated(-3, 0, 0);
173  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
174  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
175 
176  // Pop polygon matrix
177  glPopMatrix();
178 
179  // Pop detector matrix
180  glPopMatrix();
181 
182  // Check if the distance is enought to draw details
183  if (s.scale * exaggeration >= 10) {
184  // Push matrix
185  glPushMatrix();
186  // Traslate to center of detector
187  glTranslated(myShape.getLineCenter().x(), myShape.getLineCenter().y(), getType() + 0.1);
188  // Rotate depending of myBlockIconRotation
189  glRotated(myBlockIconRotation, 0, 0, -1);
190  //move to logo position
191  glTranslated(1.9, 0, 0);
192  // draw E2 logo
193  if (isAdditionalSelected()) {
195  } else {
196  GLHelper::drawText("E3", Position(), .1, 2.8, RGBColor(0, 204, 0));
197  }
198  //move to logo position
199  glTranslated(1.7, 0, 0);
200  // Rotate depending of myBlockIconRotation
201  glRotated(90, 0, 0, 1);
202  // draw E2 logo
203  if (isAdditionalSelected()) {
205  } else {
206  GLHelper::drawText("Entry", Position(), .1, 1, RGBColor(0, 204, 0));
207  }
208  // pop matrix
209  glPopMatrix();
210  // Show Lock icon depending of the Edit mode
211  drawLockIcon(0.4);
212  }
213  // Draw name
214  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
215 
216  // pop gl identificator
217  glPopName();
218 }
219 
220 
221 std::string
223  switch (key) {
224  case SUMO_ATTR_ID:
225  return getAdditionalID();
226  case SUMO_ATTR_LANE:
228  case SUMO_ATTR_POSITION:
233  return toString(myBlocked);
234  default:
235  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
236  }
237 }
238 
239 
240 void
241 GNEDetectorEntry::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
242  if (value == getAttribute(key)) {
243  return; //avoid needless changes, later logic relies on the fact that attributes have changed
244  }
245  switch (key) {
246  case SUMO_ATTR_ID:
247  case SUMO_ATTR_LANE:
248  case SUMO_ATTR_POSITION:
251  undoList->p_add(new GNEChange_Attribute(this, key, value));
252  updateGeometry();
253  break;
254  default:
255  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
256  }
257 }
258 
259 
260 bool
261 GNEDetectorEntry::isValid(SumoXMLAttr key, const std::string& value) {
262  switch (key) {
263  case SUMO_ATTR_ID:
264  if (isValidID(value) && (myViewNet->getNet()->getAdditional(getTag(), value) == NULL)) {
265  return true;
266  } else {
267  return false;
268  }
269  case SUMO_ATTR_LANE:
270  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
271  return true;
272  } else {
273  return false;
274  }
275  case SUMO_ATTR_POSITION:
276  return canParse<double>(value);
278  return canParse<bool>(value);
280  return canParse<bool>(value);
281  default:
282  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
283  }
284 }
285 
286 void
287 GNEDetectorEntry::setAttribute(SumoXMLAttr key, const std::string& value) {
288  switch (key) {
289  case SUMO_ATTR_ID:
290  setAdditionalID(value);
291  break;
292  case SUMO_ATTR_LANE:
293  changeLane(value);
294  break;
295  case SUMO_ATTR_POSITION:
296  myPositionOverLane = parse<double>(value) / myLane->getLaneParametricLength();
297  updateGeometry();
298  getViewNet()->update();
299  break;
301  myFriendlyPosition = parse<bool>(value);
302  getViewNet()->update();
303  break;
305  myBlocked = parse<bool>(value);
306  getViewNet()->update();
307  break;
308  default:
309  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
310  }
311 }
312 
313 /****************************************************************************/
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
void setBlockIconRotation()
GNEDetectorE3 * myE3Parent
pointer to E3 parent
double scale
information about a lane&#39;s width (temporary, used for a single view)
GUIVisualizationTextSettings addName
double x() const
Returns the x-position.
Definition: Position.h:63
GNELane * myLane
The lane this additional belongs.
Stores the information about how to visualize structures.
bool isAdditionalSelected() const
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
GNEDetectorEntry(GNEViewNet *viewNet, GNEDetectorE3 *parent, GNELane *lane, double pos, bool friendlyPos)
Constructor.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
~GNEDetectorEntry()
destructor
void updateGeometry()
update pre-computed geometry information
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::vector< double > myShapeRotations
GUIGlID getGlID() const
Returns the numerical id of the object.
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 ...
void writeAdditional(OutputDevice &device, bool volatileOptionsEnabled) const
writte additional element into a xml file
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:112
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
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:56
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:438
const std::string & getAdditionalID() const
returns the ID of additional
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in allGNEAttributeCarrier.
void updateGeometry()
update pre-computed geometry information
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:998
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:958
friend class GNEChange_Attribute
declare friend class
double y() const
Returns the y-position.
Definition: Position.h:68
block movement of a graphic element
double length() const
Returns the length.
std::vector< double > myShapeLengths
The lengths of the shape parts.
bool isDetectorPositionFixed() const
check if Position of detector is fixed
double getAbsolutePositionOverLane() const
get absolute position over Lane
void setAdditionalID(const std::string &id)
set the ID of additional
void drawLockIcon(double size=0.5) const
draw lock icon
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:164
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
This functions has to be implemented in allGNEAttributeCarrier.
Definition: GNELane.cpp:770
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1680
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:625
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
GNEDetectorE3 * myE3Parent
pointer to E3 parent (used by Entry/exits)
GNENet * getNet() const
get the net object
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 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:417
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:126
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0)
draw Text with given parameters
Definition: GLHelper.cpp:455
GNEDetectorE3 * getE3Parent() const
get E3 Detector parent
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:719
double myBlockIconRotation
The rotation of the block icon.
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:155
Position myBlockIconPosition
position of the block icon