SUMO - Simulation of Urban MObility
GNEDetectorEntry.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>
37 #include <utils/common/ToString.h>
38 #include <utils/geom/GeomHelper.h>
45 #include <utils/gui/div/GLHelper.h>
49 
50 #include "GNEDetectorEntry.h"
51 #include "GNEDetectorE3.h"
52 #include "GNELane.h"
53 #include "GNEViewNet.h"
54 #include "GNEUndoList.h"
55 #include "GNENet.h"
56 #include "GNEChange_Attribute.h"
57 
58 #ifdef CHECK_MEMORY_LEAKS
59 #include <foreign/nvwa/debug_new.h>
60 #endif
61 
62 // ===========================================================================
63 // member method definitions
64 // ===========================================================================
65 
66 GNEDetectorEntry::GNEDetectorEntry(const std::string& id, GNEViewNet* viewNet, GNELane* lane, SUMOReal pos, GNEDetectorE3* parent, bool blocked) :
67  GNEDetector(id, viewNet, SUMO_TAG_DET_ENTRY, lane, pos, 0, "", blocked, parent) {
68  // Update geometry;
70  // Set colors
71  myBaseColor = RGBColor(0, 204, 0, 255);
72  myBaseColorSelected = RGBColor(125, 204, 0, 255);
73 }
74 
75 
77 
78 
79 void
81  // Clear all containers
82  myShapeRotations.clear();
83  myShapeLengths.clear();
84 
85  // clear Shape
86  myShape.clear();
87 
88  // Get shape of lane parent
90 
91  // Save rotation (angle) of the vector constructed by points f and s
93 
94  // Set block icon position
96 
97  // Set offset of logo
99 
100  // Set block icon rotation, and using their rotation for logo
102 
103  // Update parent geometry
105 }
106 
107 
108 Position
111 }
112 
113 
114 void
115 GNEDetectorEntry::writeAdditional(OutputDevice& device, const std::string&) {
116  // Write parameters
117  device.openTag(getTag());
118  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
120  // Close tag
121  device.closeTag();
122 }
123 
124 
125 void
127  // Start drawing adding gl identificator
128  glPushName(getGlID());
129 
130  // Push detector matrix
131  glPushMatrix();
132  glTranslated(0, 0, getType());
133 
134  // Set initial values
135  if (isAdditionalSelected()) {
137  } else {
138  glColor3d(myBaseColor.red(), myBaseColor.green(), myBaseColor.blue());
139  }
140  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
141  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
142 
143  // Push poligon matrix
144  glPushMatrix();
145  glScaled(exaggeration, exaggeration, 1);
146  glTranslated(myShape[0].x(), myShape[0].y(), 0);
147  glRotated(myShapeRotations[0], 0, 0, 1);
148 
149  // Draw poligon
150  glBegin(GL_LINES);
151  glVertex2d(1.7, 0);
152  glVertex2d(-1.7, 0);
153  glEnd();
154  glBegin(GL_QUADS);
155  glVertex2d(-1.7, .5);
156  glVertex2d(-1.7, -.5);
157  glVertex2d(1.7, -.5);
158  glVertex2d(1.7, .5);
159  glEnd();
160 
161  // first Arrow
162  glTranslated(1.5, 0, 0);
163  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
165 
166  // second Arrow
167  glTranslated(-3, 0, 0);
168  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
170 
171  // Pop poligon matrix
172  glPopMatrix();
173 
174  // Pop detector matrix
175  glPopMatrix();
176 
177  // Check if the distance is enought to draw details
178  if (s.scale * exaggeration >= 10) {
179  // Draw icon
181 
182  // Show Lock icon depending of the Edit mode
183  drawLockIcon(0.4);
184  }
185  // Draw name
186  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
187 
188  // pop gl identificator
189  glPopName();
190 }
191 
192 
193 std::string
195  switch (key) {
196  case SUMO_ATTR_ID:
197  return getAdditionalID();
198  case SUMO_ATTR_LANE:
200  case SUMO_ATTR_POSITION:
201  return toString(myPosition.x());
202  default:
203  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
204  }
205 }
206 
207 
208 void
209 GNEDetectorEntry::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
210  if (value == getAttribute(key)) {
211  return; //avoid needless changes, later logic relies on the fact that attributes have changed
212  }
213  switch (key) {
214  case SUMO_ATTR_ID:
215  setAdditionalID(value);
216  break;
217  case SUMO_ATTR_LANE:
219  break;
220  case SUMO_ATTR_POSITION:
221  undoList->p_add(new GNEChange_Attribute(this, key, value));
222  updateGeometry();
223  break;
224  default:
225  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
226  }
227 }
228 
229 
230 bool
231 GNEDetectorEntry::isValid(SumoXMLAttr key, const std::string& value) {
232  switch (key) {
233  case SUMO_ATTR_ID:
234  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
235  return true;
236  } else {
237  return false;
238  }
239  case SUMO_ATTR_LANE:
240  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
241  return true;
242  } else {
243  return false;
244  }
245  case SUMO_ATTR_POSITION:
246  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 0 && parse<SUMOReal>(value) <= (myLane->getLaneParametricLenght()));
247  default:
248  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
249  }
250 }
251 
252 void
253 GNEDetectorEntry::setAttribute(SumoXMLAttr key, const std::string& value) {
254  switch (key) {
255  case SUMO_ATTR_ID:
256  setAdditionalID(value);
257  break;
258  case SUMO_ATTR_LANE:
260  break;
261  case SUMO_ATTR_POSITION:
262  myPosition = Position(parse<SUMOReal>(value), 0);
263  updateGeometry();
264  getViewNet()->update();
265  break;
266  default:
267  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
268  }
269 }
270 
271 /****************************************************************************/
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
Position getPositionInView() const
Returns position of detector Entry in view.
void changeLane(GNELane *newLane)
change lane of detector
GUIVisualizationTextSettings addName
Stores the information about how to visualize structures.
bool isAdditionalSelected() const
static void drawBoxLine(const Position &beg, SUMOReal rot, SUMOReal visLength, SUMOReal width, SUMOReal offset=0)
Draws a thick line.
Definition: GLHelper.cpp:130
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.
~GNEDetectorEntry()
destructor
void updateGeometry()
update pre-computed geometry information
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
GUIGlID getGlID() const
Returns the numerical id of the object.
static void drawTriangleAtEnd(const Position &p1, const Position &p2, SUMOReal tLength, SUMOReal tWidth)
Draws a triangle at the end of the given line.
Definition: GLHelper.cpp:422
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
RGBColor myBaseColorSelected
base color selected (Default blue)
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.
const std::string & getAdditionalID() const
returns the ID of additional
std::string getAttribute(SumoXMLAttr key) const
void drawDetectorIcon(const int GNELogoID, SUMOReal sizex=0.5, SUMOReal sizey=0.5) const
SUMOReal getLaneParametricLenght() const
returns the parameteric length of the lane
Definition: GNELane.cpp:518
SUMOReal getPositionRelativeToParametricLenght(SUMOReal position) const
Definition: GNELane.cpp:530
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:658
void setBlockIconRotation(GNELane *lane=NULL)
Position myDetectorLogoOffset
The position of detector.
Definition: GNEDetector.h:173
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 writeAdditional(OutputDevice &device, const std::string &)
writte additional element into a xml file
void setAdditionalID(const std::string &id)
set the ID of additional
const std::string getID() const
function to support debugging
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
bool isValid(SumoXMLAttr key, const std::string &value)
std::string getAttribute(SumoXMLAttr key) const
Definition: GNELane.cpp:601
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
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:456
GNEAdditionalSet * myAdditionalSetParent
pointer to additional set parent, if belong to set
virtual void updateGeometry()=0
update pre-computed geometry information
RGBColor myBaseColor
base color (Default green)
GNELane * myLane
The lane this detector belongs.
Definition: GNEDetector.h:159
std::vector< SUMOReal > myShapeRotations
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:845
Position getLineCenter() const
get line center
SumoXMLTag getTag() const
get Tag assigned to this 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.
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:213
static GUIGlID getGif(GUITexture which)
returns a texture Gif previously defined in the enum GUITexture
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
GNEDetectorEntry(const std::string &id, GNEViewNet *viewNet, GNELane *lane, SUMOReal pos, GNEDetectorE3 *parent, bool blocked=false)
Constructor.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Position myBlockIconPosition
position of the block icon