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.org/sumo
3// Copyright (C) 2001-2022 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
58}
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
83void
85 // calculate perpendicular line
87}
88
89
93}
94
95
96void
97GNEVaporizer::updateCenteringBoundary(const bool /*updateGrid*/) {
99 // add center
101 // grow
103}
104
105
106void
107GNEVaporizer::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
108 // geometry of this element cannot be splitted
109}
110
111
112std::string
114 return getParentEdges().front()->getID();
115}
116
117
118void
120 // Obtain exaggeration of the draw
121 const double vaporizerExaggeration = getExaggeration(s);
122 // first check if additional has to be drawn
123 if (s.drawAdditionals(vaporizerExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
124 // declare colors
125 RGBColor vaporizerColor, centralLineColor;
126 // set colors
127 if (drawUsingSelectColor()) {
128 vaporizerColor = s.colorSettings.selectedAdditionalColor;
129 centralLineColor = vaporizerColor.changedBrightness(-32);
130 } else {
131 vaporizerColor = s.additionalSettings.vaporizerColor;
132 centralLineColor = RGBColor::WHITE;
133 }
134 // draw parent and child lines
136 // Start drawing adding an gl identificator
138 // Add layer matrix matrix
140 // translate to front
142 // set base color
143 GLHelper::setColor(vaporizerColor);
144 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
146 // move to front
147 glTranslated(0, 0, .1);
148 // set central color
149 GLHelper::setColor(centralLineColor);
150 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
152 // move to icon position and front
153 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
154 // rotate over lane
156 // Draw icon depending of Route Probe is selected and if isn't being drawn for selecting
157 if (!s.drawForRectangleSelection && s.drawDetail(s.detailSettings.laneTextures, vaporizerExaggeration)) {
158 // set color
159 glColor3d(1, 1, 1);
160 // rotate texture
161 glRotated(90, 0, 0, 1);
162 // draw texture
163 if (drawUsingSelectColor()) {
165 } else {
167 }
168 } else {
169 // set route probe color
170 GLHelper::setColor(vaporizerColor);
171 // just drawn a box
173 }
174 // pop layer matrix
176 // Pop name
178 // draw additional name
180 // check if mouse is over element
182 // inspect contour
185 vaporizerExaggeration, true, true);
186 }
187 // front element contour
188 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
190 vaporizerExaggeration, true, true);
191 }
192 // delete contour
193 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
195 vaporizerExaggeration, true, true);
196 }
197 // select contour
198 if (myNet->getViewNet()->drawSelectContour(this, this)) {
200 vaporizerExaggeration, true, true);
201 }
202 }
203}
204
205
206std::string
208 switch (key) {
209 case SUMO_ATTR_ID:
210 case SUMO_ATTR_EDGE:
211 return getMicrosimID();
212 case SUMO_ATTR_BEGIN:
213 return time2string(myBegin);
214 case SUMO_ATTR_END:
215 return time2string(myEnd);
216 case SUMO_ATTR_NAME:
217 return myAdditionalName;
221 return getParametersStr();
222 default:
223 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
224 }
225}
226
227
228double
230 switch (key) {
231 case SUMO_ATTR_BEGIN:
232 return STEPS2TIME(myBegin);
233 case SUMO_ATTR_END:
234 return STEPS2TIME(myEnd);
235 default:
236 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
237 }
238}
239
240
243 return getParametersMap();
244}
245
246
247void
248GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
249 if (value == getAttribute(key)) {
250 return; //avoid needless changes, later logic relies on the fact that attributes have changed
251 }
252 switch (key) {
253 case SUMO_ATTR_ID:
254 case SUMO_ATTR_EDGE:
255 case SUMO_ATTR_BEGIN:
256 case SUMO_ATTR_END:
257 case SUMO_ATTR_NAME:
260 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
261 break;
262 default:
263 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
264 }
265}
266
267
268bool
269GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
270 switch (key) {
271 case SUMO_ATTR_ID:
272 case SUMO_ATTR_EDGE:
273 if (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) {
274 return isValidAdditionalID(value);
275 } else {
276 return false;
277 }
278 case SUMO_ATTR_BEGIN:
279 if (canParse<SUMOTime>(value)) {
280 return (parse<SUMOTime>(value) <= myEnd);
281 } else {
282 return false;
283 }
284 case SUMO_ATTR_END:
285 if (canParse<SUMOTime>(value)) {
286 return (myBegin <= parse<SUMOTime>(value));
287 } else {
288 return false;
289 }
290 case SUMO_ATTR_NAME:
293 return canParse<bool>(value);
295 return areParametersValid(value);
296 default:
297 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
298 }
299}
300
301
302std::string
304 return getTagStr();
305}
306
307
308std::string
310 return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
311}
312
313// ===========================================================================
314// private
315// ===========================================================================
316
317void
318GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
319 switch (key) {
320 case SUMO_ATTR_ID:
321 case SUMO_ATTR_EDGE:
322 // update microsimID
323 setMicrosimID(value);
325 break;
326 case SUMO_ATTR_BEGIN:
327 myBegin = parse<SUMOTime>(value);
328 break;
329 case SUMO_ATTR_END:
330 myEnd = parse<SUMOTime>(value);
331 break;
332 case SUMO_ATTR_NAME:
333 myAdditionalName = value;
334 break;
336 if (parse<bool>(value)) {
338 } else {
340 }
341 break;
343 setParametersStr(value);
344 break;
345 default:
346 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
347 }
348}
349
350
351void
353 // nothing to do
354}
355
356
357void
358GNEVaporizer::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
359 // nothing to do
360}
361
362/****************************************************************************/
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)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:54
@ 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.
Definition: GNEAdditional.h:48
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:132
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
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
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 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
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:131
SUMOTime myEnd
end time in which this vaporizer is placed
Definition: GNEVaporizer.h:134
std::string getParentName() const
Returns the name of the parent object (if any)
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
Definition: GNEViewNet.cpp:656
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.
Definition: GUIGlObject.h:141
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
void 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.
Definition: GUIGlObject.h:102
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.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
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.
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 laneTextures
details for lane textures