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-2026 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
24#include <netedit/GNENet.h>
28
29#include "GNEVaporizer.h"
30
31// ===========================================================================
32// member method definitions
33// ===========================================================================
34
38
39
41 const std::string& name, const Parameterised::Map& parameters) :
42 GNEAdditional(edge->getID(), net, SUMO_TAG_VAPORIZER, fileBucket, name),
43 Parameterised(parameters),
44 myBegin(from),
45 myEnd(end) {
46 // set parents
47 setParent<GNEEdge*>(edge);
48 // update centering boundary without updating grid
50}
51
52
55
56
59 return nullptr;
60}
61
62
65 return this;
66}
67
68
69const Parameterised*
71 return this;
72}
73
74
75void
77 device.openTag(getTagProperty()->getTag());
78 // special case for vaporizer IDs
79 device.writeAttr(SUMO_ATTR_ID, getID());
80 // write common additional attributes
82 // write specific attributes
85 // write parameters (Always after children to avoid problems with additionals.xsd)
86 XMLHelpers::writeParams(device, *this);
87 device.closeTag();
88}
89
90
91bool
93 return true;
94}
95
96
97std::string
99 return "";
100}
101
102
103void
105 // nothing to fix
106}
107
108
109bool
111 return false;
112}
113
114
115void
117 // calculate perpendicular line
119}
120
121
126
127
128void
129GNEVaporizer::updateCenteringBoundary(const bool /*updateGrid*/) {
130 // nothing to do
131}
132
133
134void
135GNEVaporizer::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
136 // geometry of this element cannot be splitted
137}
138
139
140std::string
142 return getParentEdges().front()->getID();
143}
144
145
146void
148 // first check if additional has to be drawn
150 // Obtain exaggeration of the draw
151 const double vaporizerExaggeration = getExaggeration(s);
152 // get detail level
153 const auto d = s.getDetailLevel(vaporizerExaggeration);
154 // draw geometry only if we'rent in drawForObjectUnderCursor mode
156 // declare colors
157 RGBColor vaporizerColor, centralLineColor;
158 // set colors
159 if (drawUsingSelectColor()) {
160 vaporizerColor = s.colorSettings.selectedAdditionalColor;
161 centralLineColor = vaporizerColor.changedBrightness(-32);
162 } else {
163 vaporizerColor = s.additionalSettings.vaporizerColor;
164 centralLineColor = RGBColor::WHITE;
165 }
166 // draw parent and child lines
168 // Add layer matrix matrix
170 // translate to front
172 // set base color
173 GLHelper::setColor(vaporizerColor);
174 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
175 GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.3 * vaporizerExaggeration);
176 // move to front
177 glTranslated(0, 0, .1);
178 // set central color
179 GLHelper::setColor(centralLineColor);
180 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
181 GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.05 * vaporizerExaggeration);
182 // move to icon position and front
183 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
184 // rotate over lane
186 // Draw icon depending of level of detail
188 // set color
189 glColor3d(1, 1, 1);
190 // rotate texture
191 glRotated(90, 0, 0, 1);
192 // draw texture
193 if (drawUsingSelectColor()) {
195 } else {
197 }
198 } else {
199 // set route probe color
200 GLHelper::setColor(vaporizerColor);
201 // just drawn a box
203 }
204 // pop layer matrix
206 // draw additional name
208 // draw dotted contours
211 }
212 // calculate contours
214 s.additionalSettings.vaporizerSize, getType(), 0, 0, (myAdditionalGeometry.getShapeRotations().front() * -1), vaporizerExaggeration, getParentEdges().front());
216 true, true, 0, nullptr, getParentEdges().front());
217 }
218}
219
220
221std::string
223 switch (key) {
224 case SUMO_ATTR_ID:
225 case SUMO_ATTR_EDGE:
226 return getMicrosimID();
227 case SUMO_ATTR_BEGIN:
228 return time2string(myBegin);
229 case SUMO_ATTR_END:
230 return time2string(myEnd);
231 case SUMO_ATTR_NAME:
232 return myAdditionalName;
233 default:
234 return getCommonAttribute(key);
235 }
236}
237
238
239double
241 switch (key) {
242 case SUMO_ATTR_BEGIN:
243 return STEPS2TIME(myBegin);
244 case SUMO_ATTR_END:
245 return STEPS2TIME(myEnd);
246 default:
247 return getCommonAttributeDouble(key);
248 }
249}
250
251
256
257
262
263
264void
265GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
266 if (value == getAttribute(key)) {
267 return; //avoid needless changes, later logic relies on the fact that attributes have changed
268 }
269 switch (key) {
270 case SUMO_ATTR_ID:
271 case SUMO_ATTR_EDGE:
272 case SUMO_ATTR_BEGIN:
273 case SUMO_ATTR_END:
274 case SUMO_ATTR_NAME:
275 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
276 break;
277 default:
278 setCommonAttribute(key, value, undoList);
279 break;
280 }
281}
282
283
284bool
285GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
286 switch (key) {
287 case SUMO_ATTR_ID:
288 case SUMO_ATTR_EDGE:
289 if (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) {
290 return isValidAdditionalID(value);
291 } else {
292 return false;
293 }
294 case SUMO_ATTR_BEGIN:
295 if (canParse<SUMOTime>(value)) {
296 const auto begin = parse<SUMOTime>(value);
297 return ((begin >= 0) && (parse<SUMOTime>(value) <= myEnd));
298 } else {
299 return false;
300 }
301 case SUMO_ATTR_END:
302 if (canParse<SUMOTime>(value)) {
303 const auto end = parse<SUMOTime>(value);
304 return ((end >= 0) && (myBegin <= parse<SUMOTime>(value)));
305 } else {
306 return false;
307 }
308 case SUMO_ATTR_NAME:
309 return StringUtils::isValidAttribute(value);
310 default:
311 return isCommonAttributeValid(key, value);
312 }
313}
314
315
316std::string
318 return getTagStr();
319}
320
321
322std::string
326
327// ===========================================================================
328// private
329// ===========================================================================
330
331void
332GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
333 switch (key) {
334 case SUMO_ATTR_ID:
335 case SUMO_ATTR_EDGE:
336 // update microsimID
337 setAdditionalID(value);
339 break;
340 case SUMO_ATTR_BEGIN:
341 myBegin = parse<SUMOTime>(value);
342 break;
343 case SUMO_ATTR_END:
344 myEnd = parse<SUMOTime>(value);
345 break;
346 case SUMO_ATTR_NAME:
347 myAdditionalName = value;
348 break;
349 default:
350 setCommonAttribute(key, value);
351 break;
352 }
353}
354
355/****************************************************************************/
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:107
#define STEPS2TIME(x)
Definition SUMOTime.h:58
@ 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
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
double getCommonAttributeDouble(SumoXMLAttr key) const
const std::string getID() const override
get ID (all Attribute Carriers have one)
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
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
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 override
Returns position of additional in view.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
std::string getAdditionalProblem() const override
return a string with the current additional problem (must be reimplemented in all detector children)
std::string getAttribute(SumoXMLAttr key) const override
GNEContour mySymbolBaseContour
symbol base contour
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
double getAttributeDouble(SumoXMLAttr key) const override
bool isAdditionalValid() const override
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
std::string getParentName() const override
Returns the name of the parent object.
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)
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
GNEVaporizer(GNENet *net)
default Constructor
void fixAdditionalProblem() override
fix additional problem (must be reimplemented in all detector children)
~GNEVaporizer()
Destructor.
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
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
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:211
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:228
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags
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