SUMO - Simulation of Urban MObility
GNEDetectorE1Instant.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 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
29 #include <utils/common/ToString.h>
30 #include <utils/geom/GeomHelper.h>
35 #include <utils/gui/div/GLHelper.h>
40 #include <netedit/GNEViewNet.h>
41 #include <netedit/GNEUndoList.h>
42 #include <netedit/GNENet.h>
45 #include <netedit/GNEViewParent.h>
46 
47 #include "GNEDetectorE1Instant.h"
48 
49 
50 // ===========================================================================
51 // member method definitions
52 // ===========================================================================
53 
54 GNEDetectorE1Instant::GNEDetectorE1Instant(const std::string& id, GNELane* lane, GNEViewNet* viewNet, double pos, const std::string& filename, const std::string& vehicleTypes, const std::string& name, bool friendlyPos, bool blockMovement) :
55  GNEDetector(id, viewNet, GLO_E1DETECTOR_INSTANT, SUMO_TAG_INSTANT_INDUCTION_LOOP, lane, pos, 0, filename, vehicleTypes, name, friendlyPos, blockMovement) {
56 }
57 
58 
60 }
61 
62 
63 void
65  // first check if object has to be removed from grid (SUMOTree)
66  if (updateGrid) {
68  }
69 
70  // Clear all containers
71  myShapeRotations.clear();
72  myShapeLengths.clear();
73 
74  // clear Shape
75  myShape.clear();
76 
77  // obtain position over lane
79  myShape.push_back(myLane->getShape().positionAtOffset(fixedPositionOverLane * myLane->getLengthGeometryFactor()));
80 
81  // Obtain first position
82  Position f = myShape[0] - Position(1, 0);
83 
84  // Obtain next position
85  Position s = myShape[0] + Position(1, 0);
86 
87  // Save rotation (angle) of the vector constructed by points f and s
88  myShapeRotations.push_back(myLane->getShape().rotationDegreeAtOffset(fixedPositionOverLane) * -1);
89 
90  // Set block icon position
92 
93  // Set offset of the block icon
94  myBlockIconOffset = Position(-1, 0);
95 
96  // Set block icon rotation, and using their rotation for logo
98 
99  // last step is to check if object has to be added into grid (SUMOTree) again
100  if (updateGrid) {
102  }
103 }
104 
105 
107  // with friendly position enabled position are "always fixed"
108  if (myFriendlyPosition) {
109  return true;
110  } else {
112  }
113 }
114 
115 
116 void
118  // get values
119  glPushName(getGlID());
120  double width = (double) 2.0 * s.scale;
121  glLineWidth(1.0);
122  const double exaggeration = s.addSize.getExaggeration(s);
123 
124  // set color
127  } else {
128  GLHelper::setColor(RGBColor(255, 0, 255));
129  }
130  // draw shape
131  glPushMatrix();
132  glTranslated(0, 0, getType());
133  glTranslated(myShape[0].x(), myShape[0].y(), 0);
134  glRotated(myShapeRotations[0], 0, 0, 1);
135  glScaled(exaggeration, exaggeration, 1);
136  glBegin(GL_QUADS);
137  glVertex2d(-1.0, 2);
138  glVertex2d(-1.0, -2);
139  glVertex2d(1.0, -2);
140  glVertex2d(1.0, 2);
141  glEnd();
142  glTranslated(0, 0, .01);
143  glBegin(GL_LINES);
144  glVertex2d(0, 2 - .1);
145  glVertex2d(0, -2 + .1);
146  glEnd();
147 
148  // outline if isn't being drawn for selecting
149  if ((width * exaggeration > 1) && !s.drawForSelecting) {
150  // set color
153  } else {
155  }
156  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
157  glBegin(GL_QUADS);
158  glVertex2f(-1.0, 2);
159  glVertex2f(-1.0, -2);
160  glVertex2f(1.0, -2);
161  glVertex2f(1.0, 2);
162  glEnd();
163  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
164  }
165 
166  // position indicator if isn't being drawn for selecting
167  if ((width * exaggeration > 1) && !s.drawForSelecting) {
168  // set color
171  } else {
173  }
174  glRotated(90, 0, 0, -1);
175  glBegin(GL_LINES);
176  glVertex2d(0, 1.7);
177  glVertex2d(0, -1.7);
178  glEnd();
179  }
180 
181  // Pop shape matrix
182  glPopMatrix();
183 
184  // Check if the distance is enought to draw details and isn't being drawn for selecting
185  if ((s.scale * exaggeration >= 10) && !s.drawForSelecting) {
186  // Push matrix
187  glPushMatrix();
188  // Traslate to center of detector
189  glTranslated(myShape.getLineCenter().x(), myShape.getLineCenter().y(), getType() + 0.1);
190  // Rotate depending of myBlockIconRotation
191  glRotated(myBlockIconRotation, 0, 0, -1);
192  //move to logo position
193  glTranslated(-1, 0, 0);
194  // draw E1 logo
197  } else {
198  GLHelper::drawText("E1", Position(), .1, 1.5, RGBColor::BLACK);
199  }
200  // pop matrix
201  glPopMatrix();
202  // Show Lock icon depending of the Edit mode
203  drawLockIcon();
204  }
205 
206  // Finish draw if isn't being drawn for selecting
207  if (!s.drawForSelecting) {
208  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
209  }
210  glPopName();
211 }
212 
213 
214 std::string
216  switch (key) {
217  case SUMO_ATTR_ID:
218  return getAdditionalID();
219  case SUMO_ATTR_LANE:
220  return myLane->getID();
221  case SUMO_ATTR_POSITION:
223  case SUMO_ATTR_NAME:
224  return myAdditionalName;
225  case SUMO_ATTR_FILE:
226  return myFilename;
227  case SUMO_ATTR_VTYPES:
228  return myVehicleTypes;
232  return toString(myBlockMovement);
233  case GNE_ATTR_SELECTED:
235  case GNE_ATTR_GENERIC:
236  return getGenericParametersStr();
237  default:
238  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
239  }
240 }
241 
242 
243 void
244 GNEDetectorE1Instant::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
245  if (value == getAttribute(key)) {
246  return; //avoid needless changes, later logic relies on the fact that attributes have changed
247  }
248  switch (key) {
249  case SUMO_ATTR_ID:
250  case SUMO_ATTR_LANE:
251  case SUMO_ATTR_POSITION:
252  case SUMO_ATTR_NAME:
253  case SUMO_ATTR_FILE:
254  case SUMO_ATTR_VTYPES:
257  case GNE_ATTR_SELECTED:
258  case GNE_ATTR_GENERIC:
259  undoList->p_add(new GNEChange_Attribute(this, key, value));
260  break;
261  default:
262  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
263  }
264 
265 }
266 
267 
268 bool
269 GNEDetectorE1Instant::isValid(SumoXMLAttr key, const std::string& value) {
270  switch (key) {
271  case SUMO_ATTR_ID:
272  return isValidAdditionalID(value);
273  case SUMO_ATTR_LANE:
274  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
275  return true;
276  } else {
277  return false;
278  }
279  case SUMO_ATTR_POSITION:
280  return canParse<double>(value);
281  case SUMO_ATTR_NAME:
283  case SUMO_ATTR_FILE:
285  case SUMO_ATTR_VTYPES:
286  if (value.empty()) {
287  return true;
288  } else {
290  }
292  return canParse<bool>(value);
294  return canParse<bool>(value);
295  case GNE_ATTR_SELECTED:
296  return canParse<bool>(value);
297  case GNE_ATTR_GENERIC:
298  return isGenericParametersValid(value);
299  default:
300  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
301  }
302 }
303 
304 // ===========================================================================
305 // private
306 // ===========================================================================
307 
308 void
309 GNEDetectorE1Instant::setAttribute(SumoXMLAttr key, const std::string& value) {
310  switch (key) {
311  case SUMO_ATTR_ID:
312  changeAdditionalID(value);
313  break;
314  case SUMO_ATTR_LANE:
315  myLane = changeLane(myLane, value);
316  break;
317  case SUMO_ATTR_POSITION:
318  myPositionOverLane = parse<double>(value);
319  break;
320  case SUMO_ATTR_NAME:
321  myAdditionalName = value;
322  break;
323  case SUMO_ATTR_FILE:
324  myFilename = value;
325  break;
326  case SUMO_ATTR_VTYPES:
327  myVehicleTypes = value;
328  break;
330  myFriendlyPosition = parse<bool>(value);
331  break;
333  myBlockMovement = parse<bool>(value);
334  break;
335  case GNE_ATTR_SELECTED:
336  if (parse<bool>(value)) {
338  } else {
340  }
341  break;
342  case GNE_ATTR_GENERIC:
344  break;
345  default:
346  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
347  }
348  // After setting attribute always update Geometry
349  updateGeometry(true);
350 }
351 
352 /****************************************************************************/
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)
void setBlockIconRotation(GNELane *additionalLane=nullptr)
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
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
static const RGBColor WHITE
Definition: RGBColor.h:179
Stores the information about how to visualize structures.
bool isDetectorPositionFixed() const
check if Position of detector is fixed
double y() const
Returns the y-position.
Definition: Position.h:61
double x() const
Returns the x-position.
Definition: Position.h:56
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
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
static const RGBColor BLACK
Definition: RGBColor.h:180
std::vector< double > myShapeRotations
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
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
std::string getAttribute(SumoXMLAttr key) const
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:105
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void drawLockIcon(double size=0.5) const
draw lock icon
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:1298
An instantenous induction loop.
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
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:1175
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
block movement of a graphic element
std::string myVehicleTypes
attribute vehicle types
Definition: GNEDetector.h:159
double getLengthGeometryFactor() const
get lenght geometry factor
Definition: GNELane.cpp:1355
std::vector< double > myShapeLengths
The lengths of the shape parts.
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
GNEDetectorE1Instant(const std::string &id, GNELane *lane, GNEViewNet *viewNet, double pos, const std::string &filename, const std::string &vehicleTypes, const std::string &name, bool friendlyPos, bool blockMovement)
Constructor.
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:162
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:3543
Position myBlockIconOffset
The offSet of the block icon.
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:156
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
~GNEDetectorE1Instant()
Destructor.
void updateGeometry(bool updateGrid)
update pre-computed geometry information
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:679
element is selected
GNELane * myLane
The lane in which this detector is placed.
Definition: GNEDetector.h:147
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.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
static const RGBColor selectionColor
Definition: GNENet.h:96
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:586
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1168
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:1074
double myBlockIconRotation
The rotation of the block icon.
GNELane * changeLane(GNELane *oldLane, const std::string &newLaneID)
change lane of additional
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:150
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get XML Tag assigned to this object