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 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:1020
long long int SUMOTime
Definition: SUMOTime.h:35
double scale
information about a lane&#39;s width (temporary, used for a single view)
PositionVector shape
The shape of the netElement element.
Definition: GNENetElement.h:57
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
GNEVaporizer(GNEViewNet *viewNet, GNEEdge *edge, SUMOTime begin, SUMOTime end, const std::string &name)
Constructor.
GUIVisualizationTextSettings addName
std::vector< double > shapeRotations
The rotations of the single shape parts.
Definition: GNEAdditional.h:74
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
static const RGBColor WHITE
Definition: RGBColor.h:197
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
Stores the information about how to visualize structures.
Position offset
The offSet of the block icon.
double y() const
Returns the y-position.
Definition: Position.h:62
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double x() const
Returns the x-position.
Definition: Position.h:57
weights: time range begin
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Position position
position of the block icon
BlockIcon myBlockIcon
variable BlockIcon
void clearGeometry()
reset geometry
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
SUMOTime myEnd
end time in which this vaporizer is placed
Definition: GNEVaporizer.h:119
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
Position getLineCenter() const
get line center
const std::vector< GNEEdge * > & getEdgeParents() const
get edge parents
static const RGBColor vaporizer
color for vaporizers
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
a Vaporizer
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
PositionVector shape
The shape of the additional element.
Definition: GNEAdditional.h:68
RGBColor selectionColor
basic selection color
std::string myAdditionalName
name of additional
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
static const double laneTextures
details for lane textures
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
SUMOTime myBegin
begin time of vaporizer
Definition: GNEVaporizer.h:116
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
const NetElementGeometry & getGeometry() const
std::string getAttribute(SumoXMLAttr key) const
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
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
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
GUIVisualizationDetailSettings detailSettings
detail settings
Position getPositionInView() const
Returns position of additional in view.
double length() const
Returns the length.
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:939
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
const std::string & getTagStr() const
get tag assigned to this object in string format
weights: time range end
element is selected
std::string getGenericParametersStr() const
return generic parameters in string format
vaporizer of vehicles
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GUIGlID getGlID() const
Returns the numerical id of the object.
void changeEdgeParents(GNEShape *elementChild, const std::string &newEdgeIDs)
change edge parents of a shape
GUIVisualizationColorSettings colorSettings
color settings
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
std::string getParentName() const
Returns the name of the parent object (if any)
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:136
void drawIcon(const GUIVisualizationSettings &s, const double exaggeration, const double size=0.5) const
draw lock icon
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
~GNEVaporizer()
Destructor.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
void updateGeometry()
update pre-computed geometry information
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry() function)