Eclipse SUMO - Simulation of Urban MObility
NBParking.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-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 /****************************************************************************/
18 // The representation of an imported parking area
19 /****************************************************************************/
20 #include <config.h>
21 
25 #include "NBParking.h"
26 #include "NBEdge.h"
27 #include "NBEdgeCont.h"
28 
29 
30 // ===========================================================================
31 // method definitions
32 // ===========================================================================
33 NBParking::NBParking(const std::string& id, const std::string& edgeID, const std::string& name) :
34  Named(id),
35  myEdgeID(edgeID),
36  myName(name) {
37 }
38 
39 void
41  const NBEdge* e = ec.retrieve(myEdgeID);
42  if (e != nullptr) {
43  if ((e->getPermissions() & SVC_PASSENGER) == 0) {
44  WRITE_WARNINGF(TL("Ignoring parking area on edge '%' due to invalid permissions."), e->getID());
45  return;
46  }
47  // keep minimum distance of 5m to junction corners
48  const int cornerDistance = 5;
49  int capacity = (int)((e->getFinalLength() - 2 * cornerDistance) / 7.5);
50  if (capacity <= 0) {
51  WRITE_WARNINGF(TL("Ignoring parking area on edge '%' due to insufficient space."), e->getID());
52  return;
53  }
54  int lane = 0;
55  for (; lane < e->getNumLanes(); ++lane) {
56  if ((e->getPermissions(lane) & SVC_PASSENGER) != 0) {
57  break;
58  }
59  }
61  device.writeAttr(SUMO_ATTR_ID, getID());
62  device.writeAttr(SUMO_ATTR_LANE, e->getLaneID(lane));
63  device.writeAttr(SUMO_ATTR_STARTPOS, cornerDistance);
64  device.writeAttr(SUMO_ATTR_ENDPOS, -cornerDistance);
65  device.writeAttr(SUMO_ATTR_ROADSIDE_CAPACITY, capacity);
66  if (!myName.empty()) {
68  }
69  device.closeTag();
70  } else {
71  WRITE_WARNINGF(TL("Could not find edge for parkingArea '%'."), getID());
72  }
73  // XXX else: prevent edge merging via --geometry.remove
74 }
75 
76 
77 void
78 NBParkingCont::addEdges2Keep(const OptionsCont& oc, std::set<std::string>& into) {
79  if (oc.exists("parking-output") && oc.isSet("parking-output")) {
80  for (NBParking& p : *this) {
81  into.insert(p.getEdgeID());
82  }
83  }
84 }
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define TL(string)
Definition: MsgHandler.h:315
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_LANE
@ SUMO_ATTR_ENDPOS
@ SUMO_ATTR_NAME
@ SUMO_ATTR_ROADSIDE_CAPACITY
@ SUMO_ATTR_ID
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:59
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:281
The representation of a single edge during network building.
Definition: NBEdge.h:92
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:4308
const std::string & getID() const
Definition: NBEdge.h:1522
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:516
std::string getLaneID(int lane) const
get lane ID
Definition: NBEdge.cpp:3946
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:4644
void addEdges2Keep(const OptionsCont &oc, std::set< std::string > &into)
add edges that must be kept
Definition: NBParking.cpp:78
The representation of an imported parking area.
Definition: NBParking.h:42
void write(OutputDevice &device, NBEdgeCont &ec) const
Definition: NBParking.cpp:40
std::string myName
Definition: NBParking.h:60
const std::string getEdgeID() const
Definition: NBParking.h:54
NBParking(const std::string &id, const std::string &edgeID, const std::string &name="")
Constructor.
Definition: NBParking.cpp:33
std::string myEdgeID
Definition: NBParking.h:59
Base class for objects which have an id.
Definition: Named.h:54
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A storage for options typed value containers)
Definition: OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.