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#include <config.h>
21
22#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
30
31#include "GNEVaporizer.h"
32
33// ===========================================================================
34// member method definitions
35// ===========================================================================
36
40
41
42GNEVaporizer::GNEVaporizer(GNENet* net, const std::string& filename, GNEEdge* edge, SUMOTime from, SUMOTime end,
43 const std::string& name, const Parameterised::Map& parameters) :
44 GNEAdditional(edge->getID(), net, filename, SUMO_TAG_VAPORIZER, name),
45 Parameterised(parameters),
46 myBegin(from),
47 myEnd(end) {
48 // set parents
49 setParent<GNEEdge*>(edge);
50 // update centering boundary without updating grid
52}
53
54
57
58
61 // vaporizers cannot be moved
62 return nullptr;
63}
64
65
66void
68 device.openTag(getTagProperty()->getTag());
69 device.writeAttr(SUMO_ATTR_ID, getID());
70 if (!myAdditionalName.empty()) {
72 }
75 // write parameters (Always after children to avoid problems with additionals.xsd)
76 writeParams(device);
77 device.closeTag();
78}
79
80
81bool
83 return true;
84}
85
86
87std::string
89 return "";
90}
91
92
93void
95 // nothing to fix
96}
97
98
99bool
101 return false;
102}
103
104
105void
107 // calculate perpendicular line
109}
110
111
116
117
118void
119GNEVaporizer::updateCenteringBoundary(const bool /*updateGrid*/) {
120 // nothing to do
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 // first check if additional has to be drawn
140 // Obtain exaggeration of the draw
141 const double vaporizerExaggeration = getExaggeration(s);
142 // get detail level
143 const auto d = s.getDetailLevel(vaporizerExaggeration);
144 // draw geometry only if we'rent in drawForObjectUnderCursor mode
146 // declare colors
147 RGBColor vaporizerColor, centralLineColor;
148 // set colors
149 if (drawUsingSelectColor()) {
150 vaporizerColor = s.colorSettings.selectedAdditionalColor;
151 centralLineColor = vaporizerColor.changedBrightness(-32);
152 } else {
153 vaporizerColor = s.additionalSettings.vaporizerColor;
154 centralLineColor = RGBColor::WHITE;
155 }
156 // draw parent and child lines
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
165 GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.3 * vaporizerExaggeration);
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
171 GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.05 * vaporizerExaggeration);
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 level of detail
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 // draw additional name
198 // draw dotted contours
201 }
202 // calculate contours
204 s.additionalSettings.vaporizerSize, getType(), 0, 0, 0, vaporizerExaggeration, getParentEdges().front());
206 true, true, 0, nullptr, getParentEdges().front());
207 }
208}
209
210
211std::string
213 switch (key) {
214 case SUMO_ATTR_ID:
215 case SUMO_ATTR_EDGE:
216 return getMicrosimID();
217 case SUMO_ATTR_BEGIN:
218 return time2string(myBegin);
219 case SUMO_ATTR_END:
220 return time2string(myEnd);
221 case SUMO_ATTR_NAME:
222 return myAdditionalName;
223 default:
224 return getCommonAttribute(this, key);
225 }
226}
227
228
229double
231 switch (key) {
232 case SUMO_ATTR_BEGIN:
233 return STEPS2TIME(myBegin);
234 case SUMO_ATTR_END:
235 return STEPS2TIME(myEnd);
236 default:
237 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
238 }
239}
240
241
246
247
248void
249GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
250 if (value == getAttribute(key)) {
251 return; //avoid needless changes, later logic relies on the fact that attributes have changed
252 }
253 switch (key) {
254 case SUMO_ATTR_ID:
255 case SUMO_ATTR_EDGE:
256 case SUMO_ATTR_BEGIN:
257 case SUMO_ATTR_END:
258 case SUMO_ATTR_NAME:
259 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
260 break;
261 default:
262 setCommonAttribute(key, value, undoList);
263 break;
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 const auto begin = parse<SUMOTime>(value);
281 return ((begin >= 0) && (parse<SUMOTime>(value) <= myEnd));
282 } else {
283 return false;
284 }
285 case SUMO_ATTR_END:
286 if (canParse<SUMOTime>(value)) {
287 const auto end = parse<SUMOTime>(value);
288 return ((end >= 0) && (myBegin <= parse<SUMOTime>(value)));
289 } else {
290 return false;
291 }
292 case SUMO_ATTR_NAME:
294 default:
295 return isCommonValid(key, value);
296 }
297}
298
299
300std::string
302 return getTagStr();
303}
304
305
306std::string
310
311// ===========================================================================
312// private
313// ===========================================================================
314
315void
316GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
317 switch (key) {
318 case SUMO_ATTR_ID:
319 case SUMO_ATTR_EDGE:
320 // update microsimID
321 setAdditionalID(value);
323 break;
324 case SUMO_ATTR_BEGIN:
325 myBegin = parse<SUMOTime>(value);
326 break;
327 case SUMO_ATTR_END:
328 myEnd = parse<SUMOTime>(value);
329 break;
330 case SUMO_ATTR_NAME:
331 myAdditionalName = value;
332 break;
333 default:
334 setCommonAttribute(this, key, value);
335 break;
336 }
337}
338
339
340void
342 // nothing to do
343}
344
345
346void
347GNEVaporizer::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
348 // nothing to do
349}
350
351/****************************************************************************/
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
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:653
static void popMatrix()
pop matrix
Definition GLHelper.cpp:135
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:300
static void pushMatrix()
push matrix
Definition GLHelper.cpp:122
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
std::string getCommonAttribute(const Parameterised *parameterised, 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
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) 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)
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
const GNEHierarchicalContainerParents< 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:147
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2195
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...
GNEContour mySymbolBaseContour
symbol base contour
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)
bool checkDrawMoveContour() const
check if draw move contour (red)
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
const Parameterised::Map & getParametersMap() const
Returns the inner key/value 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
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)
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 segmentWidthSmall
width of small dotted contour segments
static const double segmentWidth
width of dotted contour segments