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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // Abstract Base class for gui objects which carry attributes
16 /****************************************************************************/
17 #ifndef GNEAttributeCarrier_h
18 #define GNEAttributeCarrier_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
27 #include <utils/common/ToString.h>
33 
34 #include "GNEReferenceCounter.h"
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class GNENet;
41 class GNEUndoList;
42 class GNELane;
43 class GNEEdge;
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
56  friend class GNEChange_Attribute;
57 
58 public:
60  enum AttrProperty {
61  ATTRPROPERTY_INT = 1 << 0, // Attribute is an integer (Including Zero)
62  ATTRPROPERTY_FLOAT = 1 << 1, // Attribute is a float
63  ATTRPROPERTY_BOOL = 1 << 2, // Attribute is boolean (0/1, true/false)
64  ATTRPROPERTY_STRING = 1 << 3, // Attribute is a string
65  ATTRPROPERTY_POSITION = 1 << 4, // Attribute is a position defined by doubles (x,y or x,y,z)
66  ATTRPROPERTY_COLOR = 1 << 5, // Attribute is a color defined by a specifically word (Red, green) or by a special format (XXX,YYY,ZZZ)
67  ATTRPROPERTY_VCLASS = 1 << 6, // Attribute is a VClass (passenger, bus, motorcicle...)
68  ATTRPROPERTY_POSITIVE = 1 << 7, // Attribute is positive (Including Zero)
69  ATTRPROPERTY_NOTZERO = 1 << 8, // Attribute cannot be 0 (only for numerical attributes)
70  ATTRPROPERTY_UNIQUE = 1 << 9, // Attribute is unique (cannot be edited in a selection of similar elements (ID, Position...)
71  ATTRPROPERTY_FILENAME = 1 << 10, // Attribute is a filename (string that cannot contains certain characters)
72  ATTRPROPERTY_NONEDITABLE = 1 << 11, // Attribute is non editable (index of a lane)
73  ATTRPROPERTY_DISCRETE = 1 << 12, // Attribute is discrete (only certain values are allowed)
74  ATTRPROPERTY_PROBABILITY = 1 << 13, // Attribute is probability (only allowed values between 0 and 1, including both)
75  ATTRPROPERTY_TIME = 1 << 14, // Attribute is a Time (float positive)
76  ATTRPROPERTY_ANGLE = 1 << 15, // Attribute is an angle (only takes values between 0 and 360, including both, another value will be automatically reduced
77  ATTRPROPERTY_LIST = 1 << 16, // Attribute is a list of other elements separated by spaces
78  ATTRPROPERTY_SECUENCIAL = 1 << 17, // Attribute is a special sequence of elements (for example: secuencial lanes in Multi Lane E2 detectors)
79  ATTRPROPERTY_OPTIONAL = 1 << 18, // Attribute is optional
80  ATTRPROPERTY_DEFAULTVALUE = 1 << 19, // Attribute owns a default value
81  ATTRPROPERTY_COMBINABLE = 1 << 20, // Attribute is combinable with other Attribute
82  ATTRPROPERTY_SYNONYM = 1 << 21, // Attribute will be written with a different name in der XML
83  ATTRPROPERTY_RANGE = 1 << 22, // Attribute only accept a range of elements
84  };
85 
88  public:
91 
93  AttributeProperties(int attributeProperty, int positionListed, const std::string& definition, const std::string& defaultValue, const std::vector<std::string>& discreteValues, SumoXMLAttr synonym, double minimum = 0, double maximum = 0);
94 
97 
100 
102  int getPositionListed() const;
103 
105  const std::string& getDefinition() const;
106 
108  const std::string& getDefaultValue() const;
109 
111  std::string getDescription() const;
112 
114  const std::vector<std::string>& getDiscreteValues() const;
115 
117  SumoXMLAttr getAttrSynonym() const;
118 
120  double getMinimumRange() const;
121 
123  double getMaximumRange() const;
124 
126  bool hasDefaultValue() const;
127 
129  bool hasAttrSynonym() const;
130 
132  bool hasAttrRange() const;
133 
135  bool isInt() const;
136 
138  bool isFloat() const;
139 
141  bool isBool() const;
142 
144  bool isString() const;
145 
147  bool isposition() const;
148 
150  bool isProbability() const;
151 
153  bool isNumerical() const;
154 
156  bool isTime() const;
157 
159  bool isPositive() const;
160 
162  bool cannotBeZero() const;
163 
165  bool isColor() const;
166 
168  bool isFilename() const;
169 
171  bool isVClass() const;
172 
174  bool isSVCPermission() const;
175 
177  bool isList() const;
178 
180  bool isSecuential() const;
181 
183  bool isUnique() const;
184 
186  bool isOptional() const;
187 
189  bool isDiscrete() const;
190 
192  bool isCombinable() const;
193 
195  bool isNonEditable() const;
196 
197  private:
200 
203 
205  std::string myDefinition;
206 
208  std::string myDefaultValue;
209 
211  std::vector<std::string> myDiscreteValues;
212 
215 
218 
221  };
222 
223  enum TAGProperty {
224  TAGPROPERTY_NETELEMENT = 1 << 0, // Edges, Junctions, Lanes...
225  TAGPROPERTY_ADDITIONAL = 1 << 1, // Bus Stops, Charging Stations, Detectors...
226  TAGPROPERTY_SHAPE = 1 << 2, // POIs, Polygons
227  TAGPROPERTY_TAZ = 1 << 3, // Traffic Assignment Zones
228  TAGPROPERTY_STOPPINGPLACE = 1 << 4, // StoppingPlaces (BusStops, ChargingStations...)
229  TAGPROPERTY_DETECTOR = 1 << 5, // Detectors (E1, E2...)
230  TAGPROPERTY_ROUTEELEMENT = 1 << 6, // VTypes, Vehicles, Flows...
231  TAGPROPERTY_DRAWABLE = 1 << 7, // Element can be drawed in view
232  TAGPROPERTY_BLOCKMOVEMENT = 1 << 8, // Element can block their movement
233  TAGPROPERTY_BLOCKSHAPE = 1 << 9, // Element can block their shape
234  TAGPROPERTY_CLOSESHAPE = 1 << 10, // Element can close their shape
235  TAGPROPERTY_GEOPOSITION = 1 << 11, // Element's position can be defined using a GEO position
236  TAGPROPERTY_GEOSHAPE = 1 << 12, // Element's shape acn be defined using a GEO Shape
237  TAGPROPERTY_DIALOG = 1 << 13, // Element can be edited using a dialog (GNECalibratorDialog, GNERerouterDialog...)
238  TAGPROPERTY_PARENT = 1 << 14, // Element will be writed in XML as child of another element (E3Entry -> E3Detector...)
239  TAGPROPERTY_MINIMUMCHILDS = 1 << 15, // Element will be only writed in XML if has a minimum number of childs
240  TAGPROPERTY_REPARENT = 1 << 16, // Element can be reparent
241  TAGPROPERTY_SYNONYM = 1 << 17, // Element will be written with a different name in der XML
242  TAGPROPERTY_AUTOMATICSORTING = 1 << 18, // Element sort automatic their Childs (used by Additionals)
243  TAGPROPERTY_SELECTABLE = 1 << 19, // Element is selectable
244  TAGPROPERTY_MASKSTARTENDPOS = 1 << 20, // Element mask attributes StartPos and EndPos as "lenght" (Only used in the appropiate GNEFrame)
245  TAGPROPERTY_MASKXYZPOSITION = 1 << 21, // Element mask attributes X, Y and Z as "Position"
246  TAGPROPERTY_WRITECHILDSSEPARATE = 1 << 22, // Element writes their childs in a separated filename
247  TAGPROPERTY_PLACEDOVER_VIEW = 1 << 23, // Element will be placed in view
248  TAGPROPERTY_PLACEDOVER_EDGE = 1 << 24, // Element will be placed over an edge
249  TAGPROPERTY_PLACEDOVER_LANE = 1 << 25, // Element will be placed over a lane
250  TAGPROPERTY_PLACEDOVER_JUNCTION = 1 << 26, // Element will be placed over a junction
251  TAGPROPERTY_PLACEDOVER_EDGES = 1 << 27, // Element will be placed over a list of edges
252  TAGPROPERTY_PLACEDOVER_LANES = 1 << 28, // Element will be placed over a list of lanes
253  TAGPROPERTY_NOGENERICPARAMETERS = 1 << 29, // Element doesn't accept Generic Parameters (by default all tags supports generic parameters)
254  };
255 
258  public:
260  TagProperties();
261 
263  TagProperties(SumoXMLTag tag, int tagProperty, int &positionListed, GUIIcon icon, SumoXMLTag parentTag = SUMO_TAG_NOTHING, SumoXMLTag tagSynonym = SUMO_TAG_NOTHING);
264 
266  ~TagProperties();
267 
269  SumoXMLTag getTag() const;
270 
272  const std::string &getTagStr() const;
273 
275  void checkTagIntegrity() const;
276 
278  void addAttribute(SumoXMLAttr attr, const int attributeProperty, const std::string& definition, const std::string& defaultValue, std::vector<std::string> discreteValues = std::vector<std::string>(), SumoXMLAttr synonym = SUMO_ATTR_NOTHING);
279 
281  void addAttribute(SumoXMLAttr attr, const int attributeProperty, const std::string& definition, const std::string& defaultValue, SumoXMLAttr synonym);
282 
284  void addAttribute(SumoXMLAttr attr, const int attributeProperty, const std::string& definition, const std::string& defaultValue, double minimum, double maximum);
285 
287  void addDeprecatedAttribute(SumoXMLAttr attr);
288 
290  const AttributeProperties& getAttributeProperties(SumoXMLAttr attr) const;
291 
293  std::map<SumoXMLAttr, AttributeProperties>::const_iterator begin() const;
294 
296  std::map<SumoXMLAttr, AttributeProperties>::const_iterator end() const;
297 
299  int getNumberOfAttributes() const;
300 
302  const std::string& getDefaultValue(SumoXMLAttr attr) const;
303 
305  GUIIcon getGUIIcon() const;
306 
308  int getPositionListed() const;
309 
311  SumoXMLTag getParentTag() const;
312 
314  SumoXMLTag getTagSynonym() const;
315 
317  bool hasAttribute(SumoXMLAttr attr) const;
318 
320  bool isNetElement() const;
321 
323  bool isAdditional() const;
324 
326  bool isShape() const;
327 
329  bool isTAZ() const;
330 
332  bool isStoppingPlace() const;
333 
335  bool isDetector() const;
336 
338  bool isDrawable() const;
339 
341  bool isSelectable() const;
342 
344  bool canBlockMovement() const;
345 
347  bool canBlockShape() const;
348 
350  bool canCloseShape() const;
351 
353  bool hasGEOPosition() const;
354 
356  bool hasGEOShape() const;
357 
359  bool hasParent() const;
360 
362  bool hasTagSynonym() const;
363 
365  bool hasDialog() const;
366 
368  bool hasMinimumNumberOfChilds() const;
369 
371  bool hasGenericParameters() const;
372 
374  bool canBeReparent() const;
375 
377  bool canAutomaticSortChilds() const;
378 
380  bool canWriteChildsSeparate() const;
381 
383  bool canBePlacedOverView() const;
384 
386  bool canBePlacedOverEdge() const;
387 
389  bool canBePlacedOverLane() const;
390 
392  bool canBePlacedOverJunction() const;
393 
395  bool canBePlacedOverEdges() const;
396 
398  bool canBePlacedOverLanes() const;
399 
401  bool canMaskStartEndPos() const;
402 
404  bool canMaskXYZPositions() const;
405 
407  bool isAttributeDeprecated(SumoXMLAttr attr) const;
408 
409  private:
412 
414  std::string myTagStr;
415 
418 
420  std::map<SumoXMLAttr, AttributeProperties> myAttributeProperties;
421 
424 
427 
430 
433 
435  std::vector<SumoXMLAttr> myDeprecatedAttributes;
436  };
437 
443 
445  virtual ~GNEAttributeCarrier() {};
446 
450  virtual void selectAttributeCarrier(bool changeFlag = true) = 0;
451 
453  virtual void unselectAttributeCarrier(bool changeFlag = true) = 0;
454 
456  virtual bool isAttributeCarrierSelected() const = 0;
457 
458  /* @brief method for getting the Attribute of an XML key
459  * @param[in] key The attribute key
460  * @return string with the value associated to key
461  */
462  virtual std::string getAttribute(SumoXMLAttr key) const = 0;
463 
464  /* @brief method for setting the attribute and letting the object perform additional changes
465  * @param[in] key The attribute key
466  * @param[in] value The new value
467  * @param[in] undoList The undoList on which to register changes
468  * @param[in] net optionally the GNENet to inform about gui updates
469  */
470  virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
471 
472  /* @brief method for setting the attribute and letting the object perform additional changes
473  * @param[in] key The attribute key
474  * @param[in] value The new value
475  * @param[in] undoList The undoList on which to register changes
476  */
477  virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;
478 
480  virtual std::string getPopUpID() const = 0;
481 
483  virtual std::string getHierarchyName() const = 0;
485 
489  static const std::string FEATURE_LOADED;
490 
492  static const std::string FEATURE_GUESSED;
493 
495  static const std::string FEATURE_MODIFIED;
496 
498  static const std::string FEATURE_APPROVED;
500 
502  virtual std::string getAttributeForSelection(SumoXMLAttr key) const;
503 
505  const std::string &getTagStr() const;
506 
508  const TagProperties &getTagProperty() const;
509 
511  FXIcon* getIcon() const;
512 
514  const std::string getID() const;
515 
517  static const TagProperties& getTagProperties(SumoXMLTag tag);
518 
520  static std::vector<SumoXMLTag> allowedTags(bool onlyDrawables);
521 
523  static std::vector<SumoXMLTag> allowedTagsByCategory(int tagPropertyCategory, bool onlyDrawables);
524 
526  static int getHigherNumberOfAttributes();
527 
530 
532  virtual std::string getGenericParametersStr() const = 0;
533 
535  virtual std::vector<std::pair<std::string, std::string> > getGenericParameters() const = 0;
536 
538  virtual void setGenericParametersStr(const std::string& value) = 0;
539 
541 
543  static bool isGenericParametersValid(const std::string& value);
544 
546  template<typename T>
547  static bool canParse(const std::string& string) {
548  try {
549  parse<T>(string);
550  } catch (NumberFormatException&) {
551  return false;
552  } catch (EmptyData&) {
553  return false;
554  } catch (BoolFormatException&) {
555  return false;
556  }
557  return true;
558  }
559 
561  template<typename T>
562  static T parse(const std::string& string);
563 
565  template<typename T>
566  static bool canParse(GNENet* net, const std::string& value, bool report) {
567  try {
568  parse<T>(net, value);
569  } catch (FormatException& exception) {
570  if (report) {
571  WRITE_WARNING(exception.what())
572  }
573  return false;
574  }
575  return true;
576  }
577 
579  template<typename T>
580  static T parse(GNENet* net, const std::string& value);
581 
583  template<typename T>
584  static std::string parseIDs(const std::vector<T>& ACs);
585 
587  static bool lanesConsecutives(const std::vector<GNELane*>& lanes);
588 
590  template <typename T>
591  static T parseAttributeFromXML(const SUMOSAXAttributes& attrs, const std::string& objectID, const SumoXMLTag tag, const SumoXMLAttr attribute, bool& abort) {
592  bool parsedOk = true;
593  // @brief declare string values
594  std::string defaultValue, parsedAttribute, additionalOfWarningMessage;
595  // obtain tag properties
596  const auto& tagProperties = getTagProperties(tag);
597  // first check if attribute is deprecated
598  if (tagProperties.isAttributeDeprecated(attribute)) {
599  // show warning if deprecateda ttribute is in the SUMOSAXAttributes
600  if (attrs.hasAttribute(attribute)) {
601  WRITE_WARNING("Attribute " + toString(attribute) + "' of " + tagProperties.getTagStr() + " is deprecated and will not be loaded.");
602  }
603  // return a dummy value
604  return parse<T>("");
605  }
606  // obtain attribute properties (Only for improving efficiency)
607  const auto& attrProperties = tagProperties.getAttributeProperties(attribute);
608  // check if we're obtaining attribute of an object with an already parsed ID
609  if (objectID != "") {
610  additionalOfWarningMessage = tagProperties.getTagStr() + " with ID '" + objectID + "'";
611  } else {
612  additionalOfWarningMessage = tagProperties.getTagStr();
613  }
614  // set a special default value for numerical and boolean attributes (To avoid errors parsing)
615  if (attrProperties.isNumerical() || attrProperties.isBool()) {
616  defaultValue = "0";
617  } else if (attrProperties.isColor()) {
618  defaultValue = "black";
619  } else if (attrProperties.isposition()) {
620  defaultValue = "0,0";
621  }
622  // first check that attribute exists in XML
623  if (attrs.hasAttribute(attribute)) {
624  // First check if attribute can be parsed to string
625  parsedAttribute = attrs.get<std::string>(attribute, objectID.c_str(), parsedOk, false);
626  // check that sucesfully parsed attribute can be converted to type T
627  if (parsedOk && !canParse<T>(parsedAttribute)) {
628  parsedOk = false;
629  }
630  // declare a string for details about error formats
631  std::string errorFormat;
632  // set extra check for ID Values
633  if (attribute == SUMO_ATTR_ID) {
634  if (parsedAttribute.empty()) {
635  errorFormat = "ID cannot be empty; ";
636  parsedOk = false;
637  } else if (tagProperties.isDetector()) {
638  // special case for detectors (because in this case empty spaces are allowed)
639  if (SUMOXMLDefinitions::isValidDetectorID(parsedAttribute) == false) {
640  errorFormat = "Detector ID contains invalid characters; ";
641  parsedOk = false;
642  }
643  } else if (SUMOXMLDefinitions::isValidNetID(parsedAttribute) == false) {
644  errorFormat = "ID contains invalid characters; ";
645  parsedOk = false;
646  }
647  }
648  // Set extra checks for int values
649  if (attrProperties.isInt()) {
650  if (canParse<int>(parsedAttribute)) {
651  // obtain int value
652  int parsedIntAttribute = parse<int>(parsedAttribute);
653  // check if attribute can be negative or zero
654  if (attrProperties.isPositive() && (parsedIntAttribute < 0)) {
655  errorFormat = "Cannot be negative; ";
656  parsedOk = false;
657  } else if (attrProperties.cannotBeZero() && (parsedIntAttribute == 0)) {
658  errorFormat = "Cannot be zero; ";
659  parsedOk = false;
660  }
661  } else if (canParse<double>(parsedAttribute)) {
662  errorFormat = "Float cannot be reinterpreted as int; ";
663  parsedOk = false;
664  } else {
665  errorFormat = "Cannot be parsed to int; ";
666  parsedOk = false;
667  }
668  }
669  // Set extra checks for float(double) values
670  if (attrProperties.isFloat()) {
671  if (canParse<double>(parsedAttribute)) {
672  // obtain double value
673  double parsedDoubleAttribute = parse<double>(parsedAttribute);
674  //check if can be negative and Zero
675  if (attrProperties.isPositive() && (parsedDoubleAttribute < 0)) {
676  errorFormat = "Cannot be negative; ";
677  parsedOk = false;
678  } else if (attrProperties.cannotBeZero() && (parsedDoubleAttribute == 0)) {
679  errorFormat = "Cannot be zero; ";
680  parsedOk = false;
681  }
682  } else {
683  errorFormat = "Cannot be parsed to float; ";
684  parsedOk = false;
685  }
686  }
687  // Set extra checks for position values
688  if (attrProperties.isposition()) {
689  // check if we're parsing a single position or an entire shape
690  if (attrProperties.isList()) {
691  // check if parsed attribute can be parsed to Position Vector
692  if(!canParse<PositionVector>(parsedAttribute)) {
693  errorFormat = "List of Positions aren't neither x,y nor x,y,z; ";
694  parsedOk = false;
695  }
696  } else if (!canParse<Position>(parsedAttribute)) {
697  errorFormat = "Position is neither x,y nor x,y,z; ";
698  parsedOk = false;
699  }
700  }
701  // set extra check for time(double) values
702  if (attrProperties.isTime()) {
703  if (canParse<double>(parsedAttribute)) {
704  // parse to SUMO Real and check if is negative
705  if (parse<double>(parsedAttribute) < 0) {
706  errorFormat = "Time cannot be negative; ";
707  parsedOk = false;
708  }
709  } else {
710  errorFormat = "Cannot be parsed to time; ";
711  parsedOk = false;
712  }
713  }
714  // set extra check for probability values
715  if (attrProperties.isProbability()) {
716  if (canParse<double>(parsedAttribute)) {
717  // parse to double and check if is between [0,1]
718  double probability = parse<double>(parsedAttribute);
719  if (probability < 0) {
720  errorFormat = "Probability cannot be smaller than 0; ";
721  parsedOk = false;
722  } else if (probability > 1) {
723  errorFormat = "Probability cannot be greather than 1; ";
724  parsedOk = false;
725  }
726  } else {
727  errorFormat = "Cannot be parsed to probability; ";
728  parsedOk = false;
729  }
730  }
731  // set extra check for range values
732  if (attrProperties.hasAttrRange()) {
733  if (canParse<double>(parsedAttribute)) {
734  // parse to double and check if is in range
735  double range = parse<double>(parsedAttribute);
736  if (range < attrProperties.getMinimumRange()) {
737  errorFormat = "Float cannot be smaller than " + toString(attrProperties.getMinimumRange())+ "; ";
738  parsedOk = false;
739  } else if (range > attrProperties.getMaximumRange()) {
740  errorFormat = "Float cannot be greather than " + toString(attrProperties.getMaximumRange())+ "; ";
741  parsedOk = false;
742  }
743  } else {
744  errorFormat = "Cannot be parsed to float; ";
745  parsedOk = false;
746  }
747  }
748  // set extra check for discrete values
749  if (attrProperties.isDiscrete()) {
750  // search value in the list of discretes values of attribute properties
751  auto finder = std::find(attrProperties.getDiscreteValues().begin(), attrProperties.getDiscreteValues().end(), parsedAttribute);
752  // check if attribute is valid
753  if (finder == attrProperties.getDiscreteValues().end()) {
754  errorFormat = "value is not within the set of allowed values for attribute '" + toString(attribute) + "'";
755  parsedOk = false;
756  }
757  }
758  // set extra check for color values
759  if (attrProperties.isColor() && !canParse<RGBColor>(parsedAttribute)) {
760  errorFormat = "Invalid RGB format or named color; ";
761  parsedOk = false;
762  }
763  // set extra check for filename values
764  if (attrProperties.isFilename()) {
765  if (SUMOXMLDefinitions::isValidFilename(parsedAttribute) == false) {
766  errorFormat = "Filename contains invalid characters; ";
767  parsedOk = false;
768  } else if (parsedAttribute.empty()) {
769  errorFormat = "Filename cannot be empty; ";
770  parsedOk = false;
771  }
772  }
773  // set extra check for name values
774  if ((attribute == SUMO_ATTR_NAME) && !SUMOXMLDefinitions::isValidAttribute(parsedAttribute)) {
775  errorFormat = "name contains invalid characters; ";
776  parsedOk = false;
777  }
778  // set extra check for SVCPermissions values
779  if (attrProperties.isVClass()) {
780  if (!canParseVehicleClasses(parsedAttribute)) {
781  errorFormat = "List of VClasses isn't valid; ";
782  parsedAttribute = defaultValue;
783  parsedOk = false;
784  }
785  }
786  // set extra check for Vehicle Classes
787  if ((!parsedOk) && (attribute == SUMO_ATTR_VCLASS)) {
788  errorFormat = "Is not a part of defined set of Vehicle Classes; ";
789  }
790  // set extra check for Vehicle Classes
791  if ((!parsedOk) && (attribute == SUMO_ATTR_GUISHAPE)) {
792  errorFormat = "Is not a part of defined set of Gui Vehicle Shapes; ";
793  }
794  // set extra check for RouteProbes
795  if ((attribute == SUMO_ATTR_ROUTEPROBE) && !SUMOXMLDefinitions::isValidNetID(parsedAttribute)) {
796  errorFormat = "RouteProbe ID contains invalid characters; ";
797  parsedOk = false;
798  }
799  // set extra check for list of edges
800  if ((attribute == SUMO_ATTR_EDGES) && parsedAttribute.empty()) {
801  errorFormat = "List of edges cannot be empty; ";
802  parsedOk = false;
803  }
804  // set extra check for list of lanes
805  if ((attribute == SUMO_ATTR_LANES) && parsedAttribute.empty()) {
806  errorFormat = "List of lanes cannot be empty; ";
807  parsedOk = false;
808  }
809  // set extra check for list of VTypes
810  if ((attribute == SUMO_ATTR_VTYPES) && !parsedAttribute.empty() && !SUMOXMLDefinitions::isValidListOfTypeID(parsedAttribute)) {
811  errorFormat = "List of vTypes contains invalid characters; ";
812  parsedOk = false;
813  }
814  // set extra check for list of RouteProbe
815  if ((attribute == SUMO_ATTR_ROUTEPROBE) && !parsedAttribute.empty() && !SUMOXMLDefinitions::isValidNetID(parsedAttribute)) {
816  errorFormat = "RouteProbe ID contains invalid characters; ";
817  parsedOk = false;
818  }
819  // If attribute has an invalid format
820  if (!parsedOk) {
821  // if attribute is optional and has a default value, obtain it as string. In other case, abort.
822  if (attrProperties.isOptional() && attrProperties.hasDefaultValue()) {
823  parsedAttribute = attrProperties.getDefaultValue();
824  } else {
825  WRITE_WARNING("Format of essential " + attrProperties.getDescription() + " attribute '" + toString(attribute) + "' of " +
826  additionalOfWarningMessage + " is invalid; " + errorFormat + tagProperties.getTagStr() + " cannot be created");
827  // abort parsing (and creation) of element
828  abort = true;
829  // set default value (To avoid errors in parse<T>(parsedAttribute))
830  parsedAttribute = defaultValue;
831  }
832  }
833  } else if (tagProperties.canMaskXYZPositions() && (attribute == SUMO_ATTR_POSITION)) {
834  // if element can mask their XYPosition, then must be extracted X Y coordiantes separeted
835  std::string x, y, z;
836  // give a default value to parsedAttribute to avoid problem parsing invalid positions
837  parsedAttribute="0,0";
838  if(attrs.hasAttribute(SUMO_ATTR_X)) {
839  x = attrs.get<std::string>(SUMO_ATTR_X, objectID.c_str(), parsedOk, false);
840  // check that X attribute is valid
841  if(!canParse<double>(x)) {
842  WRITE_WARNING("Format of essential " + attrProperties.getDescription() + " attribute '" + toString(SUMO_ATTR_X) + "' of " +
843  additionalOfWarningMessage + " is invalid; Cannot be parsed to float; " + tagProperties.getTagStr() + " cannot be created");
844  // abort parsing (and creation) of element
845  abort = true;
846  }
847  } else {
848  WRITE_WARNING("Essential " + attrProperties.getDescription() + " attribute '" + toString(SUMO_ATTR_X) + "' of " +
849  additionalOfWarningMessage + " is missing; " + tagProperties.getTagStr() + " cannot be created");
850  // abort parsing (and creation) of element
851  abort = true;
852  }
853  if(attrs.hasAttribute(SUMO_ATTR_Y)) {
854  y = attrs.get<std::string>(SUMO_ATTR_Y, objectID.c_str(), parsedOk, false);
855  // check that X attribute is valid
856  if(!canParse<double>(y)) {
857  WRITE_WARNING("Format of essential " + attrProperties.getDescription() + " attribute '" + toString(SUMO_ATTR_Y) + "' of " +
858  additionalOfWarningMessage + " is invalid; Cannot be parsed to float; " + tagProperties.getTagStr() + " cannot be created");
859  // abort parsing (and creation) of element
860  abort = true;
861  }
862  } else {
863  WRITE_WARNING("Essential " + attrProperties.getDescription() + " attribute '" + toString(SUMO_ATTR_Y) + "' of " +
864  additionalOfWarningMessage + " is missing; " + tagProperties.getTagStr() + " cannot be created");
865  // abort parsing (and creation) of element
866  abort = true;
867  }
868  // Z attribute is optional
869  if(attrs.hasAttribute(SUMO_ATTR_Z)) {
870  z = attrs.get<std::string>(SUMO_ATTR_Z, objectID.c_str(), parsedOk, false);
871  // check that Z attribute is valid
872  if(!canParse<double>(z)) {
873  WRITE_WARNING("Format of optional " + attrProperties.getDescription() + " attribute '" + toString(SUMO_ATTR_Z) + "' of " +
874  additionalOfWarningMessage + " is invalid; Cannot be parsed to float; " + tagProperties.getTagStr() + " cannot be created");
875  // leave Z attribute empty
876  z.clear();
877  }
878  }
879  // create Position attribute using parsed coordinates X, Y and, optionally, Z
880  if(!abort) {
881  if(z.empty()) {
882  parsedAttribute = x + "," + y;
883  } else {
884  parsedAttribute = x + "," + y + "," + z;
885  }
886  }
887  } else {
888  // if attribute is optional and has a default value, obtain it. In other case, abort.
889  if (attrProperties.isOptional() && attrProperties.hasDefaultValue()) {
890  parsedAttribute = attrProperties.getDefaultValue();
891  } else {
892  WRITE_WARNING("Essential " + attrProperties.getDescription() + " attribute '" + toString(attribute) + "' of " +
893  additionalOfWarningMessage + " is missing; " + tagProperties.getTagStr() + " cannot be created");
894  // abort parsing (and creation) of element
895  abort = true;
896  // set default value (To avoid errors in parse<T>(parsedAttribute))
897  parsedAttribute = defaultValue;
898  }
899  }
900  // return parsed attribute
901  return parse<T>(parsedAttribute);
902  }
903 
905  static int getCircleResolution(const GUIVisualizationSettings& settings);
906 
907 protected:
909  virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
910 
912  virtual void mouseOverObject(const GUIVisualizationSettings& s) const = 0;
913 
916 
919 
922 
923 private:
925  static void fillAttributeCarriers();
926 
928  static std::map<SumoXMLTag, TagProperties> myTagProperties;
929 
931  GNEAttributeCarrier(const GNEAttributeCarrier&) = delete;
932 
934  GNEAttributeCarrier& operator=(const GNEAttributeCarrier& src) = delete;
935 };
936 
937 #endif
938 
939 /****************************************************************************/
940 
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
static const std::string FEATURE_APPROVED
feature has been approved but not changed (i.e. after being reguessed)
const TagProperties & myTagProperty
the xml tag to which this attribute carrier corresponds
bool hasAttrRange() const
return true if Attr correspond to an element that only accept a range of values
static const std::string FEATURE_MODIFIED
feature has been manually modified (implies approval)
static const TagProperties & getTagProperties(SumoXMLTag tag)
get Tag Properties
SumoXMLTag
Numbers representing SUMO-XML - element names.
GUIIcon myIcon
icon associated to this Tag
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
static bool isValidListOfTypeID(const std::string &value)
whether the given string is a valid list of ids for an edge or vehicle type (empty aren&#39;t allowed) ...
SumoXMLAttr getAttrSynonym() const
get tag synonym
GNEAttributeCarrier & operator=(const GNEAttributeCarrier &src)=delete
Invalidated assignment operator.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:36
bool isCombinable() const
return true if atribute is combinable with other Attribute
Stores the information about how to visualize structures.
std::string myDefaultValue
default value (by default empty)
struct with the attribute Properties
bool isFilename() const
return true if atribute is a filename
bool isPositive() const
return true if atribute is positive
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
static int getHigherNumberOfAttributes()
return the number of attributes of the tag with the most highter number of attributes ...
static T parseAttributeFromXML(const SUMOSAXAttributes &attrs, const std::string &objectID, const SumoXMLTag tag, const SumoXMLAttr attribute, bool &abort)
Parse attribute from XML and show warnings if there are problems parsing it.
void checkAttributeIntegrity()
check Attribute integrity (For example, throw an exception if tag has a Float default value...
bool isposition() const
return true if atribute is a position
static std::vector< SumoXMLTag > allowedTagsByCategory(int tagPropertyCategory, bool onlyDrawables)
get tags of all editable element types using TagProperty Type (TAGPROPERTY_NETELEMENT, TAGPROPERTY_ADDITIONAL, etc.)
FXIcon * getIcon() const
get FXIcon associated to this AC
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:77
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
bool isNumerical() const
return true if atribute is numerical (int or float)
bool isSecuential() const
return true if atribute is sequential
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
SumoXMLAttr myAttrSynonym
Attribute written in XML (If is SUMO_ATTR_NOTHING), original Attribute will be written) ...
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
virtual std::string getAttribute(SumoXMLAttr key) const =0
bool cannotBeZero() const
return true if atribute cannot be zero
virtual std::vector< std::pair< std::string, std::string > > getGenericParameters() const =0
return generic parameters as vector of pairs format
int getPositionListed() const
get position in list (used in frames for listing attributes with certain sort)
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
SumoXMLTag myTag
Sumo XML Tag vinculated wit this tag Property.
bool isProbability() const
return true if atribute is a probability
bool isNonEditable() const
return true if atribute isn&#39;t editable
virtual void selectAttributeCarrier(bool changeFlag=true)=0
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
bool isInt() const
return true if atribute is an integer
static TagProperties dummyTagProperty
dummy TagProperty used for reference some elements (for Example, dummyEdge)
bool isList() const
return true if atribute is a list
bool isColor() const
return true if atribute is a color
static std::vector< SumoXMLTag > allowedTags(bool onlyDrawables)
get tags of all editable element types
the function-object for an editing operation (abstract base)
virtual std::string getPopUpID() const =0
get PopPup ID (Used in AC Hierarchy)
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
double getMaximumRange() const
get maximum range
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
std::vector< std::string > myDiscreteValues
discrete values that can take this Attribute (by default empty)
Encapsulated SAX-Attributes.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
bool isBool() const
return true if atribute is boolean
std::string getDescription() const
return a description of attribute
static void fillAttributeCarriers()
fill Attribute Carriers
static bool lanesConsecutives(const std::vector< GNELane *> &lanes)
check if lanes are consecutives
double getMinimumRange() const
get minimum range
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
static bool isValidDetectorID(const std::string &value)
whether the given string is a valid id for an detector
virtual bool isAttributeCarrierSelected() const =0
check if attribute carrier is selected
AttrProperty
struct with the tag Properties
static const std::string FEATURE_GUESSED
feature has been reguessed (may still be unchanged be we can&#39;t tell (yet)
invalid attribute
bool isUnique() const
return true if atribute is unique
std::map< SumoXMLAttr, AttributeProperties > myAttributeProperties
map with the attribute values vinculated with this Tag
bool isVClass() const
return true if atribute is a VehicleClass
bool isSVCPermission() const
return true if atribute is a VehicleClass
const std::string getID() const
function to support debugging
virtual ~GNEAttributeCarrier()
Destructor.
static bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element
bool canParseVehicleClasses(const std::string &classes)
Checks whether the given string contains only known vehicle classes.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
bool isDiscrete() const
return true if atribute is discrete
GNEAttributeCarrier(SumoXMLTag tag)
Constructor.
bool isFloat() const
return true if atribute is a float
static bool canParse(GNENet *net, const std::string &value, bool report)
true if a value of type T can be parsed from string
int myTagProperty
Property of attribute.
virtual std::string getAttributeForSelection(SumoXMLAttr key) const
method for getting the attribute in the context of object selection
std::string myDefinition
text with a definition of attribute
struct with the attribute Properties
const std::vector< std::string > & getDiscreteValues() const
get discrete values
const std::string & getTagStr() const
get tag assigned to this object in string format
bool isString() const
return true if atribute is a string
bool hasAttrSynonym() const
return true if Attr correspond to an element that will be written in XML with another name ...
virtual std::string getGenericParametersStr() const =0
return generic parameters in string format
static int getCircleResolution(const GUIVisualizationSettings &settings)
function to calculate circle resolution for all circles drawn in drawGL(...) functions ...
bool hasDefaultValue() const
return true if attribute owns a default value
static const std::string FEATURE_LOADED
virtual std::string getHierarchyName() const =0
get Hierarchy Name (Used in AC Hierarchy)
const std::string & getDefaultValue() const
get default value
const TagProperties & getTagProperty() const
get Tag Property assigned to this object
virtual void unselectAttributeCarrier(bool changeFlag=true)=0
unselect attribute carrier using GUIGlobalSelection
bool isTime() const
return true if atribute is time
std::vector< SumoXMLAttr > myDeprecatedAttributes
List with the deprecated Attributes.
const std::string & getDefinition() const
get default value
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name) ...
SumoXMLTag myTagSynonym
Tag written in XML (If is SUMO_TAG_NOTHING), original Tag name will be written)
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc.)
static std::map< SumoXMLTag, TagProperties > myTagProperties
map with the tags properties
int myAttributeProperty
Property of attribute.
std::string myTagStr
Sumo XML Tag vinculated wit this tag Property in String format.
virtual void setGenericParametersStr(const std::string &value)=0
set generic parameters in string format
bool isOptional() const
return true if atribute is optional
virtual void mouseOverObject(const GUIVisualizationSettings &s) const =0
method for check if mouse is over objects