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::TRUE_STR = toString(true);
47const std::string GNEAttributeCarrier::FALSE_STR = toString(false);
48
49// ===========================================================================
50// method definitions
51// ===========================================================================
52
53GNEAttributeCarrier::GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net, const std::string& filename, const bool isTemplate) :
54 myTagProperty(net->getTagPropertiesDatabase()->getTagProperty(tag, true)),
55 myNet(net),
56 myFilename(filename),
57 myIsTemplate(isTemplate) {
58 // check if add this AC to saving file handler
59 if (myFilename.size() > 0) {
60 // add filename to saving files handler
63 } else if (myTagProperty->isDemandElement()) {
65 } else if (myTagProperty->isDataElement()) {
67 } else if (myTagProperty->isMeanData()) {
69 }
70 } else {
71 // always avoid empty files
74 } else if (myTagProperty->isDemandElement() && (net->getSavingFilesHandler()->getDemandFilenames().size() > 0)) {
76 } else if (myTagProperty->isDataElement() && (net->getSavingFilesHandler()->getDataFilenames().size() > 0)) {
78 } else if (myTagProperty->isMeanData() && (net->getSavingFilesHandler()->getMeanDataFilenames().size() > 0)) {
80 }
81 }
82}
83
84
87
88const std::string
92
93
94GNENet*
96 return myNet;
97}
98
99
100const std::string&
104
105
106void
108 if (myFilename.empty()) {
109 myFilename = file;
110 }
111}
112
113
114void
116 auto glObject = getGUIGlObject();
117 if (glObject && myTagProperty->isSelectable()) {
118 gSelected.select(glObject->getGlID());
119 mySelected = true;
120 }
121}
122
123
124void
126 auto glObject = getGUIGlObject();
127 if (glObject && myTagProperty->isSelectable()) {
128 gSelected.deselect(glObject->getGlID());
129 mySelected = false;
130 }
131}
132
133
134bool
138
139
140bool
142 // first check if element is selected
143 if (mySelected) {
144 // get flag for network element
145 const bool networkElement = myTagProperty->isNetworkElement() || myTagProperty->isAdditionalElement();
146 // check current supermode
147 if (networkElement && myNet->getViewNet()->getEditModes().isCurrentSupermodeNetwork()) {
148 return true;
150 return true;
152 return true;
153 } else {
154 return false;
155 }
156 } else {
157 return false;
158 }
159}
160
161
162bool
164 // get modes
165 const auto& modes = myNet->getViewNet()->getEditModes();
166 // check conditions
168 return false;
169 } else if (modes.isCurrentSupermodeNetwork() && (modes.networkEditMode == NetworkEditMode::NETWORK_MOVE)) {
170 return true;
171 } else if (modes.isCurrentSupermodeDemand() && (modes.demandEditMode == DemandEditMode::DEMAND_MOVE)) {
172 return true;
173 } else {
174 return false;
175 }
176}
177
178
179void
184
185
186void
191
192
193bool
197
198
199void
200GNEAttributeCarrier::drawInLayer(double typeOrLayer, const double extraOffset) const {
201 if (myDrawInFront) {
202 glTranslated(0, 0, GLO_FRONTELEMENT + extraOffset);
203 } else {
204 glTranslated(0, 0, typeOrLayer + extraOffset);
205 }
206}
207
208
209void
211 myInGrid = value;
212}
213
214
215bool
217 return myInGrid;
218}
219
220
221bool
225
226
227bool
231
232
233void
235 if (allowUndoRedo) {
236 // reset within undo-redo
237 const auto undoList = myNet->getViewNet()->getUndoList();
238 undoList->begin(myTagProperty->getGUIIcon(), TLF("reset %", myTagProperty->getTagStr()));
239 for (const auto& attrProperty : myTagProperty->getAttributeProperties()) {
240 if (!attrProperty->isUnique() && attrProperty->hasDefaultValue()) {
241 setAttribute(attrProperty->getAttr(), attrProperty->getDefaultStringValue(), undoList);
242 if (attrProperty->isActivatable()) {
243 if (attrProperty->getDefaultActivated()) {
244 enableAttribute(attrProperty->getAttr(), undoList);
245 } else {
246 disableAttribute(attrProperty->getAttr(), undoList);
247 }
248 }
249 }
250 }
251 undoList->end();
252 } else {
253 // simply reset every
254 for (const auto& attrProperty : myTagProperty->getAttributeProperties()) {
255 if (attrProperty->hasDefaultValue()) {
256 setAttribute(attrProperty->getAttr(), attrProperty->getDefaultStringValue());
257 if (attrProperty->isActivatable()) {
258 toggleAttribute(attrProperty->getAttr(), attrProperty->getDefaultActivated());
259 }
260 }
261 }
262 }
263}
264
265
266void
268 throw ProcessError(TL("Nothing to enable, implement in Children"));
269
270}
271
272
273void
275 throw ProcessError(TL("Nothing to disable, implement in Children"));
276}
277
278
279bool
281 // by default, all attributes are enabled
282 return true;
283}
284
285
286bool
288 // by default, all attributes aren't computed
289 return false;
290}
291
292
293bool
297
298// canParse functions
299
300template<> bool
301GNEAttributeCarrier::canParse<int>(const std::string& string) {
302 if (string == "INVALID_INT") {
303 return true;
304 } else {
305 return StringUtils::isInt(string);
306 }
307}
308
309
310template<> bool
311GNEAttributeCarrier::canParse<double>(const std::string& string) {
312 if (string == "INVALID_DOUBLE") {
313 return true;
314 } else {
315 return StringUtils::isDouble(string);
316 }
317}
318
319
320template<> bool
321GNEAttributeCarrier::canParse<SUMOTime>(const std::string& string) {
322 return isTime(string);
323}
324
325
326template<> bool
327GNEAttributeCarrier::canParse<bool>(const std::string& string) {
328 return StringUtils::isBool(string);
329}
330
331
332template<> bool
333GNEAttributeCarrier::canParse<Position>(const std::string& string) {
334 bool ok = true;
335 GeomConvHelper::parseShapeReporting(string, "position", 0, ok, true, false);
336 return ok;
337}
338
339
340template<> bool
341GNEAttributeCarrier::canParse<SUMOVehicleClass>(const std::string& string) {
342 return SumoVehicleClassStrings.hasString(string);
343}
344
345
346template<> bool
347GNEAttributeCarrier::canParse<RGBColor>(const std::string& string) {
348 return RGBColor::isColor(string);
349}
350
351
352template<> bool
353GNEAttributeCarrier::canParse<SumoXMLAttr>(const std::string& string) {
355}
356
357
358template<> bool
359GNEAttributeCarrier::canParse<SUMOVehicleShape>(const std::string& string) {
360 if (string.empty()) {
361 return true;
362 } else {
363 return SumoVehicleShapeStrings.hasString(string);
364 }
365}
366
367
368template<> bool
369GNEAttributeCarrier::canParse<PositionVector>(const std::string& string) {
370 bool ok = true;
371 GeomConvHelper::parseShapeReporting(string, "shape", 0, ok, true, false);
372 return ok;
373}
374
375
376template<> bool
377GNEAttributeCarrier::canParse<std::vector<int> >(const std::string& string) {
378 if (string.empty()) {
379 return true;
380 }
381 const auto values = StringTokenizer(string).getVector();
382 for (const auto& value : values) {
383 if (!canParse<int>(value)) {
384 return false;
385 }
386 }
387 return true;
388}
389
390
391template<> bool
392GNEAttributeCarrier::canParse<std::vector<double> >(const std::string& string) {
393 if (string.empty()) {
394 return true;
395 }
396 const auto values = StringTokenizer(string).getVector();
397 for (const auto& value : values) {
398 if (!canParse<double>(value)) {
399 return false;
400 }
401 }
402 return true;
403}
404
405
406template<> bool
407GNEAttributeCarrier::canParse<std::vector<bool> >(const std::string& string) {
408 if (string.empty()) {
409 return true;
410 }
411 const auto values = StringTokenizer(string).getVector();
412 for (const auto& value : values) {
413 if (!canParse<bool>(value)) {
414 return false;
415 }
416 }
417 return true;
418}
419
420
421template<> bool
422GNEAttributeCarrier::canParse<std::vector<SumoXMLAttr> >(const std::string& string) {
423 if (string.empty()) {
424 return true;
425 }
426 const auto values = StringTokenizer(string).getVector();
427 for (const auto& value : values) {
428 if (!canParse<SumoXMLAttr>(value)) {
429 return false;
430 }
431 }
432 return true;
433}
434
435// parse functions
436
437template<> int
438GNEAttributeCarrier::parse(const std::string& string) {
439 if (string == "INVALID_INT") {
440 return INVALID_INT;
441 } else {
442 return StringUtils::toInt(string);
443 }
444}
445
446
447template<> double
448GNEAttributeCarrier::parse(const std::string& string) {
449 if (string == "INVALID_DOUBLE") {
450 return INVALID_DOUBLE;
451 } else {
452 return StringUtils::toDouble(string);
453 }
454}
455
456
457template<> SUMOTime
458GNEAttributeCarrier::parse(const std::string& string) {
459 return string2time(string);
460}
461
462
463template<> bool
464GNEAttributeCarrier::parse(const std::string& string) {
465 return StringUtils::toBool(string);
466}
467
468
469template<> SUMOVehicleClass
470GNEAttributeCarrier::parse(const std::string& string) {
471 if (string.size() == 0) {
472 throw EmptyData();
473 } else if (!SumoVehicleClassStrings.hasString(string)) {
474 return SVC_IGNORING;
475 } else {
476 return SumoVehicleClassStrings.get(string);
477 }
478}
479
480
481template<> RGBColor
482GNEAttributeCarrier::parse(const std::string& string) {
483 if (string.empty()) {
484 return RGBColor::INVISIBLE;
485 } else {
486 return RGBColor::parseColor(string);
487 }
488}
489
490
491template<> Position
492GNEAttributeCarrier::parse(const std::string& string) {
493 // we handle empty strings as position invalids
494 if (string.size() == 0) {
495 return Position::INVALID;
496 } else {
497 bool ok = true;
498 PositionVector pos = GeomConvHelper::parseShapeReporting(string, "user-supplied position", 0, ok, false, false);
499 if (!ok || (pos.size() != 1)) {
500 throw NumberFormatException("(Position) " + string);
501 } else {
502 return pos[0];
503 }
504 }
505}
506
507
508template<> PositionVector
509GNEAttributeCarrier::parse(const std::string& string) {
510 PositionVector posVector;
511 // empty string are allowed (It means empty position vector)
512 if (string.empty()) {
513 return posVector;
514 } else {
515 bool ok = true;
516 posVector = GeomConvHelper::parseShapeReporting(string, "user-supplied shape", 0, ok, false, true);
517 if (!ok) {
518 throw NumberFormatException("(Position List) " + string);
519 } else {
520 return posVector;
521 }
522 }
523}
524
525
526template<> SUMOVehicleShape
527GNEAttributeCarrier::parse(const std::string& string) {
528 if (string.empty()) {
530 } else {
531 return SumoVehicleShapeStrings.get(string);
532 }
533}
534
535
536template<> std::vector<std::string>
537GNEAttributeCarrier::parse(const std::string& string) {
538 return StringTokenizer(string).getVector();
539}
540
541
542template<> std::set<std::string>
543GNEAttributeCarrier::parse(const std::string& string) {
544 const auto vectorString = StringTokenizer(string).getVector();
545 std::set<std::string> solution;
546 for (const auto& stringValue : vectorString) {
547 solution.insert(stringValue);
548 }
549 return solution;
550}
551
552
553template<> std::vector<int>
554GNEAttributeCarrier::parse(const std::string& string) {
555 const auto vectorInt = parse<std::vector<std::string> >(string);
556 std::vector<int> parsedIntValues;
557 for (const auto& intValue : vectorInt) {
558 parsedIntValues.push_back(parse<int>(intValue));
559 }
560 return parsedIntValues;
561}
562
563
564template<> std::vector<double>
565GNEAttributeCarrier::parse(const std::string& string) {
566 const auto vectorDouble = parse<std::vector<std::string> >(string);
567 std::vector<double> parsedDoubleValues;
568 for (const auto& doubleValue : vectorDouble) {
569 parsedDoubleValues.push_back(parse<double>(doubleValue));
570 }
571 return parsedDoubleValues;
572}
573
574
575template<> std::vector<bool>
576GNEAttributeCarrier::parse(const std::string& string) {
577 const auto vectorBool = parse<std::vector<std::string> >(string);
578 std::vector<bool> parsedBoolValues;
579 for (const auto& boolValue : vectorBool) {
580 parsedBoolValues.push_back(parse<bool>(boolValue));
581 }
582 return parsedBoolValues;
583}
584
585
586template<> std::vector<SumoXMLAttr>
587GNEAttributeCarrier::parse(const std::string& value) {
588 // Declare string vector
589 const auto attributesStr = parse<std::vector<std::string> > (value);
590 std::vector<SumoXMLAttr> attributes;
591 // Iterate over lanes IDs, retrieve Lanes and add it into parsedLanes
592 for (const auto& attributeStr : attributesStr) {
593 if (SUMOXMLDefinitions::Attrs.hasString(attributeStr)) {
594 attributes.push_back(static_cast<SumoXMLAttr>(SUMOXMLDefinitions::Attrs.get(attributeStr)));
595 } else {
596 throw FormatException("Error parsing attributes. Attribute '" + attributeStr + "' doesn't exist");
597 }
598 }
599 return attributes;
600}
601
602// can parse (network) functions
603
604template<> bool
605GNEAttributeCarrier::canParse<std::vector<GNEEdge*> >(const GNENet* net, const std::string& value, const bool checkConsecutivity) {
606 // Declare string vector
607 const auto edgeIds = parse<std::vector<std::string> > (value);
608 std::vector<GNEEdge*> parsedEdges;
609 parsedEdges.reserve(edgeIds.size());
610 for (const auto& edgeID : edgeIds) {
611 const auto edge = net->getAttributeCarriers()->retrieveEdge(edgeID, false);
612 if (edge == nullptr) {
613 return false;
614 } else if (checkConsecutivity) {
615 if ((parsedEdges.size() > 0) && (parsedEdges.back()->getToJunction() != edge->getFromJunction())) {
616 return false;
617 }
618 parsedEdges.push_back(edge);
619 }
620 }
621 return true;
622}
623
624
625template<> bool
626GNEAttributeCarrier::canParse<std::vector<GNELane*> >(const GNENet* net, const std::string& value, const bool checkConsecutivity) {
627 // Declare string vector
628 const auto laneIds = parse<std::vector<std::string> > (value);
629 std::vector<GNELane*> parsedLanes;
630 parsedLanes.reserve(laneIds.size());
631 // Iterate over lanes IDs, retrieve Lanes and add it into parsedLanes
632 for (const auto& laneID : laneIds) {
633 const auto lane = net->getAttributeCarriers()->retrieveLane(laneID, false);
634 if (lane == nullptr) {
635 return false;
636 } else if (checkConsecutivity) {
637 if ((parsedLanes.size() > 0) && (parsedLanes.back()->getParentEdge()->getToJunction() != lane->getParentEdge()->getFromJunction())) {
638 return false;
639 }
640 parsedLanes.push_back(lane);
641 }
642 }
643 return true;
644}
645
646// parse (network) functions
647
648template<> std::vector<GNEEdge*>
649GNEAttributeCarrier::parse(const GNENet* net, const std::string& value) {
650 // Declare string vector
651 const auto edgeIds = parse<std::vector<std::string> > (value);
652 std::vector<GNEEdge*> parsedEdges;
653 parsedEdges.reserve(edgeIds.size());
654 // Iterate over edges IDs, retrieve Edges and add it into parsedEdges
655 for (const auto& edgeID : edgeIds) {
656 parsedEdges.push_back(net->getAttributeCarriers()->retrieveEdge(edgeID));
657 }
658 return parsedEdges;
659}
660
661
662template<> std::vector<GNELane*>
663GNEAttributeCarrier::parse(const GNENet* net, const std::string& value) {
664 // Declare string vector
665 const auto laneIds = parse<std::vector<std::string> > (value);
666 std::vector<GNELane*> parsedLanes;
667 parsedLanes.reserve(laneIds.size());
668 // Iterate over lanes IDs, retrieve Lanes and add it into parsedLanes
669 for (const auto& laneID : laneIds) {
670 parsedLanes.push_back(net->getAttributeCarriers()->retrieveLane(laneID));
671 }
672 return parsedLanes;
673}
674
675// parse ID functions
676
677template<> std::string
678GNEAttributeCarrier::parseIDs(const std::vector<GNEEdge*>& ACs) {
679 // obtain ID's of edges and return their join
680 std::vector<std::string> edgeIDs;
681 for (const auto& AC : ACs) {
682 edgeIDs.push_back(AC->getID());
683 }
684 return joinToString(edgeIDs, " ");
685}
686
687
688template<> std::string
689GNEAttributeCarrier::parseIDs(const std::vector<GNELane*>& ACs) {
690 // obtain ID's of lanes and return their join
691 std::vector<std::string> laneIDs;
692 for (const auto& AC : ACs) {
693 laneIDs.push_back(AC->getID());
694 }
695 return joinToString(laneIDs, " ");
696}
697
698void
699GNEAttributeCarrier::setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters) {
700 // declare result string
701 std::string paramsStr;
702 // Generate an string using the following structure: "key1=value1|key2=value2|...
703 for (const auto& parameter : parameters) {
704 paramsStr += parameter.first + "=" + parameter.second + "|";
705 }
706 // remove the last "|"
707 if (!paramsStr.empty()) {
708 paramsStr.pop_back();
709 }
710 // set parameters
712}
713
714
715void
716GNEAttributeCarrier::setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList) {
717 // declare parametersMap
718 Parameterised::Map parametersMap;
719 // Generate an string using the following structure: "key1=value1|key2=value2|...
720 for (const auto& parameter : parameters) {
721 parametersMap[parameter.first] = parameter.second;
722 }
723 // set setACParameters map
724 setACParameters(parametersMap, undoList);
725}
726
727
728void
730 // declare result string
731 std::string paramsStr;
732 // Generate an string using the following structure: "key1=value1|key2=value2|...
733 for (const auto& parameter : parameters) {
734 paramsStr += parameter.first + "=" + parameter.second + "|";
735 }
736 // remove the last "|"
737 if (!paramsStr.empty()) {
738 paramsStr.pop_back();
739 }
740 // set parameters
741 setAttribute(GNE_ATTR_PARAMETERS, paramsStr, undoList);
742}
743
744
745std::string
747 switch (key) {
748 // Crossings
751 return "No TLS";
752 // connections
753 case SUMO_ATTR_DIR: {
754 // special case for connection directions
755 std::string direction = getAttribute(key);
756 if (direction == "s") {
757 return "Straight (s)";
758 } else if (direction == "t") {
759 return "Turn (t))";
760 } else if (direction == "l") {
761 return "Left (l)";
762 } else if (direction == "r") {
763 return "Right (r)";
764 } else if (direction == "L") {
765 return "Partially left (L)";
766 } else if (direction == "R") {
767 return "Partially right (R)";
768 } else if (direction == "invalid") {
769 return "No direction (Invalid))";
770 } else {
771 return "undefined";
772 }
773 }
774 case SUMO_ATTR_STATE: {
775 // special case for connection states
776 std::string state = getAttribute(key);
777 if (state == "-") {
778 return "Dead end (-)";
779 } else if (state == "=") {
780 return "equal (=)";
781 } else if (state == "m") {
782 return "Minor link (m)";
783 } else if (state == "M") {
784 return "Major link (M)";
785 } else if (state == "O") {
786 return "TLS controller off (O)";
787 } else if (state == "o") {
788 return "TLS yellow flashing (o)";
789 } else if (state == "y") {
790 return "TLS yellow minor link (y)";
791 } else if (state == "Y") {
792 return "TLS yellow major link (Y)";
793 } else if (state == "r") {
794 return "TLS red (r)";
795 } else if (state == "g") {
796 return "TLS green minor (g)";
797 } else if (state == "G") {
798 return "TLS green major (G)";
799 } else if (state == "Z") {
800 return "Zipper (Z)";
801 } else {
802 return "undefined";
803 }
804 }
805 default:
806 return getAttribute(key);
807 }
808}
809
810
811std::string
815
816
817const std::string&
821
822
823FXIcon*
825 // special case for vClass icons
826 if (myTagProperty->vClassIcon()) {
828 } else {
830 }
831}
832
833
834bool
838
839
840const GNETagProperties*
844
845
846std::string
848 switch (key) {
853 return myFilename;
857 if (mySelected) {
858 return TRUE_STR;
859 } else {
860 return FALSE_STR;
861 }
863 if (myDrawInFront) {
864 return TRUE_STR;
865 } else {
866 return FALSE_STR;
867 }
869 if (getParameters()) {
871 } else {
872 throw InvalidArgument(getTagStr() + " doesn't support parameters");
873 }
874 default:
875 throw InvalidArgument(getTagStr() + " doesn't have a common attribute of type '" + toString(key) + "'");
876 }
877}
878
879
880double
882 throw InvalidArgument(getTagStr() + " doesn't have a common double attribute of type '" + toString(key) + "'");
883}
884
885
888 throw InvalidArgument(getTagStr() + " doesn't have a common position attribute of type '" + toString(key) + "'");
889}
890
891
894 throw InvalidArgument(getTagStr() + " doesn't have a common positionVector attribute of type '" + toString(key) + "'");
895}
896
897
898void
899GNEAttributeCarrier::setCommonAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
900 switch (key) {
902 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
903 // update filenames of all additional childrens
904 for (auto additionalChild : getHierarchicalElement()->getChildAdditionals()) {
905 additionalChild->setAttribute(key, value, undoList);
906 }
907 break;
909 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
910 // update filenames of all demand childrens
911 for (auto demandChild : getHierarchicalElement()->getChildDemandElements()) {
912 demandChild->setAttribute(key, myFilename, undoList);
913 }
914 break;
920 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
921 break;
922 default:
923 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
924 }
925}
926
927
928bool
929GNEAttributeCarrier::isCommonAttributeValid(SumoXMLAttr key, const std::string& value) const {
930 switch (key) {
938 return canParse<bool>(value);
941 default:
942 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
943 }
944}
945
946
947void
949 switch (key) {
951 myFilename = value;
952 if (value.empty()) {
953 // try to avoid empty files
956 }
957 } else {
959 }
960 break;
962 myFilename = value;
963 if (value.empty()) {
964 // try to avoid empty files
965 if (myNet->getSavingFilesHandler()->getDemandFilenames().size() > 0) {
967 }
968 } else {
970 }
971 break;
973 myFilename = value;
974 if (value.empty()) {
975 // try to avoid empty files
976 if (myNet->getSavingFilesHandler()->getDataFilenames().size() > 0) {
978 }
979 } else {
981 }
982 break;
984 myFilename = value;
985 if (value.empty()) {
986 // try to avoid empty files
987 if (myNet->getSavingFilesHandler()->getMeanDataFilenames().size() > 0) {
989 }
990 } else {
992 }
993 break;
995 myCenterAfterCreation = parse<bool>(value);
996 break;
998 if (parse<bool>(value)) {
1000 } else {
1002 }
1003 break;
1005 if (getParameters()) {
1007 } else {
1008 throw InvalidArgument(getTagStr() + " doesn't support parameters");
1009 }
1010 break;
1011 default:
1012 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
1013 }
1014}
1015
1016// ===========================================================================
1017// private
1018// ===========================================================================
1019
1020void
1022 throw ProcessError(TL("Nothing to toggle, implement in Children"));
1023}
1024
1025/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ DEMAND_MOVE
mode for moving demand elements
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:304
#define TLF(string,...)
Definition MsgHandler.h:306
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:68
const int INVALID_INT
invalid int
Definition StdDefs.h:65
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
bool drawMovingGeometryPoints() const
check if draw moving geometry points
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
double getCommonAttributeDouble(SumoXMLAttr key) const
virtual void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
void selectAttributeCarrier()
select attribute carrier using GUIGlobalSelection
void setInGrid(bool value)
mark if this AC was inserted in grid or not
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)
static const std::string FALSE_STR
true value in string format(used for comparing boolean values in getAttribute(...))
static const std::string TRUE_STR
true value in string format (used for comparing boolean values in getAttribute(......
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 FEATURE_LOADED
feature is still unchanged after being loaded (implies approval)
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....
virtual Parameterised * getParameters()=0
get parameters associated with this AttributeCarrier
bool myInGrid
boolean to check if this AC is in grid
std::string getAlternativeValueForDisabledAttributes(SumoXMLAttr key) const
virtual bool isAttributeComputed(SumoXMLAttr key) const
std::string myFilename
filename in which save this AC
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void unselectAttributeCarrier()
unselect attribute carrier using GUIGlobalSelection
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
void setACParameters(const std::vector< std::pair< std::string, std::string > > &parameters)
set parameters (string vector)
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
Position getCommonAttributePosition(SumoXMLAttr key) const
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
methods to retrieve the elements linked to this AttributeCarrier
GNENet * myNet
pointer to net
bool inGrid() const
check if this AC was inserted in grid
void unmarkForDrawingFront()
unmark for drawing front
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)
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
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)
virtual GUIGlObject * getGUIGlObject()=0
get GUIGlObject associated with this AttributeCarrier
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:144
GNENetHelper::SavingFilesHandler * getSavingFilesHandler() const
get saving files handler
Definition GNENet.cpp:156
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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
const GNEViewNetHelper::MouseButtonKeyPressed & getMouseButtonKeyPressed() const
get Key Pressed module
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.
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:323
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
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
bool shiftKeyPressed() const
check if SHIFT is pressed during current event