1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file GUIGlObject.h 11 /// @author Daniel Krajzewicz 12 /// @author Jakob Erdmann 13 /// @author Michael Behrisch 14 /// @author Laura Bieker 15 /// @date Oct 2002 16 /// @version $Id$ 17 /// 18 // Base class for all objects that may be displayed within the openGL-gui 19 /****************************************************************************/ 20 #ifndef GUIGlObject_h 21 #define GUIGlObject_h 22 23 24 // =========================================================================== 25 // included modules 26 // =========================================================================== 27 #include <config.h> 28 29 #include <string> 30 #include <set> 31 #include "GUIGlObjectTypes.h" 32 #include <utils/geom/Boundary.h> 33 #include <utils/common/StdDefs.h> 34 #include <utils/common/StringUtils.h> 35 #include <utils/common/StringBijection.h> 36 #include <utils/common/RGBColor.h> 37 38 39 // =========================================================================== 40 // definitions 41 // =========================================================================== 42 43 typedef unsigned int GUIGlID; 44 45 // =========================================================================== 46 // class declarations 47 // =========================================================================== 48 49 class GUIGlObjectStorage; 50 class GUIParameterTableWindow; 51 class GUIMainWindow; 52 class GUIGLObjectPopupMenu; 53 class GUISUMOAbstractView; 54 class GUIVisualizationSettings; 55 struct GUIVisualizationTextSettings; 56 #ifdef HAVE_OSG 57 namespace osg { 58 class Node; 59 } 60 #endif 61 62 // =========================================================================== 63 // class definitions 64 // =========================================================================== 65 66 class GUIGlObject { 67 public: 68 /// @brief associates object types with strings 69 static StringBijection<GUIGlObjectType> TypeNames; 70 static const GUIGlID INVALID_ID; 71 72 /** @brief Constructor 73 * 74 * This is the standard constructor that assures that the object is known 75 * and its id is unique. Use it always :-) 76 * 77 * @param[in] type The GUIGlObjectType type 78 * @param[in] microsimID unique ID 79 * @see GUIGlObjectStorage 80 */ 81 GUIGlObject(GUIGlObjectType type, const std::string& microsimID); 82 83 /// @brief Destructor 84 virtual ~GUIGlObject(); 85 86 /// @name Atomar getter methods 87 /// @{ 88 /// @brief Returns the full name appearing in the tool tip 89 /// @return This object's typed id 90 const std::string& getFullName() const; 91 92 /// @brief Returns the name of the parent object (if any) 93 /// @return This object's parent id 94 virtual std::string getParentName() const; 95 96 /// @brief Returns the numerical id of the object 97 /// @return This object's gl-id 98 GUIGlID getGlID() const; 99 /// @} 100 101 /// @name interfaces to be implemented by derived classes 102 /// @{ 103 /** @brief Returns an own popup-menu 104 * 105 * @param[in] app The application needed to build the popup-menu 106 * @param[in] parent The parent window needed to build the popup-menu 107 * @return The built popup-menu 108 */ 109 virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0; 110 111 /** @brief Returns an own parameter window 112 * 113 * @param[in] app The application needed to build the parameter window 114 * @param[in] parent The parent window needed to build the parameter window 115 * @return The built parameter window 116 */ 117 virtual GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0; 118 119 /** @brief Returns an own type parameter window (optional) 120 * 121 * @param[in] app The application needed to build the parameter window 122 * @param[in] parent The parent window needed to build the parameter window 123 * @return The built parameter window 124 */ 125 virtual GUIParameterTableWindow* getTypeParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent); 126 127 /// @brief Returns the id of the object as known to microsim 128 virtual const std::string& getMicrosimID() const; 129 130 /// @brief Returns the name of the object (default "") 131 virtual const std::string getOptionalName() const; 132 133 /// @brief Changes the microsimID of the object 134 /// @note happens in NETEDIT 135 virtual void setMicrosimID(const std::string& newID); 136 137 /// @brief Returns the type of the object as coded in GUIGlObjectType 138 /// @see GUIGlObjectType 139 GUIGlObjectType getType() const; 140 141 //// @brief Returns the boundary to which the view shall be centered in order to show the object 142 virtual Boundary getCenteringBoundary() const = 0; 143 144 /// @brief Draws the object 145 /// @param[in] s The settings for the current view (may influence drawing) 146 virtual void drawGL(const GUIVisualizationSettings& s) const = 0; 147 getColorValue(const GUIVisualizationSettings &,int)148 virtual double getColorValue(const GUIVisualizationSettings& /*s*/, int /*activeScheme*/) const { 149 return 0; 150 } 151 /// @} 152 153 /** @brief Draws additional, user-triggered visualisations 154 * @param[in] parent The view 155 * @param[in] s The settings for the current view (may influence drawing) 156 */ 157 virtual void drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const; 158 159 #ifdef HAVE_OSG 160 /// @brief get OSG Node 161 osg::Node* getNode() const; 162 163 /// @brief set OSG Node 164 void setNode(osg::Node* node); 165 #endif 166 167 /// @name Parameter table window I/O 168 /// @{ 169 /// @brief Lets this object know a parameter window showing the object's values was opened 170 /// @param[in] w The opened parameter window 171 void addParameterTable(GUIParameterTableWindow* w); 172 173 /// @brief Lets this object know a parameter window showing the object's values was closed 174 /// @param[in] w The closed parameter window 175 void removeParameterTable(GUIParameterTableWindow* w); 176 /// @} 177 178 /// @brief draw name of item 179 void drawName(const Position& pos, const double scale, const GUIVisualizationTextSettings& settings, const double angle = 0) const; 180 181 protected: 182 /// @name helper methods for building popup-menus 183 /// @{ 184 /** @brief Builds the header 185 * @param[in, filled] ret The popup menu to add the entry to 186 * @param[in] addSeparator Whether a separator shall be added, too 187 */ 188 void buildPopupHeader(GUIGLObjectPopupMenu* ret, GUIMainWindow& app, bool addSeparator = true); 189 190 /** @brief Builds an entry which allows to center to the object 191 * @param[in, filled] ret The popup menu to add the entry to 192 * @param[in] addSeparator Whether a separator shall be added, too 193 */ 194 void buildCenterPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true); 195 196 /** @brief Builds entries which allow to copy the name / typed name into the clipboard 197 * @param[in, filled] ret The popup menu to add the entry to 198 * @param[in] addSeparator Whether a separator shall be added, too 199 */ 200 void buildNameCopyPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true); 201 202 /** @brief Builds an entry which allows to (de)select the object 203 * @param[in, filled] ret The popup menu to add the entry to 204 * @param[in] addSeparator Whether a separator shall be added, too 205 */ 206 void buildSelectionPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true); 207 208 /** @brief Builds an entry which allows to open the parameter window 209 * @param[in, filled] ret The popup menu to add the entry to 210 * @param[in] addSeparator Whether a separator shall be added, too 211 */ 212 void buildShowParamsPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true); 213 214 /** @brief Builds an entry which allows to open the type parameter window 215 * @param[in, filled] ret The popup menu to add the entry to 216 * @param[in] addSeparator Whether a separator shall be added, too 217 */ 218 void buildShowTypeParamsPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true); 219 220 /** @brief Builds an entry which allows to copy the cursor position 221 * if geo projection is used, also builds an entry for copying the geo-position 222 * @param[in, filled] ret The popup menu to add the entry to 223 * @param[in] addSeparator Whether a separator shall be added, too 224 */ 225 void buildPositionCopyEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true); 226 227 /** @brief Builds an entry which allows to open the manipulator window 228 * @param[in, filled] ret The popup menu to add the entry to 229 * @param[in] addSeparator Whether a separator shall be added, too 230 */ 231 void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true); 232 /// @} 233 234 protected: 235 /// @brief build basic shape popup options. Used to unify pop-ups menu in netedit and SUMO-GUI 236 void buildShapePopupOptions(GUIMainWindow& app, GUIGLObjectPopupMenu* ret, const std::string& type); 237 238 /// @brief build basic additional popup options. Used to unify pop-ups menu in netedit and SUMO-GUI 239 void buildAdditionalsPopupOptions(GUIMainWindow& app, GUIGLObjectPopupMenu* ret, const std::string& type); 240 241 private: 242 /// @brief The numerical id of the object 243 GUIGlID myGlID; 244 245 /// @brief The type of the object 246 const GUIGlObjectType myGLObjectType; 247 248 /// @brief ID of GL object 249 std::string myMicrosimID; 250 251 /// @brief full name of GL Object 252 std::string myFullName; 253 254 /// @brief Parameter table windows which refer to this object 255 std::set<GUIParameterTableWindow*> myParamWindows; 256 257 /// @brief create full name 258 std::string createFullName() const; 259 260 #ifdef HAVE_OSG 261 /// @brief OSG Node of this GL object 262 osg::Node* myOSGNode; 263 #endif 264 265 /// @brief LinkStates (Currently unused) 266 // static StringBijection<SumoXMLLinkStateValue> LinkStates; 267 268 /// @brief vector for TypeNames Initializer 269 static StringBijection<GUIGlObjectType>::Entry GUIGlObjectTypeNamesInitializer[]; 270 271 private: 272 /// @brief Invalidated copy constructor. 273 GUIGlObject(const GUIGlObject&) = delete; 274 275 /// @brief Invalidated assignment operator. 276 GUIGlObject& operator=(const GUIGlObject&) = delete; 277 }; 278 #endif 279 280 /****************************************************************************/ 281 282