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-2020 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 
35 GNEVaporizer::GNEVaporizer(GNENet* net, GNEEdge* edge, SUMOTime begin, SUMOTime end, const std::string& name) :
36  GNEAdditional(edge->getID(), net, GLO_VAPORIZER, SUMO_TAG_VAPORIZER, name, false,
37 {}, {edge}, {}, {}, {}, {}, {}, {}),
38 myBegin(begin),
39 myEnd(end) {
40  // update centering boundary without updating grid
41  updateCenteringBoundary(false);
42 }
43 
44 
46 }
47 
48 
50 GNEVaporizer::getMoveOperation(const double /*shapeOffset*/) {
51  // vaporizers cannot be moved
52  return nullptr;
53 }
54 
55 
56 void
58  // calculate perpendicular line
60 }
61 
62 
63 void
64 GNEVaporizer::updateCenteringBoundary(const bool /*updateGrid*/) {
65  // update geometry
67  // add shape boundary
69  // grow
70  myBoundary.grow(10);
71 }
72 
73 
74 void
75 GNEVaporizer::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
76  // geometry of this element cannot be splitted
77 }
78 
79 
80 std::string
82  return getParentEdges().front()->getID();
83 }
84 
85 
86 void
88  // Obtain exaggeration of the draw
89  const double vaporizerExaggeration = s.addSize.getExaggeration(s, this);
90  // first check if additional has to be drawn
91  if (s.drawAdditionals(vaporizerExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
92  // declare colors
93  RGBColor vaporizerColor, centralLineColor;
94  // set colors
95  if (drawUsingSelectColor()) {
96  vaporizerColor = s.colorSettings.selectedAdditionalColor;
97  centralLineColor = vaporizerColor.changedBrightness(-32);
98  } else {
99  vaporizerColor = s.additionalSettings.vaporizerColor;
100  centralLineColor = RGBColor::WHITE;
101  }
102  // Start drawing adding an gl identificator
103  glPushName(getGlID());
104  // Add layer matrix matrix
105  glPushMatrix();
106  // translate to front
108  // set base color
109  GLHelper::setColor(vaporizerColor);
110  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
111  GNEGeometry::drawGeometry(myNet->getViewNet(), myAdditionalGeometry, 0.3 * vaporizerExaggeration);
112  // move to front
113  glTranslated(0, 0, .1);
114  // set central color
115  GLHelper::setColor(centralLineColor);
116  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
117  GNEGeometry::drawGeometry(myNet->getViewNet(), myAdditionalGeometry, 0.05 * vaporizerExaggeration);
118  // move to icon position and front
119  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
120  // rotate over lane
122  // Draw icon depending of Route Probe is selected and if isn't being drawn for selecting
123  if (!s.drawForRectangleSelection && s.drawDetail(s.detailSettings.laneTextures, vaporizerExaggeration)) {
124  // set color
125  glColor3d(1, 1, 1);
126  // rotate texture
127  glRotated(180, 0, 0, 1);
128  // draw texture
129  if (drawUsingSelectColor()) {
131  } else {
133  }
134  } else {
135  // set route probe color
136  GLHelper::setColor(vaporizerColor);
137  // just drawn a box
139  }
140  // pop layer matrix
141  glPopMatrix();
142  // Pop name
143  glPopName();
144  // draw additional name
146  // check if dotted contours has to be drawn
149  }
150  if (s.drawDottedContour() || myNet->getViewNet()->getFrontAttributeCarrier() == this) {
152  }
153  }
154 }
155 
156 
157 std::string
159  switch (key) {
160  case SUMO_ATTR_ID:
161  case SUMO_ATTR_EDGE:
162  return getID();
163  case SUMO_ATTR_BEGIN:
164  return time2string(myBegin);
165  case SUMO_ATTR_END:
166  return time2string(myEnd);
167  case SUMO_ATTR_NAME:
168  return myAdditionalName;
169  case GNE_ATTR_SELECTED:
171  case GNE_ATTR_PARAMETERS:
172  return getParametersStr();
173  default:
174  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
175  }
176 }
177 
178 
179 double
181  switch (key) {
182  case SUMO_ATTR_BEGIN:
183  return STEPS2TIME(myBegin);
184  case SUMO_ATTR_END:
185  return STEPS2TIME(myEnd);
186  default:
187  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
188  }
189 }
190 
191 
192 void
193 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
194  if (value == getAttribute(key)) {
195  return; //avoid needless changes, later logic relies on the fact that attributes have changed
196  }
197  switch (key) {
198  case SUMO_ATTR_ID:
199  case SUMO_ATTR_EDGE:
200  case SUMO_ATTR_BEGIN:
201  case SUMO_ATTR_END:
202  case SUMO_ATTR_NAME:
203  case GNE_ATTR_SELECTED:
204  case GNE_ATTR_PARAMETERS:
205  undoList->p_add(new GNEChange_Attribute(this, key, value));
206  break;
207  default:
208  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
209  }
210 }
211 
212 
213 bool
214 GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
215  switch (key) {
216  case SUMO_ATTR_ID:
217  case SUMO_ATTR_EDGE:
218  if (myNet->retrieveEdge(value, false) != nullptr) {
219  return isValidAdditionalID(value);
220  } else {
221  return false;
222  }
223  case SUMO_ATTR_BEGIN:
224  if (canParse<SUMOTime>(value)) {
225  return (parse<SUMOTime>(value) <= myEnd);
226  } else {
227  return false;
228  }
229  case SUMO_ATTR_END:
230  if (canParse<SUMOTime>(value)) {
231  return (myBegin <= parse<SUMOTime>(value));
232  } else {
233  return false;
234  }
235  case SUMO_ATTR_NAME:
237  case GNE_ATTR_SELECTED:
238  return canParse<bool>(value);
239  case GNE_ATTR_PARAMETERS:
240  return Parameterised::areParametersValid(value);
241  default:
242  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
243  }
244 }
245 
246 
247 bool
249  return true;
250 }
251 
252 
253 std::string
255  return getTagStr();
256 }
257 
258 
259 std::string
261  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
262 }
263 
264 // ===========================================================================
265 // private
266 // ===========================================================================
267 
268 void
269 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
270  switch (key) {
271  case SUMO_ATTR_ID:
272  case SUMO_ATTR_EDGE:
273  myNet->getAttributeCarriers()->updateID(this, value);
275  break;
276  case SUMO_ATTR_BEGIN:
277  myBegin = parse<SUMOTime>(value);
278  break;
279  case SUMO_ATTR_END:
280  myEnd = parse<SUMOTime>(value);
281  break;
282  case SUMO_ATTR_NAME:
283  myAdditionalName = value;
284  break;
285  case GNE_ATTR_SELECTED:
286  if (parse<bool>(value)) {
288  } else {
290  }
291  break;
292  case GNE_ATTR_PARAMETERS:
293  setParametersStr(value);
294  break;
295  default:
296  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
297  }
298 }
299 
300 
301 void
303  // nothing to do
304 }
305 
306 
307 void
308 GNEVaporizer::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
309  // nothing to do
310 }
311 
312 /****************************************************************************/
@ GLO_VAPORIZER
a Vaporizer
@ GNETEXTURE_VAPORIZER
Definition: GUITextures.h:45
@ GNETEXTURE_VAPORIZERSELECTED
Definition: GUITextures.h:46
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:31
@ 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:44
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:446
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:135
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
GNEGeometry::Geometry 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
Boundary myBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
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
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:49
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
const PositionVector & getShape() const
The shape of the additional element.
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
move operation
move result
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true) const
get edge by id
Definition: GNENet.cpp:1141
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
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
GNEVaporizer(GNENet *net, GNEEdge *edge, SUMOTime begin, SUMOTime end, const std::string &name)
Constructor.
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:118
SUMOTime myEnd
end time in which this vaporizer is placed
Definition: GNEVaporizer.h:121
std::string getParentName() const
Returns the name of the parent object (if any)
double getAttributeDouble(SumoXMLAttr key) const
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
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:491
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
GUIGlID getGlID() const
Returns the numerical id of the object.
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
GUIVisualizationSizeSettings addSize
bool drawDottedContour() const
check if dotted contour can be drawn
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 bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, 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"
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:36
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static const RGBColor WHITE
Definition: RGBColor.h:187
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:145
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static void drawDottedContourShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration)
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.)
static void drawGeometry(const GNEViewNet *viewNet, const Geometry &geometry, const double width)
draw geometry
bool showAdditionals() const
check if additionals has to be drawn
static const double vaporizerSize
Vaporizer size.
static const RGBColor vaporizerColor
color for vaporizers
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double laneTextures
details for lane textures
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values