Path: blob/main/src/utils/gui/globjects/GUIGlObjectStorage.cpp
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 GUIGlObjectStorage.cpp14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Sept 200218///19// A storage for displayed objects via their numerical id20/****************************************************************************/21#include <config.h>2223#include <cassert>24#include <utils/foxtools/fxheader.h>25#include "GUIGlObject.h"26#include "GUIGlObjectStorage.h"272829// ===========================================================================30// static variables (instances in this case)31// ===========================================================================32GUIGlObjectStorage GUIGlObjectStorage::gIDStorage;333435// ===========================================================================36// method definitions37// ===========================================================================38GUIGlObjectStorage::GUIGlObjectStorage() :39myNextID(1),40myLock(true) {41myObjects.push_back(nullptr);42}434445GUIGlObjectStorage::~GUIGlObjectStorage() {}464748GUIGlID49GUIGlObjectStorage::registerObject(GUIGlObject* object) {50FXMutexLock locker(myLock);51const GUIGlID id = myNextID;52if (id == myObjects.size()) {53myObjects.push_back(object);54} else {55myObjects[id] = object;56}57while (myNextID < myObjects.size() && myObjects[myNextID] != nullptr) {58myNextID++;59}60return id;61}626364void65GUIGlObjectStorage::changeName(GUIGlObject* object, const std::string& fullName) {66FXMutexLock locker(myLock);67myFullNameMap.erase(object->getFullName());68myFullNameMap[fullName] = object;69}707172GUIGlObject*73GUIGlObjectStorage::getObjectBlocking(GUIGlID id) const {74FXMutexLock locker(myLock);75if (id < myObjects.size() && myObjects[id] != nullptr) {76GUIGlObject* const o = myObjects[id];77o->setBlocked();78return o;79}80return nullptr;81}828384GUIGlObject*85GUIGlObjectStorage::getObjectBlocking(const std::string& fullName) const {86FXMutexLock locker(myLock);87auto findIt = myFullNameMap.find(fullName);88if (findIt != myFullNameMap.end()) {89GUIGlObject* const o = findIt->second;90o->setBlocked();91return o;92}93return nullptr;94}959697bool98GUIGlObjectStorage::remove(GUIGlID id) {99FXMutexLock locker(myLock);100assert(id < myObjects.size() && myObjects[id] != nullptr);101myFullNameMap.erase(myObjects[id]->getFullName());102const bool wasBlocked = myObjects[id]->isBlocked();103myObjects[id] = nullptr;104if (id < myNextID) {105myNextID = id;106}107return !wasBlocked;108}109110111void112GUIGlObjectStorage::clear() {113FXMutexLock locker(myLock);114myObjects.clear();115myObjects.push_back(nullptr);116myFullNameMap.clear();117myNextID = 1;118}119120121void122GUIGlObjectStorage::unblockObject(GUIGlID id) {123FXMutexLock locker(myLock);124if (id < myObjects.size() && myObjects[id] != nullptr) {125myObjects[id]->setBlocked(false);126}127}128129130const std::vector<GUIGlObject*>&131GUIGlObjectStorage::getAllGLObjects() const {132return myObjects;133}134135/****************************************************************************/136137138