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  myFreq(freq),
69  myFilename(filename) {
70  // This additional belongs to a Lane
71  myLane = lane;
72 }
73 
74 
76 }
77 
78 
79 void
81  // Due a detector is placed over an lane ignore Warning of posy
82  UNUSED_PARAMETER(offsety);
83  // declare start and end positions
84  SUMOReal startPos = myPosition.x();
85  SUMOReal endPos = 0;
86  // set endPos if additional has the attribute lenght
88  endPos = startPos + GNEAttributeCarrier::parse<SUMOReal>(getAttribute(SUMO_ATTR_LENGTH));
89  }
90  // Move to Right if distance is positive, to left if distance is negative
91  if (((offsetx > 0) && ((endPos + offsetx) < myLane->getLaneShapeLenght())) || ((offsetx < 0) && ((startPos + offsetx) > 0))) {
92  // change attribute
93  myPosition.set(myPosition.x() + offsetx, 0);
94  // Update geometry
96  }
97 }
98 
99 
100 void
102  undoList->p_begin("position of " + toString(getTag()));
103  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(myPosition.x()), true, toString(oldPosx)));
104  undoList->p_end();
105  // Refresh element
107 }
108 
109 
110 SUMOReal
112  return myPosition.x();
113 }
114 
115 
116 int
118  return myFreq;
119 }
120 
121 
122 std::string
124  return myFilename;
125 }
126 
127 
128 void
130  if (pos < 0) {
131  throw InvalidArgument("Position '" + toString(pos) + "' not allowed. Must be greather than 0");
132  } else if (pos > myLane->getLaneShapeLenght()) {
133  throw InvalidArgument("Position '" + toString(pos) + "' not allowed. Must be smaller than lane length");
134  } else {
135  myPosition = Position(pos, 0);
136  }
137 }
138 
139 
140 void
142  if (freq >= 0) {
143  myFreq = freq;
144  } else {
145  throw InvalidArgument("Frequency '" + toString(freq) + "' not allowed. Must be greather than 0");
146  }
147 }
148 
149 
150 void
151 GNEDetector::setFilename(std::string filename) {
152  myFilename = filename;
153 }
154 
155 
156 const std::string&
158  return myLane->getMicrosimID();
159 }
160 
161 
162 void
163 GNEDetector::drawDetectorIcon(const int GNELogoID, SUMOReal sizex, SUMOReal sizey) const {
164  // Add a draw matrix
165  glPushMatrix();
166  // Traslate to center
167  glTranslated(myShape.getLineCenter().x(), myShape.getLineCenter().y(), getType() + 0.1);
168  // Set color
169  glColor3d(1, 1, 1);
170  // Set first rotation
171  glRotated(myBlockIconRotation, 0, 0, -1);
172  // Set second rotation
173  glRotated(180, 0, 0, 1);
174  //Traslate offset
175  glTranslated(myDetectorLogoOffset.x(), myDetectorLogoOffset.y(), 0);
176  // Draw detector logo
177  GUITexturesHelper::drawTexturedBox(GNELogoID, sizex, sizey, (-1 * sizex), (-1 * sizey));
178  // Pop detector logo matrix
179  glPopMatrix();
180 }
181 
182 /****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
std::string getFilename() const
returns the path to the output file
void setFilename(std::string filename)
Set a new filename in detector.
SUMOReal getPositionOverLane() const
Returns the position of the detector over lane.
GNELane * myLane
The lane this additional belongs NULL if additional doesnt&#39; belongs to a lane.
void commmitAdditionalGeometryMoved(SUMOReal oldPosx, SUMOReal, GNEUndoList *undoList)
updated geometry changes in the attributes of additional
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
const std::string & getParentName() const
Returns the name of the parent object (if any)
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:55
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:86
void setFrequency(int freq)
Set a new frequency in detector.
~GNEDetector()
Destructor.
Definition: GNEDetector.cpp:75
An Element wich group additionalSet elements.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
Position getLineCenter() const
get line center
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
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.
SUMOReal getLaneShapeLenght() const
returns the length of the lane&#39;s shape
Definition: GNELane.cpp:687
static bool hasAttribute(SumoXMLTag tag, SumoXMLAttr attr)
check if a element with certain tag has a certain attribute
SUMOReal myBlockIconRotation
The rotation of the block icon.
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:784
PositionVector myShape
The shape of the additional element.
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:93
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
virtual void updateGeometry()=0
update pre-computed geometry information
Position myDetectorLogoOffset
The position of detector.
Definition: GNEDetector.h:159
friend class GNEChange_Attribute
declare friend class
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
int getFrequency() const
returns the aggregation period the values the detector collects shall be summed up.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
void drawDetectorIcon(const int GNELogoID, SUMOReal sizex=0.5, SUMOReal sizey=0.5) const
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:151
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:63
void moveAdditionalGeometry(SUMOReal offsetx, SUMOReal offsety)
change the position of the additional geometry
Definition: GNEDetector.cpp:80
void set(SUMOReal x, SUMOReal y)
Definition: Position.h:78
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:912
Position myPosition
The position in which this additional element is located.
#define SUMOReal
Definition: config.h:213
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
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:148
virtual std::string getAttribute(SumoXMLAttr key) const =0
SumoXMLTag getTag() const
get Tag assigned to this object