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: 2026-05-24 16:29:35 Functions: - 0 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2026 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 GUIVisualizationSettings& s, const GUIGlObject* GLObject,
     109              :                                    const double layer, const GUIGlObject* parent);
     110              : 
     111              :     /// @brief check if mouse is within elements geometry (for circles)
     112              :     bool checkCircleObject(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
     113              :                            const Position& center, const double radius, const double layer);
     114              : 
     115              :     /// @brief check if mouse is within geometry point
     116              :     bool checkGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
     117              :                             const PositionVector& shape, const int index, const double layer, const double radius);
     118              : 
     119              :     /// @brief check if mouse is within geometry point
     120              :     bool checkPositionOverShape(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
     121              :                                 const PositionVector& shape, const double layer, const double distance);
     122              : 
     123              :     /// @brief check (closed) shape element
     124              :     bool checkShapeObject(const GUIVisualizationSettings& s, const GUIGlObject* GLObject, const PositionVector& shape,
     125              :                           const Boundary& shapeBoundary, const double layer, const GNESegment* segment);
     126              :     /// @}
     127              : 
     128              :     /// @name functions used for mark (select) elements
     129              :     /// @{
     130              :     ///
     131              :     /// @brief add element into list of elements under cursor
     132              :     bool selectObject(const GUIVisualizationSettings& s, const GUIGlObject* GLObject, const double layer,
     133              :                       const bool checkDuplicated, const GNESegment* segment);
     134              : 
     135              :     /// @brief add geometryPoint into list of elements under cursor
     136              :     bool selectGeometryPoint(const GUIGlObject* GLObject, const int newIndex, const double layer);
     137              : 
     138              :     /// @brief select position over shape (for example, the position over a lane shape)
     139              :     bool selectPositionOverShape(const GUIGlObject* GLObject, const Position& pos, const double layer, const double offset);
     140              : 
     141              :     /// @brief check if element was already selected
     142              :     bool isObjectSelected(const GUIGlObject* GLObject) const;
     143              : 
     144              :     /// @brief check rectangle selection
     145              :     bool checkRectangleSelection(const GUIVisualizationSettings& s, const GUIGlObject* GLObject,
     146              :                                  const double layer, const GUIGlObject* parent);
     147              : 
     148              :     /// @brief get all elements under cursor sorted by layer
     149              :     const GLObjectsSortedContainer& getSelectedObjects() const;
     150              : 
     151              :     /// @brief get segment associated with the given GLObject (if exist)
     152              :     const GNESegment* getSelectedSegment(const GUIGlObject* GLObject) const;
     153              : 
     154              :     /// @brief get geometry points for the given glObject
     155              :     const std::vector<int>& getSelectedGeometryPoints(const GUIGlObject* GLObject) const;
     156              : 
     157              :     /// @brief get position over shape
     158              :     const Position& getSelectedPositionOverShape(const GUIGlObject* GLObject) const;
     159              : 
     160              :     /// @brief get number of selected objects
     161              :     int getNumberOfSelectedObjects() const;
     162              : 
     163              :     /// @brief reverse selected objects
     164              :     void reverseSelectedObjects();
     165              : 
     166              :     /// @}
     167              : 
     168              :     /// @name functions related with redrawing path elements
     169              :     /// @{
     170              :     /// @brief get redrawing objects
     171              :     const std::set<const GNEPathElement*>& getRedrawPathElements() const;
     172              : 
     173              :     /// @brief check if the given path element has to be redraw again
     174              :     bool isPathElementMarkForRedraw(const GNEPathElement* pathElement) const;
     175              : 
     176              :     /// @brief add path element to redrawing set
     177              :     void addToRedrawPathElements(const GNEPathElement* pathElement);
     178              : 
     179              :     /// @}
     180              : 
     181              :     /// @name functions related with merging junctions
     182              :     /// @{
     183              :     /// @brief get merging junctions
     184              :     const std::vector<const GNEJunction*>& getMergingJunctions() const;
     185              : 
     186              :     /// @brief add to merging junctions (used for marking junctions to merge)
     187              :     bool addMergingJunctions(const GNEJunction* junction);
     188              : 
     189              :     /// @}
     190              : 
     191              :     /// @brief move the given object to the front (currently used only in netedit)
     192              :     void updateFrontObject(const GUIGlObject* GLObject);
     193              : 
     194              :     /// @brief isolate edge geometry points (used for moving)
     195              :     void isolateEdgeGeometryPoints();
     196              : 
     197              :     /// @brief recompute boundaries
     198              :     GUIGlObjectType recomputeBoundaries = GLO_NETWORK;
     199              : 
     200              :     /// @brief marked edge (used in create edge mode, for splitting)
     201              :     const GNEEdge* markedEdge = nullptr;
     202              : 
     203              :     /// @brief marked lane (used in create edge mode, for splitting)
     204              :     const GNELane* markedLane = nullptr;
     205              : 
     206              :     /// @brief marked TAZ (used in create TAZRel mode)
     207              :     const GUIGlObject* markedTAZ = nullptr;
     208              : 
     209              :     /// @brief marked route (used in create vehicle mode)
     210              :     const GNERoute* markedRoute = nullptr;
     211              : 
     212              :     /// @brief marked first geometry point (used for moving/delete geometry points)
     213              :     const GUIGlObject* markedFirstGeometryPoint = nullptr;
     214              : 
     215              :     /// @brief marked first geometry point (used for moving/delete geometry points)
     216              :     const GUIGlObject* markedSecondGeometryPoint = nullptr;
     217              : 
     218              : protected:
     219              :     /// @brief selected element sorted by layer
     220              :     GLObjectsSortedContainer mySortedSelectedObjects;
     221              : 
     222              :     /// @brief map with selected elements and if was selected with full boundary (used only to avoid double selections)
     223              :     std::unordered_map<const GUIGlObject*, const GNESegment*> mySelectedObjects;
     224              : 
     225              :     /// @brief number of selected objects
     226              :     int myNumberOfSelectedObjects = 0;
     227              : 
     228              :     /// @brief set with path elements marked for redrawing
     229              :     std::set<const GNEPathElement*> myRedrawPathElements;
     230              : 
     231              :     /// @brief selection triangle
     232              :     Triangle mySelectionTriangle;
     233              : 
     234              :     /// @brief position
     235              :     Position mySelectionPosition;
     236              : 
     237              :     /// @brief empty geometry points
     238              :     std::vector<int> myEmptyGeometryPoints;
     239              : 
     240              :     /// @brief merging junctions
     241              :     std::vector<const GNEJunction*> myMergingJunctions;
     242              : 
     243              : private:
     244              :     /// @brief set copy constructor private
     245              :     GUIViewObjectsHandler(const GUIViewObjectsHandler&) = default;
     246              : 
     247              :     /// @brief set assignment operator private
     248              :     GUIViewObjectsHandler& operator=(const GUIViewObjectsHandler&) = default;
     249              : };
        

Generated by: LCOV version 2.0-1