Path: blob/main/src/utils/gui/globjects/GUIGlObject_AbstractAdd.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 GUIGlObject_AbstractAdd.cpp14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date 200418///19// Base class for additional objects (detectors etc.)20/****************************************************************************/21#include <config.h>2223#include "GUIGlObject_AbstractAdd.h"24#include <cassert>25#include <iostream>26#include <algorithm>27#include <utils/gui/div/GLHelper.h>282930// ===========================================================================31// static member definitions32// ===========================================================================3334std::map<std::string, GUIGlObject_AbstractAdd*> GUIGlObject_AbstractAdd::myObjects;35std::vector<GUIGlObject_AbstractAdd*> GUIGlObject_AbstractAdd::myObjectList;3637// ===========================================================================38// method definitions39// ===========================================================================4041GUIGlObject_AbstractAdd::GUIGlObject_AbstractAdd(GUIGlObjectType type, const std::string& id, FXIcon* icon) :42GUIGlObject(type, id, icon) {43myObjects[getFullName()] = this;44myObjectList.push_back(this);45}464748GUIGlObject_AbstractAdd::~GUIGlObject_AbstractAdd() {}495051void52GUIGlObject_AbstractAdd::clearDictionary() {53std::map<std::string, GUIGlObject_AbstractAdd*>::iterator i;54for (i = myObjects.begin(); i != myObjects.end(); i++) {55//!!! delete (*i).second;56}57myObjects.clear();58myObjectList.clear();59}606162GUIGlObject_AbstractAdd*63GUIGlObject_AbstractAdd::get(const std::string& name) {64auto i = myObjects.find(name);65if (i == myObjects.end()) {66return nullptr;67} else {68return i->second;69}70}717273void74GUIGlObject_AbstractAdd::remove(GUIGlObject_AbstractAdd* o) {75myObjects.erase(o->getFullName());76myObjectList.erase(std::remove(myObjectList.begin(), myObjectList.end(), o), myObjectList.end());77}787980const std::vector<GUIGlObject_AbstractAdd*>&81GUIGlObject_AbstractAdd::getObjectList() {82return myObjectList;83}848586std::vector<GUIGlID>87GUIGlObject_AbstractAdd::getIDList(GUIGlObjectType typeFilter) {88std::vector<GUIGlID> ret;89if (typeFilter == GLO_NETWORK) {90return ret;91} else if (typeFilter == GLO_NETWORKELEMENT) {92// obtain all network elements93for (auto i : myObjectList) {94if ((i->getType() > GLO_NETWORKELEMENT) && (i->getType() < GLO_ADDITIONALELEMENT)) {95ret.push_back(i->getGlID());96}97}98} else if (typeFilter == GLO_ADDITIONALELEMENT) {99// obtain all additionals100for (auto i : myObjectList) {101if ((i->getType() > GLO_ADDITIONALELEMENT) && (i->getType() < GLO_SHAPE)) {102ret.push_back(i->getGlID());103}104}105} else if (typeFilter == GLO_SHAPE) {106// obtain all Shapes107for (auto i : myObjectList) {108if ((i->getType() > GLO_SHAPE) && (i->getType() < GLO_ROUTEELEMENT)) {109ret.push_back(i->getGlID());110}111}112} else if (typeFilter == GLO_ROUTEELEMENT) {113// obtain all Shapes114for (auto i : myObjectList) {115if ((i->getType() > GLO_ROUTEELEMENT) && (i->getType() < GLO_MAX)) {116ret.push_back(i->getGlID());117}118}119} else {120for (auto i : myObjectList) {121if ((i->getType() & typeFilter) != 0) {122ret.push_back(i->getGlID());123}124}125}126return ret;127}128129130/****************************************************************************/131132133