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;
54 
55 public:
56 
61  GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net);
62 
64  virtual ~GNEAttributeCarrier();
65 
67  GNENet* getNet() const;
68 
70  void selectAttributeCarrier(const bool changeFlag = true);
71 
73  void unselectAttributeCarrier(const bool changeFlag = true);
74 
76  bool isAttributeCarrierSelected() const;
77 
79  bool drawUsingSelectColor() const;
80 
83 
87  virtual const std::string& getID() const = 0;
88 
90  virtual GUIGlObject* getGUIGlObject() = 0;
91 
93  virtual void updateGeometry() = 0;
94 
96 
98  void resetDefaultValues();
99 
102  /* @brief method for getting the Attribute of an XML key
103  * @param[in] key The attribute key
104  * @return string with the value associated to key
105  */
106  virtual std::string getAttribute(SumoXMLAttr key) const = 0;
107 
108  /* @brief method for setting the attribute and letting the object perform additional changes
109  * @param[in] key The attribute key
110  * @param[in] value The new value
111  * @param[in] undoList The undoList on which to register changes
112  */
113  virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
114 
115  /* @brief method for check if new value for certain attribute is valid
116  * @param[in] key The attribute key
117  * @param[in] value The new value
118  */
119  virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;
120 
121  /* @brief method for enable attribute
122  * @param[in] key The attribute key
123  * @param[in] undoList The undoList on which to register changes
124  * @note certain attributes can be only enabled, and can produce the disabling of other attributes
125  */
126  virtual void enableAttribute(SumoXMLAttr key, GNEUndoList* undoList) = 0;
127 
128  /* @brief method for disable attribute
129  * @param[in] key The attribute key
130  * @param[in] undoList The undoList on which to register changes
131  * @note certain attributes can be only enabled, and can produce the disabling of other attributes
132  */
133  virtual void disableAttribute(SumoXMLAttr key, GNEUndoList* undoList) = 0;
134 
135  /* @brief method for check if the value for certain attribute is set
136  * @param[in] key The attribute key
137  */
138  virtual bool isAttributeEnabled(SumoXMLAttr key) const = 0;
139 
140  /* @brief method for check if the value for certain attribute is computed (for example, due a network recomputing)
141  * @param[in] key The attribute key
142  */
143  virtual bool isAttributeComputed(SumoXMLAttr key) const = 0;
144 
146  virtual std::string getPopUpID() const = 0;
147 
149  virtual std::string getHierarchyName() const = 0;
150 
152 
156  virtual const std::map<std::string, std::string>& getACParametersMap() const = 0;
157 
159  template<typename T>
160  T getACParameters() const;
161 
163  void setACParameters(const std::string& parameters, GNEUndoList* undoList);
164 
166  void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList);
167 
169  void setACParameters(const std::map<std::string, std::string>& parameters, GNEUndoList* undoList);
170 
172  void addACParameters(const std::string& key, const std::string& attribute, GNEUndoList* undoList);
173 
175  void removeACParametersKeys(const std::vector<std::string>& keepKeys, GNEUndoList* undoList);
176 
178 
179  /* @brief method for return an alternative value for disabled attributes. Used only in GNEFrames
180  * @param[in] key The attribute key
181  */
183 
185  virtual std::string getAttributeForSelection(SumoXMLAttr key) const;
186 
188  const std::string& getTagStr() const;
189 
191  FXIcon* getIcon() const;
192 
194  bool isTemplate() const;
195 
197  const GNETagProperties& getTagProperty() const;
198 
200  static const GNETagProperties& getTagProperty(SumoXMLTag tag);
201 
203  static const std::vector<GNETagProperties> getTagPropertiesByType(const int tagPropertyCategory);
204 
206  template<typename T>
207  static bool canParse(const std::string& string) {
208  try {
209  GNEAttributeCarrier::parse<T>(string);
210  } catch (EmptyData&) {
211  // general
212  return false;
213  } catch (NumberFormatException&) {
214  // numbers
215  return false;
216  } catch (TimeFormatException&) {
217  // time
218  return false;
219  } catch (BoolFormatException&) {
220  // booleans
221  return false;
222  } catch (InvalidArgument&) {
223  // colors
224  return false;
225  }
226  return true;
227  }
228 
230  template<typename T>
231  static T parse(const std::string& string);
232 
234  template<typename T>
235  static bool canParse(GNENet* net, const std::string& value, bool report) {
236  try {
237  parse<T>(net, value);
238  } catch (FormatException& exception) {
239  if (report) {
240  WRITE_WARNING(exception.what())
241  }
242  return false;
243  }
244  return true;
245  }
246 
248  template<typename T>
249  static T parse(GNENet* net, const std::string& value);
250 
252  template<typename T>
253  static std::string parseIDs(const std::vector<T>& ACs);
254 
256  static bool lanesConsecutives(const std::vector<GNELane*>& lanes);
257 
261  static const std::string FEATURE_LOADED;
262 
264  static const std::string FEATURE_GUESSED;
265 
267  static const std::string FEATURE_MODIFIED;
268 
270  static const std::string FEATURE_APPROVED;
272 
274  static const size_t MAXNUMBEROFATTRIBUTES;
275 
276 protected:
279 
282 
285 
288 
289 private:
291  virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
292 
294  virtual void toogleAttribute(SumoXMLAttr key, const bool value, const int previousParameters) = 0;
295 
297  void resetAttributes();
298 
300  static void fillAttributeCarriers();
301 
303  static void fillNetworkElements();
304 
306  static void fillAdditionals();
307 
309  static void fillShapes();
310 
312  static void fillTAZElements();
313 
315  static void fillDemandElements();
316 
318  static void fillVehicleElements();
319 
321  static void fillStopElements();
322 
324  static void fillPersonElements();
325 
327  static void fillPersonPlanTrips();
328 
330  static void fillPersonPlanWalks();
331 
333  static void fillPersonPlanRides();
334 
336  static void fillStopPersonElements();
337 
339  static void fillContainerElements();
340 
342  static void fillContainerTransportElements();
343 
345  static void fillContainerTranshipElements();
346 
348  static void fillContainerStopElements();
349 
351  static void fillCommonVehicleAttributes(SumoXMLTag currentTag);
352 
354  static void fillCommonFlowAttributes(SumoXMLTag currentTag, SumoXMLAttr perHour);
355 
357  static void fillCarFollowingModelAttributes(SumoXMLTag currentTag);
358 
360  static void fillJunctionModelAttributes(SumoXMLTag currentTag);
361 
363  static void fillLaneChangingModelAttributes(SumoXMLTag currentTag);
364 
366  static void fillCommonPersonAttributes(SumoXMLTag currentTag);
367 
369  static void fillCommonContainerAttributes(SumoXMLTag currentTag);
370 
372  static void fillCommonStopAttributes(SumoXMLTag currentTag);
373 
375  static void fillDataElements();
376 
378  static std::map<SumoXMLTag, GNETagProperties> myTagProperties;
379 
382 
385 };
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
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
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
static void fillCommonStopAttributes(SumoXMLTag currentTag)
fill stop person attributes
GNEAttributeCarrier(const SumoXMLTag tag, GNENet *net)
Constructor.
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 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 fillAdditionals()
fill additional elements
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 const std::string & getID() const =0
return ID of object
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
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
virtual void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)=0
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
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
const std::string & getTagStr() const
get tag assigned to this object in string format
virtual void toogleAttribute(SumoXMLAttr key, const bool value, const int previousParameters)=0
method for enable or disable the attribute and nothing else (used in GNEChange_EnableAttribute)
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
get GUIGlObject associated with this AttributeCarrier
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 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
FXIcon * getIcon() const
get FXIcon associated to this AC
virtual const std::map< std::string, std::string > & getACParametersMap() const =0
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
virtual void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)=0
GNEAttributeCarrier & operator=(const GNEAttributeCarrier &src)=delete
Invalidated assignment operator.
virtual bool isAttributeEnabled(SumoXMLAttr key) const =0
static bool lanesConsecutives(const std::vector< GNELane * > &lanes)
check if lanes are consecutives
void resetDefaultValues()
reset attribute carrier to their default values
virtual bool isAttributeComputed(SumoXMLAttr key) const =0
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
static void fillShapes()
fill shape elements
GNENet * getNet() const
get pointer to net
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 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