Skip to content

Commit

Permalink
Merge branch 'main' of github.com:eclipse-sumo/sumo into Netedit_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Jan 31, 2025
2 parents 123b8d1 + 2fb8c78 commit 0c493dc
Show file tree
Hide file tree
Showing 132 changed files with 2,902 additions and 4,085 deletions.
171 changes: 35 additions & 136 deletions src/netedit/GNEApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ GNEApplicationWindow::~GNEApplicationWindow() {

long
GNEApplicationWindow::onCmdQuit(FXObject*, FXSelector, void*) {
if (continueWithUnsavedChanges()) {
if (askSaveElements()) {
storeWindowSizeAndPos();
getApp()->reg().writeStringEntry("SETTINGS", "basedir", gCurrentFolder.text());
if (isMaximized()) {
Expand Down Expand Up @@ -1116,7 +1116,7 @@ long
GNEApplicationWindow::onCmdClose(FXObject*, FXSelector, void*) {
if (myViewNet == nullptr) {
return 1;
} else if (continueWithUnsavedChanges()) {
} else if (askSaveElements()) {
closeAllWindows();
// add a separator to the log
myMessageWindow->addSeparator();
Expand Down Expand Up @@ -4299,151 +4299,50 @@ GNEApplicationWindow::onCmdSaveMeanDatasAs(FXObject* sender, FXSelector sel, voi


bool
GNEApplicationWindow::continueWithUnsavedChanges() {
if (continueWithUnsavedNetworkChanges() &&
continueWithUnsavedAdditionalChanges() &&
continueWithUnsavedDemandElementChanges() &&
continueWithUnsavedDataElementChanges() &&
continueWithUnsavedMeanDataElementChanges()) {
// clear undo list
clearUndoList();
return true;
} else {
return false;
}
}


bool
GNEApplicationWindow::continueWithUnsavedNetworkChanges() {
if (myNet && !myNet->getSavingStatus()->isNetworkSaved()) {
// write warning if netedit is running in testing mode
// open question box
const std::string header = TL("Confirm close Network");
const std::string contentsA = TL("You have unsaved changes in the network.");
const std::string contentsB = TL("Do you wish to close and discard all changes?");
const auto answer = GUISaveDialog::question(getApp(), header.c_str(), "%s", (contentsA + "\n" + contentsB).c_str());
// if user close dialog box, check additionals and demand elements
if (answer == GUISaveDialog::CLICKED_DISCARD) {
// nothing to save, return true
return true;
} else if (answer == GUISaveDialog::CLICKED_SAVE) {
// return true if was sucessfully saved
return (onCmdSaveNetwork(nullptr, 0, nullptr) == 1);
} else {
// return false to stop closing/reloading
GNEApplicationWindow::askSaveElements() {
if (myNet) {
const auto saveNetwork = myNet->getSavingStatus()->askSaveNetwork();
const auto saveAdditionalElements = myNet->getSavingStatus()->askSaveAdditionalElements();
const auto saveDemandElements = myNet->getSavingStatus()->askSaveDemandElements();
const auto saveDataElements = myNet->getSavingStatus()->askSaveDataElements();
const auto saveMeanDataElements = myNet->getSavingStatus()->askSaveMeanDataElements();
// first check if abort saving
if ((saveNetwork == GNENetHelper::SavingStatus::AskSaving::ABORT) ||
(saveAdditionalElements == GNENetHelper::SavingStatus::AskSaving::ABORT) ||
(saveDemandElements == GNENetHelper::SavingStatus::AskSaving::ABORT) ||
(saveDataElements == GNENetHelper::SavingStatus::AskSaving::ABORT) ||
(saveMeanDataElements == GNENetHelper::SavingStatus::AskSaving::ABORT)) {
return false;
}
} else {
// nothing to save, return true
return true;
}
}


bool
GNEApplicationWindow::continueWithUnsavedAdditionalChanges() {
// Check if there are non saved additionals
if (myNet && !myNet->getSavingStatus()->isAdditionalsSaved()) {
// open question box
const std::string header = TL("Save additional elements before close");
const std::string contentsA = TL("You have unsaved additional elements.");
const std::string contentsB = TL("Do you wish to close and discard all changes?");
const auto answer = GUISaveDialog::question(getApp(), header.c_str(), "%s", (contentsA + "\n" + contentsB).c_str());
// if answer was affirmative, but there was an error during saving additionals, return false to stop closing/reloading
if (answer == GUISaveDialog::CLICKED_DISCARD) {
// nothing to save, return true
return true;
} else if (answer == GUISaveDialog::CLICKED_SAVE) {
// return true if was sucessfully saved
return (onCmdSaveAdditionals(nullptr, 0, nullptr) == 1);
} else {
// abort saving
// save every type of file
if ((saveNetwork == GNENetHelper::SavingStatus::AskSaving::SAVE) &&
(onCmdSaveNetwork(nullptr, 0, nullptr) != 1)) {
return false;
}
} else {
// nothing to save, return true
return true;
}
}


bool
GNEApplicationWindow::continueWithUnsavedDemandElementChanges() {
// Check if there are non saved demand elements
if (myNet && !myNet->getSavingStatus()->isDemandElementsSaved()) {
// open question box
const std::string header = TL("Save demand elements before close");
const std::string contentsA = TL("You have unsaved demand elements.");
const std::string contentsB = TL("Do you wish to close and discard all changes?");
const auto answer = GUISaveDialog::question(getApp(), header.c_str(), "%s", (contentsA + "\n" + contentsB).c_str());
// if answer was affirmative, but there was an error during saving demand elements, return false to stop closing/reloading
if (answer == GUISaveDialog::CLICKED_DISCARD) {
// nothing to save, return true
return true;
} else if (answer == GUISaveDialog::CLICKED_SAVE) {
// return true if was sucessfully saved
return (onCmdSaveDemandElements(nullptr, MID_GNE_AUTOMATICFILENAME, nullptr) == 1);
} else {
// abort saving
if ((saveAdditionalElements == GNENetHelper::SavingStatus::AskSaving::SAVE) &&
(onCmdSaveAdditionals(nullptr, 0, nullptr) != 1)) {
return false;
}
} else {
// nothing to save, return true
return true;
}
}


bool
GNEApplicationWindow::continueWithUnsavedDataElementChanges() {
// Check if there are non saved data elements
if (myNet && !myNet->getSavingStatus()->isDataElementsSaved()) {
// open question box
const std::string header = TL("Save data elements before close");
const std::string contentsA = TL("You have unsaved data elements.");
const std::string contentsB = TL("Do you wish to close and discard all changes?");
const auto answer = GUISaveDialog::question(getApp(), header.c_str(), "%s", (contentsA + "\n" + contentsB).c_str());
// if answer was affirmative, but there was an error during saving data elements, return false to stop closing/reloading
if (answer == GUISaveDialog::CLICKED_DISCARD) {
// nothing to save, return true
return true;
} else if (answer == GUISaveDialog::CLICKED_SAVE) {
// return true if was sucessfully saved
return (onCmdSaveDataElements(nullptr, MID_GNE_AUTOMATICFILENAME, nullptr) == 1);
} else {
// abort saving
if ((saveDemandElements == GNENetHelper::SavingStatus::AskSaving::SAVE) &&
(onCmdSaveDemandElements(nullptr, 0, nullptr) != 1)) {
return false;
}
} else {
// nothing to save, return true
return true;
}
}


bool
GNEApplicationWindow::continueWithUnsavedMeanDataElementChanges() {
// Check if there are non saved data elements
if (myNet && !myNet->getSavingStatus()->isMeanDatasSaved()) {
// open question box
const std::string header = TL("Save meanData elements before close");
const std::string contentsA = TL("You have unsaved meanData elements.");
const std::string contentsB = TL("Do you wish to close and discard all changes?");
const auto answer = GUISaveDialog::question(getApp(), header.c_str(), "%s", (contentsA + "\n" + contentsB).c_str());
// if answer was affirmative, but there was an error during saving meanData elements, return false to stop closing/reloading
if (answer == GUISaveDialog::CLICKED_DISCARD) {
// nothing to save, return true
return true;
} else if (answer == GUISaveDialog::CLICKED_SAVE) {
// return true if was sucessfully saved
return (onCmdSaveMeanDatas(nullptr, MID_GNE_AUTOMATICFILENAME, nullptr) == 1);
} else {
// abort saving
if ((saveDataElements == GNENetHelper::SavingStatus::AskSaving::SAVE) &&
(onCmdSaveDataElements(nullptr, 0, nullptr) != 1)) {
return false;
}
if ((saveMeanDataElements == GNENetHelper::SavingStatus::AskSaving::SAVE) &&
(onCmdSaveMeanDatas(nullptr, 0, nullptr) != 1)) {
return false;
}
// restore focus in viewNet
myViewNet->setFocus();
// clear undo list
clearUndoList();
// all saved, then continue
return true;
} else {
// nothing to save, return true
// nothing to do, then continue
return true;
}
}
Expand Down
17 changes: 1 addition & 16 deletions src/netedit/GNEApplicationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,22 +789,7 @@ class GNEApplicationWindow : public GUIMainWindow, public MFXInterThreadEventCli
void closeAllWindows();

/// @brief warns about unsaved changes and gives the user the option to abort
bool continueWithUnsavedChanges();

/// @brief warns about unsaved changes in network and gives the user the option to abort
bool continueWithUnsavedNetworkChanges();

/// @brief warns about unsaved changes in additionals and gives the user the option to abort
bool continueWithUnsavedAdditionalChanges();

/// @brief warns about unsaved changes in demand elements and gives the user the option to abort
bool continueWithUnsavedDemandElementChanges();

/// @brief warns about unsaved changes in data elements and gives the user the option to abort
bool continueWithUnsavedDataElementChanges();

/// @brief warns about unsaved changes in meanData elements and gives the user the option to abort
bool continueWithUnsavedMeanDataElementChanges();
bool askSaveElements();

/// @brief set input files in sumo options
void setInputInSumoOptions(const bool ignoreAdditionals, const bool ignoreRoutes);
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/GNENet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ GNENet::GNENet(NBNetBuilder* netBuilder) :
GUIGlObject(GLO_NETWORK, "", nullptr),
myNetBuilder(netBuilder),
myAttributeCarriers(new GNENetHelper::AttributeCarriers(this)),
mySavingStatus(new GNENetHelper::SavingStatus()),
mySavingStatus(new GNENetHelper::SavingStatus(this)),
myNetworkPathManager(new GNEPathManager(this)),
myDemandPathManager(new GNEPathManager(this)),
myDataPathManager(new GNEPathManager(this)) {
Expand Down
120 changes: 119 additions & 1 deletion src/netedit/GNENetHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@
#include <netedit/frames/network/GNECreateEdgeFrame.h>
#include <utils/gui/div/GUIGlobalSelection.h>
#include <utils/gui/globjects/GUIGlObjectStorage.h>
#include <utils/gui/globjects/GUISaveDialog.h>
#include <utils/options/OptionsCont.h>
#include <utils/xml/NamespaceIDs.h>


#include "GNENetHelper.h"

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -2745,7 +2747,8 @@ GNENetHelper::AttributeCarriers::updateDemandElementFrames(const GNETagPropertie
// GNENetHelper::SavingStatus - methods
// ---------------------------------------------------------------------------

GNENetHelper::SavingStatus::SavingStatus() {
GNENetHelper::SavingStatus::SavingStatus(GNENet* net) :
myNet(net) {
}


Expand Down Expand Up @@ -2926,6 +2929,121 @@ GNENetHelper::SavingStatus::isMeanDatasSaved() const {
return myMeanDataElementSaved;
}


GNENetHelper::SavingStatus::AskSaving
GNENetHelper::SavingStatus::askSaveNetwork() const {
// Check if there are non saved network elements
if (myNetworkSaved) {
return AskSaving::CONTINUE;
} else {
// open question box
const std::string header = TL("Confirm close Network");
const std::string contentsA = TL("You have unsaved changes in the network.");
const std::string contentsB = TL("Do you wish to close and discard all changes?");
const auto answer = GUISaveDialog::question(myNet->getApp(), header.c_str(), "%s", (contentsA + "\n" + contentsB).c_str());
// continue depending of answer
if (answer == GUISaveDialog::CLICKED_DISCARD) {
return AskSaving::DISCARD;
} else if (answer == GUISaveDialog::CLICKED_SAVE) {
return AskSaving::SAVE;
} else {
return AskSaving::ABORT;
}
}
}


GNENetHelper::SavingStatus::AskSaving
GNENetHelper::SavingStatus::askSaveAdditionalElements() const {
// Check if there are non saved additional elements
if (myAdditionalSaved) {
return AskSaving::CONTINUE;
} else {
// open question box
const std::string header = TL("Save additional elements before close");
const std::string contentsA = TL("You have unsaved additional elements.");
const std::string contentsB = TL("Do you wish to close and discard all changes?");
const auto answer = GUISaveDialog::question(myNet->getApp(), header.c_str(), "%s", (contentsA + "\n" + contentsB).c_str());
// continue depending of answer
if (answer == GUISaveDialog::CLICKED_DISCARD) {
return AskSaving::DISCARD;
} else if (answer == GUISaveDialog::CLICKED_SAVE) {
return AskSaving::SAVE;
} else {
return AskSaving::ABORT;
}
}
}


GNENetHelper::SavingStatus::AskSaving
GNENetHelper::SavingStatus::askSaveDemandElements() const {
// Check if there are non saved demand elements
if (myDemandElementSaved) {
return AskSaving::CONTINUE;
} else {
// open question box
const std::string header = TL("Save demand elements before close");
const std::string contentsA = TL("You have unsaved demand elements.");
const std::string contentsB = TL("Do you wish to close and discard all changes?");
const auto answer = GUISaveDialog::question(myNet->getApp(), header.c_str(), "%s", (contentsA + "\n" + contentsB).c_str());
// continue depending of answer
if (answer == GUISaveDialog::CLICKED_DISCARD) {
return AskSaving::DISCARD;
} else if (answer == GUISaveDialog::CLICKED_SAVE) {
return AskSaving::SAVE;
} else {
return AskSaving::ABORT;
}
}
}


GNENetHelper::SavingStatus::AskSaving
GNENetHelper::SavingStatus::askSaveDataElements() const {
// Check if there are non saved data elements
if (myDataElementSaved) {
return AskSaving::CONTINUE;
} else {
// open question box
const std::string header = TL("Save data elements before close");
const std::string contentsA = TL("You have unsaved data elements.");
const std::string contentsB = TL("Do you wish to close and discard all changes?");
const auto answer = GUISaveDialog::question(myNet->getApp(), header.c_str(), "%s", (contentsA + "\n" + contentsB).c_str());
// continue depending of answer
if (answer == GUISaveDialog::CLICKED_DISCARD) {
return AskSaving::DISCARD;
} else if (answer == GUISaveDialog::CLICKED_SAVE) {
return AskSaving::SAVE;
} else {
return AskSaving::ABORT;
}
}
}


GNENetHelper::SavingStatus::AskSaving
GNENetHelper::SavingStatus::askSaveMeanDataElements() const {
// Check if there are non saved mean data elements
if (myMeanDataElementSaved) {
return AskSaving::CONTINUE;
} else {
// open question box
const std::string header = TL("Save meanData elements before close");
const std::string contentsA = TL("You have unsaved meanData elements.");
const std::string contentsB = TL("Do you wish to close and discard all changes?");
const auto answer = GUISaveDialog::question(myNet->getApp(), header.c_str(), "%s", (contentsA + "\n" + contentsB).c_str());
// continue depending of answer
if (answer == GUISaveDialog::CLICKED_DISCARD) {
return AskSaving::DISCARD;
} else if (answer == GUISaveDialog::CLICKED_SAVE) {
return AskSaving::SAVE;
} else {
return AskSaving::ABORT;
}
}
}

// ---------------------------------------------------------------------------
// GNENetHelper::GNEChange_ReplaceEdgeInTLS - methods
// ---------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 0c493dc

Please sign in to comment.