SUMO - Simulation of Urban MObility
GNEDetector.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
29 #include <utils/common/ToString.h>
30 #include <utils/geom/GeomHelper.h>
35 #include <utils/gui/div/GLHelper.h>
41 #include <netedit/GNEUndoList.h>
42 #include <netedit/GNENet.h>
43 #include <netedit/GNEViewNet.h>
44 
45 #include "GNEDetector.h"
46 
47 
48 // ===========================================================================
49 // member method definitions
50 // ===========================================================================
51 
52 GNEDetector::GNEDetector(const std::string& id, GNEViewNet* viewNet, GUIGlObjectType type, SumoXMLTag tag, GNELane* lane,
53  double pos, double freq, const std::string& filename, const std::string& vehicleTypes, const std::string& name, bool friendlyPos, bool blockMovement) :
54  GNEAdditional(id, viewNet, type, tag, name, blockMovement),
55  myLane(lane),
56  myPositionOverLane(pos),
57  myFreq(freq),
58  myFilename(filename),
59  myVehicleTypes(vehicleTypes),
60  myFriendlyPosition(friendlyPos) {
61 }
62 
63 
65  double pos, double freq, const std::string& filename, const std::string& name, bool friendlyPos, bool blockMovement) :
66  GNEAdditional(additionalParent, viewNet, type, tag, name, blockMovement),
67  myLane(lane),
68  myPositionOverLane(pos),
69  myFreq(freq),
70  myFilename(filename),
71  myFriendlyPosition(friendlyPos) {
72 }
73 
74 
76 
77 
78 GNELane*
80  return myLane;
81 }
82 
83 
84 double
86  return myPositionOverLane;
87 }
88 
89 
90 void
91 GNEDetector::moveGeometry(const Position& oldPos, const Position& offset) {
92  // Calculate new position using old position
93  Position newPosition = oldPos;
94  newPosition.add(offset);
96  // Update geometry
97  updateGeometry(false);
98 }
99 
100 
101 void
103  // restore old position before commit new position
104  double originalPosOverLane = myLane->getShape().nearest_offset_to_point2D(oldPos, false);
105  // commit new position allowing undo/redo
106  undoList->p_begin("position of " + toString(getTag()));
107  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(myPositionOverLane), true, toString(originalPosOverLane)));
108  undoList->p_end();
109 }
110 
111 
112 Position
114  if (myPositionOverLane < 0) {
115  return myLane->getShape().front();
116  } else if (myPositionOverLane > myLane->getShape().length()) {
117  return myLane->getShape().back();
118  } else {
120  }
121 }
122 
123 
124 std::string
126  return myLane->getMicrosimID();
127 }
128 
129 
130 std::string
132  return toString(getTag()) + ": " + getID();
133 }
134 
135 
136 std::string
138  return toString(getTag());
139 }
140 
141 /****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
double getPositionOverLane() const
get position over lane
Definition: GNEDetector.cpp:85
std::string getParentName() const
Returns the name of the parent object.
GUIGlObjectType
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:126
double myFreq
The aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.h:153
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
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:78
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:75
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GNEDetector(const std::string &id, GNEViewNet *viewNet, GUIGlObjectType type, SumoXMLTag tag, GNELane *lane, double pos, double freq, const std::string &filename, const std::string &vehicleTypes, const std::string &name, bool friendlyPos, bool blockMovement)
Constructor.
Definition: GNEDetector.cpp:52
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
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:85
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
Position getPositionInView() const
Returns position of additional in view.
friend class GNEChange_Attribute
declare friend class
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
const std::string getID() const
function to support debugging
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:162
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:156
virtual void updateGeometry(bool updateGrid)=0
update pre-computed geometry information
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:679
double length() const
Returns the length.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
GNELane * myLane
The lane in which this detector is placed.
Definition: GNEDetector.h:147
GNELane * getLane() const
get lane
Definition: GNEDetector.cpp:79
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEDetector.cpp:91
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:150
SumoXMLTag getTag() const
get XML Tag assigned to this object