Eclipse SUMO - Simulation of Urban MObility
GNEAttributeCarrier.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 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 // Abstract Base class for gui objects which carry attributes
19 /****************************************************************************/
20 #pragma once
21 #include <config.h>
22 
25 
26 #include "GNETagProperties.h"
27 
28 
29 // ===========================================================================
30 // class declarations
31 // ===========================================================================
32 class GNENet;
33 class GNEUndoList;
34 class GUIGlObject;
36 class GNELane;
37 class GNEEdge;
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
49 
51  friend class GNEChange_Attribute;
55  friend class GNEFlowEditor;
56 
57 public:
58 
63  GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net);
64 
66  virtual ~GNEAttributeCarrier();
67 
69  const std::string getID() const;
70 
72  GNENet* getNet() const;
73 
75  void selectAttributeCarrier(const bool changeFlag = true);
76 
78  void unselectAttributeCarrier(const bool changeFlag = true);
79 
81  bool isAttributeCarrierSelected() const;
82 
84  bool drawUsingSelectColor() const;
85 
88 
92  virtual GUIGlObject* getGUIGlObject() = 0;
93 
95  virtual const GUIGlObject* getGUIGlObject() const = 0;
96 
98  virtual void updateGeometry() = 0;
99 
101 
104 
106  bool checkDrawInspectContour() const;
107 
109  bool checkDrawFrontContour() const;
110 
112  virtual bool checkDrawFromContour() const = 0;
113 
115  virtual bool checkDrawToContour() const = 0;
116 
118  virtual bool checkDrawRelatedContour() const = 0;
119 
121  virtual bool checkDrawOverContour() const = 0;
122 
124  virtual bool checkDrawDeleteContour() const = 0;
125 
127  virtual bool checkDrawSelectContour() const = 0;
128 
130  virtual bool checkDrawMoveContour() const = 0;
131 
133 
135  void resetDefaultValues();
136 
139  /* @brief method for getting the Attribute of an XML key
140  * @param[in] key The attribute key
141  * @return string with the value associated to key
142  */
143  virtual std::string getAttribute(SumoXMLAttr key) const = 0;
144 
145  /* @brief method for setting the attribute and letting the object perform additional changes
146  * @param[in] key The attribute key
147  * @param[in] value The new value
148  * @param[in] undoList The undoList on which to register changes
149  */
150  virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
151 
152  /* @brief method for check if new value for certain attribute is valid
153  * @param[in] key The attribute key
154  * @param[in] value The new value
155  */
156  virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;
157 
158  /* @brief method for enable attribute
159  * @param[in] key The attribute key
160  * @param[in] undoList The undoList on which to register changes
161  * @note certain attributes can be only enabled, and can produce the disabling of other attributes
162  */
163  virtual void enableAttribute(SumoXMLAttr key, GNEUndoList* undoList);
164 
165  /* @brief method for disable attribute
166  * @param[in] key The attribute key
167  * @param[in] undoList The undoList on which to register changes
168  * @note certain attributes can be only enabled, and can produce the disabling of other attributes
169  */
170  virtual void disableAttribute(SumoXMLAttr key, GNEUndoList* undoList);
171 
172  /* @brief method for check if the value for certain attribute is set
173  * @param[in] key The attribute key
174  */
175  virtual bool isAttributeEnabled(SumoXMLAttr key) const;
176 
177  /* @brief method for check if the value for certain attribute is computed (for example, due a network recomputing)
178  * @param[in] key The attribute key
179  */
180  virtual bool isAttributeComputed(SumoXMLAttr key) const;
181 
182  /* @brief method for check if the value for certain attribute is set
183  * @param[in] key The attribute key
184  */
185  bool hasAttribute(SumoXMLAttr key) const {
186  return myTagProperty.hasAttribute(key);
187  }
188 
190  virtual std::string getPopUpID() const = 0;
191 
193  virtual std::string getHierarchyName() const = 0;
194 
196 
200  virtual const Parameterised::Map& getACParametersMap() const = 0;
201 
203  template<typename T>
204  T getACParameters() const;
205 
207  void setACParameters(const std::string& parameters, GNEUndoList* undoList);
208 
210  void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList);
211 
213  void setACParameters(const Parameterised::Map& parameters, GNEUndoList* undoList);
214 
216  void addACParameters(const std::string& key, const std::string& attribute, GNEUndoList* undoList);
217 
219  void removeACParametersKeys(const std::vector<std::string>& keepKeys, GNEUndoList* undoList);
220 
222 
223  /* @brief method for return an alternative value for disabled attributes. Used only in GNEFrames
224  * @param[in] key The attribute key
225  */
227 
229  virtual std::string getAttributeForSelection(SumoXMLAttr key) const;
230 
232  const std::string& getTagStr() const;
233 
235  FXIcon* getACIcon() const;
236 
238  bool isTemplate() const;
239 
241  const GNETagProperties& getTagProperty() const;
242 
244  static const GNETagProperties& getTagProperty(SumoXMLTag tag);
245 
247  static const std::vector<GNETagProperties> getTagPropertiesByType(const int tagPropertyCategory);
248 
250  template<typename T>
251  static bool canParse(const std::string& string) {
252  try {
253  GNEAttributeCarrier::parse<T>(string);
254  } catch (EmptyData&) {
255  // general
256  return false;
257  } catch (FormatException&) {
258  // numbers, time, boolean, colors
259  return false;
260  }
261  return true;
262  }
263 
265  template<typename T>
266  static T parse(const std::string& string);
267 
269  template<typename T>
270  static bool canParse(GNENet* net, const std::string& value, bool report) {
271  try {
272  parse<T>(net, value);
273  } catch (FormatException& exception) {
274  if (report) {
275  WRITE_WARNING(exception.what())
276  }
277  return false;
278  }
279  return true;
280  }
281 
283  template<typename T>
284  static T parse(GNENet* net, const std::string& value);
285 
287  template<typename T>
288  static std::string parseIDs(const std::vector<T>& ACs);
289 
291  static bool lanesConsecutives(const std::vector<GNELane*>& lanes);
292 
294  static void writeAttributeHelp();
295 
298 
300  static const std::string FEATURE_LOADED;
301 
303  static const std::string FEATURE_GUESSED;
304 
306  static const std::string FEATURE_MODIFIED;
307 
309  static const std::string FEATURE_APPROVED;
310 
312 
314  static const size_t MAXNUMBEROFATTRIBUTES;
315 
318 
320  static const std::string True;
321 
323  static const std::string False;
324 
325 protected:
328 
331 
334 
337 
339  virtual void toggleAttribute(SumoXMLAttr key, const bool value);
340 
341 private:
343  virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
344 
346  void resetAttributes();
347 
349  static void fillAttributeCarriers();
350 
352  static void fillNetworkElements();
353 
355  static void fillAdditionalElements();
356 
358  static void fillShapeElements();
359 
361  static void fillTAZElements();
362 
364  static void fillWireElements();
365 
367  static void fillJuPedSimElements();
368 
370  static void fillDemandElements();
371 
373  static void fillVehicleElements();
374 
376  static void fillStopElements();
377 
379  static void fillWaypointElements();
380 
382  static void fillPersonElements();
383 
385  static void fillPersonPlanTrips();
386 
388  static void fillPersonPlanWalks();
389 
391  static void fillPersonPlanRides();
392 
394  static void fillPersonStopElements();
395 
397  static void fillContainerElements();
398 
400  static void fillContainerTransportElements();
401 
403  static void fillContainerTranshipElements();
404 
406  static void fillContainerStopElements();
407 
409  static void fillPOIAttributes(SumoXMLTag currentTag);
410 
412  static void fillCommonVehicleAttributes(SumoXMLTag currentTag);
413 
415  static void fillCommonFlowAttributes(SumoXMLTag currentTag, SumoXMLAttr perHour);
416 
418  static void fillCarFollowingModelAttributes(SumoXMLTag currentTag);
419 
421  static void fillJunctionModelAttributes(SumoXMLTag currentTag);
422 
424  static void fillLaneChangingModelAttributes(SumoXMLTag currentTag);
425 
427  static void fillCommonPersonAttributes(SumoXMLTag currentTag);
428 
430  static void fillCommonContainerAttributes(SumoXMLTag currentTag);
431 
433  static void fillCommonStopAttributes(SumoXMLTag currentTag, const bool waypoint);
434 
436  static void fillPlanParentAttributes(SumoXMLTag currentTag);
437 
439  static void fillPersonTripCommonAttributes(SumoXMLTag currentTag);
440 
442  static void fillWalkCommonAttributes(SumoXMLTag currentTag);
443 
445  static void fillRideCommonAttributes(SumoXMLTag currentTag);
446 
448  static void fillTransportCommonAttributes(SumoXMLTag currentTag);
449 
451  static void fillTranshipCommonAttributes(SumoXMLTag currentTag);
452 
454  static void fillPlanStopCommonAttributes(SumoXMLTag currentTag);
455 
457  static void fillDataElements();
458 
460  static void fillCommonMeanDataAttributes(SumoXMLTag currentTag);
461 
463  static std::map<SumoXMLTag, GNETagProperties> myTagProperties;
464 
467 
470 };
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:295
SumoXMLTag
Numbers representing SUMO-XML - element names.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNEAttributeCarrier(const GNEAttributeCarrier &)=delete
Invalidated copy constructor.
virtual std::string getAttributeForSelection(SumoXMLAttr key) const
method for getting the attribute in the context of object selection
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
virtual bool checkDrawMoveContour() const =0
check if draw move contour (red)
virtual void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
GNEAttributeCarrier(const SumoXMLTag tag, GNENet *net)
Constructor.
static void fillPlanStopCommonAttributes(SumoXMLTag currentTag)
fill plan stop common attributes
virtual bool checkDrawRelatedContour() const =0
check if draw related contour (cyan)
FXIcon * getACIcon() const
get FXIcon associated to this AC
static const std::vector< GNETagProperties > getTagPropertiesByType(const int tagPropertyCategory)
get tagProperties associated to the given GNETagProperties::TagType (NETWORKELEMENT,...
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
static void writeAttributeHelp()
write machine readable attribute help to file
static void fillContainerStopElements()
fill container stop elements
static void fillVehicleElements()
fill vehicle elements
static void fillDemandElements()
fill demand elements
static void fillWaypointElements()
fill waypoint elements
static void fillPersonElements()
fill person elements
virtual bool checkDrawToContour() const =0
check if draw from contour (magenta)
void setACParameters(const std::string &parameters, GNEUndoList *undoList)
set parameters (string)
static void fillTranshipCommonAttributes(SumoXMLTag currentTag)
fill ride common attributes
static void fillDataElements()
fill Data elements
static void fillPersonPlanRides()
fill person plan rides
static void fillCommonStopAttributes(SumoXMLTag currentTag, const bool waypoint)
fill stop person attributes
bool checkDrawFrontContour() const
check if draw front contour (green/blue)
static void fillLaneChangingModelAttributes(SumoXMLTag currentTag)
fill Junction Model Attributes of Vehicle/Person Types
void resetAttributes()
reset attributes to their default values without undo-redo (used in GNEFrameAttributeModules)
bool myIsTemplate
whether the current object is a template object (not drawn in the view)
virtual void setAttribute(SumoXMLAttr key, const std::string &value)=0
method for setting the attribute and nothing else (used in GNEChange_Attribute)
virtual bool checkDrawFromContour() const =0
check if draw from contour (green)
static void fillAttributeCarriers()
fill Attribute Carriers
virtual void toggleAttribute(SumoXMLAttr key, const bool value)
method for enable or disable the attribute and nothing else (used in GNEChange_ToggleAttribute)
static void fillAdditionalElements()
fill additional elements
static const std::string FEATURE_LOADED
feature is still unchanged after being loaded (implies approval)
static void fillCommonMeanDataAttributes(SumoXMLTag currentTag)
fill stop person attributes
static void fillCommonPersonAttributes(SumoXMLTag currentTag)
fill common person attributes (used by person and personFlows)
virtual std::string getPopUpID() const =0
get PopPup ID (Used in AC Hierarchy)
static void fillNetworkElements()
fill network elements
static void fillPersonStopElements()
fill person stop elements
static void fillWalkCommonAttributes(SumoXMLTag currentTag)
fill walk common attributes
static const std::string FEATURE_APPROVED
feature has been approved but not changed (i.e. after being reguessed)
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
std::string getAlternativeValueForDisabledAttributes(SumoXMLAttr key) const
virtual bool isAttributeComputed(SumoXMLAttr key) const
static void fillWireElements()
fill Wire elements
static const std::string True
true value in string format (used for comparing boolean values in getAttribute(......
static T parse(GNENet *net, const std::string &value)
parses a complex value of type T from string (use for list of edges, list of lanes,...
static void fillPOIAttributes(SumoXMLTag currentTag)
fill common POI attributes
void removeACParametersKeys(const std::vector< std::string > &keepKeys, GNEUndoList *undoList)
remove keys
virtual bool isAttributeEnabled(SumoXMLAttr key) const
const std::string & getTagStr() const
get tag assigned to this object in string format
static void fillJuPedSimElements()
fill JuPedSim elements
static const std::string FEATURE_GUESSED
feature has been reguessed (may still be unchanged be we can't tell (yet)
static void fillStopElements()
fill stop elements
virtual GUIGlObject * getGUIGlObject()=0
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
bool isTemplate() const
check if this AC is template
static void fillRideCommonAttributes(SumoXMLTag currentTag)
fill ride common attributes
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
static bool canParse(GNENet *net, const std::string &value, bool report)
true if a value of type T can be parsed from string
static void fillShapeElements()
fill shape elements
static void fillCommonVehicleAttributes(SumoXMLTag currentTag)
fill common vehicle attributes (used by vehicles, trips, routeFlows and flows)
void addACParameters(const std::string &key, const std::string &attribute, GNEUndoList *undoList)
add (or update attribute) key and attribute
static void fillPersonTripCommonAttributes(SumoXMLTag currentTag)
fill person trip common attributes
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
GNEAttributeCarrier & operator=(const GNEAttributeCarrier &src)=delete
Invalidated assignment operator.
static bool lanesConsecutives(const std::vector< GNELane * > &lanes)
check if lanes are consecutives
virtual const Parameterised::Map & getACParametersMap() const =0
bool hasAttribute(SumoXMLAttr key) const
void resetDefaultValues()
reset attribute carrier to their default values
static void fillPersonPlanWalks()
fill person plan walks
static void fillTAZElements()
fill TAZ elements
virtual bool checkDrawSelectContour() const =0
check if draw select contour (blue)
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
GNENet * myNet
pointer to net
static void fillCommonContainerAttributes(SumoXMLTag currentTag)
fill common container attributes (used by container and containerFlows)
virtual std::string getHierarchyName() const =0
get Hierarchy Name (Used in AC Hierarchy)
static void fillPlanParentAttributes(SumoXMLTag currentTag)
fill plan from-to attribute
static void fillCommonFlowAttributes(SumoXMLTag currentTag, SumoXMLAttr perHour)
fill common flow attributes (used by flows, routeFlows and personFlows)
virtual const GUIGlObject * getGUIGlObject() const =0
get GUIGlObject associated with this AttributeCarrier (constant)
static void fillTransportCommonAttributes(SumoXMLTag currentTag)
fill transport common attributes
static void fillJunctionModelAttributes(SumoXMLTag currentTag)
fill Junction Model Attributes of Vehicle/Person Types
GNENet * getNet() const
get pointer to net
virtual void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
static void fillPersonPlanTrips()
fill person plan trips
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
static const std::string FEATURE_MODIFIED
feature has been manually modified (implies approval)
static const std::string False
true value in string format(used for comparing boolean values in getAttribute(...))
static void fillCarFollowingModelAttributes(SumoXMLTag currentTag)
fill Car Following Model of Vehicle/Person Types
static void fillContainerElements()
fill container elements
virtual void updateGeometry()=0
update pre-computed geometry information
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
T getACParameters() const
get parameters
virtual ~GNEAttributeCarrier()
Destructor.
virtual std::string getAttribute(SumoXMLAttr key) const =0
bool checkDrawInspectContour() const
check if draw inspect contour (black/white)
static void fillContainerTranshipElements()
fill container tranship elements
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
static std::map< SumoXMLTag, GNETagProperties > myTagProperties
map with the tags properties
static const size_t MAXNUMBEROFATTRIBUTES
max number of attributes allowed for every tag
virtual GNEHierarchicalElement * getHierarchicalElement()=0
get GNEHierarchicalElement associated with this AttributeCarrier
virtual bool checkDrawOverContour() const =0
check if draw over contour (orange)
virtual bool checkDrawDeleteContour() const =0
check if draw delete contour (pink/white)
static void fillContainerTransportElements()
fill container transport elements
the function-object for an editing operation (abstract base)
the function-object for an editing operation (abstract base)
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute "attr"
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45