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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 //
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <string>
30 #include <iostream>
31 #include <utility>
35 #include <utils/common/ToString.h>
36 #include <utils/geom/GeomHelper.h>
42 #include <utils/gui/div/GLHelper.h>
46 
47 #include "GNEDetector.h"
48 #include "GNELane.h"
49 #include "GNEChange_Attribute.h"
50 #include "GNEUndoList.h"
51 #include "GNENet.h"
52 #include "GNEViewNet.h"
53 
54 
55 // ===========================================================================
56 // member method definitions
57 // ===========================================================================
58 
59 GNEDetector::GNEDetector(const std::string& id, GNEViewNet* viewNet, SumoXMLTag tag, GUIIcon icon, GNELane* lane,
60  double pos, double freq, const std::string& filename, bool friendlyPos, GNEAdditional* additionalParent) :
61  GNEAdditional(id, viewNet, tag, icon, true, additionalParent),
62  myLane(lane),
63  myPositionOverLane(pos / lane->getLaneParametricLength()),
64  myFreq(freq),
65  myFilename(filename),
66  myFriendlyPosition(friendlyPos) {
67 }
68 
69 
71 
72 
73 GNELane*
75  return myLane;
76 }
77 
78 
79 double
82 }
83 
84 
85 void
86 GNEDetector::moveGeometry(const Position& oldPos, const Position& offset) {
87  // Calculate new position using old position
88  Position newPosition = oldPos;
89  newPosition.add(offset);
91  // Update geometry
93 }
94 
95 
96 void
98  if (!myBlocked) {
99  // restore old position before commit new position
100  double originalPosOverLane = myLane->getShape().nearest_offset_to_point2D(oldPos, false);
101  undoList->p_begin("position of " + toString(getTag()));
102  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(myPositionOverLane * myLane->getLaneParametricLength()), true, toString(originalPosOverLane)));
103  undoList->p_end();
104  }
105 }
106 
107 
108 Position
111 }
112 
113 
114 const std::string&
116  return myLane->getMicrosimID();
117 }
118 
119 
120 /****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:132
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:42
GNEDetector(const std::string &id, GNEViewNet *viewNet, SumoXMLTag tag, GUIIcon icon, GNELane *lane, double pos, double freq, const std::string &filename, bool friendlyPos, GNEAdditional *additionalParent)
Constructor.
Definition: GNEDetector.cpp:59
const std::string & getParentName() const
Returns the name of the parent object.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:53
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:84
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
Definition: GNEDetector.cpp:97
~GNEDetector()
Destructor.
Definition: GNEDetector.cpp:70
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:701
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
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:91
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
Position getPositionInView() const
Returns position of additional in view.
virtual void updateGeometry()=0
update pre-computed geometry information
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:712
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:599
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
double length() const
Returns the length.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:59
GNELane * myLane
The lane in which this detector is placed.
Definition: GNEDetector.h:135
GNELane * getLane() const
get lane
Definition: GNEDetector.cpp:74
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEDetector.cpp:86
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 getAbsolutePositionOverLane() const
get absolute position over Lane
Definition: GNEDetector.cpp:80
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:138
SumoXMLTag getTag() const
get XML Tag assigned to this object