Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/GNEAttributeCarrier.cpp
193674 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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
/****************************************************************************/
14
/// @file GNEAttributeCarrier.cpp
15
/// @author Jakob Erdmann
16
/// @date Feb 2011
17
///
18
// Abstract Base class for gui objects which carry attributes
19
/****************************************************************************/
20
21
#include <netedit/changes/GNEChange_Attribute.h>
22
#include <netedit/GNEApplicationWindow.h>
23
#include <netedit/GNENet.h>
24
#include <netedit/GNETagPropertiesDatabase.h>
25
#include <netedit/GNEUndoList.h>
26
#include <netedit/GNEViewNet.h>
27
#include <netedit/GNEViewParent.h>
28
#include <utils/common/StringTokenizer.h>
29
#include <utils/common/ToString.h>
30
#include <utils/emissions/PollutantsInterface.h>
31
#include <utils/geom/GeomConvHelper.h>
32
#include <utils/gui/div/GUIGlobalSelection.h>
33
#include <utils/gui/images/VClassIcons.h>
34
#include <utils/iodevices/OutputDevice.h>
35
#include <utils/options/OptionsCont.h>
36
#include <utils/shapes/PointOfInterest.h>
37
38
#include "GNEAttributeCarrier.h"
39
40
// ===========================================================================
41
// static members
42
// ===========================================================================
43
44
const std::string GNEAttributeCarrier::FEATURE_LOADED = "loaded";
45
const std::string GNEAttributeCarrier::FEATURE_GUESSED = "guessed";
46
const std::string GNEAttributeCarrier::FEATURE_MODIFIED = "modified";
47
const std::string GNEAttributeCarrier::FEATURE_APPROVED = "approved";
48
const std::string GNEAttributeCarrier::TRUE_STR = toString(true);
49
const std::string GNEAttributeCarrier::FALSE_STR = toString(false);
50
51
// ===========================================================================
52
// method definitions
53
// ===========================================================================
54
55
GNEAttributeCarrier::GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net) :
56
myTagProperty(net->getTagPropertiesDatabase()->getTagProperty(tag, true)),
57
myNet(net),
58
myIsTemplate(true) {
59
// set default bucket for template elements
60
auto savingFilesHandler = net->getGNEApplicationWindow()->getFileBucketHandler();
61
if (myTagProperty->saveInNetworkFile()) {
62
myFileBucket = savingFilesHandler->getDefaultBucket(FileBucket::Type::NETWORK);
63
} else if (myTagProperty->saveInDataFile()) {
64
myFileBucket = savingFilesHandler->getDefaultBucket(FileBucket::Type::DATA);
65
} else if (myTagProperty->saveInDemandFile()) {
66
myFileBucket = savingFilesHandler->getDefaultBucket(FileBucket::Type::DEMAND);
67
} else if (myTagProperty->saveInMeanDataFile()) {
68
myFileBucket = savingFilesHandler->getDefaultBucket(FileBucket::Type::MEANDATA);
69
} else if (myTagProperty->saveInAdditionalFile()) {
70
// additional MUST be the last, because demand and data elements can be saved in additional files
71
myFileBucket = savingFilesHandler->getDefaultBucket(FileBucket::Type::ADDITIONAL);
72
}
73
// update counter in filebucket
74
if (myFileBucket) {
75
myFileBucket->addElement(true);
76
}
77
}
78
79
GNEAttributeCarrier::GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net, FileBucket* fileBucket) :
80
myTagProperty(net->getTagPropertiesDatabase()->getTagProperty(tag, true)),
81
myNet(net),
82
myFileBucket(fileBucket) {
83
}
84
85
86
GNEAttributeCarrier::~GNEAttributeCarrier() {
87
// update counter in filebucket
88
if (myIsTemplate && myFileBucket) {
89
myFileBucket->removeElement(true);
90
}
91
}
92
93
94
const std::string
95
GNEAttributeCarrier::getID() const {
96
return getAttribute(SUMO_ATTR_ID);
97
}
98
99
100
GNENet*
101
GNEAttributeCarrier::getNet() const {
102
return myNet;
103
}
104
105
106
void
107
GNEAttributeCarrier::selectAttributeCarrier() {
108
auto glObject = getGUIGlObject();
109
if (glObject && myTagProperty->isSelectable()) {
110
gSelected.select(glObject->getGlID());
111
mySelected = true;
112
}
113
}
114
115
116
void
117
GNEAttributeCarrier::unselectAttributeCarrier() {
118
auto glObject = getGUIGlObject();
119
if (glObject && myTagProperty->isSelectable()) {
120
gSelected.deselect(glObject->getGlID());
121
mySelected = false;
122
}
123
}
124
125
126
bool
127
GNEAttributeCarrier::isAttributeCarrierSelected() const {
128
return mySelected;
129
}
130
131
132
bool
133
GNEAttributeCarrier::drawUsingSelectColor() const {
134
// first check if element is selected
135
if (mySelected) {
136
// get flag for network element
137
const bool networkElement = myTagProperty->isNetworkElement() || myTagProperty->isAdditionalElement();
138
// check current supermode
139
if (networkElement && myNet->getViewNet()->getEditModes().isCurrentSupermodeNetwork()) {
140
return true;
141
} else if (myTagProperty->isDemandElement() && myNet->getViewNet()->getEditModes().isCurrentSupermodeDemand()) {
142
return true;
143
} else if (myTagProperty->isGenericData() && myNet->getViewNet()->getEditModes().isCurrentSupermodeData()) {
144
return true;
145
} else {
146
return false;
147
}
148
} else {
149
return false;
150
}
151
}
152
153
154
bool
155
GNEAttributeCarrier::drawMovingGeometryPoints() const {
156
// get modes
157
const auto& modes = myNet->getViewNet()->getEditModes();
158
// check conditions
159
if (!myNet->getViewNet()->getMouseButtonKeyPressed().shiftKeyPressed()) {
160
return false;
161
} else if (modes.isCurrentSupermodeNetwork() && (modes.networkEditMode == NetworkEditMode::NETWORK_MOVE)) {
162
return true;
163
} else if (modes.isCurrentSupermodeDemand() && (modes.demandEditMode == DemandEditMode::DEMAND_MOVE)) {
164
return true;
165
} else {
166
return false;
167
}
168
}
169
170
171
void
172
GNEAttributeCarrier::markForDrawingFront() {
173
myNet->getViewNet()->getMarkFrontElements().markAC(this);
174
myDrawInFront = true;
175
}
176
177
178
void
179
GNEAttributeCarrier::unmarkForDrawingFront() {
180
myNet->getViewNet()->getMarkFrontElements().unmarkAC(this);
181
myDrawInFront = false;
182
}
183
184
185
bool
186
GNEAttributeCarrier::isMarkedForDrawingFront() const {
187
return myDrawInFront;
188
}
189
190
191
void
192
GNEAttributeCarrier::drawInLayer(double typeOrLayer, const double extraOffset) const {
193
if (myDrawInFront) {
194
glTranslated(0, 0, GLO_FRONTELEMENT + extraOffset);
195
} else {
196
glTranslated(0, 0, typeOrLayer + extraOffset);
197
}
198
}
199
200
201
void
202
GNEAttributeCarrier::setInGrid(bool value) {
203
myInGrid = value;
204
}
205
206
207
bool
208
GNEAttributeCarrier::inGrid() const {
209
return myInGrid;
210
}
211
212
213
bool
214
GNEAttributeCarrier::checkDrawInspectContour() const {
215
return myNet->getViewNet()->getInspectedElements().isACInspected(this);
216
}
217
218
219
bool
220
GNEAttributeCarrier::checkDrawFrontContour() const {
221
return myDrawInFront;
222
}
223
224
225
void
226
GNEAttributeCarrier::resetDefaultValues(const bool allowUndoRedo) {
227
if (allowUndoRedo) {
228
// reset within undo-redo
229
const auto undoList = myNet->getUndoList();
230
undoList->begin(myTagProperty->getGUIIcon(), TLF("reset %", myTagProperty->getTagStr()));
231
for (const auto& attrProperty : myTagProperty->getAttributeProperties()) {
232
if ((attrProperty->getAttr() != GNE_ATTR_SAVEFILE) && !attrProperty->isUnique() && attrProperty->hasDefaultValue()) {
233
setAttribute(attrProperty->getAttr(), attrProperty->getDefaultStringValue(), undoList);
234
if (attrProperty->isActivatable()) {
235
if (attrProperty->getDefaultActivated()) {
236
enableAttribute(attrProperty->getAttr(), undoList);
237
} else {
238
disableAttribute(attrProperty->getAttr(), undoList);
239
}
240
}
241
}
242
}
243
undoList->end();
244
} else {
245
// simply reset every
246
for (const auto& attrProperty : myTagProperty->getAttributeProperties()) {
247
if ((attrProperty->getAttr() != GNE_ATTR_SAVEFILE) && attrProperty->hasDefaultValue()) {
248
setAttribute(attrProperty->getAttr(), attrProperty->getDefaultStringValue());
249
if (attrProperty->isActivatable()) {
250
toggleAttribute(attrProperty->getAttr(), attrProperty->getDefaultActivated());
251
}
252
}
253
}
254
}
255
}
256
257
258
void
259
GNEAttributeCarrier::enableAttribute(SumoXMLAttr /*key*/, GNEUndoList* /*undoList*/) {
260
throw ProcessError(TL("Nothing to enable, implement in Children"));
261
262
}
263
264
265
void
266
GNEAttributeCarrier::disableAttribute(SumoXMLAttr /*key*/, GNEUndoList* /*undoList*/) {
267
throw ProcessError(TL("Nothing to disable, implement in Children"));
268
}
269
270
271
bool
272
GNEAttributeCarrier::isAttributeEnabled(SumoXMLAttr key) const {
273
switch (key) {
274
case GNE_ATTR_SAVEFILE:
275
if (myTagProperty->saveInNetworkFile() || myTagProperty->saveInParentFile()) {
276
return false;
277
} else {
278
return (myFileBucket != nullptr);
279
}
280
default:
281
return true;
282
}
283
}
284
285
286
bool
287
GNEAttributeCarrier::isAttributeComputed(SumoXMLAttr /*key*/) const {
288
// by default, all attributes aren't computed
289
return false;
290
}
291
292
293
bool
294
GNEAttributeCarrier::hasAttribute(SumoXMLAttr key) const {
295
return myTagProperty->hasAttribute(key);
296
}
297
298
// canParse functions
299
300
template<> bool
301
GNEAttributeCarrier::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
310
template<> bool
311
GNEAttributeCarrier::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
320
template<> bool
321
GNEAttributeCarrier::canParse<SUMOTime>(const std::string& string) {
322
return isTime(string);
323
}
324
325
326
template<> bool
327
GNEAttributeCarrier::canParse<bool>(const std::string& string) {
328
return StringUtils::isBool(string);
329
}
330
331
332
template<> bool
333
GNEAttributeCarrier::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
340
template<> bool
341
GNEAttributeCarrier::canParse<SUMOVehicleClass>(const std::string& string) {
342
return SumoVehicleClassStrings.hasString(string);
343
}
344
345
346
template<> bool
347
GNEAttributeCarrier::canParse<RGBColor>(const std::string& string) {
348
return RGBColor::isColor(string);
349
}
350
351
352
template<> bool
353
GNEAttributeCarrier::canParse<SumoXMLAttr>(const std::string& string) {
354
return SUMOXMLDefinitions::Attrs.hasString(string);
355
}
356
357
358
template<> bool
359
GNEAttributeCarrier::canParse<SUMOVehicleShape>(const std::string& string) {
360
if (string.empty()) {
361
return true;
362
} else {
363
return SumoVehicleShapeStrings.hasString(string);
364
}
365
}
366
367
368
template<> bool
369
GNEAttributeCarrier::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
376
template<> bool
377
GNEAttributeCarrier::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
391
template<> bool
392
GNEAttributeCarrier::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
406
template<> bool
407
GNEAttributeCarrier::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
421
template<> bool
422
GNEAttributeCarrier::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
437
template<> int
438
GNEAttributeCarrier::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
447
template<> double
448
GNEAttributeCarrier::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
457
template<> SUMOTime
458
GNEAttributeCarrier::parse(const std::string& string) {
459
return string2time(string);
460
}
461
462
463
template<> bool
464
GNEAttributeCarrier::parse(const std::string& string) {
465
return StringUtils::toBool(string);
466
}
467
468
469
template<> SUMOVehicleClass
470
GNEAttributeCarrier::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
481
template<> RGBColor
482
GNEAttributeCarrier::parse(const std::string& string) {
483
if (string.empty()) {
484
return RGBColor::INVISIBLE;
485
} else {
486
return RGBColor::parseColor(string);
487
}
488
}
489
490
491
template<> Position
492
GNEAttributeCarrier::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
508
template<> PositionVector
509
GNEAttributeCarrier::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
526
template<> SUMOVehicleShape
527
GNEAttributeCarrier::parse(const std::string& string) {
528
if (string.empty()) {
529
return SUMOVehicleShape::UNKNOWN;
530
} else {
531
return SumoVehicleShapeStrings.get(string);
532
}
533
}
534
535
536
template<> std::vector<std::string>
537
GNEAttributeCarrier::parse(const std::string& string) {
538
return StringTokenizer(string).getVector();
539
}
540
541
542
template<> std::set<std::string>
543
GNEAttributeCarrier::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
553
template<> std::vector<int>
554
GNEAttributeCarrier::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
564
template<> std::vector<double>
565
GNEAttributeCarrier::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
575
template<> std::vector<bool>
576
GNEAttributeCarrier::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
586
template<> std::vector<SumoXMLAttr>
587
GNEAttributeCarrier::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
604
template<> bool
605
GNEAttributeCarrier::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
625
template<> bool
626
GNEAttributeCarrier::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
648
template<> std::vector<GNEEdge*>
649
GNEAttributeCarrier::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
662
template<> std::vector<GNELane*>
663
GNEAttributeCarrier::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
677
template<> std::string
678
GNEAttributeCarrier::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
688
template<> std::string
689
GNEAttributeCarrier::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
698
void
699
GNEAttributeCarrier::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
711
setAttribute(GNE_ATTR_PARAMETERS, paramsStr);
712
}
713
714
715
void
716
GNEAttributeCarrier::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
728
void
729
GNEAttributeCarrier::setACParameters(const Parameterised::Map& parameters, GNEUndoList* undoList) {
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
745
std::string
746
GNEAttributeCarrier::getAlternativeValueForDisabledAttributes(SumoXMLAttr key) const {
747
switch (key) {
748
// Crossings
749
case SUMO_ATTR_TLLINKINDEX:
750
case SUMO_ATTR_TLLINKINDEX2:
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
811
std::string
812
GNEAttributeCarrier::getAttributeForSelection(SumoXMLAttr key) const {
813
return getAttribute(key);
814
}
815
816
817
const std::string&
818
GNEAttributeCarrier::getTagStr() const {
819
return myTagProperty->getTagStr();
820
}
821
822
823
FXIcon*
824
GNEAttributeCarrier::getACIcon() const {
825
// special case for vClass icons
826
if (myTagProperty->vClassIcon()) {
827
return VClassIcons::getVClassIcon(SumoVehicleClassStrings.get(getAttribute(SUMO_ATTR_VCLASS)));
828
} else {
829
return GUIIconSubSys::getIcon(myTagProperty->getGUIIcon());
830
}
831
}
832
833
834
bool
835
GNEAttributeCarrier::isTemplate() const {
836
return myIsTemplate;
837
}
838
839
840
const GNETagProperties*
841
GNEAttributeCarrier::getTagProperty() const {
842
return myTagProperty;
843
}
844
845
846
std::string
847
GNEAttributeCarrier::getCommonAttribute(SumoXMLAttr key) const {
848
switch (key) {
849
case GNE_ATTR_SAVEFILE:
850
if (myFileBucket) {
851
return getFileBucket()->getFilename();
852
} else {
853
return TL("Parent filename");
854
}
855
case GNE_ATTR_CENTER_AFTER_CREATION:
856
return toString(myCenterAfterCreation);
857
case GNE_ATTR_SELECTED:
858
if (mySelected) {
859
return TRUE_STR;
860
} else {
861
return FALSE_STR;
862
}
863
case GNE_ATTR_FRONTELEMENT:
864
if (myDrawInFront) {
865
return TRUE_STR;
866
} else {
867
return FALSE_STR;
868
}
869
case GNE_ATTR_PARAMETERS:
870
if (getParameters()) {
871
return getParameters()->getParametersStr();
872
} else {
873
throw InvalidArgument(getTagStr() + " doesn't support parameters");
874
}
875
default:
876
throw InvalidArgument(getTagStr() + " doesn't have a common attribute of type '" + toString(key) + "'");
877
}
878
}
879
880
881
double
882
GNEAttributeCarrier::getCommonAttributeDouble(SumoXMLAttr key) const {
883
throw InvalidArgument(getTagStr() + " doesn't have a common double attribute of type '" + toString(key) + "'");
884
}
885
886
887
Position
888
GNEAttributeCarrier::getCommonAttributePosition(SumoXMLAttr key) const {
889
throw InvalidArgument(getTagStr() + " doesn't have a common position attribute of type '" + toString(key) + "'");
890
}
891
892
893
PositionVector
894
GNEAttributeCarrier::getCommonAttributePositionVector(SumoXMLAttr key) const {
895
throw InvalidArgument(getTagStr() + " doesn't have a common positionVector attribute of type '" + toString(key) + "'");
896
}
897
898
899
void
900
GNEAttributeCarrier::setCommonAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
901
switch (key) {
902
case GNE_ATTR_SAVEFILE:
903
case GNE_ATTR_CENTER_AFTER_CREATION:
904
case GNE_ATTR_SELECTED:
905
case GNE_ATTR_PARAMETERS:
906
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
907
break;
908
default:
909
throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
910
}
911
}
912
913
914
bool
915
GNEAttributeCarrier::isCommonAttributeValid(SumoXMLAttr key, const std::string& value) const {
916
switch (key) {
917
case GNE_ATTR_SAVEFILE:
918
if (SUMOXMLDefinitions::isValidFilename(value)) {
919
return myNet->getGNEApplicationWindow()->getFileBucketHandler()->checkFilename(this, value);
920
} else {
921
return false;
922
}
923
case GNE_ATTR_CENTER_AFTER_CREATION:
924
case GNE_ATTR_SELECTED:
925
return canParse<bool>(value);
926
case GNE_ATTR_PARAMETERS:
927
return Parameterised::areParametersValid(value);
928
default:
929
throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
930
}
931
}
932
933
934
void
935
GNEAttributeCarrier::setCommonAttribute(SumoXMLAttr key, const std::string& value) {
936
switch (key) {
937
case GNE_ATTR_SAVEFILE:
938
myFileBucket = myNet->getGNEApplicationWindow()->getFileBucketHandler()->updateAC(this, value);
939
break;
940
case GNE_ATTR_CENTER_AFTER_CREATION:
941
myCenterAfterCreation = parse<bool>(value);
942
break;
943
case GNE_ATTR_SELECTED:
944
if (parse<bool>(value)) {
945
selectAttributeCarrier();
946
} else {
947
unselectAttributeCarrier();
948
}
949
break;
950
case GNE_ATTR_PARAMETERS:
951
if (getParameters()) {
952
getParameters()->setParametersStr(value);
953
} else {
954
throw InvalidArgument(getTagStr() + " doesn't support parameters");
955
}
956
break;
957
default:
958
throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
959
}
960
}
961
962
// ===========================================================================
963
// private
964
// ===========================================================================
965
966
void
967
GNEAttributeCarrier::toggleAttribute(SumoXMLAttr /*key*/, const bool /*value*/) {
968
throw ProcessError(TL("Nothing to toggle, implement in Children"));
969
}
970
971
/****************************************************************************/
972
973