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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 //
19 /****************************************************************************/
20 #include <netedit/GNENet.h>
21 #include <netedit/GNEUndoList.h>
22 #include <netedit/GNEViewNet.h>
25 #include <utils/gui/div/GLHelper.h>
27 
28 #include "GNECalibrator.h"
29 
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
35 GNECalibrator::GNECalibrator(const std::string& id, GNENet* net, GNEEdge* edge, double pos, SUMOTime frequency,
36  const std::string& name, const std::string& output, const std::string& routeprobe) :
37  GNEAdditional(id, net, GLO_CALIBRATOR, SUMO_TAG_CALIBRATOR, name, false,
38 {}, {edge}, {}, {}, {}, {}, {}, {}),
39 myPositionOverLane(pos),
40 myFrequency(frequency),
41 myOutput(output),
42 myRouteProbe(routeprobe) {
43  // update centering boundary without updating grid
44  updateCenteringBoundary(false);
45 }
46 
47 
48 GNECalibrator::GNECalibrator(const std::string& id, GNENet* net, GNELane* lane, double pos, SUMOTime frequency,
49  const std::string& name, const std::string& output, const std::string& routeprobe) :
51 {}, {}, {lane}, {}, {}, {}, {}, {}),
52 myPositionOverLane(pos),
53 myFrequency(frequency),
54 myOutput(output),
55 myRouteProbe(routeprobe) {
56  // update centering boundary without updating grid
57  updateCenteringBoundary(false);
58 }
59 
60 
62 
63 
65 GNECalibrator::getMoveOperation(const double /*shapeOffset*/) {
66  // calibrators cannot be moved
67  return nullptr;
68 }
69 
70 
71 void
73  // get shape depending of we have a edge or a lane
74  if (getParentLanes().size() > 0) {
75  // update geometry
77  } else if (getParentEdges().size() > 0) {
78  // update geometry of first edge
80  // clear extra geometries
82  // iterate over every lane and get point
83  for (int i = 1; i < (int)getParentEdges().front()->getLanes().size(); i++) {
84  // add new calibrator geometry
85  GNEGeometry::Geometry calibratorGeometry;
86  calibratorGeometry.updateGeometry(getParentEdges().front()->getLanes().at(i), myPositionOverLane);
87  myEdgeCalibratorGeometries.push_back(calibratorGeometry);
88  }
89  } else {
90  throw ProcessError("Both edges and lanes aren't defined");
91  }
92 }
93 
94 
95 void
96 GNECalibrator::updateCenteringBoundary(const bool /*updateGrid*/) {
97  // first reset boundary
98  myBoundary.reset();
99  // now update geometry
100  updateGeometry();
101  // add shape boundary
103  // grow
104  myBoundary.grow(10);
105 }
106 
107 
108 void
109 GNECalibrator::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* newElement, GNEUndoList* undoList) {
110  if (splitPosition < myPositionOverLane) {
111  // change lane or edge
112  if (newElement->getTagProperty().getTag() == SUMO_TAG_LANE) {
113  setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
114  } else {
115  setAttribute(SUMO_ATTR_EDGE, newElement->getID(), undoList);
116  }
117  // now adjust start position
118  setAttribute(SUMO_ATTR_POSITION, toString(myPositionOverLane - splitPosition), undoList);
119  }
120 }
121 
122 
123 std::string
125  // get parent name depending of we have a edge or a lane
126  if (getParentLanes().size() > 0) {
127  return getParentLanes().front()->getID();
128  } else if (getParentEdges().size() > 0) {
129  return getParentEdges().front()->getLanes().at(0)->getID();
130  } else {
131  throw ProcessError("Both myEdge and myLane aren't defined");
132  }
133 }
134 
135 
136 void
138  // get values
139  const double exaggeration = s.addSize.getExaggeration(s, this);
140  // first check if additional has to be drawn
141  if (s.drawAdditionals(exaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
142  // begin push name
143  glPushName(getGlID());
144  // draw first symbol
146  // continue with the other symbols
147  for (const auto& edgeCalibratorGeometry : myEdgeCalibratorGeometries) {
148  drawCalibratorSymbol(s, exaggeration, edgeCalibratorGeometry.getShape().front(), edgeCalibratorGeometry.getShapeRotations().front());
149  }
150  // pop name
151  glPopName();
152  // draw name
153  drawAdditionalID(s);
154  }
155 }
156 
157 
158 void
160  // Open calibrator dialog
161  GNECalibratorDialog calibratorDialog(this);
162 }
163 
164 
165 std::string
167  switch (key) {
168  case SUMO_ATTR_ID:
169  return getID();
170  case SUMO_ATTR_EDGE:
171  return getParentEdges().front()->getID();
172  case SUMO_ATTR_LANE:
173  return getParentLanes().front()->getID();
174  case SUMO_ATTR_POSITION:
176  case SUMO_ATTR_FREQUENCY:
177  return time2string(myFrequency);
178  case SUMO_ATTR_NAME:
179  return myAdditionalName;
180  case SUMO_ATTR_OUTPUT:
181  return myOutput;
183  return myRouteProbe;
184  case GNE_ATTR_SELECTED:
186  case GNE_ATTR_PARAMETERS:
187  return getParametersStr();
188  default:
189  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
190  }
191 }
192 
193 
194 double
196  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
197 }
198 
199 
200 void
201 GNECalibrator::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
202  if (value == getAttribute(key)) {
203  return; //avoid needless changes, later logic relies on the fact that attributes have changed
204  }
205  switch (key) {
206  case SUMO_ATTR_ID:
207  case SUMO_ATTR_EDGE:
208  case SUMO_ATTR_LANE:
209  case SUMO_ATTR_POSITION:
210  case SUMO_ATTR_FREQUENCY:
211  case SUMO_ATTR_NAME:
212  case SUMO_ATTR_OUTPUT:
214  case GNE_ATTR_SELECTED:
215  case GNE_ATTR_PARAMETERS:
216  undoList->p_add(new GNEChange_Attribute(this, key, value));
217  break;
218  default:
219  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
220  }
221 
222 }
223 
224 
225 bool
226 GNECalibrator::isValid(SumoXMLAttr key, const std::string& value) {
227  switch (key) {
228  case SUMO_ATTR_ID:
229  return isValidAdditionalID(value);
230  case SUMO_ATTR_EDGE:
231  if (myNet->retrieveEdge(value, false) != nullptr) {
232  return true;
233  } else {
234  return false;
235  }
236  case SUMO_ATTR_LANE:
237  if (myNet->retrieveLane(value, false) != nullptr) {
238  return true;
239  } else {
240  return false;
241  }
242  case SUMO_ATTR_POSITION:
243  if (canParse<double>(value)) {
244  // obtain position and check if is valid
245  double newPosition = parse<double>(value);
246  PositionVector shape = (getParentLanes().size() > 0) ? getParentLanes().front()->getLaneShape() : getParentEdges().front()->getLanes().at(0)->getLaneShape();
247  if ((newPosition < 0) || (newPosition > shape.length())) {
248  return false;
249  } else {
250  return true;
251  }
252  } else {
253  return false;
254  }
255  case SUMO_ATTR_FREQUENCY:
256  return canParse<SUMOTime>(value);
257  case SUMO_ATTR_NAME:
259  case SUMO_ATTR_OUTPUT:
263  case GNE_ATTR_SELECTED:
264  return canParse<bool>(value);
265  case GNE_ATTR_PARAMETERS:
266  return Parameterised::areParametersValid(value);
267  default:
268  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
269  }
270 }
271 
272 
273 bool
275  return true;
276 }
277 
278 
279 std::string
281  return getTagStr() + ": " + getID();
282 }
283 
284 
285 std::string
287  return getTagStr();
288 }
289 
290 // ===========================================================================
291 // private
292 // ===========================================================================
293 
294 void GNECalibrator::drawCalibratorSymbol(const GUIVisualizationSettings& s, const double exaggeration, const Position& pos, const double rot) const {
295  // push layer matrix
296  glPushMatrix();
297  // translate to front
299  // translate to position
300  glTranslated(pos.x(), pos.y(), 0);
301  // rotate over lane
302  GNEGeometry::rotateOverLane(rot - 90);
303  // scale
304  glScaled(exaggeration, exaggeration, 1);
305  // set drawing mode
306  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
307  // set color
308  if (drawUsingSelectColor()) {
310  } else {
312  }
313  // base
314  glBegin(GL_TRIANGLES);
315  glVertex2d(0 - s.additionalSettings.calibratorWidth, 0);
318  glVertex2d(0 + s.additionalSettings.calibratorWidth, 0);
319  glVertex2d(0 - s.additionalSettings.calibratorWidth, 0);
321  glEnd();
322  // draw text if isn't being drawn for selecting
324  // set color depending of selection status
326  // draw "C"
327  GLHelper::drawText("C", Position(0, 1.5), 0.1, 3, textColor, 180);
328  // draw "edge" or "lane "
329  if (getParentLanes().size() > 0) {
330  GLHelper::drawText("lane", Position(0, 3), .1, 1, textColor, 180);
331  } else if (getParentEdges().size() > 0) {
332  GLHelper::drawText("edge", Position(0, 3), .1, 1, textColor, 180);
333  } else {
334  throw ProcessError("Both myEdge and myLane aren't defined");
335  }
336  }
337  // pop layer matrix
338  glPopMatrix();
339  // check if dotted contours has to be drawn
342  }
343  if (s.drawDottedContour() || myNet->getViewNet()->getFrontAttributeCarrier() == this) {
344  GNEGeometry::drawDottedSquaredShape(GNEGeometry::DottedContourType::FRONT, s, pos, 2, 1, 2, 0, rot, exaggeration);
345  }
346 }
347 
348 void
349 GNECalibrator::setAttribute(SumoXMLAttr key, const std::string& value) {
350  switch (key) {
351  case SUMO_ATTR_ID:
352  myNet->getAttributeCarriers()->updateID(this, value);
353  break;
354  case SUMO_ATTR_EDGE:
356  break;
357  case SUMO_ATTR_LANE:
359  break;
360  case SUMO_ATTR_POSITION:
361  myPositionOverLane = parse<double>(value);
362  break;
363  case SUMO_ATTR_FREQUENCY:
364  myFrequency = parse<SUMOTime>(value);
365  break;
366  case SUMO_ATTR_NAME:
367  myAdditionalName = value;
368  break;
369  case SUMO_ATTR_OUTPUT:
370  myOutput = value;
371  break;
373  myRouteProbe = value;
374  break;
375  case GNE_ATTR_SELECTED:
376  if (parse<bool>(value)) {
378  } else {
380  }
381  break;
382  case GNE_ATTR_PARAMETERS:
383  setParametersStr(value);
384  break;
385  default:
386  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
387  }
388 }
389 
390 
391 void
393  // nothing to do
394 }
395 
396 
397 void
398 GNECalibrator::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
399  // nothing to do
400 }
401 
402 
403 /****************************************************************************/
@ GLO_CALIBRATOR
a Calibrator
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
long long int SUMOTime
Definition: SUMOTime.h:31
@ SUMO_TAG_LANECALIBRATOR
A calibrator placed over lane (used in netedit)
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_TAG_CALIBRATOR
A calibrator placed over edge.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ SUMO_ATTR_EDGE
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_ROUTEPROBE
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_NAME
@ SUMO_ATTR_FREQUENCY
@ SUMO_ATTR_OUTPUT
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
void reset()
Resets the boundary.
Definition: Boundary.cpp:65
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
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, const int align=0, double width=-1)
Definition: GLHelper.cpp:498
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
GNEGeometry::Geometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void replaceAdditionalParentEdges(const std::string &value)
replace additional parent edges
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
std::string myAdditionalName
name of additional
Boundary myBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get Tag Property assigned to this object
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
Dialog for edit calibrators.
std::string getAttribute(SumoXMLAttr key) const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void drawCalibratorSymbol(const GUIVisualizationSettings &s, const double exaggeration, const Position &pos, const double rot) const
draw calibrator symbol
void updateGeometry()
update pre-computed geometry information
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string myRouteProbe
ID to current RouteProbe.
std::string myOutput
output of calibrator
std::string getParentName() const
Returns the name of the parent object.
~GNECalibrator()
Destructor.
SUMOTime myFrequency
Frequency of calibrator.
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
double myPositionOverLane
position over Lane
bool isAttributeEnabled(SumoXMLAttr key) const
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
double getAttributeDouble(SumoXMLAttr key) const
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
GNECalibrator(const std::string &id, GNENet *net, GNEEdge *edge, double pos, SUMOTime frequency, const std::string &name, const std::string &output, const std::string &routeprobe)
Constructor using edge.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void openAdditionalDialog()
open Calibrator Dialog
std::vector< GNEGeometry::Geometry > myEdgeCalibratorGeometries
extra calibrator geometries
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:49
class for NETEDIT geometries over lanes
Definition: GNEGeometry.h:76
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:45
move operation
move result
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1337
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true) const
get edge by id
Definition: GNENet.cpp:1141
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
const std::string & getID() const
get ID
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
GUIGlID getGlID() const
Returns the numerical id of the object.
Stores the information about how to visualize structures.
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationDetailSettings detailSettings
detail settings
GUIVisualizationSizeSettings addSize
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
bool drawDottedContour() const
check if dotted contour can be drawn
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
A list of positions.
double length() const
Returns the length.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static const RGBColor BLACK
Definition: RGBColor.h:188
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
static bool isValidAdditionalID(const std::string &value)
whether the given string is a valid id for an additional object
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
static void drawDottedSquaredShape(const DottedContourType type, const GUIVisualizationSettings &s, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
bool showAdditionals() const
check if additionals has to be drawn
static const RGBColor calibratorColor
color for Calibrators
static const double calibratorWidth
Calibrator width.
static const double calibratorHeight
Calibrator height.
RGBColor selectionColor
basic selection color
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double calibratorText
details for calibrator text
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values