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 % 4 0
Test Date: 2025-12-06 15:35:27 Functions: - 0 0

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

Generated by: LCOV version 2.0-1