Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-2024 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 GUICompleteSchemeStorage.cpp 15 : /// @author Daniel Krajzewicz 16 : /// @author Jakob Erdmann 17 : /// @author Michael Behrisch 18 : /// @author Laura Bieker 19 : /// @date 2006-01-09 20 : /// 21 : // Storage for available visualization settings 22 : /****************************************************************************/ 23 : #include <config.h> 24 : 25 : #include "GUICompleteSchemeStorage.h" 26 : #include <utils/common/ToString.h> 27 : #include <utils/common/StringUtils.h> 28 : #include <utils/common/RGBColor.h> 29 : #include <utils/foxtools/MFXUtils.h> 30 : #include <utils/gui/settings/GUISettingsHandler.h> 31 : #include <utils/iodevices/OutputDevice_String.h> 32 : 33 : 34 : // =========================================================================== 35 : // static variable definitions 36 : // =========================================================================== 37 : GUICompleteSchemeStorage gSchemeStorage; 38 : 39 : 40 : // =========================================================================== 41 : // method definitions 42 : // =========================================================================== 43 7993 : GUICompleteSchemeStorage::GUICompleteSchemeStorage() { } 44 : 45 : 46 7993 : GUICompleteSchemeStorage::~GUICompleteSchemeStorage() { 47 45205 : for (auto item : mySettings) { 48 37212 : delete item.second; 49 : } 50 15986 : } 51 : 52 : 53 : 54 : void 55 37212 : GUICompleteSchemeStorage::add(const GUIVisualizationSettings& scheme) { 56 : std::string name = scheme.name; 57 37212 : if (std::find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name) == mySortedSchemeNames.end()) { 58 37212 : mySortedSchemeNames.push_back(name); 59 : } 60 37212 : GUIVisualizationSettings* s = new GUIVisualizationSettings(name); 61 37212 : s->copy(scheme); 62 37212 : mySettings[name] = s; 63 37212 : } 64 : 65 : 66 : GUIVisualizationSettings& 67 44 : GUICompleteSchemeStorage::get(const std::string& name) { 68 44 : return *mySettings.find(name)->second; 69 : } 70 : 71 : 72 : GUIVisualizationSettings& 73 7003 : GUICompleteSchemeStorage::getDefault() { 74 7003 : return *mySettings.find(myDefaultSettingName)->second; 75 : } 76 : 77 : 78 : bool 79 7071 : GUICompleteSchemeStorage::contains(const std::string& name) const { 80 7071 : return mySettings.find(name) != mySettings.end(); 81 : } 82 : 83 : 84 : void 85 0 : GUICompleteSchemeStorage::remove(const std::string name) { 86 0 : if (!contains(name)) { 87 : return; 88 : } 89 0 : mySortedSchemeNames.erase(find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name)); 90 0 : delete mySettings.find(name)->second; 91 : mySettings.erase(name); 92 : } 93 : 94 : 95 : void 96 6989 : GUICompleteSchemeStorage::setDefault(const std::string& name) { 97 6989 : if (!contains(name)) { 98 : return; 99 : } 100 6989 : myDefaultSettingName = name; 101 : } 102 : 103 : 104 : const std::vector<std::string>& 105 7003 : GUICompleteSchemeStorage::getNames() const { 106 7003 : return mySortedSchemeNames; 107 : } 108 : 109 : 110 : int 111 0 : GUICompleteSchemeStorage::getNumInitialSettings() const { 112 0 : return myNumInitialSettings; 113 : } 114 : 115 : 116 : void 117 7436 : GUICompleteSchemeStorage::init(FXApp* app, bool netedit) { 118 : { 119 7436 : GUIVisualizationSettings vs("standard", netedit); 120 7436 : vs.laneShowBorders = true; 121 7436 : gSchemeStorage.add(vs); 122 7436 : } 123 : { 124 7436 : GUIVisualizationSettings vs("faster standard", netedit); 125 7436 : vs.laneShowBorders = false; 126 7436 : vs.showLinkDecals = false; 127 7436 : vs.showRails = false; 128 : vs.showRails = false; 129 7436 : vs.showSublanes = false; 130 7436 : gSchemeStorage.add(vs); 131 7436 : } 132 : { 133 7436 : GUIVisualizationSettings vs("real world", netedit); 134 7436 : vs.vehicleQuality = 2; 135 7436 : vs.backgroundColor = RGBColor(51, 128, 51, 255); 136 7436 : vs.laneShowBorders = true; 137 7436 : vs.hideConnectors = true; 138 7436 : vs.vehicleSize.minSize = 0; 139 7436 : vs.personQuality = 2; 140 7436 : vs.containerQuality = 2; 141 7436 : vs.showSublanes = false; 142 7436 : gSchemeStorage.add(vs); 143 7436 : } 144 : { 145 7436 : GUIVisualizationSettings vs("rail", netedit); 146 7436 : vs.vehicleQuality = 2; 147 7436 : vs.showLaneDirection = true; 148 7436 : vs.spreadSuperposed = true; 149 7436 : vs.junctionSize.constantSize = true; 150 7436 : vs.junctionColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_TYPE); 151 7436 : gSchemeStorage.add(vs); 152 7436 : } 153 : 154 7436 : if (!netedit) { 155 14872 : GUIVisualizationSettings vs("selection", netedit); 156 14872 : vs.vehicleColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION); 157 14872 : vs.edgeColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION); 158 14872 : vs.laneColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION); 159 14872 : vs.junctionColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION); 160 14872 : vs.personColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION); 161 14872 : vs.containerColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION); 162 14872 : vs.poiColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION); 163 7436 : vs.polyColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION); 164 7436 : gSchemeStorage.add(vs); 165 7436 : } 166 7436 : myNumInitialSettings = (int) mySortedSchemeNames.size(); 167 : // add saved settings 168 7436 : int noSaved = app->reg().readIntEntry("VisualizationSettings", "settingNo", 0); 169 7436 : for (int i = 0; i < noSaved; ++i) { 170 0 : std::string name = "visset#" + toString(i); 171 0 : std::string setting = app->reg().readStringEntry("VisualizationSettings", name.c_str(), ""); 172 0 : if (setting != "") { 173 0 : GUIVisualizationSettings vs(setting, netedit); 174 0 : app->reg().readStringEntry("VisualizationSettings", name.c_str(), ""); 175 : 176 : // add saved xml setting 177 0 : int xmlSize = app->reg().readIntEntry(name.c_str(), "xmlSize", 0); 178 0 : std::string content = ""; 179 0 : int index = 0; 180 0 : while (xmlSize > 0) { 181 0 : std::string part = app->reg().readStringEntry(name.c_str(), ("xml" + toString(index)).c_str(), ""); 182 0 : if (part == "") { 183 : break; 184 : } 185 : content += part; 186 0 : xmlSize -= (int) part.size(); 187 0 : index++; 188 : } 189 0 : if (content != "" && xmlSize == 0) { 190 : try { 191 0 : GUISettingsHandler handler(content, false, netedit); 192 0 : handler.addSettings(); 193 0 : } catch (ProcessError&) { } 194 : } 195 0 : } 196 : } 197 7436 : myDefaultSettingName = mySortedSchemeNames[0]; 198 : myLookFrom.set(0, 0, 0); 199 7436 : } 200 : 201 : 202 : void 203 0 : GUICompleteSchemeStorage::writeSettings(FXApp* app) { 204 0 : const std::vector<std::string>& names = getNames(); 205 0 : app->reg().writeIntEntry("VisualizationSettings", "settingNo", (FXint) names.size() - myNumInitialSettings); 206 0 : int gidx = 0; 207 0 : for (std::vector<std::string>::const_iterator it = names.begin() + myNumInitialSettings; it != names.end(); ++it, ++gidx) { 208 0 : const GUIVisualizationSettings* item = mySettings.find(*it)->second; 209 0 : std::string sname = "visset#" + toString(gidx); 210 : 211 0 : app->reg().writeStringEntry("VisualizationSettings", sname.c_str(), item->name.c_str()); 212 0 : OutputDevice_String dev; 213 0 : item->save(dev); 214 0 : std::string content = dev.getString(); 215 0 : app->reg().writeIntEntry(sname.c_str(), "xmlSize", (FXint)(content.size())); 216 : const unsigned maxSize = 1500; // this is a fox limitation for registry entries 217 0 : for (int i = 0; i < (int)content.size(); i += maxSize) { 218 0 : const std::string b = content.substr(i, maxSize); 219 0 : app->reg().writeStringEntry(sname.c_str(), ("xml" + toString(i / maxSize)).c_str(), b.c_str()); 220 : } 221 0 : } 222 0 : } 223 : 224 : 225 : void 226 14425 : GUICompleteSchemeStorage::saveViewport(const double x, const double y, const double z, const double rot) { 227 : myLookFrom.set(x, y, z); 228 14425 : myRotation = rot; 229 14425 : } 230 : 231 : void 232 6989 : GUICompleteSchemeStorage::saveDecals(const std::vector<GUISUMOAbstractView::Decal>& decals) { 233 6989 : myDecals = decals; 234 6996 : for (auto& d : myDecals) { 235 7 : d.initialised = false; 236 : } 237 6989 : } 238 : 239 : void 240 7003 : GUICompleteSchemeStorage::setViewport(GUISUMOAbstractView* view) { 241 7003 : if (myLookFrom.z() > 0) { 242 : // look straight down 243 0 : view->setViewportFromToRot(myLookFrom, Position(myLookFrom.x(), myLookFrom.y(), 0), myRotation); 244 : } else { 245 7003 : view->recenterView(); 246 : } 247 7003 : } 248 : 249 : 250 : /****************************************************************************/