Hi,
my colleagues complained about saving and loading options for data
files. I know, it is possible to save and load with .opt file, but it
would be nice to have it easier. I added one extra item fo File menu. It
is called "Save File Options":

http://dl.getdropbox.com/u/369894/Save_file_options.png

I used data file Melechov-mini.pos in this example and it saved my "file
options" to file Melechov-mini.pos.opt. When I wanted to load this data
file again:

http://dl.getdropbox.com/u/369894/open_file_with_options.png

then my setting was automatically loaded from Melechov-mini.pos.opt. I
attached patch to this e-mail. This patch was created from last night
cvs snapshot. I hope, that you will find it useful :-).

Best Regards,

Jiri

diff -r -u gmsh-2.3.0-cvs-20090108/Common/Options.cpp devel/Common/Options.cpp
--- gmsh-2.3.0-cvs-20090108/Common/Options.cpp	2009-01-08 00:02:55.000000000 +0100
+++ devel/Common/Options.cpp	2009-01-08 12:52:24.000000000 +0100
@@ -655,7 +655,7 @@
     fprintf(file, "// This file contains configuration options (preferences) that\n");
     fprintf(file, "// are loaded each time Gmsh is launched. You can create this\n");
     fprintf(file, "// file by hand, or let Gmsh generate it for you (with\n");
-    fprintf(file, "// 'Tools->Options->Save as defaults'). This file can also be\n");
+    fprintf(file, "// 'File->Save Default Options'). This file can also be\n");
     fprintf(file, "// automatically saved every time you quit Gmsh if the option\n");
     fprintf(file, "// 'General.SaveOptions' is set.\n");
     fprintf(file, "//\n");
diff -r -u gmsh-2.3.0-cvs-20090108/Fltk/menuWindow.cpp devel/Fltk/menuWindow.cpp
--- gmsh-2.3.0-cvs-20090108/Fltk/menuWindow.cpp	2009-01-08 00:02:56.000000000 +0100
+++ devel/Fltk/menuWindow.cpp	2009-01-08 15:34:25.000000000 +0100
@@ -121,7 +121,15 @@
 {
   int n = PView::list.size();
   if(file_chooser(0, 0, "Open", input_formats)) {
-    OpenProject(file_chooser_get_name(1));
+	std::string filename = file_chooser_get_name(1);
+	std::string option_filename = filename + std::string(".opt");
+	FILE *fp = fopen(option_filename.c_str(), "rb");
+	// Stupid (but multiplatform) test, if .opt file exist
+	if(fp) {
+		fclose(fp);
+		OpenProject(option_filename);
+	}
+	OpenProject(filename);
     Draw();
   }
   if(n != (int)PView::list.size())
@@ -2144,6 +2152,7 @@
     {"&Rename...",  FL_CTRL+'r', (Fl_Callback *)file_rename_cb, 0},
     {"Save &As...", FL_CTRL+'s', (Fl_Callback *)file_save_as_cb, 0},
     {"Sa&ve Mesh",  FL_CTRL+FL_SHIFT+'s', (Fl_Callback *)mesh_save_cb, 0},
+    {"Save File Options", 0, (Fl_Callback *)file_options_save_cb, 0},
     {"Save Default Options", 0, (Fl_Callback *)options_save_cb, 0, FL_MENU_DIVIDER},
     {"&Quit",       FL_CTRL+'q', (Fl_Callback *)file_quit_cb, 0},
     {0},
@@ -2187,6 +2196,7 @@
     {"Rename...",  FL_META+'r', (Fl_Callback *)file_rename_cb, 0},
     {"Save As...", FL_META+'s', (Fl_Callback *)file_save_as_cb, 0},
     {"Save Mesh",  FL_META+FL_SHIFT+'s', (Fl_Callback *)mesh_save_cb, 0},
+    {"Save File Options", 0, (Fl_Callback *)file_options_save_cb, 0},
     {"Save Default Options", 0, (Fl_Callback *)options_save_cb, 0},
     {0},
   {"Tools", 0, 0, 0, FL_SUBMENU},
diff -r -u gmsh-2.3.0-cvs-20090108/Fltk/optionWindow.cpp devel/Fltk/optionWindow.cpp
--- gmsh-2.3.0-cvs-20090108/Fltk/optionWindow.cpp	2009-01-08 00:02:56.000000000 +0100
+++ devel/Fltk/optionWindow.cpp	2009-01-08 15:51:50.000000000 +0100
@@ -24,6 +24,7 @@
 #include "PViewOptions.h"
 #include "OS.h"
 #include "Context.h"
+#include "fileDialogs.h"
 
 extern Context_T CTX;
 
@@ -140,6 +141,13 @@
   GUI::instance()->options->showGroup(GUI::instance()->options->browser->value());
 }
 
+// save file option to .opt file (it uses file name of last opened file)
+void file_options_save_cb(Fl_Widget *w, void *data)
+{
+	std::string option_file_name = GModel::current()->getFileName() + std::string(".opt");
+	options_dialog((option_file_name).c_str());
+}
+
 void options_save_cb(Fl_Widget *w, void *data)
 {
   Msg::StatusBar(2, true, "Writing '%s'",
diff -r -u gmsh-2.3.0-cvs-20090108/Fltk/optionWindow.h devel/Fltk/optionWindow.h
--- gmsh-2.3.0-cvs-20090108/Fltk/optionWindow.h	2009-01-04 00:02:55.000000000 +0100
+++ devel/Fltk/optionWindow.h	2009-01-08 13:23:29.000000000 +0100
@@ -93,6 +93,7 @@
 };
 
 void options_cb(Fl_Widget *w, void *data);
+void file_options_save_cb(Fl_Widget *w, void *data);
 void options_save_cb(Fl_Widget *w, void *data);
 void general_options_cb(Fl_Widget *w, void *data);
 void geometry_options_cb(Fl_Widget *w, void *data);

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
gmsh mailing list
[email protected]
http://www.geuz.org/mailman/listinfo/gmsh

Reply via email to