LCOV - code coverage report
Current view: top level - src/utils/gui/div - GUIViewObjectsHandler.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 0.0 % 3 0
Test Date: 2024-12-21 15:45:41 Functions: - 0 0

            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 <unordered_map>
      25              : #include <utils/gui/globjects/GUIGlObject.h>
      26              : #include <utils/gui/settings/GUIVisualizationSettings.h>
      27              : 
      28              : // ===========================================================================
      29              : // class declaration
      30              : // ===========================================================================
      31              : 
      32              : class GNEJunction;
      33              : class GNEEdge;
      34              : class GNELane;
      35              : class GNERoute;
      36              : class GNEPathElement;
      37              : class GNESegment;
      38              : 
      39              : // ===========================================================================
      40              : // class definitions
      41              : // ===========================================================================
      42              : 
      43              : class GUIViewObjectsHandler {
      44              : 
      45              : public:
      46              :     /// @brief object container
      47            0 :     struct ObjectContainer {
      48              : 
      49              :         /// @brief parameter constructor
      50            0 :         ObjectContainer(const GUIGlObject* object_) :
      51            0 :             object(object_) {}
      52              : 
      53              :         /// @brief object
      54              :         const GUIGlObject* object = nullptr;
      55              : 
      56              :         /// @brief vector with geometry points
      57              :         std::vector<int> geometryPoints;
      58              : 
      59              :         /// @brief position over shape
      60              :         Position posOverShape = Position::INVALID;
      61              : 
      62              :         /// @brief offset of position over shape
      63              :         double offset = 0;
      64              :     };
      65              : 
      66              :     /// @brief typedef for pack elements sorted by layer
      67              :     typedef std::map<double, std::vector<ObjectContainer> > GLObjectsSortedContainer;
      68              : 
      69              :     /// @brief constructor
      70              :     GUIViewObjectsHandler();
      71              : 
      72              :     /// @brief reset view objects handler
      73              :     void reset();
      74              : 
      75              :     /// @name position and boundary functions. used for defining the posion that will be check (usually the mouse position)
      76              :     /// @{
      77              :     /// @brief get selection position
      78              :     const Position& getSelectionPosition() const;
      79              : 
      80              :     /// @brief get selection boundary
      81              :     const Boundary& getSelectionBoundary() const;
      82              : 
      83              :     /// @brief set selection position
      84              :     void setSelectionPosition(const Position& pos);
      85              : 
      86              :     /// @brief set selection boundary
      87              :     void setSelectionBoundary(const Boundary& boundary);
      88              : 
      89              :     /// @}
      90              : 
      91              :     /// @name check functions. If the result is positive, the given GLObject will be added to elementUnderCursor
      92              :     /// @{
      93              :     /// @brief check boundary parent element
      94              :     bool checkBoundaryParentObject(const GUIGlObject* GLObject, const double layer, const GUIGlObject* parent);
      95              : 
      96              :     /// @brief check if mouse is within elements geometry (for circles)
      97              :     bool checkCircleObject(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
      98              :                            const Position& center, const double radius, const Boundary& circleBoundary,
      99              :                            const double layer);
     100              : 
     101              :     /// @brief check if mouse is within geometry point
     102              :     bool checkGeometryPoint(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
     103              :                             const PositionVector& shape, const int index, const double layer, const double radius);
     104              : 
     105              :     /// @brief check if mouse is within geometry point
     106              :     bool checkPositionOverShape(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
     107              :                                 const PositionVector& shape, const double layer, const double distance);
     108              : 
     109              :     /// @brief check (closed) shape element
     110              :     bool checkShapeObject(const GUIGlObject* GLObject, const PositionVector& shape, const Boundary& shapeBoundary,
     111              :                           const double layer, const GNESegment* segment);
     112              :     /// @}
     113              : 
     114              :     /// @name functions used for mark (select) elements
     115              :     /// @{
     116              :     /// @brief add element into list of elements under cursor
     117              :     bool selectObject(const GUIGlObject* GLObject, const double layer, const bool checkDuplicated,
     118              :                       const bool fullBoundary, const GNESegment* segment);
     119              : 
     120              :     /// @brief add geometryPoint into list of elements under cursor
     121              :     bool selectGeometryPoint(const GUIGlObject* GLObject, const int newIndex, const double layer);
     122              : 
     123              :     /// @brief select position over shape (for example, the position over a lane shape)
     124              :     bool selectPositionOverShape(const GUIGlObject* GLObject, const Position& pos, const double layer, const double offset);
     125              : 
     126              :     /// @brief check if element was already selected
     127              :     bool isObjectSelected(const GUIGlObject* GLObject) const;
     128              : 
     129              :     /// @brief check rectangle selection
     130              :     bool checkRectangleSelection(const GUIVisualizationSettings& s, const GUIGlObject* GLObject,
     131              :                                  const double layer, const GUIGlObject* parent);
     132              : 
     133              :     /// @brief get all elements under cursor sorted by layer
     134              :     const GLObjectsSortedContainer& getSelectedObjects() const;
     135              : 
     136              :     /// @brief get segment associated with the given GLObject (if exist)
     137              :     const GNESegment* getSelectedSegment(const GUIGlObject* GLObject) const;
     138              : 
     139              :     /// @brief get geometry points for the given glObject
     140              :     const std::vector<int>& getSelectedGeometryPoints(const GUIGlObject* GLObject) const;
     141              : 
     142              :     /// @brief get position over shape
     143              :     const Position& getSelectedPositionOverShape(const GUIGlObject* GLObject) const;
     144              : 
     145              :     /// @brief get number of selected objects
     146              :     int getNumberOfSelectedObjects() const;
     147              : 
     148              :     /// @}
     149              : 
     150              :     /// @name functions related with redrawing path elements
     151              :     /// @{
     152              :     /// @brief get redrawing objects
     153              :     const std::set<const GNEPathElement*>& getRedrawPathElements() const;
     154              : 
     155              :     /// @brief check if the given path element has to be redraw again
     156              :     bool isPathElementMarkForRedraw(const GNEPathElement* pathElement) const;
     157              : 
     158              :     /// @brief add path element to redrawing set
     159              :     void addToRedrawPathElements(const GNEPathElement* pathElement);
     160              : 
     161              :     /// @}
     162              : 
     163              :     /// @name functions related with merging junctions
     164              :     /// @{
     165              :     /// @brief get merging junctions
     166              :     const std::vector<const GNEJunction*>& getMergingJunctions() const;
     167              : 
     168              :     /// @brief add to merging junctions (used for marking junctions to merge)
     169              :     bool addMergingJunctions(const GNEJunction* junction);
     170              : 
     171              :     /// @}
     172              : 
     173              :     /// @brief move the given object to the front (currently used only in netedit)
     174              :     void updateFrontObject(const GUIGlObject* GLObject);
     175              : 
     176              :     /// @brief isolate edge geometry points (used for moving)
     177              :     void isolateEdgeGeometryPoints();
     178              : 
     179              :     /// @brief recompute boundaries
     180              :     GUIGlObjectType recomputeBoundaries = GLO_NETWORK;
     181              : 
     182              :     /// @brief marked edge (used in create edge mode, for splitting)
     183              :     const GNEEdge* markedEdge = nullptr;
     184              : 
     185              :     /// @brief marked lane (used in create edge mode, for splitting)
     186              :     const GNELane* markedLane = nullptr;
     187              : 
     188              :     /// @brief marked TAZ (used in create TAZRel mode)
     189              :     const GUIGlObject* markedTAZ = nullptr;
     190              : 
     191              :     /// @brief marked route (used in create vehicle mode)
     192              :     const GNERoute* markedRoute = nullptr;
     193              : 
     194              :     /// @brief marked first geometry point (used for moving/delete geometry points)
     195              :     const GUIGlObject* markedFirstGeometryPoint = nullptr;
     196              : 
     197              :     /// @brief marked first geometry point (used for moving/delete geometry points)
     198              :     const GUIGlObject* markedSecondGeometryPoint = nullptr;
     199              : 
     200              : protected:
     201              :     /// @brief selected element sorted by layer
     202              :     GLObjectsSortedContainer mySortedSelectedObjects;
     203              : 
     204              :     /// @brief map with selected elements and if was selected with full boundary (used only to avoid double selections)
     205              :     std::unordered_map<const GUIGlObject*, std::pair<bool, const GNESegment*> > mySelectedObjects;
     206              : 
     207              :     /// @brief number of selected objects
     208              :     int myNumberOfSelectedObjects = 0;
     209              : 
     210              :     /// @brief set with path elements marked for redrawing
     211              :     std::set<const GNEPathElement*> myRedrawPathElements;
     212              : 
     213              :     /// @brief selection boundary
     214              :     Boundary mySelectionBoundary;
     215              : 
     216              :     /// @brief selection boundary (shape)
     217              :     PositionVector mySelectionBoundaryShape;
     218              : 
     219              :     /// @brief position
     220              :     Position mySelectionPosition;
     221              : 
     222              :     /// @brief empty geometry points
     223              :     std::vector<int> myEmptyGeometryPoints;
     224              : 
     225              :     /// @brief merging junctions
     226              :     std::vector<const GNEJunction*> myMergingJunctions;
     227              : 
     228              : private:
     229              :     /// @brief set copy constructor private
     230              :     GUIViewObjectsHandler(const GUIViewObjectsHandler&) = default;
     231              : 
     232              :     /// @brief set assignment operator private
     233              :     GUIViewObjectsHandler& operator=(const GUIViewObjectsHandler&) = default;
     234              : };
        

Generated by: LCOV version 2.0-1