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 GUIViewObjectsHandler.h 15 : /// @author Pablo Alvarez Lopez 16 : /// @date Jun 22 17 : /// 18 : // class used for handle objects over view 19 : /****************************************************************************/ 20 : #pragma once 21 : #include <config.h> 22 : 23 : #include <vector> 24 : #include <utils/gui/globjects/GUIGlObject.h> 25 : #include <utils/gui/settings/GUIVisualizationSettings.h> 26 : 27 : // =========================================================================== 28 : // class declaration 29 : // =========================================================================== 30 : 31 : class GNEEdge; 32 : class GNELane; 33 : class GNERoute; 34 : 35 : // =========================================================================== 36 : // class definitions 37 : // =========================================================================== 38 : 39 : class GUIViewObjectsHandler { 40 : 41 : public: 42 : /// @brief object container 43 0 : struct ObjectContainer { 44 : 45 : /// @brief parameter constructor 46 0 : ObjectContainer(const GUIGlObject* object_) : 47 0 : object(object_) {} 48 : 49 : /// @brief object 50 : const GUIGlObject* object = nullptr; 51 : 52 : /// @brief vector with geometry points 53 : std::vector<int> geometryPoints; 54 : 55 : /// @brief position over shape 56 : Position posOverShape = Position::INVALID; 57 : 58 : /// @brief offset of position over shape 59 : double offset = 0; 60 : }; 61 : 62 : /// @brief typedef 63 : typedef std::map<double, std::vector<ObjectContainer> > GLObjectsSortedContainer; 64 : 65 : /// @brief constructor 66 : GUIViewObjectsHandler(); 67 : 68 : /// @brief clear selected elements 69 : void clearSelectedElements(); 70 : 71 : /// @brief get selection position (usually the mouse position) 72 : const Position& getSelectionPosition() const; 73 : 74 : /// @brief get selection boundary (usually the mouse position) 75 : const Boundary& getSelectionBoundary() const; 76 : 77 : /// @brief set selection position (usually the mouse position) 78 : void setSelectionPosition(const Position& pos); 79 : 80 : /// @brief set selection boundary (usually the mouse position) 81 : void setSelectionBoundary(const Boundary& boundary); 82 : 83 : /// @brief check if element was already selected 84 : bool isElementSelected(const GUIGlObject* GLObject) const; 85 : 86 : /// @brief check boundary parent element 87 : bool checkBoundaryParentElement(const GUIGlObject* GLObject, const GUIGlObject* parent); 88 : 89 : /// @brief check if mouse is within elements geometry (for circles) 90 : bool checkCircleElement(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject, 91 : const Position& center, const double radius, const Boundary& circleBoundary); 92 : 93 : /// @brief check if mouse is within geometry point 94 : bool checkGeometryPoint(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject, 95 : const PositionVector& shape, const int index, const double radius); 96 : 97 : /// @brief check if mouse is within geometry point 98 : bool checkPositionOverShape(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject, 99 : const PositionVector& shape, const double distance); 100 : 101 : /// @brief check (closed) shape element 102 : bool checkShapeElement(const GUIGlObject* GLObject, const PositionVector& shape, 103 : const Boundary& shapeBoundary); 104 : 105 : /// @brief add element into list of elements under cursor 106 : bool addElementUnderCursor(const GUIGlObject* GLObject, const bool checkDuplicated, const bool fullBoundary); 107 : 108 : /// @brief add geometryPoint into list of elements under cursor 109 : bool addGeometryPointUnderCursor(const GUIGlObject* GLObject, const int newIndex); 110 : 111 : /// @brief add position over shape 112 : bool addPositionOverShape(const GUIGlObject* GLObject, const Position& pos, const double offset); 113 : 114 : /// @brief get all elements under cursor sorted by layer 115 : const GLObjectsSortedContainer& getSelectedObjects() const; 116 : 117 : /// @brief get geometry points for the given glObject 118 : const std::vector<int>& getGeometryPoints(const GUIGlObject* GLObject) const; 119 : 120 : /// @brief get position over shape 121 : const Position& getPositionOverShape(const GUIGlObject* GLObject) const; 122 : 123 : /// @brief move front element in elements under cursor (currently used only in netedit) 124 : void updateFrontElement(const GUIGlObject* GLObject); 125 : 126 : /// @brief isolate edge geometry points (used for moving) 127 : void isolateEdgeGeometryPoints(); 128 : 129 : /// @brief recompute boundaries 130 : GUIGlObjectType recomputeBoundaries = GLO_NETWORK; 131 : 132 : /// @brief marked edge (used in create edge mode, for splitting) 133 : const GNEEdge* markedEdge = nullptr; 134 : 135 : /// @brief marked lane (used in create edge mode, for splitting) 136 : const GNELane* markedLane = nullptr; 137 : 138 : /// @brief marked TAZ (used in create TAZRel mode) 139 : const GUIGlObject* markedTAZ = nullptr; 140 : 141 : /// @brief marked route (used in create vehicle mode) 142 : const GNERoute* markedRoute = nullptr; 143 : 144 : /// @brief marked first geometry point (used for moving/delete geometry points) 145 : const GUIGlObject* markedFirstGeometryPoint = nullptr; 146 : 147 : /// @brief marked first geometry point (used for moving/delete geometry points) 148 : const GUIGlObject* markedSecondGeometryPoint = nullptr; 149 : 150 : protected: 151 : /// @brief selected element sorted by layer 152 : GLObjectsSortedContainer mySortedSelectedObjects; 153 : 154 : /// @brief map with selected elements and if was selected with full boundary (used only to avoid double seletions) 155 : std::map<const GUIGlObject*, bool> mySelectedObjects; 156 : 157 : /// @brief selection boundary 158 : Boundary mySelectionBoundary; 159 : 160 : /// @brief selection boundary (shape) 161 : PositionVector mySelectionBoundaryShape; 162 : 163 : /// @brief position 164 : Position mySelectionPosition; 165 : 166 : /// @brief empty geometry points 167 : std::vector<int> myEmptyGeometryPoints; 168 : 169 : private: 170 : /// @brief set copy constructor private 171 : GUIViewObjectsHandler(const GUIViewObjectsHandler&) = default; 172 : 173 : /// @brief set assignment operator private 174 : GUIViewObjectsHandler& operator=(const GUIViewObjectsHandler&) = default; 175 : };