SUMO - Simulation of Urban MObility
GNEDetectorE3.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>
30 #include <utils/common/ToString.h>
31 #include <utils/geom/GeomHelper.h>
36 #include <utils/gui/div/GLHelper.h>
42 #include <netedit/GNEViewNet.h>
43 #include <netedit/GNEUndoList.h>
44 #include <netedit/GNENet.h>
47 #include <netedit/GNEViewParent.h>
48 
49 #include "GNEDetectorE3.h"
50 #include "GNEDetectorEntry.h"
51 #include "GNEDetectorExit.h"
52 
53 
54 // ===========================================================================
55 // member method definitions
56 // ===========================================================================
57 
58 GNEDetectorE3::GNEDetectorE3(const std::string& id, GNEViewNet* viewNet, Position pos, double freq, const std::string& filename, const std::string& vehicleTypes, const std::string& name, const double timeThreshold, double speedThreshold, bool blockMovement) :
59  GNEAdditional(id, viewNet, GLO_E3DETECTOR, SUMO_TAG_E3DETECTOR, name, blockMovement),
60  myPosition(pos),
61  myFreq(freq),
62  myFilename(filename),
63  myVehicleTypes(vehicleTypes),
64  myTimeThreshold(timeThreshold),
65  mySpeedThreshold(speedThreshold) {
66 }
67 
68 
70 
71 
72 void
74  // first check if object has to be removed from grid (SUMOTree)
75  if (updateGrid) {
77  }
78 
79  // Clear shape
80  myShape.clear();
81 
82  // Set block icon position
84 
85  // Set block icon offset
86  myBlockIconOffset = Position(-0.5, -0.5);
87 
88  // Set block icon rotation, and using their rotation for draw logo
90 
91  // Set position
92  myShape.push_back(myPosition);
93 
94  // Update connection's geometry
96 
97  // last step is to check if object has to be added into grid (SUMOTree) again
98  if (updateGrid) {
100  }
101 }
102 
103 
104 Position
106  return myPosition;
107 }
108 
109 
110 void
111 GNEDetectorE3::moveGeometry(const Position& oldPos, const Position& offset) {
112  // restore old position, apply offset and update Geometry
113  myPosition = oldPos;
114  myPosition.add(offset);
115  updateGeometry(false);
116 }
117 
118 
119 void
121  // commit new position allowing undo/redo
122  undoList->p_begin("position of " + toString(getTag()));
123  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(myPosition), true, toString(oldPos)));
124  undoList->p_end();
125 }
126 
127 
128 std::string
130  return myViewNet->getNet()->getMicrosimID();
131 }
132 
133 
134 void
136  // Start drawing adding an gl identificator
137  glPushName(getGlID());
138 
139  // Add a draw matrix for drawing logo
140  glPushMatrix();
141  glTranslated(myShape[0].x(), myShape[0].y(), getType());
142 
143  // Draw icon depending of detector is selected and if isn't being drawn for selecting
144  if (s.drawForSelecting) {
146  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
147  } else {
148  glColor3d(1, 1, 1);
149  glRotated(180, 0, 0, 1);
152  } else {
154  }
155  }
156 
157  // Pop logo matrix
158  glPopMatrix();
159  if (!s.drawForSelecting) {
160  // Show Lock icon depending of the Edit mode
161  drawLockIcon(0.4);
162  // Draw connections
164  }
165  // Draw name if isn't being drawn for selecting
166  if (!s.drawForSelecting) {
167  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
168  }
169  // check if dotted contour has to be drawn
170  if (!s.drawForSelecting && (myViewNet->getACUnderCursor() == this)) {
172  // draw shape dotte contour aroud alld connections between child and parents
173  for (auto i : myChildConnectionPositions) {
175  }
176  }
177  // Pop name
178  glPopName();
179 }
180 
181 
182 std::string
184  switch (key) {
185  case SUMO_ATTR_ID:
186  return getAdditionalID();
187  case SUMO_ATTR_POSITION:
188  return toString(myPosition);
189  case SUMO_ATTR_FREQUENCY:
190  return toString(myFreq);
191  case SUMO_ATTR_NAME:
192  return myAdditionalName;
193  case SUMO_ATTR_FILE:
194  return myFilename;
195  case SUMO_ATTR_VTYPES:
196  return myVehicleTypes;
198  return toString(myTimeThreshold);
200  return toString(mySpeedThreshold);
202  return toString(myBlockMovement);
203  case GNE_ATTR_SELECTED:
205  case GNE_ATTR_GENERIC:
206  return getGenericParametersStr();
207  default:
208  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
209  }
210 }
211 
212 
213 void
214 GNEDetectorE3::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
215  if (value == getAttribute(key)) {
216  return; //avoid needless changes, later logic relies on the fact that attributes have changed
217  }
218  switch (key) {
219  case SUMO_ATTR_ID: {
220  // change ID of Entry
221  undoList->p_add(new GNEChange_Attribute(this, key, value));
222  // Change Ids of all Entry/Exits childs
223  for (auto i : myAdditionalChilds) {
224  i->setAttribute(SUMO_ATTR_ID, generateAdditionalChildID(i->getTag()), undoList);
225  }
226  break;
227  }
228  case SUMO_ATTR_FREQUENCY:
229  case SUMO_ATTR_POSITION:
230  case SUMO_ATTR_NAME:
231  case SUMO_ATTR_FILE:
232  case SUMO_ATTR_VTYPES:
236  case GNE_ATTR_SELECTED:
237  case GNE_ATTR_GENERIC:
238  undoList->p_add(new GNEChange_Attribute(this, key, value));
239  break;
240  default:
241  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
242  }
243 }
244 
245 
246 bool
247 GNEDetectorE3::isValid(SumoXMLAttr key, const std::string& value) {
248  switch (key) {
249  case SUMO_ATTR_ID:
250  return isValidAdditionalID(value);
251  case SUMO_ATTR_POSITION:
252  return canParse<Position>(value);
253  case SUMO_ATTR_FREQUENCY:
254  return canParse<double>(value) && (parse<double>(value) >= 0);
255  case SUMO_ATTR_NAME:
257  case SUMO_ATTR_FILE:
259  case SUMO_ATTR_VTYPES:
260  if (value.empty()) {
261  return true;
262  } else {
264  }
266  return canParse<double>(value) && (parse<double>(value) >= 0);
268  return canParse<double>(value) && (parse<double>(value) >= 0);
270  return canParse<bool>(value);
271  case GNE_ATTR_SELECTED:
272  return canParse<bool>(value);
273  case GNE_ATTR_GENERIC:
274  return isGenericParametersValid(value);
275  default:
276  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
277  }
278 }
279 
280 
281 bool
283  int numEntrys = 0;
284  int numExits = 0;
285  // iterate over additional chidls and obtain number of entrys and exits
286  for (auto i : myAdditionalChilds) {
287  if (i->getTag() == SUMO_TAG_DET_ENTRY) {
288  numEntrys++;
289  } else if (i->getTag() == SUMO_TAG_DET_EXIT) {
290  numExits++;
291  }
292  }
293  // write warnings
294  if (numEntrys == 0) {
295  WRITE_WARNING("An " + toString(SUMO_TAG_E3DETECTOR) + " need at least one " + toString(SUMO_TAG_DET_ENTRY) + " detector");
296  }
297  if (numExits == 0) {
298  WRITE_WARNING("An " + toString(SUMO_TAG_E3DETECTOR) + " need at least one " + toString(SUMO_TAG_DET_EXIT) + " detector");
299  }
300  // return false depending of number of Entrys and Exits
301  return ((numEntrys != 0) && (numExits != 0));
302 }
303 
304 
305 std::string
307  return toString(getTag()) + ":" + getID();
308 }
309 
310 
311 std::string
313  return toString(getTag());
314 }
315 
316 // ===========================================================================
317 // private
318 // ===========================================================================
319 
320 void
321 GNEDetectorE3::setAttribute(SumoXMLAttr key, const std::string& value) {
322  switch (key) {
323  case SUMO_ATTR_ID:
324  changeAdditionalID(value);
325  break;
326  case SUMO_ATTR_POSITION:
327  myPosition = parse<Position>(value);
328  break;
329  case SUMO_ATTR_FREQUENCY:
330  myFreq = parse<double>(value);
331  break;
332  case SUMO_ATTR_NAME:
333  myAdditionalName = value;
334  break;
335  case SUMO_ATTR_FILE:
336  myFilename = value;
337  break;
338  case SUMO_ATTR_VTYPES:
339  myVehicleTypes = value;
340  break;
342  myTimeThreshold = parse<double>(value);
343  break;
345  mySpeedThreshold = parse<double>(value);
346  break;
348  myBlockMovement = parse<bool>(value);
349  break;
350  case GNE_ATTR_SELECTED:
351  if (parse<bool>(value)) {
353  } else {
355  }
356  break;
357  case GNE_ATTR_GENERIC:
359  break;
360  default:
361  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
362  }
363  // After setting attribute always update Geometry
364  updateGeometry(true);
365 }
366 
367 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
double mySpeedThreshold
The speed-based threshold that describes how slow a vehicle has to be to be recognized as halting...
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)
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
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
std::string getAttribute(SumoXMLAttr key) const
Position myPosition
position of E3 in view
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:126
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
std::string myVehicleTypes
attribute vehicle types
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
Position getPositionInView() const
Returns position of additional in view.
Stores the information about how to visualize structures.
double myTimeThreshold
The time-based threshold that describes how much time has to pass until a vehicle is recognized as ha...
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:78
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
bool checkAdditionalChildRestriction() const
check restriction with the number of childs
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
std::vector< PositionVector > myChildConnectionPositions
Matrix with the Vertex&#39;s positions of connections between parents an their childs.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:242
an e3 entry point
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
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.
a E3 detector
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static const RGBColor GREY
Definition: RGBColor.h:181
void drawChildConnections() const
draw connections between Parent and childrens
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
PositionVector myShape
The shape of the additional element.
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:85
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
GNEDetectorE3(const std::string &id, GNEViewNet *viewNet, Position pos, double freq, const std::string &filename, const std::string &vehicleTypes, const std::string &name, const double timeThreshold, double speedThreshold, bool blockMovement)
GNEDetectorE3 Constructor.
an e3 exit point
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:1175
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
block movement of a graphic element
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
void updateChildConnections()
update Connection&#39;s geometry
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
const std::string getID() const
function to support debugging
Position myBlockIconOffset
The offSet of the block icon.
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
std::vector< GNEAdditional * > myAdditionalChilds
vector with the Additional childs
std::string getParentName() const
Returns the name of the parent object (if any)
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void updateGeometry(bool updateGrid)
update pre-computed geometry information
double myFreq
frequency of E3 detector
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
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
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
element is selected
std::string getGenericParametersStr() const
return generic parameters in string format
~GNEDetectorE3()
GNEDetectorE3 Destructor.
GNENet * getNet() const
get the net object
std::string generateAdditionalChildID(SumoXMLTag childTag)
gererate a new ID for an additional child
GUIGlID getGlID() const
Returns the numerical id of the object.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:132
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1168
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name) ...
std::string myFilename
fielname of E3 detector
Position myBlockIconPosition
position of the block icon
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
SumoXMLTag getTag() const
get XML Tag assigned to this object