Skip to content

Commit

Permalink
Updated GNENetHelper::AttributeCarriers. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent c2007a9 commit c3adae6
Show file tree
Hide file tree
Showing 19 changed files with 272 additions and 270 deletions.
90 changes: 45 additions & 45 deletions src/netedit/GNENet.cpp

Large diffs are not rendered by default.

184 changes: 93 additions & 91 deletions src/netedit/GNENetHelper.cpp

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/netedit/GNENetHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ struct GNENetHelper {
GNEAdditional* retrieveRerouterInterval(const std::string& rerouterID, const SUMOTime begin, const SUMOTime end) const;

/// @brief get additionals
const std::map<SumoXMLTag, std::set<GNEAdditional*> >& getAdditionals() const;
const std::map<SumoXMLTag, std::map<const GUIGlObject*, GNEAdditional*> >& getAdditionals() const;

/// @brief get selected additionals
std::vector<GNEAdditional*> getSelectedAdditionals() const;
Expand Down Expand Up @@ -448,7 +448,7 @@ struct GNENetHelper {
std::vector<GNEDemandElement*> getSelectedDemandElements() const;

/// @brief get demand elements
const std::map<SumoXMLTag, std::set<GNEDemandElement*> >& getDemandElements() const;
const std::map<SumoXMLTag, std::map<const GUIGlObject*, GNEDemandElement*> >& getDemandElements() const;

/// @brief Return the number of demand elements
int getNumberOfDemandElements() const;
Expand Down Expand Up @@ -757,10 +757,10 @@ struct GNENetHelper {
std::set<GNEConnection*> myConnections;

/// @brief map with the tag and pointer to additional elements of net
std::map<SumoXMLTag, std::set<GNEAdditional*> > myAdditionals;
std::map<SumoXMLTag, std::map<const GUIGlObject*, GNEAdditional*> > myAdditionals;

/// @brief map with the tag and pointer to demand elements of net
std::map<SumoXMLTag, std::set<GNEDemandElement*> > myDemandElements;
std::map<SumoXMLTag, std::map<const GUIGlObject*, GNEDemandElement*> > myDemandElements;

/// @brief set with the ID and pointer to all datasets of net
std::set<GNEDataSet*> myDataSets;
Expand Down
24 changes: 12 additions & 12 deletions src/netedit/GNEViewNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4038,27 +4038,27 @@ GNEViewNet::onCmdToggleDrawSpreadVehicles(FXObject*, FXSelector sel, void*) {
std::set<GNEEdge*> edgesToUpdate;
// compute vehicle geometry
for (const auto& vehicle : myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VEHICLE)) {
if (vehicle->getParentEdges().size() > 0) {
edgesToUpdate.insert(vehicle->getParentEdges().front());
} else if (vehicle->getChildDemandElements().size() > 0 && (vehicle->getChildDemandElements().front()->getTagProperty().getTag() == GNE_TAG_ROUTE_EMBEDDED)) {
edgesToUpdate.insert(vehicle->getChildDemandElements().front()->getParentEdges().front());
if (vehicle.second->getParentEdges().size() > 0) {
edgesToUpdate.insert(vehicle.second->getParentEdges().front());
} else if (vehicle.second->getChildDemandElements().size() > 0 && (vehicle.second->getChildDemandElements().front()->getTagProperty().getTag() == GNE_TAG_ROUTE_EMBEDDED)) {
edgesToUpdate.insert(vehicle.second->getChildDemandElements().front()->getParentEdges().front());
}
}
for (const auto& routeFlow : myNet->getAttributeCarriers()->getDemandElements().at(GNE_TAG_FLOW_ROUTE)) {
if (routeFlow->getParentEdges().size() > 0) {
edgesToUpdate.insert(routeFlow->getParentEdges().front());
} else if (routeFlow->getChildDemandElements().size() > 0 && (routeFlow->getChildDemandElements().front()->getTagProperty().getTag() == GNE_TAG_ROUTE_EMBEDDED)) {
edgesToUpdate.insert(routeFlow->getChildDemandElements().front()->getParentEdges().front());
if (routeFlow.second->getParentEdges().size() > 0) {
edgesToUpdate.insert(routeFlow.second->getParentEdges().front());
} else if (routeFlow.second->getChildDemandElements().size() > 0 && (routeFlow.second->getChildDemandElements().front()->getTagProperty().getTag() == GNE_TAG_ROUTE_EMBEDDED)) {
edgesToUpdate.insert(routeFlow.second->getChildDemandElements().front()->getParentEdges().front());
}
}
for (const auto& trip : myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_TRIP)) {
if (trip->getParentEdges().size() > 0) {
edgesToUpdate.insert(trip->getParentEdges().front());
if (trip.second->getParentEdges().size() > 0) {
edgesToUpdate.insert(trip.second->getParentEdges().front());
}
}
for (const auto& flow : myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_FLOW)) {
if (flow->getParentEdges().size() > 0) {
edgesToUpdate.insert(flow->getParentEdges().front());
if (flow.second->getParentEdges().size() > 0) {
edgesToUpdate.insert(flow.second->getParentEdges().front());
}
}
// update spread geometries of all edges
Expand Down
16 changes: 8 additions & 8 deletions src/netedit/GNEViewParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ GNEViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
// fill ACsToLocate with all vehicles
for (const auto& vehicleTag : NamespaceIDs::vehicles) {
for (const auto& vehicle : viewNet->getNet()->getAttributeCarriers()->getDemandElements().at(vehicleTag)) {
ACsToLocate.push_back(vehicle);
ACsToLocate.push_back(vehicle.second);
}
}
break;
Expand All @@ -563,7 +563,7 @@ GNEViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
// fill ACsToLocate with all persons
for (const auto& personTag : NamespaceIDs::persons) {
for (const auto& person : viewNet->getNet()->getAttributeCarriers()->getDemandElements().at(personTag)) {
ACsToLocate.push_back(person);
ACsToLocate.push_back(person.second);
}
}
break;
Expand All @@ -573,15 +573,15 @@ GNEViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
// fill ACsToLocate with all containers
for (const auto& containerTag : NamespaceIDs::containers) {
for (const auto& container : viewNet->getNet()->getAttributeCarriers()->getDemandElements().at(containerTag)) {
ACsToLocate.push_back(container);
ACsToLocate.push_back(container.second);
}
}
break;
case MID_HOTKEY_SHIFT_R_LOCATEROUTE:
chooserLoc = &myACChoosers.ACChooserRoutes;
locateTitle = TL("Route Chooser");
for (const auto& route : viewNet->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE)) {
ACsToLocate.push_back(route);
ACsToLocate.push_back(route.second);
}
break;
case MID_HOTKEY_SHIFT_S_LOCATESTOP: {
Expand All @@ -590,7 +590,7 @@ GNEViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
// fill ACsToLocate with all vehicles
for (const auto& stopTag : NamespaceIDs::stops) {
for (const auto& flowTAZ : viewNet->getNet()->getAttributeCarriers()->getDemandElements().at(stopTag)) {
ACsToLocate.push_back(flowTAZ);
ACsToLocate.push_back(flowTAZ.second);
}
}
break;
Expand All @@ -613,7 +613,7 @@ GNEViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
if (!GNEAttributeCarrier::getTagProperty(additionalTag.first).isShapeElement() &&
!GNEAttributeCarrier::getTagProperty(additionalTag.first).isTAZElement()) {
for (const auto& additional : additionalTag.second) {
ACsToLocate.push_back(additional);
ACsToLocate.push_back(additional.second);
}
}
}
Expand All @@ -624,7 +624,7 @@ GNEViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
// fill ACsToLocate with all POIs
for (const auto& POITag : NamespaceIDs::POIs) {
for (const auto& flowTAZ : viewNet->getNet()->getAttributeCarriers()->getAdditionals().at(POITag)) {
ACsToLocate.push_back(flowTAZ);
ACsToLocate.push_back(flowTAZ.second);
}
}
break;
Expand All @@ -634,7 +634,7 @@ GNEViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
// fill ACsToLocate with all polygons
for (const auto& polygonTag : NamespaceIDs::polygons) {
for (const auto& flowTAZ : viewNet->getNet()->getAttributeCarriers()->getAdditionals().at(polygonTag)) {
ACsToLocate.push_back(flowTAZ);
ACsToLocate.push_back(flowTAZ.second);
}
}
break;
Expand Down
10 changes: 5 additions & 5 deletions src/netedit/dialogs/GNECalibratorDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ GNECalibratorDialog::onCmdAddFlow(FXObject*, FXSelector, void*) {
// only add flow if there is at least a GNERoute (There is always a Vehicle Type)
if (routes.size() > 0) {
// create new calibrator and configure it with modal GNECalibratorFlowDialog
GNECalibratorFlowDialog(new GNECalibratorFlow(myEditedAdditional, defaultVType, *routes.begin()), false); // NOSONAR, constructor returns after dialog has been closed
GNECalibratorFlowDialog(new GNECalibratorFlow(myEditedAdditional, defaultVType, routes.begin()->second), false); // NOSONAR, constructor returns after dialog has been closed
// update flows table
updateFlowTable();
return 1;
Expand Down Expand Up @@ -363,10 +363,10 @@ GNECalibratorDialog::updateRouteTable() {
// iterate over routes
for (const auto& route : myEditedAdditional->getNet()->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE)) {
// Set ID
item = new FXTableItem(toString(route->getAttribute(SUMO_ATTR_ID)).c_str());
item = new FXTableItem(toString(route.second->getAttribute(SUMO_ATTR_ID)).c_str());
myRouteList->setItem(indexRow, 0, item);
// Set edges
item = new FXTableItem(toString(route->getAttribute(SUMO_ATTR_EDGES)).c_str());
item = new FXTableItem(toString(route.second->getAttribute(SUMO_ATTR_EDGES)).c_str());
myRouteList->setItem(indexRow, 1, item);
// set remove
item = new FXTableItem("", GUIIconSubSys::getIcon(GUIIcon::REMOVE));
Expand Down Expand Up @@ -441,10 +441,10 @@ GNECalibratorDialog::updateVehicleTypeTable() {
// iterate over vehicle types
for (const auto& vType : myEditedAdditional->getNet()->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE)) {
// Set id
item = new FXTableItem(vType->getAttribute(SUMO_ATTR_ID).c_str());
item = new FXTableItem(vType.second->getAttribute(SUMO_ATTR_ID).c_str());
myVehicleTypeList->setItem(indexRow, 0, item);
// Set VClass
item = new FXTableItem(vType->getAttribute(SUMO_ATTR_VCLASS).c_str());
item = new FXTableItem(vType.second->getAttribute(SUMO_ATTR_VCLASS).c_str());
myVehicleTypeList->setItem(indexRow, 1, item);
// set remove icon except for default vehicle type
if (indexRow != 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/netedit/dialogs/GNECalibratorFlowDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ GNECalibratorFlowDialog::GNECalibratorFlowDialog(GNEAdditional* editedCalibrator

// fill comboBox of VTypes
for (const auto& vType : myEditedAdditional->getNet()->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE)) {
myComboBoxVehicleType->appendIconItem(vType->getID().c_str(), vType->getACIcon());
myComboBoxVehicleType->appendIconItem(vType.second->getID().c_str(), vType.second->getACIcon());
}

// fill comboBox of Routes
for (const auto& route : myEditedAdditional->getNet()->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE)) {
myComboBoxRoute->appendIconItem(route->getID().c_str(), route->getACIcon());
myComboBoxRoute->appendIconItem(route.second->getID().c_str(), route.second->getACIcon());
}

// update tables
Expand Down
4 changes: 2 additions & 2 deletions src/netedit/dialogs/GNERerouterIntervalDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ GNERerouterIntervalDialog::onCmdAddRouteProbReroute(FXObject*, FXSelector, void*
// check if there is at least one route
if (routes.size() > 0) {
// create route Prob Reroute
GNERouteProbReroute* routeProbReroute = new GNERouteProbReroute(myEditedAdditional, *routes.begin(), 1);
GNERouteProbReroute* routeProbReroute = new GNERouteProbReroute(myEditedAdditional, routes.begin()->second, 1);
myEditedAdditional->getNet()->getViewNet()->getUndoList()->add(new GNEChange_Additional(routeProbReroute, true), true);
myRouteProbReroutesEdited.push_back(routeProbReroute);
// update route prob reroutes table
Expand All @@ -386,7 +386,7 @@ GNERerouterIntervalDialog::onCmdAddParkingAreaReroute(FXObject*, FXSelector, voi
// first check if there is lanes in the network
if (myEditedAdditional->getNet()->getAttributeCarriers()->getAdditionals().at(SUMO_TAG_PARKING_AREA).size() > 0) {
// get parking area
GNEAdditional* parkingArea = *myEditedAdditional->getNet()->getAttributeCarriers()->getAdditionals().at(SUMO_TAG_PARKING_AREA).begin();
GNEAdditional* parkingArea = myEditedAdditional->getNet()->getAttributeCarriers()->getAdditionals().at(SUMO_TAG_PARKING_AREA).begin()->second;
// create parkingAreaReroute and add it to table
GNEParkingAreaReroute* parkingAreaReroute = new GNEParkingAreaReroute(myEditedAdditional, parkingArea, 1, 1);
// add it using undoList
Expand Down
10 changes: 5 additions & 5 deletions src/netedit/elements/demand/GNEDemandElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,15 @@ GNEDemandElement::getTypeParent() const {
// obtain all types with the given typeDistribution sorted by ID
std::map<std::string, GNEDemandElement*> sortedTypes;
for (const auto& type : myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE)) {
if (type->getAttribute(GNE_ATTR_VTYPE_DISTRIBUTION) == typeDistributionID) {
sortedTypes[type->getID()] = type;
if (type.second->getAttribute(GNE_ATTR_VTYPE_DISTRIBUTION) == typeDistributionID) {
sortedTypes[type.second->getID()] = type.second;
}
}
// return first type, or default vType
if (sortedTypes.size() > 0) {
return sortedTypes.begin()->second;
} else if (myNet->getAttributeCarriers()->getDemandElements().size() > 0) {
return *myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE).begin();
return myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE).begin()->second;
} else {
throw InvalidArgument("no vTypes");
}
Expand Down Expand Up @@ -695,8 +695,8 @@ GNEDemandElement::getDistributionParents() const {
// check if the current element is in the distributions
std::vector<std::string> distributionParents;
for (const auto& distribution : myNet->getAttributeCarriers()->getDemandElements().at(tagDistribution)) {
if (distribution->keyExists(this)) {
distributionParents.push_back(distribution->getID());
if (distribution.second->keyExists(this)) {
distributionParents.push_back(distribution.second->getID());
}
}
return toString(distributionParents);
Expand Down
4 changes: 2 additions & 2 deletions src/netedit/elements/demand/GNEDemandElementDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ GNEDemandElementDistribution::getPossibleDistributionKeys(SumoXMLTag type) const
auto allKeys = myDemandElement->getNet()->getAttributeCarriers()->getDemandElements().at(type);
// fill possible keys with non used keys
for (const auto& key : allKeys) {
if (!keyExists(key)) {
possibleKeys[key->getID()] = key;
if (!keyExists(key.second)) {
possibleKeys[key.second->getID()] = key.second;
}
}
return possibleKeys;
Expand Down
12 changes: 6 additions & 6 deletions src/netedit/frames/GNEDemandSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ GNEDemandElementSelector::refreshDemandElementSelector() {
// add rest of vTypes
for (const auto& vType : ACs->getDemandElements().at(demandElementTag)) {
// avoid insert duplicated default vType
if (DEFAULT_VTYPES.count(vType->getID()) == 0) {
myDemandElementsComboBox->appendIconItem(vType->getID().c_str(), vType->getACIcon());
if (DEFAULT_VTYPES.count(vType.second->getID()) == 0) {
myDemandElementsComboBox->appendIconItem(vType.second->getID().c_str(), vType.second->getACIcon());
}
}
} else {
// insert all elements sorted by ID
std::map<std::string, GNEDemandElement*> sortedElements;
for (const auto& demandElement : ACs->getDemandElements().at(demandElementTag)) {
sortedElements[demandElement->getID()] = demandElement;
sortedElements[demandElement.second->getID()] = demandElement.second;
}
for (const auto& demandElement : sortedElements) {
myDemandElementsComboBox->appendIconItem(demandElement.first.c_str(), demandElement.second->getACIcon(),
Expand All @@ -228,7 +228,7 @@ GNEDemandElementSelector::refreshDemandElementSelector() {
// update myCurrentDemandElement with the first allowed element
for (auto i = myDemandElementTags.begin(); (i != myDemandElementTags.end()) && (myCurrentDemandElement == nullptr); i++) {
if (ACs->getDemandElements().at(*i).size() > 0) {
myCurrentDemandElement = *ACs->getDemandElements().at(*i).begin();
myCurrentDemandElement = ACs->getDemandElements().at(*i).begin()->second;
}
}
}
Expand Down Expand Up @@ -257,12 +257,12 @@ GNEDemandElementSelector::onCmdSelectDemandElement(FXObject*, FXSelector, void*)
// Check if value of myTypeMatchBox correspond to a demand element
for (const auto& demandElementTag : myDemandElementTags) {
for (const auto& demandElement : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(demandElementTag)) {
if (demandElement->getID() == myDemandElementsComboBox->getText().text()) {
if (demandElement.second->getID() == myDemandElementsComboBox->getText().text()) {
// set color of myTypeMatchBox to black (valid)
myDemandElementsComboBox->setTextColor(FXRGB(0, 0, 0));
myDemandElementsComboBox->killFocus();
// Set new current demand element
myCurrentDemandElement = demandElement;
myCurrentDemandElement = demandElement.second;
// call demandElementSelected function
myFrameParent->demandElementSelected();
// Write Warning in console if we're in testing mode
Expand Down
4 changes: 2 additions & 2 deletions src/netedit/frames/GNEFrameAttributeModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,14 +730,14 @@ GNEFrameAttributeModules::AttributesEditorRow::fillComboBox(const std::string& v
// fill comboBox with all vTypes and vType distributions sorted by ID
std::map<std::string, GNEDemandElement*> sortedTypes;
for (const auto& type : ACs->getDemandElements().at(SUMO_TAG_VTYPE)) {
sortedTypes[type->getID()] = type;
sortedTypes[type.second->getID()] = type.second;
}
for (const auto& sortedType : sortedTypes) {
myValueComboBox->appendIconItem(sortedType.first.c_str(), sortedType.second->getACIcon());
}
sortedTypes.clear();
for (const auto& typeDistribution : ACs->getDemandElements().at(SUMO_TAG_VTYPE_DISTRIBUTION)) {
sortedTypes[typeDistribution->getID()] = typeDistribution;
sortedTypes[typeDistribution.second->getID()] = typeDistribution.second;
}
for (const auto& sortedType : sortedTypes) {
myValueComboBox->appendIconItem(sortedType.first.c_str(), sortedType.second->getACIcon());
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/frames/GNESelectorParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ GNESelectorParent::refreshSelectorParentModule() {
// additionals
if (tagProperty.isAdditionalElement()) {
for (const auto& additional : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getAdditionals().at(parentTag)) {
IDs.insert(additional->getID().c_str());
IDs.insert(additional.second->getID().c_str());
}
}
}
Expand Down

0 comments on commit c3adae6

Please sign in to comment.