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