Skip to content

Commit

Permalink
Added function checkOverwritteElement. Refs #16027
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Jan 23, 2025
1 parent ca07eb1 commit a22aa75
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
50 changes: 47 additions & 3 deletions src/netedit/elements/demand/GNERouteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ bool
GNERouteHandler::buildRoute(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& id, SUMOVehicleClass vClass,
const std::vector<std::string>& edgeIDs, const RGBColor& color, const int repeat, const SUMOTime cycleTime,
const double probability, const Parameterised::Map& routeParameters) {
// first check if we have to overwritte element
checkOverwritteElement({SUMO_TAG_ROUTE}, id);
// check conditions
if (!checkValidDemandElementID(SUMO_TAG_ROUTE, id)) {
return false;
Expand Down Expand Up @@ -259,6 +261,8 @@ GNERouteHandler::buildRouteDistribution(const CommonXMLStructure::SumoBaseObject

bool
GNERouteHandler::buildVehicleOverRoute(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const SUMOVehicleParameter& vehicleParameters) {
// first check if we have to overwritte element
checkOverwritteElement(myVehicleTags, vehicleParameters.id);
// first check if ID is duplicated
if (!checkValidDemandElementID(SUMO_TAG_VEHICLE, vehicleParameters.id)) {
return false;
Expand Down Expand Up @@ -300,6 +304,8 @@ bool
GNERouteHandler::buildVehicleEmbeddedRoute(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const SUMOVehicleParameter& vehicleParameters,
const std::vector<std::string>& edgeIDs, const RGBColor& color, const int repeat, const SUMOTime cycleTime,
const double probability, const Parameterised::Map& routeParameters) {
// first check if we have to overwritte element
checkOverwritteElement(myVehicleTags, vehicleParameters.id);
// check if ID is duplicated
if (!checkValidDemandElementID(GNE_TAG_VEHICLE_WITHROUTE, vehicleParameters.id)) {
return false;
Expand Down Expand Up @@ -349,6 +355,8 @@ GNERouteHandler::buildVehicleEmbeddedRoute(const CommonXMLStructure::SumoBaseObj

bool
GNERouteHandler::buildFlowOverRoute(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const SUMOVehicleParameter& vehicleParameters) {
// first check if we have to overwritte element
checkOverwritteElement(myVehicleTags, vehicleParameters.id);
// first check if ID is duplicated
if (!checkValidDemandElementID(GNE_TAG_FLOW_ROUTE, vehicleParameters.id)) {
return false;
Expand Down Expand Up @@ -390,6 +398,8 @@ bool
GNERouteHandler::buildFlowEmbeddedRoute(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const SUMOVehicleParameter& vehicleParameters,
const std::vector<std::string>& edgeIDs, const RGBColor& color, const int repeat, const SUMOTime cycleTime,
const double probability, const Parameterised::Map& routeParameters) {
// first check if we have to overwritte element
checkOverwritteElement(myVehicleTags, vehicleParameters.id);
// check if ID is duplicated
if (!checkValidDemandElementID(GNE_TAG_FLOW_WITHROUTE, vehicleParameters.id)) {
return false;
Expand Down Expand Up @@ -440,7 +450,8 @@ GNERouteHandler::buildFlowEmbeddedRoute(const CommonXMLStructure::SumoBaseObject
bool
GNERouteHandler::buildTrip(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const SUMOVehicleParameter& vehicleParameters,
const std::string& fromEdgeID, const std::string& toEdgeID) {

// first check if we have to overwritte element
checkOverwritteElement(myVehicleTags, vehicleParameters.id);
// set via attribute
if (sumoBaseObject && sumoBaseObject->hasStringListAttribute(SUMO_ATTR_VIA)) {
vehicleParameters.via = sumoBaseObject->getStringListAttribute(SUMO_ATTR_VIA);
Expand Down Expand Up @@ -493,7 +504,8 @@ GNERouteHandler::buildTrip(const CommonXMLStructure::SumoBaseObject* sumoBaseObj
bool
GNERouteHandler::buildTripJunctions(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const SUMOVehicleParameter& vehicleParameters,
const std::string& fromJunctionID, const std::string& toJunctionID) {

// first check if we have to overwritte element
checkOverwritteElement(myVehicleTags, vehicleParameters.id);
// check if exist another vehicle with the same ID (note: Vehicles, Flows and Trips share namespace)
if (!checkValidDemandElementID(GNE_TAG_TRIP_JUNCTIONS, vehicleParameters.id)) {
return false;
Expand Down Expand Up @@ -540,6 +552,8 @@ GNERouteHandler::buildTripJunctions(const CommonXMLStructure::SumoBaseObject* /*
bool
GNERouteHandler::buildTripTAZs(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const SUMOVehicleParameter& vehicleParameters,
const std::string& fromTAZID, const std::string& toTAZID) {
// first check if we have to overwritte element
checkOverwritteElement(myVehicleTags, vehicleParameters.id);
// check if exist another vehicle with the same ID (note: Vehicles, Flows and Trips share namespace)
if (!checkValidDemandElementID(GNE_TAG_TRIP_TAZS, vehicleParameters.id)) {
return false;
Expand Down Expand Up @@ -586,7 +600,8 @@ GNERouteHandler::buildTripTAZs(const CommonXMLStructure::SumoBaseObject* /*sumoB
bool
GNERouteHandler::buildFlow(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const SUMOVehicleParameter& vehicleParameters,
const std::string& fromEdgeID, const std::string& toEdgeID) {

// first check if we have to overwritte element
checkOverwritteElement(myVehicleTags, vehicleParameters.id);
// set via attribute
if (sumoBaseObject && sumoBaseObject->hasStringListAttribute(SUMO_ATTR_VIA)) {
vehicleParameters.via = sumoBaseObject->getStringListAttribute(SUMO_ATTR_VIA);
Expand Down Expand Up @@ -639,6 +654,8 @@ GNERouteHandler::buildFlow(const CommonXMLStructure::SumoBaseObject* sumoBaseObj
bool
GNERouteHandler::buildFlowJunctions(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const SUMOVehicleParameter& vehicleParameters,
const std::string& fromJunctionID, const std::string& toJunctionID) {
// first check if we have to overwritte element
checkOverwritteElement(myVehicleTags, vehicleParameters.id);
// check if exist another vehicle with the same ID (note: Vehicles, Flows and Trips share namespace)
if (!checkValidDemandElementID(GNE_TAG_FLOW_JUNCTIONS, vehicleParameters.id)) {
return false;
Expand Down Expand Up @@ -685,6 +702,8 @@ GNERouteHandler::buildFlowJunctions(const CommonXMLStructure::SumoBaseObject* /*
bool
GNERouteHandler::buildFlowTAZs(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const SUMOVehicleParameter& vehicleParameters,
const std::string& fromTAZID, const std::string& toTAZID) {
// first check if we have to overwritte element
checkOverwritteElement(myVehicleTags, vehicleParameters.id);
// check if exist another vehicle with the same ID (note: Vehicles, Flows and Trips share namespace)
if (!checkValidDemandElementID(GNE_TAG_FLOW_TAZS, vehicleParameters.id)) {
return false;
Expand Down Expand Up @@ -730,6 +749,8 @@ GNERouteHandler::buildFlowTAZs(const CommonXMLStructure::SumoBaseObject* /*sumoB

bool
GNERouteHandler::buildPerson(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const SUMOVehicleParameter& personParameters) {
// first check if we have to overwritte element
checkOverwritteElement(myPersonTags, personParameters.id);
// first check if ID is duplicated
if (!checkValidDemandElementID(SUMO_TAG_PERSON, personParameters.id)) {
return false;
Expand Down Expand Up @@ -763,6 +784,8 @@ GNERouteHandler::buildPerson(const CommonXMLStructure::SumoBaseObject* /*sumoBas

bool
GNERouteHandler::buildPersonFlow(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const SUMOVehicleParameter& personFlowParameters) {
// first check if we have to overwritte element
checkOverwritteElement(myPersonTags, personFlowParameters.id);
// first check if ID is duplicated
if (!checkValidDemandElementID(SUMO_TAG_PERSONFLOW, personFlowParameters.id)) {
return false;
Expand Down Expand Up @@ -904,6 +927,8 @@ GNERouteHandler::buildRide(const CommonXMLStructure::SumoBaseObject* sumoBaseObj

bool
GNERouteHandler::buildContainer(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const SUMOVehicleParameter& containerParameters) {
// first check if we have to overwritte element
checkOverwritteElement(myPersonTags, containerParameters.id);
// first check if ID is duplicated
if (!checkValidDemandElementID(SUMO_TAG_CONTAINER, containerParameters.id)) {
return false;
Expand Down Expand Up @@ -937,6 +962,8 @@ GNERouteHandler::buildContainer(const CommonXMLStructure::SumoBaseObject* /*sumo

bool
GNERouteHandler::buildContainerFlow(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const SUMOVehicleParameter& containerFlowParameters) {
// first check if we have to overwritte element
checkOverwritteElement(myPersonTags, containerFlowParameters.id);
// first check if ID is duplicated
if (!checkValidDemandElementID(SUMO_TAG_CONTAINERFLOW, containerFlowParameters.id)) {
return false;
Expand Down Expand Up @@ -2618,4 +2645,21 @@ GNERouteHandler::checkDuplicatedDemandElement(const SumoXMLTag tag, const std::v
return true;
}


void
GNERouteHandler::checkOverwritteElement(const std::vector<SumoXMLTag> &tags, const std::string &id) {
if (myOverwrite) {
// retrieve demand element and remove it
for (const auto &tag : tags) {
auto demandElement = myNet->getAttributeCarriers()->retrieveDemandElement(tag, id, false);
if (demandElement) {
writeWarningOverwritting(tag, id);
myNet->getViewNet()->getUndoList()->begin(demandElement, TL("delete ") + demandElement->getTagStr() + " '" + id + "'");
myNet->getViewNet()->getUndoList()->add(new GNEChange_DemandElement(demandElement, false), true);
myNet->getViewNet()->getUndoList()->end();
}
}
}
}

/****************************************************************************/
3 changes: 3 additions & 0 deletions src/netedit/elements/demand/GNERouteHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ class GNERouteHandler : public RouteHandler {
/// @brief check if given ID correspond to a duplicated demand element
bool checkDuplicatedDemandElement(const SumoXMLTag tag, const std::vector<SumoXMLTag> tags, const std::string& id);

/// @brief check if
void checkOverwritteElement(const std::vector<SumoXMLTag> &tags, const std::string &id);

private:
/// @brief pointer to GNENet
GNENet* myNet;
Expand Down
6 changes: 3 additions & 3 deletions src/netedit/elements/network/GNEEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,7 @@ GNEEdge::getVehiclesOverEdgeMap() const {
vehicles.insert(std::make_pair(routeChild->getAttributeDouble(SUMO_ATTR_DEPART), routeChild));
}
}
} else if ((edgeChild->getTagProperty().getTag() == GNE_TAG_ROUTE_EMBEDDED) && (edgeChild->getParentEdges().front() == this)) {
} else if ((edgeChild->getTagProperty().getTag() == GNE_TAG_ROUTE_EMBEDDED) && (edgeChild->getParentEdges().front() == this) && (edgeChild->getParentDemandElements().size() > 0)) {
vehicles.insert(std::make_pair(edgeChild->getParentDemandElements().front()->getAttributeDouble(SUMO_ATTR_DEPART), edgeChild->getParentDemandElements().front()));
}
}
Expand Down Expand Up @@ -2542,7 +2542,7 @@ GNEEdge::getPersonsOverEdgeMap() const {
std::set<std::pair<double, GNEDemandElement*> > persons;
// first obtain all persons of this edge
for (const auto& edgeChild : getChildDemandElements()) {
if (edgeChild->getTagProperty().isPlanPerson()) {
if (edgeChild->getTagProperty().isPlanPerson() && (edgeChild->getParentDemandElements().size() > 0)) {
persons.insert(std::make_pair(edgeChild->getParentDemandElements().front()->getAttributeDouble(SUMO_ATTR_DEPARTPOS), edgeChild->getParentDemandElements().front()));
}
}
Expand Down Expand Up @@ -2575,7 +2575,7 @@ GNEEdge::getContainersOverEdgeMap() const {
std::set<std::pair<double, GNEDemandElement*> > containers;
// first obtain all containers of this edge
for (const auto& edgeChild : getChildDemandElements()) {
if (edgeChild->getTagProperty().isPlanContainer()) {
if (edgeChild->getTagProperty().isPlanContainer() && (edgeChild->getParentDemandElements().size() > 0)) {
containers.insert(std::make_pair(edgeChild->getParentDemandElements().front()->getAttributeDouble(SUMO_ATTR_DEPARTPOS), edgeChild->getParentDemandElements().front()));
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/handlers/CommonHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ CommonHandler::checkValidDemandElementID(const SumoXMLTag tag, const std::string
}


void
CommonHandler::writeWarningOverwritting(const SumoXMLTag tag, const std::string& id) {
WRITE_WARNING(TLF("Overwritting % with ID '%'", toString(tag), id));
}


bool
CommonHandler::writeError(const std::string& error) {
WRITE_ERROR(error);
Expand Down
5 changes: 4 additions & 1 deletion src/utils/handlers/CommonHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ class CommonHandler {

/// @}

/// @brief write warning overwritting element
void writeWarningOverwritting(const SumoXMLTag tag, const std::string& id);

/// @brief write error and enable error creating element
bool writeError(const std::string& error);

/// @brief write error "invalid position"
bool writeErrorInvalidPosition(const SumoXMLTag tag, const std::string& id);

/// @brief write error "duplicated additional"
/// @brief write error duplicated element
bool writeErrorDuplicated(const SumoXMLTag tag, const std::string& id, const SumoXMLTag checkedTag);

/// @brief write error "empty edges"
Expand Down

0 comments on commit a22aa75

Please sign in to comment.