SUMO - Simulation of Urban MObility
GNEDetector.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 //
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 pos, double freq, const std::string& filename, bool friendlyPos) :
63  GNEAdditional(id, viewNet, tag, icon),
64  myPositionOverLane(pos / lane->getLaneParametricLength()),
65  myFreq(freq),
66  myFilename(filename),
67  myFriendlyPosition(friendlyPos) {
68  // This additional belongs to a Lane
69  myLane = lane;
70 }
71 
72 
74 }
75 
76 
77 double
79  return myFreq;
80 }
81 
82 
83 const std::string&
85  return myFilename;
86 }
87 
88 
89 void
90 GNEDetector::setFrequency(const double freq) {
91  if (freq > 0) {
92  myFreq = freq;
93  } else {
94  throw InvalidArgument("Frequency '" + toString(freq) + "' not allowed. Must be greater than 0");
95  }
96 }
97 
98 
99 void
100 GNEDetector::setFilename(const std::string& filename) {
101  myFilename = filename;
102 }
103 
106 }
107 
108 
109 void GNEDetector::moveGeometry(const Position& newPosition) {
110  // First we need to change the absolute new position to a relative position
111  double lenghtDifference = 0;
112  if (myLane->getLaneShapeLength() > 0) {
113  lenghtDifference = myLane->getLaneParametricLength() / myLane->getLaneShapeLength();
114  }
115  double relativePos = newPosition.x() / myLane->getLaneParametricLength() * lenghtDifference;
116  // change relative position position over lane
117  myPositionOverLane += relativePos;
118  // Update geometry
119  updateGeometry();
120 }
121 
122 
124  undoList->p_begin("position of " + toString(getTag()));
126  undoList->p_end();
127  // Refresh element
129 }
130 
133 }
134 
135 const std::string&
137  return myLane->getMicrosimID();
138 }
139 
140 
141 /****************************************************************************/
double getLaneShapeLength() const
returns the length of the lane&#39;s shape
Definition: GNELane.cpp:730
SumoXMLTag
Numbers representing SUMO-XML - element names.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
double x() const
Returns the x-position.
Definition: Position.h:63
GNELane * myLane
The lane this additional belongs.
double myFreq
The aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.h:158
GNEDetector(const std::string &id, GNEViewNet *viewNet, SumoXMLTag tag, GUIIcon icon, GNELane *lane, double pos, double freq, const std::string &filename, bool friendlyPos)
Constructor.
Definition: GNEDetector.cpp:62
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:85
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
~GNEDetector()
Destructor.
Definition: GNEDetector.cpp:73
const std::string & getFilename() const
returns the path to the output file
Definition: GNEDetector.cpp:84
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:998
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:92
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
virtual void updateGeometry()=0
update pre-computed geometry information
friend class GNEChange_Attribute
declare friend class
double length() const
Returns the length.
const std::string & getParentName() const
Returns the name of the parent object.
double getAbsolutePositionOverLane() const
get absolute position over Lane
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:161
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:625
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
void setFrequency(const double freq)
Set a new frequency in detector.
Definition: GNEDetector.cpp:90
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:62
void setFilename(const std::string &filename)
Set a new filename in detector.
double getFrequency() const
returns the aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.cpp:78
GNENet * getNet() const
get the net object
SumoXMLTag getTag() const
get XML Tag assigned to this object
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:719
Position getPositionInView() const
Returns position of additional in view.
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:155
void moveGeometry(const Position &newPosition)
change the position of the element geometry without saving in undoList