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-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// ===========================================================================
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
76
79
81 bool isAttributeCarrierSelected() const;
82
84 bool drawUsingSelectColor() const;
85
88
91
94
96 bool isMarkedForDrawingFront() const;
97
99 void drawInLayer(const double typeOrLayer, const double extraOffset = 0) const;
100
102
105
109 void setInGrid(bool value);
110
112 bool inGrid() const;
113
115
120
122 virtual const GUIGlObject* getGUIGlObject() const = 0;
123
125 virtual void updateGeometry() = 0;
126
128
131
133 bool checkDrawInspectContour() const;
134
136 bool checkDrawFrontContour() const;
137
139 virtual bool checkDrawFromContour() const = 0;
140
142 virtual bool checkDrawToContour() const = 0;
143
145 virtual bool checkDrawRelatedContour() const = 0;
146
148 virtual bool checkDrawOverContour() const = 0;
149
151 virtual bool checkDrawDeleteContour() const = 0;
152
154 virtual bool checkDrawSelectContour() const = 0;
155
157 virtual bool checkDrawMoveContour() const = 0;
158
160
162 void resetDefaultValues();
163
166 /* @brief method for getting the Attribute of an XML key
167 * @param[in] key The attribute key
168 * @return string with the value associated to key
169 */
170 virtual std::string getAttribute(SumoXMLAttr key) const = 0;
171
172 /* @brief method for setting the attribute and letting the object perform additional changes
173 * @param[in] key The attribute key
174 * @param[in] value The new value
175 * @param[in] undoList The undoList on which to register changes
176 */
177 virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
178
179 /* @brief method for check if new value for certain attribute is valid
180 * @param[in] key The attribute key
181 * @param[in] value The new value
182 */
183 virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;
184
185 /* @brief method for enable attribute
186 * @param[in] key The attribute key
187 * @param[in] undoList The undoList on which to register changes
188 * @note certain attributes can be only enabled, and can produce the disabling of other attributes
189 */
190 virtual void enableAttribute(SumoXMLAttr key, GNEUndoList* undoList);
191
192 /* @brief method for disable attribute
193 * @param[in] key The attribute key
194 * @param[in] undoList The undoList on which to register changes
195 * @note certain attributes can be only enabled, and can produce the disabling of other attributes
196 */
197 virtual void disableAttribute(SumoXMLAttr key, GNEUndoList* undoList);
198
199 /* @brief method for check if the value for certain attribute is set
200 * @param[in] key The attribute key
201 */
202 virtual bool isAttributeEnabled(SumoXMLAttr key) const;
203
204 /* @brief method for check if the value for certain attribute is computed (for example, due a network recomputing)
205 * @param[in] key The attribute key
206 */
207 virtual bool isAttributeComputed(SumoXMLAttr key) const;
208
209 /* @brief method for check if the value for certain attribute is set
210 * @param[in] key The attribute key
211 */
212 bool hasAttribute(SumoXMLAttr key) const {
213 return myTagProperty.hasAttribute(key);
214 }
215
217 virtual std::string getPopUpID() const = 0;
218
220 virtual std::string getHierarchyName() const = 0;
221
223
227 virtual const Parameterised::Map& getACParametersMap() const = 0;
228
230 template<typename T>
232
234 void setACParameters(const std::string& parameters, GNEUndoList* undoList);
235
237 void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList);
238
240 void setACParameters(const Parameterised::Map& parameters, GNEUndoList* undoList);
241
243 void addACParameters(const std::string& key, const std::string& attribute, GNEUndoList* undoList);
244
246 void removeACParametersKeys(const std::vector<std::string>& keepKeys, GNEUndoList* undoList);
247
249
250 /* @brief method for return an alternative value for disabled attributes. Used only in GNEFrames
251 * @param[in] key The attribute key
252 */
254
256 virtual std::string getAttributeForSelection(SumoXMLAttr key) const;
257
259 const std::string& getTagStr() const;
260
262 FXIcon* getACIcon() const;
263
265 bool isTemplate() const;
266
268 const GNETagProperties& getTagProperty() const;
269
271 static const GNETagProperties& getTagProperty(SumoXMLTag tag);
272
274 static const std::vector<GNETagProperties> getTagPropertiesByType(const int tagPropertyCategory, const bool mergeCommonPlans);
275
277 static const std::vector<GNETagProperties> getTagPropertiesByMergingTag(SumoXMLTag mergingTag);
278
280 template<typename T>
281 static bool canParse(const std::string& string) {
282 try {
283 GNEAttributeCarrier::parse<T>(string);
284 } catch (EmptyData&) {
285 // general
286 return false;
287 } catch (FormatException&) {
288 // numbers, time, boolean, colors
289 return false;
290 }
291 return true;
292 }
293
295 template<typename T>
296 static T parse(const std::string& string);
297
299 template<typename T>
300 static bool canParse(GNENet* net, const std::string& value, bool report) {
301 try {
302 parse<T>(net, value);
303 } catch (FormatException& exception) {
304 if (report) {
305 WRITE_WARNING(exception.what())
306 }
307 return false;
308 }
309 return true;
310 }
311
313 template<typename T>
314 static T parse(GNENet* net, const std::string& value);
315
317 template<typename T>
318 static std::string parseIDs(const std::vector<T>& ACs);
319
321 static bool lanesConsecutives(const std::vector<GNELane*>& lanes);
322
324 static void writeAttributeHelp();
325
328
330 static const std::string FEATURE_LOADED;
331
333 static const std::string FEATURE_GUESSED;
334
336 static const std::string FEATURE_MODIFIED;
337
339 static const std::string FEATURE_APPROVED;
340
342
345
348
351
354
357
359 static const std::string True;
360
362 static const std::string False;
363
364protected:
367
369 GNENet* myNet = nullptr;
370
372 bool mySelected = false;
373
375 bool myDrawInFront = false;
376
378 bool myInGrid = false;
379
381 bool myIsTemplate = false;
382
384 virtual void toggleAttribute(SumoXMLAttr key, const bool value);
385
388 /* @brief method for getting the common attribute of an XML key
389 * @param[in] key The attribute key
390 * @return string with the value associated to key
391 */
392 std::string getCommonAttribute(SumoXMLAttr key) const;
393
394 /* @brief method for setting the common attribute and letting the object perform additional changes
395 * @param[in] key The attribute key
396 * @param[in] value The new value
397 * @param[in] undoList The undoList on which to register changes
398 */
399 void setCommonAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList);
400
401 /* @brief method for check if new value for certain common attribute is valid
402 * @param[in] key The attribute key
403 * @param[in] value The new value
404 */
405 bool isCommonValid(SumoXMLAttr key, const std::string& value);
406
408 void setCommonAttribute(SumoXMLAttr key, const std::string& value);
409
411
412private:
414 virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
415
417 void resetAttributes();
418
420 static void fillAttributeCarriers();
421
423 static void fillNetworkElements();
424
426 static void fillAdditionalElements();
427
429 static void fillShapeElements();
430
432 static void fillTAZElements();
433
435 static void fillWireElements();
436
438 static void fillJuPedSimElements();
439
441 static void fillDemandElements();
442
444 static void fillVehicleElements();
445
447 static void fillStopElements();
448
450 static void fillWaypointElements();
451
453 static void fillPersonElements();
454
456 static void fillPersonPlanTrips();
457
459 static void fillPersonPlanWalks();
460
462 static void fillPersonPlanRides();
463
465 static void fillPersonStopElements();
466
468 static void fillContainerElements();
469
471 static void fillContainerTransportElements();
472
474 static void fillContainerTranshipElements();
475
477 static void fillContainerStopElements();
478
480 static void fillCommonAttributes(GNETagProperties& tagProperties);
481
483 static void fillPOIAttributes(GNETagProperties& tagProperties);
484
486 static void fillCommonVehicleAttributes(GNETagProperties& tagProperties);
487
489 static void fillCommonFlowAttributes(GNETagProperties& tagProperties, SumoXMLAttr perHour);
490
492 static void fillCarFollowingModelAttributes(GNETagProperties& tagProperties);
493
495 static void fillJunctionModelAttributes(GNETagProperties& tagProperties);
496
498 static void fillLaneChangingModelAttributes(GNETagProperties& tagProperties);
499
501 static void fillCommonPersonAttributes(GNETagProperties& tagProperties);
502
504 static void fillCommonContainerAttributes(GNETagProperties& tagProperties);
505
507 static void fillCommonStopAttributes(GNETagProperties& tagProperties, const bool waypoint);
508
510 static void fillPlanParentAttributes(GNETagProperties& tagProperties);
511
513 static void fillPersonTripCommonAttributes(GNETagProperties& tagProperties);
514
516 static void fillWalkCommonAttributes(GNETagProperties& tagProperties);
517
519 static void fillRideCommonAttributes(GNETagProperties& tagProperties);
520
522 static void fillTransportCommonAttributes(GNETagProperties& tagProperties);
523
525 static void fillTranshipCommonAttributes(GNETagProperties& tagProperties);
526
528 static void fillPlanStopCommonAttributes(GNETagProperties& tagProperties);
529
531 static void fillDataElements();
532
534 static void fillCommonMeanDataAttributes(GNETagProperties& tagProperties);
535
537 static void updateMaxNumberOfAttributes();
538
540 static std::map<SumoXMLTag, GNETagProperties> myTagProperties;
541
543 static std::map<SumoXMLTag, GNETagProperties> myMergedPlanTagProperties;
544
547
550};
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
SumoXMLTag
Numbers representing SUMO-XML - element names.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
static void fillPersonTripCommonAttributes(GNETagProperties &tagProperties)
fill person trip common attributes
static void fillPlanStopCommonAttributes(GNETagProperties &tagProperties)
fill plan stop common attributes
static int maxNumberOfGeoAttributes
max number of geo attributes (needed for geo attributes editor)
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)
void markForDrawingFront()
mark for drawing front
GNEAttributeCarrier & operator=(const GNEAttributeCarrier &src)=delete
Invalidated assignment operator.
virtual void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
void selectAttributeCarrier()
select attribute carrier using GUIGlobalSelection
static std::map< SumoXMLTag, GNETagProperties > myMergedPlanTagProperties
map with the merged tags properties
virtual bool checkDrawRelatedContour() const =0
check if draw related contour (cyan)
bool isMarkedForDrawingFront() const
check if this AC is marked for drawing front
bool myDrawInFront
boolean to check if drawn this AC over other elements
FXIcon * getACIcon() const
get FXIcon associated to this AC
bool mySelected
boolean to check if this AC is selected (more quickly as checking 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
virtual const GUIGlObject * getGUIGlObject() const =0
get GUIGlObject associated with this AttributeCarrier (constant)
static void fillPlanParentAttributes(GNETagProperties &tagProperties)
fill plan from-to attribute
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 fillDataElements()
fill Data elements
static void fillPersonPlanRides()
fill person plan rides
bool checkDrawFrontContour() const
check if draw front contour (green/blue)
static void updateMaxNumberOfAttributes()
update max number of attributes by type
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)
virtual std::string getPopUpID() const =0
get PopPup ID (Used in AC Hierarchy)
static void fillNetworkElements()
fill network elements
static void fillWalkCommonAttributes(GNETagProperties &tagProperties)
fill walk common attributes
static void fillPersonStopElements()
fill person stop elements
static const std::vector< GNETagProperties > getTagPropertiesByType(const int tagPropertyCategory, const bool mergeCommonPlans)
get tagProperties associated to the given GNETagProperties::TagType (NETWORKELEMENT,...
static void fillTransportCommonAttributes(GNETagProperties &tagProperties)
fill transport 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....
bool myInGrid
boolean to check if this AC is in grid
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 unselectAttributeCarrier()
unselect attribute carrier using GUIGlobalSelection
static int maxNumberOfNeteditAttributes
max number of netedit attributes (needed for netedit attributes editor)
static void fillCommonContainerAttributes(GNETagProperties &tagProperties)
fill common container attributes (used by container and containerFlows)
static void fillTranshipCommonAttributes(GNETagProperties &tagProperties)
fill ride common attributes
static void fillPOIAttributes(GNETagProperties &tagProperties)
fill common POI attributes
static void fillCommonMeanDataAttributes(GNETagProperties &tagProperties)
fill stop person attributes
void removeACParametersKeys(const std::vector< std::string > &keepKeys, GNEUndoList *undoList)
remove keys
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
virtual bool isAttributeEnabled(SumoXMLAttr key) const
const std::string & getTagStr() const
get tag assigned to this object in string format
static void fillCommonVehicleAttributes(GNETagProperties &tagProperties)
fill common vehicle attributes (used by vehicles, trips, routeFlows and flows)
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
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
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
bool isCommonValid(SumoXMLAttr key, const std::string &value)
static bool canParse(GNENet *net, const std::string &value, bool report)
true if a value of type T can be parsed from string
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
static void fillShapeElements()
fill shape elements
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 void fillCommonFlowAttributes(GNETagProperties &tagProperties, SumoXMLAttr perHour)
fill common flow attributes (used by flows, routeFlows and personFlows)
static bool lanesConsecutives(const std::vector< GNELane * > &lanes)
check if lanes are consecutives
bool hasAttribute(SumoXMLAttr key) const
static int maxNumberOfEditableAttributes
max number of editable (non extended) attributes (needed for attributes editor)
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)
static int maxNumberOfFlowAttributes
max number of flow attributes (needed for geo attributes editor)
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
bool inGrid() const
check if this AC was inserted in grid
void unmarkForDrawingFront()
unmark for drawing front
virtual std::string getHierarchyName() const =0
get Hierarchy Name (Used in AC Hierarchy)
static void fillLaneChangingModelAttributes(GNETagProperties &tagProperties)
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
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 fillCommonPersonAttributes(GNETagProperties &tagProperties)
fill common person attributes (used by person and personFlows)
static void fillContainerElements()
fill container elements
static void fillCarFollowingModelAttributes(GNETagProperties &tagProperties)
fill Car Following Model of Vehicle/Person Types
static void fillCommonStopAttributes(GNETagProperties &tagProperties, const bool waypoint)
fill stop person attributes
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
std::string getCommonAttribute(SumoXMLAttr key) const
bool checkDrawInspectContour() const
check if draw inspect contour (black/white)
static const std::vector< GNETagProperties > getTagPropertiesByMergingTag(SumoXMLTag mergingTag)
get tagProperties associated to the given merging tag
static void fillCommonAttributes(GNETagProperties &tagProperties)
fill common POI attributes
static void fillContainerTranshipElements()
fill container tranship elements
virtual GUIGlObject * getGUIGlObject()=0
static void fillRideCommonAttributes(GNETagProperties &tagProperties)
fill ride common attributes
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
static std::map< SumoXMLTag, GNETagProperties > myTagProperties
map with the tags properties
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 fillJunctionModelAttributes(GNETagProperties &tagProperties)
fill Junction Model Attributes of Vehicle/Person Types
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