SUMO - Simulation of Urban MObility
GNEVaporizer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <string>
31 #include <iostream>
32 #include <utility>
38 #include <utils/common/ToString.h>
39 #include <utils/geom/GeomHelper.h>
46 #include <utils/gui/div/GLHelper.h>
50 
51 #include "GNEViewNet.h"
52 #include "GNEVaporizer.h"
53 #include "GNEEdge.h"
54 #include "GNELane.h"
55 #include "GNEViewNet.h"
56 #include "GNEUndoList.h"
57 #include "GNENet.h"
58 #include "GNEChange_Attribute.h"
59 
60 
61 // ===========================================================================
62 // member method definitions
63 // ===========================================================================
64 
65 GNEVaporizer::GNEVaporizer(GNEViewNet* viewNet, GNEEdge* edge, double startTime, double end) :
66  GNEAdditional(viewNet->getNet()->generateVaporizerID(), viewNet, Position(), SUMO_TAG_VAPORIZER, ICON_VAPORIZER),
67  myStartTime(startTime),
68  myEnd(end) {
69  // This additional belongs to a edge
70  myEdge = edge;
71  // this additional ISN'T movable
72  myMovable = false;
73  // Update geometry;
75  // Center view in the position of Vaporizer
76  myViewNet->centerTo(getGlID(), false);
77 }
78 
79 
81 }
82 
83 
84 void
86  // Clear all containers
87  myShapeRotations.clear();
88  myShapeLengths.clear();
89 
90  // clear Shape
91  myShape.clear();
92 
93  // obtain relative position of vaporizer in edge
95 
96  // get lanes of edge
97  GNELane* firstLane = myEdge->getLanes().at(0);
98 
99  // Save number of lanes
100  myNumberOfLanes = int(myEdge->getLanes().size());
101 
102  // Get shape of lane parent
103  myShape.push_back(firstLane->getShape().positionAtOffset(5));
104 
105  // Obtain first position
106  Position f = myShape[0] - Position(1, 0);
107 
108  // Obtain next position
109  Position s = myShape[0] + Position(1, 0);
110 
111  // Save rotation (angle) of the vector constructed by points f and s
112  myShapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(5) * -1);
113 
114  // Set block icon position
116 
117  // Set offset of the block icon
118  myBlockIconOffset = Position(1.1, (-3.06) - myRelativePosition);
119 
120  // Set block icon rotation, and using their rotation for logo
121  setBlockIconRotation(firstLane);
122 
123  // Refresh element (neccesary to avoid grabbing problems)
125 }
126 
127 
128 Position
130  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(myPosition.x());
131  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(myPosition.x());
132 
133  // return Middle point
134  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
135 }
136 
137 
138 void
140  // This additional cannot be moved
141 }
142 
143 
144 void
146  // This additional cannot be moved
147 }
148 
149 
150 void
152  // Write parameters
153  device.openTag(getTag());
154  device.writeAttr(SUMO_ATTR_EDGE, myEdge->getID());
156  device.writeAttr(SUMO_ATTR_END, myEnd);
157  // Close tag
158  device.closeTag();
159 }
160 
161 
162 double
164  return myStartTime;
165 }
166 
167 
168 double
170  return myEnd;
171 }
172 
173 
174 void
175 GNEVaporizer::setStartTime(double startTime) {
176  myStartTime = startTime;
177 }
178 
179 
180 void
182  myEnd = end;
183 }
184 
185 
186 const std::string&
188  return myEdge->getMicrosimID();
189 }
190 
191 
192 void
194  // get values
195  glPushName(getGlID());
196  double width = (double) 2.0 * s.scale;
197  glLineWidth(1.0);
198  const double exaggeration = s.addSize.getExaggeration(s);
199 
200  // draw shape
201  glColor3ub(120, 216, 0);
202  glPushMatrix();
203  glTranslated(0, 0, getType());
204  glTranslated(myShape[0].x(), myShape[0].y(), 0);
205  glRotated(myShapeRotations[0], 0, 0, 1);
206  glScaled(exaggeration, exaggeration, 1);
207  glTranslated(-1.6, -1.6, 0);
208  glBegin(GL_QUADS);
209  glVertex2d(0, 0.25);
210  glVertex2d(0, -0.25);
211  glVertex2d((myNumberOfLanes * 3.3), -0.25);
212  glVertex2d((myNumberOfLanes * 3.3), 0.25);
213  glEnd();
214  glTranslated(0, 0, .01);
215  glBegin(GL_LINES);
216  glVertex2d(0, 0.25 - .1);
217  glVertex2d(0, -0.25 + .1);
218  glEnd();
219 
220  // position indicator (White)
221  if (width * exaggeration > 1) {
222  glRotated(90, 0, 0, -1);
223  glColor3d(1, 1, 1);
224  glBegin(GL_LINES);
225  glVertex2d(0, 0);
226  glVertex2d(0, (myNumberOfLanes * 3.3));
227  glEnd();
228  }
229 
230  // Pop shape matrix
231  glPopMatrix();
232 
233  // Add a draw matrix for drawing logo
234  glPushMatrix();
235  glTranslated(myShape[0].x(), myShape[0].y(), getType());
236  glRotated(myShapeRotations[0], 0, 0, 1);
237  glTranslated((-2.56) - myRelativePosition, (-1.6), 0);
238  glColor3d(1, 1, 1);
239  glRotated(-90, 0, 0, 1);
240 
241  // Draw icon depending of detector is or isn't selected
242  if (isAdditionalSelected()) {
244  } else {
246  }
247 
248  // Pop logo matrix
249  glPopMatrix();
250 
251  // Check if the distance is enought to draw details
252  if (s.scale * exaggeration >= 10) {
253  // Show Lock icon depending of the Edit mode
254  drawLockIcon(0.4);
255  }
256 
257  // Finish draw
258  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
259  glPopName();
260 }
261 
262 
263 std::string
265  switch (key) {
266  case SUMO_ATTR_ID:
267  return getAdditionalID();
268  case SUMO_ATTR_EDGE:
269  return myEdge->getID();
270  case SUMO_ATTR_STARTTIME:
271  return toString(myStartTime);
272  case SUMO_ATTR_END:
273  return toString(myEnd);
274  default:
275  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
276  }
277 }
278 
279 
280 void
281 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
282  if (value == getAttribute(key)) {
283  return; //avoid needless changes, later logic relies on the fact that attributes have changed
284  }
285  switch (key) {
286  case SUMO_ATTR_ID:
287  case SUMO_ATTR_EDGE:
288  case SUMO_ATTR_STARTTIME:
289  case SUMO_ATTR_END:
290  undoList->p_add(new GNEChange_Attribute(this, key, value));
291  updateGeometry();
292  break;
293  default:
294  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
295  }
296 }
297 
298 
299 bool
300 GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
301  switch (key) {
302  case SUMO_ATTR_ID:
303  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
304  return true;
305  } else {
306  return false;
307  }
308  case SUMO_ATTR_EDGE:
309  if (myViewNet->getNet()->retrieveEdge(value, false) != NULL) {
310  return true;
311  } else {
312  return false;
313  }
314  case SUMO_ATTR_STARTTIME:
315  if (canParse<double>(value) && (parse<double>(value) >= 0)) {
316  double startTime = parse<double>(value);
317  if (startTime <= myEnd) {
318  return true;
319  } else {
320  return false;
321  }
322  } else {
323  return false;
324  }
325  case SUMO_ATTR_END:
326  if (canParse<double>(value) && (parse<double>(value) >= 0)) {
327  double end = parse<double>(value);
328  if (myStartTime <= end) {
329  return true;
330  } else {
331  return false;
332  }
333  } else {
334  return false;
335  }
336  default:
337  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
338  }
339 }
340 
341 
342 void
343 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
344  switch (key) {
345  case SUMO_ATTR_ID:
346  setAdditionalID(value);
347  break;
348  case SUMO_ATTR_EDGE:
349  changeEdge(value);
350  break;
351  case SUMO_ATTR_STARTTIME:
352  myStartTime = parse<double>(value);
353  break;
354  case SUMO_ATTR_END:
355  myEnd = parse<double>(value);
356  break;
357  default:
358  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
359  }
360 }
361 
362 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
double myStartTime
start time of vaporizer
Definition: GNEVaporizer.h:133
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:743
double scale
information about a lane&#39;s width (temporary, used for a single view)
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
void setEndTime(double end)
set end
void commmitAdditionalGeometryMoved(double, double, GNEUndoList *)
updated geometry changes in the attributes of additional
GUIVisualizationTextSettings addName
void setStartTime(double startTime)
set start time
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
double x() const
Returns the x-position.
Definition: Position.h:63
Stores the information about how to visualize structures.
bool isAdditionalSelected() const
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
std::vector< double > myShapeRotations
GUIGlID getGlID() const
Returns the numerical id of the object.
std::string getAttribute(SumoXMLAttr key) const
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void changeEdge(const std::string &edgeID)
change edge of additional
bool myMovable
boolean to check if additional element is movable (with the mouse). By default true ...
const std::string & getAdditionalID() const
returns the ID of additional
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:825
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:46
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
void setBlockIconRotation(GNELane *lane=NULL)
set Rotation of block Icon
friend class GNEChange_Attribute
declare friend class
virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist=20)
centers to the chosen artifact
double y() const
Returns the y-position.
Definition: Position.h:68
int getVaporizerRelativePosition(GNEVaporizer *vaporizer) const
obtain relative positions of Vaporizer
Definition: GNEEdge.cpp:493
std::vector< double > myShapeLengths
The lengths of the shape parts.
void setAdditionalID(const std::string &id)
set the ID of additional
const std::string getID() const
function to support debugging
void drawLockIcon(double size=0.5) const
draw lock icon
Position myBlockIconOffset
The offSet of the block icon.
Position getPositionInView() const
Returns position of Vaporizer in view.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:57
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1331
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:621
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:543
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:62
double myEnd
end time in which this vaporizer is placed
Definition: GNEVaporizer.h:136
weights: time range end
GNENet * getNet() const
get the net object
vaporizer of vehicles
Position getLineCenter() const
get line center
double getEnd() const
get end
SumoXMLTag getTag() const
get XML Tag assigned to this object
int myRelativePosition
relative position regarding to other route probes
Definition: GNEVaporizer.h:142
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
Position myPosition
The position in which this additional element is located.
bool closeTag()
Closes the most recently opened tag.
GNEVaporizer(GNEViewNet *viewNet, GNEEdge *edge, double startTime, double end)
Constructor.
void moveAdditionalGeometry(double, double)
change the position of the RouteProbe geometry
int myNumberOfLanes
number of lanes of edge (To improve efficiency)
Definition: GNEVaporizer.h:139
GNEEdge * myEdge
The edge this additional belongs.
double getStartTime() const
get start time
~GNEVaporizer()
Destructor.
void updateGeometry()
update pre-computed geometry information
const std::string & getParentName() const
Returns the name of the parent object (if any)
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Position myBlockIconPosition
position of the block icon
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.