Eclipse 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-2019 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, SUMOTime 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  edge
42 }, {}, {}, {}, {}, {}, {}, {}, {}, {}),
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, SUMOTime frequency, const std::string& name, const std::string& output, const std::string& routeprobe) :
51  GNEAdditional(id, viewNet, GLO_CALIBRATOR, SUMO_TAG_LANECALIBRATOR, name, false, {}, {lane}, {}, {}, {}, {}, {}, {}, {}, {}),
53 myFrequency(frequency),
54 myOutput(output),
55 myRouteProbe(routeprobe) {
56 }
57 
58 
60 
61 
62 void
64  // This additional cannot be moved
65 }
66 
67 
68 void
70  // This additional cannot be moved
71 }
72 
73 
74 void
76  // Clear all containers
78  // get shape depending of we have a edge or a lane
79  if (getLaneParents().size() > 0) {
80  // Get shape of lane parent
81  myGeometry.shape.push_back(getLaneParents().front()->getGeometry().shape.positionAtOffset(myPositionOverLane));
82  // Save rotation (angle) of the vector constructed by points f and s
83  myGeometry.shapeRotations.push_back(getLaneParents().front()->getGeometry().shape.rotationDegreeAtOffset(myPositionOverLane) * -1);
84  } else if (getEdgeParents().size() > 0) {
85  for (auto i : getEdgeParents().front()->getLanes()) {
86  // Get shape of lane parent
87  myGeometry.shape.push_back(i->getGeometry().shape.positionAtOffset(myPositionOverLane));
88  // Save rotation (angle) of the vector constructed by points f and s
89  myGeometry.shapeRotations.push_back(getEdgeParents().front()->getLanes().at(0)->getGeometry().shape.rotationDegreeAtOffset(myPositionOverLane) * -1);
90  }
91  } else {
92  throw ProcessError("Both myEdge and myLane aren't defined");
93  }
94 }
95 
96 
99  PositionVector shape = (getLaneParents().size() > 0) ? getLaneParents().front()->getGeometry().shape : getEdgeParents().front()->getLanes().at(0)->getGeometry().shape;
100  if (myPositionOverLane < 0) {
101  return shape.front();
102  } else if (myPositionOverLane > shape.length()) {
103  return shape.back();
104  } else {
105  return shape.positionAtOffset(myPositionOverLane);
106  }
107 }
108 
109 
110 Boundary
112  return myGeometry.shape.getBoxBoundary().grow(10);
113 }
114 
115 
116 std::string
118  // get parent name depending of we have a edge or a lane
119  if (getLaneParents().size() > 0) {
120  return getLaneParents().front()->getMicrosimID();
121  } else if (getEdgeParents().size() > 0) {
122  return getEdgeParents().front()->getLanes().at(0)->getMicrosimID();
123  } else {
124  throw ProcessError("Both myEdge and myLane aren't defined");
125  }
126 }
127 
128 
129 void
131  // get values
132  const double exaggeration = s.addSize.getExaggeration(s, this);
133  // begin draw
134  glPushName(getGlID());
135  glLineWidth(1.0);
136  // iterate over every Calibrator symbol
137  for (int i = 0; i < (int)myGeometry.shape.size(); ++i) {
138  const Position& pos = myGeometry.shape[i];
139  double rot = myGeometry.shapeRotations[i];
140  glPushMatrix();
141  glTranslated(pos.x(), pos.y(), getType());
142  glRotated(rot, 0, 0, 1);
143  glTranslated(0, 0, getType());
144  glScaled(exaggeration, exaggeration, 1);
145  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
146  // set color
147  if (drawUsingSelectColor()) {
149  } else {
151  }
152  // base
153  glBegin(GL_TRIANGLES);
154  glVertex2d(0 - 1.4, 0);
155  glVertex2d(0 - 1.4, 6);
156  glVertex2d(0 + 1.4, 6);
157  glVertex2d(0 + 1.4, 0);
158  glVertex2d(0 - 1.4, 0);
159  glVertex2d(0 + 1.4, 6);
160  glEnd();
161  // draw text if isn't being drawn for selecting
162  if (!s.drawForSelecting && s.drawDetail(s.detailSettings.calibratorText, exaggeration)) {
163  // set color depending of selection status
165  // draw "C"
166  GLHelper::drawText("C", Position(0, 1.5), 0.1, 3, textColor, 180);
167  // draw "edge" or "lane "
168  if (getLaneParents().size() > 0) {
169  GLHelper::drawText("lane", Position(0, 3), .1, 1, textColor, 180);
170  } else if (getEdgeParents().size() > 0) {
171  GLHelper::drawText("edge", Position(0, 3), .1, 1, textColor, 180);
172  } else {
173  throw ProcessError("Both myEdge and myLane aren't defined");
174  }
175  }
176  glPopMatrix();
177  // check if dotted contour has to be drawn
178  if (myViewNet->getDottedAC() == this) {
179  GLHelper::drawShapeDottedContourRectangle(s, getType(), pos, 2.8, 6, rot, 0, 3);
180  }
181  }
182  // draw name
184  // pop name
185  glPopName();
186 }
187 
188 
189 void
191  // Open calibrator dialog
192  GNECalibratorDialog calibratorDialog(this);
193 }
194 
195 
196 std::string
198  switch (key) {
199  case SUMO_ATTR_ID:
200  return getAdditionalID();
201  case SUMO_ATTR_EDGE:
202  return getEdgeParents().front()->getID();
203  case SUMO_ATTR_LANE:
204  return getLaneParents().front()->getID();
205  case SUMO_ATTR_POSITION:
207  case SUMO_ATTR_FREQUENCY:
208  return time2string(myFrequency);
209  case SUMO_ATTR_NAME:
210  return myAdditionalName;
211  case SUMO_ATTR_OUTPUT:
212  return myOutput;
214  return myRouteProbe;
215  case GNE_ATTR_SELECTED:
217  case GNE_ATTR_GENERIC:
218  return getGenericParametersStr();
219  default:
220  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
221  }
222 }
223 
224 
225 void
226 GNECalibrator::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
227  if (value == getAttribute(key)) {
228  return; //avoid needless changes, later logic relies on the fact that attributes have changed
229  }
230  switch (key) {
231  case SUMO_ATTR_ID:
232  case SUMO_ATTR_EDGE:
233  case SUMO_ATTR_LANE:
234  case SUMO_ATTR_POSITION:
235  case SUMO_ATTR_FREQUENCY:
236  case SUMO_ATTR_NAME:
237  case SUMO_ATTR_OUTPUT:
239  case GNE_ATTR_SELECTED:
240  case GNE_ATTR_GENERIC:
241  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
242  break;
243  default:
244  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
245  }
246 
247 }
248 
249 
250 bool
251 GNECalibrator::isValid(SumoXMLAttr key, const std::string& value) {
252  switch (key) {
253  case SUMO_ATTR_ID:
254  return isValidAdditionalID(value);
255  case SUMO_ATTR_EDGE:
256  if (myViewNet->getNet()->retrieveEdge(value, false) != nullptr) {
257  return true;
258  } else {
259  return false;
260  }
261  case SUMO_ATTR_LANE:
262  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
263  return true;
264  } else {
265  return false;
266  }
267  case SUMO_ATTR_POSITION:
268  if (canParse<double>(value)) {
269  // obtain position and check if is valid
270  double newPosition = parse<double>(value);
271  PositionVector shape = (getLaneParents().size() > 0) ? getLaneParents().front()->getGeometry().shape : getEdgeParents().front()->getLanes().at(0)->getGeometry().shape;
272  if ((newPosition < 0) || (newPosition > shape.length())) {
273  return false;
274  } else {
275  return true;
276  }
277  } else {
278  return false;
279  }
280  case SUMO_ATTR_FREQUENCY:
281  return canParse<SUMOTime>(value);
282  case SUMO_ATTR_NAME:
284  case SUMO_ATTR_OUTPUT:
287  return SUMOXMLDefinitions::isValidNetID(value);
288  case GNE_ATTR_SELECTED:
289  return canParse<bool>(value);
290  case GNE_ATTR_GENERIC:
291  return isGenericParametersValid(value);
292  default:
293  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
294  }
295 }
296 
297 
298 std::string
300  return getTagStr() + ": " + getID();
301 }
302 
303 
304 std::string
306  return getTagStr();
307 }
308 
309 // ===========================================================================
310 // private
311 // ===========================================================================
312 
313 void
314 GNECalibrator::setAttribute(SumoXMLAttr key, const std::string& value) {
315  switch (key) {
316  case SUMO_ATTR_ID:
317  changeAdditionalID(value);
318  break;
319  case SUMO_ATTR_EDGE:
320  changeEdgeParents(this, value);
321  break;
322  case SUMO_ATTR_LANE:
323  changeLaneParents(this, value);
324  break;
325  case SUMO_ATTR_POSITION:
326  myPositionOverLane = parse<double>(value);
327  break;
328  case SUMO_ATTR_FREQUENCY:
329  myFrequency = parse<SUMOTime>(value);
330  break;
331  case SUMO_ATTR_NAME:
332  myAdditionalName = value;
333  break;
334  case SUMO_ATTR_OUTPUT:
335  myOutput = value;
336  break;
338  myRouteProbe = value;
339  break;
340  case GNE_ATTR_SELECTED:
341  if (parse<bool>(value)) {
343  } else {
345  }
346  break;
347  case GNE_ATTR_GENERIC:
349  break;
350  default:
351  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
352  }
353 }
354 
355 /****************************************************************************/
std::string myRouteProbe
ID to current RouteProbe.
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:1020
long long int SUMOTime
Definition: SUMOTime.h:35
double scale
information about a lane&#39;s width (temporary, used for a single view)
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.
Definition: GNEAdditional.h:74
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
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.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
SUMOTime myFrequency
Frequency of calibrator.
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:668
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
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:46
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const RGBColor BLACK
Definition: RGBColor.h:198
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
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
void openAdditionalDialog()
open Calibrator Dialog
const std::vector< GNEEdge * > & getEdgeParents() const
get edge parents
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
GNECalibrator(const std::string &id, GNEViewNet *viewNet, GNEEdge *edge, double pos, SUMOTime frequency, const std::string &name, const std::string &output, const std::string &routeprobe)
Constructor using edge.
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:48
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
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.
Definition: GNEAdditional.h:68
RGBColor selectionColor
basic selection color
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
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
A calibrator placed over lane (used in netedit)
const std::vector< GNELane * > & getLaneParents() const
get lanes of VSS
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
const std::string getID() const
function to support debugging
a Calibrator
static bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element
static void drawShapeDottedContourRectangle(const GUIVisualizationSettings &s, const int type, const Position &center, const double width, const double height, const double rotation=0, const double offsetX=0, const double offsetY=0)
draw a dotted contour around the given Position with certain width and height
Definition: GLHelper.cpp:555
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
GUIVisualizationDetailSettings detailSettings
detail settings
Dialog for edit calibrators.
double myPositionOverLane
position over Lane
void changeLaneParents(GNEShape *elementChild, const std::string &newLaneIDs)
change edge parents of a shape
std::string getParentName() const
Returns the name of the parent object.
double length() const
Returns the length.
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:939
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
static const RGBColor calibrator
color for Calibrators
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
GUIGlID getGlID() const
Returns the numerical id of the object.
void changeEdgeParents(GNEShape *elementChild, const std::string &newEdgeIDs)
change edge parents of a shape
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
void updateGeometry()
update pre-computed geometry information
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
static const double calibratorText
details for calibrator text
GUIVisualizationColorSettings colorSettings
color settings
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
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)
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:1179