Path: blob/main/src/utils/gui/settings/GUIPropertySchemeStorage.h
169684 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GUIPropertySchemeStorage.h14/// @author Michael Behrisch15/// @author Daniel Krajzewicz16/// @author Jakob Erdmann17/// @author Laura Bieker18/// @date Mon, 20.07.200919///20//21/****************************************************************************/22#pragma once23#include <config.h>2425#include <vector>26#include <utils/foxtools/fxheader.h>27#include <utils/gui/images/GUIIconSubSys.h>28#include <utils/foxtools/MFXComboBoxIcon.h>29#include <utils/foxtools/MFXUtils.h>30#include "GUIPropertyScheme.h"313233// ===========================================================================34// class declarations35// ===========================================================================36class OutputDevice;373839// ===========================================================================40// class definitions41// ===========================================================================42/**43* @class GUIPropertySchemeStorage44* @brief Base class for coloring. Allows changing the used colors and sets45* the used color in dependence to a value46*/47template<class T>48class GUIPropertySchemeStorage {49public:50/// @brief Constructor51GUIPropertySchemeStorage() : myActiveScheme(0) { }5253/// @brief Destructor54virtual ~GUIPropertySchemeStorage() { }5556/// @brief Fills the given combobox with the names of available colorings57void fill(MFXComboBoxIcon& cb) {58for (const auto& scheme : mySchemes) {59cb.appendIconItem(scheme.getTranslatedName().c_str(),60scheme.getIcon() == GUIIcon::EMPTY ? nullptr : GUIIconSubSys::getIcon(scheme.getIcon()),61MFXUtils::getFXColor(scheme.getBackgroundColor()));62}63cb.setCurrentItem((FXint)myActiveScheme);64}6566void setActive(int scheme) {67if (scheme < (int)mySchemes.size()) {68myActiveScheme = scheme;69}70}7172int getActive() const {73return myActiveScheme;74}7576T& getScheme() {77return mySchemes[myActiveScheme];78}7980const T& getScheme() const {81return mySchemes[myActiveScheme];82}8384const std::vector<T>& getSchemes() const {85return mySchemes;86}8788T* getSchemeByName(std::string name) {89for (typename std::vector<T>::iterator i = mySchemes.begin(); i != mySchemes.end(); ++i) {90if ((*i).getName() == name) {91return &(*i);92}93}94return 0;95}9697void setSchemeByName(std::string name) {98for (int i = 0; i < (int)mySchemes.size(); i++) {99if (mySchemes[i].getName() == name) {100myActiveScheme = i;101break;102}103}104}105106void save(OutputDevice& dev, const std::string& prefix = "") const {107for (typename std::vector<T>::const_iterator i = mySchemes.begin(); i != mySchemes.end(); ++i) {108i->save(dev, prefix);109}110}111112bool operator==(const GUIPropertySchemeStorage& c) const {113return myActiveScheme == c.myActiveScheme && mySchemes == c.mySchemes;114}115116117void addScheme(T scheme) {118mySchemes.push_back(scheme);119}120121int size() const {122return (int)mySchemes.size();123}124125126protected:127int myActiveScheme;128std::vector<T> mySchemes;129130};131132typedef GUIPropertySchemeStorage<GUIColorScheme> GUIColorer;133typedef GUIPropertySchemeStorage<GUIScaleScheme> GUIScaler;134135136