Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2023 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>
27
28#include "GNEVaporizer.h"
29
30
31// ===========================================================================
32// member method definitions
33// ===========================================================================
34
37{}, {}, {}, {}, {}, {}),
38myBegin(0),
39myEnd(0) {
40 // reset default values
41 resetDefaultValues();
42}
43
44
45GNEVaporizer::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}, {}, {}, {}, {}),
49Parameterised(parameters),
50myBegin(from),
51myEnd(end) {
52 // update centering boundary without updating grid
53 updateCenteringBoundary(false);
54}
55
56
59
60
63 // vaporizers cannot be moved
64 return nullptr;
65}
66
67
68void
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
83bool
85 return true;
86}
87
88
89std::string
91 return "";
92}
93
94
95void
97 // nothing to fix
98}
99
100
101void
103 // calculate perpendicular line
105}
106
107
112
113
114void
115GNEVaporizer::updateCenteringBoundary(const bool /*updateGrid*/) {
117 // add center
119 // grow
121}
122
123
124void
125GNEVaporizer::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
126 // geometry of this element cannot be splitted
127}
128
129
130std::string
132 return getParentEdges().front()->getID();
133}
134
135
136void
138 // Obtain exaggeration of the draw
139 const double vaporizerExaggeration = getExaggeration(s);
140 // first check if additional has to be drawn
141 if (s.drawAdditionals(vaporizerExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
142 // declare colors
143 RGBColor vaporizerColor, centralLineColor;
144 // set colors
145 if (drawUsingSelectColor()) {
146 vaporizerColor = s.colorSettings.selectedAdditionalColor;
147 centralLineColor = vaporizerColor.changedBrightness(-32);
148 } else {
149 vaporizerColor = s.additionalSettings.vaporizerColor;
150 centralLineColor = RGBColor::WHITE;
151 }
152 // avoid draw invisible elements
153 if (vaporizerColor.alpha() != 0) {
154 // draw parent and child lines
156 // Start drawing adding an gl identificator
158 // Add layer matrix matrix
160 // translate to front
162 // set base color
163 GLHelper::setColor(vaporizerColor);
164 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
166 // move to front
167 glTranslated(0, 0, .1);
168 // set central color
169 GLHelper::setColor(centralLineColor);
170 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
172 // move to icon position and front
173 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
174 // rotate over lane
176 // Draw icon depending of Route Probe is selected and if isn't being drawn for selecting
177 if (!s.drawForRectangleSelection && s.drawDetail(s.detailSettings.laneTextures, vaporizerExaggeration)) {
178 // set color
179 glColor3d(1, 1, 1);
180 // rotate texture
181 glRotated(90, 0, 0, 1);
182 // draw texture
183 if (drawUsingSelectColor()) {
185 } else {
187 }
188 } else {
189 // set route probe color
190 GLHelper::setColor(vaporizerColor);
191 // just drawn a box
193 }
194 // pop layer matrix
196 // Pop name
198 }
199 // draw additional name
201 // check if mouse is over element
203 // inspect contour
206 vaporizerExaggeration, true, true);
207 }
208 // front element contour
209 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
211 vaporizerExaggeration, true, true);
212 }
213 // delete contour
214 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
216 vaporizerExaggeration, true, true);
217 }
218 // select contour
219 if (myNet->getViewNet()->drawSelectContour(this, this)) {
221 vaporizerExaggeration, true, true);
222 }
223 }
224}
225
226
227std::string
229 switch (key) {
230 case SUMO_ATTR_ID:
231 case SUMO_ATTR_EDGE:
232 return getMicrosimID();
233 case SUMO_ATTR_BEGIN:
234 return time2string(myBegin);
235 case SUMO_ATTR_END:
236 return time2string(myEnd);
237 case SUMO_ATTR_NAME:
238 return myAdditionalName;
242 return getParametersStr();
243 default:
244 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
245 }
246}
247
248
249double
251 switch (key) {
252 case SUMO_ATTR_BEGIN:
253 return STEPS2TIME(myBegin);
254 case SUMO_ATTR_END:
255 return STEPS2TIME(myEnd);
256 default:
257 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
258 }
259}
260
261
266
267
268void
269GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
270 if (value == getAttribute(key)) {
271 return; //avoid needless changes, later logic relies on the fact that attributes have changed
272 }
273 switch (key) {
274 case SUMO_ATTR_ID:
275 case SUMO_ATTR_EDGE:
276 case SUMO_ATTR_BEGIN:
277 case SUMO_ATTR_END:
278 case SUMO_ATTR_NAME:
281 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
282 break;
283 default:
284 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
285 }
286}
287
288
289bool
290GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
291 switch (key) {
292 case SUMO_ATTR_ID:
293 case SUMO_ATTR_EDGE:
294 if (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) {
295 return isValidAdditionalID(value);
296 } else {
297 return false;
298 }
299 case SUMO_ATTR_BEGIN:
300 if (canParse<SUMOTime>(value)) {
301 return (parse<SUMOTime>(value) <= myEnd);
302 } else {
303 return false;
304 }
305 case SUMO_ATTR_END:
306 if (canParse<SUMOTime>(value)) {
307 return (myBegin <= parse<SUMOTime>(value));
308 } else {
309 return false;
310 }
311 case SUMO_ATTR_NAME:
314 return canParse<bool>(value);
316 return areParametersValid(value);
317 default:
318 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
319 }
320}
321
322
323std::string
325 return getTagStr();
326}
327
328
329std::string
333
334// ===========================================================================
335// private
336// ===========================================================================
337
338void
339GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
340 switch (key) {
341 case SUMO_ATTR_ID:
342 case SUMO_ATTR_EDGE:
343 // update microsimID
344 setMicrosimID(value);
346 break;
347 case SUMO_ATTR_BEGIN:
348 myBegin = parse<SUMOTime>(value);
349 break;
350 case SUMO_ATTR_END:
351 myEnd = parse<SUMOTime>(value);
352 break;
353 case SUMO_ATTR_NAME:
354 myAdditionalName = value;
355 break;
357 if (parse<bool>(value)) {
359 } else {
361 }
362 break;
364 setParametersStr(value);
365 break;
366 default:
367 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
368 }
369}
370
371
372void
374 // nothing to do
375}
376
377
378void
379GNEVaporizer::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
380 // nothing to do
381}
382
383/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ 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
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition Boundary.cpp:78
void reset()
Resets the boundary.
Definition Boundary.cpp:66
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:300
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:583
static void pushName(unsigned int name)
push Name
Definition GLHelper.cpp:139
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:277
static void popName()
pop Name
Definition GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
An Element which don't belong to GNENet but has influence in the simulation.
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
Boundary myAdditionalBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
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
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 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
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:120
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
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 writed into XML (must be reimplemented in all detector chi...
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
SUMOTime myEnd
end time in which this vaporizer is placed
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)
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool drawSelectContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw select contour
bool drawDeleteContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw delete contour
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
static void drawDottedContourShape(const GUIVisualizationSettings &s, const DottedContourType type, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem)
draw dotted contour for the given shape (used by additionals)
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 &s, const Position &mousePos, 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.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
bool mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlID getGlID() const
Returns the numerical id of the object.
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
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.
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationDetailSettings detailSettings
detail settings
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 storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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.
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
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
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:92
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 laneTextures
details for lane textures