Skip to content

Commit

Permalink
added rerouter attr vTypes to netedit. refs #4031
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Jul 2, 2018
1 parent 3a71321 commit d5e4854
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/netedit/GNEAttributeCarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,10 @@ GNEAttributeCarrier::fillAttributeCarriers() {
ATTRPROPERTY_FLOAT | ATTRPROPERTY_POSITIVE | ATTRPROPERTY_TIME | ATTRPROPERTY_DEFAULTVALUE | ATTRPROPERTY_OPTIONAL,
"The waiting time threshold (in s) that must be reached to activate rerouting (default -1 which disables the threshold)",
"0.00");
myAllowedTags[currentTag].addAttribute(SUMO_ATTR_VTYPES,
ATTRPROPERTY_STRING | ATTRPROPERTY_DEFAULTVALUE | ATTRPROPERTY_OPTIONAL,
"The list of vehicle types that shall be affected by this rerouter (empty to affect all types)",
"");
myAllowedTags[currentTag].addAttribute(SUMO_ATTR_OFF,
ATTRPROPERTY_BOOL | ATTRPROPERTY_DEFAULTVALUE | ATTRPROPERTY_OPTIONAL,
"Whether the router should be inactive initially (and switched on in the gui)",
Expand Down
10 changes: 6 additions & 4 deletions src/netedit/additionals/GNEAdditionalHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ GNEAdditionalHandler::parseAndBuildRerouter(const SUMOSAXAttributes& attrs, cons
double probability = GNEAttributeCarrier::parseAttributeFromXML<double>(attrs, id, tag, SUMO_ATTR_PROB, abort);
bool off = GNEAttributeCarrier::parseAttributeFromXML<bool>(attrs, id, tag, SUMO_ATTR_OFF, abort);
double timeThreshold = attrs.getOpt<double>(SUMO_ATTR_HALTING_TIME_THRESHOLD, id.c_str(), abort, 0);
const std::string vTypes = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id.c_str(), abort, "");
Position pos = GNEAttributeCarrier::parseAttributeFromXML<Position>(attrs, id, tag, SUMO_ATTR_POSITION, abort);
// Continue if all parameters were sucesfully loaded
if (!abort) {
Expand All @@ -432,7 +433,7 @@ GNEAdditionalHandler::parseAndBuildRerouter(const SUMOSAXAttributes& attrs, cons
// check that all elements are valid
if (myViewNet->getNet()->retrieveAdditional(tag, id, false) != nullptr) {
WRITE_WARNING("There is another " + toString(tag) + " with the same ID='" + id + "'.");
} else if ((edgesIDs.size() > 0) && buildRerouter(myViewNet, myUndoAdditionals, id, pos, edges, probability, file, off, timeThreshold, false)) {
} else if ((edgesIDs.size() > 0) && buildRerouter(myViewNet, myUndoAdditionals, id, pos, edges, probability, file, off, timeThreshold, vTypes, false)) {
// save ID of last created element
myParentElements.back().second = id;
}
Expand Down Expand Up @@ -1264,11 +1265,12 @@ GNEAdditionalHandler::buildAdditional(GNEViewNet* viewNet, bool allowUndoRedo, S
bool off = GNEAttributeCarrier::parse<bool>(values[SUMO_ATTR_OFF]);
double prob = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_PROB]);
double timeThreshold = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_HALTING_TIME_THRESHOLD]);
const std::string vTypes = values[SUMO_ATTR_VTYPES];
bool blockMovement = GNEAttributeCarrier::parse<bool>(values[GNE_ATTR_BLOCK_MOVEMENT]);
std::string file = values[SUMO_ATTR_FILE];
// Build rerouter
if (pos.size() == 1) {
return buildRerouter(viewNet, allowUndoRedo, id, pos[0], edges, prob, file, off, timeThreshold, blockMovement);
return buildRerouter(viewNet, allowUndoRedo, id, pos[0], edges, prob, file, off, timeThreshold, vTypes, blockMovement);
} else {
return false;
}
Expand Down Expand Up @@ -1679,9 +1681,9 @@ GNEAdditionalHandler::buildCalibratorFlow(GNEViewNet* viewNet, bool allowUndoRed


bool
GNEAdditionalHandler::buildRerouter(GNEViewNet* viewNet, bool allowUndoRedo, const std::string& id, Position pos, const std::vector<GNEEdge*>& edges, double prob, const std::string& file, bool off, double timeThreshold, bool blockMovement) {
GNEAdditionalHandler::buildRerouter(GNEViewNet* viewNet, bool allowUndoRedo, const std::string& id, Position pos, const std::vector<GNEEdge*>& edges, double prob, const std::string& file, bool off, double timeThreshold, const std::string& vTypes, bool blockMovement) {
if (viewNet->getNet()->retrieveAdditional(SUMO_TAG_REROUTER, id, false) == nullptr) {
GNERerouter* rerouter = new GNERerouter(id, viewNet, pos, edges, file, prob, off, timeThreshold, blockMovement);
GNERerouter* rerouter = new GNERerouter(id, viewNet, pos, edges, file, prob, off, timeThreshold, vTypes, blockMovement);
if (allowUndoRedo) {
viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_REROUTER));
viewNet->getUndoList()->add(new GNEChange_Additional(rerouter, true), true);
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/additionals/GNEAdditionalHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ class GNEAdditionalHandler : public SUMOSAXHandler {
* @param[in] blockMovemet enable or disable block movement
* @return true if was sucesfully created, false in other case
*/
static bool buildRerouter(GNEViewNet* viewNet, bool allowUndoRedo, const std::string& id, Position pos, const std::vector<GNEEdge*>& edges, double prob, const std::string& file, bool off, double timeThreshold, bool blockMovement);
static bool buildRerouter(GNEViewNet* viewNet, bool allowUndoRedo, const std::string& id, Position pos, const std::vector<GNEEdge*>& edges, double prob, const std::string& file, bool off, double timeThreshold, const std::string& vTypes, bool blockMovement);

/**@brief builds a rerouter interval
* @param[in] viewNet viewNet in which element will be inserted
Expand Down
15 changes: 12 additions & 3 deletions src/netedit/additionals/GNERerouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@
// member method definitions
// ===========================================================================

GNERerouter::GNERerouter(const std::string& id, GNEViewNet* viewNet, const Position &pos, const std::vector<GNEEdge*> &edges, const std::string& filename, double probability, bool off, double timeThreshold, bool blockMovement) :
GNERerouter::GNERerouter(const std::string& id, GNEViewNet* viewNet, const Position &pos, const std::vector<GNEEdge*> &edges, const std::string& filename, double probability, bool off, double timeThreshold, const std::string& vTypes, bool blockMovement) :
GNEAdditional(id, viewNet, GLO_REROUTER, SUMO_TAG_REROUTER, true, blockMovement, edges),
myPosition(pos),
myFilename(filename),
myProbability(probability),
myOff(off),
myTimeThreshold(timeThreshold) {
}
myTimeThreshold(timeThreshold),
myVTypes(vTypes)
{ }


GNERerouter::~GNERerouter() {
Expand Down Expand Up @@ -264,6 +265,8 @@ GNERerouter::getAttribute(SumoXMLAttr key) const {
return toString(myProbability);
case SUMO_ATTR_HALTING_TIME_THRESHOLD:
return toString(myTimeThreshold);
case SUMO_ATTR_VTYPES:
return myVTypes;
case SUMO_ATTR_OFF:
return toString(myOff);
case GNE_ATTR_BLOCK_MOVEMENT:
Expand Down Expand Up @@ -296,6 +299,7 @@ GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList
case SUMO_ATTR_FILE:
case SUMO_ATTR_PROB:
case SUMO_ATTR_HALTING_TIME_THRESHOLD:
case SUMO_ATTR_VTYPES:
case SUMO_ATTR_OFF:
case GNE_ATTR_BLOCK_MOVEMENT:
case GNE_ATTR_SELECTED:
Expand Down Expand Up @@ -326,6 +330,8 @@ GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
case SUMO_ATTR_HALTING_TIME_THRESHOLD:
return canParse<double>(value) && (parse<double>(value) >= 0);
case SUMO_ATTR_VTYPES:
return true;
case SUMO_ATTR_OFF:
return canParse<bool>(value);
case GNE_ATTR_BLOCK_MOVEMENT:
Expand Down Expand Up @@ -369,6 +375,9 @@ GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
case SUMO_ATTR_HALTING_TIME_THRESHOLD:
myTimeThreshold = parse<double>(value);
break;
case SUMO_ATTR_VTYPES:
myVTypes = value;
break;
case SUMO_ATTR_OFF:
myOff = parse<bool>(value);
break;
Expand Down
5 changes: 4 additions & 1 deletion src/netedit/additionals/GNERerouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GNERerouter : public GNEAdditional {
* @param[in] block movement enable or disable additional movement
*/
GNERerouter(const std::string& id, GNEViewNet* viewNet, const Position &pos, const std::vector<GNEEdge*> &edges,
const std::string& filename, double probability, bool off, double timeThreshold, bool blockMovement);
const std::string& filename, double probability, bool off, double timeThreshold, const std::string& vTypes, bool blockMovement);

/// @brief Destructor
~GNERerouter();
Expand Down Expand Up @@ -144,6 +144,9 @@ class GNERerouter : public GNEAdditional {
/// @brief attribute to configure activation time threshold
double myTimeThreshold;

/// @brief optional vehicle types for restricting the rerouter
std::string myVTypes;

private:
/// @brief set attribute after validation
void setAttribute(SumoXMLAttr key, const std::string& value);
Expand Down

0 comments on commit d5e4854

Please sign in to comment.