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.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 // 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 void updateGeometry() = 0;
96 
98 
100  void resetDefaultValues();
101 
104  /* @brief method for getting the Attribute of an XML key
105  * @param[in] key The attribute key
106  * @return string with the value associated to key
107  */
108  virtual std::string getAttribute(SumoXMLAttr key) const = 0;
109 
110  /* @brief method for setting the attribute and letting the object perform additional changes
111  * @param[in] key The attribute key
112  * @param[in] value The new value
113  * @param[in] undoList The undoList on which to register changes
114  */
115  virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
116 
117  /* @brief method for check if new value for certain attribute is valid
118  * @param[in] key The attribute key
119  * @param[in] value The new value
120  */
121  virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;
122 
123  /* @brief method for enable attribute
124  * @param[in] key The attribute key
125  * @param[in] undoList The undoList on which to register changes
126  * @note certain attributes can be only enabled, and can produce the disabling of other attributes
127  */
128  virtual void enableAttribute(SumoXMLAttr key, GNEUndoList* undoList);
129 
130  /* @brief method for disable attribute
131  * @param[in] key The attribute key
132  * @param[in] undoList The undoList on which to register changes
133  * @note certain attributes can be only enabled, and can produce the disabling of other attributes
134  */
135  virtual void disableAttribute(SumoXMLAttr key, GNEUndoList* undoList);
136 
137  /* @brief method for check if the value for certain attribute is set
138  * @param[in] key The attribute key
139  */
140  virtual bool isAttributeEnabled(SumoXMLAttr key) const;
141 
142  /* @brief method for check if the value for certain attribute is computed (for example, due a network recomputing)
143  * @param[in] key The attribute key
144  */
145  virtual bool isAttributeComputed(SumoXMLAttr key) const;
146 
148  virtual std::string getPopUpID() const = 0;
149 
151  virtual std::string getHierarchyName() const = 0;
152 
154 
158  virtual const Parameterised::Map& getACParametersMap() const = 0;
159 
161  template<typename T>
162  T getACParameters() const;
163 
165  void setACParameters(const std::string& parameters, GNEUndoList* undoList);
166 
168  void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList);
169 
171  void setACParameters(const Parameterised::Map& parameters, GNEUndoList* undoList);
172 
174  void addACParameters(const std::string& key, const std::string& attribute, GNEUndoList* undoList);
175 
177  void removeACParametersKeys(const std::vector<std::string>& keepKeys, GNEUndoList* undoList);
178 
180 
181  /* @brief method for return an alternative value for disabled attributes. Used only in GNEFrames
182  * @param[in] key The attribute key
183  */
185 
187  virtual std::string getAttributeForSelection(SumoXMLAttr key) const;
188 
190  const std::string& getTagStr() const;
191 
193  FXIcon* getACIcon() const;
194 
196  bool isTemplate() const;
197 
199  const GNETagProperties& getTagProperty() const;
200 
202  static const GNETagProperties& getTagProperty(SumoXMLTag tag);
203 
205  static const std::vector<GNETagProperties> getTagPropertiesByType(const int tagPropertyCategory);
206 
208  template<typename T>
209  static bool canParse(const std::string& string) {
210  try {
211  GNEAttributeCarrier::parse<T>(string);
212  } catch (EmptyData&) {
213  // general
214  return false;
215  } catch (NumberFormatException&) {
216  // numbers
217  return false;
218  } catch (TimeFormatException&) {
219  // time
220  return false;
221  } catch (BoolFormatException&) {
222  // booleans
223  return false;
224  } catch (InvalidArgument&) {
225  // colors
226  return false;
227  }
228  return true;
229  }
230 
232  template<typename T>
233  static T parse(const std::string& string);
234 
236  template<typename T>
237  static bool canParse(GNENet* net, const std::string& value, bool report) {
238  try {
239  parse<T>(net, value);
240  } catch (FormatException& exception) {
241  if (report) {
242  WRITE_WARNING(exception.what())
243  }
244  return false;
245  }
246  return true;
247  }
248 
250  template<typename T>
251  static T parse(GNENet* net, const std::string& value);
252 
254  template<typename T>
255  static std::string parseIDs(const std::vector<T>& ACs);
256 
258  static bool lanesConsecutives(const std::vector<GNELane*>& lanes);
259 
261  static FXIcon* getVClassIcon(const SUMOVehicleClass vc);
262 
266  static const std::string FEATURE_LOADED;
267 
269  static const std::string FEATURE_GUESSED;
270 
272  static const std::string FEATURE_MODIFIED;
273 
275  static const std::string FEATURE_APPROVED;
277 
279  static const size_t MAXNUMBEROFATTRIBUTES;
280 
283 
285  static const std::string True;
286 
288  static const std::string False;
289 
290 protected:
293 
296 
299 
302 
304  virtual void toggleAttribute(SumoXMLAttr key, const bool value);
305 
306 private:
308  virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
309 
311  void resetAttributes();
312 
314  static void fillAttributeCarriers();
315 
317  static void fillNetworkElements();
318 
320  static void fillAdditionalElements();
321 
323  static void fillShapeElements();
324 
326  static void fillTAZElements();
327 
329  static void fillWireElements();
330 
332  static void fillDemandElements();
333 
335  static void fillVehicleElements();
336 
338  static void fillStopElements();
339 
341  static void fillWaypointElements();
342 
344  static void fillPersonElements();
345 
347  static void fillPersonPlanTrips();
348 
350  static void fillPersonPlanWalks();
351 
353  static void fillPersonPlanRides();
354 
356  static void fillStopPersonElements();
357 
359  static void fillContainerElements();
360 
362  static void fillContainerTransportElements();
363 
365  static void fillContainerTranshipElements();
366 
368  static void fillContainerStopElements();
369 
371  static void fillCommonVehicleAttributes(SumoXMLTag currentTag);
372 
374  static void fillCommonFlowAttributes(SumoXMLTag currentTag, SumoXMLAttr perHour);
375 
377  static void fillCarFollowingModelAttributes(SumoXMLTag currentTag);
378 
380  static void fillJunctionModelAttributes(SumoXMLTag currentTag);
381 
383  static void fillLaneChangingModelAttributes(SumoXMLTag currentTag);
384 
386  static void fillCommonPersonAttributes(SumoXMLTag currentTag);
387 
389  static void fillCommonContainerAttributes(SumoXMLTag currentTag);
390 
392  static void fillCommonStopAttributes(SumoXMLTag currentTag, const bool waypoint);
393 
395  static void fillDataElements();
396 
398  static std::map<SumoXMLTag, GNETagProperties> myTagProperties;
399 
402 
405 };
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:265
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
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 void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
GNEAttributeCarrier(const SumoXMLTag tag, GNENet *net)
Constructor.
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 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
void setACParameters(const std::string &parameters, GNEUndoList *undoList)
set parameters (string)
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
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)
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_EnableAttribute)
static void fillAdditionalElements()
fill additional elements
static const std::string FEATURE_LOADED
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 fillStopPersonElements()
fill stopPerson elements
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,...
void removeACParametersKeys(const std::vector< std::string > &keepKeys, GNEUndoList *undoList)
remove keys
static FXIcon * getVClassIcon(const SUMOVehicleClass vc)
returns icon associated to the given vClass
virtual bool isAttributeEnabled(SumoXMLAttr key) const
const std::string & getTagStr() const
get tag assigned to this object in string format
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
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 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
void resetDefaultValues()
reset attribute carrier to their default values
static void fillPersonPlanWalks()
fill person plan walks
static void fillTAZElements()
fill TAZ elements
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 fillCommonFlowAttributes(SumoXMLTag currentTag, SumoXMLAttr perHour)
fill common flow attributes (used by flows, routeFlows and personFlows)
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
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
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
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45