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 }
80 
81 
83  if (myEdge) {
84  myEdge->removeAdditional(this);
85  }
86 }
87 
88 
89 void
91  // Clear all containers
92  myShapeRotations.clear();
93  myShapeLengths.clear();
94 
95  // clear Shape
96  myShape.clear();
97 
98  // get lanes of edge
99  GNELane* firstLane = myEdge->getLanes().at(0);
100 
101  // Get shape of lane parent
102  myShape.push_back(firstLane->getShape().positionAtOffset(3));
103 
104  // Obtain first position
105  Position f = myShape[0] - Position(1, 0);
106 
107  // Obtain next position
108  Position s = myShape[0] + Position(1, 0);
109 
110  // Save rotation (angle) of the vector constructed by points f and s
111  myShapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(5) * -1);
112 
113  // Set block icon position
115 
116  // Set offset of the block icon
117  myBlockIconOffset = Position(1.1, -3.06);
118 
119  // Set block icon rotation, and using their rotation for logo
120  setBlockIconRotation(firstLane);
121 }
122 
123 
124 Position
126  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(myPosition.x());
127  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(myPosition.x());
128 
129  // return Middle point
130  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
131 }
132 
133 
134 void
136  // This additional cannot be moved
137 }
138 
139 
140 void
141 GNEVaporizer::writeAdditional(OutputDevice& device, const std::string&) {
142  // Write parameters
143  device.openTag(getTag());
144  device.writeAttr(SUMO_ATTR_ID, getID());
145  device.writeAttr(SUMO_ATTR_EDGE, myEdge->getID());
147  device.writeAttr(SUMO_ATTR_END, myEnd);
148  // Close tag
149  device.closeTag();
150 }
151 
152 
153 GNEEdge*
155  return myEdge;
156 }
157 
158 
159 void
161  myEdge = NULL;
162 }
163 
164 
165 SUMOTime
167  return myStartTime;
168 }
169 
170 
171 SUMOTime
173  return myEnd;
174 }
175 
176 
177 void
179  myStartTime = startTime;
180 }
181 
182 
183 void
185  myEnd = end;
186 }
187 
188 
189 const std::string&
191  return myEdge->getMicrosimID();
192 }
193 
194 
195 void
197  // get values
198  glPushName(getGlID());
199  glLineWidth(1.0);
200 
201  // Declare auxiliar values
202  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
203  int numberOfLanes = int(myEdge->getLanes().size());
204  SUMOReal width = (SUMOReal) 2.0 * s.scale;
205 
206  // draw shape
207  glColor3ub(120, 216, 0);
208  glPushMatrix();
209  glTranslated(0, 0, getType());
210  glTranslated(myShape[0].x(), myShape[0].y(), 0);
211  glRotated(myShapeRotations[0], 0, 0, 1);
212  glScaled(exaggeration, exaggeration, 1);
213  glTranslated(-1.6, -1.6, 0);
214  glBegin(GL_QUADS);
215  glVertex2d(0, 0.25);
216  glVertex2d(0, -0.25);
217  glVertex2d((numberOfLanes * 3.3), -0.25);
218  glVertex2d((numberOfLanes * 3.3), 0.25);
219  glEnd();
220  glTranslated(0, 0, .01);
221  glBegin(GL_LINES);
222  glVertex2d(0, 0.25 - .1);
223  glVertex2d(0, -0.25 + .1);
224  glEnd();
225 
226  // position indicator (White)
227  if (width * exaggeration > 1) {
228  glRotated(90, 0, 0, -1);
229  glColor3d(1, 1, 1);
230  glBegin(GL_LINES);
231  glVertex2d(0, 0);
232  glVertex2d(0, (numberOfLanes * 3.3));
233  glEnd();
234  }
235 
236  // Pop shape matrix
237  glPopMatrix();
238 
239  // Add a draw matrix for drawing logo
240  glPushMatrix();
241  glTranslated(myShape[0].x(), myShape[0].y(), getType());
242  glRotated(myShapeRotations[0], 0, 0, 1);
243  glTranslated(-2.56, - 1.6, 0);
244  glColor3d(1, 1, 1);
245  glRotated(-90, 0, 0, 1);
246 
247  // Draw icon depending of detector is or isn't selected
248  if (isAdditionalSelected()) {
250  } else {
252  }
253 
254  // Pop logo matrix
255  glPopMatrix();
256 
257  // Check if the distance is enought to draw details
258  if (s.scale * exaggeration >= 10) {
259  // Show Lock icon depending of the Edit mode
260  drawLockIcon(0.4);
261  }
262 
263  // Finish draw
264  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
265  glPopName();
266 }
267 
268 
269 std::string
271  switch (key) {
272  case SUMO_ATTR_ID:
273  return getAdditionalID();
274  case SUMO_ATTR_EDGE:
275  return myEdge->getID();
276  case SUMO_ATTR_STARTTIME:
277  return toString(myStartTime);
278  case SUMO_ATTR_END:
279  return toString(myEnd);
280  default:
281  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
282  }
283 }
284 
285 
286 void
287 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
288  if (value == getAttribute(key)) {
289  return; //avoid needless changes, later logic relies on the fact that attributes have changed
290  }
291  switch (key) {
292  case SUMO_ATTR_ID:
293  case SUMO_ATTR_EDGE:
294  case SUMO_ATTR_STARTTIME:
295  case SUMO_ATTR_END:
296  undoList->p_add(new GNEChange_Attribute(this, key, value));
297  updateGeometry();
298  break;
299  default:
300  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
301  }
302 }
303 
304 
305 bool
306 GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
307  switch (key) {
308  case SUMO_ATTR_ID:
309  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
310  return true;
311  } else {
312  return false;
313  }
314  case SUMO_ATTR_EDGE:
315  if (myViewNet->getNet()->retrieveEdge(value, false) != NULL) {
316  return true;
317  } else {
318  return false;
319  }
320  case SUMO_ATTR_STARTTIME:
321  return canParse<int>(value);
322  case SUMO_ATTR_END:
323  return canParse<int>(value);
324  default:
325  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
326  }
327 }
328 
329 
330 void
331 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
332  switch (key) {
333  case SUMO_ATTR_ID:
334  setAdditionalID(value);
335  break;
336  case SUMO_ATTR_EDGE:
337  myEdge->removeAdditional(this);
338  myEdge = myViewNet->getNet()->retrieveEdge(value);
339  myEdge->addAdditional(this);
340  updateGeometry();
341  getViewNet()->update();
342  break;
343  case SUMO_ATTR_STARTTIME:
344  myStartTime = parse<int>(value);
345  break;
346  case SUMO_ATTR_END:
347  myEnd = parse<int>(value);
348  break;
349  default:
350  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
351  }
352 }
353 
354 /****************************************************************************/
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
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:822
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:836
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.
static void drawTexturedBox(unsigned int which, SUMOReal size)
Draws a named texture as a box with the given size.
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:434
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:214
void removeEdgeReference()
remove reference to edge
static GUIGlID getGif(GUITexture which)
returns a texture Gif previously defined in the enum GUITexture
~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.