SUMO - Simulation of Urban MObility
GNEDetectorE1.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
29 #include <utils/common/ToString.h>
30 #include <utils/geom/GeomHelper.h>
35 #include <utils/gui/div/GLHelper.h>
40 #include <netedit/GNEViewNet.h>
41 #include <netedit/GNEUndoList.h>
42 #include <netedit/GNENet.h>
45 #include <netedit/GNEViewParent.h>
46 
47 #include "GNEDetectorE1.h"
48 
49 
50 // ===========================================================================
51 // member method definitions
52 // ===========================================================================
53 
54 GNEDetectorE1::GNEDetectorE1(const std::string& id, GNELane* lane, GNEViewNet* viewNet, double pos, double freq, const std::string& filename, const std::string& vehicleTypes, const std::string& name, bool friendlyPos, bool blockMovement) :
55  GNEDetector(id, viewNet, GLO_E1DETECTOR, SUMO_TAG_E1DETECTOR, lane, pos, freq, filename, vehicleTypes, name, friendlyPos, blockMovement) {
56 }
57 
58 
60 }
61 
62 
63 void
65  // first check if object has to be removed from grid (SUMOTree)
66  if (updateGrid) {
68  }
69 
70  // Clear all containers
71  myShapeRotations.clear();
72  myShapeLengths.clear();
73 
74  // clear Shape
75  myShape.clear();
76 
77  // obtain position over lane
79  myShape.push_back(myLane->getShape().positionAtOffset(fixedPositionOverLane * myLane->getLengthGeometryFactor()));
80 
81  // Obtain first position
82  Position f = myShape[0] - Position(1, 0);
83 
84  // Obtain next position
85  Position s = myShape[0] + Position(1, 0);
86 
87  // Save rotation (angle) of the vector constructed by points f and s
88  myShapeRotations.push_back(myLane->getShape().rotationDegreeAtOffset(fixedPositionOverLane) * -1);
89 
90  // Set block icon position
92 
93  // Set offset of the block icon
94  myBlockIconOffset = Position(-1, 0);
95 
96  // Set block icon rotation, and using their rotation for logo
98 
99  // last step is to check if object has to be added into grid (SUMOTree) again
100  if (updateGrid) {
102  }
103 }
104 
106  // with friendly position enabled position are "always fixed"
107  if (myFriendlyPosition) {
108  return true;
109  } else {
111  }
112 }
113 
114 
115 void
117  // get values
118  glPushName(getGlID());
119  double width = (double) 2.0 * s.scale;
120  glLineWidth(1.0);
121  const double exaggeration = s.addSize.getExaggeration(s);
122 
123  // set color
126  } else {
127  GLHelper::setColor(RGBColor(255, 255, 0));
128  }
129  // draw shape
130  glPushMatrix();
131  glTranslated(0, 0, getType());
132  glTranslated(myShape[0].x(), myShape[0].y(), 0);
133  glRotated(myShapeRotations[0], 0, 0, 1);
134  glScaled(exaggeration, exaggeration, 1);
135  glBegin(GL_QUADS);
136  glVertex2d(-1.0, 2);
137  glVertex2d(-1.0, -2);
138  glVertex2d(1.0, -2);
139  glVertex2d(1.0, 2);
140  glEnd();
141  glTranslated(0, 0, .01);
142  glBegin(GL_LINES);
143  glVertex2d(0, 2 - .1);
144  glVertex2d(0, -2 + .1);
145  glEnd();
146 
147  // outline if isn't being drawn for selecting
148  if ((width * exaggeration > 1) && !s.drawForSelecting) {
149  // set color
152  } else {
154  }
155  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
156  glBegin(GL_QUADS);
157  glVertex2f(-1.0, 2);
158  glVertex2f(-1.0, -2);
159  glVertex2f(1.0, -2);
160  glVertex2f(1.0, 2);
161  glEnd();
162  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
163  }
164 
165  // position indicator if isn't being drawn for selecting
166  if ((width * exaggeration > 1) && !s.drawForSelecting) {
167  // set color
170  } else {
172  }
173  glRotated(90, 0, 0, -1);
174  glBegin(GL_LINES);
175  glVertex2d(0, 1.7);
176  glVertex2d(0, -1.7);
177  glEnd();
178  }
179 
180  // Pop shape matrix
181  glPopMatrix();
182 
183  // Check if the distance is enought to draw details and isn't being drawn for selecting
184  if ((s.scale * exaggeration >= 10) && !s.drawForSelecting) {
185  // Push matrix
186  glPushMatrix();
187  // Traslate to center of detector
188  glTranslated(myShape.getLineCenter().x(), myShape.getLineCenter().y(), getType() + 0.1);
189  // Rotate depending of myBlockIconRotation
190  glRotated(myBlockIconRotation, 0, 0, -1);
191  //move to logo position
192  glTranslated(-1, 0, 0);
193  // draw E1 logo
196  } else {
197  GLHelper::drawText("E1", Position(), .1, 1.5, RGBColor::BLACK);
198  }
199  // pop matrix
200  glPopMatrix();
201  // Show Lock icon depending of the Edit mode
202  drawLockIcon();
203  }
204 
205  // Finish draw if isn't being drawn for selecting
206  if (!s.drawForSelecting) {
207  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
208  }
209 
210  // check if dotted contour has to be drawn
211  if (!s.drawForSelecting && (myViewNet->getACUnderCursor() == this)) {
213  }
214 
215  // pop name
216  glPopName();
217 }
218 
219 
220 std::string
222  switch (key) {
223  case SUMO_ATTR_ID:
224  return getAdditionalID();
225  case SUMO_ATTR_LANE:
226  return myLane->getID();
227  case SUMO_ATTR_POSITION:
229  case SUMO_ATTR_FREQUENCY:
230  return toString(myFreq);
231  case SUMO_ATTR_NAME:
232  return myAdditionalName;
233  case SUMO_ATTR_FILE:
234  return myFilename;
235  case SUMO_ATTR_VTYPES:
236  return myVehicleTypes;
240  return toString(myBlockMovement);
241  case GNE_ATTR_SELECTED:
243  case GNE_ATTR_GENERIC:
244  return getGenericParametersStr();
245  default:
246  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
247  }
248 }
249 
250 
251 void
252 GNEDetectorE1::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
253  if (value == getAttribute(key)) {
254  return; //avoid needless changes, later logic relies on the fact that attributes have changed
255  }
256  switch (key) {
257  case SUMO_ATTR_ID:
258  case SUMO_ATTR_LANE:
259  case SUMO_ATTR_POSITION:
260  case SUMO_ATTR_FREQUENCY:
261  case SUMO_ATTR_NAME:
262  case SUMO_ATTR_FILE:
263  case SUMO_ATTR_VTYPES:
266  case GNE_ATTR_SELECTED:
267  case GNE_ATTR_GENERIC:
268  undoList->p_add(new GNEChange_Attribute(this, key, value));
269  break;
270  default:
271  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
272  }
273 
274 }
275 
276 
277 bool
278 GNEDetectorE1::isValid(SumoXMLAttr key, const std::string& value) {
279  switch (key) {
280  case SUMO_ATTR_ID:
281  return isValidAdditionalID(value);
282  case SUMO_ATTR_LANE:
283  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
284  return true;
285  } else {
286  return false;
287  }
288  case SUMO_ATTR_POSITION:
289  return canParse<double>(value);
290  case SUMO_ATTR_FREQUENCY:
291  return (canParse<double>(value) && (parse<double>(value) >= 0));
292  case SUMO_ATTR_NAME:
294  case SUMO_ATTR_FILE:
296  case SUMO_ATTR_VTYPES:
297  if (value.empty()) {
298  return true;
299  } else {
301  }
303  return canParse<bool>(value);
305  return canParse<bool>(value);
306  case GNE_ATTR_SELECTED:
307  return canParse<bool>(value);
308  case GNE_ATTR_GENERIC:
309  return isGenericParametersValid(value);
310  default:
311  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
312  }
313 }
314 
315 // ===========================================================================
316 // private
317 // ===========================================================================
318 
319 void
320 GNEDetectorE1::setAttribute(SumoXMLAttr key, const std::string& value) {
321  switch (key) {
322  case SUMO_ATTR_ID:
323  changeAdditionalID(value);
324  break;
325  case SUMO_ATTR_LANE:
326  myLane = changeLane(myLane, value);
327  break;
328  case SUMO_ATTR_POSITION:
329  myPositionOverLane = parse<double>(value);
330  break;
331  case SUMO_ATTR_FREQUENCY:
332  myFreq = parse<double>(value);
333  break;
334  case SUMO_ATTR_FILE:
335  myFilename = value;
336  break;
337  case SUMO_ATTR_NAME:
338  myAdditionalName = value;
339  break;
340  case SUMO_ATTR_VTYPES:
341  myVehicleTypes = value;
342  break;
344  myFriendlyPosition = parse<bool>(value);
345  break;
347  myBlockMovement = parse<bool>(value);
348  break;
349  case GNE_ATTR_SELECTED:
350  if (parse<bool>(value)) {
352  } else {
354  }
355  break;
356  case GNE_ATTR_GENERIC:
358  break;
359  default:
360  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
361  }
362  // After setting attribute always update Geometry
363  updateGeometry(true);
364 }
365 
366 /****************************************************************************/
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
const GNEAttributeCarrier * getACUnderCursor() const
get AttributeCarrier under cursor
double scale
information about a lane&#39;s width (temporary, used for a single view)
void setBlockIconRotation(GNELane *additionalLane=nullptr)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
static bool isValidListOfTypeID(const std::string &value)
whether the given string is a valid list of ids for an edge or vehicle type (empty aren&#39;t allowed) ...
GUIVisualizationTextSettings addName
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
static const RGBColor WHITE
Definition: RGBColor.h:179
GNEDetectorE1(const std::string &id, GNELane *lane, GNEViewNet *viewNet, double pos, double freq, const std::string &filename, const std::string &vehicleTypes, const std::string &name, bool friendlyPos, bool blockMovement)
Constructor.
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:61
double x() const
Returns the x-position.
Definition: Position.h:56
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
double myFreq
The aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.h:153
~GNEDetectorE1()
Destructor.
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, int align=0, double width=-1)
Definition: GLHelper.cpp:611
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
static const RGBColor BLACK
Definition: RGBColor.h:180
std::vector< double > myShapeRotations
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
Position getLineCenter() const
get line center
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.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:105
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:49
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1230
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
std::string myAdditionalName
name of additional
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1167
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
block movement of a graphic element
std::string myVehicleTypes
attribute vehicle types
Definition: GNEDetector.h:159
double getLengthGeometryFactor() const
get lenght geometry factor
Definition: GNELane.cpp:1287
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
const std::string getID() const
function to support debugging
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:162
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:3523
Position myBlockIconOffset
The offSet of the block icon.
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:156
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
void updateGeometry(bool updateGrid)
update pre-computed geometry information
std::string getAttribute(SumoXMLAttr key) const
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:613
static void drawShapeDottedContour(const int type, const PositionVector &shape, const double width)
draw a dotted contour around the given Non closed shape with certain width
Definition: GLHelper.cpp:471
bool isDetectorPositionFixed() const
check if Position of detector is fixed
a E1 detector
element is selected
GNELane * myLane
The lane in which this detector is placed.
Definition: GNEDetector.h:147
std::string getGenericParametersStr() const
return generic parameters in string format
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
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
static const RGBColor selectionColor
Definition: GNENet.h:96
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:586
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1160
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name) ...
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1066
double myBlockIconRotation
The rotation of the block icon.
GNELane * changeLane(GNELane *oldLane, const std::string &newLaneID)
change lane of additional
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:150
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get XML Tag assigned to this object