Skip to content

Commit

Permalink
Now saveAs... buttons are only enabled if there is elements to save. …
Browse files Browse the repository at this point in the history
…Refs #10426
  • Loading branch information
palvarezlopez committed Apr 26, 2022
1 parent 0b0bf3b commit c6493d1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 9 deletions.
31 changes: 26 additions & 5 deletions src/netedit/GNEApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ FXDEFMAP(GNEApplicationWindow) GNEApplicationWindowMap[] = {
FXMAPFUNC(SEL_COMMAND, MID_HOTKEY_CTRL_SHIFT_A_SAVEADDITIONALS, GNEApplicationWindow::onCmdSaveAdditionals),
FXMAPFUNC(SEL_UPDATE, MID_HOTKEY_CTRL_SHIFT_A_SAVEADDITIONALS, GNEApplicationWindow::onUpdSaveAdditionals),
FXMAPFUNC(SEL_COMMAND, MID_GNE_TOOLBARFILE_SAVEADDITIONALS_AS, GNEApplicationWindow::onCmdSaveAdditionalsAs),
FXMAPFUNC(SEL_UPDATE, MID_GNE_TOOLBARFILE_SAVEADDITIONALS_AS, GNEApplicationWindow::onUpdNeedsNetwork),
FXMAPFUNC(SEL_UPDATE, MID_GNE_TOOLBARFILE_SAVEADDITIONALS_AS, GNEApplicationWindow::onUpdSaveAdditionalsAs),
// demand elements
FXMAPFUNC(SEL_COMMAND, MID_HOTKEY_CTRL_D_SINGLESIMULATIONSTEP_OPENDEMANDELEMENTS, GNEApplicationWindow::onCmdOpenDemandElements),
FXMAPFUNC(SEL_UPDATE, MID_HOTKEY_CTRL_D_SINGLESIMULATIONSTEP_OPENDEMANDELEMENTS, GNEApplicationWindow::onUpdNeedsNetwork),
Expand All @@ -132,7 +132,7 @@ FXDEFMAP(GNEApplicationWindow) GNEApplicationWindowMap[] = {
FXMAPFUNC(SEL_COMMAND, MID_HOTKEY_CTRL_SHIFT_D_SAVEDEMANDELEMENTS, GNEApplicationWindow::onCmdSaveDemandElements),
FXMAPFUNC(SEL_UPDATE, MID_HOTKEY_CTRL_SHIFT_D_SAVEDEMANDELEMENTS, GNEApplicationWindow::onUpdSaveDemandElements),
FXMAPFUNC(SEL_COMMAND, MID_GNE_TOOLBARFILE_SAVEDEMAND_AS, GNEApplicationWindow::onCmdSaveDemandElementsAs),
FXMAPFUNC(SEL_UPDATE, MID_GNE_TOOLBARFILE_SAVEDEMAND_AS, GNEApplicationWindow::onUpdNeedsNetwork),
FXMAPFUNC(SEL_UPDATE, MID_GNE_TOOLBARFILE_SAVEDEMAND_AS, GNEApplicationWindow::onUpdSaveDemandElementsAs),
// data elements
FXMAPFUNC(SEL_COMMAND, MID_HOTKEY_CTRL_B_EDITBREAKPOINT_OPENDATAELEMENTS, GNEApplicationWindow::onCmdOpenDataElements),
FXMAPFUNC(SEL_UPDATE, MID_HOTKEY_CTRL_B_EDITBREAKPOINT_OPENDATAELEMENTS, GNEApplicationWindow::onUpdNeedsNetwork),
Expand All @@ -141,7 +141,7 @@ FXDEFMAP(GNEApplicationWindow) GNEApplicationWindowMap[] = {
FXMAPFUNC(SEL_COMMAND, MID_HOTKEY_CTRL_SHIFT_B_SAVEDATAELEMENTS, GNEApplicationWindow::onCmdSaveDataElements),
FXMAPFUNC(SEL_UPDATE, MID_HOTKEY_CTRL_SHIFT_B_SAVEDATAELEMENTS, GNEApplicationWindow::onUpdSaveDataElements),
FXMAPFUNC(SEL_COMMAND, MID_GNE_TOOLBARFILE_SAVEDATA_AS, GNEApplicationWindow::onCmdSaveDataElementsAs),
FXMAPFUNC(SEL_UPDATE, MID_GNE_TOOLBARFILE_SAVEDATA_AS, GNEApplicationWindow::onUpdNeedsNetwork),
FXMAPFUNC(SEL_UPDATE, MID_GNE_TOOLBARFILE_SAVEDATA_AS, GNEApplicationWindow::onUpdSaveDataElementsAs),
// other
FXMAPFUNC(SEL_COMMAND, MID_GNE_TOOLBARFILE_SAVETLSPROGRAMS_AS, GNEApplicationWindow::onCmdSaveTLSProgramsAs),
FXMAPFUNC(SEL_UPDATE, MID_GNE_TOOLBARFILE_SAVETLSPROGRAMS_AS, GNEApplicationWindow::onUpdSaveTLSPrograms),
Expand Down Expand Up @@ -1497,8 +1497,8 @@ GNEApplicationWindow::computeJunctionWithVolatileOptions() {
// clear additional path
additionalsSavePath = "";
}
// Check if there are demand elements in our net (3 due default vehicle types and person types)
if (myNet->getAttributeCarriers()->getNumberOfDemandElements() > 3) {
// Check if there are demand elements in our net
if (myNet->getAttributeCarriers()->getNumberOfDemandElements() > 0) {
// ask user if want to save demand elements if weren't saved previously
if (oc.getString("route-files") == "") {
// write warning if netedit is running in testing mode
Expand Down Expand Up @@ -2592,20 +2592,41 @@ GNEApplicationWindow::onUpdSaveAdditionals(FXObject* sender, FXSelector, void*)
}


long
GNEApplicationWindow::onUpdSaveAdditionalsAs(FXObject* sender, FXSelector, void*) {
sender->handle(this, ((myNet == nullptr) || (myNet->getAttributeCarriers()->getNumberOfAdditionals() == 0)) ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
return 1;
}


long
GNEApplicationWindow::onUpdSaveDemandElements(FXObject* sender, FXSelector, void*) {
sender->handle(this, ((myNet == nullptr) || myNet->isDemandElementsSaved()) ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
return 1;
}


long
GNEApplicationWindow::onUpdSaveDemandElementsAs(FXObject* sender, FXSelector, void*) {
sender->handle(this, ((myNet == nullptr) || (myNet->getAttributeCarriers()->getNumberOfDemandElements() == 0)) ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
return 1;
}


long
GNEApplicationWindow::onUpdSaveDataElements(FXObject* sender, FXSelector, void*) {
sender->handle(this, ((myNet == nullptr) || myNet->isDataElementsSaved()) ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
return 1;
}


long
GNEApplicationWindow::onUpdSaveDataElementsAs(FXObject* sender, FXSelector, void*) {
sender->handle(this, ((myNet == nullptr) || (myNet->getAttributeCarriers()->getDataSets().size() == 0)) ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
return 1;
}


long
GNEApplicationWindow::onUpdUndo(FXObject* obj, FXSelector sel, void* ptr) {
return myUndoList->onUpdUndo(obj, sel, ptr);
Expand Down
9 changes: 9 additions & 0 deletions src/netedit/GNEApplicationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,21 @@ class GNEApplicationWindow : public GUIMainWindow, public MFXInterThreadEventCli
/// @brief called when the update/FXCall save additionals is executed
long onUpdSaveAdditionals(FXObject*, FXSelector, void*);

/// @brief called when the update/FXCall save additionals as is executed
long onUpdSaveAdditionalsAs(FXObject*, FXSelector, void*);

/// @brief called when the update/FXCall save demand elements is executed
long onUpdSaveDemandElements(FXObject*, FXSelector, void*);

/// @brief called when the update/FXCall save demand elements as is executed
long onUpdSaveDemandElementsAs(FXObject*, FXSelector, void*);

/// @brief called when the update/FXCall save data elements is executed
long onUpdSaveDataElements(FXObject*, FXSelector, void*);

/// @brief called when the update/FXCall save data elements as is executed
long onUpdSaveDataElementsAs(FXObject*, FXSelector, void*);

/// @brief called when the update/FXCall undo is executed
long onUpdUndo(FXObject* obj, FXSelector sel, void* ptr);

Expand Down
11 changes: 10 additions & 1 deletion src/netedit/GNENetHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,16 @@ int
GNENetHelper::AttributeCarriers::getNumberOfDemandElements() const {
int counter = 0;
for (const auto& demandElementTag : myDemandElements) {
counter += (int)demandElementTag.second.size();
if (demandElementTag.first == SUMO_TAG_VTYPE) {
// iterate over vehicle types to avoid default vTypes
for (const auto &vType : demandElementTag.second) {
if (vType->getAttribute(GNE_ATTR_DEFAULT_VTYPE) != GNEAttributeCarrier::True) {
counter++;
}
}
} else {
counter += (int)demandElementTag.second.size();
}
}
return counter;
}
Expand Down
2 changes: 2 additions & 0 deletions src/netedit/elements/GNEAttributeCarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const std::string GNEAttributeCarrier::FEATURE_MODIFIED = "modified";
const std::string GNEAttributeCarrier::FEATURE_APPROVED = "approved";
const size_t GNEAttributeCarrier::MAXNUMBEROFATTRIBUTES = 128;
const Parameterised::Map GNEAttributeCarrier::PARAMETERS_EMPTY;
const std::string GNEAttributeCarrier::True = toString(true);
const std::string GNEAttributeCarrier::False = toString(false);


// ===========================================================================
Expand Down
6 changes: 6 additions & 0 deletions src/netedit/elements/GNEAttributeCarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ class GNEAttributeCarrier : public GNEReferenceCounter {
/// @brief empty parameter maps (used by ACs without parameters)
static const Parameterised::Map PARAMETERS_EMPTY;

/// @brief true value in string format (used for comparing boolean values in getAttribute(...))
static const std::string True;

/// @brief true value in string format(used for comparing boolean values in getAttribute(...))
static const std::string False;

protected:
/// @brief reference to tagProperty associated with this attribute carrier
const GNETagProperties& myTagProperty;
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/elements/demand/GNEVType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ GNEVType::getAttribute(SumoXMLAttr key) const {
if (myDefaultVehicleType) {
return toString(myDefaultVehicleTypeModified);
} else {
return toString(false);
return False;
}
default:
throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
Expand Down
4 changes: 2 additions & 2 deletions src/netedit/elements/network/GNEJunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,11 +1000,11 @@ GNEJunction::getAttribute(SumoXMLAttr key) const {
for (const auto& i : myGNEIncomingEdges) {
for (const auto& j : i->getGNEConnections()) {
if (j->getNBEdgeConnection().keepClear) {
return toString(true);
return True;
}
}
}
return toString(false);
return False;
case SUMO_ATTR_RIGHT_OF_WAY:
return SUMOXMLDefinitions::RightOfWayValues.getString(myNBNode->getRightOfWay());
case SUMO_ATTR_FRINGE:
Expand Down

0 comments on commit c6493d1

Please sign in to comment.