Eclipse 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-2019 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 /****************************************************************************/
14 //
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
25 
26 #include "GNEDetector.h"
27 
28 
29 // ===========================================================================
30 // member method definitions
31 // ===========================================================================
32 
33 GNEDetector::GNEDetector(const std::string& id, GNEViewNet* viewNet, GUIGlObjectType type, SumoXMLTag tag,
34  double pos, SUMOTime freq, const std::string& filename, const std::string& vehicleTypes,
35  const std::string& name, bool friendlyPos, bool blockMovement, const std::vector<GNELane*>& parentLanes) :
36  GNEAdditional(id, viewNet, type, tag, name, blockMovement, {}, parentLanes, {}, {}, {}, {}, {}, {}, {}, {}),
37  myPositionOverLane(pos),
38  myFreq(freq),
39  myFilename(filename),
40  myVehicleTypes(vehicleTypes),
41 myFriendlyPosition(friendlyPos) {
42 }
43 
44 
46  double pos, SUMOTime freq, const std::string& filename, const std::string& name, bool friendlyPos,
47  bool blockMovement, const std::vector<GNELane*>& parentLanes) :
48  GNEAdditional(additionalParent, viewNet, type, tag, name, blockMovement, {}, parentLanes, {}, {additionalParent}, {}, {}, {}, {}, {}, {}),
49 myPositionOverLane(pos),
50 myFreq(freq),
51 myFilename(filename),
52 myFriendlyPosition(friendlyPos) {
53 }
54 
55 
57 
58 
59 double
61  return myPositionOverLane;
62 }
63 
64 
65 GNELane*
67  return getParentLanes().front();
68 }
69 
70 
74 }
75 
76 
79  if (getParentLanes().size() > 1) {
81  } else {
83  }
84 }
85 
86 
87 void
88 GNEDetector::splitEdgeGeometry(const double splitPosition, const GNENetElement* originalElement, const GNENetElement* newElement, GNEUndoList* undoList) {
89  // only split geometry of E2 multilane detectors
91  if ((originalElement->getTagProperty().getTag() == SUMO_TAG_LANE) &&
92  (originalElement->getTagProperty().getTag() == SUMO_TAG_LANE)) {
93  // obtain new list of E2 lanes
94  std::string newE2Lanes = getNewListOfParents(originalElement, newElement);
95  // update E2 Lanes
96  if (newE2Lanes.size() > 0) {
97  setAttribute(SUMO_ATTR_LANES, newE2Lanes, undoList);
98  }
99  }
100  } else if (splitPosition < myPositionOverLane) {
101  // change lane
102  setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
103  // now adjust start position
104  setAttribute(SUMO_ATTR_POSITION, toString(myPositionOverLane - splitPosition), undoList);
105  }
106 }
107 
108 
109 double
111  double fixedPos = myPositionOverLane;
112  const double len = getLane()->getParentEdge()->getNBEdge()->getFinalLength();
113  if (fixedPos < 0) {
114  fixedPos += len;
115  }
117  return fixedPos * getLane()->getLengthGeometryFactor();
118 }
119 
120 
121 double
123  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
124 }
125 
126 
127 std::string
129  return getLane()->getMicrosimID();
130 }
131 
132 
133 std::string
135  return getTagStr() + ": " + getID();
136 }
137 
138 
139 std::string
141  return getTagStr();
142 }
143 
144 /****************************************************************************/
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1289
GNELane::getParentEdge
GNEEdge * getParentEdge() const
Returns underlying parent edge.
Definition: GNELane.cpp:1371
GNEDetector::~GNEDetector
~GNEDetector()
Destructor.
Definition: GNEDetector.cpp:56
GNEDetector::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEDetector.cpp:72
GNEDetector::getPositionOverLane
double getPositionOverLane() const
get position over lane
Definition: GNEDetector.cpp:60
SUMO_TAG_LANE
begin/end of the description of a single lane
Definition: SUMOXMLDefinitions.h:49
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
GNEHierarchicalParentElements::getParentLanes
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
Definition: GNEHierarchicalParentElements.cpp:235
GNEViewNet
Definition: GNEViewNet.h:42
SUMO_ATTR_LANE
Definition: SUMOXMLDefinitions.h:637
GNEDetector::myPositionOverLane
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:174
PositionVector::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Definition: PositionVector.cpp:390
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:41
GNEDetector::splitEdgeGeometry
void splitEdgeGeometry(const double splitPosition, const GNENetElement *originalElement, const GNENetElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNEDetector.cpp:88
GNEAttributeCarrier::TagProperties::getTag
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
Definition: GNEAttributeCarrier.cpp:523
GNEDetector::getGeometryPositionOverLane
double getGeometryPositionOverLane() const
get position over lane that is applicable to the shape
Definition: GNEDetector.cpp:110
GUIGlObjectType
GUIGlObjectType
Definition: GUIGlObjectTypes.h:39
GNEDetector::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNEDetector.cpp:128
GNEAttributeCarrier::getTagProperty
const TagProperties & getTagProperty() const
get Tag Property assigned to this object
Definition: GNEAttributeCarrier.cpp:1273
GNEGeometry::Geometry::getShape
const PositionVector & getShape() const
The shape of the additional element.
Definition: GNEGeometry.cpp:147
GNELane::getLaneShape
const PositionVector & getLaneShape() const
Definition: GNELane.cpp:86
GNEEdge::getNBEdge
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition: GNEEdge.cpp:631
GNEAdditionalHandler.h
PositionVector::positionAtOffset
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Definition: PositionVector.cpp:248
GNELane::getLengthGeometryFactor
double getLengthGeometryFactor() const
get length geometry factor
Definition: GNELane.cpp:1428
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
GNEDetector::getLane
GNELane * getLane() const
get lane
Definition: GNEDetector.cpp:66
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
GNEEdge.h
GNEAttributeCarrier::myTagProperty
const TagProperties & myTagProperty
the xml tag to which this attribute carrier corresponds
Definition: GNEAttributeCarrier.h:785
GNEAdditional::myAdditionalGeometry
GNEGeometry::Geometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
Definition: GNEAdditional.h:338
GNENetElement
Definition: GNENetElement.h:43
GNEGeometry::SegmentGeometry::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing all segments.
Definition: GNEGeometry.cpp:353
GNEDetector::setAttribute
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
method for setting the attribute and letting the object perform additional changes
GNELane.h
SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:660
GNEHierarchicalParentElements::getNewListOfParents
std::string getNewListOfParents(const GNENetElement *currentElement, const GNENetElement *newNextElement) const
if use edge/parent lanes as a list of consecutive elements, obtain a list of IDs of elements after in...
Definition: GNEHierarchicalParentElements.cpp:120
SUMO_TAG_E2DETECTOR_MULTILANE
an e2 detector over multiple lanes (used by Netedit)
Definition: SUMOXMLDefinitions.h:69
SUMO_ATTR_LANES
Definition: SUMOXMLDefinitions.h:638
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
GNEDetector::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEDetector.cpp:140
GNEDetector::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEDetector.cpp:78
GNEDetector::getAttributeDouble
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNEDetector.cpp:122
GNEDetector.h
InvalidArgument
Definition: UtilExceptions.h:56
NBEdge::getFinalLength
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:3682
config.h
Boundary::grow
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
GNEDetector::GNEDetector
GNEDetector(const std::string &id, GNEViewNet *viewNet, GUIGlObjectType type, SumoXMLTag tag, double pos, SUMOTime freq, const std::string &filename, const std::string &vehicleTypes, const std::string &name, bool friendlyPos, bool blockMovement, const std::vector< GNELane * > &parentLanes)
Constructor.
Definition: GNEDetector.cpp:33
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEUndoList
Definition: GNEUndoList.h:48
GNEAdditional::mySegmentGeometry
GNEGeometry::SegmentGeometry mySegmentGeometry
segment geometry to be precomputed in updateGeometry(...) (used by E2Multilane)
Definition: GNEAdditional.h:341
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:372
GUIGlObject::getMicrosimID
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.cpp:163
GNELane
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:45
GNEAdditionalHandler::checkAndFixDetectorPosition
static bool checkAndFixDetectorPosition(double &pos, const double laneLength, const bool friendlyPos)
check if the position of a detector over a lane is valid
Definition: GNEAdditionalHandler.cpp:987
GNEDetector::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEDetector.cpp:134