Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2023 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// ===========================================================================
32class GNENet;
33class GNEUndoList;
34class GUIGlObject;
36class GNELane;
37class GNEEdge;
38
39// ===========================================================================
40// class definitions
41// ===========================================================================
49
51 friend class GNEChange_Attribute;
55 friend class GNEFlowEditor;
56
57public:
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
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
147 /* @brief method for check if the value for certain attribute is set
148 * @param[in] key The attribute key
149 */
150 bool hasAttribute(SumoXMLAttr key) const {
151 return myTagProperty.hasAttribute(key);
152 }
153
155 virtual std::string getPopUpID() const = 0;
156
158 virtual std::string getHierarchyName() const = 0;
159
161
165 virtual const Parameterised::Map& getACParametersMap() const = 0;
166
168 template<typename T>
170
172 void setACParameters(const std::string& parameters, GNEUndoList* undoList);
173
175 void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList);
176
178 void setACParameters(const Parameterised::Map& parameters, GNEUndoList* undoList);
179
181 void addACParameters(const std::string& key, const std::string& attribute, GNEUndoList* undoList);
182
184 void removeACParametersKeys(const std::vector<std::string>& keepKeys, GNEUndoList* undoList);
185
187
188 /* @brief method for return an alternative value for disabled attributes. Used only in GNEFrames
189 * @param[in] key The attribute key
190 */
192
194 virtual std::string getAttributeForSelection(SumoXMLAttr key) const;
195
197 const std::string& getTagStr() const;
198
200 FXIcon* getACIcon() const;
201
203 bool isTemplate() const;
204
206 const GNETagProperties& getTagProperty() const;
207
209 static const GNETagProperties& getTagProperty(SumoXMLTag tag);
210
212 static const std::vector<GNETagProperties> getTagPropertiesByType(const int tagPropertyCategory);
213
215 template<typename T>
216 static bool canParse(const std::string& string) {
217 try {
218 GNEAttributeCarrier::parse<T>(string);
219 } catch (EmptyData&) {
220 // general
221 return false;
222 } catch (FormatException&) {
223 // numbers, time, boolean, 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
259 static void writeAttributeHelp();
260
264 static const std::string FEATURE_LOADED;
265
267 static const std::string FEATURE_GUESSED;
268
270 static const std::string FEATURE_MODIFIED;
271
273 static const std::string FEATURE_APPROVED;
275
277 static const size_t MAXNUMBEROFATTRIBUTES;
278
281
283 static const std::string True;
284
286 static const std::string False;
287
288protected:
291
294
297
300
302 virtual void toggleAttribute(SumoXMLAttr key, const bool value);
303
304private:
306 virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
307
309 void resetAttributes();
310
312 static void fillAttributeCarriers();
313
315 static void fillNetworkElements();
316
318 static void fillAdditionalElements();
319
321 static void fillShapeElements();
322
324 static void fillTAZElements();
325
327 static void fillWireElements();
328
330 static void fillDemandElements();
331
333 static void fillVehicleElements();
334
336 static void fillStopElements();
337
339 static void fillWaypointElements();
340
342 static void fillPersonElements();
343
345 static void fillPersonPlanTrips();
346
348 static void fillPersonPlanWalks();
349
351 static void fillPersonPlanRides();
352
354 static void fillStopPersonElements();
355
357 static void fillContainerElements();
358
360 static void fillContainerTransportElements();
361
363 static void fillContainerTranshipElements();
364
366 static void fillContainerStopElements();
367
369 static void fillCommonVehicleAttributes(SumoXMLTag currentTag);
370
372 static void fillCommonFlowAttributes(SumoXMLTag currentTag, SumoXMLAttr perHour);
373
375 static void fillCarFollowingModelAttributes(SumoXMLTag currentTag);
376
378 static void fillJunctionModelAttributes(SumoXMLTag currentTag);
379
381 static void fillLaneChangingModelAttributes(SumoXMLTag currentTag);
382
384 static void fillCommonPersonAttributes(SumoXMLTag currentTag);
385
387 static void fillCommonContainerAttributes(SumoXMLTag currentTag);
388
390 static void fillCommonStopAttributes(SumoXMLTag currentTag, const bool waypoint);
391
393 static void fillDataElements();
394
396 static void fillCommonMeanDataAttributes(SumoXMLTag currentTag);
397
399 static std::map<SumoXMLTag, GNETagProperties> myTagProperties;
400
403
406};
#define WRITE_WARNING(msg)
Definition MsgHandler.h:270
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
GNEAttributeCarrier & operator=(const GNEAttributeCarrier &src)=delete
Invalidated assignment operator.
virtual void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
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
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 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 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
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
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
bool isTemplate() const
check if this AC is template
virtual const Parameterised::Map & getACParametersMap() const =0
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
static bool lanesConsecutives(const std::vector< GNELane * > &lanes)
check if lanes are consecutives
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 isValid(SumoXMLAttr key, const std::string &value)=0
virtual GNEHierarchicalElement * getHierarchicalElement()=0
get GNEHierarchicalElement associated with this AttributeCarrier
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
virtual GUIGlObject * getGUIGlObject()=0
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
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