SUMO - Simulation of Urban MObility
GNEDetectorE1.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 "GNEDetectorE1.h"
32 #include "GNEAdditionalHandler.h"
33 
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
39 GNEDetectorE1::GNEDetectorE1(const std::string& id, GNELane* lane, GNEViewNet* viewNet, double pos, double freq, const std::string& filename, const std::string& vehicleTypes, const std::string& name, bool friendlyPos, bool blockMovement) :
40  GNEDetector(id, viewNet, GLO_E1DETECTOR, SUMO_TAG_E1DETECTOR, pos, freq, filename, vehicleTypes, name, friendlyPos, blockMovement),
41  myLane(lane) {
42 }
43 
44 
46 }
47 
48 
49 bool
51  // with friendly position enabled position are "always fixed"
52  if (myFriendlyPosition) {
53  return true;
54  } else {
56  }
57 }
58 
59 
60 std::string
62  // declare variable for error position
63  std::string errorPosition;
64  // check positions over lane
65  if (myPositionOverLane < 0) {
66  errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
67  }
69  errorPosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
70  }
71  return errorPosition;
72 }
73 
74 
75 void
77  // declare new position
78  double newPositionOverLane = myPositionOverLane;
79  // fix pos and lenght checkAndFixDetectorPosition
81  // set new position
83 }
84 
85 
86 void
88  // Calculate new position using old position
89  Position newPosition = myMove.originalViewPosition;
90  newPosition.add(offset);
91  // filtern position using snap to active grid
92  newPosition = myViewNet->snapToActiveGrid(newPosition);
94  // Update geometry
95  updateGeometry(false);
96 }
97 
98 
99 void
101  // commit new position allowing undo/redo
102  undoList->p_begin("position of " + getTagStr());
104  undoList->p_end();
105 }
106 
107 
108 void
110  // first check if object has to be removed from grid (SUMOTree)
111  if (updateGrid) {
113  }
114 
115  // Clear all containers
117 
118  // obtain position over lane
120  myGeometry.shape.push_back(myLane->getShape().positionAtOffset(fixedPositionOverLane * myLane->getLengthGeometryFactor()));
121 
122  // Obtain first position
123  Position f = myGeometry.shape[0] - Position(1, 0);
124 
125  // Obtain next position
126  Position s = myGeometry.shape[0] + Position(1, 0);
127 
128  // Save rotation (angle) of the vector constructed by points f and s
129  myGeometry.shapeRotations.push_back(myLane->getShape().rotationDegreeAtOffset(fixedPositionOverLane) * -1);
130 
131  // Set block icon position
133 
134  // Set offset of the block icon
135  myBlockIcon.offset = Position(-1, 0);
136 
137  // Set block icon rotation, and using their rotation for logo
139 
140  // last step is to check if object has to be added into grid (SUMOTree) again
141  if (updateGrid) {
143  }
144 }
145 
146 
147 GNELane*
149  return myLane;
150 }
151 
152 
153 void
155  // get values
156  glPushName(getGlID());
157  double width = (double) 2.0 * s.scale;
158  glLineWidth(1.0);
159  const double exaggeration = s.addSize.getExaggeration(s, this);
160 
161  // set color
164  } else {
166  }
167  // draw shape
168  glPushMatrix();
169  glTranslated(0, 0, getType());
170  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), 0);
171  glRotated(myGeometry.shapeRotations[0], 0, 0, 1);
172  glScaled(exaggeration, exaggeration, 1);
173  glBegin(GL_QUADS);
174  glVertex2d(-1.0, 2);
175  glVertex2d(-1.0, -2);
176  glVertex2d(1.0, -2);
177  glVertex2d(1.0, 2);
178  glEnd();
179  glTranslated(0, 0, .01);
180  glBegin(GL_LINES);
181  glVertex2d(0, 2 - .1);
182  glVertex2d(0, -2 + .1);
183  glEnd();
184 
185  // outline if isn't being drawn for selecting
186  if ((width * exaggeration > 1) && !s.drawForSelecting) {
187  // set color
190  } else {
192  }
193  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
194  glBegin(GL_QUADS);
195  glVertex2f(-1.0, 2);
196  glVertex2f(-1.0, -2);
197  glVertex2f(1.0, -2);
198  glVertex2f(1.0, 2);
199  glEnd();
200  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
201  }
202 
203  // position indicator if isn't being drawn for selecting
204  if ((width * exaggeration > 1) && !s.drawForSelecting) {
205  // set color
208  } else {
210  }
211  glRotated(90, 0, 0, -1);
212  glBegin(GL_LINES);
213  glVertex2d(0, 1.7);
214  glVertex2d(0, -1.7);
215  glEnd();
216  }
217 
218  // Pop shape matrix
219  glPopMatrix();
220 
221  // Check if the distance is enought to draw details and isn't being drawn for selecting
222  if ((s.scale * exaggeration >= 10) && !s.drawForSelecting) {
223  // Push matrix
224  glPushMatrix();
225  // Traslate to center of detector
226  glTranslated(myGeometry.shape.getLineCenter().x(), myGeometry.shape.getLineCenter().y(), getType() + 0.1);
227  // Rotate depending of myBlockIcon.rotation
228  glRotated(myBlockIcon.rotation, 0, 0, -1);
229  //move to logo position
230  glTranslated(-1, 0, 0);
231  // draw E1 logo
233  GLHelper::drawText("E1", Position(), .1, 1.5, s.selectionColor);
234  } else {
235  GLHelper::drawText("E1", Position(), .1, 1.5, RGBColor::BLACK);
236  }
237  // pop matrix
238  glPopMatrix();
239  // Show Lock icon depending of the Edit mode
240  myBlockIcon.draw();
241  }
242 
243  // Finish draw if isn't being drawn for selecting
244  if (!s.drawForSelecting) {
245  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
246  }
247 
248  // check if dotted contour has to be drawn
249  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
251  }
252 
253  // pop name
254  glPopName();
255 }
256 
257 
258 std::string
260  switch (key) {
261  case SUMO_ATTR_ID:
262  return getAdditionalID();
263  case SUMO_ATTR_LANE:
264  return myLane->getID();
265  case SUMO_ATTR_POSITION:
267  case SUMO_ATTR_FREQUENCY:
268  return toString(myFreq);
269  case SUMO_ATTR_NAME:
270  return myAdditionalName;
271  case SUMO_ATTR_FILE:
272  return myFilename;
273  case SUMO_ATTR_VTYPES:
274  return myVehicleTypes;
278  return toString(myBlockMovement);
279  case GNE_ATTR_SELECTED:
281  case GNE_ATTR_GENERIC:
282  return getGenericParametersStr();
283  default:
284  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
285  }
286 }
287 
288 
289 void
290 GNEDetectorE1::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
291  if (value == getAttribute(key)) {
292  return; //avoid needless changes, later logic relies on the fact that attributes have changed
293  }
294  switch (key) {
295  case SUMO_ATTR_ID:
296  case SUMO_ATTR_LANE:
297  case SUMO_ATTR_POSITION:
298  case SUMO_ATTR_FREQUENCY:
299  case SUMO_ATTR_NAME:
300  case SUMO_ATTR_FILE:
301  case SUMO_ATTR_VTYPES:
304  case GNE_ATTR_SELECTED:
305  case GNE_ATTR_GENERIC:
306  undoList->p_add(new GNEChange_Attribute(this, key, value));
307  break;
308  default:
309  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
310  }
311 
312 }
313 
314 
315 bool
316 GNEDetectorE1::isValid(SumoXMLAttr key, const std::string& value) {
317  switch (key) {
318  case SUMO_ATTR_ID:
319  return isValidDetectorID(value);
320  case SUMO_ATTR_LANE:
321  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
322  return true;
323  } else {
324  return false;
325  }
326  case SUMO_ATTR_POSITION:
327  return canParse<double>(value);
328  case SUMO_ATTR_FREQUENCY:
329  return (canParse<double>(value) && (parse<double>(value) >= 0));
330  case SUMO_ATTR_NAME:
332  case SUMO_ATTR_FILE:
334  case SUMO_ATTR_VTYPES:
335  if (value.empty()) {
336  return true;
337  } else {
339  }
341  return canParse<bool>(value);
343  return canParse<bool>(value);
344  case GNE_ATTR_SELECTED:
345  return canParse<bool>(value);
346  case GNE_ATTR_GENERIC:
347  return isGenericParametersValid(value);
348  default:
349  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
350  }
351 }
352 
353 // ===========================================================================
354 // private
355 // ===========================================================================
356 
357 void
358 GNEDetectorE1::setAttribute(SumoXMLAttr key, const std::string& value) {
359  switch (key) {
360  case SUMO_ATTR_ID:
361  changeAdditionalID(value);
362  break;
363  case SUMO_ATTR_LANE:
364  myLane = changeLane(myLane, value);
365  break;
366  case SUMO_ATTR_POSITION:
367  myPositionOverLane = parse<double>(value);
368  break;
369  case SUMO_ATTR_FREQUENCY:
370  myFreq = parse<double>(value);
371  break;
372  case SUMO_ATTR_FILE:
373  myFilename = value;
374  break;
375  case SUMO_ATTR_NAME:
376  myAdditionalName = value;
377  break;
378  case SUMO_ATTR_VTYPES:
379  myVehicleTypes = value;
380  break;
382  myFriendlyPosition = parse<bool>(value);
383  break;
385  myBlockMovement = parse<bool>(value);
386  break;
387  case GNE_ATTR_SELECTED:
388  if (parse<bool>(value)) {
390  } else {
392  }
393  break;
394  case GNE_ATTR_GENERIC:
396  break;
397  default:
398  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
399  }
400  // Update Geometry after setting a new attribute (but avoided for certain attributes)
401  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
402  updateGeometry(true);
403  }
404 }
405 
406 /****************************************************************************/
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
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
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::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
static const RGBColor SUMO_color_E1
color for E1 detectors
static const RGBColor WHITE
Definition: RGBColor.h:191
GNEDetectorE1(const std::string &id, GNELane *lane, GNEViewNet *viewNet, double pos, double freq, const std::string &filename, const std::string &vehicleTypes, const std::string &name, bool friendlyPos, bool blockMovement)
Constructor.
Stores the information about how to visualize structures.
Position offset
The offSet of the block icon.
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
bool isAdditionalValid() const
check if current additional is valid to be writed into XML (by default true, can be reimplemented in ...
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
double myFreq
The aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.h:154
~GNEDetectorE1()
Destructor.
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.
static const RGBColor BLACK
Definition: RGBColor.h:192
void fixAdditionalProblem()
fix additional problem
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
double rotation
The rotation of the block icon.
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.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
AdditionalMove myMove
variable AdditionalMove
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
GNEUndoList * getUndoList() const
get the undoList object
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
GNELane * myLane
The lane in which this detector is placed.
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.
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:1160
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
block movement of a graphic element
RGBColor selectionColor
NETEDIT special colors.
std::string myVehicleTypes
attribute vehicle types
Definition: GNEDetector.h:160
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
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:163
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:3575
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:157
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
void updateGeometry(bool updateGrid)
update pre-computed geometry information
std::string getAttribute(SumoXMLAttr key) const
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:669
GNELane * getLane() const
get lane
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
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
a E1 detector
element is selected
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.
std::string firstOriginalLanePosition
value for saving first original position over lane before moving
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
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
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.
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name) ...
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1059
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
std::string getAdditionalProblem() const
return a string with the current additional problem