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

add way to remove last command in script generated interactively

parent b0a12a6d
No related branches found
No related tags found
No related merge requests found
......@@ -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},
......
......@@ -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
......
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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment