Eclipse SUMO - Simulation of Urban MObility
GNEVaporizer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 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>
24 #include <utils/gui/div/GLHelper.h>
27 
28 #include "GNEVaporizer.h"
29 
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
37 {}, {}, {}, {}, {}, {}),
38 myBegin(0),
39 myEnd(0) {
40  // reset default values
41  resetDefaultValues();
42 }
43 
44 
45 GNEVaporizer::GNEVaporizer(GNENet* net, GNEEdge* edge, SUMOTime from, SUMOTime end, const std::string& name,
46  const Parameterised::Map& parameters) :
47  GNEAdditional(edge->getID(), net, GLO_VAPORIZER, SUMO_TAG_VAPORIZER, GUIIconSubSys::getIcon(GUIIcon::VAPORIZER), name,
48 {}, {edge}, {}, {}, {}, {}),
49 Parameterised(parameters),
50 myBegin(from),
51 myEnd(end) {
52  // update centering boundary without updating grid
53  updateCenteringBoundary(false);
54 }
55 
56 
58 }
59 
60 
63  // vaporizers cannot be moved
64  return nullptr;
65 }
66 
67 
68 void
70  device.openTag(getTagProperty().getTag());
71  device.writeAttr(SUMO_ATTR_ID, getID());
72  if (!myAdditionalName.empty()) {
74  }
77  // write parameters (Always after children to avoid problems with additionals.xsd)
78  writeParams(device);
79  device.closeTag();
80 }
81 
82 
83 bool
85  return true;
86 }
87 
88 
89 std::string
91  return "";
92 }
93 
94 
95 void
97  // nothing to fix
98 }
99 
100 
101 bool
103  return false;
104 }
105 
106 
107 void
109  // calculate perpendicular line
111 }
112 
113 
114 Position
117 }
118 
119 
120 void
121 GNEVaporizer::updateCenteringBoundary(const bool /*updateGrid*/) {
122  // nothing to do
123 }
124 
125 
126 void
127 GNEVaporizer::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
128  // geometry of this element cannot be splitted
129 }
130 
131 
132 std::string
134  return getParentEdges().front()->getID();
135 }
136 
137 
138 void
140  // Obtain exaggeration of the draw
141  const double vaporizerExaggeration = getExaggeration(s);
142  // first check if additional has to be drawn
144  // get detail level
145  const auto d = s.getDetailLevel(vaporizerExaggeration);
146  // draw geometry only if we'rent in drawForObjectUnderCursor mode
147  if (!s.drawForViewObjectsHandler) {
148  // declare colors
149  RGBColor vaporizerColor, centralLineColor;
150  // set colors
151  if (drawUsingSelectColor()) {
152  vaporizerColor = s.colorSettings.selectedAdditionalColor;
153  centralLineColor = vaporizerColor.changedBrightness(-32);
154  } else {
155  vaporizerColor = s.additionalSettings.vaporizerColor;
156  centralLineColor = RGBColor::WHITE;
157  }
158  // draw parent and child lines
160  // Add layer matrix matrix
162  // translate to front
164  // set base color
165  GLHelper::setColor(vaporizerColor);
166  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
167  GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.3 * vaporizerExaggeration);
168  // move to front
169  glTranslated(0, 0, .1);
170  // set central color
171  GLHelper::setColor(centralLineColor);
172  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
173  GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.05 * vaporizerExaggeration);
174  // move to icon position and front
175  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
176  // rotate over lane
178  // Draw icon depending of level of detail
180  // set color
181  glColor3d(1, 1, 1);
182  // rotate texture
183  glRotated(90, 0, 0, 1);
184  // draw texture
185  if (drawUsingSelectColor()) {
187  } else {
189  }
190  } else {
191  // set route probe color
192  GLHelper::setColor(vaporizerColor);
193  // just drawn a box
195  }
196  // pop layer matrix
198  // draw additional name
200  // draw dotted contour
202  }
203  // calculate contour and draw dotted geometry
204  myAdditionalContour.calculateContourExtrudedShape(s, d, this, myAdditionalGeometry.getShape(), 0.5, vaporizerExaggeration, true, true, 0);
205  }
206 }
207 
208 
209 std::string
211  switch (key) {
212  case SUMO_ATTR_ID:
213  case SUMO_ATTR_EDGE:
214  return getMicrosimID();
215  case SUMO_ATTR_BEGIN:
216  return time2string(myBegin);
217  case SUMO_ATTR_END:
218  return time2string(myEnd);
219  case SUMO_ATTR_NAME:
220  return myAdditionalName;
221  case GNE_ATTR_SELECTED:
223  case GNE_ATTR_PARAMETERS:
224  return getParametersStr();
225  default:
226  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
227  }
228 }
229 
230 
231 double
233  switch (key) {
234  case SUMO_ATTR_BEGIN:
235  return STEPS2TIME(myBegin);
236  case SUMO_ATTR_END:
237  return STEPS2TIME(myEnd);
238  default:
239  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
240  }
241 }
242 
243 
244 const Parameterised::Map&
246  return getParametersMap();
247 }
248 
249 
250 void
251 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
252  if (value == getAttribute(key)) {
253  return; //avoid needless changes, later logic relies on the fact that attributes have changed
254  }
255  switch (key) {
256  case SUMO_ATTR_ID:
257  case SUMO_ATTR_EDGE:
258  case SUMO_ATTR_BEGIN:
259  case SUMO_ATTR_END:
260  case SUMO_ATTR_NAME:
261  case GNE_ATTR_SELECTED:
262  case GNE_ATTR_PARAMETERS:
263  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
264  break;
265  default:
266  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
267  }
268 }
269 
270 
271 bool
272 GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
273  switch (key) {
274  case SUMO_ATTR_ID:
275  case SUMO_ATTR_EDGE:
276  if (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) {
277  return isValidAdditionalID(value);
278  } else {
279  return false;
280  }
281  case SUMO_ATTR_BEGIN:
282  if (canParse<SUMOTime>(value)) {
283  return (parse<SUMOTime>(value) <= myEnd);
284  } else {
285  return false;
286  }
287  case SUMO_ATTR_END:
288  if (canParse<SUMOTime>(value)) {
289  return (myBegin <= parse<SUMOTime>(value));
290  } else {
291  return false;
292  }
293  case SUMO_ATTR_NAME:
295  case GNE_ATTR_SELECTED:
296  return canParse<bool>(value);
297  case GNE_ATTR_PARAMETERS:
298  return areParametersValid(value);
299  default:
300  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
301  }
302 }
303 
304 
305 std::string
307  return getTagStr();
308 }
309 
310 
311 std::string
313  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
314 }
315 
316 // ===========================================================================
317 // private
318 // ===========================================================================
319 
320 void
321 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
322  switch (key) {
323  case SUMO_ATTR_ID:
324  case SUMO_ATTR_EDGE:
325  // update microsimID
326  setAdditionalID(value);
328  break;
329  case SUMO_ATTR_BEGIN:
330  myBegin = parse<SUMOTime>(value);
331  break;
332  case SUMO_ATTR_END:
333  myEnd = parse<SUMOTime>(value);
334  break;
335  case SUMO_ATTR_NAME:
336  myAdditionalName = value;
337  break;
338  case GNE_ATTR_SELECTED:
339  if (parse<bool>(value)) {
341  } else {
343  }
344  break;
345  case GNE_ATTR_PARAMETERS:
346  setParametersStr(value);
347  break;
348  default:
349  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
350  }
351 }
352 
353 
354 void
356  // nothing to do
357 }
358 
359 
360 void
361 GNEVaporizer::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
362  // nothing to do
363 }
364 
365 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
@ GLO_VAPORIZER
a Vaporizer
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ VAPORIZER_SELECTED
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
#define STEPS2TIME(x)
Definition: SUMOTime.h:55
@ SUMO_TAG_VAPORIZER
vaporizer of vehicles
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_EDGE
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_BEGIN
weights: time range begin
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_NAME
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:655
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:295
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void setAdditionalID(const std::string &newID)
set additional ID
GNEContour myAdditionalContour
variable used for draw additional contours
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void replaceAdditionalParentEdges(const std::string &value)
replace additional parent edges
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
void calculatePerpendicularLine(const double endLaneposition)
calculate perpendicular line between lane parents
std::string myAdditionalName
name of additional
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
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
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void calculateContourExtrudedShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const PositionVector &shape, const double extrusionWidth, const double scale, const bool closeFirstExtrem, const bool closeLastExtrem, const double offset) const
calculate contour extruded (used in elements formed by a central shape)
Definition: GNEContour.cpp:88
void drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
drawing contour functions
Definition: GNEContour.cpp:263
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
move operation
move result
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:121
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2022
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Position getPositionInView() const
Returns position of additional in view.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
const Parameterised::Map & getACParametersMap() const
get parameters map
GNEMoveOperation * getMoveOperation()
get move operation
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
void updateGeometry()
update pre-computed geometry information
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
SUMOTime myBegin
begin time of vaporizer
Definition: GNEVaporizer.h:159
SUMOTime myEnd
end time in which this vaporizer is placed
Definition: GNEVaporizer.h:162
std::string getParentName() const
Returns the name of the parent object.
double getAttributeDouble(SumoXMLAttr key) const
GNEVaporizer(GNENet *net)
default Constructor
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
~GNEVaporizer()
Destructor.
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool checkDrawMoveContour() const
check if draw move contour (red)
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:727
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
static void drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
const PositionVector & getShape() const
The shape of the additional element.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:143
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
Stores the information about how to visualize structures.
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
bool drawForViewObjectsHandler
whether drawing is performed for the purpose of selecting objects in view using ViewObjectsHandler
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
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"
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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:37
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
static const RGBColor WHITE
Definition: RGBColor.h:192
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:200
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
bool showAdditionals() const
check if additionals has to be drawn
static const double vaporizerSize
Vaporizer size.
static const RGBColor connectionColor
connection color
static const RGBColor vaporizerColor
color for vaporizers
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double segmentWidth
width of dotted contour segments