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.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // The representation of an imported parking area
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
33 #include "NBParking.h"
34 #include "NBEdge.h"
35 #include "NBEdgeCont.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 NBParking::NBParking(const std::string& id, const std::string& edgeID, const std::string& name) :
42  Named(id),
43  myEdgeID(edgeID),
44  myName(name) {
45 }
46 
47 void
49  const NBEdge* e = ec.retrieve(myEdgeID);
50  if (e != nullptr) {
51  if ((e->getPermissions() & SVC_PASSENGER) == 0) {
52  WRITE_WARNING("Ignoring parking area on edge '" + e->getID() + "' due to invalid permissions.");
53  return;
54  }
55  // keep minimum distance of 5m to junction corners
56  const int cornerDistance = 5;
57  int capacity = (int)((e->getFinalLength() - 2 * cornerDistance) / 7.5);
58  if (capacity <= 0) {
59  WRITE_WARNING("Ignoring parking area on edge '" + e->getID() + "' due to insufficient space.");
60  return;
61  }
62  int lane = 0;
63  for (; lane < e->getNumLanes(); ++lane) {
64  if ((e->getPermissions(lane) & SVC_PASSENGER) != 0) {
65  break;
66  }
67  }
69  device.writeAttr(SUMO_ATTR_ID, getID());
70  device.writeAttr(SUMO_ATTR_LANE, e->getLaneID(lane));
71  device.writeAttr(SUMO_ATTR_STARTPOS, cornerDistance);
72  device.writeAttr(SUMO_ATTR_ENDPOS, -cornerDistance);
73  device.writeAttr(SUMO_ATTR_ROADSIDE_CAPACITY, capacity);
74  if (!myName.empty()) {
76  }
77  device.closeTag();
78  } else {
79  std::cout << "could not find edge for parkingArea '" << getID() << "'\n";
80  }
81  // XXX else: prevent edge merging via --geometry.remove
82 }
83 
84 
85 void
86 NBParkingCont::addEdges2Keep(const OptionsCont& oc, std::set<std::string>& into) {
87  if (oc.isSet("parking-output")) {
88  for (NBParking& p : *this) {
89  into.insert(p.getID());
90  }
91  }
92 }
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
void addEdges2Keep(const OptionsCont &oc, std::set< std::string > &into)
add edges that must be kept
Definition: NBParking.cpp:86
The representation of a single edge during network building.
Definition: NBEdge.h:70
const std::string & getID() const
Returns the id.
Definition: Named.h:65
void write(OutputDevice &device, NBEdgeCont &ec) const
Definition: NBParking.cpp:48
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
The representation of a single pt stop.
Definition: NBParking.h:50
std::string getLaneID(int lane) const
get Lane ID (Secure)
Definition: NBEdge.cpp:2783
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:412
std::string myName
Definition: NBParking.h:65
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:3025
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:3269
vehicle is a passenger car (a "normal" car)
Base class for objects which have an id.
Definition: Named.h:45
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:250
A storage for options typed value containers)
Definition: OptionsCont.h:98
std::string myEdgeID
Definition: NBParking.h:64
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
NBParking(const std::string &id, const std::string &edgeID, const std::string &name="")
Constructor.
Definition: NBParking.cpp:41
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.