Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2013-2024 German Aerospace Center (DLR) and others. 4 : // This program and the accompanying materials are made available under the 5 : // terms of the Eclipse Public License 2.0 which is available at 6 : // https://www.eclipse.org/legal/epl-2.0/ 7 : // This Source Code may also be made available under the following Secondary 8 : // Licenses when the conditions for such availability set forth in the Eclipse 9 : // Public License 2.0 are satisfied: GNU General Public License, version 2 10 : // or later which is available at 11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 13 : /****************************************************************************/ 14 : /// @file MSDevice_FCDReplay.h 15 : /// @author Michael Behrisch 16 : /// @date 01.03.2024 17 : /// 18 : // A device which replays recorded floating car data 19 : /****************************************************************************/ 20 : #pragma once 21 : #include <config.h> 22 : 23 : #include <utils/common/Command.h> 24 : #include <utils/xml/SUMOSAXHandler.h> 25 : #include "MSVehicleDevice.h" 26 : 27 : 28 : // =========================================================================== 29 : // class definitions 30 : // =========================================================================== 31 : /** 32 : * @class MSDevice_FCDReplay 33 : * @brief A device which replays a vehicle trajectory from an fcd file 34 : * 35 : * @see MSDevice 36 : */ 37 : class MSDevice_FCDReplay : public MSVehicleDevice { 38 : public: 39 : /** @brief Inserts MSDevice_FCDReplay-options 40 : * @param[filled] oc The options container to add the options to 41 : */ 42 : static void insertOptions(OptionsCont& oc); 43 : 44 : 45 : /** @brief Build devices for the given vehicle, if needed 46 : * 47 : * The options are read and evaluated whether a FCDReplay-device shall be built 48 : * for the given vehicle. 49 : * 50 : * The built device is stored in the given vector. 51 : * 52 : * @param[in] v The vehicle for which a device may be built 53 : * @param[filled] into The vector to store the built device in 54 : */ 55 : static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into); 56 : 57 : /** @brief Static intialization 58 : */ 59 : static void init(); 60 : 61 : public: 62 : /// @brief Destructor. 63 : ~MSDevice_FCDReplay(); 64 : 65 : bool move(); 66 : 67 : /// @brief return the name for this type of device 68 0 : const std::string deviceName() const { 69 0 : return "fcd-replay"; 70 : } 71 : 72 : typedef std::vector<std::tuple<Position, std::string, double, double, double> > Trajectory; 73 : 74 : void setTrajectory(Trajectory* const t) { 75 20 : myTrajectory = t; 76 : } 77 : 78 : private: 79 : /** @brief Constructor 80 : * 81 : * @param[in] holder The vehicle that holds this device 82 : * @param[in] id The ID of the device 83 : */ 84 : MSDevice_FCDReplay(SUMOVehicle& holder, const std::string& id); 85 : 86 8 : class MoveVehicles : public Command { 87 : public: 88 : SUMOTime execute(SUMOTime currentTime); 89 : private: 90 : /// @brief Invalidated assignment operator. 91 : MoveVehicles& operator=(const MoveVehicles&) = delete; 92 : }; 93 : 94 : class FCDHandler : public SUMOSAXHandler { 95 : public: 96 : void reset(); 97 : void addTrafficObjects(); 98 : 99 : protected: 100 : /// @name inherited from GenericSAXHandler 101 : //@{ 102 : 103 : /** @brief Called on the opening of a tag 104 : * 105 : * @param[in] element ID of the currently opened element 106 : * @param[in] attrs Attributes within the currently opened element 107 : * @exception ProcessError If something fails 108 : * @see GenericSAXHandler::myStartElement 109 : */ 110 : void myStartElement(int element, const SUMOSAXAttributes& attrs); 111 : //@} 112 : 113 : private: 114 : SUMOTime myTime; 115 : std::map<std::string, Trajectory> myTrajectories; 116 : std::map<std::string, std::tuple<SUMOTime, std::string, bool, ConstMSEdgeVector > > myRoutes; 117 : }; 118 : 119 : private: 120 : static FCDHandler myHandler; 121 : Trajectory* myTrajectory = nullptr; 122 : 123 : private: 124 : /// @brief Invalidated copy constructor. 125 : MSDevice_FCDReplay(const MSDevice_FCDReplay&) = delete; 126 : 127 : /// @brief Invalidated assignment operator. 128 : MSDevice_FCDReplay& operator=(const MSDevice_FCDReplay&) = delete; 129 : 130 : };