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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
28 #include <utils/gui/div/GLHelper.h>
31 
32 #include "GNEVaporizer.h"
33 
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
39 GNEVaporizer::GNEVaporizer(GNEViewNet* viewNet, GNEEdge* edge, SUMOTime begin, SUMOTime end, const std::string& name) :
40  GNEAdditional(edge->getID(), viewNet, GLO_VAPORIZER, SUMO_TAG_VAPORIZER, name, false, {
41  edge
42 }, {}, {}, {}, {}, {}, {}, {}, {}, {}),
43 myBegin(begin),
44 myEnd(end) {
45 }
46 
47 
49 }
50 
51 
52 void
54  // Clear all containers
56 
57  // get lanes of edge
58  GNELane* firstLane = getEdgeParents().front()->getLanes().at(0);
59 
60  // Get shape of lane parent
61  double offset = firstLane->getGeometry().shape.length() < 2.5 ? firstLane->getGeometry().shape.length() : 2.5;
62  myGeometry.shape.push_back(firstLane->getGeometry().shape.positionAtOffset(offset));
63 
64  // Save rotation (angle) of the vector constructed by points f and s
65  myGeometry.shapeRotations.push_back(firstLane->getGeometry().shape.rotationDegreeAtOffset(0) * -1);
66 
67  // Set block icon position
69 
70  // Set offset of the block icon
71  myBlockIcon.offset = Position(1.1, (-3.06));
72 
73  // Set block icon rotation, and using their rotation for logo
74  myBlockIcon.setRotation(firstLane);
75 }
76 
77 
80  if (getEdgeParents().front()->getLanes().front()->getGeometry().shape.length() < 2.5) {
81  return getEdgeParents().front()->getLanes().front()->getGeometry().shape.front();
82  } else {
83  Position A = getEdgeParents().front()->getLanes().front()->getGeometry().shape.positionAtOffset(2.5);
84  Position B = getEdgeParents().front()->getLanes().back()->getGeometry().shape.positionAtOffset(2.5);
85 
86  // return Middle point
87  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
88  }
89 }
90 
91 
94  return myGeometry.shape.getBoxBoundary().grow(10);
95 }
96 
97 
98 void
100  // This additional cannot be moved
101 }
102 
103 
104 void
106  // This additional cannot be moved
107 }
108 
109 
110 std::string
112  return getEdgeParents().front()->getMicrosimID();
113 }
114 
115 
116 void
118  // get values
119  const double exaggeration = s.addSize.getExaggeration(s, this);
120  const int numberOfLanes = int(getEdgeParents().front()->getLanes().size());
121  const double width = (double) 2.0 * s.scale;
122  // begin draw
123  glPushName(getGlID());
124  glLineWidth(1.0);
125  // set color
126  if (drawUsingSelectColor()) {
128  } else {
130  }
131  // draw shape
132  glPushMatrix();
133  glTranslated(0, 0, getType());
134  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), 0);
135  glRotated(myGeometry.shapeRotations[0], 0, 0, 1);
136  glScaled(exaggeration, exaggeration, 1);
137  glTranslated(-1.6, -1.6, 0);
138  glBegin(GL_QUADS);
139  glVertex2d(0, 0.25);
140  glVertex2d(0, -0.25);
141  glVertex2d((numberOfLanes * 3.3), -0.25);
142  glVertex2d((numberOfLanes * 3.3), 0.25);
143  glEnd();
144  glTranslated(0, 0, .01);
145  glBegin(GL_LINES);
146  glVertex2d(0, 0.25 - .1);
147  glVertex2d(0, -0.25 + .1);
148  glEnd();
149  // draw position indicator (White) if isn't being drawn for selecting
150  if ((width * exaggeration > 1) && !s.drawForSelecting) {
151  if (drawUsingSelectColor()) {
153  } else {
155  }
156  glRotated(90, 0, 0, -1);
157  glBegin(GL_LINES);
158  glVertex2d(0, 0);
159  glVertex2d(0, (numberOfLanes * 3.3));
160  glEnd();
161  }
162  // Pop shape matrix
163  glPopMatrix();
164  // Add a draw matrix for drawing logo
165  glPushMatrix();
166  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), getType());
167  glRotated(myGeometry.shapeRotations[0], 0, 0, 1);
168  glTranslated((-2.56), (-1.6), 0);
169  // Draw icon depending of Vaporizer is selected and if isn't being drawn for selecting
170  if (!s.drawForSelecting && s.drawDetail(s.detailSettings.laneTextures, exaggeration)) {
171  glColor3d(1, 1, 1);
172  glRotated(-90, 0, 0, 1);
173  if (drawUsingSelectColor()) {
175  } else {
177  }
178  } else {
180  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
181  }
182  // Pop logo matrix
183  glPopMatrix();
184  // Show Lock icon
185  myBlockIcon.drawIcon(s, exaggeration, 0.4);
186  // draw name
188  // check if dotted contour has to be drawn
189  if (myViewNet->getDottedAC() == this) {
191  }
192  // pop name
193  glPopName();
194 }
195 
196 
197 std::string
199  switch (key) {
200  case SUMO_ATTR_ID:
201  case SUMO_ATTR_EDGE:
202  return getAdditionalID();
203  case SUMO_ATTR_BEGIN:
204  return time2string(myBegin);
205  case SUMO_ATTR_END:
206  return time2string(myEnd);
207  case SUMO_ATTR_NAME:
208  return myAdditionalName;
209  case GNE_ATTR_SELECTED:
211  case GNE_ATTR_GENERIC:
212  return getGenericParametersStr();
213  default:
214  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
215  }
216 }
217 
218 
219 void
220 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
221  if (value == getAttribute(key)) {
222  return; //avoid needless changes, later logic relies on the fact that attributes have changed
223  }
224  switch (key) {
225  case SUMO_ATTR_ID:
226  case SUMO_ATTR_EDGE:
227  case SUMO_ATTR_BEGIN:
228  case SUMO_ATTR_END:
229  case SUMO_ATTR_NAME:
230  case GNE_ATTR_SELECTED:
231  case GNE_ATTR_GENERIC:
232  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
233  break;
234  default:
235  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
236  }
237 }
238 
239 
240 bool
241 GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
242  switch (key) {
243  case SUMO_ATTR_ID:
244  case SUMO_ATTR_EDGE:
245  if (myViewNet->getNet()->retrieveEdge(value, false) != nullptr) {
246  return isValidAdditionalID(value);
247  } else {
248  return false;
249  }
250  case SUMO_ATTR_BEGIN:
251  if (canParse<SUMOTime>(value)) {
252  return (parse<SUMOTime>(value) <= myEnd);
253  } else {
254  return false;
255  }
256  case SUMO_ATTR_END:
257  if (canParse<SUMOTime>(value)) {
258  return (myBegin <= parse<SUMOTime>(value));
259  } else {
260  return false;
261  }
262  case SUMO_ATTR_NAME:
264  case GNE_ATTR_SELECTED:
265  return canParse<bool>(value);
266  case GNE_ATTR_GENERIC:
267  return isGenericParametersValid(value);
268  default:
269  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
270  }
271 }
272 
273 
274 std::string
276  return getTagStr();
277 }
278 
279 
280 std::string
282  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
283 }
284 
285 // ===========================================================================
286 // private
287 // ===========================================================================
288 
289 void
290 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
291  switch (key) {
292  case SUMO_ATTR_ID:
293  case SUMO_ATTR_EDGE:
294  changeAdditionalID(value);
295  changeEdgeParents(this, value);
296  break;
297  case SUMO_ATTR_BEGIN:
298  myBegin = parse<SUMOTime>(value);
299  break;
300  case SUMO_ATTR_END:
301  myEnd = parse<SUMOTime>(value);
302  break;
303  case SUMO_ATTR_NAME:
304  myAdditionalName = value;
305  break;
306  case GNE_ATTR_SELECTED:
307  if (parse<bool>(value)) {
309  } else {
311  }
312  break;
313  case GNE_ATTR_GENERIC:
315  break;
316  default:
317  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
318  }
319 }
320 
321 /****************************************************************************/
GUIGlObject::getType
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.cpp:181
SUMOXMLDefinitions::isValidAttribute
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
Definition: SUMOXMLDefinitions.cpp:988
GNEAdditional::BlockIcon::position
Position position
position of the block icon
Definition: GNEAdditional.h:351
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
GNEAdditional::setGenericParametersStr
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
Definition: GNEAdditional.cpp:704
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:578
GNEVaporizer::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNEVaporizer.cpp:53
GNEAdditional::AdditionalGeometry::shape
PositionVector shape
The shape of the additional element.
Definition: GNEAdditional.h:68
GNEAdditional::BlockIcon::setRotation
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry() function)
Definition: GNEAdditional.cpp:502
GUIGlObject::drawName
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
Definition: GUIGlObject.cpp:355
GNEAdditional::AdditionalGeometry::shapeRotations
std::vector< double > shapeRotations
The rotations of the single shape parts.
Definition: GNEAdditional.h:74
GNEVaporizer::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEVaporizer.cpp:105
GNEAttributeCarrier::isGenericParametersValid
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
Definition: GNEAttributeCarrier.cpp:1354
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMO_ATTR_EDGE
Definition: SUMOXMLDefinitions.h:424
GNEViewNet
Definition: GNEViewNet.h:43
GNEVaporizer::getAttribute
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEVaporizer.cpp:198
GNEHierarchicalElementParents::getEdgeParents
const std::vector< GNEEdge * > & getEdgeParents() const
get edge parents
Definition: GNEHierarchicalElementParents.cpp:150
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
PositionVector::length
double length() const
Returns the length.
Definition: PositionVector.cpp:476
GLHelper.h
GNEVaporizer::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEVaporizer.cpp:275
GNEVaporizer::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEVaporizer.cpp:99
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:604
GNEAdditional::unselectAttributeCarrier
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Definition: GNEAdditional.cpp:634
GNETEXTURE_VAPORIZERSELECTED
Definition: GUITextures.h:49
GNEAdditional::myBlockIcon
BlockIcon myBlockIcon
variable BlockIcon
Definition: GNEAdditional.h:380
GNEVaporizer::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEVaporizer.cpp:93
GLHelper::setColor
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
PositionVector::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Definition: PositionVector.cpp:382
GNEVaporizer::myEnd
SUMOTime myEnd
end time in which this vaporizer is placed
Definition: GNEVaporizer.h:119
GUITexturesHelper::drawTexturedBox
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
Definition: GUITexturesHelper.cpp:73
GNENetElement::NetElementGeometry::shape
PositionVector shape
The shape of the netElement element.
Definition: GNENetElement.h:57
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:365
SUMO_ATTR_BEGIN
weights: time range begin
Definition: SUMOXMLDefinitions.h:675
GNEEdge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
GNEAttributeCarrier::GNEChange_Attribute
friend class GNEChange_Attribute
declare friend class
Definition: GNEAttributeCarrier.h:57
GNEUndoList::p_add
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Definition: GNEUndoList.cpp:132
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GNEAdditional::isAttributeCarrierSelected
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
Definition: GNEAdditional.cpp:650
GUIVisualizationSettings::addName
GUIVisualizationTextSettings addName
Definition: GUIVisualizationSettings.h:582
GUIVisualizationSettings::detailSettings
GUIVisualizationDetailSettings detailSettings
detail settings
Definition: GUIVisualizationSettings.h:655
GUIVisualizationColorSettings::selectedAdditionalColor
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
Definition: GUIVisualizationSettings.h:148
GNEAdditional::selectAttributeCarrier
void selectAttributeCarrier(bool changeFlag=true)
Definition: GNEAdditional.cpp:619
GNEViewNet.h
PositionVector::positionAtOffset
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Definition: PositionVector.cpp:246
PositionVector::rotationDegreeAtOffset
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
Definition: PositionVector.cpp:311
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:150
GNEViewNet::getDottedAC
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:939
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
GUITextureSubSys::getTexture
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
Definition: GUITextureSubSys.cpp:102
GLHelper::drawShapeDottedContourRectangle
static void drawShapeDottedContourRectangle(const GUIVisualizationSettings &s, const int type, const Position &center, const double width, const double height, const double rotation=0, const double offsetX=0, const double offsetY=0)
draw a dotted contour around the given Position with certain width and height
Definition: GLHelper.cpp:555
GUIVisualizationSettings::scale
double scale
information about a lane's width (temporary, used for a single view)
Definition: GUIVisualizationSettings.h:623
GNEAdditional::AdditionalGeometry::clearGeometry
void clearGeometry()
reset geometry
Definition: GNEAdditional.cpp:53
GNEVaporizer::getParentName
std::string getParentName() const
Returns the name of the parent object (if any)
Definition: GNEVaporizer.cpp:111
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
GUIVisualizationColorSettings::vaporizer
static const RGBColor vaporizer
color for vaporizers
Definition: GUIVisualizationSettings.h:229
Position::x
double x() const
Returns the x-position.
Definition: Position.h:57
GNEEdge.h
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
GNEAdditional::myAdditionalName
std::string myAdditionalName
name of additional
Definition: GNEAdditional.h:374
GNEVaporizer::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEVaporizer.cpp:117
GNEVaporizer::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEVaporizer.cpp:79
GUIVisualizationDetailSettings::laneTextures
static const double laneTextures
details for lane textures
Definition: GUIVisualizationSettings.h:284
GNELane.h
GNEVaporizer::isValid
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEVaporizer.cpp:241
GNENetElement::getGeometry
const NetElementGeometry & getGeometry() const
Definition: GNENetElement.cpp:95
GUIVisualizationSettings::colorSettings
GUIVisualizationColorSettings colorSettings
color settings
Definition: GUIVisualizationSettings.h:649
GUIVisualizationColorSettings::selectionColor
RGBColor selectionColor
basic selection color
Definition: GUIVisualizationSettings.h:130
GNEVaporizer::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEVaporizer.cpp:281
GLIncludes.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNE_ATTR_GENERIC
generic attribute
Definition: SUMOXMLDefinitions.h:986
GNEAdditional::BlockIcon::drawIcon
void drawIcon(const GUIVisualizationSettings &s, const double exaggeration, const double size=0.5) const
draw lock icon
Definition: GNEAdditional.cpp:518
Position::y
double y() const
Returns the y-position.
Definition: Position.h:62
GLO_VAPORIZER
a Vaporizer
Definition: GUIGlObjectTypes.h:96
GNEVaporizer::setAttribute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNEVaporizer.cpp:220
GNEVaporizer::myBegin
SUMOTime myBegin
begin time of vaporizer
Definition: GNEVaporizer.h:116
GNEVaporizer.h
InvalidArgument
Definition: UtilExceptions.h:57
GLHelper::drawBoxLine
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:136
GNEAdditional::getGenericParametersStr
std::string getGenericParametersStr() const
return generic parameters in string format
Definition: GNEAdditional.cpp:678
SUMO_TAG_VAPORIZER
vaporizer of vehicles
Definition: SUMOXMLDefinitions.h:219
GNEAdditional::drawUsingSelectColor
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
Definition: GNEAdditional.cpp:656
GNENet::retrieveEdge
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:1020
GNEAdditional::myGeometry
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
Definition: GNEAdditional.h:368
GNEVaporizer::GNEVaporizer
GNEVaporizer(GNEViewNet *viewNet, GNEEdge *edge, SUMOTime begin, SUMOTime end, const std::string &name)
Constructor.
Definition: GNEVaporizer.cpp:39
GUIVisualizationSettings::addSize
GUIVisualizationSizeSettings addSize
Definition: GUIVisualizationSettings.h:580
GNE_ATTR_SELECTED
element is selected
Definition: SUMOXMLDefinitions.h:968
SUMO_ATTR_END
weights: time range end
Definition: SUMOXMLDefinitions.h:677
Boundary::grow
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
GUIVisualizationSettings::drawDetail
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
Definition: GUIVisualizationSettings.cpp:1621
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
SUMO_ATTR_NAME
Definition: SUMOXMLDefinitions.h:381
GNEUndoList
Definition: GNEUndoList.h:49
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:346
PositionVector::getLineCenter
Position getLineCenter() const
get line center
Definition: PositionVector.cpp:466
GNEHierarchicalElementParents::changeEdgeParents
void changeEdgeParents(GNEShape *elementChild, const std::string &newEdgeIDs)
change edge parents of a shape
Definition: GNEHierarchicalElementParents.cpp:340
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:584
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:373
GNELane
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
GUITextureSubSys.h
GNEChange_Attribute.h
GNENet.h
GNEVaporizer::~GNEVaporizer
~GNEVaporizer()
Destructor.
Definition: GNEVaporizer.cpp:48
GUIVisualizationSizeSettings::getExaggeration
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
Definition: GUIVisualizationSettings.cpp:212
GNETEXTURE_VAPORIZER
Definition: GUITextures.h:48
GNEAdditional::BlockIcon::offset
Position offset
The offSet of the block icon.
Definition: GNEAdditional.h:354
RGBColor::WHITE
static const RGBColor WHITE
Definition: RGBColor.h:197
GNEUndoList.h
GUIVisualizationSettings::drawForSelecting
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
Definition: GUIVisualizationSettings.h:635