Path: blob/main/src/netedit/elements/additional/GNEPoly.h
169684 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 GNEPoly.h14/// @author Pablo Alvarez Lopez15/// @date Jun 201716///17// A class for visualizing and editing POIS in netedit (adapted from18// GUIPolygon and NLHandler)19/****************************************************************************/20#pragma once21#include <config.h>22#include <utils/gui/globjects/GUIPolygon.h>23#include <utils/xml/CommonXMLStructure.h>2425#include "GNEAdditional.h"2627// ===========================================================================28// class declarations29// ===========================================================================3031class GeoConvHelper;32class GNENetworkElement;3334// ===========================================================================35// class definitions36// ===========================================================================3738class GNEPoly : public TesselatedPolygon, public GNEAdditional {3940public:41/// @brief needed to avoid diamond problem between SUMOPolygon and GNEAdditional42using GNEAdditional::getID;4344/// @brief default Constructor45GNEPoly(SumoXMLTag tag, GNENet* net);4647/** @brief Constructor for polygons48* @param[in] id The name of the polygon49* @param[in] net net in which this polygon is placed50* @param[in] filename file in which this element is stored51* @param[in] type The (abstract) type of the polygon52* @param[in] shape The shape of the polygon53* @param[in] geo specify if shape was loaded as GEO54* @param[in] color The color of the polygon55* @param[in] layer The layer of the polygon56* @param[in] angle The rotation of the polygon57* @param[in] imgFile The raster image of the polygon58* @param[in] fill Whether the polygon shall be filled59* @param[in] lineWidth Line width when drawing unfilled polygon60* @param[in] name Poly's name61* @param[in] parameters generic parameters62*/63GNEPoly(const std::string& id, GNENet* net, const std::string& filename, const std::string& type, const PositionVector& shape,64bool geo, bool fill, double lineWidth, const RGBColor& color, double layer, double angle, const std::string& imgFile,65const std::string& name, const Parameterised::Map& parameters);6667/** @brief Constructor for JuPedSim elements68* @param[in] id The name of the polygon69* @param[in] net net in which this polygon is placed70* @param[in] filename file in which this element is stored71* @param[in] shape The shape of the polygon72* @param[in] geo specify if shape was loaded as GEO73* @param[in] name Poly's name74* @param[in] parameters generic parameters75*/76GNEPoly(SumoXMLTag tag, const std::string& id, GNENet* net, const std::string& filename, const PositionVector& shape,77bool geo, const std::string& name, const Parameterised::Map& parameters);7879/// @brief Destructor80~GNEPoly();8182/**@brief get move operation83* @note returned GNEMoveOperation can be nullptr84*/85GNEMoveOperation* getMoveOperation() override;8687/// @brief remove geometry point in the clicked position88void removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) override;8990/// @brief gererate a new ID for an element child91std::string generateChildID(SumoXMLTag childTag);9293/// @name inherited from GNEAdditional94/// @{95/// @brief update pre-computed geometry information96void updateGeometry() override;9798/// @brief Returns position of shape in view99Position getPositionInView() const override;100101/// @brief return exaggeration associated with this GLObject102double getExaggeration(const GUIVisualizationSettings& s) const override;103104/// @brief update centering boundary (implies change in RTREE)105void updateCenteringBoundary(const bool updateGrid) override;106107/// @brief split geometry108void splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement,109const GNENetworkElement* newElement, GNEUndoList* undoList) override;110111/**@brief write additional element into a xml file112* @param[in] device device in which write parameters of additional element113*/114void writeAdditional(OutputDevice& device) const override;115116/// @brief check if current additional is valid to be written into XML (must be reimplemented in all detector children)117bool isAdditionalValid() const override;118119/// @brief return a string with the current additional problem (must be reimplemented in all detector children)120std::string getAdditionalProblem() const override;121122/// @brief fix additional problem (must be reimplemented in all detector children)123void fixAdditionalProblem() override;124125/// @brief Returns the numerical id of the object126GUIGlID getGlID() const;127128/// @}129130/// @name Function related with contour drawing131/// @{132133/// @brief check if draw move contour (red)134bool checkDrawMoveContour() const override;135136/// @}137138/// @name inherited from GUIGlObject139/// @{140/**@brief Returns the name of the parent object141* @return This object's parent id142*/143std::string getParentName() const override;144145/**@brief Returns an own popup-menu146*147* @param[in] app The application needed to build the popup-menu148* @param[in] parent The parent window needed to build the popup-menu149* @return The built popup-menu150* @see GUIGlObject::getPopUpMenu151*/152GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;153154/**@brief Draws the object155* @param[in] s The settings for the current view (may influence drawing)156* @see GUIGlObject::drawGL157*/158void drawGL(const GUIVisualizationSettings& s) const override;159160/// @}161162/// @name inherited from GNEAttributeCarrier163/// @{164/* @brief method for getting the Attribute of an XML key165* @param[in] key The attribute key166* @return string with the value associated to key167*/168std::string getAttribute(SumoXMLAttr key) const override;169170/* @brief method for getting the Attribute of an XML key in double format (to avoid unnecessary parse<double>(...) for certain attributes)171* @param[in] key The attribute key172* @return double with the value associated to key173*/174double getAttributeDouble(SumoXMLAttr key) const override;175176/// @brief get parameters map177const Parameterised::Map& getACParametersMap() const override;178179/**@brief method for setting the attribute and letting the object perform additional changes180* @param[in] key The attribute key181* @param[in] value The new value182* @param[in] undoList The undoList on which to register changes183*/184void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) override;185186/**@brief method for checking if the key and their conrrespond attribute are valids187* @param[in] key The attribute key188* @param[in] value The value associated to key key189* @return true if the value is valid, false in other case190*/191bool isValid(SumoXMLAttr key, const std::string& value) override;192193/* @brief method for check if the value for certain attribute is set194* @param[in] key The attribute key195*/196bool isAttributeEnabled(SumoXMLAttr key) const override;197/// @}198199/// @brief get PopPup ID (Used in AC Hierarchy)200std::string getPopUpID() const override;201202/// @brief get Hierarchy Name (Used in AC Hierarchy)203std::string getHierarchyName() const override;204205/**@brief return index of a vertex of shape, or of a new vertex if position is over an shape's edge206* @param pos position of new/existent vertex207* @param snapToGrid enable or disable snapToActiveGrid208* @return index of position vector209*/210int getVertexIndex(Position pos, bool snapToGrid);211212/// @brief delete the geometry point closest to the given pos213void deleteGeometryPoint(const Position& pos, bool allowUndo = true);214215/// @brief check if polygon is closed216bool isPolygonClosed() const;217218/// @brief open polygon219void openPolygon(bool allowUndo = true);220221/// @brief close polygon222void closePolygon(bool allowUndo = true);223224/// @brief change first geometry point225void changeFirstGeometryPoint(int oldIndex, bool allowUndo = true);226227/// @brief replace the current shape with a rectangle228void simplifyShape(bool allowUndo = true);229230/// @brief get SUMOBaseObject with all polygon attributes231CommonXMLStructure::SumoBaseObject* getSumoBaseObject() const;232233protected:234/// @brief Latitude of Polygon235PositionVector myGeoShape;236237/// @brief flag to indicate if polygon is closed238bool myClosedShape = false;239240/// @brief flag to indicate if polygon is simplified241bool mySimplifiedShape = false;242243private:244/// @brief set attribute after validation245void setAttribute(SumoXMLAttr key, const std::string& value) override;246247/// @brief set move shape248void setMoveShape(const GNEMoveResult& moveResult) override;249250/// @brief commit move shape251void commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) override;252253/// @brief draw polygon254void drawPolygon(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,255const RGBColor& color, const double exaggeration) const;256257/// @brief draw contour258void drawPolygonContour(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,259const RGBColor& color, const double exaggeration) const;260261/// @brief draw geometry points262void drawGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,263const RGBColor& color, const double exaggeration) const;264265/// @brief draw polygon name and type266void drawPolygonNameAndType(const GUIVisualizationSettings& s) const;267268/// @brief Invalidated copy constructor.269GNEPoly(const GNEPoly&) = delete;270271/// @brief Invalidated assignment operator.272GNEPoly& operator=(const GNEPoly&) = delete;273};274275276