Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/GNEAttributeCarrier.cpp
169678 views
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
/****************************************************************************/
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/GNENet.h>
22
#include <netedit/GNETagPropertiesDatabase.h>
23
#include <netedit/GNEUndoList.h>
24
#include <netedit/GNEViewNet.h>
25
#include <netedit/changes/GNEChange_Attribute.h>
26
#include <utils/common/StringTokenizer.h>
27
#include <utils/common/ToString.h>
28
#include <utils/emissions/PollutantsInterface.h>
29
#include <utils/geom/GeomConvHelper.h>
30
#include <utils/gui/div/GUIGlobalSelection.h>
31
#include <utils/gui/images/VClassIcons.h>
32
#include <utils/iodevices/OutputDevice.h>
33
#include <utils/options/OptionsCont.h>
34
#include <utils/shapes/PointOfInterest.h>
35
36
#include "GNEAttributeCarrier.h"
37
38
// ===========================================================================
39
// static members
40
// ===========================================================================
41
42
const std::string GNEAttributeCarrier::FEATURE_LOADED = "loaded";
43
const std::string GNEAttributeCarrier::FEATURE_GUESSED = "guessed";
44
const std::string GNEAttributeCarrier::FEATURE_MODIFIED = "modified";
45
const std::string GNEAttributeCarrier::FEATURE_APPROVED = "approved";
46
const std::string GNEAttributeCarrier::LANE_START = TL("lane start");
47
const std::string GNEAttributeCarrier::LANE_END = TL("lane end");
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, 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
63
if (myTagProperty->isAdditionalElement()) {
64
net->getSavingFilesHandler()->addAdditionalFilename(this);
65
} else if (myTagProperty->isDemandElement()) {
66
net->getSavingFilesHandler()->addDemandFilename(this);
67
} else if (myTagProperty->isDataElement()) {
68
net->getSavingFilesHandler()->addDataFilename(this);
69
} else if (myTagProperty->isMeanData()) {
70
net->getSavingFilesHandler()->addMeanDataFilename(this);
71
}
72
} else {
73
// always avoid empty files
74
if (myTagProperty->isAdditionalElement() && (net->getSavingFilesHandler()->getAdditionalFilenames().size() > 0)) {
75
myFilename = net->getSavingFilesHandler()->getAdditionalFilenames().front();
76
} else if (myTagProperty->isDemandElement() && (net->getSavingFilesHandler()->getDemandFilenames().size() > 0)) {
77
myFilename = net->getSavingFilesHandler()->getDemandFilenames().front();
78
} else if (myTagProperty->isDataElement() && (net->getSavingFilesHandler()->getDataFilenames().size() > 0)) {
79
myFilename = net->getSavingFilesHandler()->getDataFilenames().front();
80
} else if (myTagProperty->isMeanData() && (net->getSavingFilesHandler()->getMeanDataFilenames().size() > 0)) {
81
myFilename = net->getSavingFilesHandler()->getMeanDataFilenames().front();
82
}
83
}
84
}
85
86
87
GNEAttributeCarrier::~GNEAttributeCarrier() {}
88
89
90
const std::string
91
GNEAttributeCarrier::getID() const {
92
return getAttribute(SUMO_ATTR_ID);
93
}
94
95
96
GNENet*
97
GNEAttributeCarrier::getNet() const {
98
return myNet;
99
}
100
101
102
const std::string&
103
GNEAttributeCarrier::getFilename() const {
104
return myFilename;
105
}
106
107
108
void
109
GNEAttributeCarrier::changeDefaultFilename(const std::string& file) {
110
if (myFilename.empty()) {
111
myFilename = file;
112
}
113
}
114
115
116
void
117
GNEAttributeCarrier::selectAttributeCarrier() {
118
auto glObject = getGUIGlObject();
119
if (glObject && myTagProperty->isSelectable()) {
120
gSelected.select(glObject->getGlID());
121
mySelected = true;
122
}
123
}
124
125
126
void
127
GNEAttributeCarrier::unselectAttributeCarrier() {
128
auto glObject = getGUIGlObject();
129
if (glObject && myTagProperty->isSelectable()) {
130
gSelected.deselect(glObject->getGlID());
131
mySelected = false;
132
}
133
}
134
135
136
bool
137
GNEAttributeCarrier::isAttributeCarrierSelected() const {
138
return mySelected;
139
}
140
141
142
bool
143
GNEAttributeCarrier::drawUsingSelectColor() const {
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;
151
} else if (myTagProperty->isDemandElement() && myNet->getViewNet()->getEditModes().isCurrentSupermodeDemand()) {
152
return true;
153
} else if (myTagProperty->isGenericData() && myNet->getViewNet()->getEditModes().isCurrentSupermodeData()) {
154
return true;
155
} else {
156
return false;
157
}
158
} else {
159
return false;
160
}
161
}
162
163
void
164
GNEAttributeCarrier::markForDrawingFront() {
165
myNet->getViewNet()->getMarkFrontElements().markAC(this);
166
myDrawInFront = true;
167
}
168
169
170
void
171
GNEAttributeCarrier::unmarkForDrawingFront() {
172
myNet->getViewNet()->getMarkFrontElements().unmarkAC(this);
173
myDrawInFront = false;
174
}
175
176
177
bool
178
GNEAttributeCarrier::isMarkedForDrawingFront() const {
179
return myDrawInFront;
180
}
181
182
183
void
184
GNEAttributeCarrier::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
193
void
194
GNEAttributeCarrier::setInGrid(bool value) {
195
myInGrid = value;
196
}
197
198
199
bool
200
GNEAttributeCarrier::inGrid() const {
201
return myInGrid;
202
}
203
204
205
bool
206
GNEAttributeCarrier::checkDrawInspectContour() const {
207
return myNet->getViewNet()->getInspectedElements().isACInspected(this);
208
}
209
210
211
bool
212
GNEAttributeCarrier::checkDrawFrontContour() const {
213
return myDrawInFront;
214
}
215
216
217
void
218
GNEAttributeCarrier::resetDefaultValues(const bool allowUndoRedo) {
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
250
void
251
GNEAttributeCarrier::enableAttribute(SumoXMLAttr /*key*/, GNEUndoList* /*undoList*/) {
252
throw ProcessError(TL("Nothing to enable, implement in Children"));
253
254
}
255
256
257
void
258
GNEAttributeCarrier::disableAttribute(SumoXMLAttr /*key*/, GNEUndoList* /*undoList*/) {
259
throw ProcessError(TL("Nothing to disable, implement in Children"));
260
}
261
262
263
bool
264
GNEAttributeCarrier::isAttributeEnabled(SumoXMLAttr /*key*/) const {
265
// by default, all attributes are enabled
266
return true;
267
}
268
269
270
bool
271
GNEAttributeCarrier::isAttributeComputed(SumoXMLAttr /*key*/) const {
272
// by default, all attributes aren't computed
273
return false;
274
}
275
276
277
bool
278
GNEAttributeCarrier::hasAttribute(SumoXMLAttr key) const {
279
return myTagProperty->hasAttribute(key);
280
}
281
282
// canParse functions
283
284
template<> bool
285
GNEAttributeCarrier::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
294
template<> bool
295
GNEAttributeCarrier::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
304
template<> bool
305
GNEAttributeCarrier::canParse<SUMOTime>(const std::string& string) {
306
return isTime(string);
307
}
308
309
310
template<> bool
311
GNEAttributeCarrier::canParse<bool>(const std::string& string) {
312
return StringUtils::isBool(string);
313
}
314
315
316
template<> bool
317
GNEAttributeCarrier::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
324
template<> bool
325
GNEAttributeCarrier::canParse<SUMOVehicleClass>(const std::string& string) {
326
return SumoVehicleClassStrings.hasString(string);
327
}
328
329
330
template<> bool
331
GNEAttributeCarrier::canParse<RGBColor>(const std::string& string) {
332
return RGBColor::isColor(string);
333
}
334
335
336
template<> bool
337
GNEAttributeCarrier::canParse<SumoXMLAttr>(const std::string& string) {
338
return SUMOXMLDefinitions::Attrs.hasString(string);
339
}
340
341
342
template<> bool
343
GNEAttributeCarrier::canParse<SUMOVehicleShape>(const std::string& string) {
344
if (string.empty()) {
345
return true;
346
} else {
347
return SumoVehicleShapeStrings.hasString(string);
348
}
349
}
350
351
352
template<> bool
353
GNEAttributeCarrier::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
360
template<> bool
361
GNEAttributeCarrier::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
375
template<> bool
376
GNEAttributeCarrier::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
390
template<> bool
391
GNEAttributeCarrier::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
405
template<> bool
406
GNEAttributeCarrier::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
421
template<> int
422
GNEAttributeCarrier::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
431
template<> double
432
GNEAttributeCarrier::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
441
template<> SUMOTime
442
GNEAttributeCarrier::parse(const std::string& string) {
443
return string2time(string);
444
}
445
446
447
template<> bool
448
GNEAttributeCarrier::parse(const std::string& string) {
449
return StringUtils::toBool(string);
450
}
451
452
453
template<> SUMOVehicleClass
454
GNEAttributeCarrier::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
465
template<> RGBColor
466
GNEAttributeCarrier::parse(const std::string& string) {
467
if (string.empty()) {
468
return RGBColor::INVISIBLE;
469
} else {
470
return RGBColor::parseColor(string);
471
}
472
}
473
474
475
template<> Position
476
GNEAttributeCarrier::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
492
template<> PositionVector
493
GNEAttributeCarrier::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
510
template<> SUMOVehicleShape
511
GNEAttributeCarrier::parse(const std::string& string) {
512
if (string.empty()) {
513
return SUMOVehicleShape::UNKNOWN;
514
} else {
515
return SumoVehicleShapeStrings.get(string);
516
}
517
}
518
519
520
template<> std::vector<std::string>
521
GNEAttributeCarrier::parse(const std::string& string) {
522
return StringTokenizer(string).getVector();
523
}
524
525
526
template<> std::set<std::string>
527
GNEAttributeCarrier::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
537
template<> std::vector<int>
538
GNEAttributeCarrier::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
548
template<> std::vector<double>
549
GNEAttributeCarrier::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
559
template<> std::vector<bool>
560
GNEAttributeCarrier::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
570
template<> std::vector<SumoXMLAttr>
571
GNEAttributeCarrier::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
588
template<> bool
589
GNEAttributeCarrier::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
609
template<> bool
610
GNEAttributeCarrier::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
632
template<> std::vector<GNEEdge*>
633
GNEAttributeCarrier::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
646
template<> std::vector<GNELane*>
647
GNEAttributeCarrier::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
661
template<> std::string
662
GNEAttributeCarrier::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
672
template<> std::string
673
GNEAttributeCarrier::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
void
683
GNEAttributeCarrier::setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters) {
684
// declare result string
685
std::string paramsStr;
686
// Generate an string using the following structure: "key1=value1|key2=value2|...
687
for (const auto& parameter : parameters) {
688
paramsStr += parameter.first + "=" + parameter.second + "|";
689
}
690
// remove the last "|"
691
if (!paramsStr.empty()) {
692
paramsStr.pop_back();
693
}
694
// set parameters
695
setAttribute(GNE_ATTR_PARAMETERS, paramsStr);
696
}
697
698
699
void
700
GNEAttributeCarrier::setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList) {
701
// declare parametersMap
702
Parameterised::Map parametersMap;
703
// Generate an string using the following structure: "key1=value1|key2=value2|...
704
for (const auto& parameter : parameters) {
705
parametersMap[parameter.first] = parameter.second;
706
}
707
// set setACParameters map
708
setACParameters(parametersMap, undoList);
709
}
710
711
712
void
713
GNEAttributeCarrier::setACParameters(const Parameterised::Map& parameters, GNEUndoList* undoList) {
714
// declare result string
715
std::string paramsStr;
716
// Generate an string using the following structure: "key1=value1|key2=value2|...
717
for (const auto& parameter : parameters) {
718
paramsStr += parameter.first + "=" + parameter.second + "|";
719
}
720
// remove the last "|"
721
if (!paramsStr.empty()) {
722
paramsStr.pop_back();
723
}
724
// set parameters
725
setAttribute(GNE_ATTR_PARAMETERS, paramsStr, undoList);
726
}
727
728
729
std::string
730
GNEAttributeCarrier::getAlternativeValueForDisabledAttributes(SumoXMLAttr key) const {
731
switch (key) {
732
// Crossings
733
case SUMO_ATTR_TLLINKINDEX:
734
case SUMO_ATTR_TLLINKINDEX2:
735
return "No TLS";
736
// connections
737
case SUMO_ATTR_DIR: {
738
// special case for connection directions
739
std::string direction = getAttribute(key);
740
if (direction == "s") {
741
return "Straight (s)";
742
} else if (direction == "t") {
743
return "Turn (t))";
744
} else if (direction == "l") {
745
return "Left (l)";
746
} else if (direction == "r") {
747
return "Right (r)";
748
} else if (direction == "L") {
749
return "Partially left (L)";
750
} else if (direction == "R") {
751
return "Partially right (R)";
752
} else if (direction == "invalid") {
753
return "No direction (Invalid))";
754
} else {
755
return "undefined";
756
}
757
}
758
case SUMO_ATTR_STATE: {
759
// special case for connection states
760
std::string state = getAttribute(key);
761
if (state == "-") {
762
return "Dead end (-)";
763
} else if (state == "=") {
764
return "equal (=)";
765
} else if (state == "m") {
766
return "Minor link (m)";
767
} else if (state == "M") {
768
return "Major link (M)";
769
} else if (state == "O") {
770
return "TLS controller off (O)";
771
} else if (state == "o") {
772
return "TLS yellow flashing (o)";
773
} else if (state == "y") {
774
return "TLS yellow minor link (y)";
775
} else if (state == "Y") {
776
return "TLS yellow major link (Y)";
777
} else if (state == "r") {
778
return "TLS red (r)";
779
} else if (state == "g") {
780
return "TLS green minor (g)";
781
} else if (state == "G") {
782
return "TLS green major (G)";
783
} else if (state == "Z") {
784
return "Zipper (Z)";
785
} else {
786
return "undefined";
787
}
788
}
789
default:
790
return getAttribute(key);
791
}
792
}
793
794
795
std::string
796
GNEAttributeCarrier::getAttributeForSelection(SumoXMLAttr key) const {
797
return getAttribute(key);
798
}
799
800
801
const std::string&
802
GNEAttributeCarrier::getTagStr() const {
803
return myTagProperty->getTagStr();
804
}
805
806
807
FXIcon*
808
GNEAttributeCarrier::getACIcon() const {
809
// special case for vClass icons
810
if (myTagProperty->vClassIcon()) {
811
return VClassIcons::getVClassIcon(SumoVehicleClassStrings.get(getAttribute(SUMO_ATTR_VCLASS)));
812
} else {
813
return GUIIconSubSys::getIcon(myTagProperty->getGUIIcon());
814
}
815
}
816
817
818
bool
819
GNEAttributeCarrier::isTemplate() const {
820
return myIsTemplate;
821
}
822
823
824
const GNETagProperties*
825
GNEAttributeCarrier::getTagProperty() const {
826
return myTagProperty;
827
}
828
829
// ===========================================================================
830
// private
831
// ===========================================================================
832
833
void
834
GNEAttributeCarrier::toggleAttribute(SumoXMLAttr /*key*/, const bool /*value*/) {
835
throw ProcessError(TL("Nothing to toggle, implement in Children"));
836
}
837
838
839
std::string
840
GNEAttributeCarrier::getCommonAttribute(const Parameterised* parameterised, SumoXMLAttr key) const {
841
switch (key) {
842
case GNE_ATTR_ADDITIONAL_FILE:
843
case GNE_ATTR_DEMAND_FILE:
844
case GNE_ATTR_DATA_FILE:
845
case GNE_ATTR_MEANDATA_FILE:
846
return myFilename;
847
case GNE_ATTR_CENTER_AFTER_CREATION:
848
return toString(myCenterAfterCreation);
849
case GNE_ATTR_SELECTED:
850
if (mySelected) {
851
return TRUE_STR;
852
} else {
853
return FALSE_STR;
854
}
855
case GNE_ATTR_FRONTELEMENT:
856
if (myDrawInFront) {
857
return TRUE_STR;
858
} else {
859
return FALSE_STR;
860
}
861
case GNE_ATTR_PARAMETERS:
862
return parameterised->getParametersStr();
863
default:
864
throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
865
}
866
}
867
868
869
void
870
GNEAttributeCarrier::setCommonAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
871
switch (key) {
872
case GNE_ATTR_ADDITIONAL_FILE:
873
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
874
// update filenames of all additional childrens
875
for (auto additionalChild : getHierarchicalElement()->getChildAdditionals()) {
876
additionalChild->setAttribute(key, value, undoList);
877
}
878
break;
879
case GNE_ATTR_DEMAND_FILE:
880
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
881
// update filenames of all demand childrens
882
for (auto demandChild : getHierarchicalElement()->getChildDemandElements()) {
883
demandChild->setAttribute(key, myFilename, undoList);
884
}
885
break;
886
case GNE_ATTR_DATA_FILE:
887
case GNE_ATTR_MEANDATA_FILE:
888
case GNE_ATTR_CENTER_AFTER_CREATION:
889
case GNE_ATTR_SELECTED:
890
case GNE_ATTR_PARAMETERS:
891
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
892
break;
893
default:
894
throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
895
}
896
}
897
898
899
bool
900
GNEAttributeCarrier::isCommonValid(SumoXMLAttr key, const std::string& value) const {
901
switch (key) {
902
case GNE_ATTR_ADDITIONAL_FILE:
903
case GNE_ATTR_DEMAND_FILE:
904
case GNE_ATTR_DATA_FILE:
905
case GNE_ATTR_MEANDATA_FILE:
906
return SUMOXMLDefinitions::isValidFilename(value);
907
case GNE_ATTR_CENTER_AFTER_CREATION:
908
case GNE_ATTR_SELECTED:
909
return canParse<bool>(value);
910
case GNE_ATTR_PARAMETERS:
911
return Parameterised::areParametersValid(value);
912
default:
913
throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
914
}
915
}
916
917
918
void
919
GNEAttributeCarrier::setCommonAttribute(Parameterised* parameterised, SumoXMLAttr key, const std::string& value) {
920
switch (key) {
921
case GNE_ATTR_ADDITIONAL_FILE:
922
myFilename = value;
923
if (value.empty()) {
924
// try to avoid empty files
925
if (myNet->getSavingFilesHandler()->getAdditionalFilenames().size() > 0) {
926
myFilename = myNet->getSavingFilesHandler()->getAdditionalFilenames().front();
927
}
928
} else {
929
myNet->getSavingFilesHandler()->addAdditionalFilename(this);
930
}
931
break;
932
case GNE_ATTR_DEMAND_FILE:
933
myFilename = value;
934
if (value.empty()) {
935
// try to avoid empty files
936
if (myNet->getSavingFilesHandler()->getDemandFilenames().size() > 0) {
937
myFilename = myNet->getSavingFilesHandler()->getDemandFilenames().front();
938
}
939
} else {
940
myNet->getSavingFilesHandler()->addDemandFilename(this);
941
}
942
break;
943
case GNE_ATTR_DATA_FILE:
944
myFilename = value;
945
if (value.empty()) {
946
// try to avoid empty files
947
if (myNet->getSavingFilesHandler()->getDataFilenames().size() > 0) {
948
myFilename = myNet->getSavingFilesHandler()->getDataFilenames().front();
949
}
950
} else {
951
myNet->getSavingFilesHandler()->addDataFilename(this);
952
}
953
break;
954
case GNE_ATTR_MEANDATA_FILE:
955
myFilename = value;
956
if (value.empty()) {
957
// try to avoid empty files
958
if (myNet->getSavingFilesHandler()->getMeanDataFilenames().size() > 0) {
959
myFilename = myNet->getSavingFilesHandler()->getMeanDataFilenames().front();
960
}
961
} else {
962
myNet->getSavingFilesHandler()->addMeanDataFilename(this);
963
}
964
break;
965
case GNE_ATTR_CENTER_AFTER_CREATION:
966
myCenterAfterCreation = parse<bool>(value);
967
break;
968
case GNE_ATTR_SELECTED:
969
if (parse<bool>(value)) {
970
selectAttributeCarrier();
971
} else {
972
unselectAttributeCarrier();
973
}
974
break;
975
case GNE_ATTR_PARAMETERS:
976
parameterised->setParametersStr(value);
977
break;
978
default:
979
throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
980
}
981
}
982
983
/****************************************************************************/
984
985