SUMO - Simulation of Urban MObility
GNEDetectorEntry.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>
28 #include <utils/gui/div/GLHelper.h>
30 
31 #include "GNEDetectorEntry.h"
32 #include "GNEAdditionalHandler.h"
33 
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
39 GNEDetectorEntry::GNEDetectorEntry(GNEViewNet* viewNet, GNEAdditional* parent, GNELane* lane, double pos, bool friendlyPos, bool blockMovement) :
40  GNEDetector(parent, viewNet, GLO_DET_ENTRY, SUMO_TAG_DET_ENTRY, pos, 0, "", "", friendlyPos, blockMovement),
41  myLane(lane) {
42 }
43 
44 
46 
47 
48 bool
50  // with friendly position enabled position are "always fixed"
51  if (myFriendlyPosition) {
52  return true;
53  } else {
55  }
56 }
57 
58 
59 std::string
61  // declare variable for error position
62  std::string errorPosition;
63  // check positions over lane
64  if (myPositionOverLane < 0) {
65  errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
66  }
68  errorPosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
69  }
70  return errorPosition;
71 }
72 
73 
74 void
76  // declare new position
77  double newPositionOverLane = myPositionOverLane;
78  // fix pos and lenght checkAndFixDetectorPosition
80  // set new position
82 }
83 
84 
85 void
87  // Calculate new position using old position
88  Position newPosition = myMove.originalViewPosition;
89  newPosition.add(offset);
90  // filtern position using snap to active grid
91  newPosition = myViewNet->snapToActiveGrid(newPosition);
93  // Update geometry
94  updateGeometry(false);
95 }
96 
97 
98 void
100  // commit new position allowing undo/redo
101  undoList->p_begin("position of " + getTagStr());
103  undoList->p_end();
104 }
105 
106 
107 void
109  // first check if object has to be removed from grid (SUMOTree)
110  if (updateGrid) {
112  }
113 
114  // Clear all containers
116 
117  // obtain position over lane
119  myGeometry.shape.push_back(myLane->getShape().positionAtOffset(fixedPositionOverLane * myLane->getLengthGeometryFactor()));
120 
121  // Save rotation (angle) of the vector constructed by points f and s
122  myGeometry.shapeRotations.push_back(myLane->getShape().rotationDegreeAtOffset(fixedPositionOverLane) * -1);
123 
124  // Set block icon position
126 
127  // Set block icon rotation, and using their rotation for logo
129 
130  // last step is to check if object has to be added into grid (SUMOTree) again
131  if (updateGrid) {
133  }
134 
135  // update E3 parent Geometry
137 }
138 
139 
140 GNELane*
142  return myLane;
143 }
144 
145 
146 void
148  // Start drawing adding gl identificator
149  glPushName(getGlID());
150 
151  // Push detector matrix
152  glPushMatrix();
153  glTranslated(0, 0, getType());
154 
155  // Set initial values
158  } else {
160  }
161  const double exaggeration = s.addSize.getExaggeration(s, this);
162  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
163 
164  // Push polygon matrix
165  glPushMatrix();
166  glScaled(exaggeration, exaggeration, 1);
167  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), 0);
168  glRotated(myGeometry.shapeRotations[0], 0, 0, 1);
169 
170  // draw details if isn't being drawn for selecting
171  if (!s.drawForSelecting) {
172  // Draw polygon
173  glBegin(GL_LINES);
174  glVertex2d(1.7, 0);
175  glVertex2d(-1.7, 0);
176  glEnd();
177  glBegin(GL_QUADS);
178  glVertex2d(-1.7, .5);
179  glVertex2d(-1.7, -.5);
180  glVertex2d(1.7, -.5);
181  glVertex2d(1.7, .5);
182  glEnd();
183 
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 
189  // second Arrow
190  glTranslated(-3, 0, 0);
191  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
192  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
193  } else {
194  // Draw square in drawy for selecting mode
195  glBegin(GL_QUADS);
196  glVertex2d(-1.7, 4.3);
197  glVertex2d(-1.7, -.5);
198  glVertex2d(1.7, -.5);
199  glVertex2d(1.7, 4.3);
200  glEnd();
201  }
202 
203  // Pop polygon matrix
204  glPopMatrix();
205 
206  // Pop detector matrix
207  glPopMatrix();
208 
209  // Check if the distance is enought to draw details
210  if (!s.drawForSelecting && ((s.scale * exaggeration) >= 10)) {
211  // Push matrix
212  glPushMatrix();
213  // Traslate to center of detector
214  glTranslated(myGeometry.shape.getLineCenter().x(), myGeometry.shape.getLineCenter().y(), getType() + 0.1);
215  // Rotate depending of myBlockIcon.rotation
216  glRotated(myBlockIcon.rotation, 0, 0, -1);
217  //move to logo position
218  glTranslated(1.9, 0, 0);
219  // draw Entry logo if isn't being drawn for selecting
220  if (s.drawForSelecting) {
222  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
223  } else if (isAttributeCarrierSelected()) {
225  } else {
226  GLHelper::drawText("E3", Position(), .1, 2.8, s.SUMO_color_E3Entry);
227  }
228  //move to logo position
229  glTranslated(1.7, 0, 0);
230  // Rotate depending of myBlockIcon.rotation
231  glRotated(90, 0, 0, 1);
232  // draw Entry text if isn't being drawn for selecting
233  if (s.drawForSelecting) {
235  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
236  } else if (isAttributeCarrierSelected()) {
238  } else {
239  GLHelper::drawText("Entry", Position(), .1, 1, s.SUMO_color_E3Entry);
240  }
241  // pop matrix
242  glPopMatrix();
243  // Show Lock icon depending of the Edit mode and if isn't being drawn for selecting
244  if (!s.drawForSelecting) {
245  myBlockIcon.draw(0.4);
246  }
247  }
248  // Draw name if isn't being drawn for selecting
249  if (!s.drawForSelecting) {
250  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
251  }
252  // check if dotted contour has to be drawn
253  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
255  }
256  // pop gl identificator
257  glPopName();
258 }
259 
260 
261 std::string
263  switch (key) {
264  case SUMO_ATTR_ID:
265  return getAdditionalID();
266  case SUMO_ATTR_LANE:
267  return myLane->getID();
268  case SUMO_ATTR_POSITION:
273  return toString(myBlockMovement);
274  case GNE_ATTR_PARENT:
275  return myFirstAdditionalParent->getID();
276  case GNE_ATTR_SELECTED:
278  case GNE_ATTR_GENERIC:
279  return getGenericParametersStr();
280  default:
281  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
282  }
283 }
284 
285 
286 void
287 GNEDetectorEntry::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
288  if (value == getAttribute(key)) {
289  return; //avoid needless changes, later logic relies on the fact that attributes have changed
290  }
291  switch (key) {
292  case SUMO_ATTR_ID:
293  case SUMO_ATTR_LANE:
294  case SUMO_ATTR_POSITION:
297  case GNE_ATTR_PARENT:
298  case GNE_ATTR_SELECTED:
299  case GNE_ATTR_GENERIC:
300  undoList->p_add(new GNEChange_Attribute(this, key, value));
301  break;
302  default:
303  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
304  }
305 }
306 
307 
308 bool
309 GNEDetectorEntry::isValid(SumoXMLAttr key, const std::string& value) {
310  switch (key) {
311  case SUMO_ATTR_ID:
312  return isValidAdditionalID(value);
313  case SUMO_ATTR_LANE:
314  return (myViewNet->getNet()->retrieveLane(value, false) != nullptr);
315  case SUMO_ATTR_POSITION:
316  return canParse<double>(value);
318  return canParse<bool>(value);
320  return canParse<bool>(value);
321  case GNE_ATTR_PARENT:
322  return (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_E3DETECTOR, value, false) != nullptr);
323  case GNE_ATTR_SELECTED:
324  return canParse<bool>(value);
325  case GNE_ATTR_GENERIC:
326  return isGenericParametersValid(value);
327  default:
328  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
329  }
330 }
331 
332 void
333 GNEDetectorEntry::setAttribute(SumoXMLAttr key, const std::string& value) {
334  switch (key) {
335  case SUMO_ATTR_ID:
336  changeAdditionalID(value);
337  break;
338  case SUMO_ATTR_LANE:
339  myLane = changeLane(myLane, value);
340  break;
341  case SUMO_ATTR_POSITION:
342  myPositionOverLane = parse<double>(value);
343  break;
345  myFriendlyPosition = parse<bool>(value);
346  break;
348  myBlockMovement = parse<bool>(value);
349  break;
350  case GNE_ATTR_PARENT:
352  break;
353  case GNE_ATTR_SELECTED:
354  if (parse<bool>(value)) {
356  } else {
358  }
359  break;
360  case GNE_ATTR_GENERIC:
362  break;
363  default:
364  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
365  }
366  // Update Geometry after setting a new attribute (but avoided for certain attributes)
367  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
368  updateGeometry(true);
369  }
370 }
371 
372 /****************************************************************************/
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
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.
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
void changeFirstAdditionalParent(const std::string &newAdditionalParentID)
change first additional parent of additional
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:62
Position snapToActiveGrid(const Position &pos) const
Returns a position that is mapped to the closest grid point if the grid is active.
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:611
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:47
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.
~GNEDetectorEntry()
destructor
GNEDetectorEntry(GNEViewNet *viewNet, GNEAdditional *parent, GNELane *lane, double pos, bool friendlyPos, bool blockMovement)
Constructor.
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.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
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.
AdditionalMove myMove
variable AdditionalMove
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:1785
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
GNEUndoList * getUndoList() const
get the undoList object
GNELane * myLane
The lane in which this detector is placed.
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
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1260
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
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.
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
double getLengthGeometryFactor() const
get lenght geometry factor
Definition: GNELane.cpp:1317
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
static const RGBColor SUMO_color_E3Entry
color for Entrys
std::string getAdditionalProblem() const
return a string with the current additional problem
virtual void updateGeometry(bool updateGrid)=0
update pre-computed geometry information
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:163
bool isAdditionalValid() const
check if current additional is valid to be writed into XML (by default true, can be reimplemented in ...
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:3575
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:669
void fixAdditionalProblem()
fix additional problem
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
a DetEntry detector
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
GNELane * getLane() const
get lane
element is selected
std::string getAttribute(SumoXMLAttr key) const
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
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.
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:436
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element
std::string firstOriginalLanePosition
value for saving first original position over lane before moving
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:132
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:613
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
void updateGeometry(bool updateGrid)
update pre-computed geometry information
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1153
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1059
GNEAdditional * myFirstAdditionalParent
pointer to first Additional parent
GNELane * changeLane(GNELane *oldLane, const std::string &newLaneID)
change lane of additional
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry(bool updateGrid) function) ...
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:151
void draw(double size=0.5) const
draw lock icon