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-sim.org/
10 // Copyright (C) 2001-2013 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 #ifdef CHECK_MEMORY_LEAKS
61 #include <foreign/nvwa/debug_new.h>
62 #endif
63 
64 // ===========================================================================
65 // member method definitions
66 // ===========================================================================
67 
68 GNEVaporizer::GNEVaporizer(const std::string& id, GNEViewNet* viewNet, GNEEdge* edge, SUMOTime startTime, SUMOTime end, bool blocked) :
69  GNEAdditional(id, viewNet, Position(), SUMO_TAG_VAPORIZER, NULL, blocked),
70  myEdge(edge),
71  myStartTime(startTime),
72  myEnd(end) {
73  // this additional ISN'T movable
74  myMovable = false;
75  // Add additional to edge parent
76  myEdge->addAdditional(this);
77  // Update geometry;
79  // Center view in the position of Vaporizer
80  myViewNet->centerTo(getGlID(), false);
81 }
82 
83 
85  if (myEdge) {
86  myEdge->removeAdditional(this);
87  }
88 }
89 
90 
91 void
93  // Clear all containers
94  myShapeRotations.clear();
95  myShapeLengths.clear();
96 
97  // clear Shape
98  myShape.clear();
99 
100  // get lanes of edge
101  GNELane* firstLane = myEdge->getLanes().at(0);
102 
103  // Get shape of lane parent
104  myShape.push_back(firstLane->getShape().positionAtOffset(3));
105 
106  // Obtain first position
107  Position f = myShape[0] - Position(1, 0);
108 
109  // Obtain next position
110  Position s = myShape[0] + Position(1, 0);
111 
112  // Save rotation (angle) of the vector constructed by points f and s
113  myShapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(5) * -1);
114 
115  // Set block icon position
117 
118  // Set offset of the block icon
119  myBlockIconOffset = Position(1.1, -3.06);
120 
121  // Set block icon rotation, and using their rotation for logo
122  setBlockIconRotation(firstLane);
123 }
124 
125 
126 Position
128  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(myPosition.x());
129  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(myPosition.x());
130 
131  // return Middle point
132  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
133 }
134 
135 
136 void
138  // This additional cannot be moved
139 }
140 
141 
142 void
143 GNEVaporizer::writeAdditional(OutputDevice& device, const std::string&) {
144  // Write parameters
145  device.openTag(getTag());
146  device.writeAttr(SUMO_ATTR_ID, getID());
147  device.writeAttr(SUMO_ATTR_EDGE, myEdge->getID());
149  device.writeAttr(SUMO_ATTR_END, myEnd);
150  // Close tag
151  device.closeTag();
152 }
153 
154 
155 GNEEdge*
157  return myEdge;
158 }
159 
160 
161 void
163  myEdge = NULL;
164 }
165 
166 
167 SUMOTime
169  return myStartTime;
170 }
171 
172 
173 SUMOTime
175  return myEnd;
176 }
177 
178 
179 void
181  myStartTime = startTime;
182 }
183 
184 
185 void
187  myEnd = end;
188 }
189 
190 
191 const std::string&
193  return myEdge->getMicrosimID();
194 }
195 
196 
197 void
199  // get values
200  glPushName(getGlID());
201  glLineWidth(1.0);
202 
203  // Declare auxiliar values
204  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
205  int numberOfLanes = int(myEdge->getLanes().size());
206  SUMOReal width = (SUMOReal) 2.0 * s.scale;
207 
208  // draw shape
209  glColor3ub(120, 216, 0);
210  glPushMatrix();
211  glTranslated(0, 0, getType());
212  glTranslated(myShape[0].x(), myShape[0].y(), 0);
213  glRotated(myShapeRotations[0], 0, 0, 1);
214  glScaled(exaggeration, exaggeration, 1);
215  glTranslated(-1.6, -1.6, 0);
216  glBegin(GL_QUADS);
217  glVertex2d(0, 0.25);
218  glVertex2d(0, -0.25);
219  glVertex2d((numberOfLanes * 3.3), -0.25);
220  glVertex2d((numberOfLanes * 3.3), 0.25);
221  glEnd();
222  glTranslated(0, 0, .01);
223  glBegin(GL_LINES);
224  glVertex2d(0, 0.25 - .1);
225  glVertex2d(0, -0.25 + .1);
226  glEnd();
227 
228  // position indicator (White)
229  if (width * exaggeration > 1) {
230  glRotated(90, 0, 0, -1);
231  glColor3d(1, 1, 1);
232  glBegin(GL_LINES);
233  glVertex2d(0, 0);
234  glVertex2d(0, (numberOfLanes * 3.3));
235  glEnd();
236  }
237 
238  // Pop shape matrix
239  glPopMatrix();
240 
241  // Add a draw matrix for drawing logo
242  glPushMatrix();
243  glTranslated(myShape[0].x(), myShape[0].y(), getType());
244  glRotated(myShapeRotations[0], 0, 0, 1);
245  glTranslated(-2.56, - 1.6, 0);
246  glColor3d(1, 1, 1);
247  glRotated(-90, 0, 0, 1);
248 
249  // Draw icon depending of detector is or isn't selected
250  if (isAdditionalSelected()) {
252  } else {
254  }
255 
256  // Pop logo matrix
257  glPopMatrix();
258 
259  // Check if the distance is enought to draw details
260  if (s.scale * exaggeration >= 10) {
261  // Show Lock icon depending of the Edit mode
262  drawLockIcon(0.4);
263  }
264 
265  // Finish draw
266  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
267  glPopName();
268 }
269 
270 
271 std::string
273  switch (key) {
274  case SUMO_ATTR_ID:
275  return getAdditionalID();
276  case SUMO_ATTR_EDGE:
277  return myEdge->getID();
278  case SUMO_ATTR_STARTTIME:
279  return toString(myStartTime);
280  case SUMO_ATTR_END:
281  return toString(myEnd);
282  default:
283  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
284  }
285 }
286 
287 
288 void
289 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
290  if (value == getAttribute(key)) {
291  return; //avoid needless changes, later logic relies on the fact that attributes have changed
292  }
293  switch (key) {
294  case SUMO_ATTR_ID:
295  case SUMO_ATTR_EDGE:
296  case SUMO_ATTR_STARTTIME:
297  case SUMO_ATTR_END:
298  undoList->p_add(new GNEChange_Attribute(this, key, value));
299  updateGeometry();
300  break;
301  default:
302  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
303  }
304 }
305 
306 
307 bool
308 GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
309  switch (key) {
310  case SUMO_ATTR_ID:
311  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
312  return true;
313  } else {
314  return false;
315  }
316  case SUMO_ATTR_EDGE:
317  if (myViewNet->getNet()->retrieveEdge(value, false) != NULL) {
318  return true;
319  } else {
320  return false;
321  }
322  case SUMO_ATTR_STARTTIME:
323  return canParse<int>(value);
324  case SUMO_ATTR_END:
325  return canParse<int>(value);
326  default:
327  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
328  }
329 }
330 
331 
332 void
333 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
334  switch (key) {
335  case SUMO_ATTR_ID:
336  setAdditionalID(value);
337  break;
338  case SUMO_ATTR_EDGE:
339  myEdge->removeAdditional(this);
340  myEdge = myViewNet->getNet()->retrieveEdge(value);
341  myEdge->addAdditional(this);
342  updateGeometry();
343  getViewNet()->update();
344  break;
345  case SUMO_ATTR_STARTTIME:
346  myStartTime = parse<int>(value);
347  break;
348  case SUMO_ATTR_END:
349  myEnd = parse<int>(value);
350  break;
351  default:
352  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
353  }
354 }
355 
356 /****************************************************************************/
SUMOReal getExaggeration(const GUIVisualizationSettings &s, SUMOReal factor=20) const
return the drawing size including exaggeration and constantSize values
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:257
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:616
long long int SUMOTime
Definition: SUMOTime.h:43
void setStartTime(SUMOTime startTime)
set start time
GUIVisualizationTextSettings addName
void setEndTime(SUMOTime end)
set end
virtual void centerTo(GUIGlID id, bool applyZoom, SUMOReal zoomDist=20)
centers to the chosen artifact
GNEEdge * getEdge() const
get edge in which the RouteProbe is placed
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.
SUMOTime myEnd
end time in which this vaporizer is placed
Definition: GNEVaporizer.h:141
GNEEdge * myEdge
edge in which this vaporizer is placed
Definition: GNEVaporizer.h:135
bool addAdditional(GNEAdditional *additional)
add additional to this edge
Definition: GNEEdge.cpp:821
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
GUIGlID getGlID() const
Returns the numerical id of the object.
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
bool removeAdditional(GNEAdditional *additional)
remove additional from this edge
Definition: GNEEdge.cpp:835
std::string getAttribute(SumoXMLAttr key) const
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
SUMOTime myStartTime
start time of vaporizer
Definition: GNEVaporizer.h:138
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.
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
std::vector< SUMOReal > myShapeLengths
The lengths of the shape parts.
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
PositionVector myShape
The shape of the additional element.
bool isValid(SumoXMLAttr key, const std::string &value)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
void setBlockIconRotation(GNELane *lane=NULL)
friend class GNEChange_Attribute
declare friend class
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
void drawLockIcon(SUMOReal size=0.5) const
draw lock icon
void setAdditionalID(const std::string &id)
set the ID of additional
const std::string getID() const
function to support debugging
void moveAdditional(SUMOReal, SUMOReal, GNEUndoList *)
change the position of the RouteProbe geometry
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
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:54
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1093
GNEVaporizer(const std::string &id, GNEViewNet *viewNet, GNEEdge *edge, SUMOTime startTime, SUMOTime end, bool blocked)
Constructor.
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:456
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:424
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:63
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
std::vector< SUMOReal > myShapeRotations
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:845
SUMOTime getEnd() const
get end
Position getLineCenter() const
get line center
void writeAdditional(OutputDevice &device, const std::string &)
writte additional element into a xml file
SumoXMLTag getTag() const
get Tag assigned to this object
SUMOTime getStartTime() const
get start time
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.
#define SUMOReal
Definition: config.h:213
void removeEdgeReference()
remove reference to edge
static GUIGlID getGif(GUITexture which)
returns a texture Gif previously defined in the enum GUITexture
~GNEVaporizer()
Destructor.
static void drawTexturedBox(int which, SUMOReal size)
Draws a named texture as a box with the given size.
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.