Eclipse SUMO - Simulation of Urban MObility
GNEDetectorE1.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 
26 #include "GNEDetectorE1.h"
27 #include "GNEAdditionalHandler.h"
28 
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
33 
34 GNEDetectorE1::GNEDetectorE1(const std::string& id, GNELane* lane, GNENet* net, double pos, SUMOTime freq, const std::string& filename, const std::string& vehicleTypes, const std::string& name, bool friendlyPos, bool blockMovement) :
35  GNEDetector(id, net, GLO_E1DETECTOR, SUMO_TAG_E1DETECTOR, pos, time2string(freq), filename, vehicleTypes, name, friendlyPos, blockMovement, {
36  lane
37 }) {
38  // update centering boundary without updating grid
39  updateCenteringBoundary(false);
40 }
41 
42 
44 }
45 
46 
47 bool
49  // with friendly position enabled position are "always fixed"
50  if (myFriendlyPosition) {
51  return true;
52  } else {
53  return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
54  }
55 }
56 
57 
58 std::string
60  // declare variable for error position
61  std::string errorPosition;
62  const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
63  // check positions over lane
64  if (myPositionOverLane < -len) {
65  errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
66  }
67  if (myPositionOverLane > len) {
68  errorPosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
69  }
70  return errorPosition;
71 }
72 
73 
74 void
76  // declare new position
77  double newPositionOverLane = myPositionOverLane;
78  // fix pos and length checkAndFixDetectorPosition
79  GNEAdditionalHandler::checkAndFixDetectorPosition(newPositionOverLane, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), true);
80  // set new position
82 }
83 
84 
85 void
87  // update geometry
89 }
90 
91 
92 void
94  // Obtain exaggeration of the draw
95  const double E1Exaggeration = s.addSize.getExaggeration(s, this);
96  // first check if additional has to be drawn
97  if (s.drawAdditionals(E1Exaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
98  // obtain scaledSize
99  const double scaledWidth = s.detectorSettings.E1Width * 0.5 * s.scale;
100  // declare colors
101  RGBColor mainColor, secondColor, textColor;
102  // set color
103  if (drawUsingSelectColor()) {
105  secondColor = mainColor.changedBrightness(-32);
106  textColor = mainColor.changedBrightness(32);
107  } else {
108  mainColor = s.detectorSettings.E1Color;
109  secondColor = RGBColor::WHITE;
110  textColor = RGBColor::BLACK;
111  }
112  // start drawing
113  glPushName(getGlID());
114  // push layer matrix
115  glPushMatrix();
116  // translate to front
118  // draw E1 shape
119  drawE1Shape(s, E1Exaggeration, scaledWidth, mainColor, secondColor);
120  // Check if the distance is enought to draw details
121  if (s.drawDetail(s.detailSettings.detectorDetails, E1Exaggeration)) {
122  // draw E1 Logo
123  drawDetectorLogo(s, E1Exaggeration, "E1", textColor);
124  // draw lock icon
125  GNEViewNetHelper::LockIcon::drawLockIcon(this, myAdditionalGeometry, E1Exaggeration, 1, 0, true);
126  }
127  // pop layer matrix
128  glPopMatrix();
129  // Pop name
130  glPopName();
131  // Draw additional ID
132  drawAdditionalID(s);
133  // draw additional name
135  // check if dotted contours has to be drawn
138  }
139  if (s.drawDottedContour() || myNet->getViewNet()->getFrontAttributeCarrier() == this) {
141  }
142  }
143 }
144 
145 
146 std::string
148  switch (key) {
149  case SUMO_ATTR_ID:
150  return getID();
151  case SUMO_ATTR_LANE:
152  return getParentLanes().front()->getID();
153  case SUMO_ATTR_POSITION:
155  case SUMO_ATTR_FREQUENCY:
156  return myFreq;
157  case SUMO_ATTR_NAME:
158  return myAdditionalName;
159  case SUMO_ATTR_FILE:
160  return myFilename;
161  case SUMO_ATTR_VTYPES:
162  return myVehicleTypes;
166  return toString(myBlockMovement);
167  case GNE_ATTR_SELECTED:
169  case GNE_ATTR_PARAMETERS:
170  return getParametersStr();
171  default:
172  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
173  }
174 }
175 
176 
177 void
178 GNEDetectorE1::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
179  if (value == getAttribute(key)) {
180  return; //avoid needless changes, later logic relies on the fact that attributes have changed
181  }
182  switch (key) {
183  case SUMO_ATTR_ID:
184  case SUMO_ATTR_LANE:
185  case SUMO_ATTR_POSITION:
186  case SUMO_ATTR_FREQUENCY:
187  case SUMO_ATTR_NAME:
188  case SUMO_ATTR_FILE:
189  case SUMO_ATTR_VTYPES:
192  case GNE_ATTR_SELECTED:
193  case GNE_ATTR_PARAMETERS:
194  undoList->p_add(new GNEChange_Attribute(this, key, value));
195  break;
196  default:
197  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
198  }
199 
200 }
201 
202 
203 bool
204 GNEDetectorE1::isValid(SumoXMLAttr key, const std::string& value) {
205  switch (key) {
206  case SUMO_ATTR_ID:
207  return isValidDetectorID(value);
208  case SUMO_ATTR_LANE:
209  if (myNet->retrieveLane(value, false) != nullptr) {
210  return true;
211  } else {
212  return false;
213  }
214  case SUMO_ATTR_POSITION:
215  return canParse<double>(value) && fabs(parse<double>(value)) < getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
216  case SUMO_ATTR_FREQUENCY:
217  return (canParse<double>(value) && (parse<double>(value) >= 0));
218  case SUMO_ATTR_NAME:
220  case SUMO_ATTR_FILE:
222  case SUMO_ATTR_VTYPES:
223  if (value.empty()) {
224  return true;
225  } else {
227  }
229  return canParse<bool>(value);
231  return canParse<bool>(value);
232  case GNE_ATTR_SELECTED:
233  return canParse<bool>(value);
234  case GNE_ATTR_PARAMETERS:
235  return Parameterised::areParametersValid(value);
236  default:
237  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
238  }
239 }
240 
241 
242 bool
244  return true;
245 }
246 
247 // ===========================================================================
248 // private
249 // ===========================================================================
250 
251 void
252 GNEDetectorE1::setAttribute(SumoXMLAttr key, const std::string& value) {
253  switch (key) {
254  case SUMO_ATTR_ID:
255  myNet->getAttributeCarriers()->updateID(this, value);
256  break;
257  case SUMO_ATTR_LANE:
259  break;
260  case SUMO_ATTR_POSITION:
261  myPositionOverLane = parse<double>(value);
262  break;
263  case SUMO_ATTR_FREQUENCY:
264  myFreq = value;
265  break;
266  case SUMO_ATTR_FILE:
267  myFilename = value;
268  break;
269  case SUMO_ATTR_NAME:
270  myAdditionalName = value;
271  break;
272  case SUMO_ATTR_VTYPES:
273  myVehicleTypes = value;
274  break;
276  myFriendlyPosition = parse<bool>(value);
277  break;
279  myBlockMovement = parse<bool>(value);
280  break;
281  case GNE_ATTR_SELECTED:
282  if (parse<bool>(value)) {
284  } else {
286  }
287  break;
288  case GNE_ATTR_PARAMETERS:
289  setParametersStr(value);
290  break;
291  default:
292  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
293  }
294 }
295 
296 
297 /****************************************************************************/
@ GLO_E1DETECTOR
a E1 detector
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
long long int SUMOTime
Definition: SUMOTime.h:31
@ SUMO_TAG_E1DETECTOR
an e1 detector
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ SUMO_ATTR_FILE
@ GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_FREQUENCY
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
static bool checkAndFixDetectorPosition(double &pos, const double laneLength, const bool friendlyPos)
check if the position of a detector over a lane is valid
const std::string & getID() const
get ID
GNEGeometry::Geometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
std::string myAdditionalName
name of additional
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
bool isValidDetectorID(const std::string &newID) const
check if a new detector 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
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
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
bool isAttributeEnabled(SumoXMLAttr key) const
void updateGeometry()
update pre-computed geometry information
std::string getAdditionalProblem() const
return a string with the current additional problem
void fixAdditionalProblem()
fix additional problem
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
bool isAdditionalValid() const
check if current additional is valid to be writed into XML (by default true, can be reimplemented in ...
~GNEDetectorE1()
Destructor.
GNEDetectorE1(const std::string &id, GNELane *lane, GNENet *net, double pos, SUMOTime freq, const std::string &filename, const std::string &vehicleTypes, const std::string &name, bool friendlyPos, bool blockMovement)
Constructor.
std::string getAttribute(SumoXMLAttr key) const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:169
std::string myFreq
The aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.h:166
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:163
void drawE1Shape(const GUIVisualizationSettings &s, const double exaggeration, const double scaledWidth, const RGBColor &mainColor, const RGBColor &secondColor) const
draw E1 shape
double getGeometryPositionOverLane() const
get position over lane that is applicable to the shape
std::string myVehicleTypes
attribute vehicle types
Definition: GNEDetector.h:172
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:175
void drawDetectorLogo(const GUIVisualizationSettings &s, const double exaggeration, const std::string &logo, const RGBColor &textColor) const
draw detector Logo
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< 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
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
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
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
GNEUndoList * getUndoList() const
get the undoList object
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.
GUIVisualizationDetailSettings detailSettings
detail settings
GUIVisualizationSizeSettings addSize
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
double scale
information about a lane's width (temporary, used for a single view)
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
GUIVisualizationDetectorSettings detectorSettings
Detector 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".
static const RGBColor WHITE
Definition: RGBColor.h:187
static const RGBColor BLACK
Definition: RGBColor.h:188
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:145
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (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't allowed)
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 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 void drawLockIcon(const GNEAttributeCarrier *AC, const GNEGeometry::Geometry &geometry, const double exaggeration, const double offsetx, const double offsety, const bool overlane, const double size=0.5)
draw lock icon
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double detectorDetails
details for detectors
static const RGBColor E1Color
color for E1 detectors
static const double E1Width
E1 detector widths.
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values