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 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
29 #include <utils/gui/div/GLHelper.h>
31 
32 #include "GNECalibrator.h"
33 
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
39 GNECalibrator::GNECalibrator(const std::string& id, GNEViewNet* viewNet, GNEEdge* edge, double pos, double frequency, const std::string& name, const std::string& output, const std::string& routeprobe) :
40  GNEAdditional(id, viewNet, GLO_CALIBRATOR, SUMO_TAG_CALIBRATOR, name, false),
41  myEdge(edge),
42  myLane(nullptr),
43  myPositionOverLane(pos),
44  myFrequency(frequency),
45  myOutput(output),
46  myRouteProbe(routeprobe) {
47 }
48 
49 
50 GNECalibrator::GNECalibrator(const std::string& id, GNEViewNet* viewNet, GNELane* lane, double pos, double frequency, const std::string& name, const std::string& output, const std::string& routeprobe) :
51  GNEAdditional(id, viewNet, GLO_CALIBRATOR, SUMO_TAG_LANECALIBRATOR, name, false),
52  myEdge(nullptr),
53  myLane(lane),
54  myPositionOverLane(pos),
55  myFrequency(frequency),
56  myOutput(output),
57  myRouteProbe(routeprobe) {
58 }
59 
60 
62 
63 
64 void
66  // This additional cannot be moved
67 }
68 
69 
70 void
72  // This additional cannot be moved
73 }
74 
75 
76 void
78  // first check if object has to be removed from grid (SUMOTree)
79  if (updateGrid) {
81  }
82 
83  // Clear all containers
85 
86  // get shape depending of we have a edge or a lane
87  if (myLane) {
88  // Get shape of lane parent
90  // Save rotation (angle) of the vector constructed by points f and s
92  } else if (myEdge) {
93  for (auto i : myEdge->getLanes()) {
94  // Get shape of lane parent
95  myGeometry.shape.push_back(i->getShape().positionAtOffset(myPositionOverLane));
96  // Save rotation (angle) of the vector constructed by points f and s
97  myGeometry.shapeRotations.push_back(myEdge->getLanes().at(0)->getShape().rotationDegreeAtOffset(myPositionOverLane) * -1);
98  }
99  } else {
100  throw ProcessError("Both myEdge and myLane aren't defined");
101  }
102 
103  // last step is to check if object has to be added into grid (SUMOTree) again
104  if (updateGrid) {
106  }
107 }
108 
109 
110 Position
112  PositionVector shape = myLane ? myLane->getShape() : myEdge->getLanes().at(0)->getShape();
113  if (myPositionOverLane < 0) {
114  return shape.front();
115  } else if (myPositionOverLane > shape.length()) {
116  return shape.back();
117  } else {
118  return shape.positionAtOffset(myPositionOverLane);
119  }
120 }
121 
122 
123 std::string
125  // get parent name depending of we have a edge or a lane
126  if (myLane) {
127  return myLane->getMicrosimID();
128  } else if (myEdge) {
129  return myEdge->getLanes().at(0)->getMicrosimID();
130  } else {
131  throw ProcessError("Both myEdge and myLane aren't defined");
132  }
133 }
134 
135 
136 void
138  // get values
139  glPushName(getGlID());
140  glLineWidth(1.0);
141  const double exaggeration = s.addSize.getExaggeration(s, this);
142 
143  // iterate over every Calibrator symbol
144  for (int i = 0; i < (int)myGeometry.shape.size(); ++i) {
145  const Position& pos = myGeometry.shape[i];
146  double rot = myGeometry.shapeRotations[i];
147  glPushMatrix();
148  glTranslated(pos.x(), pos.y(), getType());
149  glRotated(rot, 0, 0, 1);
150  glTranslated(0, 0, getType());
151  glScaled(exaggeration, exaggeration, 1);
152  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
153 
156  } else {
157  GLHelper::setColor(RGBColor(255, 204, 0));
158  }
159  // base
160  glBegin(GL_TRIANGLES);
161  glVertex2d(0 - 1.4, 0);
162  glVertex2d(0 - 1.4, 6);
163  glVertex2d(0 + 1.4, 6);
164  glVertex2d(0 + 1.4, 0);
165  glVertex2d(0 - 1.4, 0);
166  glVertex2d(0 + 1.4, 6);
167  glEnd();
168 
169  // draw text if isn't being drawn for selecting
170  if ((s.scale * exaggeration >= 1.) && !s.drawForSelecting) {
171  // set color depending of selection status
173  // draw "C"
174  GLHelper::drawText("C", Position(0, 1.5), 0.1, 3, textColor, 180);
175  // draw "edge" or "lane "
176  if (myLane) {
177  GLHelper::drawText("lane", Position(0, 3), .1, 1, textColor, 180);
178  } else if (myEdge) {
179  GLHelper::drawText("edge", Position(0, 3), .1, 1, textColor, 180);
180  } else {
181  throw ProcessError("Both myEdge and myLane aren't defined");
182  }
183  }
184  glPopMatrix();
185  // check if dotted contour has to be drawn
186  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
187  GLHelper::drawShapeDottedContour(getType(), pos, 2.8, 6, rot, 0, 3);
188  }
189  }
190  // draw name
191  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
192 
193  // pop name
194  glPopName();
195 }
196 
197 
198 void
200  // Open calibrator dialog
201  GNECalibratorDialog calibratorDialog(this);
202 }
203 
204 
205 std::string
207  switch (key) {
208  case SUMO_ATTR_ID:
209  return getAdditionalID();
210  case SUMO_ATTR_EDGE:
211  return myEdge->getID();
212  case SUMO_ATTR_LANE:
213  return myLane->getID();
214  case SUMO_ATTR_POSITION:
216  case SUMO_ATTR_FREQUENCY:
217  return toString(myFrequency);
218  case SUMO_ATTR_NAME:
219  return myAdditionalName;
220  case SUMO_ATTR_OUTPUT:
221  return myOutput;
223  return myRouteProbe;
224  case GNE_ATTR_SELECTED:
226  case GNE_ATTR_GENERIC:
227  return getGenericParametersStr();
228  default:
229  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
230  }
231 }
232 
233 
234 void
235 GNECalibrator::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
236  if (value == getAttribute(key)) {
237  return; //avoid needless changes, later logic relies on the fact that attributes have changed
238  }
239  switch (key) {
240  case SUMO_ATTR_ID:
241  case SUMO_ATTR_EDGE:
242  case SUMO_ATTR_LANE:
243  case SUMO_ATTR_POSITION:
244  case SUMO_ATTR_FREQUENCY:
245  case SUMO_ATTR_NAME:
246  case SUMO_ATTR_OUTPUT:
248  case GNE_ATTR_SELECTED:
249  case GNE_ATTR_GENERIC:
250  undoList->p_add(new GNEChange_Attribute(this, key, value));
251  break;
252  default:
253  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
254  }
255 
256 }
257 
258 
259 bool
260 GNECalibrator::isValid(SumoXMLAttr key, const std::string& value) {
261  switch (key) {
262  case SUMO_ATTR_ID:
263  return isValidAdditionalID(value);
264  case SUMO_ATTR_EDGE:
265  if (myViewNet->getNet()->retrieveEdge(value, false) != nullptr) {
266  return true;
267  } else {
268  return false;
269  }
270  case SUMO_ATTR_LANE:
271  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
272  return true;
273  } else {
274  return false;
275  }
276  case SUMO_ATTR_POSITION:
277  if (canParse<double>(value)) {
278  // obtain position and check if is valid
279  double newPosition = parse<double>(value);
280  PositionVector shape = myLane ? myLane->getShape() : myEdge->getLanes().at(0)->getShape();
281  if ((newPosition < 0) || (newPosition > shape.length())) {
282  return false;
283  } else {
284  return true;
285  }
286  } else {
287  return false;
288  }
289  case SUMO_ATTR_FREQUENCY:
290  return (canParse<double>(value) && parse<double>(value) >= 0);
291  case SUMO_ATTR_NAME:
293  case SUMO_ATTR_OUTPUT:
296  return SUMOXMLDefinitions::isValidNetID(value);
297  case GNE_ATTR_SELECTED:
298  return canParse<bool>(value);
299  case GNE_ATTR_GENERIC:
300  return isGenericParametersValid(value);
301  default:
302  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
303  }
304 }
305 
306 
307 std::string
309  return getTagStr() + ": " + getID();
310 }
311 
312 
313 std::string
315  return getTagStr();
316 }
317 
318 // ===========================================================================
319 // private
320 // ===========================================================================
321 
322 void
323 GNECalibrator::setAttribute(SumoXMLAttr key, const std::string& value) {
324  switch (key) {
325  case SUMO_ATTR_ID:
326  changeAdditionalID(value);
327  break;
328  case SUMO_ATTR_EDGE:
329  myEdge = changeEdge(myEdge, value);
330  break;
331  case SUMO_ATTR_LANE:
332  myLane = changeLane(myLane, value);
333  break;
334  case SUMO_ATTR_POSITION:
335  myPositionOverLane = parse<double>(value);
336  break;
337  case SUMO_ATTR_FREQUENCY:
338  myFrequency = parse<double>(value);
339  break;
340  case SUMO_ATTR_NAME:
341  myAdditionalName = value;
342  break;
343  case SUMO_ATTR_OUTPUT:
344  myOutput = value;
345  break;
347  myRouteProbe = value;
348  break;
349  case GNE_ATTR_SELECTED:
350  if (parse<bool>(value)) {
352  } else {
354  }
355  break;
356  case GNE_ATTR_GENERIC:
358  break;
359  default:
360  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
361  }
362  // Update Geometry after setting a new attribute (but avoided for certain attributes)
363  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
364  updateGeometry(true);
365  }
366 }
367 
368 /****************************************************************************/
std::string myRouteProbe
ID to current RouteProbe.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
GNECalibrator(const std::string &id, GNEViewNet *viewNet, GNEEdge *edge, double pos, double frequency, const std::string &name, const std::string &output, const std::string &routeprobe)
Constructor using edge.
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:900
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
std::vector< double > shapeRotations
The rotations of the single shape parts.
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.
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:62
std::string getAttribute(SumoXMLAttr key) const
~GNECalibrator()
Destructor.
double x() const
Returns the x-position.
Definition: Position.h:57
Position getPositionInView() const
Returns position of additional in view.
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 clearGeometry()
reset geometry
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:192
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
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
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.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
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
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
PositionVector shape
The shape of the additional element.
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:1160
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
A calibrator placed over lane (used in netedit)
RGBColor selectionColor
NETEDIT special colors.
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:669
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:873
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:48
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
element is selected
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.
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
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
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
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
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