Skip to content
Snippets Groups Projects
Commit b9a6e631 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

refactoring

parent 067bf70b
Branches
Tags
No related merge requests found
...@@ -380,6 +380,36 @@ static void updateGraphs() ...@@ -380,6 +380,36 @@ static void updateGraphs()
} }
} }
static void writeDb(const std::string &fileName, bool withTimeStamp=false)
{
std::string name(fileName);
if(withTimeStamp){
time_t now;
time(&now);
tm *t = localtime(&now);
char stamp[32];
sprintf(stamp, "_%04d-%02d-%02d-%02d:%02d:%02d", 1900 + t->tm_year,
1 + t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
std::vector<std::string> split = SplitFileName(fileName);
name = split[0] + split[1] + stamp + split[2];
}
Msg::StatusBar(2, true, "Writing database '%s'...", name.c_str());
if(onelab::server::instance()->toFile(name))
Msg::StatusBar(2, true, "Done writing database '%s'", name.c_str());
else
Msg::Error("Could not write database '%s'", name.c_str());
}
static void loadDb(const std::string &name)
{
Msg::StatusBar(2, true, "Loading database '%s'...", name.c_str());
if(onelab::server::instance()->fromFile(name))
Msg::StatusBar(2, true, "Done loading database '%s'", name.c_str());
else
Msg::Error("Could not load database '%s'", name.c_str());
}
void onelab_cb(Fl_Widget *w, void *data) void onelab_cb(Fl_Widget *w, void *data)
{ {
if(!data) return; if(!data) return;
...@@ -419,30 +449,16 @@ void onelab_cb(Fl_Widget *w, void *data) ...@@ -419,30 +449,16 @@ void onelab_cb(Fl_Widget *w, void *data)
if(db[i][j] == onelab::parameter::charSep()) db[i][j] = '|'; if(db[i][j] == onelab::parameter::charSep()) db[i][j] = '|';
Msg::Direct("%s", db[i].c_str()); Msg::Direct("%s", db[i].c_str());
} }
std::string path = SplitFileName(GModel::current()->getFileName())[0]; std::string s = SplitFileName(GModel::current()->getFileName())[0] + "onelab.db";
if(fileChooser(FILE_CHOOSER_CREATE, "Save", "*.db", if(fileChooser(FILE_CHOOSER_CREATE, "Save", "*.db", s.c_str()))
(path + "onelab.db").c_str())){ writeDb(fileChooserGetName(1));
std::string name = fileChooserGetName(1);
Msg::StatusBar(2, true, "Writing database '%s'...", name.c_str());
if(onelab::server::instance()->toFile(name))
Msg::StatusBar(2, true, "Done writing database '%s'", name.c_str());
else
Msg::Error("Could not write database '%s'", name.c_str());
}
return; return;
} }
if(action == "load"){ if(action == "load"){
std::string path = SplitFileName(GModel::current()->getFileName())[0]; std::string s = SplitFileName(GModel::current()->getFileName())[0] + "onelab.db";
if(fileChooser(FILE_CHOOSER_SINGLE, "Load", "*.db", if(fileChooser(FILE_CHOOSER_SINGLE, "Load", "*.db", s.c_str()))
(path + "onelab.db").c_str())) { loadDb(fileChooserGetName(1));
std::string name = fileChooserGetName(1);
Msg::StatusBar(2, true, "Loading database '%s'...", name.c_str());
if(onelab::server::instance()->fromFile(name))
Msg::StatusBar(2, true, "Done loading database '%s'", name.c_str());
else
Msg::Error("Could not load database '%s'", name.c_str());
}
action = "check"; action = "check";
} }
...@@ -520,6 +536,12 @@ void onelab_cb(Fl_Widget *w, void *data) ...@@ -520,6 +536,12 @@ void onelab_cb(Fl_Widget *w, void *data)
} while(action == "compute" && !FlGui::instance()->onelab->stop() && } while(action == "compute" && !FlGui::instance()->onelab->stop() &&
incrementLoops()); incrementLoops());
bool autoSaveDb = false;
if(action == "compute" && autoSaveDb){
std::string s = SplitFileName(GModel::current()->getFileName())[0] + "onelab.db";
writeDb(s, true);
}
FlGui::instance()->onelab->stop(false); FlGui::instance()->onelab->stop(false);
FlGui::instance()->onelab->setButtonMode("check", "compute"); FlGui::instance()->onelab->setButtonMode("check", "compute");
if(action != "initialize") FlGui::instance()->onelab->show(); if(action != "initialize") FlGui::instance()->onelab->show();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment