SUMO - Simulation of Urban MObility
GNEVaporizer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 //
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, SUMO_TAG_VAPORIZER, ICON_VAPORIZER),
67  myStartTime(startTime),
68  myEnd(end),
69  myRelativePositionY(0) {
70  // This additional belongs to a edge
71  myEdge = edge;
72  // this additional ISN'T movable
73  myMovable = false;
74  // Update geometry;
76  // Center view in the position of Vaporizer
77  myViewNet->centerTo(getGlID(), false);
78 }
79 
80 
82 }
83 
84 
85 void
87  // Clear all containers
88  myShapeRotations.clear();
89  myShapeLengths.clear();
90 
91  // clear Shape
92  myShape.clear();
93 
94  // obtain relative position of vaporizer in edge
96 
97  // get lanes of edge
98  GNELane* firstLane = myEdge->getLanes().at(0);
99 
100  // Save number of lanes
101  myNumberOfLanes = int(myEdge->getLanes().size());
102 
103  // Get shape of lane parent
104  double offset = firstLane->getShape().length() < 2.5 ? firstLane->getShape().length() : 2.5;
105  myShape.push_back(firstLane->getShape().positionAtOffset(offset));
106 
107  // Obtain first position
108  Position f = myShape[0] - Position(1, 0);
109 
110  // Obtain next position
111  Position s = myShape[0] + Position(1, 0);
112 
113  // Save rotation (angle) of the vector constructed by points f and s
114  myShapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(offset) * -1);
115 
116  // Set block icon position
118 
119  // Set offset of the block icon
120  myBlockIconOffset = Position(1.1, (-3.06) - myRelativePositionY);
121 
122  // Set block icon rotation, and using their rotation for logo
124 
125  // Refresh element (neccesary to avoid grabbing problems)
127 }
128 
129 
130 Position
132  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(5);
133  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(5);
134 
135  // return Middle point
136  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
137 }
138 
139 
140 void
142  // This additional cannot be moved
143 }
144 
145 
146 void
148  // This additional cannot be moved
149 }
150 
151 
152 void
153 GNEVaporizer::writeAdditional(OutputDevice& device, bool /*volatileOptionsEnabled*/) const {
154  // Write parameters
155  device.openTag(getTag());
156  device.writeAttr(SUMO_ATTR_EDGE, myEdge->getID());
158  device.writeAttr(SUMO_ATTR_END, myEnd);
159  // Close tag
160  device.closeTag();
161 }
162 
163 
164 double
166  return myStartTime;
167 }
168 
169 
170 double
172  return myEnd;
173 }
174 
175 
176 void
177 GNEVaporizer::setStartTime(double startTime) {
178  myStartTime = startTime;
179 }
180 
181 
182 void
184  myEnd = end;
185 }
186 
187 
188 const std::string&
190  return myEdge->getMicrosimID();
191 }
192 
193 
194 void
196  // get values
197  glPushName(getGlID());
198  double width = (double) 2.0 * s.scale;
199  glLineWidth(1.0);
200  const double exaggeration = s.addSize.getExaggeration(s);
201 
202  // set color
203  if (isAdditionalSelected()) {
205  } else {
206  GLHelper::setColor(RGBColor(120, 216, 0));
207  }
208  // draw shape
209  glPushMatrix();
210  glTranslated(0, 0, getType());
211  glTranslated(myShape[0].x(), myShape[0].y(), 0);
212  glRotated(myShapeRotations[0], 0, 0, 1);
213  glScaled(exaggeration, exaggeration, 1);
214  glTranslated(-1.6, -1.6, 0);
215  glBegin(GL_QUADS);
216  glVertex2d(0, 0.25);
217  glVertex2d(0, -0.25);
218  glVertex2d((myNumberOfLanes * 3.3), -0.25);
219  glVertex2d((myNumberOfLanes * 3.3), 0.25);
220  glEnd();
221  glTranslated(0, 0, .01);
222  glBegin(GL_LINES);
223  glVertex2d(0, 0.25 - .1);
224  glVertex2d(0, -0.25 + .1);
225  glEnd();
226 
227  // position indicator (White)
228  if (width * exaggeration > 1) {
229  if (isAdditionalSelected()) {
231  } else {
233  }
234  glRotated(90, 0, 0, -1);
235  glBegin(GL_LINES);
236  glVertex2d(0, 0);
237  glVertex2d(0, (myNumberOfLanes * 3.3));
238  glEnd();
239  }
240 
241  // Pop shape matrix
242  glPopMatrix();
243 
244  // Add a draw matrix for drawing logo
245  glPushMatrix();
246  glTranslated(myShape[0].x(), myShape[0].y(), getType());
247  glRotated(myShapeRotations[0], 0, 0, 1);
248  glTranslated((-2.56) - myRelativePositionY, (-1.6), 0);
249  glColor3d(1, 1, 1);
250  glRotated(-90, 0, 0, 1);
251 
252  // Draw icon depending of detector is or isn't selected
253  if (isAdditionalSelected()) {
255  } else {
257  }
258 
259  // Pop logo matrix
260  glPopMatrix();
261 
262  // Check if the distance is enought to draw details
263  if (s.scale * exaggeration >= 10) {
264  // Show Lock icon depending of the Edit mode
265  drawLockIcon(0.4);
266  }
267 
268  // Finish draw
269  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
270  glPopName();
271 }
272 
273 
274 std::string
276  switch (key) {
277  case SUMO_ATTR_ID:
278  return getAdditionalID();
279  case SUMO_ATTR_EDGE:
280  return myEdge->getID();
281  case SUMO_ATTR_STARTTIME:
282  return toString(myStartTime);
283  case SUMO_ATTR_END:
284  return toString(myEnd);
285  default:
286  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
287  }
288 }
289 
290 
291 void
292 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
293  if (value == getAttribute(key)) {
294  return; //avoid needless changes, later logic relies on the fact that attributes have changed
295  }
296  switch (key) {
297  case SUMO_ATTR_ID:
298  case SUMO_ATTR_EDGE:
299  case SUMO_ATTR_STARTTIME:
300  case SUMO_ATTR_END:
301  undoList->p_add(new GNEChange_Attribute(this, key, value));
302  updateGeometry();
303  break;
304  default:
305  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
306  }
307 }
308 
309 
310 bool
311 GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
312  switch (key) {
313  case SUMO_ATTR_ID:
314  if (isValidID(value) && (myViewNet->getNet()->getAdditional(getTag(), value) == NULL)) {
315  return true;
316  } else {
317  return false;
318  }
319  case SUMO_ATTR_EDGE:
320  if (myViewNet->getNet()->retrieveEdge(value, false) != NULL) {
321  return true;
322  } else {
323  return false;
324  }
325  case SUMO_ATTR_STARTTIME:
326  if (canParse<double>(value) && (parse<double>(value) >= 0)) {
327  double startTime = parse<double>(value);
328  if (startTime <= myEnd) {
329  return true;
330  } else {
331  return false;
332  }
333  } else {
334  return false;
335  }
336  case SUMO_ATTR_END:
337  if (canParse<double>(value) && (parse<double>(value) >= 0)) {
338  double end = parse<double>(value);
339  if (myStartTime <= end) {
340  return true;
341  } else {
342  return false;
343  }
344  } else {
345  return false;
346  }
347  default:
348  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
349  }
350 }
351 
352 
353 void
354 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
355  switch (key) {
356  case SUMO_ATTR_ID:
357  setAdditionalID(value);
358  break;
359  case SUMO_ATTR_EDGE:
360  changeEdge(value);
361  break;
362  case SUMO_ATTR_STARTTIME:
363  myStartTime = parse<double>(value);
364  break;
365  case SUMO_ATTR_END:
366  myEnd = parse<double>(value);
367  break;
368  default:
369  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
370  }
371 }
372 
373 /****************************************************************************/
void writeAdditional(OutputDevice &device, bool volatileOptionsEnabled) const
writte additional element into a xml file
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:143
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:261
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
void setBlockIconRotation()
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:899
double scale
information about a lane&#39;s width (temporary, used for a single view)
int myRelativePositionY
relative position regarding to other route probes
Definition: GNEVaporizer.h:152
void setEndTime(double end)
set end
GUIVisualizationTextSettings addName
void setStartTime(double startTime)
set start time
static const RGBColor WHITE
Definition: RGBColor.h:186
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
This functions has to be implemented in allGNEAttributeCarrier.
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
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:112
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
void moveGeometry(const Position &newPosition)
change the position of the element geometry without saving in undoList
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:438
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:998
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.
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:532
double length() const
Returns the length.
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 additional in view.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:58
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1680
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:625
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:599
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:146
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
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
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
GNEVaporizer(GNEViewNet *viewNet, GNEEdge *edge, double startTime, double end)
Constructor.
static const RGBColor selectionColor
Definition: GNENet.h:103
int myNumberOfLanes
number of lanes of edge (To improve efficiency)
Definition: GNEVaporizer.h:149
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.