Eclipse 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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 //
19 /****************************************************************************/
20 #include <netedit/GNENet.h>
21 #include <netedit/GNEUndoList.h>
22 #include <netedit/GNEViewNet.h>
24 #include <utils/gui/div/GLHelper.h>
27 
28 #include "GNEDetectorE3.h"
29 
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
35 GNEDetectorE3::GNEDetectorE3(const std::string& id, GNENet* net, Position pos, SUMOTime freq, const std::string& filename,
36  const std::string& vehicleTypes, const std::string& name, SUMOTime timeThreshold, double speedThreshold, bool blockMovement) :
37  GNEAdditional(id, net, GLO_E3DETECTOR, SUMO_TAG_E3DETECTOR, name, blockMovement,
38 {}, {}, {}, {}, {}, {}, {}, {}),
39 myPosition(pos),
40 myFreq(freq),
41 myFilename(filename),
42 myVehicleTypes(vehicleTypes),
43 myTimeThreshold(timeThreshold),
44 mySpeedThreshold(speedThreshold) {
45  // update centering boundary without updating grid
46  updateCenteringBoundary(false);
47 }
48 
49 
51 
52 
54 GNEDetectorE3::getMoveOperation(const double /*shapeOffset*/) {
55  if (myBlockMovement) {
56  // element blocked, then nothing to move
57  return nullptr;
58  } else {
59  // return move operation for additional placed in view
60  return new GNEMoveOperation(this, myPosition);
61  }
62 }
63 
64 
65 void
67  // update additional geometry
69  // Update Hierarchical connections geometry
71 }
72 
73 
74 void
76  // remove additional from grid
77  if (updateGrid) {
79  }
80  // now update geometry
82  // add shape boundary
84  // grow
85  myBoundary.grow(10);
86  // add additional into RTREE again
87  if (updateGrid) {
89  }
90 }
91 
92 
93 void
94 GNEDetectorE3::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
95  // geometry of this element cannot be splitted
96 }
97 
98 
99 std::string
101  return myNet->getMicrosimID();
102 }
103 
104 
105 void
107  // Obtain exaggeration of the draw
108  const double E3Exaggeration = s.addSize.getExaggeration(s, this);
109  // first check if additional has to be drawn
110  if (s.drawAdditionals(E3Exaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
111  // check if boundary has to be drawn
112  if (s.drawBoundaries) {
114  }
115  // Start drawing adding an gl identificator
116  glPushName(getGlID());
117  // Add layer matrix
118  glPushMatrix();
119  // translate to front
121  // Add texture matrix
122  glPushMatrix();
123  // translate to position
124  glTranslated(myPosition.x(), myPosition.y(), 0);
125  // scale
126  glScaled(E3Exaggeration, E3Exaggeration, 1);
127  // set color
128  glColor3d(1, 1, 1);
129  // rotate
130  glRotated(180, 0, 0, 1);
131  // draw depending
132  if (s.drawForRectangleSelection || !s.drawDetail(s.detailSettings.laneTextures, E3Exaggeration)) {
133  // set color
135  // just draw a box
137  } else {
138  // draw texture
139  if (drawUsingSelectColor()) {
141  } else {
143  }
144  }
145  // Pop texture matrix
146  glPopMatrix();
147  // draw lock icon
148  GNEViewNetHelper::LockIcon::drawLockIcon(this, myAdditionalGeometry, E3Exaggeration, -0.5, -0.5, false, 0.4);
149  // Pop layer matrix
150  glPopMatrix();
151  // Pop name
152  glPopName();
153  // Pop name
154  glPopName();
155  // push connection matrix
156  glPushMatrix();
157  // translate to front
159  // Draw child connections
160  drawHierarchicalConnections(s, this, E3Exaggeration);
161  // Pop connection matrix
162  glPopMatrix();
163  // Draw additional ID
164  drawAdditionalID(s);
165  // draw additional name
167  // check if dotted contours has to be drawn
170  }
171  if (s.drawDottedContour() || myNet->getViewNet()->getFrontAttributeCarrier() == this) {
173  }
174  }
175 }
176 
177 
178 std::string
180  switch (key) {
181  case SUMO_ATTR_ID:
182  return getID();
183  case SUMO_ATTR_POSITION:
184  return toString(myPosition);
185  case SUMO_ATTR_FREQUENCY:
186  return time2string(myFreq);
187  case SUMO_ATTR_NAME:
188  return myAdditionalName;
189  case SUMO_ATTR_FILE:
190  return myFilename;
191  case SUMO_ATTR_VTYPES:
192  return myVehicleTypes;
196  return toString(mySpeedThreshold);
198  return toString(myBlockMovement);
199  case GNE_ATTR_SELECTED:
201  case GNE_ATTR_PARAMETERS:
202  return getParametersStr();
203  default:
204  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
205  }
206 }
207 
208 
209 double
211  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
212 }
213 
214 
215 void
216 GNEDetectorE3::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
217  if (value == getAttribute(key)) {
218  return; //avoid needless changes, later logic relies on the fact that attributes have changed
219  }
220  switch (key) {
221  case SUMO_ATTR_ID:
222  case SUMO_ATTR_FREQUENCY:
223  case SUMO_ATTR_POSITION:
224  case SUMO_ATTR_NAME:
225  case SUMO_ATTR_FILE:
226  case SUMO_ATTR_VTYPES:
230  case GNE_ATTR_SELECTED:
231  case GNE_ATTR_PARAMETERS:
232  undoList->p_add(new GNEChange_Attribute(this, key, value));
233  break;
234  default:
235  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
236  }
237 }
238 
239 
240 bool
241 GNEDetectorE3::isValid(SumoXMLAttr key, const std::string& value) {
242  switch (key) {
243  case SUMO_ATTR_ID:
244  return isValidDetectorID(value);
245  case SUMO_ATTR_POSITION:
246  return canParse<Position>(value);
247  case SUMO_ATTR_FREQUENCY:
248  return canParse<SUMOTime>(value);
249  case SUMO_ATTR_NAME:
251  case SUMO_ATTR_FILE:
253  case SUMO_ATTR_VTYPES:
254  if (value.empty()) {
255  return true;
256  } else {
258  }
260  return canParse<SUMOTime>(value);
262  return canParse<double>(value) && (parse<double>(value) >= 0);
264  return canParse<bool>(value);
265  case GNE_ATTR_SELECTED:
266  return canParse<bool>(value);
267  case GNE_ATTR_PARAMETERS:
268  return Parameterised::areParametersValid(value);
269  default:
270  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
271  }
272 }
273 
274 
275 bool
277  int numEntrys = 0;
278  int numExits = 0;
279  // iterate over additional chidls and obtain number of entrys and exits
280  for (auto i : getChildAdditionals()) {
281  if (i->getTagProperty().getTag() == SUMO_TAG_DET_ENTRY) {
282  numEntrys++;
283  } else if (i->getTagProperty().getTag() == SUMO_TAG_DET_EXIT) {
284  numExits++;
285  }
286  }
287  // write warnings
288  if (numEntrys == 0) {
289  WRITE_WARNING("An " + toString(SUMO_TAG_E3DETECTOR) + " need at least one " + toString(SUMO_TAG_DET_ENTRY) + " detector");
290  }
291  if (numExits == 0) {
292  WRITE_WARNING("An " + toString(SUMO_TAG_E3DETECTOR) + " need at least one " + toString(SUMO_TAG_DET_EXIT) + " detector");
293  }
294  // return false depending of number of Entrys and Exits
295  return ((numEntrys != 0) && (numExits != 0));
296 }
297 
298 
299 bool
301  return true;
302 }
303 
304 
305 std::string
307  return getTagStr() + ":" + getID();
308 }
309 
310 
311 std::string
313  return getTagStr();
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  myNet->getAttributeCarriers()->updateID(this, value);
325  // Change IDs of all Entry/Exits children
326  for (const auto& entryExit : getChildAdditionals()) {
327  entryExit->setMicrosimID(getID());
328  }
329  break;
330  case SUMO_ATTR_POSITION:
331  myPosition = parse<Position>(value);
332  // update boundary
334  break;
335  case SUMO_ATTR_FREQUENCY:
336  myFreq = parse<SUMOTime>(value);
337  break;
338  case SUMO_ATTR_NAME:
339  myAdditionalName = value;
340  break;
341  case SUMO_ATTR_FILE:
342  myFilename = value;
343  break;
344  case SUMO_ATTR_VTYPES:
345  myVehicleTypes = value;
346  break;
348  myTimeThreshold = parse<SUMOTime>(value);
349  break;
351  mySpeedThreshold = parse<double>(value);
352  break;
354  myBlockMovement = parse<bool>(value);
355  break;
356  case GNE_ATTR_SELECTED:
357  if (parse<bool>(value)) {
359  } else {
361  }
362  break;
363  case GNE_ATTR_PARAMETERS:
364  setParametersStr(value);
365  break;
366  default:
367  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
368  }
369 }
370 
371 
372 void
374  // update position
375  myPosition = moveResult.shapeToUpdate.front();
376  // update geometry
377  updateGeometry();
378 }
379 
380 
381 void
383  undoList->p_begin("position of " + getTagStr());
384  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
385  undoList->p_end();
386 }
387 
388 
389 /****************************************************************************/
@ GLO_E3DETECTOR
a E3 detector
@ GNETEXTURE_E3SELECTED
Definition: GUITextures.h:33
@ GNETEXTURE_E3
Definition: GUITextures.h:32
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:276
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
long long int SUMOTime
Definition: SUMOTime.h:31
@ SUMO_TAG_DET_ENTRY
an e3 entry point
@ SUMO_TAG_DET_EXIT
an e3 exit point
@ SUMO_TAG_E3DETECTOR
an e3 detector
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_FILE
@ GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_HALTING_TIME_THRESHOLD
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_HALTING_SPEED_THRESHOLD
@ SUMO_ATTR_FREQUENCY
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:647
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:135
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
GNEGeometry::Geometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
std::string myAdditionalName
name of additional
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
Boundary myBoundary
Additional Boundary.
bool isValidDetectorID(const std::string &newID) const
check if a new detector ID is valid
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
std::string getAttribute(SumoXMLAttr key) const
std::string myFilename
fielname of E3 detector
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool isAttributeEnabled(SumoXMLAttr key) const
double mySpeedThreshold
The speed-based threshold that describes how slow a vehicle has to be to be recognized as halting.
double getAttributeDouble(SumoXMLAttr key) const
void updateGeometry()
update pre-computed geometry information
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
~GNEDetectorE3()
GNEDetectorE3 Destructor.
bool checkChildAdditionalRestriction() const
check restriction with the number of children
std::string getParentName() const
Returns the name of the parent object (if any)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Position myPosition
position of E3 in view
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
SUMOTime myFreq
frequency of E3 detector
GNEDetectorE3(const std::string &id, GNENet *net, Position pos, SUMOTime freq, const std::string &filename, const std::string &vehicleTypes, const std::string &name, SUMOTime timeThreshold, double speedThreshold, bool blockMovement)
GNEDetectorE3 Constructor.
SUMOTime myTimeThreshold
The time-based threshold that describes how much time has to pass until a vehicle is recognized as ha...
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
std::string myVehicleTypes
attribute vehicle types
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
void update()
update Connection's geometry
void drawHierarchicalConnections(const GUIVisualizationSettings &s, const GNEAttributeCarrier *AC, const double exaggeration) const
Draw hierarchical connections between parent and children.
GNEGeometry::HierarchicalConnections myHierarchicalConnections
hierarchical connections
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1411
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1423
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
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:71
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:78
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
GUIGlID getGlID() const
Returns the numerical id of the object.
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
Stores the information about how to visualize structures.
bool drawBoundaries
enable or disable draw boundaries
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationDetailSettings detailSettings
detail settings
GUIVisualizationSizeSettings addSize
bool drawDottedContour() const
check if dotted contour can be drawn
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
GUIVisualizationDetectorSettings detectorSettings
Detector settings.
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static const RGBColor GREY
Definition: RGBColor.h:189
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (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't allowed)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static void drawDottedSquaredShape(const DottedContourType type, const GUIVisualizationSettings &s, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GNEAttributeCarrier *AC, const GNEGeometry::Geometry &geometry, const double exaggeration, const double offsetx, const double offsety, const bool overlane, const double size=0.5)
draw lock icon
static const double laneTextures
details for lane textures
static const double E3Size
E3 detector size.
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values