diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp index 15f8edf9ccb5590646cf590f2c669f99a360e211..8e7556bce22a0cabe8217ff888cab4f4c41bb75d 100644 --- a/Fltk/graphicWindow.cpp +++ b/Fltk/graphicWindow.cpp @@ -618,7 +618,27 @@ void geometry_reload_cb(Fl_Widget *w, void *data) void geometry_remove_last_command_cb(Fl_Widget *w, void *data) { std::string fileName = GModel::current()->getFileName(); - // TODO! + // FIXME: make this work with compressed files + std::ifstream t(fileName); + std::stringstream buffer; + buffer << t.rdbuf(); + std::string s(buffer.str()); + int found = s.rfind("//+"); + if(found != std::string::npos){ + s.erase(found); + } + else{ + Msg::Warning("Could not find last command in script `%s'", fileName.c_str()); + return; + } + FILE *fp = Fopen(fileName.c_str(), "w"); + if(fp){ + fprintf(fp, "%s", s.c_str()); + fclose(fp); + } + else{ + Msg::Error("Could not open file `%s'", fileName.c_str()); + } OpenProject(fileName); drawContext::global()->draw(); } @@ -3746,13 +3766,11 @@ static menuItem static_modules[] = { (Fl_Callback *)geometry_physical_remove_cb, (void*)"Volume" } , {"0Modules/Geometry/Coherence", (Fl_Callback *)geometry_elementary_coherence_cb} , - {"0Modules/Geometry/Reload", + {"0Modules/Geometry/Reload script", (Fl_Callback *)geometry_reload_cb} , - /* FIXME: toto - {"0Modules/Geometry/Remove last command in file", + {"0Modules/Geometry/Remove last script command", (Fl_Callback *)geometry_remove_last_command_cb} , - */ - {"0Modules/Geometry/Edit file", + {"0Modules/Geometry/Edit script", (Fl_Callback *)geometry_edit_cb} , {"0Modules/Mesh/Define/Size fields", (Fl_Callback *)field_cb}, diff --git a/Geo/GeoStringInterface.cpp b/Geo/GeoStringInterface.cpp index 885079b69422d6df29d647f0e618247d2f7fdd88..004c53acfbaeb607d985ea198956b50d26095886 100644 --- a/Geo/GeoStringInterface.cpp +++ b/Geo/GeoStringInterface.cpp @@ -113,7 +113,7 @@ void add_infile(const std::string &text, const std::string &fileName, bool force Msg::Error("Unable to open file '%s'", fileName.c_str()); return; } - gmshprintf(fp, "%s\n", text.c_str()); + gmshprintf(fp, "//+\n%s\n", text.c_str()); gmshclose(fp); } else{ @@ -122,7 +122,7 @@ void add_infile(const std::string &text, const std::string &fileName, bool force Msg::Error("Unable to open file '%s'", fileName.c_str()); return; } - fprintf(fp, "%s\n", text.c_str()); + fprintf(fp, "//+\n%s\n", text.c_str()); fclose(fp); } #else @@ -131,7 +131,7 @@ void add_infile(const std::string &text, const std::string &fileName, bool force Msg::Error("Unable to open file '%s'", fileName.c_str()); return; } - fprintf(fp, "%s\n", text.c_str()); + fprintf(fp, "//+\n%s\n", text.c_str()); fclose(fp); #endif diff --git a/doc/VERSIONS.txt b/doc/VERSIONS.txt index 8ed30eac5103312f5164e4e0700573219e687a94..c9c52ca78971c75603ce45b9f5770704ee9c0d3b 100644 --- a/doc/VERSIONS.txt +++ b/doc/VERSIONS.txt @@ -1,3 +1,6 @@ +2.13.3: new Tochnog file format export; added ability to remove last command in +scripts generated interactively. + 2.13.2 (August 18, 2016)): small improvements (scale labels, periodic and high-order meshes) and bug fixes.