Skip to content

Commit

Permalink
check parking access rights ref #14482
Browse files Browse the repository at this point in the history
Signed-off-by: m-kro <m.barthauer@t-online.de>
  • Loading branch information
m-kro committed Apr 30, 2024
1 parent 344e851 commit 9c478e8
Show file tree
Hide file tree
Showing 29 changed files with 239 additions and 28 deletions.
1 change: 1 addition & 0 deletions data/xsd/additional_file.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@
<xsd:attribute name="name" type="xsd:string" use="optional"/>
<xsd:attribute name="departPos" type="floatType" use="optional"/>
<xsd:attribute name="lefthand" type="boolType" use="optional"/>
<xsd:attribute name="acceptedBadges" type="xsd:string" use="optional"/>
</xsd:complexType>

<xsd:complexType name="parkingSpaceType">
Expand Down
2 changes: 2 additions & 0 deletions data/xsd/routeTypes.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<xsd:attribute name="decel" type="positiveFloatType"/>
<xsd:attribute name="emergencyDecel" type="positiveFloatType"/>
<xsd:attribute name="apparentDecel" type="positiveFloatType"/>
<xsd:attribute name="parkingBadges" type="xsd:string"/>
<xsd:attribute name="personCapacity" type="xsd:nonNegativeInteger"/>
<xsd:attribute name="containerCapacity" type="xsd:nonNegativeInteger"/>
<xsd:attribute name="boardingDuration" type="nonNegativeFloatType"/>
Expand Down Expand Up @@ -483,6 +484,7 @@
<xsd:attribute name="containerNumber" type="xsd:nonNegativeInteger"/>
<xsd:attribute name="speedFactor" type="positiveFloatType"/>
<xsd:attribute name="insertionChecks" type="xsd:string"/>
<xsd:attribute name="parkingBadges" type="xsd:string"/>
</xsd:complexType>

<xsd:complexType name="flowWithoutIDType">
Expand Down
3 changes: 2 additions & 1 deletion src/guinetload/GUITriggerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ GUITriggerBuilder::buildStoppingPlace(MSNet& net, std::string id, std::vector<st
void
GUITriggerBuilder::beginParkingArea(MSNet& net, const std::string& id,
const std::vector<std::string>& lines,
const std::vector<std::string>& badges,
MSLane* lane,
double frompos, double topos,
unsigned int capacity,
Expand All @@ -90,7 +91,7 @@ GUITriggerBuilder::beginParkingArea(MSNet& net, const std::string& id,
const std::string& departPos,
bool lefthand) {
assert(myParkingArea == 0);
GUIParkingArea* stop = new GUIParkingArea(id, lines, *lane, frompos, topos, capacity, width, length, angle, name, onRoad, departPos, lefthand);
GUIParkingArea* stop = new GUIParkingArea(id, lines, badges, *lane, frompos, topos, capacity, width, length, angle, name, onRoad, departPos, lefthand);
if (!net.addStoppingPlace(SUMO_TAG_PARKING_AREA, stop)) {
delete stop;
throw InvalidArgument("Could not build parking area '" + id + "'; probably declared twice.");
Expand Down
5 changes: 3 additions & 2 deletions src/guinetload/GUITriggerBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class GUITriggerBuilder : public NLTriggerBuilder {
* @param[in] net The net the parking area belongs to
* @param[in] id The id of the parking area
* @param[in] lines Names of the lines that halt on this parking area
* @param[in] badges Names which grant access to this parking area
* @param[in] lane The lane the parking area is placed on
* @param[in] frompos Begin position of the parking area on the lane
* @param[in] topos End position of the parking area on the lane
Expand All @@ -129,8 +130,8 @@ class GUITriggerBuilder : public NLTriggerBuilder {
* @exception InvalidArgument If the parking area can not be added to the net (is duplicate)
*/
void beginParkingArea(MSNet& net, const std::string& id,
const std::vector<std::string>& lines, MSLane* lane,
double frompos, double topos,
const std::vector<std::string>& lines, const std::vector<std::string>& badges,
MSLane* lane, double frompos, double topos,
unsigned int capacity,
double width, double length, double angle, const std::string& name,
bool onRoad,
Expand Down
9 changes: 5 additions & 4 deletions src/guisim/GUIParkingArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
// ===========================================================================
// method definitions
// ===========================================================================
GUIParkingArea::GUIParkingArea(const std::string& id, const std::vector<std::string>& lines, MSLane& lane,
double frompos, double topos, unsigned int capacity,
double width, double length, double angle, const std::string& name,
GUIParkingArea::GUIParkingArea(const std::string& id, const std::vector<std::string>& lines,
const std::vector<std::string>& badges, MSLane& lane, double frompos, double topos,
unsigned int capacity, double width, double length, double angle, const std::string& name,
bool onRoad,
const std::string& departPos,
bool lefthand) :
MSParkingArea(id, lines, lane, frompos, topos, capacity, width, length, angle, name, onRoad, departPos, lefthand),
MSParkingArea(id, lines, badges, lane, frompos, topos, capacity, width, length, angle, name, onRoad, departPos, lefthand),
GUIGlObject_AbstractAdd(GLO_PARKING_AREA, id, GUIIconSubSys::getIcon(GUIIcon::PARKINGAREA)) {
const double offsetSign = MSGlobals::gLefthand ? -1 : 1;
myShapeRotations.reserve(myShape.size() - 1);
Expand Down Expand Up @@ -110,6 +110,7 @@ GUIParkingArea::getParameterWindow(GUIMainWindow& app,
ret->mkItem(TL("occupancy [#]"), true, getOccupancy());
ret->mkItem(TL("capacity [#]"), false, getCapacity());
ret->mkItem(TL("alternatives [#]"), false, getNumAlternatives());
ret->mkItem(TL("access badges"), false, joinToString(myAcceptedBadges, " "));
// close building
ret->closeBuilding();
return ret;
Expand Down
3 changes: 2 additions & 1 deletion src/guisim/GUIParkingArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class GUIParkingArea : public MSParkingArea, public GUIGlObject_AbstractAdd {
* @param[in] idStorage The gl-id storage for giving this object an gl-id
* @param[in] id The id of the parking area
* @param[in] lines Names of the parking lines that halt on this parking area
* @param[in] badges Names which grant access to this parking area
* @param[in] lane The lane the parking area is placed on
* @param[in] begPos Begin position of the parking area on the lane
* @param[in] endPos End position of the parking area on the lane
Expand All @@ -71,7 +72,7 @@ class GUIParkingArea : public MSParkingArea, public GUIGlObject_AbstractAdd {
* @param[in] angle Default angle of the lot rectangle relative to lane direction (if = 0 is computed ... TODO)
*/
GUIParkingArea(const std::string& id,
const std::vector<std::string>& lines, MSLane& lane,
const std::vector<std::string>& lines, const std::vector<std::string>& badges, MSLane& lane,
double frompos, double topos, unsigned int capacity,
double width, double length, double angle, const std::string& name,
bool onRoad,
Expand Down
3 changes: 2 additions & 1 deletion src/guisim/GUIVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ GUIVehicle::getParameterWindow(GUIMainWindow& app,
new FunctionBinding<GUIVehicle, int>(this, &MSVehicle::getContainerNumber));
ret->mkItem(TL("lcState right"), true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getLCStateRight));
ret->mkItem(TL("lcState left"), true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getLCStateLeft));
ret->mkItem(TL("parking badges"), false, joinToString(getParkingBadges(), " "));
// close building
if (MSGlobals::gLateralResolution > 0) {
ret->mkItem(TL("lcState center"), true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getLCStateCenter));
Expand Down Expand Up @@ -320,7 +321,7 @@ GUIVehicle::drawAction_drawCarriageClass(const GUIVisualizationSettings& s, bool
if (exaggeration == 0) {
return;
}
// bool reversed =
// bool reversed =
MSTrainHelper trainHelper(this, isReversed() && s.drawReversed, s.secondaryShape, exaggeration, s.vehicleQuality);
const int numCarriages = trainHelper.getNumCarriages();
const int firstPassengerCarriage = trainHelper.getFirstPassengerCarriage();
Expand Down
32 changes: 32 additions & 0 deletions src/microsim/MSBaseVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,15 @@ MSBaseVehicle::getCurrentParkingArea() {
}


const std::vector<std::string>&
MSBaseVehicle::getParkingBadges() const {
if (myParameter->wasSet(VEHPARS_PARKING_BADGES_SET)) {
return myParameter->parkingBadges;
} else {
return getVehicleType().getParkingBadges();
}
}


double
MSBaseVehicle::basePos(const MSEdge* edge) const {
Expand Down Expand Up @@ -1203,6 +1212,11 @@ MSBaseVehicle::addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& e
&& MSNet::getInstance()->warnOnce(stopType + ":" + stopID)) {
errorMsg = errorMsgStart + " on lane '" + stop.lane->getID() + "' is too short for vehicle '" + myParameter->id + "'.";
}
if (stopType == "parkingArea" && !stop.parkingarea->accepts(this)) {
// forbid access in case the parking requests other badges
errorMsg = errorMsgStart + "on lane '" + stop.lane->getID() + "' forbids access because vehicle '" + myParameter->id + "' does not provide any valid badge.";
return false;
}
const MSEdge* stopLaneEdge = &stop.lane->getEdge();
const MSEdge* stopEdge;
if (stopLaneEdge->getOppositeEdge() != nullptr && stopLaneEdge->getOppositeEdge()->getID() == stopPar.edge) {
Expand Down Expand Up @@ -1628,6 +1642,15 @@ MSBaseVehicle::replaceStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, c
std::advance(itStop, nextStopIndex);
MSStop& replacedStop = *itStop;

// check parking access rights
if (stop.parkingarea != "") {
MSParkingArea* pa = dynamic_cast<MSParkingArea*>(MSNet::getInstance()->getStoppingPlace(stop.parkingarea, SUMO_TAG_PARKING_AREA));
if (pa != nullptr && !pa->accepts(this)) {
errorMsg = "Vehicle '" + getID() + "' does not have the right badge to access parkingArea '" + stop.parkingarea + "'.";
return false;
}
}

if (replacedStop.lane == stopLane && replacedStop.pars.endPos == stop.endPos && !teleport) {
// only replace stop attributes
const_cast<SUMOVehicleParameter::Stop&>(replacedStop.pars) = stop;
Expand Down Expand Up @@ -1852,6 +1875,15 @@ MSBaseVehicle::insertStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, co
return false;
}

// check parking access rights
if (stop.parkingarea != "") {
MSParkingArea* pa = dynamic_cast<MSParkingArea*>(MSNet::getInstance()->getStoppingPlace(stop.parkingarea, SUMO_TAG_PARKING_AREA));
if (pa != nullptr && !pa->accepts(this)) {
errorMsg = "Vehicle '" + getID() + "' does not have the right badge to access parkingArea '" + stop.parkingarea + "'.";
return false;
}
}

const ConstMSEdgeVector& oldEdges = getRoute().getEdges();
std::vector<MSStop> stops(myStops.begin(), myStops.end());
const int junctionOffset = getLane() != nullptr && getLane()->isInternal() ? 1 : 0;
Expand Down
3 changes: 3 additions & 0 deletions src/microsim/MSBaseVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ class MSBaseVehicle : public SUMOVehicle {
/** @brief get the current parking area stop or nullptr */
MSParkingArea* getCurrentParkingArea();

/// @brief get the valid parking access rights (vehicle settings override vehicle type settings)
const std::vector<std::string>& getParkingBadges() const;

/// @brief departure position where the vehicle fits fully onto the edge (if possible)
double basePos(const MSEdge* edge) const;

Expand Down
36 changes: 35 additions & 1 deletion src/microsim/MSParkingArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <utils/geom/GeomHelper.h>
#include <microsim/MSEventControl.h>
#include <microsim/MSNet.h>
#include <microsim/MSVehicle.h>
#include <microsim/MSVehicleType.h>
#include "MSLane.h"
#include <microsim/transportables/MSTransportable.h>
Expand All @@ -43,7 +44,8 @@
// method definitions
// ===========================================================================
MSParkingArea::MSParkingArea(const std::string& id, const std::vector<std::string>& lines,
MSLane& lane, double begPos, double endPos, int capacity, double width, double length,
const std::vector<std::string>& badges, MSLane& lane,
double begPos, double endPos, int capacity, double width, double length,
double angle, const std::string& name, bool onRoad,
const std::string& departPos, bool lefthand) :
MSStoppingPlace(id, SUMO_TAG_PARKING_AREA, lines, lane, begPos, endPos, name),
Expand All @@ -53,6 +55,7 @@ MSParkingArea::MSParkingArea(const std::string& id, const std::vector<std::strin
myWidth(width),
myLength(length),
myAngle(lefthand ? -angle : angle),
myAcceptedBadges(badges.begin(), badges.end()),
myEgressBlocked(false),
myReservationTime(-1),
myReservations(0),
Expand Down Expand Up @@ -532,6 +535,37 @@ MSParkingArea::getLastStepOccupancy() const {
return myLastStepOccupancy;
}


void MSParkingArea::accept(std::string badge) {
myAcceptedBadges.insert(badge);
}


void MSParkingArea::accept(std::vector<std::string> badges) {
myAcceptedBadges.insert(badges.begin(), badges.end());
}


void MSParkingArea::refuse(std::string badge) {
myAcceptedBadges.erase(badge);
}


bool MSParkingArea::accepts(const MSBaseVehicle* veh) const {
if (myAcceptedBadges.size() == 0) {
return true;
} else {
std::vector<std::string> vehicleBadges = veh->getParkingBadges();
for (auto badge : vehicleBadges) {
if (myAcceptedBadges.count(badge) != 0) {
return true;
}
}
return false;
}
}


void
MSParkingArea::notifyEgressBlocked() {
computeLastFreePos();
Expand Down
23 changes: 21 additions & 2 deletions src/microsim/MSParkingArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/****************************************************************************/
/// @file MSParkingArea.h
/// @author Mirco Sturari
/// @author Mirko Barthauer
/// @date Tue, 19.01.2016
///
// A area where vehicles can park next to the road
Expand All @@ -36,6 +37,7 @@
class MSLane;
class SUMOVehicle;
class MSTransportable;
class MSBaseVehicle;
class Position;
class Command;

Expand Down Expand Up @@ -63,6 +65,7 @@ class MSParkingArea : public MSStoppingPlace {
* @param[in] id The id of the stop
* @param[in] net The net the stop belongs to
* @param[in] lines Names of the lines that halt on this stop
* @param[in] badges Names which grant access to this parking area
* @param[in] lane The lane the stop is placed on
* @param[in] begPos Begin position of the stop on the lane
* @param[in] endPos End position of the stop on the lane
Expand All @@ -72,7 +75,8 @@ class MSParkingArea : public MSStoppingPlace {
* @param[in] angle Angle of the default lot rectangle
*/
MSParkingArea(const std::string& id,
const std::vector<std::string>& lines, MSLane& lane,
const std::vector<std::string>& lines,
const std::vector<std::string>& badges, MSLane& lane,
double begPos, double endPos, int capacity,
double width, double length, double angle, const std::string& name,
bool onRoad,
Expand Down Expand Up @@ -105,6 +109,18 @@ class MSParkingArea : public MSStoppingPlace {
/// @brief Returns the area occupancy at the end of the last simulation step
int getLastStepOccupancy() const;

/// @brief Add a badge to the accepted set
void accept(std::string badge);

/// @brief Add badges to the accepted set
void accept(std::vector<std::string> badges);

/// @brief Remove the access right for the given badge
void refuse(std::string badge);

/// @brief Return the parking accepts the vehicle (due to its given badges)
bool accepts(const MSBaseVehicle* veh) const;

/** @brief Called if a vehicle enters this stop
*
* Stores the position of the entering vehicle in myEndPositions.
Expand Down Expand Up @@ -140,7 +156,7 @@ class MSParkingArea : public MSStoppingPlace {
double getLastFreePos(const SUMOVehicle& forVehicle, double brakePos = 0) const;

/** @brief Returns the last free position on this stop including
* reservatiosn from the current lane and time step
* reservations from the current lane and time step
*
* @return The last free position of this bus stop
*/
Expand Down Expand Up @@ -288,6 +304,9 @@ class MSParkingArea : public MSStoppingPlace {
/// @brief The roadside shape of this parkingArea
PositionVector myShape;

/// @brief The parking badges to grant access
std::set<std::string> myAcceptedBadges;

/// @brief whether a vehicle wants to exit but is blocked
bool myEgressBlocked;

Expand Down
7 changes: 7 additions & 0 deletions src/microsim/MSVehicleType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ MSVehicleType::setColor(const RGBColor& color) {
}


void
MSVehicleType::setParkingBadges(const std::vector<std::string>& badges) {
myParameter.parkingBadges.assign(badges.begin(), badges.end());
myParameter.parametersSet |= VTYPEPARS_PARKING_BADGES_SET;
}


void
MSVehicleType::setWidth(const double& width) {
if (myOriginalType != nullptr && width < 0) {
Expand Down
14 changes: 14 additions & 0 deletions src/microsim/MSVehicleType.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ class MSVehicleType {
}


/** @brief Returns the parking access rights of this type
* @return The parking access rights
*/
const std::vector<std::string>& getParkingBadges() const {
return myParameter.parkingBadges;
}


/** @brief Returns this type's speed factor
* @return The speed factor of this type
*/
Expand Down Expand Up @@ -516,6 +524,12 @@ class MSVehicleType {
void setColor(const RGBColor& color);


/** @brief Set a new value for parking access rights of this type
* @param[in] badges The new parking access rights of this type
*/
void setParkingBadges(const std::vector<std::string>& badges);


/** @brief Set a new value for this type's width
*
* If the given value<0 then the one from the original type will
Expand Down
10 changes: 10 additions & 0 deletions src/netedit/elements/GNEAttributeCarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,11 @@ GNEAttributeCarrier::fillAdditionalElements() {
TL("Name of parkingArea"));
myTagProperties[currentTag].addAttribute(attrProperty);

attrProperty = GNEAttributeProperties(SUMO_ATTR_ACCEPTED_BADGES,
GNEAttributeProperties::STRING | GNEAttributeProperties::LIST | GNEAttributeProperties::DEFAULTVALUE,
TL("Accepted badges to access this parkingArea"));
myTagProperties[currentTag].addAttribute(attrProperty);

attrProperty = GNEAttributeProperties(SUMO_ATTR_ROADSIDE_CAPACITY,
GNEAttributeProperties::INT | GNEAttributeProperties::POSITIVE | GNEAttributeProperties::DEFAULTVALUE,
TL(" The number of parking spaces for road-side parking"),
Expand Down Expand Up @@ -3597,6 +3602,11 @@ GNEAttributeCarrier::fillDemandElements() {
"1.5");
myTagProperties[currentTag].addAttribute(attrProperty);

attrProperty = GNEAttributeProperties(SUMO_ATTR_PARKING_BADGES,
GNEAttributeProperties::STRING | GNEAttributeProperties::LIST | GNEAttributeProperties::DEFAULTVALUE,
TL("The parking badges assigned to the vehicle"));
myTagProperties[currentTag].addAttribute(attrProperty);

attrProperty = GNEAttributeProperties(SUMO_ATTR_IMGFILE,
GNEAttributeProperties::STRING | GNEAttributeProperties::FILENAME | GNEAttributeProperties::DEFAULTVALUE | GNEAttributeProperties::EXTENDED,
TL("Image file for rendering vehicles of this type (should be grayscale to allow functional coloring)"));
Expand Down

0 comments on commit 9c478e8

Please sign in to comment.