Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2017-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 BusStop.cpp 15 : /// @author Jakob Erdmann 16 : /// @date 16.03.2020 17 : /// 18 : // C++ TraCI client API implementation 19 : /****************************************************************************/ 20 : #include <config.h> 21 : 22 : #include <microsim/MSNet.h> 23 : #include <microsim/MSLane.h> 24 : #include <microsim/MSStoppingPlace.h> 25 : #include <microsim/transportables/MSTransportable.h> 26 : #include <libsumo/TraCIConstants.h> 27 : #include "Helper.h" 28 : #include "BusStop.h" 29 : 30 : 31 : namespace libsumo { 32 : // =========================================================================== 33 : // static member initializations 34 : // =========================================================================== 35 : SubscriptionResults BusStop::mySubscriptionResults; 36 : ContextSubscriptionResults BusStop::myContextSubscriptionResults; 37 : 38 : 39 : // =========================================================================== 40 : // static member definitions 41 : // =========================================================================== 42 : std::vector<std::string> 43 286 : BusStop::getIDList() { 44 : std::vector<std::string> ids; 45 804 : for (auto& item : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_BUS_STOP)) { 46 518 : ids.push_back(item.first); 47 : } 48 284 : std::sort(ids.begin(), ids.end()); 49 284 : return ids; 50 2 : } 51 : 52 : int 53 12 : BusStop::getIDCount() { 54 12 : return (int)getIDList().size(); 55 : } 56 : 57 : 58 : std::string 59 12 : BusStop::getLaneID(const std::string& stopID) { 60 12 : return getBusStop(stopID)->getLane().getID(); 61 : } 62 : 63 : double 64 12 : BusStop::getStartPos(const std::string& stopID) { 65 12 : return getBusStop(stopID)->getBeginLanePosition(); 66 : } 67 : 68 : double 69 12 : BusStop::getEndPos(const std::string& stopID) { 70 12 : return getBusStop(stopID)->getEndLanePosition(); 71 : } 72 : 73 : std::string 74 12 : BusStop::getName(const std::string& stopID) { 75 12 : return getBusStop(stopID)->getMyName(); 76 : } 77 : 78 : int 79 120 : BusStop::getVehicleCount(const std::string& stopID) { 80 120 : return (int)getBusStop(stopID)->getStoppedVehicles().size(); 81 : } 82 : 83 : std::vector<std::string> 84 120 : BusStop::getVehicleIDs(const std::string& stopID) { 85 : std::vector<std::string> result; 86 145 : for (const SUMOVehicle* veh : getBusStop(stopID)->getStoppedVehicles()) { 87 25 : result.push_back(veh->getID()); 88 : } 89 120 : return result; 90 0 : } 91 : 92 : int 93 122 : BusStop::getPersonCount(const std::string& stopID) { 94 122 : return (int)getBusStop(stopID)->getNumWaitingPersons(); 95 : } 96 : 97 : std::vector<std::string> 98 244 : BusStop::getPersonIDs(const std::string& stopID) { 99 : std::vector<std::string> result; 100 122 : getBusStop(stopID)->getWaitingPersonIDs(result); 101 122 : return result; 102 0 : } 103 : 104 : 105 : std::string 106 0 : BusStop::getParameter(const std::string& stopID, const std::string& param) { 107 0 : return getBusStop(stopID)->getParameter(param, ""); 108 : } 109 : 110 0 : LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(BusStop) 111 : 112 : void 113 0 : BusStop::setParameter(const std::string& stopID, const std::string& key, const std::string& value) { 114 0 : getBusStop(stopID)->setParameter(key, value); 115 0 : } 116 : 117 : 118 152 : LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(BusStop, BUSSTOP) 119 : 120 : 121 : MSStoppingPlace* 122 532 : BusStop::getBusStop(const std::string& id) { 123 532 : return Helper::getStoppingPlace(id, SUMO_TAG_BUS_STOP); 124 : } 125 : 126 : 127 : std::shared_ptr<VariableWrapper> 128 267 : BusStop::makeWrapper() { 129 267 : return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults); 130 : } 131 : 132 : 133 : bool 134 538 : BusStop::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) { 135 538 : switch (variable) { 136 174 : case TRACI_ID_LIST: 137 174 : return wrapper->wrapStringList(objID, variable, getIDList()); 138 8 : case ID_COUNT: 139 8 : return wrapper->wrapInt(objID, variable, getIDCount()); 140 8 : case VAR_LANE_ID: 141 16 : return wrapper->wrapString(objID, variable, getLaneID(objID)); 142 8 : case VAR_POSITION: 143 8 : return wrapper->wrapDouble(objID, variable, getStartPos(objID)); 144 8 : case VAR_LANEPOSITION: 145 8 : return wrapper->wrapDouble(objID, variable, getEndPos(objID)); 146 8 : case VAR_NAME: 147 16 : return wrapper->wrapString(objID, variable, getName(objID)); 148 80 : case VAR_STOP_STARTING_VEHICLES_NUMBER: 149 80 : return wrapper->wrapInt(objID, variable, getVehicleCount(objID)); 150 80 : case VAR_STOP_STARTING_VEHICLES_IDS: 151 80 : return wrapper->wrapStringList(objID, variable, getVehicleIDs(objID)); 152 82 : case VAR_BUS_STOP_WAITING: 153 82 : return wrapper->wrapInt(objID, variable, getPersonCount(objID)); 154 82 : case VAR_BUS_STOP_WAITING_IDS: 155 82 : return wrapper->wrapStringList(objID, variable, getPersonIDs(objID)); 156 0 : case libsumo::VAR_PARAMETER: 157 0 : paramData->readUnsignedByte(); 158 0 : return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString())); 159 0 : case libsumo::VAR_PARAMETER_WITH_KEY: 160 0 : paramData->readUnsignedByte(); 161 0 : return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString())); 162 : default: 163 : return false; 164 : } 165 : } 166 : 167 : 168 : } 169 : 170 : 171 : /****************************************************************************/