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 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
27 #include <utils/gui/div/GLHelper.h>
30 
31 #include "GNEDetectorE3.h"
32 
33 
34 // ===========================================================================
35 // member method definitions
36 // ===========================================================================
37 
38 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) :
39  GNEAdditional(id, viewNet, GLO_E3DETECTOR, SUMO_TAG_E3DETECTOR, name, blockMovement),
40  myPosition(pos),
41  myFreq(freq),
42  myFilename(filename),
43  myVehicleTypes(vehicleTypes),
44  myTimeThreshold(timeThreshold),
45  mySpeedThreshold(speedThreshold) {
46 }
47 
48 
50 
51 
52 void
54  // first check if object has to be removed from grid (SUMOTree)
55  if (updateGrid) {
57  }
58 
59  // Clear shape
60  myGeometry.shape.clear();
61 
62  // Set block icon position
64 
65  // Set block icon offset
66  myBlockIcon.offset = Position(-0.5, -0.5);
67 
68  // Set block icon rotation, and using their rotation for draw logo
70 
71  // Set position
72  myGeometry.shape.push_back(myPosition);
73 
74  // Update connection's geometry
76 
77  // last step is to check if object has to be added into grid (SUMOTree) again
78  if (updateGrid) {
80  }
81 }
82 
83 
86  return myPosition;
87 }
88 
89 
90 void
92  // restore old position, apply offset and update Geometry
94  myPosition.add(offset);
95  // filtern position using snap to active grid
96  // filtern position using snap to active grid
98  updateGeometry(false);
99 }
100 
101 
102 void
104  // commit new position allowing undo/redo
105  undoList->p_begin("position of " + getTagStr());
107  undoList->p_end();
108 }
109 
110 
111 std::string
113  return myViewNet->getNet()->getMicrosimID();
114 }
115 
116 
117 void
119  // Start drawing adding an gl identificator
120  glPushName(getGlID());
121 
122  // Add a draw matrix for drawing logo
123  glPushMatrix();
124  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), getType());
125 
126  // Draw icon depending of detector is selected and if isn't being drawn for selecting
127  if (s.drawForSelecting) {
129  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
130  } else {
131  glColor3d(1, 1, 1);
132  glRotated(180, 0, 0, 1);
135  } else {
137  }
138  }
139 
140  // Pop logo matrix
141  glPopMatrix();
142  if (!s.drawForSelecting) {
143  // Show Lock icon depending of the Edit mode
144  myBlockIcon.draw(0.4);
145  // Draw connections
147  }
148  // Draw name if isn't being drawn for selecting
149  if (!s.drawForSelecting) {
150  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
151  }
152  // check if dotted contour has to be drawn
153  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
155  // draw shape dotte contour aroud alld connections between child and parents
156  for (auto i : myChildConnections.connectionPositions) {
158  }
159  }
160  // Pop name
161  glPopName();
162 }
163 
164 
165 std::string
167  switch (key) {
168  case SUMO_ATTR_ID:
169  return getAdditionalID();
170  case SUMO_ATTR_POSITION:
171  return toString(myPosition);
172  case SUMO_ATTR_FREQUENCY:
173  return toString(myFreq);
174  case SUMO_ATTR_NAME:
175  return myAdditionalName;
176  case SUMO_ATTR_FILE:
177  return myFilename;
178  case SUMO_ATTR_VTYPES:
179  return myVehicleTypes;
181  return toString(myTimeThreshold);
183  return toString(mySpeedThreshold);
185  return toString(myBlockMovement);
186  case GNE_ATTR_SELECTED:
188  case GNE_ATTR_GENERIC:
189  return getGenericParametersStr();
190  default:
191  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
192  }
193 }
194 
195 
196 void
197 GNEDetectorE3::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
198  if (value == getAttribute(key)) {
199  return; //avoid needless changes, later logic relies on the fact that attributes have changed
200  }
201  switch (key) {
202  case SUMO_ATTR_ID: {
203  // change ID of Entry
204  undoList->p_add(new GNEChange_Attribute(this, key, value));
205  // Change Ids of all Entry/Exits childs
206  for (auto i : myAdditionalChilds) {
207  i->setAttribute(SUMO_ATTR_ID, generateAdditionalChildID(i->getTagProperty().getTag()), undoList);
208  }
209  break;
210  }
211  case SUMO_ATTR_FREQUENCY:
212  case SUMO_ATTR_POSITION:
213  case SUMO_ATTR_NAME:
214  case SUMO_ATTR_FILE:
215  case SUMO_ATTR_VTYPES:
219  case GNE_ATTR_SELECTED:
220  case GNE_ATTR_GENERIC:
221  undoList->p_add(new GNEChange_Attribute(this, key, value));
222  break;
223  default:
224  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
225  }
226 }
227 
228 
229 bool
230 GNEDetectorE3::isValid(SumoXMLAttr key, const std::string& value) {
231  switch (key) {
232  case SUMO_ATTR_ID:
233  return isValidDetectorID(value);
234  case SUMO_ATTR_POSITION:
235  return canParse<Position>(value);
236  case SUMO_ATTR_FREQUENCY:
237  return canParse<double>(value) && (parse<double>(value) >= 0);
238  case SUMO_ATTR_NAME:
240  case SUMO_ATTR_FILE:
242  case SUMO_ATTR_VTYPES:
243  if (value.empty()) {
244  return true;
245  } else {
247  }
249  return canParse<double>(value) && (parse<double>(value) >= 0);
251  return canParse<double>(value) && (parse<double>(value) >= 0);
253  return canParse<bool>(value);
254  case GNE_ATTR_SELECTED:
255  return canParse<bool>(value);
256  case GNE_ATTR_GENERIC:
257  return isGenericParametersValid(value);
258  default:
259  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
260  }
261 }
262 
263 
264 bool
266  int numEntrys = 0;
267  int numExits = 0;
268  // iterate over additional chidls and obtain number of entrys and exits
269  for (auto i : myAdditionalChilds) {
270  if (i->getTagProperty().getTag() == SUMO_TAG_DET_ENTRY) {
271  numEntrys++;
272  } else if (i->getTagProperty().getTag() == SUMO_TAG_DET_EXIT) {
273  numExits++;
274  }
275  }
276  // write warnings
277  if (numEntrys == 0) {
278  WRITE_WARNING("An " + toString(SUMO_TAG_E3DETECTOR) + " need at least one " + toString(SUMO_TAG_DET_ENTRY) + " detector");
279  }
280  if (numExits == 0) {
281  WRITE_WARNING("An " + toString(SUMO_TAG_E3DETECTOR) + " need at least one " + toString(SUMO_TAG_DET_EXIT) + " detector");
282  }
283  // return false depending of number of Entrys and Exits
284  return ((numEntrys != 0) && (numExits != 0));
285 }
286 
287 
288 std::string
290  return getTagStr() + ":" + getID();
291 }
292 
293 
294 std::string
296  return getTagStr();
297 }
298 
299 // ===========================================================================
300 // private
301 // ===========================================================================
302 
303 void
304 GNEDetectorE3::setAttribute(SumoXMLAttr key, const std::string& value) {
305  switch (key) {
306  case SUMO_ATTR_ID:
307  changeAdditionalID(value);
308  break;
309  case SUMO_ATTR_POSITION:
310  myPosition = parse<Position>(value);
311  break;
312  case SUMO_ATTR_FREQUENCY:
313  myFreq = parse<double>(value);
314  break;
315  case SUMO_ATTR_NAME:
316  myAdditionalName = value;
317  break;
318  case SUMO_ATTR_FILE:
319  myFilename = value;
320  break;
321  case SUMO_ATTR_VTYPES:
322  myVehicleTypes = value;
323  break;
325  myTimeThreshold = parse<double>(value);
326  break;
328  mySpeedThreshold = parse<double>(value);
329  break;
331  myBlockMovement = parse<bool>(value);
332  break;
333  case GNE_ATTR_SELECTED:
334  if (parse<bool>(value)) {
336  } else {
338  }
339  break;
340  case GNE_ATTR_GENERIC:
342  break;
343  default:
344  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
345  }
346  // Update Geometry after setting a new attribute (but avoided for certain attributes)
347  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
348  updateGeometry(true);
349  }
350 }
351 
352 /****************************************************************************/
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...
double scale
information about a lane&#39;s width (temporary, used for a single view)
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:127
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.
Position offset
The offSet of the block icon.
Position snapToActiveGrid(const Position &pos) const
Returns a position that is mapped to the closest grid point if the grid is active.
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.
Position position
position of the block icon
BlockIcon myBlockIcon
variable BlockIcon
Position originalViewPosition
value for saving first original position over lane before moving
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:73
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
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
an e3 entry point
bool isValidDetectorID(const std::string &newID) const
check if a new detector ID is valid
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
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
AdditionalMove myMove
variable AdditionalMove
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static const RGBColor GREY
Definition: RGBColor.h:193
void draw() const
draw connections between Parent and childrens
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
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
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:80
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
PositionVector shape
The shape of the additional element.
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
std::vector< PositionVector > connectionPositions
Matrix with the Vertex&#39;s positions of connections between parents an their childs.
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:1160
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
ChildConnections myChildConnections
variable ChildConnections
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
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
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:48
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
const std::string & getTagStr() const
get tag assigned to this object in string format
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.
void update()
update Connection&#39;s geometry
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:132
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1153
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name) ...
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry(bool updateGrid) function) ...
std::string myFilename
fielname of E3 detector
void draw(double size=0.5) const
draw lock icon
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...