Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/settings/GUIPropertySchemeStorage.h
169684 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 GUIPropertySchemeStorage.h
15
/// @author Michael Behrisch
16
/// @author Daniel Krajzewicz
17
/// @author Jakob Erdmann
18
/// @author Laura Bieker
19
/// @date Mon, 20.07.2009
20
///
21
//
22
/****************************************************************************/
23
#pragma once
24
#include <config.h>
25
26
#include <vector>
27
#include <utils/foxtools/fxheader.h>
28
#include <utils/gui/images/GUIIconSubSys.h>
29
#include <utils/foxtools/MFXComboBoxIcon.h>
30
#include <utils/foxtools/MFXUtils.h>
31
#include "GUIPropertyScheme.h"
32
33
34
// ===========================================================================
35
// class declarations
36
// ===========================================================================
37
class OutputDevice;
38
39
40
// ===========================================================================
41
// class definitions
42
// ===========================================================================
43
/**
44
* @class GUIPropertySchemeStorage
45
* @brief Base class for coloring. Allows changing the used colors and sets
46
* the used color in dependence to a value
47
*/
48
template<class T>
49
class GUIPropertySchemeStorage {
50
public:
51
/// @brief Constructor
52
GUIPropertySchemeStorage() : myActiveScheme(0) { }
53
54
/// @brief Destructor
55
virtual ~GUIPropertySchemeStorage() { }
56
57
/// @brief Fills the given combobox with the names of available colorings
58
void fill(MFXComboBoxIcon& cb) {
59
for (const auto& scheme : mySchemes) {
60
cb.appendIconItem(scheme.getTranslatedName().c_str(),
61
scheme.getIcon() == GUIIcon::EMPTY ? nullptr : GUIIconSubSys::getIcon(scheme.getIcon()),
62
MFXUtils::getFXColor(scheme.getBackgroundColor()));
63
}
64
cb.setCurrentItem((FXint)myActiveScheme);
65
}
66
67
void setActive(int scheme) {
68
if (scheme < (int)mySchemes.size()) {
69
myActiveScheme = scheme;
70
}
71
}
72
73
int getActive() const {
74
return myActiveScheme;
75
}
76
77
T& getScheme() {
78
return mySchemes[myActiveScheme];
79
}
80
81
const T& getScheme() const {
82
return mySchemes[myActiveScheme];
83
}
84
85
const std::vector<T>& getSchemes() const {
86
return mySchemes;
87
}
88
89
T* getSchemeByName(std::string name) {
90
for (typename std::vector<T>::iterator i = mySchemes.begin(); i != mySchemes.end(); ++i) {
91
if ((*i).getName() == name) {
92
return &(*i);
93
}
94
}
95
return 0;
96
}
97
98
void setSchemeByName(std::string name) {
99
for (int i = 0; i < (int)mySchemes.size(); i++) {
100
if (mySchemes[i].getName() == name) {
101
myActiveScheme = i;
102
break;
103
}
104
}
105
}
106
107
void save(OutputDevice& dev, const std::string& prefix = "") const {
108
for (typename std::vector<T>::const_iterator i = mySchemes.begin(); i != mySchemes.end(); ++i) {
109
i->save(dev, prefix);
110
}
111
}
112
113
bool operator==(const GUIPropertySchemeStorage& c) const {
114
return myActiveScheme == c.myActiveScheme && mySchemes == c.mySchemes;
115
}
116
117
118
void addScheme(T scheme) {
119
mySchemes.push_back(scheme);
120
}
121
122
int size() const {
123
return (int)mySchemes.size();
124
}
125
126
127
protected:
128
int myActiveScheme;
129
std::vector<T> mySchemes;
130
131
};
132
133
typedef GUIPropertySchemeStorage<GUIColorScheme> GUIColorer;
134
typedef GUIPropertySchemeStorage<GUIScaleScheme> GUIScaler;
135
136