SUMO - Simulation of Urban MObility
GNEDetector.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 "GNEDetector.h"
51 #include "GNELane.h"
52 #include "GNEChange_Attribute.h"
53 #include "GNEUndoList.h"
54 #include "GNENet.h"
55 #include "GNEViewNet.h"
56 
57 
58 #ifdef CHECK_MEMORY_LEAKS
59 #include <foreign/nvwa/debug_new.h>
60 #endif
61 
62 // ===========================================================================
63 // member method definitions
64 // ===========================================================================
65 
66 GNEDetector::GNEDetector(const std::string& id, GNEViewNet* viewNet, SumoXMLTag tag, GNELane* lane, SUMOReal posOverLane, int freq, const std::string& filename, bool blocked, GNEAdditionalSet* parent) :
67  GNEAdditional(id, viewNet, Position(posOverLane, 0), tag, parent, blocked),
68  myLane(lane),
69  myFreq(freq),
70  myFilename(filename) {
71  myLane->addAdditional(this);
72 }
73 
74 
76  if (myLane) {
77  myLane->removeAdditional(this);
78  }
79 }
80 
81 
82 void
84  // Due a detector is placed over an lane ignore Warning of posy
85  UNUSED_PARAMETER(posy);
86  // if item isn't blocked
87  if (myBlocked == false) {
88  // Move to Right if posx is positive, to left if posx is negative
89  if (((posx > 0) && ((myPosition.x() + posx) < myLane->getLaneShapeLenght())) || ((posx < 0) && ((myPosition.x() + posx) > 0))) {
90  // change attribute
91  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(myPosition.x() + posx)));
92  }
93  }
94 }
95 
96 
97 GNELane*
99  return myLane;
100 }
101 
102 
103 void
105  myLane = NULL;
106 }
107 
108 
109 SUMOReal
111  return myPosition.x();
112 }
113 
114 
115 int
117  return myFreq;
118 }
119 
120 
121 std::string
123  return myFilename;
124 }
125 
126 
127 void
129  if (pos < 0) {
130  throw InvalidArgument("Position '" + toString(pos) + "' not allowed. Must be greather than 0");
131  } else if (pos > myLane->getLaneShapeLenght()) {
132  throw InvalidArgument("Position '" + toString(pos) + "' not allowed. Must be smaller than lane length");
133  } else {
134  myPosition = Position(pos, 0);
135  }
136 }
137 
138 
139 void
141  if (freq >= 0) {
142  myFreq = freq;
143  } else {
144  throw InvalidArgument("Frequency '" + toString(freq) + "' not allowed. Must be greather than 0");
145  }
146 }
147 
148 
149 void
150 GNEDetector::setFilename(std::string filename) {
151  myFilename = filename;
152 }
153 
154 
155 void
157  myLane->removeAdditional(this);
158  myLane = newLane;
159  myLane->addAdditional(this);
160  updateGeometry();
161  getViewNet()->update();
162 }
163 
164 
165 const std::string&
167  return myLane->getMicrosimID();
168 }
169 
170 
171 void
172 GNEDetector::drawDetectorIcon(const int GNELogoID, SUMOReal sizex, SUMOReal sizey) const {
173  // Add a draw matrix
174  glPushMatrix();
175  // Traslate to center
176  glTranslated(myShape.getLineCenter().x(), myShape.getLineCenter().y(), getType() + 0.1);
177  // Set color
178  glColor3d(1, 1, 1);
179  // Set first rotation
180  glRotated(myBlockIconRotation, 0, 0, -1);
181  // Set second rotation
182  glRotated(180, 0, 0, 1);
183  //Traslate offset
184  glTranslated(myDetectorLogoOffset.x(), myDetectorLogoOffset.y(), 0);
185  // Draw detector logo
186  GUITexturesHelper::drawTexturedBox(GNELogoID, sizex, sizey, (-1 * sizex), (-1 * sizey));
187  // Pop detector logo matrix
188  glPopMatrix();
189 }
190 
191 /****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
void changeLane(GNELane *newLane)
change lane of detector
void setFilename(std::string filename)
Set a new filename in detector.
GNEDetector(const std::string &id, GNEViewNet *viewNet, SumoXMLTag tag, GNELane *lane, SUMOReal posOverLane, int freq, const std::string &filename, bool blocked=false, GNEAdditionalSet *parent=NULL)
Constructor.
Definition: GNEDetector.cpp:66
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
void setFrequency(int freq)
Set a new frequency in detector.
std::string getFilename() const
returns the path to the output file
~GNEDetector()
Destructor.
Definition: GNEDetector.cpp:75
An Element wich group additionalSet elements.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
void removeLaneReference()
Remove reference to Lane of stopping place.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void setPositionOverLane(SUMOReal pos)
Set a new position of detector over lane.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
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.
GNELane * getLane() const
Returns pointer to Lane of detector.
Definition: GNEDetector.cpp:98
SUMOReal myBlockIconRotation
The rotation of the block icon.
void drawDetectorIcon(const int GNELogoID, SUMOReal sizex=0.5, SUMOReal sizey=0.5) const
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
virtual void updateGeometry()=0
update pre-computed geometry information
int getFrequency() const
returns the aggregation period the values the detector collects shall be summed up.
Position myDetectorLogoOffset
The position of detector.
Definition: GNEDetector.h:173
friend class GNEChange_Attribute
declare friend class
const std::string & getParentName() const
Returns the name of the parent object (if any)
void moveAdditional(SUMOReal posx, SUMOReal posy, GNEUndoList *undoList)
change the position of the additional geometry
Definition: GNEDetector.cpp:83
bool removeAdditional(GNEAdditional *additional)
Definition: GNELane.cpp:548
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:165
SUMOReal getPositionOverLane() const
Returns the position of the detector over lane.
SUMOReal getLaneShapeLenght() const
returns the length of the lane&#39;s shape
Definition: GNELane.cpp:524
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:63
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
GNELane * myLane
The lane this detector belongs.
Definition: GNEDetector.h:159
Position getLineCenter() const
get line center
Position myPosition
The position in which this additional element is located.
#define SUMOReal
Definition: config.h:213
void addAdditional(GNEAdditional *additional)
Definition: GNELane.cpp:542
static void drawTexturedBox(int which, SUMOReal size)
Draws a named texture as a box with the given size.
int myFreq
The aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.h:162