Path: blob/main/src/netedit/elements/additional/GNEDetector.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 GNEDetector.h14/// @author Pablo Alvarez Lopez15/// @date Nov 201516///17// A abstract class to define common parameters of detectors placed over lanes18/****************************************************************************/19#pragma once20#include <config.h>2122#include "GNEAdditional.h"2324// ===========================================================================25// class definitions26// ===========================================================================2728class GNEDetector : public GNEAdditional, public Parameterised {2930public:31/**@brief Default constructor32* @param[in] net pointer to GNENet of this additional element belongs33* @param[in] tag Type of xml tag that define the detector (SUMO_TAG_INDUCTION_LOOP, SUMO_TAG_LANE_AREA_DETECTOR, etc...)34*/35GNEDetector(GNENet* net, SumoXMLTag tag);3637/**@brief Constructor38* @param[in] id Gl-id of the detector (Must be unique)39* @param[in] net pointer to GNENet of this additional element belongs40* @param[in] filename file in which this AttributeCarrier is stored41* @param[in] tag Type of xml tag that define the detector (SUMO_TAG_INDUCTION_LOOP, SUMO_TAG_LANE_AREA_DETECTOR, etc...)42* @param[in] pos position of the detector on the lane43* @param[in] period the aggregation period the values the detector collects shall be summed up.44* @param[in] lane parent lane45* @param[in] vehicleTypes space separated list of vehicle type ids to consider46* @param[in] nextEdges list of edge ids that must all be part of the future route of the vehicle to qualify for detection47* @param[in] detectPersons detect persons instead of vehicles (pedestrians or passengers)48* @param[in] outputFilename The path to the output file.49* @param[in] name detector name50* @param[in] friendlyPos enable or disable friendly positions51* @param[in] parameters generic parameters52*/53GNEDetector(const std::string& id, GNENet* net, const std::string& filename, SumoXMLTag tag,54const double pos, const SUMOTime period, GNELane* lane, const std::string& outputFilename,55const std::vector<std::string>& vehicleTypes, const std::vector<std::string>& nextEdges,56const std::string& detectPersons, const std::string& name, const bool friendlyPos,57const Parameterised::Map& parameters);5859/**@brief Constructor60* @param[in] id Gl-id of the detector (Must be unique)61* @param[in] net pointer to GNENet of this additional element belongs62* @param[in] filename file in which this AttributeCarrier is stored63* @param[in] tag Type of xml tag that define the detector (SUMO_TAG_INDUCTION_LOOP, SUMO_TAG_LANE_AREA_DETECTOR, etc...)64* @param[in] pos position of the detector on the lane65* @param[in] period the aggregation period the values the detector collects shall be summed up.66* @param[in] lanes vector of parent lanes67* @param[in] vehicleTypes space separated list of vehicle type ids to consider68* @param[in] nextEdges list of edge ids that must all be part of the future route of the vehicle to qualify for detection69* @param[in] detectPersons detect persons instead of vehicles (pedestrians or passengers)70* @param[in] outputFilename The path to the output file.71* @param[in] name detector name72* @param[in] friendlyPos enable or disable friendly positions73* @param[in] parameters generic parameters74*/75GNEDetector(const std::string& id, GNENet* net, const std::string& filename, SumoXMLTag tag, const double pos,76const SUMOTime period, const std::vector<GNELane*>& lanes, const std::string& outputFilename,77const std::vector<std::string>& vehicleTypes, const std::vector<std::string>& nextEdges,78const std::string& detectPersons, const std::string& name, const bool friendlyPos,79const Parameterised::Map& parameters);8081/**@brief Constructor82* @param[in] additionalParent parent additional of this detector (ID will be generated automatically)83* @param[in] tag Type of xml tag that define the detector (SUMO_TAG_INDUCTION_LOOP, SUMO_TAG_LANE_AREA_DETECTOR, etc...)84* @param[in] pos position of the detector on the lane85* @param[in] period the aggregation period the values the detector collects shall be summed up.86* @param[in] parentLanes vector of parent lanes87* @param[in] outputFilename The path to the output file.88* @param[in] name detector name89* @param[in] friendlyPos enable or disable friendly positions90* @param[in] parameters generic parameters91*/92GNEDetector(GNEAdditional* additionalParent, SumoXMLTag tag, const double pos, const SUMOTime period, GNELane* lane,93const std::string& outputFilename, const std::string& name, const bool friendlyPos, const Parameterised::Map& parameters);9495/// @brief Destructor96~GNEDetector();9798/**@brief get move operation99* @note returned GNEMoveOperation can be nullptr100*/101GNEMoveOperation* getMoveOperation();102103/// @name members and functions relative to write additionals into XML104/// @{105106/**@brief write additional element into a xml file107* @param[in] device device in which write parameters of additional element108*/109virtual void writeAdditional(OutputDevice& device) const = 0;110111/// @brief check if current additional is valid to be written into XML (must be reimplemented in all detector children)112virtual bool isAdditionalValid() const = 0;113114/// @brief return a string with the current additional problem (must be reimplemented in all detector children)115virtual std::string getAdditionalProblem() const = 0;116117/// @brief fix additional problem (must be reimplemented in all detector children)118virtual void fixAdditionalProblem() = 0;119120/// @}121122/// @name Function related with contour drawing123/// @{124125/// @brief check if draw move contour (red)126bool checkDrawMoveContour() const;127128/// @}129130/// @brief get lane131GNELane* getLane() const;132133/// @brief get position over lane134double getPositionOverLane() const;135136/// @brief get position over lane that is applicable to the shape137double getGeometryPositionOverLane() const;138139/// @name Functions related with geometry of element140/// @{141142/// @brief update pre-computed geometry information143virtual void updateGeometry() = 0;144145/// @brief Returns position of additional in view146Position getPositionInView() const;147148/// @brief update centering boundary (implies change in RTREE)149void updateCenteringBoundary(const bool updateGrid);150151/// @brief split geometry152void splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList);153154/// @}155156/// @name inherited from GUIGLObject157/// @{158159/**@brief Returns the name of the parent object160* @return This object's parent id161*/162std::string getParentName() const;163164/**@brief Draws the object165* @param[in] s The settings for the current view (may influence drawing)166* @see GUIGlObject::drawGL167*/168virtual void drawGL(const GUIVisualizationSettings& s) const = 0;169170/// @}171172/// @name inherited from GNEAttributeCarrier173/// @{174175/* @brief method for getting the Attribute of an XML key176* @param[in] key The attribute key177* @return string with the value associated to key178*/179virtual std::string getAttribute(SumoXMLAttr key) const = 0;180181/* @brief method for getting the Attribute of an XML key in double format (to avoid unnecessary parse<double>(...) for certain attributes)182* @param[in] key The attribute key183* @return double with the value associated to key184*/185virtual double getAttributeDouble(SumoXMLAttr key) const = 0;186187/// @brief get parameters map188const Parameterised::Map& getACParametersMap() const;189190/* @brief method for setting the attribute and letting the object perform additional changes191* @param[in] key The attribute key192* @param[in] value The new value193* @param[in] undoList The undoList on which to register changes194*/195virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;196197/* @brief method for checking if the key and their conrrespond attribute are valids198* @param[in] key The attribute key199* @param[in] value The value associated to key key200* @return true if the value is valid, false in other case201*/202virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;203204/// @brief get PopPup ID (Used in AC Hierarchy)205std::string getPopUpID() const;206207/// @brief get Hierarchy Name (Used in AC Hierarchy)208std::string getHierarchyName() const;209210/// @}211212protected:213/// @brief position of detector over Lane214double myPositionOverLane = 0;215216/// @brief The aggregation period the values the detector collects shall be summed up.217SUMOTime myPeriod = 0;218219/// @brief The path to the output file220std::string myOutputFilename;221222/// @brief attribute vehicle types223std::vector<std::string> myVehicleTypes;224225/// @brief next edges226std::vector<std::string> myNextEdges;227228/// @brief detect persons229std::string myDetectPersons;230231/// @brief Flag for friendly position232bool myFriendlyPosition = false;233234/* @brief method for getting the Attribute of an XML key235* @param[in] key The attribute key236* @return string with the value associated to key237*/238std::string getDetectorAttribute(SumoXMLAttr key) const;239240/* @brief method for getting the Attribute of an XML key in double format (to avoid unnecessary parse<double>(...) for certain attributes)241* @param[in] key The attribute key242* @return double with the value associated to key243*/244double getDetectorAttributeDouble(SumoXMLAttr key) const;245246/* @brief method for setting the attribute and letting the object perform additional changes247* @param[in] key The attribute key248* @param[in] value The new value249* @param[in] undoList The undoList on which to register changes250*/251void setDetectorAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList);252253/* @brief method for checking if the key and their conrrespond attribute are valids254* @param[in] key The attribute key255* @param[in] value The value associated to key key256* @return true if the value is valid, false in other case257*/258bool isDetectorValid(SumoXMLAttr key, const std::string& value);259260/**@brief write additional element into a xml file261* @param[in] device device in which write parameters of additional element262*/263void writeDetectorValues(OutputDevice& device) const;264265/// @brief set attribute after validation266void setDetectorAttribute(SumoXMLAttr key, const std::string& value);267268/// @brief draw E1 shape269void drawE1Shape(const GUIVisualizationSettings::Detail d, const double exaggeration,270const RGBColor& mainColor, const RGBColor& secondColor) const;271272/// @brief draw E1 detector Logo273void drawE1DetectorLogo(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,274const double exaggeration, const std::string& logo, const RGBColor& textColor) const;275276/// @brief draw E2 detector Logo277void drawE2DetectorLogo(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,278const double exaggeration, const std::string& logo, const RGBColor& textColor) const;279280private:281/// @brief set attribute after validation282virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;283284/// @brief set move shape285virtual void setMoveShape(const GNEMoveResult& moveResult) = 0;286287/// @brief commit move shape288virtual void commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) = 0;289290/// @brief Invalidate return position of additional291const Position& getPosition() const = delete;292293/// @brief Invalidate set new position in the view294void setPosition(const Position& pos) = delete;295};296297298