Path: blob/main/src/netedit/elements/additional/GNEPoly.h
193674 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 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>2223#include <utils/gui/globjects/GUIPolygon.h>24#include <utils/xml/CommonXMLStructure.h>2526#include "GNEAdditional.h"2728// ===========================================================================29// class declarations30// ===========================================================================3132class GeoConvHelper;33class GNEMoveElementShape;34class GNENetworkElement;3536// ===========================================================================37// class definitions38// ===========================================================================3940class GNEPoly : public TesselatedPolygon, public GNEAdditional {4142public:43/// @brief needed to avoid diamond problem between SUMOPolygon and GNEAdditional44using GNEAdditional::getID;4546/// @brief default Constructor47GNEPoly(SumoXMLTag tag, GNENet* net);4849/** @brief Constructor for polygons50* @param[in] id The name of the polygon51* @param[in] net net in which this polygon is placed52* @param[in] fileBucket file in which this element is stored53* @param[in] type The (abstract) type of the polygon54* @param[in] shape The shape of the polygon55* @param[in] geo specify if shape was loaded as GEO56* @param[in] color The color of the polygon57* @param[in] layer The layer of the polygon58* @param[in] angle The rotation of the polygon59* @param[in] imgFile The raster image of the polygon60* @param[in] fill Whether the polygon shall be filled61* @param[in] lineWidth Line width when drawing unfilled polygon62* @param[in] name Poly's name63* @param[in] parameters generic parameters64*/65GNEPoly(const std::string& id, GNENet* net, FileBucket* fileBucket, const std::string& type, const PositionVector& shape,66bool geo, bool fill, double lineWidth, const RGBColor& color, double layer, double angle, const std::string& imgFile,67const std::string& name, const Parameterised::Map& parameters);6869/** @brief Constructor for JuPedSim elements70* @param[in] id The name of the polygon71* @param[in] net net in which this polygon is placed72* @param[in] fileBucket file in which this element is stored73* @param[in] shape The shape of the polygon74* @param[in] geo specify if shape was loaded as GEO75* @param[in] name Poly's name76* @param[in] parameters generic parameters77*/78GNEPoly(SumoXMLTag tag, const std::string& id, GNENet* net, FileBucket* fileBucket, const PositionVector& shape,79bool geo, const std::string& name, const Parameterised::Map& parameters);8081/// @brief Destructor82~GNEPoly();8384/// @brief methods to retrieve the elements linked to this poly85/// @{8687/// @brief get GNEMoveElement associated with this poly88GNEMoveElement* getMoveElement() const override;8990/// @brief get parameters associated with this poly91Parameterised* getParameters() override;9293/// @brief get parameters associated with this poly (constant)94const Parameterised* getParameters() const override;9596/// @}9798/// @brief gererate a new ID for an element child99std::string generateChildID(SumoXMLTag childTag);100101/// @name inherited from GNEAdditional102/// @{103/// @brief update pre-computed geometry information104void updateGeometry() override;105106/// @brief Returns position of shape in view107Position getPositionInView() const override;108109/// @brief return exaggeration associated with this GLObject110double getExaggeration(const GUIVisualizationSettings& s) const override;111112/// @brief update centering boundary (implies change in RTREE)113void updateCenteringBoundary(const bool updateGrid) override;114115/// @brief split geometry116void splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement,117const GNENetworkElement* newElement, GNEUndoList* undoList) override;118119/**@brief write additional element into a xml file120* @param[in] device device in which write parameters of additional element121*/122void writeAdditional(OutputDevice& device) const override;123124/// @brief check if current additional is valid to be written into XML (must be reimplemented in all detector children)125bool isAdditionalValid() const override;126127/// @brief return a string with the current additional problem (must be reimplemented in all detector children)128std::string getAdditionalProblem() const override;129130/// @brief fix additional problem (must be reimplemented in all detector children)131void fixAdditionalProblem() override;132133/// @brief Returns the numerical id of the object134GUIGlID getGlID() const;135136/// @}137138/// @name Function related with contour drawing139/// @{140141/// @brief check if draw move contour (red)142bool checkDrawMoveContour() const override;143144/// @}145146/// @name inherited from GUIGlObject147/// @{148/**@brief Returns the name of the parent object149* @return This object's parent id150*/151std::string getParentName() const override;152153/**@brief Returns an own popup-menu154*155* @param[in] app The application needed to build the popup-menu156* @param[in] parent The parent window needed to build the popup-menu157* @return The built popup-menu158* @see GUIGlObject::getPopUpMenu159*/160GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;161162/**@brief Draws the object163* @param[in] s The settings for the current view (may influence drawing)164* @see GUIGlObject::drawGL165*/166void drawGL(const GUIVisualizationSettings& s) const override;167168/// @}169170/// @name inherited from GNEAttributeCarrier171/// @{172/* @brief method for getting the Attribute of an XML key173* @param[in] key The attribute key174* @return string with the value associated to key175*/176std::string getAttribute(SumoXMLAttr key) const override;177178/* @brief method for getting the Attribute of an XML key in double format179* @param[in] key The attribute key180* @return double with the value associated to key181*/182double getAttributeDouble(SumoXMLAttr key) const override;183184/* @brief method for getting the Attribute of an XML key in position format185* @param[in] key The attribute key186* @return position with the value associated to key187*/188Position getAttributePosition(SumoXMLAttr key) const override;189190/* @brief method for getting the Attribute of an XML key in positionVector format191* @param[in] key The attribute key192* @return positionVector with the value associated to key193*/194PositionVector getAttributePositionVector(SumoXMLAttr key) const override;195196/**@brief method for setting the attribute and letting the object perform additional changes197* @param[in] key The attribute key198* @param[in] value The new value199* @param[in] undoList The undoList on which to register changes200*/201void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) override;202203/**@brief method for checking if the key and their conrrespond attribute are valids204* @param[in] key The attribute key205* @param[in] value The value associated to key key206* @return true if the value is valid, false in other case207*/208bool isValid(SumoXMLAttr key, const std::string& value) override;209210/* @brief method for check if the value for certain attribute is set211* @param[in] key The attribute key212*/213bool isAttributeEnabled(SumoXMLAttr key) const override;214/// @}215216/// @brief get PopPup ID (Used in AC Hierarchy)217std::string getPopUpID() const override;218219/// @brief get Hierarchy Name (Used in AC Hierarchy)220std::string getHierarchyName() const override;221222/**@brief return index of a vertex of shape, or of a new vertex if position is over an shape's edge223* @param pos position of new/existent vertex224* @param snapToGrid enable or disable snapToActiveGrid225* @return index of position vector226*/227int getVertexIndex(Position pos, bool snapToGrid);228229/// @brief delete the geometry point closest to the given pos230void deleteGeometryPoint(const Position& pos, bool allowUndo = true);231232/// @brief check if polygon is closed233bool isPolygonClosed() const;234235/// @brief open polygon236void openPolygon(bool allowUndo = true);237238/// @brief close polygon239void closePolygon(bool allowUndo = true);240241/// @brief change first geometry point242void changeFirstGeometryPoint(int oldIndex, bool allowUndo = true);243244/// @brief replace the current shape with a rectangle245void simplifyShape(bool allowUndo = true);246247/// @brief get SUMOBaseObject with all polygon attributes248CommonXMLStructure::SumoBaseObject* getSumoBaseObject() const;249250protected:251/// @brief move element shape252GNEMoveElementShape* myMoveElementShape = nullptr;253254/// @brief Latitude of Polygon255PositionVector myGeoShape;256257/// @brief flag to indicate if polygon is closed258bool myClosedShape = false;259260/// @brief flag to indicate if polygon is simplified261bool mySimplifiedShape = false;262263private:264/// @brief set attribute after validation265void setAttribute(SumoXMLAttr key, const std::string& value) override;266267/// @brief draw polygon268void drawPolygon(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,269const RGBColor& color, const double exaggeration) const;270271/// @brief draw contour272void drawPolygonContour(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,273const RGBColor& color, const double exaggeration) const;274275/// @brief draw geometry points276void drawGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,277const RGBColor& color, const double exaggeration) const;278279/// @brief draw polygon name and type280void drawPolygonNameAndType(const GUIVisualizationSettings& s) const;281282/// @brief Invalidated copy constructor.283GNEPoly(const GNEPoly&) = delete;284285/// @brief Invalidated assignment operator.286GNEPoly& operator=(const GNEPoly&) = delete;287};288289290