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-2025 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
22#include <netedit/GNENet.h>
26
27#include "GNEVaporizer.h"
28
29// ===========================================================================
30// member method definitions
31// ===========================================================================
32
36
37
38GNEVaporizer::GNEVaporizer(GNENet* net, const std::string& filename, GNEEdge* edge, SUMOTime from, SUMOTime end,
39 const std::string& name, const Parameterised::Map& parameters) :
40 GNEAdditional(edge->getID(), net, filename, SUMO_TAG_VAPORIZER, name),
41 Parameterised(parameters),
42 myBegin(from),
43 myEnd(end) {
44 // set parents
45 setParent<GNEEdge*>(edge);
46 // update centering boundary without updating grid
48}
49
50
53
54
57 return nullptr;
58}
59
60
63 return this;
64}
65
66
67const Parameterised*
69 return this;
70}
71
72
73void
75 device.openTag(getTagProperty()->getTag());
76 // special case for vaporizer IDs
77 device.writeAttr(SUMO_ATTR_ID, getID());
78 // write common additional attributes
80 // write specific attributes
83 // write parameters (Always after children to avoid problems with additionals.xsd)
84 writeParams(device);
85 device.closeTag();
86}
87
88
89bool
91 return true;
92}
93
94
95std::string
97 return "";
98}
99
100
101void
103 // nothing to fix
104}
105
106
107bool
109 return false;
110}
111
112
113void
115 // calculate perpendicular line
117}
118
119
124
125
126void
127GNEVaporizer::updateCenteringBoundary(const bool /*updateGrid*/) {
128 // nothing to do
129}
130
131
132void
133GNEVaporizer::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
134 // geometry of this element cannot be splitted
135}
136
137
138std::string
140 return getParentEdges().front()->getID();
141}
142
143
144void
146 // first check if additional has to be drawn
148 // Obtain exaggeration of the draw
149 const double vaporizerExaggeration = getExaggeration(s);
150 // get detail level
151 const auto d = s.getDetailLevel(vaporizerExaggeration);
152 // draw geometry only if we'rent in drawForObjectUnderCursor mode
154 // declare colors
155 RGBColor vaporizerColor, centralLineColor;
156 // set colors
157 if (drawUsingSelectColor()) {
158 vaporizerColor = s.colorSettings.selectedAdditionalColor;
159 centralLineColor = vaporizerColor.changedBrightness(-32);
160 } else {
161 vaporizerColor = s.additionalSettings.vaporizerColor;
162 centralLineColor = RGBColor::WHITE;
163 }
164 // draw parent and child lines
166 // Add layer matrix matrix
168 // translate to front
170 // set base color
171 GLHelper::setColor(vaporizerColor);
172 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
173 GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.3 * vaporizerExaggeration);
174 // move to front
175 glTranslated(0, 0, .1);
176 // set central color
177 GLHelper::setColor(centralLineColor);
178 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
179 GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.05 * vaporizerExaggeration);
180 // move to icon position and front
181 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
182 // rotate over lane
184 // Draw icon depending of level of detail
186 // set color
187 glColor3d(1, 1, 1);
188 // rotate texture
189 glRotated(90, 0, 0, 1);
190 // draw texture
191 if (drawUsingSelectColor()) {
193 } else {
195 }
196 } else {
197 // set route probe color
198 GLHelper::setColor(vaporizerColor);
199 // just drawn a box
201 }
202 // pop layer matrix
204 // draw additional name
206 // draw dotted contours
209 }
210 // calculate contours
212 s.additionalSettings.vaporizerSize, getType(), 0, 0, (myAdditionalGeometry.getShapeRotations().front() * -1), vaporizerExaggeration, getParentEdges().front());
214 true, true, 0, nullptr, getParentEdges().front());
215 }
216}
217
218
219std::string
221 switch (key) {
222 case SUMO_ATTR_ID:
223 case SUMO_ATTR_EDGE:
224 return getMicrosimID();
225 case SUMO_ATTR_BEGIN:
226 return time2string(myBegin);
227 case SUMO_ATTR_END:
228 return time2string(myEnd);
229 case SUMO_ATTR_NAME:
230 return myAdditionalName;
231 default:
232 return getCommonAttribute(key);
233 }
234}
235
236
237double
239 switch (key) {
240 case SUMO_ATTR_BEGIN:
241 return STEPS2TIME(myBegin);
242 case SUMO_ATTR_END:
243 return STEPS2TIME(myEnd);
244 default:
245 return getCommonAttributeDouble(key);
246 }
247}
248
249
254
255
260
261
262void
263GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
264 if (value == getAttribute(key)) {
265 return; //avoid needless changes, later logic relies on the fact that attributes have changed
266 }
267 switch (key) {
268 case SUMO_ATTR_ID:
269 case SUMO_ATTR_EDGE:
270 case SUMO_ATTR_BEGIN:
271 case SUMO_ATTR_END:
272 case SUMO_ATTR_NAME:
273 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
274 break;
275 default:
276 setCommonAttribute(key, value, undoList);
277 break;
278 }
279}
280
281
282bool
283GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
284 switch (key) {
285 case SUMO_ATTR_ID:
286 case SUMO_ATTR_EDGE:
287 if (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) {
288 return isValidAdditionalID(value);
289 } else {
290 return false;
291 }
292 case SUMO_ATTR_BEGIN:
293 if (canParse<SUMOTime>(value)) {
294 const auto begin = parse<SUMOTime>(value);
295 return ((begin >= 0) && (parse<SUMOTime>(value) <= myEnd));
296 } else {
297 return false;
298 }
299 case SUMO_ATTR_END:
300 if (canParse<SUMOTime>(value)) {
301 const auto end = parse<SUMOTime>(value);
302 return ((end >= 0) && (myBegin <= parse<SUMOTime>(value)));
303 } else {
304 return false;
305 }
306 case SUMO_ATTR_NAME:
308 default:
309 return isCommonAttributeValid(key, value);
310 }
311}
312
313
314std::string
316 return getTagStr();
317}
318
319
320std::string
324
325// ===========================================================================
326// private
327// ===========================================================================
328
329void
330GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
331 switch (key) {
332 case SUMO_ATTR_ID:
333 case SUMO_ATTR_EDGE:
334 // update microsimID
335 setAdditionalID(value);
337 break;
338 case SUMO_ATTR_BEGIN:
339 myBegin = parse<SUMOTime>(value);
340 break;
341 case SUMO_ATTR_END:
342 myEnd = parse<SUMOTime>(value);
343 break;
344 case SUMO_ATTR_NAME:
345 myAdditionalName = value;
346 break;
347 default:
348 setCommonAttribute(key, value);
349 break;
350 }
351}
352
353/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ GLO_VAPORIZER
a Vaporizer
@ VAPORIZER_SELECTED
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
#define STEPS2TIME(x)
Definition SUMOTime.h:55
@ SUMO_TAG_VAPORIZER
vaporizer of vehicles
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_NAME
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_ID
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:296
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
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
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 writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
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
double getCommonAttributeDouble(SumoXMLAttr key) const
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
Position getCommonAttributePosition(SumoXMLAttr key) const
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
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 layer, const double extrusionWidth, const double scale, const bool closeFirstExtrem, const bool closeLastExtrem, const double offset, const GNESegment *segment, const GUIGlObject *boundaryParent, const bool addToSelectedObjects=true) const
calculate contour extruded (used in elements formed by a central shape)
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
void calculateContourRectangleShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const Position &pos, const double width, const double height, const double layer, const double offsetX, const double offsetY, const double rot, const double scale, const GUIGlObject *boundaryParent) const
calculate contour (for rectangled elements)
const GNEHierarchicalContainerParents< GNEEdge * > & getParentEdges() const
get parent edges
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:144
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
bool isValid(SumoXMLAttr key, const std::string &value) override
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this vaporizer
Parameterised * getParameters() override
get parameters associated with this vaporizer
Position getPositionInView() const
Returns position of additional in view.
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
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 override
get Hierarchy Name (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const override
GNEContour mySymbolBaseContour
symbol base contour
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
double getAttributeDouble(SumoXMLAttr key) const override
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void updateGeometry() override
update pre-computed geometry information
SUMOTime myBegin
begin time of vaporizer
Position getAttributePosition(SumoXMLAttr key) const override
SUMOTime myEnd
end time in which this vaporizer is placed
bool checkDrawMoveContour() const override
check if draw move contour (red)
std::string getParentName() const
Returns the name of the parent object.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
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
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.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
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 checkDrawAdditional(Detail d, const bool selected) const
check if draw additionals
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
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.
std::map< std::string, std::string > Map
parameters map
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
static const RGBColor WHITE
Definition RGBColor.h:195
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)
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 segmentWidthSmall
width of small dotted contour segments
static const double segmentWidth
width of dotted contour segments