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 GUISettingsHandler.h 15 : /// @author Michael Behrisch 16 : /// @author Daniel Krajzewicz 17 : /// @author Jakob Erdmann 18 : /// @date Fri, 24. Apr 2009 19 : /// 20 : // The handler for parsing gui settings from xml. 21 : /****************************************************************************/ 22 : #pragma once 23 : #include <config.h> 24 : 25 : #include <utils/xml/SUMOSAXHandler.h> 26 : #include <utils/distribution/RandomDistributor.h> 27 : 28 : 29 : // =========================================================================== 30 : // class declarations 31 : // =========================================================================== 32 : class GUISUMOAbstractView; 33 : class Position; 34 : 35 : 36 : // =========================================================================== 37 : // class definitions 38 : // =========================================================================== 39 : /** @class GUISettingsHandler 40 : * @brief An XML-handler for visualisation schemes 41 : */ 42 : class GUISettingsHandler : public SUMOSAXHandler { 43 : public: 44 : /** @brief Constructor 45 : * @param[in] file the file to parse 46 : */ 47 : GUISettingsHandler(const std::string& content, bool isFile = true, bool netedit = false); 48 : 49 : 50 : /// @brief Destructor 51 : ~GUISettingsHandler(); 52 : 53 : 54 : 55 : /// @name inherited from GenericSAXHandler 56 : //@{ 57 : 58 : /** @brief Called on the opening of a tag 59 : * @param[in] element ID of the currently opened element 60 : * @param[in] attrs Attributes within the currently opened element 61 : * @exception ProcessError If something fails 62 : * @see GenericSAXHandler::myStartElement 63 : */ 64 : void myStartElement(int element, const SUMOSAXAttributes& attrs); 65 : 66 : /** @brief Called when a closing tag occurs 67 : * 68 : * @param[in] element ID of the currently opened element 69 : * @exception ProcessError If something fails 70 : * @see GenericSAXHandler::myEndElement 71 : */ 72 : void myEndElement(int element); 73 : //@} 74 : 75 : 76 : 77 : /** @brief Adds the parsed settings to the global list of settings 78 : * @return the names of the parsed settings 79 : */ 80 : const std::vector<std::string>& addSettings(GUISUMOAbstractView* view = 0) const; 81 : 82 : 83 : /** @brief Sets the viewport which has been parsed 84 : * @param[in] parent the view for which the viewport has to be set 85 : */ 86 : void applyViewport(GUISUMOAbstractView* view) const; 87 : 88 : 89 : /** @brief Makes a snapshot if it has been parsed 90 : * @param[in] parent the view which needs to be shot 91 : * @todo Please describe why the snapshots are only set if no other existed before (see code) 92 : */ 93 : void setSnapshots(GUISUMOAbstractView* view) const; 94 : 95 : 96 : /** @brief Returns whether any decals have been parsed 97 : * @return whether decals have been parsed 98 : */ 99 : bool hasDecals() const; 100 : 101 : 102 : /** @brief Returns the parsed decals 103 : * @return the parsed decals 104 : */ 105 : const std::vector<GUISUMOAbstractView::Decal>& getDecals() const; 106 : 107 : 108 : /** @brief Returns the parsed delay 109 : * @return the parsed delay 110 : */ 111 : double getDelay() const; 112 : 113 : 114 : /** @brief Returns the parsed breakpoints 115 : * @return the parsed breakpoints 116 : */ 117 : const std::vector<SUMOTime>& getBreakpoints() const { 118 : return myBreakpoints; 119 : } 120 : 121 : 122 : /// @brief loads breakpoints from the specified file 123 : static std::vector<SUMOTime> loadBreakpoints(const std::string& file); 124 : 125 : 126 : /** @brief Returns the parsed view type 127 : * @return the parsed view type 128 : */ 129 : const std::string& getViewType() const { 130 : return myViewType; 131 : } 132 : 133 : RandomDistributor<std::string> getEventDistribution(const std::string& id); 134 : double getJamSoundTime() { 135 38 : return myJamSoundTime; 136 : } 137 : 138 : const std::string& getSettingName() const { 139 : return mySettings.name; 140 : } 141 : 142 : private: 143 : /// @brief The settings to fill 144 : GUIVisualizationSettings mySettings; 145 : 146 : /// @brief names of all loaded settings 147 : std::vector<std::string> myLoadedSettingNames; 148 : 149 : /// @brief The view type (osg, opengl, default) loaded 150 : std::string myViewType; 151 : 152 : /// @brief The delay loaded 153 : double myDelay; 154 : 155 : /// @brief The viewport loaded, zoom is stored in z coordinate 156 : Position myLookFrom; 157 : 158 : /// @brief The point to look at, only needed for osg view 159 : Position myLookAt; 160 : 161 : /// @brief Whether the Z coordinate is set in 3D view 162 : bool myZCoordSet; 163 : 164 : /// @brief View rotation 165 : double myRotation; 166 : 167 : /// @brief Zoom level 168 : double myZoom; 169 : 170 : /// @brief mappig of time steps to filenames for potential snapshots 171 : std::map<SUMOTime, std::vector<std::string> > mySnapshots; 172 : 173 : /// @brief The decals list to fill 174 : std::vector<GUISUMOAbstractView::Decal> myDecals; 175 : 176 : /// @brief The last color scheme category (edges or vehicles) 177 : int myCurrentColorer; 178 : 179 : /// @brief The current color scheme 180 : GUIColorScheme* myCurrentScheme; 181 : 182 : /// @brief The current scaling scheme 183 : GUIScaleScheme* myCurrentScaleScheme; 184 : 185 : /// @brief The parsed breakpoints 186 : std::vector<SUMOTime> myBreakpoints; 187 : 188 : /// @brief The parsed event distributions 189 : std::map<std::string, RandomDistributor<std::string> > myEventDistributions; 190 : double myJamSoundTime; 191 : 192 : private: 193 : /// @brief parse color attribute 194 : RGBColor parseColor(const SUMOSAXAttributes& attrs, const std::string attribute, const RGBColor& defaultValue) const; 195 : 196 : /// @brief parse attributes for textSettings 197 : GUIVisualizationTextSettings parseTextSettings( 198 : const std::string& prefix, const SUMOSAXAttributes& attrs, 199 : GUIVisualizationTextSettings defaults); 200 : 201 : /// @brief parse attributes for sizeSettings 202 : GUIVisualizationSizeSettings parseSizeSettings( 203 : const std::string& prefix, const SUMOSAXAttributes& attrs, 204 : GUIVisualizationSizeSettings defaults); 205 : 206 : /// @brief parse attributes for rainbowSettings 207 : GUIVisualizationRainbowSettings parseRainbowSettings( 208 : const std::string& prefix, const SUMOSAXAttributes& attrs, 209 : GUIVisualizationRainbowSettings defaults); 210 : };