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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
28 #include <utils/gui/div/GLHelper.h>
31 
32 #include "GNEVaporizer.h"
33 
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
39 GNEVaporizer::GNEVaporizer(GNEViewNet* viewNet, GNEEdge* edge, double begin, double end, const std::string& name) :
40  GNEAdditional(edge->getID(), viewNet, GLO_VAPORIZER, SUMO_TAG_VAPORIZER, name, false),
41  myEdge(edge),
42  myBegin(begin),
43  myEnd(end) {
44 }
45 
46 
48 }
49 
50 
51 void
52 GNEVaporizer::updateGeometry(bool updateGrid) {
53  // first check if object has to be removed from grid (SUMOTree)
54  if (updateGrid) {
56  }
57 
58  // Clear all containers
60 
61  // get lanes of edge
62  GNELane* firstLane = myEdge->getLanes().at(0);
63 
64  // Get shape of lane parent
65  double offset = firstLane->getShape().length() < 2.5 ? firstLane->getShape().length() : 2.5;
66  myGeometry.shape.push_back(firstLane->getShape().positionAtOffset(offset));
67 
68  // Obtain first position
69  Position f = myGeometry.shape[0] - Position(1, 0);
70 
71  // Obtain next position
72  Position s = myGeometry.shape[0] + Position(1, 0);
73 
74  // Save rotation (angle) of the vector constructed by points f and s
75  myGeometry.shapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(0) * -1);
76 
77  // Set block icon position
79 
80  // Set offset of the block icon
81  myBlockIcon.offset = Position(1.1, (-3.06));
82 
83  // Set block icon rotation, and using their rotation for logo
84  myBlockIcon.setRotation(firstLane);
85 
86  // last step is to check if object has to be added into grid (SUMOTree) again
87  if (updateGrid) {
89  }
90 }
91 
92 
95  if (myEdge->getLanes().front()->getShape().length() < 2.5) {
96  return myEdge->getLanes().front()->getShape().front();
97  } else {
98  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(2.5);
99  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(2.5);
100 
101  // return Middle point
102  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
103  }
104 }
105 
106 
107 void
109  // This additional cannot be moved
110 }
111 
112 
113 void
115  // This additional cannot be moved
116 }
117 
118 
119 std::string
121  return myEdge->getMicrosimID();
122 }
123 
124 
125 void
127  // get values
128  glPushName(getGlID());
129  double width = (double) 2.0 * s.scale;
130  glLineWidth(1.0);
131  const double exaggeration = s.addSize.getExaggeration(s, this);
132  const int numberOfLanes = int(myEdge->getLanes().size());
133 
134  // set color
137  } else {
138  GLHelper::setColor(RGBColor(120, 216, 0));
139  }
140  // draw shape
141  glPushMatrix();
142  glTranslated(0, 0, getType());
143  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), 0);
144  glRotated(myGeometry.shapeRotations[0], 0, 0, 1);
145  glScaled(exaggeration, exaggeration, 1);
146  glTranslated(-1.6, -1.6, 0);
147  glBegin(GL_QUADS);
148  glVertex2d(0, 0.25);
149  glVertex2d(0, -0.25);
150  glVertex2d((numberOfLanes * 3.3), -0.25);
151  glVertex2d((numberOfLanes * 3.3), 0.25);
152  glEnd();
153  glTranslated(0, 0, .01);
154  glBegin(GL_LINES);
155  glVertex2d(0, 0.25 - .1);
156  glVertex2d(0, -0.25 + .1);
157  glEnd();
158 
159  // draw position indicator (White) if isn't being drawn for selecting
160  if ((width * exaggeration > 1) && !s.drawForSelecting) {
163  } else {
165  }
166  glRotated(90, 0, 0, -1);
167  glBegin(GL_LINES);
168  glVertex2d(0, 0);
169  glVertex2d(0, (numberOfLanes * 3.3));
170  glEnd();
171  }
172 
173  // Pop shape matrix
174  glPopMatrix();
175 
176  // Add a draw matrix for drawing logo
177  glPushMatrix();
178  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), getType());
179  glRotated(myGeometry.shapeRotations[0], 0, 0, 1);
180  glTranslated((-2.56), (-1.6), 0);
181 
182  // Draw icon depending of Vaporizer is selected and if isn't being drawn for selecting
183  if (s.drawForSelecting) {
185  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
186  } else {
187  glColor3d(1, 1, 1);
188  glRotated(-90, 0, 0, 1);
191  } else {
193  }
194  }
195 
196  // Pop logo matrix
197  glPopMatrix();
198 
199  // Check if the distance is enought to draw details
200  if ((s.scale * exaggeration >= 10) && !s.drawForSelecting) {
201  // Show Lock icon depending of the Edit mode
202  myBlockIcon.draw(0.4);
203  }
204 
205  // draw name
206  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
207 
208  // check if dotted contour has to be drawn
209  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
211  }
212 
213  // pop name
214  glPopName();
215 }
216 
217 
218 std::string
220  switch (key) {
221  case SUMO_ATTR_ID:
222  case SUMO_ATTR_EDGE:
223  return getAdditionalID();
224  case SUMO_ATTR_BEGIN:
225  return toString(myBegin);
226  case SUMO_ATTR_END:
227  return toString(myEnd);
228  case SUMO_ATTR_NAME:
229  return myAdditionalName;
230  case GNE_ATTR_SELECTED:
232  case GNE_ATTR_GENERIC:
233  return getGenericParametersStr();
234  default:
235  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
236  }
237 }
238 
239 
240 void
241 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
242  if (value == getAttribute(key)) {
243  return; //avoid needless changes, later logic relies on the fact that attributes have changed
244  }
245  switch (key) {
246  case SUMO_ATTR_ID:
247  case SUMO_ATTR_EDGE:
248  case SUMO_ATTR_BEGIN:
249  case SUMO_ATTR_END:
250  case SUMO_ATTR_NAME:
251  case GNE_ATTR_SELECTED:
252  case GNE_ATTR_GENERIC:
253  undoList->p_add(new GNEChange_Attribute(this, key, value));
254  break;
255  default:
256  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
257  }
258 }
259 
260 
261 bool
262 GNEVaporizer::isValid(SumoXMLAttr key, const std::string& value) {
263  switch (key) {
264  case SUMO_ATTR_ID:
265  case SUMO_ATTR_EDGE:
266  if (myViewNet->getNet()->retrieveEdge(value, false) != nullptr) {
267  return isValidAdditionalID(value);
268  } else {
269  return false;
270  }
271  case SUMO_ATTR_BEGIN:
272  if (canParse<double>(value) && (parse<double>(value) >= 0)) {
273  return (parse<double>(value) <= myEnd);
274  } else {
275  return false;
276  }
277  case SUMO_ATTR_END:
278  if (canParse<double>(value) && (parse<double>(value) >= 0)) {
279  return (myBegin <= parse<double>(value));
280  } else {
281  return false;
282  }
283  case SUMO_ATTR_NAME:
285  case GNE_ATTR_SELECTED:
286  return canParse<bool>(value);
287  case GNE_ATTR_GENERIC:
288  return isGenericParametersValid(value);
289  default:
290  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
291  }
292 }
293 
294 
295 std::string
297  return getTagStr();
298 }
299 
300 
301 std::string
303  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
304 }
305 
306 // ===========================================================================
307 // private
308 // ===========================================================================
309 
310 void
311 GNEVaporizer::setAttribute(SumoXMLAttr key, const std::string& value) {
312  switch (key) {
313  case SUMO_ATTR_ID:
314  case SUMO_ATTR_EDGE:
315  changeAdditionalID(value);
316  myEdge = changeEdge(myEdge, value);
317  break;
318  case SUMO_ATTR_BEGIN:
319  myBegin = parse<double>(value);
320  break;
321  case SUMO_ATTR_END:
322  myEnd = parse<double>(value);
323  break;
324  case SUMO_ATTR_NAME:
325  myAdditionalName = value;
326  break;
327  case GNE_ATTR_SELECTED:
328  if (parse<bool>(value)) {
330  } else {
332  }
333  break;
334  case GNE_ATTR_GENERIC:
336  break;
337  default:
338  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
339  }
340  // Update Geometry after setting a new attribute (but avoided for certain attributes)
341  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
342  updateGeometry(true);
343  }
344 }
345 
346 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
double myBegin
begin time of vaporizer
Definition: GNEVaporizer.h:116
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:900
double scale
information about a lane&#39;s width (temporary, used for a single view)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
GUIVisualizationTextSettings addName
std::vector< double > shapeRotations
The rotations of the single shape parts.
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
static const RGBColor WHITE
Definition: RGBColor.h:191
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
Stores the information about how to visualize structures.
Position offset
The offSet of the block icon.
double y() const
Returns the y-position.
Definition: Position.h:62
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double x() const
Returns the x-position.
Definition: Position.h:57
weights: time range begin
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Position position
position of the block icon
BlockIcon myBlockIcon
variable BlockIcon
void clearGeometry()
reset geometry
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNEEdge * myEdge
The edge in which this vaporizer is placed.
Definition: GNEVaporizer.h:113
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
Position getLineCenter() const
get line center
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.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
static const RGBColor GREEN
Definition: RGBColor.h:185
a Vaporizer
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
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:39
PositionVector shape
The shape of the additional element.
std::string myAdditionalName
name of additional
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1160
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
RGBColor selectionColor
NETEDIT special colors.
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
std::string getAttribute(SumoXMLAttr key) const
void updateGeometry(bool updateGrid)
update pre-computed geometry information
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
Position getPositionInView() const
Returns position of additional in view.
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:669
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:873
double length() const
Returns the length.
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 ...
static void drawShapeDottedContour(const int type, const PositionVector &shape, const double width)
draw a dotted contour around the given Non closed shape with certain width
Definition: GLHelper.cpp:471
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
double myEnd
end time in which this vaporizer is placed
Definition: GNEVaporizer.h:119
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
const std::string & getTagStr() const
get tag assigned to this object in string format
weights: time range end
element is selected
std::string getGenericParametersStr() const
return generic parameters in string format
vaporizer of vehicles
GNENet * getNet() const
get the net object
GUIGlID getGlID() const
Returns the numerical id of the object.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
GNEVaporizer(GNEViewNet *viewNet, GNEEdge *edge, double begin, double end, const std::string &name)
Constructor.
std::string getParentName() const
Returns the name of the parent object (if any)
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:132
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
~GNEVaporizer()
Destructor.
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1153
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry(bool updateGrid) function) ...
void draw(double size=0.5) const
draw lock icon