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  myStartTime(startTime),
71  myEnd(end) {
72  // This additional belongs to a edge
73  myEdge = edge;
74  // this additional ISN'T movable
75  myMovable = false;
76  // Update geometry;
78  // Center view in the position of Vaporizer
79  myViewNet->centerTo(getGlID(), false);
80 }
81 
82 
84 }
85 
86 
87 void
89  // Clear all containers
90  myShapeRotations.clear();
91  myShapeLengths.clear();
92 
93  // clear Shape
94  myShape.clear();
95 
96  // get lanes of edge
97  GNELane* firstLane = myEdge->getLanes().at(0);
98 
99  // Get shape of lane parent
100  myShape.push_back(firstLane->getShape().positionAtOffset(3));
101 
102  // Obtain first position
103  Position f = myShape[0] - Position(1, 0);
104 
105  // Obtain next position
106  Position s = myShape[0] + Position(1, 0);
107 
108  // Save rotation (angle) of the vector constructed by points f and s
109  myShapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(5) * -1);
110 
111  // Set block icon position
113 
114  // Set offset of the block icon
115  myBlockIconOffset = Position(1.1, -3.06);
116 
117  // Set block icon rotation, and using their rotation for logo
118  setBlockIconRotation(firstLane);
119 
120  // Refresh element (neccesary to avoid grabbing problems)
122 }
123 
124 
125 Position
127  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(myPosition.x());
128  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(myPosition.x());
129 
130  // return Middle point
131  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
132 }
133 
134 
135 void
137  // This additional cannot be moved
138 }
139 
140 
141 void
143  // This additional cannot be moved
144 }
145 
146 
147 void
148 GNEVaporizer::writeAdditional(OutputDevice& device, const std::string&) {
149  // Write parameters
150  device.openTag(getTag());
151  device.writeAttr(SUMO_ATTR_ID, getID());
152  device.writeAttr(SUMO_ATTR_EDGE, myEdge->getID());
154  device.writeAttr(SUMO_ATTR_END, myEnd);
155  // Close tag
156  device.closeTag();
157 }
158 
159 
160 SUMOTime
162  return myStartTime;
163 }
164 
165 
166 SUMOTime
168  return myEnd;
169 }
170 
171 
172 void
174  myStartTime = startTime;
175 }
176 
177 
178 void
180  myEnd = end;
181 }
182 
183 
184 const std::string&
186  return myEdge->getMicrosimID();
187 }
188 
189 
190 void
192  // get values
193  glPushName(getGlID());
194  glLineWidth(1.0);
195 
196  // Declare auxiliar values
197  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
198  int numberOfLanes = int(myEdge->getLanes().size());
199  SUMOReal width = (SUMOReal) 2.0 * s.scale;
200 
201  // draw shape
202  glColor3ub(120, 216, 0);
203  glPushMatrix();
204  glTranslated(0, 0, getType());
205  glTranslated(myShape[0].x(), myShape[0].y(), 0);
206  glRotated(myShapeRotations[0], 0, 0, 1);
207  glScaled(exaggeration, exaggeration, 1);
208  glTranslated(-1.6, -1.6, 0);
209  glBegin(GL_QUADS);
210  glVertex2d(0, 0.25);
211  glVertex2d(0, -0.25);
212  glVertex2d((numberOfLanes * 3.3), -0.25);
213  glVertex2d((numberOfLanes * 3.3), 0.25);
214  glEnd();
215  glTranslated(0, 0, .01);
216  glBegin(GL_LINES);
217  glVertex2d(0, 0.25 - .1);
218  glVertex2d(0, -0.25 + .1);
219  glEnd();
220 
221  // position indicator (White)
222  if (width * exaggeration > 1) {
223  glRotated(90, 0, 0, -1);
224  glColor3d(1, 1, 1);
225  glBegin(GL_LINES);
226  glVertex2d(0, 0);
227  glVertex2d(0, (numberOfLanes * 3.3));
228  glEnd();
229  }
230 
231  // Pop shape matrix
232  glPopMatrix();
233 
234  // Add a draw matrix for drawing logo
235  glPushMatrix();
236  glTranslated(myShape[0].x(), myShape[0].y(), getType());
237  glRotated(myShapeRotations[0], 0, 0, 1);
238  glTranslated(-2.56, - 1.6, 0);
239  glColor3d(1, 1, 1);
240  glRotated(-90, 0, 0, 1);
241 
242  // Draw icon depending of detector is or isn't selected
243  if (isAdditionalSelected()) {
245  } else {
247  }
248 
249  // Pop logo matrix
250  glPopMatrix();
251 
252  // Check if the distance is enought to draw details
253  if (s.scale * exaggeration >= 10) {
254  // Show Lock icon depending of the Edit mode
255  drawLockIcon(0.4);
256  }
257 
258  // Finish draw
259  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
260  glPopName();
261 }
262 
263 
264 std::string
266  switch (key) {
267  case SUMO_ATTR_ID:
268  return getAdditionalID();
269  case SUMO_ATTR_EDGE:
270  return myEdge->getID();
271  case SUMO_ATTR_STARTTIME:
272  return toString(myStartTime);
273  case SUMO_ATTR_END:
274  return toString(myEnd);
275  default:
276  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
277  }
278 }
279 
280 
281 void
282 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
283  if (value == getAttribute(key)) {
284  return; //avoid needless changes, later logic relies on the fact that attributes have changed
285  }
286  switch (key) {
287  case SUMO_ATTR_ID:
288  case SUMO_ATTR_EDGE:
289  case SUMO_ATTR_STARTTIME:
290  case SUMO_ATTR_END:
291  undoList->p_add(new GNEChange_Attribute(this, key, value));
292  updateGeometry();
293  break;
294  default:
295  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
296  }
297 }
298 
299 
300 bool
301 GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
302  switch (key) {
303  case SUMO_ATTR_ID:
304  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
305  return true;
306  } else {
307  return false;
308  }
309  case SUMO_ATTR_EDGE:
310  if (myViewNet->getNet()->retrieveEdge(value, false) != NULL) {
311  return true;
312  } else {
313  return false;
314  }
315  case SUMO_ATTR_STARTTIME:
316  return canParse<int>(value);
317  case SUMO_ATTR_END:
318  return canParse<int>(value);
319  default:
320  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
321  }
322 }
323 
324 
325 void
326 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
327  switch (key) {
328  case SUMO_ATTR_ID:
329  setAdditionalID(value);
330  break;
331  case SUMO_ATTR_EDGE:
332  changeEdge(value);
333  break;
334  case SUMO_ATTR_STARTTIME:
335  myStartTime = parse<int>(value);
336  break;
337  case SUMO_ATTR_END:
338  myEnd = parse<int>(value);
339  break;
340  default:
341  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
342  }
343 }
344 
345 /****************************************************************************/
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
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:702
long long int SUMOTime
Definition: SUMOTime.h:43
void setStartTime(SUMOTime startTime)
set start time
void commmitAdditionalGeometryMoved(SUMOReal, SUMOReal, GNEUndoList *)
updated geometry changes in the attributes of additional
void moveAdditionalGeometry(SUMOReal, SUMOReal)
change the position of the RouteProbe geometry
GUIVisualizationTextSettings addName
void setEndTime(SUMOTime end)
set end
virtual void centerTo(GUIGlID id, bool applyZoom, SUMOReal zoomDist=20)
centers to the chosen artifact
const std::string & getAdditionalID() const
returns the ID of additional
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1250
Stores the information about how to visualize structures.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:55
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
SUMOTime myEnd
end time in which this vaporizer is placed
Definition: GNEVaporizer.h:138
Position getLineCenter() const
get line center
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
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.
SUMOTime myStartTime
start time of vaporizer
Definition: GNEVaporizer.h:135
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.
void changeEdge(const std::string &edgeID)
change edge of additional
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 & getParentName() const
Returns the name of the parent object (if any)
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:784
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
void setBlockIconRotation(GNELane *lane=NULL)
friend class GNEChange_Attribute
declare friend class
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
void drawLockIcon(SUMOReal size=0.5) const
draw lock icon
void setAdditionalID(const std::string &id)
set the ID of additional
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
const std::string getID() const
function to support debugging
std::string getAttribute(SumoXMLAttr key) const
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
Position myBlockIconOffset
The offSet of the block icon.
SUMOTime getStartTime() const
get start time
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:55
GNEVaporizer(const std::string &id, GNEViewNet *viewNet, GNEEdge *edge, SUMOTime startTime, SUMOTime end, bool blocked)
Constructor.
Position getPositionInView() const
Returns position of Vaporizer in view.
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:583
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:485
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:63
std::vector< SUMOReal > myShapeRotations
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:912
void writeAdditional(OutputDevice &device, const std::string &)
writte additional element into a xml file
GUIGlID getGlID() const
Returns the numerical id of the object.
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
SUMOReal getExaggeration(const GUIVisualizationSettings &s, SUMOReal factor=20) const
return the drawing size including exaggeration and constantSize values
bool isAdditionalSelected() const
GNEEdge * myEdge
The edge this additional belongs NULL if additional doesnt&#39; belongs to a edge.
static GUIGlID getGif(GUITexture which)
returns a texture Gif previously defined in the enum GUITexture
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
~GNEVaporizer()
Destructor.
SUMOTime getEnd() const
get end
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
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get Tag assigned to this object