Eclipse SUMO - Simulation of Urban MObility
GNEVTypeDistribution.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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // VehicleType distribution used in NETEDIT
19 /****************************************************************************/
20 #include <netedit/GNENet.h>
21 #include <netedit/GNEUndoList.h>
23 
24 #include "GNEVTypeDistribution.h"
25 
26 
27 // ===========================================================================
28 // member method definitions
29 // ===========================================================================
30 
32  GNEDemandElement("", net, GLO_VTYPE, SUMO_TAG_VTYPE_DISTRIBUTION, GNEPathManager::PathElement::Options::DEMAND_ELEMENT,
33 {}, {}, {}, {}, {}, {}, {}, {}) {
34  // reset default values
35  resetDefaultValues();
36 }
37 
38 
39 GNEVTypeDistribution::GNEVTypeDistribution(GNENet* net, const std::string& vTypeID) :
40  GNEDemandElement(vTypeID, net, GLO_VTYPE, SUMO_TAG_VTYPE_DISTRIBUTION, GNEPathManager::PathElement::Options::DEMAND_ELEMENT,
41 {}, {}, {}, {}, {}, {}, {}, {}) {
42 }
43 
44 
46 
47 
50  return nullptr;
51 }
52 
53 
54 void
56  device.openTag(getTagProperty().getTag());
57  device.writeAttr(SUMO_ATTR_ID, getID());
58  // write all vTypes
59  for (const auto& vType : getChildDemandElements()) {
60  vType->writeDemandElement(device);
61  }
62  device.closeTag();
63 }
64 
65 
68  // currently vTypeDistributions don't have problems
70 }
71 
72 
73 std::string
75  return "";
76 }
77 
78 
79 void
81  // nothing to fix
82 }
83 
84 
87  return SVC_IGNORING;
88 }
89 
90 
91 const RGBColor&
93  return RGBColor::BLACK;
94 }
95 
96 
97 void
99  // nothing to update
100 }
101 
102 
103 Position
105  return Position();
106 }
107 
108 
109 std::string
111  return myNet->getMicrosimID();
112 }
113 
114 
115 double
117  return 1;
118 }
119 
120 
121 Boundary
123  // VehicleType distribution doesn't have boundaries
124  return Boundary(-0.1, -0.1, 0.1, 0.1);
125 }
126 
127 
128 void
129 GNEVTypeDistribution::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
130  // geometry of this element cannot be splitted
131 }
132 
133 
134 void
136  // Vehicle Types aren't draw
137 }
138 
139 
140 void
142  // nothing to compute
143 }
144 
145 
146 void
147 GNEVTypeDistribution::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*lane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
148  // vehicleType distributions don't use drawPartialGL
149 }
150 
151 
152 void
153 GNEVTypeDistribution::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*fromLane*/, const GNELane* /*toLane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
154  // vehicleType distributions don't use drawPartialGL
155 }
156 
157 
158 GNELane*
160  // vehicle types don't use lanes
161  return nullptr;
162 }
163 
164 
165 GNELane*
167  // vehicle types don't use lanes
168  return nullptr;
169 }
170 
171 
172 std::string
174  switch (key) {
175  case SUMO_ATTR_ID:
176  return getID();
177  default:
178  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
179  }
180 }
181 
182 
183 double
185  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
186 }
187 
188 
189 Position
191  throw InvalidArgument(getTagStr() + " doesn't have a Position attribute of type '" + toString(key) + "'");
192 }
193 
194 
195 void
196 GNEVTypeDistribution::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
197  if (value == getAttribute(key)) {
198  return; //avoid needless changes, later logic relies on the fact that attributes have changed
199  }
200  switch (key) {
201  case SUMO_ATTR_ID:
202  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
203  break;
204 
205  default:
206  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
207  }
208 }
209 
210 
211 bool
212 GNEVTypeDistribution::isValid(SumoXMLAttr key, const std::string& value) {
213  switch (key) {
214  case SUMO_ATTR_ID:
215  // Vtypes and PTypes shares namespace
217  return true;
218  } else {
219  return false;
220  }
221  default:
222  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
223  }
224 }
225 
226 
227 void
229  // nothing to enable
230 }
231 
232 
233 void
235  // nothing to disable
236 }
237 
238 
239 bool
241  return true;
242 }
243 
244 
245 std::string
247  return getTagStr();
248 }
249 
250 
251 std::string
253  return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) ;
254 }
255 
256 
257 const std::map<std::string, std::string>&
259  throw InvalidArgument(getTagStr() + " doesn't have parameters");
260 }
261 
262 // ===========================================================================
263 // private
264 // ===========================================================================
265 
266 void
267 GNEVTypeDistribution::setAttribute(SumoXMLAttr key, const std::string& value) {
268  switch (key) {
269  case SUMO_ATTR_ID:
270  setMicrosimID(value);
271  break;
272  default:
273  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
274  }
275 }
276 
277 
278 void
279 GNEVTypeDistribution::toogleAttribute(SumoXMLAttr /*key*/, const bool /*value*/, const int /*previousParameters*/) {
280  // nothing to toogle
281 }
282 
283 
284 void
286  // vehicleType distributions cannot be moved
287 }
288 
289 
290 void
291 GNEVTypeDistribution::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
292  // vehicleType distributions cannot be moved
293 }
294 
295 /****************************************************************************/
@ GLO_VTYPE
@bief vTypes
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
An Element which don't belongs to GNENet but has influency in the simulation.
Problem
enum class for demandElement problems
const std::string & getID() const
get ID
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
move operation
move result
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:125
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object.
std::string getParentName() const
Returns the name of the parent object.
void computePathElement()
compute pathElement
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
Problem isDemandElementValid() const
check if current demand element is valid to be writed into XML
void writeDemandElement(OutputDevice &device) const
writte demand element element into a xml file
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
GNELane * getFirstPathLane() const
get first path lane
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Position getPositionInView() const
Returns position of additional in view.
void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
void updateGeometry()
update pre-computed geometry information
GNEVTypeDistribution(GNENet *net)
default constructor
const RGBColor & getColor() const
get color
double getAttributeDouble(SumoXMLAttr key) const
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
SUMOVehicleClass getVClass() const
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration asociated with this GLObject
void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
GNELane * getLastPathLane() const
get last path lane
Position getAttributePosition(SumoXMLAttr key) const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEMoveOperation * getMoveOperation()
get move operation
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
bool isAttributeEnabled(SumoXMLAttr key) const
void toogleAttribute(SumoXMLAttr key, const bool value, const int previousParameters)
method for enable or disable the attribute and nothing else (used in GNEChange_EnableAttribute)
void fixDemandElementProblem()
fix demand element problem
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
std::string getDemandElementProblem() const
return a string with the current demand element problem
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
Stores the information about how to visualize structures.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
static const RGBColor BLACK
Definition: RGBColor.h:193
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow