Skip to content

Commit

Permalink
Added new netedit attributes GNE_ATTR_FLOW_TERMINATE and GNE_ATTR_FLO…
Browse files Browse the repository at this point in the history
…W_SPACING, used in flow inspector. Refs #15776
  • Loading branch information
palvarezlopez committed Nov 29, 2024
1 parent 3d95db7 commit 9207a86
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 12 deletions.
14 changes: 14 additions & 0 deletions src/netedit/elements/GNEAttributeCarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8439,6 +8439,20 @@ GNEAttributeCarrier::fillCommonFlowAttributes(SumoXMLTag currentTag, SumoXMLAttr
"0");
myTagProperties[currentTag].addAttribute(attrProperty);

attrProperty = GNEAttributeProperties(GNE_ATTR_FLOW_TERMINATE,
GNEAttributeProperties::STRING | GNEAttributeProperties::DISCRETE | GNEAttributeProperties::DEFAULTVALUE | GNEAttributeProperties::FLOW,
TL("Criterium for terminate flow"),
toString(SUMO_ATTR_END));
attrProperty.setDiscreteValues({toString(SUMO_ATTR_END), toString(SUMO_ATTR_NUMBER), toString(SUMO_ATTR_END) + "-" + toString(SUMO_ATTR_NUMBER)});
myTagProperties[currentTag].addAttribute(attrProperty);

attrProperty = GNEAttributeProperties(GNE_ATTR_FLOW_SPACING,
GNEAttributeProperties::STRING | GNEAttributeProperties::DISCRETE | GNEAttributeProperties::DEFAULTVALUE | GNEAttributeProperties::FLOW,
TL("Criterium for spacing flow"),
toString(perHour));
attrProperty.setDiscreteValues({toString(perHour), toString(SUMO_ATTR_PERIOD), toString(SUMO_ATTR_PROB), toString(GNE_ATTR_POISSON)});
myTagProperties[currentTag].addAttribute(attrProperty);

attrProperty = GNEAttributeProperties(SUMO_ATTR_END,
GNEAttributeProperties::SUMOTIME | GNEAttributeProperties::DEFAULTVALUE | GNEAttributeProperties::FLOW,
TL("End of departure interval"),
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/elements/demand/GNEContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ GNEContainer::getAttribute(SumoXMLAttr key) const {
case GNE_ATTR_PARAMETERS:
return getParametersStr();
default:
return getFlowAttribute(key);
return getFlowAttribute(this, key);
}
}

Expand Down
95 changes: 88 additions & 7 deletions src/netedit/elements/demand/GNEDemandElementFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,29 @@ GNEDemandElementFlow::writeFlowAttributes(const GNEDemandElement* flowElement, O
if (flowElement->getTagProperty().isFlow()) {
// write routeFlow values depending if it was set
if (isFlowAttributeEnabled(SUMO_ATTR_END)) {
device.writeAttr(SUMO_ATTR_END, getFlowAttribute(SUMO_ATTR_END));
device.writeAttr(SUMO_ATTR_END, getFlowAttribute(flowElement, SUMO_ATTR_END));
}
if (isFlowAttributeEnabled(SUMO_ATTR_NUMBER)) {
device.writeAttr(SUMO_ATTR_NUMBER, getFlowAttribute(SUMO_ATTR_NUMBER));
device.writeAttr(SUMO_ATTR_NUMBER, getFlowAttribute(flowElement, SUMO_ATTR_NUMBER));
}
if (isFlowAttributeEnabled(xph)) {
device.writeAttr(xph, getFlowAttribute(xph));
device.writeAttr(xph, getFlowAttribute(flowElement, xph));
}
if (isFlowAttributeEnabled(SUMO_ATTR_PERIOD)) {
device.writeAttr(SUMO_ATTR_PERIOD, getFlowAttribute(SUMO_ATTR_PERIOD));
device.writeAttr(SUMO_ATTR_PERIOD, getFlowAttribute(flowElement, SUMO_ATTR_PERIOD));
}
if (isFlowAttributeEnabled(GNE_ATTR_POISSON)) {
device.writeAttr(SUMO_ATTR_PERIOD, "exp(" + getFlowAttribute(GNE_ATTR_POISSON) + ")");
device.writeAttr(SUMO_ATTR_PERIOD, "exp(" + getFlowAttribute(flowElement, GNE_ATTR_POISSON) + ")");
}
if (isFlowAttributeEnabled(SUMO_ATTR_PROB)) {
device.writeAttr(SUMO_ATTR_PROB, getFlowAttribute(SUMO_ATTR_PROB));
device.writeAttr(SUMO_ATTR_PROB, getFlowAttribute(flowElement, SUMO_ATTR_PROB));
}
}
}


std::string
GNEDemandElementFlow::getFlowAttribute(SumoXMLAttr key) const {
GNEDemandElementFlow::getFlowAttribute(const GNEDemandElement* flowElement, SumoXMLAttr key) const {
switch (key) {
case SUMO_ATTR_DEPART:
case SUMO_ATTR_BEGIN:
Expand Down Expand Up @@ -136,6 +136,34 @@ GNEDemandElementFlow::getFlowAttribute(SumoXMLAttr key) const {
return adjustDecimalValue(repetitionProbability);
case SUMO_ATTR_NUMBER:
return toString(repetitionNumber);
case GNE_ATTR_FLOW_TERMINATE:
if (isFlowAttributeEnabled(SUMO_ATTR_END)) {
if (isFlowAttributeEnabled(SUMO_ATTR_NUMBER)) {
return toString(SUMO_ATTR_END) + "-" + toString(SUMO_ATTR_NUMBER);
} else {
return toString(SUMO_ATTR_END);
}
} else if (isFlowAttributeEnabled(SUMO_ATTR_NUMBER)) {
return toString(SUMO_ATTR_NUMBER);
} else {
return "invalid terminate";
}
case GNE_ATTR_FLOW_SPACING:
if (flowElement->getTagProperty().hasAttribute(SUMO_ATTR_VEHSPERHOUR) && isFlowAttributeEnabled(SUMO_ATTR_VEHSPERHOUR)) {
return toString(SUMO_ATTR_VEHSPERHOUR);
} else if (flowElement->getTagProperty().hasAttribute(SUMO_ATTR_PERSONSPERHOUR) && isFlowAttributeEnabled(SUMO_ATTR_PERSONSPERHOUR)) {
return toString(SUMO_ATTR_PERSONSPERHOUR);
} else if (flowElement->getTagProperty().hasAttribute(SUMO_ATTR_CONTAINERSPERHOUR) && isFlowAttributeEnabled(SUMO_ATTR_CONTAINERSPERHOUR)) {
return toString(SUMO_ATTR_CONTAINERSPERHOUR);
} else if (isFlowAttributeEnabled(SUMO_ATTR_PERIOD)) {
return toString(SUMO_ATTR_PERIOD);
} else if (isFlowAttributeEnabled(SUMO_ATTR_PROB)) {
return toString(SUMO_ATTR_PROB);
} else if (isFlowAttributeEnabled(GNE_ATTR_POISSON)) {
return toString(GNE_ATTR_POISSON);
} else {
return "invalid flow spacing";
}
default:
throw InvalidArgument("Flow doesn't have an attribute of type '" + toString(key) + "'");
}
Expand Down Expand Up @@ -167,6 +195,8 @@ GNEDemandElementFlow::setFlowAttribute(GNEDemandElement* flowElement, SumoXMLAtt
case SUMO_ATTR_PERIOD:
case GNE_ATTR_POISSON:
case SUMO_ATTR_PROB:
case GNE_ATTR_FLOW_TERMINATE:
case GNE_ATTR_FLOW_SPACING:
GNEChange_Attribute::changeAttribute(flowElement, key, value, undoList);
break;
default:
Expand Down Expand Up @@ -217,6 +247,15 @@ GNEDemandElementFlow::isValidFlowAttribute(GNEDemandElement* flowElement, SumoXM
} else {
return false;
}
case GNE_ATTR_FLOW_TERMINATE:
case GNE_ATTR_FLOW_SPACING: {
const auto& flowValues = flowElement->getTagProperty().getAttributeProperties(key).getDiscreteValues();
if (std::find(flowValues.begin(), flowValues.end(), value) != flowValues.end()) {
return true;
} else {
return false;
}
}
default:
throw InvalidArgument("Flow doesn't have an attribute of type '" + toString(key) + "'");
}
Expand Down Expand Up @@ -317,6 +356,48 @@ GNEDemandElementFlow::setFlowAttribute(const GNEDemandElement* flowElement, Sumo
case SUMO_ATTR_NUMBER:
repetitionNumber = GNEAttributeCarrier::parse<int>(value);
break;
case GNE_ATTR_FLOW_TERMINATE:
if (value == (toString(SUMO_ATTR_END) + "-" + toString(SUMO_ATTR_NUMBER))) {
toggleFlowAttribute(SUMO_ATTR_END, true);
toggleFlowAttribute(SUMO_ATTR_NUMBER, true);
// in this special case, disable other spacing
toggleFlowAttribute(SUMO_ATTR_VEHSPERHOUR, false);
toggleFlowAttribute(SUMO_ATTR_PERIOD, false);
toggleFlowAttribute(GNE_ATTR_POISSON, false);
toggleFlowAttribute(SUMO_ATTR_PROB, false);
} else if (value == toString(SUMO_ATTR_END)) {
toggleFlowAttribute(SUMO_ATTR_END, true);
toggleFlowAttribute(SUMO_ATTR_NUMBER, false);
} else if (value == toString(SUMO_ATTR_NUMBER)) {
toggleFlowAttribute(SUMO_ATTR_END, false);
toggleFlowAttribute(SUMO_ATTR_NUMBER, true);
}
break;
case GNE_ATTR_FLOW_SPACING:
if ((value == toString(SUMO_ATTR_VEHSPERHOUR)) ||
(value == toString(SUMO_ATTR_PERSONSPERHOUR)) ||
(value == toString(SUMO_ATTR_CONTAINERSPERHOUR))) {
toggleFlowAttribute(SUMO_ATTR_VEHSPERHOUR, true);
toggleFlowAttribute(SUMO_ATTR_PERIOD, false);
toggleFlowAttribute(GNE_ATTR_POISSON, false);
toggleFlowAttribute(SUMO_ATTR_PROB, false);
} else if (value == toString(SUMO_ATTR_PERIOD)) {
toggleFlowAttribute(SUMO_ATTR_VEHSPERHOUR, false);
toggleFlowAttribute(SUMO_ATTR_PERIOD, true);
toggleFlowAttribute(GNE_ATTR_POISSON, false);
toggleFlowAttribute(SUMO_ATTR_PROB, false);
} else if (value == toString(GNE_ATTR_POISSON)) {
toggleFlowAttribute(SUMO_ATTR_VEHSPERHOUR, false);
toggleFlowAttribute(SUMO_ATTR_PERIOD, false);
toggleFlowAttribute(GNE_ATTR_POISSON, true);
toggleFlowAttribute(SUMO_ATTR_PROB, false);
} else if (value == toString(SUMO_ATTR_PROB)) {
toggleFlowAttribute(SUMO_ATTR_VEHSPERHOUR, false);
toggleFlowAttribute(SUMO_ATTR_PERIOD, false);
toggleFlowAttribute(GNE_ATTR_POISSON, false);
toggleFlowAttribute(SUMO_ATTR_PROB, true);
}
break;
default:
throw InvalidArgument("Flow doesn't have an attribute of type '" + toString(key) + "'");
}
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/elements/demand/GNEDemandElementFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GNEDemandElementFlow : public SUMOVehicleParameter {
* @param[in] key The attribute key
* @return string with the value associated to key
*/
std::string getFlowAttribute(SumoXMLAttr key) const;
std::string getFlowAttribute(const GNEDemandElement* flowElement, SumoXMLAttr key) const;

/* @brief method for getting the Attribute of an XML key in double format (to avoid unnecessary parse<double>(...) for certain attributes)
* @param[in] key The attribute key
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/elements/demand/GNEPerson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ GNEPerson::getAttribute(SumoXMLAttr key) const {
case GNE_ATTR_PARAMETERS:
return getParametersStr();
default:
return getFlowAttribute(key);
return getFlowAttribute(this, key);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/netedit/elements/demand/GNEVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ GNEVehicle::getAttribute(SumoXMLAttr key) const {
case GNE_ATTR_FLOWPARAMETERS:
return toString(parametersSet);
default:
return getFlowAttribute(key);
return getFlowAttribute(this, key);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/utils/xml/SUMOXMLDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,8 @@ SequentialStringBijection::Entry SUMOXMLDefinitions::attrs[] = {
{ "fromLaneID", GNE_ATTR_FROM_LANEID },
{ "toLaneID", GNE_ATTR_TO_LANEID },
{ "tazCentroid", GNE_ATTR_TAZ_CENTROID },
{ "terminate", GNE_ATTR_FLOW_TERMINATE },
{ "spacing", GNE_ATTR_FLOW_SPACING },
// mapped to additional elements on writing
{ "fromBusStop", GNE_ATTR_FROM_BUSSTOP },
{ "fromTrainStop", GNE_ATTR_FROM_TRAINSTOP },
Expand Down
5 changes: 4 additions & 1 deletion src/utils/xml/SUMOXMLDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,10 @@ enum SumoXMLAttr {
GNE_ATTR_TO_LANEID,
/// @brief TAZ Center (uses to return the TAZ centroid if center is not defined)
GNE_ATTR_TAZ_CENTROID,

/// @brief flow terminating
GNE_ATTR_FLOW_TERMINATE,
/// @brief flow spacing
GNE_ATTR_FLOW_SPACING,
// virtual attributes for easier UI
GNE_ATTR_FROM_BUSSTOP,
GNE_ATTR_FROM_TRAINSTOP,
Expand Down

0 comments on commit 9207a86

Please sign in to comment.