Eclipse SUMO - Simulation of Urban MObility
GNEDetectorEntryExit.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-2019 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>
28 #include <utils/gui/div/GLHelper.h>
30 
31 #include "GNEDetectorEntryExit.h"
32 #include "GNEAdditionalHandler.h"
33 
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
39 GNEDetectorEntryExit::GNEDetectorEntryExit(SumoXMLTag entryExitTag, GNEViewNet* viewNet, GNEAdditional* parent, GNELane* lane, double pos, bool friendlyPos, bool blockMovement) :
40  GNEDetector(parent, viewNet, GLO_DET_ENTRY, entryExitTag, pos, 0, "", "", friendlyPos, blockMovement, {
41  lane
42 }) {
43  //check that this is a TAZ Source OR a TAZ Sink
44  if ((entryExitTag != SUMO_TAG_DET_ENTRY) && (entryExitTag != SUMO_TAG_DET_EXIT)) {
45  throw InvalidArgument("Invalid E3 Child Tag");
46  }
47 }
48 
49 
51 
52 
53 bool
55  // with friendly position enabled position are "always fixed"
56  if (myFriendlyPosition) {
57  return true;
58  } else {
59  return fabs(myPositionOverLane) <= getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength();
60  }
61 }
62 
63 
64 std::string
66  // declare variable for error position
67  std::string errorPosition;
68  const double len = getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength();
69  // check positions over lane
70  if (myPositionOverLane < -len) {
71  errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
72  }
73  if (myPositionOverLane > len) {
74  errorPosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
75  }
76  return errorPosition;
77 }
78 
79 
80 void
82  // declare new position
83  double newPositionOverLane = myPositionOverLane;
84  // fix pos and lenght checkAndFixDetectorPosition
85  GNEAdditionalHandler::checkAndFixDetectorPosition(newPositionOverLane, getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength(), true);
86  // set new position
88 }
89 
90 
91 void
93  // Calculate new position using old position
94  Position newPosition = myMove.originalViewPosition;
95  newPosition.add(offset);
96  // filtern position using snap to active grid
97  newPosition = myViewNet->snapToActiveGrid(newPosition);
98  const bool storeNegative = myPositionOverLane < 0;
99  myPositionOverLane = getLaneParents().front()->getGeometry().shape.nearest_offset_to_point2D(newPosition, false);
100  if (storeNegative) {
101  myPositionOverLane -= getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength();
102  }
103  // Update geometry
104  updateGeometry();
105 }
106 
107 
108 void
110  // commit new position allowing undo/redo
111  undoList->p_begin("position of " + getTagStr());
113  undoList->p_end();
114 }
115 
116 
117 void
119  // Clear all containers
121 
122  // obtain position over lane
123  myGeometry.shape.push_back(getPositionInView());
124 
125  // Obtain first position
126  Position f = myGeometry.shape[0] - Position(1, 0);
127 
128  // Obtain next position
129  Position s = myGeometry.shape[0] + Position(1, 0);
130 
131  // Save rotation (angle) of the vector constructed by points f and s
132  myGeometry.shapeRotations.push_back(getLaneParents().front()->getGeometry().shape.rotationDegreeAtOffset(getGeometryPositionOverLane()) * -1);
133 
134  // Set block icon position
136 
137  // Set offset of the block icon
138  myBlockIcon.offset = Position(-1, 0);
139 
140  // Set block icon rotation, and using their rotation for logo
142 
143  // update E3 parent children
144  getAdditionalParents().at(0)->updateChildConnections();
145 }
146 
147 
148 void
150  // Set initial values
151  const double exaggeration = s.addSize.getExaggeration(s, this);
152  // Start drawing adding gl identificator
153  glPushName(getGlID());
154  // Push detector matrix
155  glPushMatrix();
156  glTranslated(0, 0, getType());
157  // Set color
158  if (drawUsingSelectColor()) {
160  } else if (myTagProperty.getTag() == SUMO_TAG_DET_ENTRY) {
162  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
164  }
165  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
166  // Push polygon matrix
167  glPushMatrix();
168  glScaled(exaggeration, exaggeration, 1);
169  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), 0);
170  glRotated(myGeometry.shapeRotations[0], 0, 0, 1);
171  // draw details if isn't being drawn for selecting
172  if (!s.drawForSelecting) {
173  // Draw polygon
174  glBegin(GL_LINES);
175  glVertex2d(1.7, 0);
176  glVertex2d(-1.7, 0);
177  glEnd();
178  glBegin(GL_QUADS);
179  glVertex2d(-1.7, .5);
180  glVertex2d(-1.7, -.5);
181  glVertex2d(1.7, -.5);
182  glVertex2d(1.7, .5);
183  glEnd();
184  // first Arrow
185  glTranslated(1.5, 0, 0);
186  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
187  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
188  // second Arrow
189  glTranslated(-3, 0, 0);
190  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
191  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
192  } else {
193  // Draw square in drawy for selecting mode
194  glBegin(GL_QUADS);
195  glVertex2d(-1.7, 4.3);
196  glVertex2d(-1.7, -.5);
197  glVertex2d(1.7, -.5);
198  glVertex2d(1.7, 4.3);
199  glEnd();
200  }
201  // Pop polygon matrix
202  glPopMatrix();
203  // Pop detector matrix
204  glPopMatrix();
205  // Check if the distance is enought to draw details
206  if (!s.drawForSelecting && s.drawDetail(s.detailSettings.detectorDetails, exaggeration)) {
207  // Push matrix
208  glPushMatrix();
209  // Traslate to center of detector
210  glTranslated(myGeometry.shape.getLineCenter().x(), myGeometry.shape.getLineCenter().y(), getType() + 0.1);
211  // Rotate depending of myBlockIcon.rotation
212  glRotated(myBlockIcon.rotation, 0, 0, -1);
213  //move to logo position
214  glTranslated(1.9, 0, 0);
215  // draw Entry or Exit logo if isn't being drawn for selecting
216  if (s.drawForSelecting) {
218  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
219  } else if (drawUsingSelectColor()) {
221  } else if (myTagProperty.getTag() == SUMO_TAG_DET_ENTRY) {
222  GLHelper::drawText("E3", Position(), .1, 2.8, s.colorSettings.E3Entry);
223  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
224  GLHelper::drawText("E3", Position(), .1, 2.8, s.colorSettings.E3Exit);
225  }
226  //move to logo position
227  glTranslated(1.7, 0, 0);
228  // Rotate depending of myBlockIcon.rotation
229  glRotated(90, 0, 0, 1);
230  // draw Entry or Exit text if isn't being drawn for selecting
231  if (s.drawForSelecting) {
233  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
234  } else if (drawUsingSelectColor()) {
237  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
239  }
240  } else {
242  GLHelper::drawText("Entry", Position(), .1, 1, s.colorSettings.E3Entry);
243  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
244  GLHelper::drawText("Exit", Position(), .1, 1, s.colorSettings.E3Exit);
245  }
246  }
247  // pop matrix
248  glPopMatrix();
249  // draw lock icon
250  myBlockIcon.drawIcon(s, exaggeration, 0.4);
251  }
252  // Draw name if isn't being drawn for selecting
253  if (!s.drawForSelecting) {
255  }
256  // check if dotted contour has to be drawn
257  if (myViewNet->getDottedAC() == this) {
259  }
260  // pop gl identificator
261  glPopName();
262 }
263 
264 
265 std::string
267  switch (key) {
268  case SUMO_ATTR_ID:
269  return getAdditionalID();
270  case SUMO_ATTR_LANE:
271  return getLaneParents().front()->getID();
272  case SUMO_ATTR_POSITION:
277  return toString(myBlockMovement);
278  case GNE_ATTR_PARENT:
279  return getAdditionalParents().at(0)->getID();
280  case GNE_ATTR_SELECTED:
282  case GNE_ATTR_GENERIC:
283  return getGenericParametersStr();
284  default:
285  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
286  }
287 }
288 
289 
290 void
291 GNEDetectorEntryExit::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
292  if (value == getAttribute(key)) {
293  return; //avoid needless changes, later logic relies on the fact that attributes have changed
294  }
295  switch (key) {
296  case SUMO_ATTR_ID:
297  case SUMO_ATTR_LANE:
298  case SUMO_ATTR_POSITION:
301  case GNE_ATTR_PARENT:
302  case GNE_ATTR_SELECTED:
303  case GNE_ATTR_GENERIC:
304  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
305  break;
306  default:
307  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
308  }
309 }
310 
311 
312 bool
313 GNEDetectorEntryExit::isValid(SumoXMLAttr key, const std::string& value) {
314  switch (key) {
315  case SUMO_ATTR_ID:
316  return isValidAdditionalID(value);
317  case SUMO_ATTR_LANE:
318  return (myViewNet->getNet()->retrieveLane(value, false) != nullptr);
319  case SUMO_ATTR_POSITION:
320  return canParse<double>(value) && fabs(parse<double>(value)) < getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength();
322  return canParse<bool>(value);
324  return canParse<bool>(value);
325  case GNE_ATTR_PARENT:
326  return (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_E3DETECTOR, value, false) != nullptr);
327  case GNE_ATTR_SELECTED:
328  return canParse<bool>(value);
329  case GNE_ATTR_GENERIC:
330  return isGenericParametersValid(value);
331  default:
332  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
333  }
334 }
335 
336 void
337 GNEDetectorEntryExit::setAttribute(SumoXMLAttr key, const std::string& value) {
338  switch (key) {
339  case SUMO_ATTR_ID:
340  changeAdditionalID(value);
341  break;
342  case SUMO_ATTR_LANE:
343  changeLaneParents(this, value);
344  break;
345  case SUMO_ATTR_POSITION:
346  myPositionOverLane = parse<double>(value);
347  break;
349  myFriendlyPosition = parse<bool>(value);
350  break;
352  myBlockMovement = parse<bool>(value);
353  break;
354  case GNE_ATTR_PARENT:
355  changeAdditionalParent(this, value, 0);
356  break;
357  case GNE_ATTR_SELECTED:
358  if (parse<bool>(value)) {
360  } else {
362  }
363  break;
364  case GNE_ATTR_GENERIC:
366  break;
367  default:
368  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
369  }
370 }
371 
372 /****************************************************************************/
GNEDetectorEntryExit(SumoXMLTag entryExitTag, GNEViewNet *viewNet, GNEAdditional *parent, GNELane *lane, double pos, bool friendlyPos, bool blockMovement)
Constructor.
const TagProperties & myTagProperty
the xml tag to which this attribute carrier corresponds
SumoXMLTag
Numbers representing SUMO-XML - element names.
Position snapToActiveGrid(const Position &pos, bool snapXY=true) const
Returns a position that is mapped to the closest grid point if the grid is active.
double scale
information about a lane&#39;s width (temporary, used for a single view)
static bool checkAndFixDetectorPosition(double &pos, const double laneLength, const bool friendlyPos)
check if the position of a detector over a lane is valid
GUIVisualizationTextSettings addName
std::vector< double > shapeRotations
The rotations of the single shape parts.
Definition: GNEAdditional.h:74
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
std::string getAttribute(SumoXMLAttr key) const
const std::string & getAdditionalID() const
Stores the information about how to visualize structures.
void changeAdditionalParent(GNEShape *shapeTobeChanged, const std::string &newAdditionalParentID, int additionalParentIndex)
change additional parent of a shape
Position offset
The offSet of the block icon.
double y() const
Returns the y-position.
Definition: Position.h:62
double x() const
Returns the x-position.
Definition: Position.h:57
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:668
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Position position
position of the block icon
BlockIcon myBlockIcon
variable BlockIcon
void clearGeometry()
reset geometry
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
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.
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
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
an e3 entry point
double rotation
The rotation of the block icon.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
AdditionalMove myMove
variable AdditionalMove
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:2133
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
void fixAdditionalProblem()
fix additional problem
GUIVisualizationSizeSettings addSize
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:933
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:48
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
static const RGBColor E3Exit
color for Exits
double getGeometryPositionOverLane() const
get position over lane that is applicable to the shape
Definition: GNEDetector.cpp:90
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.
Definition: GNEAdditional.h:68
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEDetector.cpp:74
an e3 exit point
bool isAdditionalValid() const
check if current additional is valid to be writed into XML (by default true, can be reimplemented in ...
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
const std::vector< GNELane * > & getLaneParents() const
get lanes of VSS
block movement of a graphic element
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
static const double detectorDetails
details for detectors
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
std::string getAdditionalProblem() const
return a string with the current additional problem
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:173
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
static void drawShapeDottedContourRectangle(const GUIVisualizationSettings &s, const int type, const Position &center, const double width, const double height, const double rotation=0, const double offsetX=0, const double offsetY=0)
draw a dotted contour around the given Position with certain width and height
Definition: GLHelper.cpp:555
GUIVisualizationDetailSettings detailSettings
detail settings
static const RGBColor E3Entry
color for Entrys
void changeLaneParents(GNEShape *elementChild, const std::string &newLaneIDs)
change edge parents of a shape
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
a DetEntry detector
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:939
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
void updateGeometry()
update pre-computed geometry information
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GUIGlID getGlID() const
Returns the numerical id of the object.
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
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:440
GUIVisualizationColorSettings colorSettings
color settings
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
parent of an additional element
std::string firstOriginalLanePosition
value for saving first original position over lane before moving
~GNEDetectorEntryExit()
destructor
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:136
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
void drawIcon(const GUIVisualizationSettings &s, const double exaggeration, const double size=0.5) const
draw lock icon
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1179
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry() function)
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:161