Path: blob/main/src/utils/gui/div/GUIViewObjectsHandler.h
169685 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GUIViewObjectsHandler.h14/// @author Pablo Alvarez Lopez15/// @date Jun 2216///17// class used for handle objects over view18/****************************************************************************/19#pragma once20#include <config.h>2122#include <vector>23#include <unordered_map>24#include <utils/geom/Triangle.h>25#include <utils/gui/globjects/GUIGlObject.h>26#include <utils/gui/settings/GUIVisualizationSettings.h>2728// ===========================================================================29// class declaration30// ===========================================================================3132class GNEJunction;33class GNEEdge;34class GNELane;35class GNERoute;36class GNEPathElement;37class GNESegment;3839// ===========================================================================40// class definitions41// ===========================================================================4243class GUIViewObjectsHandler {4445public:46/// @brief object container47struct ObjectContainer {4849/// @brief parameter constructor50ObjectContainer(const GUIGlObject* object_) :51object(object_) {}5253/// @brief object54const GUIGlObject* object = nullptr;5556/// @brief vector with geometry points57std::vector<int> geometryPoints;5859/// @brief position over shape60Position posOverShape = Position::INVALID;6162/// @brief offset of position over shape63double offset = 0;64};6566/// @brief object container layer67struct ObjectContainerLayer : public std::vector<ObjectContainer> {6869/// @brief parameter constructor70ObjectContainerLayer() {}7172// @brief append object container and resize if neccesary73void append(const ObjectContainer& objectContainer);74};7576/// @brief typedef for pack elements sorted by layer77typedef std::map<double, ObjectContainerLayer > GLObjectsSortedContainer;7879/// @brief constructor80GUIViewObjectsHandler();8182/// @brief reset view objects handler83void reset();8485/// @name position and boundary functions. used for defining the posion that will be check (usually the mouse position)86/// @{87/// @brief get selection position88const Position& getSelectionPosition() const;8990/// @brief get selection triangle91const Triangle& getSelectionTriangle() const;9293/// @brief set selection position94void setSelectionPosition(const Position& pos);9596/// @brief set selection triangle97void setSelectionTriangle(const Triangle& triangle);9899/// @brief return true if we're selecting using a triangle100bool selectingUsingRectangle() const;101102/// @}103104/// @name check functions. If the result is positive, the given GLObject will be added to elementUnderCursor105/// @{106/// @brief check boundary parent element107bool checkBoundaryParentObject(const GUIGlObject* GLObject, const double layer, const GUIGlObject* parent);108109/// @brief check if mouse is within elements geometry (for circles)110bool checkCircleObject(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,111const Position& center, const double radius, const double layer);112113/// @brief check if mouse is within geometry point114bool checkGeometryPoint(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,115const PositionVector& shape, const int index, const double layer, const double radius);116117/// @brief check if mouse is within geometry point118bool checkPositionOverShape(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,119const PositionVector& shape, const double layer, const double distance);120121/// @brief check (closed) shape element122bool checkShapeObject(const GUIGlObject* GLObject, const PositionVector& shape, const Boundary& shapeBoundary,123const double layer, const GNESegment* segment);124/// @}125126/// @name functions used for mark (select) elements127/// @{128/// @brief add element into list of elements under cursor129bool selectObject(const GUIGlObject* GLObject, const double layer, const bool checkDuplicated,130const bool fullBoundary, const GNESegment* segment);131132/// @brief add geometryPoint into list of elements under cursor133bool selectGeometryPoint(const GUIGlObject* GLObject, const int newIndex, const double layer);134135/// @brief select position over shape (for example, the position over a lane shape)136bool selectPositionOverShape(const GUIGlObject* GLObject, const Position& pos, const double layer, const double offset);137138/// @brief check if element was already selected139bool isObjectSelected(const GUIGlObject* GLObject) const;140141/// @brief check rectangle selection142bool checkRectangleSelection(const GUIVisualizationSettings& s, const GUIGlObject* GLObject,143const double layer, const GUIGlObject* parent);144145/// @brief get all elements under cursor sorted by layer146const GLObjectsSortedContainer& getSelectedObjects() const;147148/// @brief get segment associated with the given GLObject (if exist)149const GNESegment* getSelectedSegment(const GUIGlObject* GLObject) const;150151/// @brief get geometry points for the given glObject152const std::vector<int>& getSelectedGeometryPoints(const GUIGlObject* GLObject) const;153154/// @brief get position over shape155const Position& getSelectedPositionOverShape(const GUIGlObject* GLObject) const;156157/// @brief get number of selected objects158int getNumberOfSelectedObjects() const;159160/// @brief reverse selected objects161void reverseSelectedObjects();162163/// @}164165/// @name functions related with redrawing path elements166/// @{167/// @brief get redrawing objects168const std::set<const GNEPathElement*>& getRedrawPathElements() const;169170/// @brief check if the given path element has to be redraw again171bool isPathElementMarkForRedraw(const GNEPathElement* pathElement) const;172173/// @brief add path element to redrawing set174void addToRedrawPathElements(const GNEPathElement* pathElement);175176/// @}177178/// @name functions related with merging junctions179/// @{180/// @brief get merging junctions181const std::vector<const GNEJunction*>& getMergingJunctions() const;182183/// @brief add to merging junctions (used for marking junctions to merge)184bool addMergingJunctions(const GNEJunction* junction);185186/// @}187188/// @brief move the given object to the front (currently used only in netedit)189void updateFrontObject(const GUIGlObject* GLObject);190191/// @brief isolate edge geometry points (used for moving)192void isolateEdgeGeometryPoints();193194/// @brief recompute boundaries195GUIGlObjectType recomputeBoundaries = GLO_NETWORK;196197/// @brief marked edge (used in create edge mode, for splitting)198const GNEEdge* markedEdge = nullptr;199200/// @brief marked lane (used in create edge mode, for splitting)201const GNELane* markedLane = nullptr;202203/// @brief marked TAZ (used in create TAZRel mode)204const GUIGlObject* markedTAZ = nullptr;205206/// @brief marked route (used in create vehicle mode)207const GNERoute* markedRoute = nullptr;208209/// @brief marked first geometry point (used for moving/delete geometry points)210const GUIGlObject* markedFirstGeometryPoint = nullptr;211212/// @brief marked first geometry point (used for moving/delete geometry points)213const GUIGlObject* markedSecondGeometryPoint = nullptr;214215protected:216/// @brief selected element sorted by layer217GLObjectsSortedContainer mySortedSelectedObjects;218219/// @brief map with selected elements and if was selected with full boundary (used only to avoid double selections)220std::unordered_map<const GUIGlObject*, std::pair<bool, const GNESegment*> > mySelectedObjects;221222/// @brief number of selected objects223int myNumberOfSelectedObjects = 0;224225/// @brief set with path elements marked for redrawing226std::set<const GNEPathElement*> myRedrawPathElements;227228/// @brief selection triangle229Triangle mySelectionTriangle;230231/// @brief position232Position mySelectionPosition;233234/// @brief empty geometry points235std::vector<int> myEmptyGeometryPoints;236237/// @brief merging junctions238std::vector<const GNEJunction*> myMergingJunctions;239240private:241/// @brief set copy constructor private242GUIViewObjectsHandler(const GUIViewObjectsHandler&) = default;243244/// @brief set assignment operator private245GUIViewObjectsHandler& operator=(const GUIViewObjectsHandler&) = default;246};247248249