Skip to content

Commit

Permalink
Updated GNEAllowVClassesDialog. Refs #15776
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Nov 27, 2024
1 parent 02a1ba9 commit 709205b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 44 deletions.
45 changes: 11 additions & 34 deletions src/netedit/dialogs/GNEAllowVClassesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,9 @@ FXIMPLEMENT(GNEAllowVClassesDialog, FXDialogBox, GNEAllowVClassesDialogMap, ARRA
// member method definitions
// ===========================================================================

GNEAllowVClassesDialog::GNEAllowVClassesDialog(GNEViewNet* viewNet, GNEAttributeCarrier* AC, SumoXMLAttr attr, bool* acceptChanges) :
FXDialogBox(viewNet->getApp(), ("Edit " + toString(attr) + " " + toString(SUMO_ATTR_VCLASS) + "es").c_str(), GUIDesignDialogBox),
GNEAllowVClassesDialog::GNEAllowVClassesDialog(GNEViewNet* viewNet, SumoXMLAttr attr, std::string* allow, bool* acceptChanges) :
FXDialogBox(viewNet->getApp(), TLF("Edit vClasses of attribute '%'", toString(attr)).c_str(), GUIDesignDialogBox),
myViewNet(viewNet),
myAC(AC),
myEditedAttr(attr),
myAcceptChanges(acceptChanges),
myAllow(nullptr) {
// call constructor
constructor();
}


GNEAllowVClassesDialog::GNEAllowVClassesDialog(GNEViewNet* viewNet, std::string* allow, bool* acceptChanges) :
FXDialogBox(viewNet->getApp(), TL("Edit allow vClasses"), GUIDesignDialogBox),
myViewNet(viewNet),
myAC(nullptr),
myEditedAttr(SUMO_ATTR_ALLOW),
myAcceptChanges(acceptChanges),
myAllow(allow) {
Expand Down Expand Up @@ -147,24 +134,21 @@ GNEAllowVClassesDialog::onCmdSelectOnlyRail(FXObject*, FXSelector, void*) {
long
GNEAllowVClassesDialog::onCmdAccept(FXObject*, FXSelector, void*) {
// clear allow and disallow VClasses
std::vector<std::string> allowedVehicles, disallowedVehicles;
std::vector<std::string> allowedVehicles;
for (const auto& vClass : myVClassMap) {
// check if vehicle is allowed depending on the Icon
if (vClass.second.first->getIcon() == GUIIconSubSys::getIcon(GUIIcon::ACCEPT)) {
allowedVehicles.push_back(getVehicleClassNames(vClass.first));
} else {
disallowedVehicles.push_back(getVehicleClassNames(vClass.first));
}
}
// check if all vehicles are enabled and set new allowed vehicles
if (myAC) {
myAC->setAttribute(myEditedAttr, joinToString(allowedVehicles, " "), myViewNet->getUndoList());
} else {
// update strings
const auto newAllow = joinToString(allowedVehicles, " ");
// only mark as accepted changes if the new vehicles are differents
if (newAllow != *myAllow) {
// check if all vehicles are enabled and set new allowed vehicles
*myAllow = joinToString(allowedVehicles, " ");
// enable accept flag
*myAcceptChanges = true;
}
// enable accept flag
*myAcceptChanges = true;
// Stop Modal
getApp()->stopModal(this, TRUE);
return 1;
Expand All @@ -183,22 +167,15 @@ GNEAllowVClassesDialog::onCmdCancel(FXObject*, FXSelector, void*) {

long
GNEAllowVClassesDialog::onCmdReset(FXObject*, FXSelector, void*) {
std::string allow;
// set allow depending of myAC
if (myAC) {
allow = myAC->getAttribute(myEditedAttr);
} else {
allow = *myAllow;
}
// continue depending of allow
if (allow == "all") {
if (*myAllow == "all") {
// iterate over myVClassMap and set all icons as true
for (const auto& vClass : myVClassMap) {
vClass.second.first->setIcon(GUIIconSubSys::getIcon(GUIIcon::ACCEPT));
}
} else {
// declare string vector for saving all vclasses
const std::vector<std::string>& allowStringVector = StringTokenizer(allow).getVector();
const std::vector<std::string>& allowStringVector = StringTokenizer(*myAllow).getVector();
const std::set<std::string> allowSet(allowStringVector.begin(), allowStringVector.end());
// iterate over myVClassMap and set icons
for (const auto& vClass : myVClassMap) {
Expand Down
15 changes: 5 additions & 10 deletions src/netedit/dialogs/GNEAllowVClassesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ class GNEAllowVClassesDialog : public FXDialogBox {
FXDECLARE(GNEAllowVClassesDialog)

public:
/// @brief Constructor (for AC)
GNEAllowVClassesDialog(GNEViewNet* viewNet, GNEAttributeCarrier* AC, SumoXMLAttr attr, bool* acceptChanges);

/// @brief Constructor (For
GNEAllowVClassesDialog(GNEViewNet* viewNet, std::string* allow, bool* acceptChanges);
/// @brief Constructor
GNEAllowVClassesDialog(GNEViewNet* viewNet, SumoXMLAttr attr, std::string* allow, bool* acceptChanges);

/// @brief destructor
~GNEAllowVClassesDialog();
Expand Down Expand Up @@ -76,6 +73,7 @@ class GNEAllowVClassesDialog : public FXDialogBox {

/// @brief event after press reset button
long onCmdReset(FXObject*, FXSelector, void*);

/// @}

protected:
Expand All @@ -85,16 +83,13 @@ class GNEAllowVClassesDialog : public FXDialogBox {
/// @pointer to viewNet
GNEViewNet* myViewNet;

/// @brief edited AC
GNEAttributeCarrier* myAC;

/// @brief the attribute being edited
SumoXMLAttr myEditedAttr;

/// @brief accept changes
/// @brief reference for mark that the new set of VClasses was accepted
bool* myAcceptChanges;

/// @brief allow vehicles
/// @brief reference to allow vehicles. Will be modified with the new allowed vehicles
std::string* myAllow;

/// @brief accept button
Expand Down
2 changes: 2 additions & 0 deletions src/netedit/frames/GNEFrameAttributeModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ GNEFrameAttributeModules::AttributesEditorRow::onCmdOpenColorDialog(FXObject*, F

long
GNEFrameAttributeModules::AttributesEditorRow::onCmdOpenAllowDialog(FXObject*, FXSelector, void*) {
/*
GNEViewNet* viewNet = myAttributesEditorParent->getFrameParent()->getViewNet();
const auto& inspectedElements = viewNet->getInspectedElements();
if (inspectedElements.getFirstAC()) {
Expand All @@ -263,6 +264,7 @@ GNEFrameAttributeModules::AttributesEditorRow::onCmdOpenAllowDialog(FXObject*, F
myAttributesEditorParent->getFrameParent()->attributeUpdated(myACAttr.getAttr());
}
}
*/
return 1;
}

Expand Down

0 comments on commit 709205b

Please sign in to comment.