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.dlr.de/
10 // Copyright (C) 2001-2017 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 // ===========================================================================
59 // member method definitions
60 // ===========================================================================
61 
62 GNEDetector::GNEDetector(const std::string& id, GNEViewNet* viewNet, SumoXMLTag tag, GUIIcon icon, GNELane* lane, double posOverLane, double freq, const std::string& filename) :
63  GNEAdditional(id, viewNet, Position(posOverLane, 0), tag, icon),
64  myFreq(freq),
65  myFilename(filename) {
66  // This additional belongs to a Lane
67  myLane = lane;
68 }
69 
70 
72 }
73 
74 
75 void
76 GNEDetector::moveAdditionalGeometry(double offsetx, double offsety) {
77  // Due a detector is placed over an lane ignore Warning of posy
78  UNUSED_PARAMETER(offsety);
79  // declare start and end positions
80  double startPos = myPosition.x();
81  double endPos = 0;
82  // set endPos if additional has the attribute length
84  endPos = startPos + GNEAttributeCarrier::parse<double>(getAttribute(SUMO_ATTR_LENGTH));
85  }
86  // Move to Right if distance is positive, to left if distance is negative
87  if (((offsetx > 0) && ((endPos + offsetx) < myLane->getLaneShapeLength())) || ((offsetx < 0) && ((startPos + offsetx) > 0))) {
88  // change attribute
89  myPosition.set(myPosition.x() + offsetx, 0);
90  // Update geometry
92  }
93 }
94 
95 
96 void
97 GNEDetector::commmitAdditionalGeometryMoved(double oldPosx, double, GNEUndoList* undoList) {
98  undoList->p_begin("position of " + toString(getTag()));
99  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(myPosition.x()), true, toString(oldPosx)));
100  undoList->p_end();
101  // Refresh element
103 }
104 
105 
106 double
108  return myPosition.x();
109 }
110 
111 
112 double
114  return myFreq;
115 }
116 
117 
118 std::string
120  return myFilename;
121 }
122 
123 
124 void
126  if (pos < 0) {
127  throw InvalidArgument("Position '" + toString(pos) + "' of " + toString(getTag()) + " not allowed. Must be greater than 0");
128  } else if (pos > myLane->getLaneShapeLength()) {
129  throw InvalidArgument("Position '" + toString(pos) + "' of " + toString(getTag()) + " not allowed. Must be smaller than lane length");
130  } else {
131  myPosition = Position(pos, 0);
132  }
133 }
134 
135 
136 void
137 GNEDetector::setFrequency(const double freq) {
138  if (freq > 0) {
139  myFreq = freq;
140  } else {
141  throw InvalidArgument("Frequency '" + toString(freq) + "' not allowed. Must be greater than 0");
142  }
143 }
144 
145 
146 void
147 GNEDetector::setFilename(std::string filename) {
148  myFilename = filename;
149 }
150 
151 
152 const std::string&
154  return myLane->getMicrosimID();
155 }
156 
157 
158 void
159 GNEDetector::drawDetectorIcon(const int GNELogoID, double sizex, double sizey) const {
160  // Add a draw matrix
161  glPushMatrix();
162  // Traslate to center
163  glTranslated(myShape.getLineCenter().x(), myShape.getLineCenter().y(), getType() + 0.1);
164  // Set color
165  glColor3d(1, 1, 1);
166  // Set first rotation
167  glRotated(myBlockIconRotation, 0, 0, -1);
168  // Set second rotation
169  glRotated(180, 0, 0, 1);
170  //Traslate offset
171  glTranslated(myDetectorLogoOffset.x(), myDetectorLogoOffset.y(), 0);
172  // Draw detector logo
173  GUITexturesHelper::drawTexturedBox(GNELogoID, sizex, sizey, (-1 * sizex), (-1 * sizey));
174  // Pop detector logo matrix
175  glPopMatrix();
176 }
177 
178 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
void commmitAdditionalGeometryMoved(double oldPosx, double, GNEUndoList *undoList)
updated geometry changes in the attributes of additional
Definition: GNEDetector.cpp:97
SumoXMLTag
Numbers representing SUMO-XML - element names.
double getPositionOverLane() const
Returns the position of the detector over lane.
std::string getFilename() const
returns the path to the output file
void setFilename(std::string filename)
Set a new filename in detector.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
GNELane * myLane
The lane this additional belongs.
double y() const
Returns the y-position.
Definition: Position.h:68
double x() const
Returns the x-position.
Definition: Position.h:63
double myFreq
The aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.h:147
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:54
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:82
~GNEDetector()
Destructor.
Definition: GNEDetector.cpp:71
void set(double x, double y)
set positions x and y
Definition: Position.h:93
GNEDetector(const std::string &id, GNEViewNet *viewNet, SumoXMLTag tag, GUIIcon icon, GNELane *lane, double posOverLane, double freq, const std::string &filename)
Constructor.
Definition: GNEDetector.cpp:62
void setPositionOverLane(double pos)
Set a new position of detector over lane.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:38
Position getLineCenter() const
get line center
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
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.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
static bool hasAttribute(SumoXMLTag tag, SumoXMLAttr attr)
check if an element with certain tag has a certain attribute
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:825
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:89
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:158
friend class GNEChange_Attribute
declare friend class
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
double getLaneShapeLength() const
returns the length of the lane&#39;s shape
Definition: GNELane.cpp:721
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:150
void drawDetectorIcon(const int GNELogoID, double sizex=0.5, double sizey=0.5) const
double getFrequency() const
returns the aggregation period the values the detector collects shall be summed up.
void setFrequency(const double freq)
Set a new frequency in detector.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:62
void moveAdditionalGeometry(double offsetx, double offsety)
change the position of the additional geometry
Definition: GNEDetector.cpp:76
GNENet * getNet() const
get the net object
Position myPosition
The position in which this additional element is located.
double myBlockIconRotation
The rotation of the block icon.
virtual std::string getAttribute(SumoXMLAttr key) const =0
SumoXMLTag getTag() const
get XML Tag assigned to this object