Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEAttributeCarrier.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 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
21#include <netedit/GNENet.h>
23#include <netedit/GNEUndoList.h>
24#include <netedit/GNEViewNet.h>
35
36#include "GNEAttributeCarrier.h"
37
38// ===========================================================================
39// static members
40// ===========================================================================
41
42const std::string GNEAttributeCarrier::FEATURE_LOADED = "loaded";
43const std::string GNEAttributeCarrier::FEATURE_GUESSED = "guessed";
44const std::string GNEAttributeCarrier::FEATURE_MODIFIED = "modified";
45const std::string GNEAttributeCarrier::FEATURE_APPROVED = "approved";
46const std::string GNEAttributeCarrier::LANE_START = TL("lane start");
47const std::string GNEAttributeCarrier::LANE_END = TL("lane end");
48const std::string GNEAttributeCarrier::True = toString(true);
49const std::string GNEAttributeCarrier::False = toString(false);
50
51// ===========================================================================
52// method definitions
53// ===========================================================================
54
55GNEAttributeCarrier::GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net, const std::string& filename, const bool isTemplate) :
56 myTagProperty(net->getTagPropertiesDatabase()->getTagProperty(tag, true)),
57 myNet(net),
58 myFilename(filename),
59 myIsTemplate(isTemplate) {
60 // check if add this AC to saving file handler
61 if (myFilename.size() > 0) {
62 // add filename to saving files handler
65 } else if (myTagProperty->isDemandElement()) {
67 } else if (myTagProperty->isDataElement()) {
69 } else if (myTagProperty->isMeanData()) {
71 }
72 } else {
73 // always avoid empty files
76 } else if (myTagProperty->isDemandElement() && (net->getSavingFilesHandler()->getDemandFilenames().size() > 0)) {
78 } else if (myTagProperty->isDataElement() && (net->getSavingFilesHandler()->getDataFilenames().size() > 0)) {
80 } else if (myTagProperty->isMeanData() && (net->getSavingFilesHandler()->getMeanDataFilenames().size() > 0)) {
82 }
83 }
84}
85
86
88
89
90const std::string
94
95
96GNENet*
98 return myNet;
99}
100
101
102const std::string&
106
107
108void
110 if (myFilename.empty()) {
111 myFilename = file;
112 }
113}
114
115
116void
118 auto glObject = getGUIGlObject();
119 if (glObject && myTagProperty->isSelectable()) {
120 gSelected.select(glObject->getGlID());
121 mySelected = true;
122 }
123}
124
125
126void
128 auto glObject = getGUIGlObject();
129 if (glObject && myTagProperty->isSelectable()) {
130 gSelected.deselect(glObject->getGlID());
131 mySelected = false;
132 }
133}
134
135
136bool
140
141
142bool
144 // first check if element is selected
145 if (mySelected) {
146 // get flag for network element
147 const bool networkElement = myTagProperty->isNetworkElement() || myTagProperty->isAdditionalElement();
148 // check current supermode
149 if (networkElement && myNet->getViewNet()->getEditModes().isCurrentSupermodeNetwork()) {
150 return true;
152 return true;
154 return true;
155 } else {
156 return false;
157 }
158 } else {
159 return false;
160 }
161}
162
163void
168
169
170void
175
176
177bool
181
182
183void
184GNEAttributeCarrier::drawInLayer(double typeOrLayer, const double extraOffset) const {
185 if (myDrawInFront) {
186 glTranslated(0, 0, GLO_FRONTELEMENT + extraOffset);
187 } else {
188 glTranslated(0, 0, typeOrLayer + extraOffset);
189 }
190}
191
192
193void
195 myInGrid = value;
196}
197
198
199bool
201 return myInGrid;
202}
203
204
205bool
209
210
211bool
215
216
217void
219 if (allowUndoRedo) {
220 // reset within undo-redo
221 const auto undoList = myNet->getViewNet()->getUndoList();
222 undoList->begin(myTagProperty->getGUIIcon(), TLF("reset %", myTagProperty->getTagStr()));
223 for (const auto& attrProperty : myTagProperty->getAttributeProperties()) {
224 if (!attrProperty->isUnique() && attrProperty->hasDefaultValue()) {
225 setAttribute(attrProperty->getAttr(), attrProperty->getDefaultStringValue(), undoList);
226 if (attrProperty->isActivatable()) {
227 if (attrProperty->getDefaultActivated()) {
228 enableAttribute(attrProperty->getAttr(), undoList);
229 } else {
230 disableAttribute(attrProperty->getAttr(), undoList);
231 }
232 }
233 }
234 }
235 undoList->end();
236 } else {
237 // simply reset every
238 for (const auto& attrProperty : myTagProperty->getAttributeProperties()) {
239 if (attrProperty->hasDefaultValue()) {
240 setAttribute(attrProperty->getAttr(), attrProperty->getDefaultStringValue());
241 if (attrProperty->isActivatable()) {
242 toggleAttribute(attrProperty->getAttr(), attrProperty->getDefaultActivated());
243 }
244 }
245 }
246 }
247}
248
249
250void
252 throw ProcessError(TL("Nothing to enable, implement in Children"));
253
254}
255
256
257void
259 throw ProcessError(TL("Nothing to disable, implement in Children"));
260}
261
262
263bool
265 // by default, all attributes are enabled
266 return true;
267}
268
269
270bool
272 // by default, all attributes aren't computed
273 return false;
274}
275
276
277bool
281
282// canParse functions
283
284template<> bool
285GNEAttributeCarrier::canParse<int>(const std::string& string) {
286 if (string == "INVALID_INT") {
287 return true;
288 } else {
289 return StringUtils::isInt(string);
290 }
291}
292
293
294template<> bool
295GNEAttributeCarrier::canParse<double>(const std::string& string) {
296 if (string == "INVALID_DOUBLE") {
297 return true;
298 } else {
299 return StringUtils::isDouble(string);
300 }
301}
302
303
304template<> bool
305GNEAttributeCarrier::canParse<SUMOTime>(const std::string& string) {
306 return isTime(string);
307}
308
309
310template<> bool
311GNEAttributeCarrier::canParse<bool>(const std::string& string) {
312 return StringUtils::isBool(string);
313}
314
315
316template<> bool
317GNEAttributeCarrier::canParse<Position>(const std::string& string) {
318 bool ok = true;
319 GeomConvHelper::parseShapeReporting(string, "position", 0, ok, true, false);
320 return ok;
321}
322
323
324template<> bool
325GNEAttributeCarrier::canParse<SUMOVehicleClass>(const std::string& string) {
326 return SumoVehicleClassStrings.hasString(string);
327}
328
329
330template<> bool
331GNEAttributeCarrier::canParse<RGBColor>(const std::string& string) {
332 return RGBColor::isColor(string);
333}
334
335
336template<> bool
337GNEAttributeCarrier::canParse<SumoXMLAttr>(const std::string& string) {
339}
340
341
342template<> bool
343GNEAttributeCarrier::canParse<SUMOVehicleShape>(const std::string& string) {
344 if (string.empty()) {
345 return true;
346 } else {
347 return SumoVehicleShapeStrings.hasString(string);
348 }
349}
350
351
352template<> bool
353GNEAttributeCarrier::canParse<PositionVector>(const std::string& string) {
354 bool ok = true;
355 GeomConvHelper::parseShapeReporting(string, "shape", 0, ok, true, false);
356 return ok;
357}
358
359
360template<> bool
361GNEAttributeCarrier::canParse<std::vector<int> >(const std::string& string) {
362 if (string.empty()) {
363 return true;
364 }
365 const auto values = StringTokenizer(string).getVector();
366 for (const auto& value : values) {
367 if (!canParse<int>(value)) {
368 return false;
369 }
370 }
371 return true;
372}
373
374
375template<> bool
376GNEAttributeCarrier::canParse<std::vector<double> >(const std::string& string) {
377 if (string.empty()) {
378 return true;
379 }
380 const auto values = StringTokenizer(string).getVector();
381 for (const auto& value : values) {
382 if (!canParse<double>(value)) {
383 return false;
384 }
385 }
386 return true;
387}
388
389
390template<> bool
391GNEAttributeCarrier::canParse<std::vector<bool> >(const std::string& string) {
392 if (string.empty()) {
393 return true;
394 }
395 const auto values = StringTokenizer(string).getVector();
396 for (const auto& value : values) {
397 if (!canParse<bool>(value)) {
398 return false;
399 }
400 }
401 return true;
402}
403
404
405template<> bool
406GNEAttributeCarrier::canParse<std::vector<SumoXMLAttr> >(const std::string& string) {
407 if (string.empty()) {
408 return true;
409 }
410 const auto values = StringTokenizer(string).getVector();
411 for (const auto& value : values) {
412 if (!canParse<SumoXMLAttr>(value)) {
413 return false;
414 }
415 }
416 return true;
417}
418
419// parse functions
420
421template<> int
422GNEAttributeCarrier::parse(const std::string& string) {
423 if (string == "INVALID_INT") {
424 return INVALID_INT;
425 } else {
426 return StringUtils::toInt(string);
427 }
428}
429
430
431template<> double
432GNEAttributeCarrier::parse(const std::string& string) {
433 if (string == "INVALID_DOUBLE") {
434 return INVALID_DOUBLE;
435 } else {
436 return StringUtils::toDouble(string);
437 }
438}
439
440
441template<> SUMOTime
442GNEAttributeCarrier::parse(const std::string& string) {
443 return string2time(string);
444}
445
446
447template<> bool
448GNEAttributeCarrier::parse(const std::string& string) {
449 return StringUtils::toBool(string);
450}
451
452
453template<> SUMOVehicleClass
454GNEAttributeCarrier::parse(const std::string& string) {
455 if (string.size() == 0) {
456 throw EmptyData();
457 } else if (!SumoVehicleClassStrings.hasString(string)) {
458 return SVC_IGNORING;
459 } else {
460 return SumoVehicleClassStrings.get(string);
461 }
462}
463
464
465template<> RGBColor
466GNEAttributeCarrier::parse(const std::string& string) {
467 if (string.empty()) {
468 return RGBColor::INVISIBLE;
469 } else {
470 return RGBColor::parseColor(string);
471 }
472}
473
474
475template<> Position
476GNEAttributeCarrier::parse(const std::string& string) {
477 // we handle empty strings as position invalids
478 if (string.size() == 0) {
479 return Position::INVALID;
480 } else {
481 bool ok = true;
482 PositionVector pos = GeomConvHelper::parseShapeReporting(string, "user-supplied position", 0, ok, false, false);
483 if (!ok || (pos.size() != 1)) {
484 throw NumberFormatException("(Position) " + string);
485 } else {
486 return pos[0];
487 }
488 }
489}
490
491
492template<> PositionVector
493GNEAttributeCarrier::parse(const std::string& string) {
494 PositionVector posVector;
495 // empty string are allowed (It means empty position vector)
496 if (string.empty()) {
497 return posVector;
498 } else {
499 bool ok = true;
500 posVector = GeomConvHelper::parseShapeReporting(string, "user-supplied shape", 0, ok, false, true);
501 if (!ok) {
502 throw NumberFormatException("(Position List) " + string);
503 } else {
504 return posVector;
505 }
506 }
507}
508
509
510template<> SUMOVehicleShape
511GNEAttributeCarrier::parse(const std::string& string) {
512 if (string.empty()) {
514 } else {
515 return SumoVehicleShapeStrings.get(string);
516 }
517}
518
519
520template<> std::vector<std::string>
521GNEAttributeCarrier::parse(const std::string& string) {
522 return StringTokenizer(string).getVector();
523}
524
525
526template<> std::set<std::string>
527GNEAttributeCarrier::parse(const std::string& string) {
528 const auto vectorString = StringTokenizer(string).getVector();
529 std::set<std::string> solution;
530 for (const auto& stringValue : vectorString) {
531 solution.insert(stringValue);
532 }
533 return solution;
534}
535
536
537template<> std::vector<int>
538GNEAttributeCarrier::parse(const std::string& string) {
539 const auto vectorInt = parse<std::vector<std::string> >(string);
540 std::vector<int> parsedIntValues;
541 for (const auto& intValue : vectorInt) {
542 parsedIntValues.push_back(parse<int>(intValue));
543 }
544 return parsedIntValues;
545}
546
547
548template<> std::vector<double>
549GNEAttributeCarrier::parse(const std::string& string) {
550 const auto vectorDouble = parse<std::vector<std::string> >(string);
551 std::vector<double> parsedDoubleValues;
552 for (const auto& doubleValue : vectorDouble) {
553 parsedDoubleValues.push_back(parse<double>(doubleValue));
554 }
555 return parsedDoubleValues;
556}
557
558
559template<> std::vector<bool>
560GNEAttributeCarrier::parse(const std::string& string) {
561 const auto vectorBool = parse<std::vector<std::string> >(string);
562 std::vector<bool> parsedBoolValues;
563 for (const auto& boolValue : vectorBool) {
564 parsedBoolValues.push_back(parse<bool>(boolValue));
565 }
566 return parsedBoolValues;
567}
568
569
570template<> std::vector<SumoXMLAttr>
571GNEAttributeCarrier::parse(const std::string& value) {
572 // Declare string vector
573 const auto attributesStr = parse<std::vector<std::string> > (value);
574 std::vector<SumoXMLAttr> attributes;
575 // Iterate over lanes IDs, retrieve Lanes and add it into parsedLanes
576 for (const auto& attributeStr : attributesStr) {
577 if (SUMOXMLDefinitions::Attrs.hasString(attributeStr)) {
578 attributes.push_back(static_cast<SumoXMLAttr>(SUMOXMLDefinitions::Attrs.get(attributeStr)));
579 } else {
580 throw FormatException("Error parsing attributes. Attribute '" + attributeStr + "' doesn't exist");
581 }
582 }
583 return attributes;
584}
585
586// can parse (network) functions
587
588template<> bool
589GNEAttributeCarrier::canParse<std::vector<GNEEdge*> >(const GNENet* net, const std::string& value, const bool checkConsecutivity) {
590 // Declare string vector
591 const auto edgeIds = parse<std::vector<std::string> > (value);
592 std::vector<GNEEdge*> parsedEdges;
593 parsedEdges.reserve(edgeIds.size());
594 for (const auto& edgeID : edgeIds) {
595 const auto edge = net->getAttributeCarriers()->retrieveEdge(edgeID, false);
596 if (edge == nullptr) {
597 return false;
598 } else if (checkConsecutivity) {
599 if ((parsedEdges.size() > 0) && (parsedEdges.back()->getToJunction() != edge->getFromJunction())) {
600 return false;
601 }
602 parsedEdges.push_back(edge);
603 }
604 }
605 return true;
606}
607
608
609template<> bool
610GNEAttributeCarrier::canParse<std::vector<GNELane*> >(const GNENet* net, const std::string& value, const bool checkConsecutivity) {
611 // Declare string vector
612 const auto laneIds = parse<std::vector<std::string> > (value);
613 std::vector<GNELane*> parsedLanes;
614 parsedLanes.reserve(laneIds.size());
615 // Iterate over lanes IDs, retrieve Lanes and add it into parsedLanes
616 for (const auto& laneID : laneIds) {
617 const auto lane = net->getAttributeCarriers()->retrieveLane(laneID, false);
618 if (lane == nullptr) {
619 return false;
620 } else if (checkConsecutivity) {
621 if ((parsedLanes.size() > 0) && (parsedLanes.back()->getParentEdge()->getToJunction() != lane->getParentEdge()->getFromJunction())) {
622 return false;
623 }
624 parsedLanes.push_back(lane);
625 }
626 }
627 return true;
628}
629
630// parse (network) functions
631
632template<> std::vector<GNEEdge*>
633GNEAttributeCarrier::parse(const GNENet* net, const std::string& value) {
634 // Declare string vector
635 const auto edgeIds = parse<std::vector<std::string> > (value);
636 std::vector<GNEEdge*> parsedEdges;
637 parsedEdges.reserve(edgeIds.size());
638 // Iterate over edges IDs, retrieve Edges and add it into parsedEdges
639 for (const auto& edgeID : edgeIds) {
640 parsedEdges.push_back(net->getAttributeCarriers()->retrieveEdge(edgeID));
641 }
642 return parsedEdges;
643}
644
645
646template<> std::vector<GNELane*>
647GNEAttributeCarrier::parse(const GNENet* net, const std::string& value) {
648 // Declare string vector
649 const auto laneIds = parse<std::vector<std::string> > (value);
650 std::vector<GNELane*> parsedLanes;
651 parsedLanes.reserve(laneIds.size());
652 // Iterate over lanes IDs, retrieve Lanes and add it into parsedLanes
653 for (const auto& laneID : laneIds) {
654 parsedLanes.push_back(net->getAttributeCarriers()->retrieveLane(laneID));
655 }
656 return parsedLanes;
657}
658
659// parse ID functions
660
661template<> std::string
662GNEAttributeCarrier::parseIDs(const std::vector<GNEEdge*>& ACs) {
663 // obtain ID's of edges and return their join
664 std::vector<std::string> edgeIDs;
665 for (const auto& AC : ACs) {
666 edgeIDs.push_back(AC->getID());
667 }
668 return joinToString(edgeIDs, " ");
669}
670
671
672template<> std::string
673GNEAttributeCarrier::parseIDs(const std::vector<GNELane*>& ACs) {
674 // obtain ID's of lanes and return their join
675 std::vector<std::string> laneIDs;
676 for (const auto& AC : ACs) {
677 laneIDs.push_back(AC->getID());
678 }
679 return joinToString(laneIDs, " ");
680}
681
682
683template<> std::string
685 std::string result;
686 // Generate an string using the following structure: "key1=value1|key2=value2|...
687 for (const auto& parameter : getACParametersMap()) {
688 result += parameter.first + "=" + parameter.second + "|";
689 }
690 // remove the last "|"
691 if (!result.empty()) {
692 result.pop_back();
693 }
694 return result;
695}
696
697
698template<> std::vector<std::pair<std::string, std::string> >
700 std::vector<std::pair<std::string, std::string> > result;
701 // Generate a vector string using the following structure: "<key1,value1>, <key2, value2>,...
702 for (const auto& parameter : getACParametersMap()) {
703 result.push_back(std::make_pair(parameter.first, parameter.second));
704 }
705 return result;
706}
707
708
709void
710GNEAttributeCarrier::setACParameters(const std::string& parameters, GNEUndoList* undoList) {
711 // declare map
712 Parameterised::Map parametersMap;
713 // separate value in a vector of string using | as separator
714 StringTokenizer parametersTokenizer(parameters, "|", true);
715 // iterate over all values
716 while (parametersTokenizer.hasNext()) {
717 // obtain key and value and save it in myParameters
718 const std::vector<std::string> keyValue = StringTokenizer(parametersTokenizer.next(), "=", true).getVector();
719 if (keyValue.size() == 2) {
720 parametersMap[keyValue.front()] = keyValue.back();
721 }
722 }
723 // set setACParameters map
724 setACParameters(parametersMap, undoList);
725}
726
727
728void
729GNEAttributeCarrier::setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList) {
730 // declare parametersMap
731 Parameterised::Map parametersMap;
732 // Generate an string using the following structure: "key1=value1|key2=value2|...
733 for (const auto& parameter : parameters) {
734 parametersMap[parameter.first] = parameter.second;
735 }
736 // set setACParameters map
737 setACParameters(parametersMap, undoList);
738}
739
740
741void
743 // declare result string
744 std::string paramsStr;
745 // Generate an string using the following structure: "key1=value1|key2=value2|...
746 for (const auto& parameter : parameters) {
747 paramsStr += parameter.first + "=" + parameter.second + "|";
748 }
749 // remove the last "|"
750 if (!paramsStr.empty()) {
751 paramsStr.pop_back();
752 }
753 // set parameters
754 setAttribute(GNE_ATTR_PARAMETERS, paramsStr, undoList);
755}
756
757
758void
759GNEAttributeCarrier::addACParameters(const std::string& key, const std::string& attribute, GNEUndoList* undoList) {
760 // get parametersMap
761 Parameterised::Map parametersMap = getACParametersMap();
762 // add (or update) attribute
763 parametersMap[key] = attribute;
764 // set attribute
765 setACParameters(parametersMap, undoList);
766}
767
768
769void
770GNEAttributeCarrier::removeACParametersKeys(const std::vector<std::string>& keepKeys, GNEUndoList* undoList) {
771 // declare parametersMap
772 Parameterised::Map newParametersMap;
773 // iterate over parameters map
774 for (const auto& parameter : getACParametersMap()) {
775 // copy to newParametersMap if key is in keepKeys
776 if (std::find(keepKeys.begin(), keepKeys.end(), parameter.first) != keepKeys.end()) {
777 newParametersMap.insert(parameter);
778 }
779 }
780 // set newParametersMap map
781 setACParameters(newParametersMap, undoList);
782}
783
784
785std::string
787 switch (key) {
788 // Crossings
791 return "No TLS";
792 // connections
793 case SUMO_ATTR_DIR: {
794 // special case for connection directions
795 std::string direction = getAttribute(key);
796 if (direction == "s") {
797 return "Straight (s)";
798 } else if (direction == "t") {
799 return "Turn (t))";
800 } else if (direction == "l") {
801 return "Left (l)";
802 } else if (direction == "r") {
803 return "Right (r)";
804 } else if (direction == "L") {
805 return "Partially left (L)";
806 } else if (direction == "R") {
807 return "Partially right (R)";
808 } else if (direction == "invalid") {
809 return "No direction (Invalid))";
810 } else {
811 return "undefined";
812 }
813 }
814 case SUMO_ATTR_STATE: {
815 // special case for connection states
816 std::string state = getAttribute(key);
817 if (state == "-") {
818 return "Dead end (-)";
819 } else if (state == "=") {
820 return "equal (=)";
821 } else if (state == "m") {
822 return "Minor link (m)";
823 } else if (state == "M") {
824 return "Major link (M)";
825 } else if (state == "O") {
826 return "TLS controller off (O)";
827 } else if (state == "o") {
828 return "TLS yellow flashing (o)";
829 } else if (state == "y") {
830 return "TLS yellow minor link (y)";
831 } else if (state == "Y") {
832 return "TLS yellow major link (Y)";
833 } else if (state == "r") {
834 return "TLS red (r)";
835 } else if (state == "g") {
836 return "TLS green minor (g)";
837 } else if (state == "G") {
838 return "TLS green major (G)";
839 } else if (state == "Z") {
840 return "Zipper (Z)";
841 } else {
842 return "undefined";
843 }
844 }
845 default:
846 return getAttribute(key);
847 }
848}
849
850
851std::string
855
856
857const std::string&
861
862
863FXIcon*
865 // special case for vClass icons
866 if (myTagProperty->vClassIcon()) {
868 } else {
870 }
871}
872
873
874bool
878
879
880const GNETagProperties*
884
885// ===========================================================================
886// private
887// ===========================================================================
888
889void
890GNEAttributeCarrier::toggleAttribute(SumoXMLAttr /*key*/, const bool /*value*/) {
891 throw ProcessError(TL("Nothing to toggle, implement in Children"));
892}
893
894
895std::string
897 switch (key) {
902 return myFilename;
906 if (mySelected) {
907 return True;
908 } else {
909 return False;
910 }
912 if (myDrawInFront) {
913 return True;
914 } else {
915 return False;
916 }
918 return parameterised->getParametersStr();
919 default:
920 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
921 }
922}
923
924
925void
926GNEAttributeCarrier::setCommonAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
927 switch (key) {
929 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
930 // update filenames of all additional childrens
931 for (auto additionalChild : getHierarchicalElement()->getChildAdditionals()) {
932 additionalChild->setAttribute(key, value, undoList);
933 }
934 break;
936 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
937 // update filenames of all demand childrens
938 for (auto demandChild : getHierarchicalElement()->getChildDemandElements()) {
939 demandChild->setAttribute(key, myFilename, undoList);
940 }
941 break;
947 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
948 break;
949 default:
950 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
951 }
952}
953
954
955bool
956GNEAttributeCarrier::isCommonValid(SumoXMLAttr key, const std::string& value) const {
957 switch (key) {
965 return canParse<bool>(value);
968 default:
969 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
970 }
971}
972
973
974void
975GNEAttributeCarrier::setCommonAttribute(Parameterised* parameterised, SumoXMLAttr key, const std::string& value) {
976 switch (key) {
978 myFilename = value;
979 if (value.empty()) {
980 // try to avoid empty files
983 }
984 } else {
986 }
987 break;
989 myFilename = value;
990 if (value.empty()) {
991 // try to avoid empty files
992 if (myNet->getSavingFilesHandler()->getDemandFilenames().size() > 0) {
994 }
995 } else {
997 }
998 break;
1000 myFilename = value;
1001 if (value.empty()) {
1002 // try to avoid empty files
1003 if (myNet->getSavingFilesHandler()->getDataFilenames().size() > 0) {
1005 }
1006 } else {
1008 }
1009 break;
1011 myFilename = value;
1012 if (value.empty()) {
1013 // try to avoid empty files
1014 if (myNet->getSavingFilesHandler()->getMeanDataFilenames().size() > 0) {
1016 }
1017 } else {
1019 }
1020 break;
1022 myCenterAfterCreation = parse<bool>(value);
1023 break;
1024 case GNE_ATTR_SELECTED:
1025 if (parse<bool>(value)) {
1027 } else {
1029 }
1030 break;
1032 parameterised->setParametersStr(value);
1033 break;
1034 default:
1035 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
1036 }
1037}
1038
1039/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ GLO_FRONTELEMENT
front element (used in netedit)
GUISelectedStorage gSelected
A global holder of selected objects.
#define TL(string)
Definition MsgHandler.h:305
#define TLF(string,...)
Definition MsgHandler.h:307
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
bool isTime(const std::string &r)
check if the given string is a valid time
Definition SUMOTime.cpp:69
StringBijection< SUMOVehicleShape > SumoVehicleShapeStrings(sumoVehicleShapeStringInitializer, SUMOVehicleShape::UNKNOWN, false)
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
SUMOVehicleShape
Definition of vehicle classes to differ between different appearances.
@ UNKNOWN
not defined
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
SumoXMLTag
Numbers representing SUMO-XML - element names.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_MEANDATA_FILE
meanData data file
@ GNE_ATTR_DEMAND_FILE
demand demand file
@ SUMO_ATTR_TLLINKINDEX2
link: the index of the opposite direction link of a pedestrian crossing
@ GNE_ATTR_CENTER_AFTER_CREATION
flag to center camera after element creation
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ GNE_ATTR_ADDITIONAL_FILE
additional save file
@ GNE_ATTR_DATA_FILE
data data file
@ SUMO_ATTR_VCLASS
@ GNE_ATTR_FRONTELEMENT
@ SUMO_ATTR_ID
@ SUMO_ATTR_DIR
The abstract direction of a link.
@ SUMO_ATTR_TLLINKINDEX
link: the index of the link within the traffic light
@ SUMO_ATTR_STATE
The state of a link.
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:64
const int INVALID_INT
invalid int
Definition StdDefs.h:61
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:283
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
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
void markForDrawingFront()
mark for drawing front
virtual void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
void selectAttributeCarrier()
select attribute carrier using GUIGlobalSelection
static const std::string LANE_START
lane start
bool isMarkedForDrawingFront() const
check if this AC is marked for drawing front
bool myDrawInFront
boolean to check if drawn this AC over other elements
bool myCenterAfterCreation
boolean to check if center this element after creation
FXIcon * getACIcon() const
get FXIcon associated to this AC
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
void setACParameters(const std::string &parameters, GNEUndoList *undoList)
set parameters (string)
bool checkDrawFrontContour() const
check if draw front contour (green/blue)
const bool myIsTemplate
whether the current object is a template object (used for edit attributes)
virtual void toggleAttribute(SumoXMLAttr key, const bool value)
method for enable or disable the attribute and nothing else (used in GNEChange_ToggleAttribute)
static const std::string LANE_END
lane end
static const std::string FEATURE_LOADED
feature is still unchanged after being loaded (implies approval)
std::string getCommonAttribute(const Parameterised *parameterised, SumoXMLAttr key) const
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 const std::string True
true value in string format (used for comparing boolean values in getAttribute(......
std::string myFilename
filename in which save this AC
void unselectAttributeCarrier()
unselect attribute carrier using GUIGlobalSelection
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 const std::string FEATURE_GUESSED
feature has been reguessed (may still be unchanged be we can't tell (yet)
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.
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
void addACParameters(const std::string &key, const std::string &attribute, GNEUndoList *undoList)
add (or update attribute) key and attribute
void resetDefaultValues(const bool allowUndoRedo)
reset attribute carrier to their default values
const std::string & getFilename() const
get filename in which save this AC
bool hasAttribute(SumoXMLAttr key) const
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNEAttributeCarrier(const SumoXMLTag tag, GNENet *net, const std::string &filename, const bool isTemplate)
Constructor.
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
bool isCommonValid(SumoXMLAttr key, const std::string &value) const
GNENet * getNet() const
get pointer to net
virtual void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
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(...))
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
bool checkDrawInspectContour() const
check if draw inspect contour (black/white)
virtual GUIGlObject * getGUIGlObject()=0
void changeDefaultFilename(const std::string &file)
change defaultFilename (only used in SavingFilesHandler)
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
const GNEHierarchicalContainerChildren< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
GNELane * retrieveLane(const std::string &id, bool hardFail=true, bool checkVolatileChange=false) const
get lane by id
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
const std::vector< std::string > & getAdditionalFilenames() const
get vector with additional elements saving files (starting with default)
void addDataFilename(const GNEAttributeCarrier *dataElement)
data elements
void addMeanDataFilename(const GNEAttributeCarrier *meanDataElement)
meanData elements
const std::vector< std::string > & getDemandFilenames() const
get vector with demand elements saving files (starting with default)
const std::vector< std::string > & getMeanDataFilenames() const
get vector with meanData elements saving files (starting with default)
const std::vector< std::string > & getDataFilenames() const
get vector with data elements saving files (starting with default)
void addDemandFilename(const GNEAttributeCarrier *demandElement)
demand elements
void addAdditionalFilename(const GNEAttributeCarrier *additionalElement)
additional elements
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:147
GNENetHelper::SavingFilesHandler * getSavingFilesHandler() const
get saving files handler
Definition GNENet.cpp:159
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2195
bool isMeanData() const
return true if tag correspond to a mean data element
bool vClassIcon() const
return true if tag correspond to an element that has vClass icons
bool isGenericData() const
data elements
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
bool isNetworkElement() const
network elements
bool isDataElement() const
return true if tag correspond to a data element
bool isSelectable() const
return true if tag correspond to a selectable element
GUIIcon getGUIIcon() const
get GUI icon associated to this tag property
bool isDemandElement() const
return true if tag correspond to a demand element
const std::vector< const GNEAttributeProperties * > & getAttributeProperties() const
get all attribute properties
bool isAdditionalElement() const
return true if tag correspond to an additional element (note: this include TAZ, shapes and wires)
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute "attr"
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
bool isACInspected(GNEAttributeCarrier *AC) const
void unmarkAC(GNEAttributeCarrier *AC)
unmark AC for drawing front
void markAC(GNEAttributeCarrier *AC)
mark AC as drawing front
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
GNEViewNetHelper::InspectedElements & getInspectedElements()
get inspected elements
GNEViewNetHelper::MarkFrontElements & getMarkFrontElements()
get marked for drawing front elements
GNEUndoList * getUndoList() const
get the undoList object
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
void deselect(GUIGlID id)
Deselects the object with the given id.
static PositionVector parseShapeReporting(const std::string &shpdef, const std::string &objecttype, const char *objectid, bool &ok, bool allowEmpty, bool report=true)
Builds a PositionVector from a string representation, reporting occurred errors.
An upper class for objects with additional parameters.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static const Position INVALID
used to indicate that a position is valid
Definition Position.h:319
A list of positions.
static const RGBColor INVISIBLE
Definition RGBColor.h:198
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition RGBColor.cpp:239
static bool isColor(std::string coldef)
check if the given string can be parsed to color
Definition RGBColor.cpp:329
static SequentialStringBijection Attrs
The names of SUMO-XML attributes for use in netbuild.
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
bool hasString(const std::string &str) const
std::vector< std::string > getVector()
return vector of strings
bool hasNext()
returns the information whether further substrings exist
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined
static bool isDouble(const std::string &sData)
check if the given sData can be conveted to double
static bool isBool(const std::string &sData)
check if the given value can be converted to bool
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
static bool isInt(const std::string &sData)
check if the given sData can be converted to int
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
static FXIcon * getVClassIcon(const SUMOVehicleClass vc)
returns icon associated to the given vClass
bool isCurrentSupermodeDemand() const
@check if current supermode is Demand
bool isCurrentSupermodeData() const
@check if current supermode is Data
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network