SUMO - Simulation of Urban MObility
GNEVaporizer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 //
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <string>
30 #include <iostream>
31 #include <utility>
36 #include <utils/common/ToString.h>
37 #include <utils/geom/GeomHelper.h>
43 #include <utils/gui/div/GLHelper.h>
47 
48 #include "GNEViewNet.h"
49 #include "GNEVaporizer.h"
50 #include "GNEEdge.h"
51 #include "GNELane.h"
52 #include "GNEViewNet.h"
53 #include "GNEUndoList.h"
54 #include "GNENet.h"
55 #include "GNEChange_Attribute.h"
56 
57 
58 // ===========================================================================
59 // member method definitions
60 // ===========================================================================
61 
62 GNEVaporizer::GNEVaporizer(GNEViewNet* viewNet, GNEEdge* edge, double startTime, double end) :
63  GNEAdditional(viewNet->getNet()->generateVaporizerID(), viewNet, SUMO_TAG_VAPORIZER, ICON_VAPORIZER, false),
64  myEdge(edge),
65  myStartTime(startTime),
66  myEnd(end),
67  myRelativePositionY(0) {
68 }
69 
70 
72 }
73 
74 
75 void
77  // Clear all containers
78  myShapeRotations.clear();
79  myShapeLengths.clear();
80 
81  // clear Shape
82  myShape.clear();
83 
84  // obtain relative position of vaporizer in edge
86 
87  // get lanes of edge
88  GNELane* firstLane = myEdge->getLanes().at(0);
89 
90  // Save number of lanes
91  myNumberOfLanes = int(myEdge->getLanes().size());
92 
93  // Get shape of lane parent
94  double offset = firstLane->getShape().length() < 2.5 ? firstLane->getShape().length() : 2.5;
95  myShape.push_back(firstLane->getShape().positionAtOffset(offset));
96 
97  // Obtain first position
98  Position f = myShape[0] - Position(1, 0);
99 
100  // Obtain next position
101  Position s = myShape[0] + Position(1, 0);
102 
103  // Save rotation (angle) of the vector constructed by points f and s
104  myShapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(offset) * -1);
105 
106  // Set block icon position
108 
109  // Set offset of the block icon
110  myBlockIconOffset = Position(1.1, (-3.06) - myRelativePositionY);
111 
112  // Set block icon rotation, and using their rotation for logo
113  setBlockIconRotation(firstLane);
114 
115  // Refresh element (neccesary to avoid grabbing problems)
116  myViewNet->getNet()->refreshElement(this);
117 }
118 
119 
120 Position
122  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(5);
123  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(5);
124 
125  // return Middle point
126  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
127 }
128 
129 
130 void
132  // This additional cannot be moved
133 }
134 
135 
136 void
138  // This additional cannot be moved
139 }
140 
141 
142 void
144  // Write parameters
145  device.openTag(getTag());
146  device.writeAttr(SUMO_ATTR_EDGE, myEdge->getID());
148  device.writeAttr(SUMO_ATTR_END, myEnd);
149  // Close tag
150  device.closeTag();
151 }
152 
153 
154 const std::string&
156  return myEdge->getMicrosimID();
157 }
158 
159 
160 void
162  // get values
163  glPushName(getGlID());
164  double width = (double) 2.0 * s.scale;
165  glLineWidth(1.0);
166  const double exaggeration = s.addSize.getExaggeration(s);
167 
168  // set color
169  if (isAdditionalSelected()) {
171  } else {
172  GLHelper::setColor(RGBColor(120, 216, 0));
173  }
174  // draw shape
175  glPushMatrix();
176  glTranslated(0, 0, getType());
177  glTranslated(myShape[0].x(), myShape[0].y(), 0);
178  glRotated(myShapeRotations[0], 0, 0, 1);
179  glScaled(exaggeration, exaggeration, 1);
180  glTranslated(-1.6, -1.6, 0);
181  glBegin(GL_QUADS);
182  glVertex2d(0, 0.25);
183  glVertex2d(0, -0.25);
184  glVertex2d((myNumberOfLanes * 3.3), -0.25);
185  glVertex2d((myNumberOfLanes * 3.3), 0.25);
186  glEnd();
187  glTranslated(0, 0, .01);
188  glBegin(GL_LINES);
189  glVertex2d(0, 0.25 - .1);
190  glVertex2d(0, -0.25 + .1);
191  glEnd();
192 
193  // position indicator (White)
194  if (width * exaggeration > 1) {
195  if (isAdditionalSelected()) {
197  } else {
199  }
200  glRotated(90, 0, 0, -1);
201  glBegin(GL_LINES);
202  glVertex2d(0, 0);
203  glVertex2d(0, (myNumberOfLanes * 3.3));
204  glEnd();
205  }
206 
207  // Pop shape matrix
208  glPopMatrix();
209 
210  // Add a draw matrix for drawing logo
211  glPushMatrix();
212  glTranslated(myShape[0].x(), myShape[0].y(), getType());
213  glRotated(myShapeRotations[0], 0, 0, 1);
214  glTranslated((-2.56) - myRelativePositionY, (-1.6), 0);
215  glColor3d(1, 1, 1);
216  glRotated(-90, 0, 0, 1);
217 
218  // Draw icon depending of detector is or isn't selected
219  if (isAdditionalSelected()) {
221  } else {
223  }
224 
225  // Pop logo matrix
226  glPopMatrix();
227 
228  // Check if the distance is enought to draw details
229  if (s.scale * exaggeration >= 10) {
230  // Show Lock icon depending of the Edit mode
231  drawLockIcon(0.4);
232  }
233 
234  // Finish draw
235  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
236  glPopName();
237 }
238 
239 
240 std::string
242  switch (key) {
243  case SUMO_ATTR_ID:
244  return getAdditionalID();
245  case SUMO_ATTR_EDGE:
246  return myEdge->getID();
247  case SUMO_ATTR_STARTTIME:
248  return toString(myStartTime);
249  case SUMO_ATTR_END:
250  return toString(myEnd);
251  default:
252  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
253  }
254 }
255 
256 
257 void
258 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
259  if (value == getAttribute(key)) {
260  return; //avoid needless changes, later logic relies on the fact that attributes have changed
261  }
262  switch (key) {
263  case SUMO_ATTR_ID:
264  case SUMO_ATTR_EDGE:
265  case SUMO_ATTR_STARTTIME:
266  case SUMO_ATTR_END:
267  undoList->p_add(new GNEChange_Attribute(this, key, value));
268  break;
269  default:
270  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
271  }
272 }
273 
274 
275 bool
276 GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
277  switch (key) {
278  case SUMO_ATTR_ID:
279  return isValidAdditionalID(value);
280  case SUMO_ATTR_EDGE:
281  if (myViewNet->getNet()->retrieveEdge(value, false) != NULL) {
282  return true;
283  } else {
284  return false;
285  }
286  case SUMO_ATTR_STARTTIME:
287  if (canParse<double>(value) && (parse<double>(value) >= 0)) {
288  double startTime = parse<double>(value);
289  if (startTime <= myEnd) {
290  return true;
291  } else {
292  return false;
293  }
294  } else {
295  return false;
296  }
297  case SUMO_ATTR_END:
298  if (canParse<double>(value) && (parse<double>(value) >= 0)) {
299  double end = parse<double>(value);
300  if (myStartTime <= end) {
301  return true;
302  } else {
303  return false;
304  }
305  } else {
306  return false;
307  }
308  default:
309  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
310  }
311 }
312 
313 
314 void
315 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
316  switch (key) {
317  case SUMO_ATTR_ID:
318  changeAdditionalID(value);
319  break;
320  case SUMO_ATTR_EDGE:
321  myEdge = changeEdge(myEdge, value);
322  break;
323  case SUMO_ATTR_STARTTIME:
324  myStartTime = parse<double>(value);
325  break;
326  case SUMO_ATTR_END:
327  myEnd = parse<double>(value);
328  break;
329  default:
330  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
331  }
332  // After setting attribute always update Geometry
333  updateGeometry();
334 }
335 
336 /****************************************************************************/
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:123
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:260
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:902
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:132
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
GUIVisualizationTextSettings addName
void refreshElement(GUIGlObject *o)
refreshes boundary information for o and update
Definition: GNENet.cpp:1082
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
static const RGBColor WHITE
Definition: RGBColor.h:185
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
double x() const
Returns the x-position.
Definition: Position.h:62
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:53
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNEEdge * myEdge
The edge in which this vaporizer is placed.
Definition: GNEVaporizer.h:120
std::vector< double > myShapeRotations
GUIGlID getGlID() const
Returns the numerical id of the object.
void changeAdditionalID(const std::string &newID)
change ID of additional
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in all GNEAttributeCarriers.
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.
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:116
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:55
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:449
const std::string & getAdditionalID() const
returns Additional ID
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:45
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
friend class GNEChange_Attribute
declare friend class
double y() const
Returns the y-position.
Definition: Position.h:67
int getVaporizerRelativePosition(GNEVaporizer *vaporizer) const
obtain relative positions of Vaporizer
Definition: GNEEdge.cpp:556
double length() const
Returns the length.
std::vector< double > myShapeLengths
The lengths of the shape parts.
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
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:56
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:599
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:653
GNEEdge * changeEdge(GNEEdge *oldEdge, const std::string &newEdgeID)
change edge of additional
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:59
double myEnd
end time in which this vaporizer is placed
Definition: GNEVaporizer.h:126
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
weights: time range end
void setBlockIconRotation(GNELane *additionalLane=NULL)
GNENet * getNet() const
get the net object
vaporizer of vehicles
Position getLineCenter() const
get line center
SumoXMLTag getTag() const
get XML Tag assigned to this object
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
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:107
int myNumberOfLanes
number of lanes of edge (To improve efficiency)
Definition: GNEVaporizer.h:129
~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.