SUMO - Simulation of Urban MObility
GNECalibrator.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>
43 #include <netedit/GNEViewNet.h>
44 #include <netedit/GNEUndoList.h>
45 #include <netedit/GNENet.h>
46 #include <netedit/GNEViewParent.h>
47 
48 #include "GNECalibrator.h"
49 #include "GNERouteProbe.h"
50 #include "GNECalibratorFlow.h"
52 #include "GNECalibratorRoute.h"
53 
54 
55 // ===========================================================================
56 // member method definitions
57 // ===========================================================================
58 
59 GNECalibrator::GNECalibrator(const std::string& id, GNEViewNet* viewNet, GNEEdge* edge, double pos, double frequency, const std::string& name, const std::string& output) :
60  GNEAdditional(id, viewNet, GLO_CALIBRATOR, SUMO_TAG_CALIBRATOR, name, false),
61  myEdge(edge),
62  myLane(nullptr),
63  myPositionOverLane(pos),
64  myFrequency(frequency),
65  myOutput(output),
66  myRouteProbe(nullptr) {
67 }
68 
69 
70 GNECalibrator::GNECalibrator(const std::string& id, GNEViewNet* viewNet, GNELane* lane, double pos, double frequency, const std::string& name, const std::string& output) :
71  GNEAdditional(id, viewNet, GLO_CALIBRATOR, SUMO_TAG_LANECALIBRATOR, name, false),
72  myEdge(nullptr),
73  myLane(lane),
74  myPositionOverLane(pos),
75  myFrequency(frequency),
76  myOutput(output),
77  myRouteProbe(nullptr) {
78 }
79 
80 
82 
83 
84 void
86  // This additional cannot be moved
87 }
88 
89 
90 void
92  // This additional cannot be moved
93 }
94 
95 
96 void
98  // first check if object has to be removed from grid (SUMOTree)
99  if (updateGrid) {
101  }
102  // Clear all containers
103  myShapeRotations.clear();
104  myShapeLengths.clear();
105  // clear Shape
106  myShape.clear();
107  // get shape depending of we have a edge or a lane
108  if (myLane) {
109  // Get shape of lane parent
111  // Save rotation (angle) of the vector constructed by points f and s
113  } else if (myEdge) {
114  for (auto i : myEdge->getLanes()) {
115  // Get shape of lane parent
116  myShape.push_back(i->getShape().positionAtOffset(myPositionOverLane));
117  // Save rotation (angle) of the vector constructed by points f and s
118  myShapeRotations.push_back(myEdge->getLanes().at(0)->getShape().rotationDegreeAtOffset(myPositionOverLane) * -1);
119  }
120  } else {
121  throw ProcessError("Both myEdge and myLane aren't defined");
122  }
123  // last step is to check if object has to be added into grid (SUMOTree) again
124  if (updateGrid) {
126  }
127 }
128 
129 
130 Position
132  PositionVector shape = myLane ? myLane->getShape() : myEdge->getLanes().at(0)->getShape();
133  if (myPositionOverLane < 0) {
134  return shape.front();
135  } else if (myPositionOverLane > shape.length()) {
136  return shape.back();
137  } else {
138  return shape.positionAtOffset(myPositionOverLane);
139  }
140 }
141 
142 
143 std::string
145  // get parent name depending of we have a edge or a lane
146  if (myLane) {
147  return myLane->getMicrosimID();
148  } else if (myEdge) {
149  return myEdge->getLanes().at(0)->getMicrosimID();
150  } else {
151  throw ProcessError("Both myEdge and myLane aren't defined");
152  }
153 }
154 
155 
156 void
158  // get values
159  glPushName(getGlID());
160  glLineWidth(1.0);
161  const double exaggeration = s.addSize.getExaggeration(s);
162 
163  // iterate over every Calibrator symbol
164  for (int i = 0; i < (int)myShape.size(); ++i) {
165  const Position& pos = myShape[i];
166  double rot = myShapeRotations[i];
167  glPushMatrix();
168  glTranslated(pos.x(), pos.y(), getType());
169  glRotated(rot, 0, 0, 1);
170  glTranslated(0, 0, getType());
171  glScaled(exaggeration, exaggeration, 1);
172  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
173 
176  } else {
177  GLHelper::setColor(RGBColor(255, 204, 0));
178  }
179  // base
180  glBegin(GL_TRIANGLES);
181  glVertex2d(0 - 1.4, 0);
182  glVertex2d(0 - 1.4, 6);
183  glVertex2d(0 + 1.4, 6);
184  glVertex2d(0 + 1.4, 0);
185  glVertex2d(0 - 1.4, 0);
186  glVertex2d(0 + 1.4, 6);
187  glEnd();
188 
189  // draw text if isn't being drawn for selecting
190  if ((s.scale * exaggeration >= 1.) && !s.drawForSelecting) {
191  // set color depending of selection status
193  // draw "C"
194  GLHelper::drawText("C", Position(0, 1.5), 0.1, 3, textColor, 180);
195  // draw "edge" or "lane "
196  if (myLane) {
197  GLHelper::drawText("lane", Position(0, 3), .1, 1, textColor, 180);
198  } else if (myEdge) {
199  GLHelper::drawText("edge", Position(0, 3), .1, 1, textColor, 180);
200  } else {
201  throw ProcessError("Both myEdge and myLane aren't defined");
202  }
203  }
204  glPopMatrix();
205  // check if dotted contour has to be drawn
206  if (!s.drawForSelecting && (myViewNet->getACUnderCursor() == this)) {
207  GLHelper::drawShapeDottedContour(getType(), pos, 2.8, 6, rot, 0, 3);
208  }
209  }
210  // draw name
211  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
212 
213  // pop name
214  glPopName();
215 }
216 
217 
218 void
220  // Open calibrator dialog
221  GNECalibratorDialog calibratorDialog(this);
222 }
223 
224 
225 std::string
227  switch (key) {
228  case SUMO_ATTR_ID:
229  return getAdditionalID();
230  case SUMO_ATTR_EDGE:
231  return myEdge->getID();
232  case SUMO_ATTR_LANE:
233  return myLane->getID();
234  case SUMO_ATTR_POSITION:
236  case SUMO_ATTR_FREQUENCY:
237  return toString(myFrequency);
238  case SUMO_ATTR_NAME:
239  return myAdditionalName;
240  case SUMO_ATTR_OUTPUT:
241  return myOutput;
243  if (myRouteProbe) {
244  return myRouteProbe->getID();
245  } else {
246  return "";
247  }
248  case GNE_ATTR_SELECTED:
250  case GNE_ATTR_GENERIC:
251  return getGenericParametersStr();
252  default:
253  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
254  }
255 }
256 
257 
258 void
259 GNECalibrator::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
260  if (value == getAttribute(key)) {
261  return; //avoid needless changes, later logic relies on the fact that attributes have changed
262  }
263  switch (key) {
264  case SUMO_ATTR_ID:
265  case SUMO_ATTR_EDGE:
266  case SUMO_ATTR_LANE:
267  case SUMO_ATTR_POSITION:
268  case SUMO_ATTR_FREQUENCY:
269  case SUMO_ATTR_NAME:
270  case SUMO_ATTR_OUTPUT:
272  case GNE_ATTR_SELECTED:
273  case GNE_ATTR_GENERIC:
274  undoList->p_add(new GNEChange_Attribute(this, key, value));
275  break;
276  default:
277  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
278  }
279 
280 }
281 
282 
283 bool
284 GNECalibrator::isValid(SumoXMLAttr key, const std::string& value) {
285  switch (key) {
286  case SUMO_ATTR_ID:
287  return isValidAdditionalID(value);
288  case SUMO_ATTR_EDGE:
289  if (myViewNet->getNet()->retrieveEdge(value, false) != nullptr) {
290  return true;
291  } else {
292  return false;
293  }
294  case SUMO_ATTR_LANE:
295  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
296  return true;
297  } else {
298  return false;
299  }
300  case SUMO_ATTR_POSITION:
301  if (canParse<double>(value)) {
302  // obtain position and check if is valid
303  double newPosition = parse<double>(value);
304  PositionVector shape = myLane ? myLane->getShape() : myEdge->getLanes().at(0)->getShape();
305  if ((newPosition < 0) || (newPosition > shape.length())) {
306  return false;
307  } else {
308  return true;
309  }
310  } else {
311  return false;
312  }
313  case SUMO_ATTR_FREQUENCY:
314  return (canParse<double>(value) && parse<double>(value) >= 0);
315  case SUMO_ATTR_NAME:
317  case SUMO_ATTR_OUTPUT:
320  if (SUMOXMLDefinitions::isValidNetID(value) && (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_ROUTEPROBE, value, false) != nullptr)) {
321  return true;
322  } else {
323  return false;
324  }
325  case GNE_ATTR_SELECTED:
326  return canParse<bool>(value);
327  case GNE_ATTR_GENERIC:
328  return isGenericParametersValid(value);
329  default:
330  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
331  }
332 }
333 
334 
335 std::string
337  return toString(getTag()) + ": " + getID();
338 }
339 
340 
341 std::string
343  return toString(getTag());
344 }
345 
346 // ===========================================================================
347 // private
348 // ===========================================================================
349 
350 void
351 GNECalibrator::setAttribute(SumoXMLAttr key, const std::string& value) {
352  switch (key) {
353  case SUMO_ATTR_ID:
354  changeAdditionalID(value);
355  break;
356  case SUMO_ATTR_EDGE:
357  myEdge = changeEdge(myEdge, value);
358  break;
359  case SUMO_ATTR_LANE:
360  myLane = changeLane(myLane, value);
361  break;
362  case SUMO_ATTR_POSITION:
363  myPositionOverLane = parse<double>(value);
364  break;
365  case SUMO_ATTR_FREQUENCY:
366  myFrequency = parse<double>(value);
367  break;
368  case SUMO_ATTR_NAME:
369  myAdditionalName = value;
370  break;
371  case SUMO_ATTR_OUTPUT:
372  myOutput = value;
373  break;
376  break;
377  case GNE_ATTR_SELECTED:
378  if (parse<bool>(value)) {
380  } else {
382  }
383  break;
384  case GNE_ATTR_GENERIC:
386  break;
387  default:
388  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
389  }
390  // After setting attribute always update Geometry
391  updateGeometry(true);
392 }
393 
394 /****************************************************************************/
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
const GNEAttributeCarrier * getACUnderCursor() const
get AttributeCarrier under cursor
a routeprobe detector
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:907
double scale
information about a lane&#39;s width (temporary, used for a single view)
void updateGeometry(bool updateGrid)
update pre-computed geometry information
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
GUIVisualizationTextSettings addName
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
A calibrator placed over edge.
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:61
std::string getAttribute(SumoXMLAttr key) const
~GNECalibrator()
Destructor.
double x() const
Returns the x-position.
Definition: Position.h:56
Position getPositionInView() const
Returns position of additional in view.
Representation of a RouteProbe in netedit.
Definition: GNERouteProbe.h:36
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
GNERouteProbe * myRouteProbe
pointer to current RouteProbe
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
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
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
void openAdditionalDialog()
open Calibrator Dialog
GNECalibrator(const std::string &id, GNEViewNet *viewNet, GNEEdge *edge, double pos, double frequency, const std::string &name, const std::string &output)
Constructor using edge.
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.
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:1787
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.
std::string myOutput
output of calibrator
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
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
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:1167
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
A calibrator placed over lane (used in netedit)
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
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
const std::string getID() const
function to support debugging
a Calibrator
GNELane * myLane
The lane in which CalibratorLane are placed.
static bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
Dialog for edit calibrators.
double myPositionOverLane
position over Lane
std::string getParentName() const
Returns the name of the parent object.
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:613
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:832
double length() const
Returns the length.
GNEEdge * changeEdge(GNEEdge *oldEdge, const std::string &newEdgeID)
change edge of additional
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:53
element is selected
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
std::string getGenericParametersStr() const
return generic parameters in string format
GNEEdge * myEdge
The edge in which Calibrators are placed.
GNENet * getNet() const
get the net object
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
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
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
double myFrequency
Frequency of calibrator.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
static const RGBColor selectionColor
Definition: GNENet.h:96
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1160
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:1066
GNELane * changeLane(GNELane *oldLane, const std::string &newLaneID)
change lane of additional
SumoXMLTag getTag() const
get XML Tag assigned to this object