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-2018 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 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
30 #include <utils/common/ToString.h>
31 #include <utils/geom/GeomHelper.h>
36 #include <utils/gui/div/GLHelper.h>
42 #include <netedit/GNEViewNet.h>
43 #include <netedit/GNEUndoList.h>
44 #include <netedit/GNENet.h>
46 #include <netedit/GNEViewParent.h>
47 
48 #include "GNEVaporizer.h"
49 
50 
51 // ===========================================================================
52 // member method definitions
53 // ===========================================================================
54 
55 GNEVaporizer::GNEVaporizer(GNEViewNet* viewNet, GNEEdge* edge, double begin, double end, const std::string& name) :
56  GNEAdditional(edge->getID(), viewNet, GLO_VAPORIZER, SUMO_TAG_VAPORIZER, name, false),
57  myEdge(edge),
58  myBegin(begin),
59  myEnd(end) {
60 }
61 
62 
64 }
65 
66 
67 void
68 GNEVaporizer::updateGeometry(bool updateGrid) {
69  // first check if object has to be removed from grid (SUMOTree)
70  if (updateGrid) {
72  }
73 
74  // Clear all containers
75  myShapeRotations.clear();
76  myShapeLengths.clear();
77 
78  // clear Shape
79  myShape.clear();
80 
81  // get lanes of edge
82  GNELane* firstLane = myEdge->getLanes().at(0);
83 
84  // Get shape of lane parent
85  double offset = firstLane->getShape().length() < 2.5 ? firstLane->getShape().length() : 2.5;
86  myShape.push_back(firstLane->getShape().positionAtOffset(offset));
87 
88  // Obtain first position
89  Position f = myShape[0] - Position(1, 0);
90 
91  // Obtain next position
92  Position s = myShape[0] + Position(1, 0);
93 
94  // Save rotation (angle) of the vector constructed by points f and s
95  myShapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(0) * -1);
96 
97  // Set block icon position
99 
100  // Set offset of the block icon
101  myBlockIconOffset = Position(1.1, (-3.06));
102 
103  // Set block icon rotation, and using their rotation for logo
104  setBlockIconRotation(firstLane);
105 
106  // last step is to check if object has to be added into grid (SUMOTree) again
107  if (updateGrid) {
109  }
110 }
111 
112 
113 Position
115  if (myEdge->getLanes().front()->getShape().length() < 2.5) {
116  return myEdge->getLanes().front()->getShape().front();
117  } else {
118  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(2.5);
119  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(2.5);
120 
121  // return Middle point
122  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
123  }
124 }
125 
126 
127 void
129  // This additional cannot be moved
130 }
131 
132 
133 void
135  // This additional cannot be moved
136 }
137 
138 
139 std::string
141  return myEdge->getMicrosimID();
142 }
143 
144 
145 void
147  // get values
148  glPushName(getGlID());
149  double width = (double) 2.0 * s.scale;
150  glLineWidth(1.0);
151  const double exaggeration = s.addSize.getExaggeration(s);
152  const int numberOfLanes = int(myEdge->getLanes().size());
153 
154  // set color
157  } else {
158  GLHelper::setColor(RGBColor(120, 216, 0));
159  }
160  // draw shape
161  glPushMatrix();
162  glTranslated(0, 0, getType());
163  glTranslated(myShape[0].x(), myShape[0].y(), 0);
164  glRotated(myShapeRotations[0], 0, 0, 1);
165  glScaled(exaggeration, exaggeration, 1);
166  glTranslated(-1.6, -1.6, 0);
167  glBegin(GL_QUADS);
168  glVertex2d(0, 0.25);
169  glVertex2d(0, -0.25);
170  glVertex2d((numberOfLanes * 3.3), -0.25);
171  glVertex2d((numberOfLanes * 3.3), 0.25);
172  glEnd();
173  glTranslated(0, 0, .01);
174  glBegin(GL_LINES);
175  glVertex2d(0, 0.25 - .1);
176  glVertex2d(0, -0.25 + .1);
177  glEnd();
178 
179  // draw position indicator (White) if isn't being drawn for selecting
180  if ((width * exaggeration > 1) && !s.drawForSelecting) {
183  } else {
185  }
186  glRotated(90, 0, 0, -1);
187  glBegin(GL_LINES);
188  glVertex2d(0, 0);
189  glVertex2d(0, (numberOfLanes * 3.3));
190  glEnd();
191  }
192 
193  // Pop shape matrix
194  glPopMatrix();
195 
196  // Add a draw matrix for drawing logo
197  glPushMatrix();
198  glTranslated(myShape[0].x(), myShape[0].y(), getType());
199  glRotated(myShapeRotations[0], 0, 0, 1);
200  glTranslated((-2.56), (-1.6), 0);
201 
202  // Draw icon depending of Vaporizer is selected and if isn't being drawn for selecting
203  if (s.drawForSelecting) {
205  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
206  } else {
207  glColor3d(1, 1, 1);
208  glRotated(-90, 0, 0, 1);
211  } else {
213  }
214  }
215 
216  // Pop logo matrix
217  glPopMatrix();
218 
219  // Check if the distance is enought to draw details
220  if ((s.scale * exaggeration >= 10) && !s.drawForSelecting) {
221  // Show Lock icon depending of the Edit mode
222  drawLockIcon(0.4);
223  }
224 
225  // draw name
226  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
227 
228  // check if dotted contour has to be drawn
229  if (!s.drawForSelecting && (myViewNet->getACUnderCursor() == this)) {
231  }
232 
233  // pop name
234  glPopName();
235 }
236 
237 
238 std::string
240  switch (key) {
241  case SUMO_ATTR_ID:
242  return getAdditionalID();
243  case SUMO_ATTR_BEGIN:
244  return toString(myBegin);
245  case SUMO_ATTR_END:
246  return toString(myEnd);
247  case SUMO_ATTR_NAME:
248  return myAdditionalName;
249  case GNE_ATTR_SELECTED:
251  case GNE_ATTR_GENERIC:
252  return getGenericParametersStr();
253  default:
254  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
255  }
256 }
257 
258 
259 void
260 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
261  if (value == getAttribute(key)) {
262  return; //avoid needless changes, later logic relies on the fact that attributes have changed
263  }
264  switch (key) {
265  case SUMO_ATTR_ID:
266  case SUMO_ATTR_EDGE:
267  case SUMO_ATTR_BEGIN:
268  case SUMO_ATTR_END:
269  case SUMO_ATTR_NAME:
270  case GNE_ATTR_SELECTED:
271  case GNE_ATTR_GENERIC:
272  undoList->p_add(new GNEChange_Attribute(this, key, value));
273  break;
274  default:
275  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
276  }
277 }
278 
279 
280 bool
281 GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
282  switch (key) {
283  case SUMO_ATTR_ID:
284  if (myViewNet->getNet()->retrieveEdge(value, false) != nullptr) {
285  return isValidAdditionalID(value);
286  } else {
287  return false;
288  }
289  case SUMO_ATTR_BEGIN:
290  if (canParse<double>(value) && (parse<double>(value) >= 0)) {
291  return (parse<double>(value) <= myEnd);
292  } else {
293  return false;
294  }
295  case SUMO_ATTR_END:
296  if (canParse<double>(value) && (parse<double>(value) >= 0)) {
297  return (myBegin <= parse<double>(value));
298  } else {
299  return false;
300  }
301  case SUMO_ATTR_NAME:
303  case GNE_ATTR_SELECTED:
304  return canParse<bool>(value);
305  case GNE_ATTR_GENERIC:
306  return isGenericParametersValid(value);
307  default:
308  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
309  }
310 }
311 
312 
313 std::string
315  return toString(getTag());
316 }
317 
318 
319 std::string
321  return toString(getTag()) + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
322 }
323 
324 // ===========================================================================
325 // private
326 // ===========================================================================
327 
328 void
329 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
330  switch (key) {
331  case SUMO_ATTR_ID:
332  changeAdditionalID(value);
333  myEdge = changeEdge(myEdge, value);
334  break;
335  case SUMO_ATTR_BEGIN:
336  myBegin = parse<double>(value);
337  break;
338  case SUMO_ATTR_END:
339  myEnd = parse<double>(value);
340  break;
341  case SUMO_ATTR_NAME:
342  myAdditionalName = value;
343  break;
344  case GNE_ATTR_SELECTED:
345  if (parse<bool>(value)) {
347  } else {
349  }
350  break;
351  case GNE_ATTR_GENERIC:
353  break;
354  default:
355  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
356  }
357  // After setting attribute always update Geometry
358  updateGeometry(true);
359 }
360 
361 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
double myBegin
begin time of vaporizer
Definition: GNEVaporizer.h:119
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
const GNEAttributeCarrier * getACUnderCursor() const
get AttributeCarrier under cursor
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:915
double scale
information about a lane&#39;s width (temporary, used for a single view)
void setBlockIconRotation(GNELane *additionalLane=nullptr)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
GUIVisualizationTextSettings addName
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
static const RGBColor WHITE
Definition: RGBColor.h:179
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.
double y() const
Returns the y-position.
Definition: Position.h:61
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double x() const
Returns the x-position.
Definition: Position.h:56
weights: time range begin
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNEEdge * myEdge
The edge in which this vaporizer is placed.
Definition: GNEVaporizer.h:116
std::vector< double > myShapeRotations
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
Position getLineCenter() const
get line center
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
static const RGBColor GREEN
Definition: RGBColor.h:173
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:105
a Vaporizer
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void drawLockIcon(double size=0.5) const
draw lock icon
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
PositionVector myShape
The shape of the additional element.
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
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
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1175
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
std::vector< double > myShapeLengths
The lengths of the shape parts.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
std::string getAttribute(SumoXMLAttr key) const
void updateGeometry(bool updateGrid)
update pre-computed geometry information
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Position myBlockIconOffset
The offSet of the block icon.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
Position getPositionInView() const
Returns position of additional in view.
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:679
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:832
double length() const
Returns the length.
GNEEdge * changeEdge(GNEEdge *oldEdge, const std::string &newEdgeID)
change edge of additional
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
static void drawShapeDottedContour(const int type, const PositionVector &shape, const double width)
draw a dotted contour around the given Non closed shape with certain width
Definition: GLHelper.cpp:471
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
double myEnd
end time in which this vaporizer is placed
Definition: GNEVaporizer.h:122
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
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
GUIGlID getGlID() const
Returns the numerical id of the object.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
static const RGBColor selectionColor
Definition: GNENet.h:96
GNEVaporizer(GNEViewNet *viewNet, GNEEdge *edge, double begin, double end, const std::string &name)
Constructor.
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:132
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
~GNEVaporizer()
Destructor.
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1168
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get XML Tag assigned to this object