Path: blob/main/src/netedit/elements/additional/GNEAdditional.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 GNEAdditional.h14/// @author Pablo Alvarez Lopez15/// @date Jan 201616///17// A abstract class for representation of additional elements18/****************************************************************************/19#pragma once20#include <config.h>2122#include <netedit/elements/GNEAttributeCarrier.h>23#include <netedit/elements/GNEContour.h>24#include <netedit/elements/GNEHierarchicalElement.h>25#include <netedit/elements/GNEMoveElement.h>26#include <netedit/elements/GNEPathElement.h>27#include <utils/gui/globjects/GUIGlObject.h>28#include <utils/gui/images/GUITextureSubSys.h>2930// ===========================================================================31// class declarations32// ===========================================================================3334class GNENetworkElement;35class GUIGLObjectPopupMenu;3637// ===========================================================================38// class definitions39// ===========================================================================4041class GNEAdditional : public GNEAttributeCarrier, public GNEHierarchicalElement, public GUIGlObject, public GNEPathElement, public GNEMoveElement {4243public:44/**@brief Constructor45* @param[in] id Gl-id of the additional element (Must be unique)46* @param[in] net pointer to GNENet of this additional element belongs47* @param[in] filename file in which this AttributeCarrier is stored48* @param[in] tag Type of xml tag that define the additional element (SUMO_TAG_BUS_STOP, SUMO_TAG_REROUTER, etc...)49* @param[in] additionalName Additional name50*/51GNEAdditional(const std::string& id, GNENet* net, const std::string& filename,52SumoXMLTag tag, const std::string& additionalName);5354/**@brief Constructor for additional with parents55* @param[in] additionalParent pointer to additional parent56* @param[in] tag Type of xml tag that define the additional element (SUMO_TAG_BUS_STOP, SUMO_TAG_REROUTER, etc...)57* @param[in] additionalName Additional name58*/59GNEAdditional(GNEAdditional* additionalParent, SumoXMLTag tag, const std::string& additionalName);6061/// @brief Destructor62~GNEAdditional();6364/// @brief get GNEHierarchicalElement associated with this AttributeCarrier65GNEHierarchicalElement* getHierarchicalElement();6667/**@brief get move operation68* @note returned GNEMoveOperation can be nullptr69*/70virtual GNEMoveOperation* getMoveOperation() = 0;7172/// @brief remove geometry point in the clicked position (Currently unused in shapes)73void removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList);7475/// @brief get GUIGlObject associated with this AttributeCarrier76GUIGlObject* getGUIGlObject();7778/// @brief get GUIGlObject associated with this AttributeCarrier (constant)79const GUIGlObject* getGUIGlObject() const;8081/// @brief Returns the name of the object (default "")82virtual const std::string getOptionalName() const;8384/// @brief obtain additional geometry85const GUIGeometry& getAdditionalGeometry() const;8687/// @brief set special color88void setSpecialColor(const RGBColor* color);8990/// @brief reset additional contour91void resetAdditionalContour();9293/// @name members and functions relative to write additionals into XML94/// @{9596/**@brief write additional element into a xml file97* @param[in] device device in which write parameters of additional element98*/99virtual void writeAdditional(OutputDevice& device) const = 0;100101/// @brief check if current additional is valid to be written into XML (by default true, can be reimplemented in children)102virtual bool isAdditionalValid() const = 0;103104/// @brief return a string with the current additional problem (by default empty, can be reimplemented in children)105virtual std::string getAdditionalProblem() const = 0;106107/// @brief fix additional problem (by default throw an exception, has to be reimplemented in children)108virtual void fixAdditionalProblem() = 0;109110/// @}111112/// @name functions related with geometry113/// @{114115/**@brief open Additional Dialog116* @note: if additional needs an additional dialog, this function has to be implemented in childrens (see GNERerouter and GNEVariableSpeedSign)117* @throw invalid argument if additional doesn't have an additional Dialog118*/119virtual void openAdditionalDialog();120121/// @brief update pre-computed geometry information122virtual void updateGeometry() = 0;123124/// @brief Returns position of additional in view125virtual Position getPositionInView() const = 0;126127/// @brief return exaggeration associated with this GLObject128double getExaggeration(const GUIVisualizationSettings& s) const;129130/// @brief Returns the boundary to which the view shall be centered in order to show the object131Boundary getCenteringBoundary() const;132133/// @brief update centering boundary (implies change in RTREE)134virtual void updateCenteringBoundary(const bool updateGrid) = 0;135136/// @brief split geometry137virtual void splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) = 0;138139/// @}140141/// @name Function related with contour drawing142/// @{143144/// @brief check if draw from contour (green)145bool checkDrawFromContour() const;146147/// @brief check if draw from contour (magenta)148bool checkDrawToContour() const;149150/// @brief check if draw related contour (cyan)151bool checkDrawRelatedContour() const;152153/// @brief check if draw over contour (orange)154bool checkDrawOverContour() const;155156/// @brief check if draw delete contour (pink/white)157bool checkDrawDeleteContour() const;158159/// @brief check if draw delete contour small (pink/white)160bool checkDrawDeleteContourSmall() const;161162/// @brief check if draw select contour (blue)163bool checkDrawSelectContour() const;164165/// @brief check if draw move contour (red)166virtual bool checkDrawMoveContour() const = 0;167168/// @}169170/// @name inherited from GUIGlObject171/// @{172173/**@brief Returns an own popup-menu174*175* @param[in] app The application needed to build the popup-menu176* @param[in] parent The parent window needed to build the popup-menu177* @return The built popup-menu178* @see GUIGlObject::getPopUpMenu179*/180virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent);181182/**@brief Returns an own parameter window183*184* @param[in] app The application needed to build the parameter window185* @param[in] parent The parent window needed to build the parameter window186* @return The built parameter window187* @see GUIGlObject::getParameterWindow188*/189GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent);190191/// @brief Returns the additional name192const std::string& getOptionalAdditionalName() const;193194/**@brief Draws the object195* @param[in] s The settings for the current view (may influence drawing)196* @see GUIGlObject::drawGL197*/198virtual void drawGL(const GUIVisualizationSettings& s) const = 0;199200/// @brief check if element is locked201bool isGLObjectLocked() const;202203/// @brief mark element as front element204void markAsFrontElement();205206/// @brief delete element207void deleteGLObject();208209/// @brief select element210void selectGLObject();211212/// @brief update GLObject (geometry, ID, etc.)213void updateGLObject();214215/// @}216217/// @name inherited from GNEPathElement218/// @{219220/// @brief compute pathElement221virtual void computePathElement();222223/// @brief check if path element is selected224bool isPathElementSelected() const;225226/**@brief Draws partial object over lane227* @param[in] s The settings for the current view (may influence drawing)228* @param[in] segment lane segment229* @param[in] offsetFront front offset230*/231virtual void drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const;232233/**@brief Draws partial object over junction234* @param[in] s The settings for the current view (may influence drawing)235* @param[in] segment junction segment236* @param[in] offsetFront front offset237*/238virtual void drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const;239240/// @brief get first path lane241GNELane* getFirstPathLane() const;242243/// @brief get last path lane244GNELane* getLastPathLane() const;245246/// @}247248/// @name inherited from GNEAttributeCarrier249/// @{250251/* @brief method for getting the Attribute of an XML key252* @param[in] key The attribute key253* @return string with the value associated to key254*/255virtual std::string getAttribute(SumoXMLAttr key) const = 0;256257/* @brief method for getting the Attribute of an XML key in double format (to avoid unnecessary parse<double>(...) for certain attributes)258* @param[in] key The attribute key259* @return double with the value associated to key260*/261virtual double getAttributeDouble(SumoXMLAttr key) const = 0;262263/* @brief method for getting the Attribute of an XML key in position format (to avoid unnecessary parse<position>(...) for certain attributes)264* @param[in] key The attribute key265* @return double with the value associated to key266*/267virtual Position getAttributePosition(SumoXMLAttr key) const;268269/// @brief get parameters map270virtual const Parameterised::Map& getACParametersMap() const = 0;271272/**@brief method for setting the attribute and letting the object perform additional changes273* @param[in] key The attribute key274* @param[in] value The new value275* @param[in] undoList The undoList on which to register changes276*/277virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;278279/**@brief method for checking if the key and their correspondent attribute are valids280* @param[in] key The attribute key281* @param[in] value The value associated to key key282* @return true if the value is valid, false in other case283*/284virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;285286/// @brief get PopPup ID (Used in AC Hierarchy)287virtual std::string getPopUpID() const = 0;288289/// @brief get Hierarchy Name (Used in AC Hierarchy)290virtual std::string getHierarchyName() const = 0;291292/// @}293294/// @brief draw parent and child lines295void drawParentChildLines(const GUIVisualizationSettings& s, const RGBColor& color, const bool onlySymbols = false) const;296297/// @brief draw up geometry point298void drawUpGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const Position& pos,299const double rot, const RGBColor& baseColor, const bool ignoreShift = false) const;300301/// @brief draw down geometry point302void drawDownGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const Position& pos,303const double rot, const RGBColor& baseColor, const bool ignoreShift = false) const;304305/// @brief draw left geometry point306void drawLeftGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const Position& pos,307const double rot, const RGBColor& baseColor, const bool ignoreShift = false) const;308309/// @brief draw right geometry point310void drawRightGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const Position& pos,311const double rot, const RGBColor& baseColor, const bool ignoreShift = false) const;312313/// @brief get draw position index (used in rerouters and VSS)314int getDrawPositionIndex() const;315316/// @brief check if the given lanes are consecutive317static bool areLaneConsecutives(const std::vector<GNELane*>& lanes);318319/// @brief check if the given lanes are connected320static bool areLaneConnected(const std::vector<GNELane*>& lanes);321322protected:323/// @brief Additional Boundary (used only by additionals placed over grid)324Boundary myAdditionalBoundary;325326/// @brief geometry to be precomputed in updateGeometry(...)327GUIGeometry myAdditionalGeometry;328329/// @brief variable used for draw additional contours330GNEContour myAdditionalContour;331332/// @brief name of additional333std::string myAdditionalName;334335/// @brief pointer to special color (used for drawing Additional with a certain color, mainly used for selections)336const RGBColor* mySpecialColor = nullptr;337338/// @name Functions relative to change values in setAttribute(...)339/// @{340341/// @brief check if a new additional ID is valid342bool isValidAdditionalID(const std::string& value) const;343344/// @brief check if a new additional ID is valid345bool isValidAdditionalID(const std::vector<SumoXMLTag>& tags, const std::string& value) const;346347/// @brief check if a new detector ID is valid348bool isValidDetectorID(const std::string& value) const;349350/// @brief check if a new detector ID is valid351bool isValidDetectorID(const std::vector<SumoXMLTag>& tags, const std::string& value) const;352353/// @brief set additional ID354void setAdditionalID(const std::string& newID);355356/// @}357358/// @brief draw additional ID359void drawAdditionalID(const GUIVisualizationSettings& s) const;360361/// @brief draw additional name362void drawAdditionalName(const GUIVisualizationSettings& s) const;363364/// @brief replace additional parent edges365void replaceAdditionalParentEdges(const std::string& value);366367/// @brief replace additional parent lanes368void replaceAdditionalParentLanes(const std::string& value);369370/// @brief replace additional child edges371void replaceAdditionalChildEdges(const std::string& value);372373/// @brief replace additional child lanes374void replaceAdditionalChildLanes(const std::string& value);375376/// @brief replace additional parent377void replaceAdditionalParent(SumoXMLTag tag, const std::string& value, const int parentIndex);378379/// @brief replace demand element parent380void replaceDemandElementParent(SumoXMLTag tag, const std::string& value, const int parentIndex);381382/// @brief shift lane index383void shiftLaneIndex();384385/// @brief calculate perpendicular line between lane parents386void calculatePerpendicularLine(const double endLaneposition);387388/// @brief draw squared additional389void drawSquaredAdditional(const GUIVisualizationSettings& s, const Position& pos, const double size,390GUITexture texture, GUITexture selectedTexture) const;391392/// @brief draw listed additional393void drawListedAdditional(const GUIVisualizationSettings& s, const Position& parentPosition, const double offsetX,394const double extraOffsetY, const RGBColor baseCol, const RGBColor textCol, GUITexture texture,395const std::string text) const;396397/// @brief check if draw additional extrem geometry points398bool drawMovingGeometryPoints(const bool ignoreShift) const;399400/// @brief draw demand element children401void drawDemandElementChildren(const GUIVisualizationSettings& s) const;402403/// @brief get moveOperation for an element over single lane404GNEMoveOperation* getMoveOperationSingleLane(const double startPos, const double endPos);405406/// @brief get moveOperation for an element over multi lane407GNEMoveOperation* getMoveOperationMultiLane(const double startPos, const double endPos);408409/// @name JuPedSim values410/// @{411412/// @brief get JuPedSim type413static std::string getJuPedSimType(SumoXMLTag tag);414415/// @brief get JuPedSim color416static RGBColor getJuPedSimColor(SumoXMLTag tag);417418/// @brief get JuPedSim fill419static bool getJuPedSimFill(SumoXMLTag tag);420421/// @brief get JuPedSim color422static double getJuPedSimLayer(SumoXMLTag tag);423424/// @}425426/// @name calculate contours427/// @{428429/// @brief calculate contour for polygons430void calculateContourPolygons(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,431const double layer, const double exaggeration, const bool filledShape) const;432433/// @}434435private:436/**@brief check restriction with the number of children437* @throw ProcessError if is called without be reimplemented in child class438*/439virtual bool checkChildAdditionalRestriction() const;440441/// @brief method for setting the attribute and nothing else (used in GNEChange_Attribute)442virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;443444/// @brief set move shape445virtual void setMoveShape(const GNEMoveResult& moveResult) = 0;446447/// @brief commit move shape448virtual void commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) = 0;449450/// @brief draw geometry point451void drawSemiCircleGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,452const Position& pos, const double rot, const RGBColor& baseColor,453const double fromAngle, const double toAngle, const bool ignoreShift) const;454455/// @brief adjust listed additional text456std::string adjustListedAdditionalText(const std::string& text) const;457458/// @brief Invalidated copy constructor.459GNEAdditional(const GNEAdditional&) = delete;460461/// @brief Invalidated assignment operator.462GNEAdditional& operator=(const GNEAdditional&) = delete;463};464465466