Path: blob/main/src/utils/gui/div/GUIViewObjectsHandler.h
193678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 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///129/// @brief add element into list of elements under cursor130bool selectObject(const GUIGlObject* GLObject, const double layer, const bool checkDuplicated,131const GNESegment* segment);132133/// @brief add geometryPoint into list of elements under cursor134bool selectGeometryPoint(const GUIGlObject* GLObject, const int newIndex, const double layer);135136/// @brief select position over shape (for example, the position over a lane shape)137bool selectPositionOverShape(const GUIGlObject* GLObject, const Position& pos, const double layer, const double offset);138139/// @brief check if element was already selected140bool isObjectSelected(const GUIGlObject* GLObject) const;141142/// @brief check rectangle selection143bool checkRectangleSelection(const GUIVisualizationSettings& s, const GUIGlObject* GLObject,144const double layer, const GUIGlObject* parent);145146/// @brief get all elements under cursor sorted by layer147const GLObjectsSortedContainer& getSelectedObjects() const;148149/// @brief get segment associated with the given GLObject (if exist)150const GNESegment* getSelectedSegment(const GUIGlObject* GLObject) const;151152/// @brief get geometry points for the given glObject153const std::vector<int>& getSelectedGeometryPoints(const GUIGlObject* GLObject) const;154155/// @brief get position over shape156const Position& getSelectedPositionOverShape(const GUIGlObject* GLObject) const;157158/// @brief get number of selected objects159int getNumberOfSelectedObjects() const;160161/// @brief reverse selected objects162void reverseSelectedObjects();163164/// @}165166/// @name functions related with redrawing path elements167/// @{168/// @brief get redrawing objects169const std::set<const GNEPathElement*>& getRedrawPathElements() const;170171/// @brief check if the given path element has to be redraw again172bool isPathElementMarkForRedraw(const GNEPathElement* pathElement) const;173174/// @brief add path element to redrawing set175void addToRedrawPathElements(const GNEPathElement* pathElement);176177/// @}178179/// @name functions related with merging junctions180/// @{181/// @brief get merging junctions182const std::vector<const GNEJunction*>& getMergingJunctions() const;183184/// @brief add to merging junctions (used for marking junctions to merge)185bool addMergingJunctions(const GNEJunction* junction);186187/// @}188189/// @brief move the given object to the front (currently used only in netedit)190void updateFrontObject(const GUIGlObject* GLObject);191192/// @brief isolate edge geometry points (used for moving)193void isolateEdgeGeometryPoints();194195/// @brief recompute boundaries196GUIGlObjectType recomputeBoundaries = GLO_NETWORK;197198/// @brief marked edge (used in create edge mode, for splitting)199const GNEEdge* markedEdge = nullptr;200201/// @brief marked lane (used in create edge mode, for splitting)202const GNELane* markedLane = nullptr;203204/// @brief marked TAZ (used in create TAZRel mode)205const GUIGlObject* markedTAZ = nullptr;206207/// @brief marked route (used in create vehicle mode)208const GNERoute* markedRoute = nullptr;209210/// @brief marked first geometry point (used for moving/delete geometry points)211const GUIGlObject* markedFirstGeometryPoint = nullptr;212213/// @brief marked first geometry point (used for moving/delete geometry points)214const GUIGlObject* markedSecondGeometryPoint = nullptr;215216protected:217/// @brief selected element sorted by layer218GLObjectsSortedContainer mySortedSelectedObjects;219220/// @brief map with selected elements and if was selected with full boundary (used only to avoid double selections)221std::unordered_map<const GUIGlObject*, const GNESegment*> mySelectedObjects;222223/// @brief number of selected objects224int myNumberOfSelectedObjects = 0;225226/// @brief set with path elements marked for redrawing227std::set<const GNEPathElement*> myRedrawPathElements;228229/// @brief selection triangle230Triangle mySelectionTriangle;231232/// @brief position233Position mySelectionPosition;234235/// @brief empty geometry points236std::vector<int> myEmptyGeometryPoints;237238/// @brief merging junctions239std::vector<const GNEJunction*> myMergingJunctions;240241private:242/// @brief set copy constructor private243GUIViewObjectsHandler(const GUIViewObjectsHandler&) = default;244245/// @brief set assignment operator private246GUIViewObjectsHandler& operator=(const GUIViewObjectsHandler&) = default;247};248249250