Eclipse SUMO - Simulation of Urban MObility
GNEDetectorE1Instant.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 "GNEDetectorE1Instant.h"
27 #include "GNEAdditionalHandler.h"
28 
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
33 
34 GNEDetectorE1Instant::GNEDetectorE1Instant(const std::string& id, GNELane* lane, GNENet* net, double pos, const std::string& filename, const std::string& vehicleTypes, const std::string& name, bool friendlyPos, bool blockMovement) :
35  GNEDetector(id, net, GLO_E1DETECTOR_INSTANT, SUMO_TAG_INSTANT_INDUCTION_LOOP, pos, "", 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 E1InstantExaggeration = s.addSize.getExaggeration(s, this);
96  // first check if additional has to be drawn
97  if (s.drawAdditionals(E1InstantExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
98  // obtain scaledSize
99  const double scaledWidth = s.detectorSettings.E1InstantWidth * 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.E1InstantColor;
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 E1Instant shape
119  drawE1Shape(s, E1InstantExaggeration, scaledWidth, mainColor, secondColor);
120  // Check if the distance is enought to draw details
121  if (s.drawDetail(s.detailSettings.detectorDetails, E1InstantExaggeration)) {
122  // draw E1 Logo
123  drawDetectorLogo(s, E1InstantExaggeration, "E1", textColor);
124  // draw lock icon
125  GNEViewNetHelper::LockIcon::drawLockIcon(this, myAdditionalGeometry, E1InstantExaggeration, 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_NAME:
156  return myAdditionalName;
157  case SUMO_ATTR_FILE:
158  return myFilename;
159  case SUMO_ATTR_VTYPES:
160  return myVehicleTypes;
164  return toString(myBlockMovement);
165  case GNE_ATTR_SELECTED:
167  case GNE_ATTR_PARAMETERS:
168  return getParametersStr();
169  default:
170  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
171  }
172 }
173 
174 
175 void
176 GNEDetectorE1Instant::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
177  if (value == getAttribute(key)) {
178  return; //avoid needless changes, later logic relies on the fact that attributes have changed
179  }
180  switch (key) {
181  case SUMO_ATTR_ID:
182  case SUMO_ATTR_LANE:
183  case SUMO_ATTR_POSITION:
184  case SUMO_ATTR_NAME:
185  case SUMO_ATTR_FILE:
186  case SUMO_ATTR_VTYPES:
189  case GNE_ATTR_SELECTED:
190  case GNE_ATTR_PARAMETERS:
191  undoList->p_add(new GNEChange_Attribute(this, key, value));
192  break;
193  default:
194  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
195  }
196 
197 }
198 
199 
200 bool
201 GNEDetectorE1Instant::isValid(SumoXMLAttr key, const std::string& value) {
202  switch (key) {
203  case SUMO_ATTR_ID:
204  return isValidDetectorID(value);
205  case SUMO_ATTR_LANE:
206  if (myNet->retrieveLane(value, false) != nullptr) {
207  return true;
208  } else {
209  return false;
210  }
211  case SUMO_ATTR_POSITION:
212  return canParse<double>(value) && fabs(parse<double>(value)) < getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
213  case SUMO_ATTR_NAME:
215  case SUMO_ATTR_FILE:
217  case SUMO_ATTR_VTYPES:
218  if (value.empty()) {
219  return true;
220  } else {
222  }
224  return canParse<bool>(value);
226  return canParse<bool>(value);
227  case GNE_ATTR_SELECTED:
228  return canParse<bool>(value);
229  case GNE_ATTR_PARAMETERS:
230  return Parameterised::areParametersValid(value);
231  default:
232  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
233  }
234 }
235 
236 
237 bool
239  return true;
240 }
241 
242 // ===========================================================================
243 // private
244 // ===========================================================================
245 
246 void
247 GNEDetectorE1Instant::setAttribute(SumoXMLAttr key, const std::string& value) {
248  switch (key) {
249  case SUMO_ATTR_ID:
250  myNet->getAttributeCarriers()->updateID(this, value);
251  break;
252  case SUMO_ATTR_LANE:
254  break;
255  case SUMO_ATTR_POSITION:
256  myPositionOverLane = parse<double>(value);
257  break;
258  case SUMO_ATTR_NAME:
259  myAdditionalName = value;
260  break;
261  case SUMO_ATTR_FILE:
262  myFilename = value;
263  break;
264  case SUMO_ATTR_VTYPES:
265  myVehicleTypes = value;
266  break;
268  myFriendlyPosition = parse<bool>(value);
269  break;
271  myBlockMovement = parse<bool>(value);
272  break;
273  case GNE_ATTR_SELECTED:
274  if (parse<bool>(value)) {
276  } else {
278  }
279  break;
280  case GNE_ATTR_PARAMETERS:
281  setParametersStr(value);
282  break;
283  default:
284  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
285  }
286 }
287 
288 
289 /****************************************************************************/
@ GLO_E1DETECTOR_INSTANT
a E1 detector
@ SUMO_TAG_INSTANT_INDUCTION_LOOP
An instantenous induction loop.
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_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
std::string getAdditionalProblem() const
return a string with the current additional problem
std::string getAttribute(SumoXMLAttr key) const
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void updateGeometry()
update pre-computed geometry information
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
bool isAttributeEnabled(SumoXMLAttr key) const
bool isAdditionalValid() const
check if current additional is valid to be writed into XML (by default true, can be reimplemented in ...
GNEDetectorE1Instant(const std::string &id, GNELane *lane, GNENet *net, double pos, const std::string &filename, const std::string &vehicleTypes, const std::string &name, bool friendlyPos, bool blockMovement)
Constructor.
void fixAdditionalProblem()
fix additional problem
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:169
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 double E1InstantWidth
E1 Instant detector widths.
static const RGBColor E1InstantColor
color for E1 Instant detectors
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values