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>
24 #include <utils/gui/div/GLHelper.h>
27 
28 #include "GNEVaporizer.h"
29 
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
37 {}, {}, {}, {}, {}, {}, {}, {},
38 std::map<std::string, std::string>()),
39  myBegin(0),
40 myEnd(0) {
41  // reset default values
42  resetDefaultValues();
43 }
44 
45 
46 GNEVaporizer::GNEVaporizer(GNENet* net, GNEEdge* edge, SUMOTime from, SUMOTime end, const std::string& name,
47  const std::map<std::string, std::string>& parameters) :
48  GNEAdditional(edge->getID(), net, GLO_VAPORIZER, SUMO_TAG_VAPORIZER, name,
49 {}, {edge}, {}, {}, {}, {}, {}, {},
50 parameters),
51 myBegin(from),
52 myEnd(end) {
53  // update centering boundary without updating grid
54  updateCenteringBoundary(false);
55 }
56 
57 
59 }
60 
61 
64  // vaporizers cannot be moved
65  return nullptr;
66 }
67 
68 
69 void
71  device.openTag(getTagProperty().getTag());
72  device.writeAttr(SUMO_ATTR_ID, getID());
73  if (!myAdditionalName.empty()) {
75  }
78  // write parameters (Always after children to avoid problems with additionals.xsd)
79  writeParams(device);
80  device.closeTag();
81 }
82 
83 
84 void
86  // calculate perpendicular line
88 }
89 
90 
94 }
95 
96 
97 void
98 GNEVaporizer::updateCenteringBoundary(const bool /*updateGrid*/) {
100  // add center
102  // grow
104 }
105 
106 
107 void
108 GNEVaporizer::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
109  // geometry of this element cannot be splitted
110 }
111 
112 
113 std::string
115  return getParentEdges().front()->getID();
116 }
117 
118 
119 void
121  // Obtain exaggeration of the draw
122  const double vaporizerExaggeration = getExaggeration(s);
123  // first check if additional has to be drawn
124  if (s.drawAdditionals(vaporizerExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
125  // declare colors
126  RGBColor vaporizerColor, centralLineColor;
127  // set colors
128  if (drawUsingSelectColor()) {
129  vaporizerColor = s.colorSettings.selectedAdditionalColor;
130  centralLineColor = vaporizerColor.changedBrightness(-32);
131  } else {
132  vaporizerColor = s.additionalSettings.vaporizerColor;
133  centralLineColor = RGBColor::WHITE;
134  }
135  // draw parent and child lines
137  // Start drawing adding an gl identificator
139  // Add layer matrix matrix
141  // translate to front
143  // set base color
144  GLHelper::setColor(vaporizerColor);
145  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
147  // move to front
148  glTranslated(0, 0, .1);
149  // set central color
150  GLHelper::setColor(centralLineColor);
151  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
153  // move to icon position and front
154  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
155  // rotate over lane
157  // Draw icon depending of Route Probe is selected and if isn't being drawn for selecting
158  if (!s.drawForRectangleSelection && s.drawDetail(s.detailSettings.laneTextures, vaporizerExaggeration)) {
159  // set color
160  glColor3d(1, 1, 1);
161  // rotate texture
162  glRotated(90, 0, 0, 1);
163  // draw texture
164  if (drawUsingSelectColor()) {
166  } else {
168  }
169  } else {
170  // set route probe color
171  GLHelper::setColor(vaporizerColor);
172  // just drawn a box
174  }
175  // pop layer matrix
177  // Pop name
179  // draw additional name
181  // check if dotted contours has to be drawn
184  vaporizerExaggeration, 1, 1);
185  }
186  if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
188  vaporizerExaggeration, 1, 1);
189  }
190  }
191 }
192 
193 
194 std::string
196  switch (key) {
197  case SUMO_ATTR_ID:
198  case SUMO_ATTR_EDGE:
199  return getID();
200  case SUMO_ATTR_BEGIN:
201  return time2string(myBegin);
202  case SUMO_ATTR_END:
203  return time2string(myEnd);
204  case SUMO_ATTR_NAME:
205  return myAdditionalName;
206  case GNE_ATTR_SELECTED:
208  case GNE_ATTR_PARAMETERS:
209  return getParametersStr();
210  default:
211  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
212  }
213 }
214 
215 
216 double
218  switch (key) {
219  case SUMO_ATTR_BEGIN:
220  return STEPS2TIME(myBegin);
221  case SUMO_ATTR_END:
222  return STEPS2TIME(myEnd);
223  default:
224  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
225  }
226 }
227 
228 
229 void
230 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
231  if (value == getAttribute(key)) {
232  return; //avoid needless changes, later logic relies on the fact that attributes have changed
233  }
234  switch (key) {
235  case SUMO_ATTR_ID:
236  case SUMO_ATTR_EDGE:
237  case SUMO_ATTR_BEGIN:
238  case SUMO_ATTR_END:
239  case SUMO_ATTR_NAME:
240  case GNE_ATTR_SELECTED:
241  case GNE_ATTR_PARAMETERS:
242  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
243  break;
244  default:
245  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
246  }
247 }
248 
249 
250 bool
251 GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
252  switch (key) {
253  case SUMO_ATTR_ID:
254  case SUMO_ATTR_EDGE:
255  if (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) {
256  return isValidAdditionalID(value);
257  } else {
258  return false;
259  }
260  case SUMO_ATTR_BEGIN:
261  if (canParse<SUMOTime>(value)) {
262  return (parse<SUMOTime>(value) <= myEnd);
263  } else {
264  return false;
265  }
266  case SUMO_ATTR_END:
267  if (canParse<SUMOTime>(value)) {
268  return (myBegin <= parse<SUMOTime>(value));
269  } else {
270  return false;
271  }
272  case SUMO_ATTR_NAME:
274  case GNE_ATTR_SELECTED:
275  return canParse<bool>(value);
276  case GNE_ATTR_PARAMETERS:
277  return Parameterised::areParametersValid(value);
278  default:
279  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
280  }
281 }
282 
283 
284 bool
286  return true;
287 }
288 
289 
290 std::string
292  return getTagStr();
293 }
294 
295 
296 std::string
298  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
299 }
300 
301 // ===========================================================================
302 // private
303 // ===========================================================================
304 
305 void
306 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
307  switch (key) {
308  case SUMO_ATTR_ID:
309  case SUMO_ATTR_EDGE:
310  // update microsimID
311  setMicrosimID(value);
313  break;
314  case SUMO_ATTR_BEGIN:
315  myBegin = parse<SUMOTime>(value);
316  break;
317  case SUMO_ATTR_END:
318  myEnd = parse<SUMOTime>(value);
319  break;
320  case SUMO_ATTR_NAME:
321  myAdditionalName = value;
322  break;
323  case GNE_ATTR_SELECTED:
324  if (parse<bool>(value)) {
326  } else {
328  }
329  break;
330  case GNE_ATTR_PARAMETERS:
331  setParametersStr(value);
332  break;
333  default:
334  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
335  }
336 }
337 
338 
339 void
341  // nothing to do
342 }
343 
344 
345 void
346 GNEVaporizer::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
347  // nothing to do
348 }
349 
350 /****************************************************************************/
@ GLO_VAPORIZER
a Vaporizer
@ VAPORIZER_SELECTED
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
long long int SUMOTime
Definition: SUMOTime.h:32
@ 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:77
void reset()
Resets the boundary.
Definition: Boundary.cpp:65
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:231
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const std::string & getID() const
get ID
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 asociated 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
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:125
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
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
writte 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 conrrespond 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
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:133
SUMOTime myEnd
end time in which this vaporizer is placed
Definition: GNEVaporizer.h:136
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.
bool isAttributeEnabled(SumoXMLAttr key) const
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:537
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
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 DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem, const double lineWidth=-1)
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.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
GUIGlID getGlID() const
Returns the numerical id of the object.
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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|....
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"
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:197
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