From 9950dcb2a8f5034447e29bac873a005dc1d37f0c Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 28 Oct 2004 08:13:09 +0000
Subject: [PATCH] New options to enable/desable all default
 post-processing/solver plugins

---
 Common/Context.h        |  4 +--
 Common/DefaultOptions.h |  6 ++++
 Common/Options.cpp      | 16 ++++++++-
 Common/Options.h        |  2 ++
 Fltk/Main.cpp           | 12 ++++---
 Fltk/Makefile           |  4 +--
 Plugin/Makefile         |  5 +--
 Plugin/Plugin.cpp       | 80 +++++++++++++++++++++--------------------
 8 files changed, 78 insertions(+), 51 deletions(-)

diff --git a/Common/Context.h b/Common/Context.h
index 744ac46fc6..b7dea14908 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -197,13 +197,13 @@ public :
     int force_num, compute_bb, vertex_arrays;
     int draw, scales, link, horizontal_scales ;
     int smooth, anim_cycle, combine_time, combine_remove_orig ;
-    int file_format;
+    int file_format, plugins;
     double anim_delay ;
   }post;
 
   // solver options 
   struct{
-    int max_delay ;
+    int max_delay, plugins ;
   }solver;
 
   // print options 
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index 324dfa5823..7245542be8 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -888,6 +888,9 @@ StringXNumber SolverOptions_Number[] = {
   { F|O, "MaximumDelay" , opt_solver_max_delay , 4.0 ,
     "Maximum delay allowed for solver response (in seconds)" },
 
+  { F|O, "Plugins" , opt_solver_plugins , 0. ,
+    "Enable default solver plugins?" },
+
   { F|O, "ClientServer0" , opt_solver_client_server0 , 1. ,
     "Connect solver 0 to the Gmsh server" },
   { F|O, "MergeViews0" , opt_solver_merge_views0 , 1. , 
@@ -952,6 +955,9 @@ StringXNumber PostProcessingOptions_Number[] = {
   { F,   "NbViews" , opt_post_nb_views , 0. ,//this default val is not used
     "Current number of views merged" },
 
+  { F|O, "Plugins" , opt_post_plugins , 1. ,
+    "Enable default post-processing plugins?" },
+
   { F|O, "Scales" , opt_post_scales , 1. , 
     "Show value scales" },
   { F|O, "Smoothing" , opt_post_smooth , 0. ,
diff --git a/Common/Options.cpp b/Common/Options.cpp
index aafd143168..bc56d956a9 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.196 2004-10-26 01:04:50 geuzaine Exp $
+// $Id: Options.cpp,v 1.197 2004-10-28 08:13:09 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -4107,6 +4107,13 @@ double opt_solver_max_delay(OPT_ARGS_NUM)
   return CTX.solver.max_delay;
 }
 
+double opt_solver_plugins(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET)
+    CTX.solver.plugins = (int)val;
+  return CTX.solver.plugins;
+}
+
 double opt_solver_client_server(OPT_ARGS_NUM)
 {
 #if defined(HAVE_FLTK)
@@ -4304,6 +4311,13 @@ double opt_post_combine_remove_orig(OPT_ARGS_NUM)
   return CTX.post.combine_remove_orig;
 }
 
+double opt_post_plugins(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET)
+    CTX.post.plugins = (int)val;
+  return CTX.post.plugins;
+}
+
 double opt_post_nb_views(OPT_ARGS_NUM)
 {
   return List_Nbr(CTX.post.list);
diff --git a/Common/Options.h b/Common/Options.h
index 63bf21b7c3..afb56e82a6 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -422,6 +422,7 @@ double opt_mesh_nb_prisms(OPT_ARGS_NUM);
 double opt_mesh_nb_pyramids(OPT_ARGS_NUM);
 double opt_mesh_cpu_time(OPT_ARGS_NUM);
 double opt_solver_max_delay(OPT_ARGS_NUM);
+double opt_solver_plugins(OPT_ARGS_NUM);
 double opt_solver_client_server(OPT_ARGS_NUM);
 double opt_solver_client_server0(OPT_ARGS_NUM);
 double opt_solver_client_server1(OPT_ARGS_NUM);
@@ -448,6 +449,7 @@ double opt_post_smooth(OPT_ARGS_NUM);
 double opt_post_anim_delay(OPT_ARGS_NUM);
 double opt_post_anim_cycle(OPT_ARGS_NUM);
 double opt_post_combine_remove_orig(OPT_ARGS_NUM);
+double opt_post_plugins(OPT_ARGS_NUM);
 double opt_post_nb_views(OPT_ARGS_NUM);
 double opt_post_file_format(OPT_ARGS_NUM);
 double opt_view_nb_timestep(OPT_ARGS_NUM);
diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp
index ebf6de3ae2..2bd70952a3 100644
--- a/Fltk/Main.cpp
+++ b/Fltk/Main.cpp
@@ -1,4 +1,4 @@
-// $Id: Main.cpp,v 1.72 2004-09-28 17:13:49 geuzaine Exp $
+// $Id: Main.cpp,v 1.73 2004-10-28 08:13:09 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -88,13 +88,11 @@ int main(int argc, char *argv[])
   M.BGM.bgm = NULL;
   M.Grid.init = 0;
 
-  // Initialize the default plugins
-
-  GMSH_PluginManager::instance()->registerDefaultPlugins();
-
   // Generate automatic documentation (before getting user-defined options)
   
   if(argc == 2 && !strcmp(argv[1], "-doc")){
+    // force all plugins for the doc
+    GMSH_PluginManager::instance()->registerDefaultPlugins();
     Print_OptionsDoc();
     exit(0);
   }
@@ -114,6 +112,10 @@ int main(int argc, char *argv[])
   signal(SIGSEGV, Signal);
   signal(SIGFPE, Signal);
 
+  // Initialize the default plugins
+
+  GMSH_PluginManager::instance()->registerDefaultPlugins();
+
   // Non-interactive Gmsh
 
   if(CTX.batch) {
diff --git a/Fltk/Makefile b/Fltk/Makefile
index c67721718c..766321366d 100644
--- a/Fltk/Makefile
+++ b/Fltk/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.59 2004-10-28 06:11:22 geuzaine Exp $
+# $Id: Makefile,v 1.60 2004-10-28 08:13:09 geuzaine Exp $
 #
 # Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 #
@@ -108,7 +108,7 @@ Callbacks.o: Callbacks.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../Parser/OpenFile.h ../Common/CommandLine.h ../Common/Context.h \
   ../Common/Options.h GUI.h Opengl_Window.h Colorbar_Window.h \
   File_Picker.h Callbacks.h ../Plugin/Plugin.h ../Plugin/PluginManager.h \
-  ../Common/Visibility.h ../Geo/MinMax.h Solvers.h
+  ../Common/Visibility.h ../Geo/MinMax.h ../Numeric/Numeric.h Solvers.h
 Opengl.o: Opengl.cpp ../Common/Gmsh.h ../Common/Message.h \
   ../DataStr/Malloc.h ../DataStr/List.h ../DataStr/Tree.h \
   ../DataStr/avl.h ../DataStr/Tools.h ../Common/GmshUI.h \
diff --git a/Plugin/Makefile b/Plugin/Makefile
index e7a15077ab..7dadbe3d34 100644
--- a/Plugin/Makefile
+++ b/Plugin/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.56 2004-10-28 06:11:23 geuzaine Exp $
+# $Id: Makefile,v 1.57 2004-10-28 08:13:09 geuzaine Exp $
 #
 # Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 #
@@ -76,7 +76,8 @@ Plugin.o: Plugin.cpp Plugin.h ../Common/Options.h ../Common/Message.h \
   SphericalRaise.h DisplacementRaise.h StructuralSolver.h ../Geo/Geo.h \
   ../Mesh/Mesh.h ../Mesh/Vertex.h ../Mesh/Element.h ../Mesh/Simplex.h \
   ../Mesh/Face.h ../Mesh/Edge.h ../Geo/ExtrudeParams.h ../Mesh/STL.h \
-  ../Mesh/Metric.h ../Mesh/Matrix.h ../Common/GmshUI.h Evaluate.h
+  ../Mesh/Metric.h ../Mesh/Matrix.h ../Common/GmshUI.h Evaluate.h \
+  ../Common/Context.h
 Levelset.o: Levelset.cpp Levelset.h Plugin.h ../Common/Options.h \
   ../Common/Message.h ../Common/Views.h ../Common/ColorTable.h \
   ../DataStr/List.h ../Common/VertexArray.h ../Common/SmoothNormals.h \
diff --git a/Plugin/Plugin.cpp b/Plugin/Plugin.cpp
index 4e6b63be8b..958f42301d 100644
--- a/Plugin/Plugin.cpp
+++ b/Plugin/Plugin.cpp
@@ -1,4 +1,4 @@
-// $Id: Plugin.cpp,v 1.60 2004-10-28 03:40:16 geuzaine Exp $
+// $Id: Plugin.cpp,v 1.61 2004-10-28 08:13:09 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -49,9 +49,12 @@
 #include "DisplacementRaise.h"
 #include "StructuralSolver.h"
 #include "Evaluate.h"
+#include "Context.h"
 
 using namespace std;
 
+extern Context_T CTX;
+
 const char *GMSH_PluginEntry = "GMSH_RegisterPlugin";
 
 GMSH_PluginManager *GMSH_PluginManager::_instance = 0;
@@ -76,12 +79,6 @@ GMSH_Plugin *GMSH_PluginManager::find(char *pluginName)
 
 GMSH_Solve_Plugin *GMSH_PluginManager::findSolverPlugin()
 {
-  // to avoid showing the solver plugin popups for "regular" users,
-  // let's just say for the moment that we don't have any solver
-  // plugins if the environment variable is not defined...
-  if(!getenv("GMSHPLUGINSHOME"))
-    return 0;
-
   iter it  = allPlugins.begin();
   iter ite = allPlugins.end();
   for (;it!=ite;++it) {
@@ -159,43 +156,48 @@ GMSH_PluginManager *GMSH_PluginManager::instance()
 void GMSH_PluginManager::registerDefaultPlugins()
 {
   // SOLVE PLUGINS
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-    		    ("StructuralSolver", GMSH_RegisterStructuralSolverPlugin()));
+  if(CTX.solver.plugins){
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("StructuralSolver", GMSH_RegisterStructuralSolverPlugin()));
+  }
+
   // POST PLUGINS
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("StreamLines", GMSH_RegisterStreamLinesPlugin()));
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("CutGrid", GMSH_RegisterCutGridPlugin()));
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("CutMap", GMSH_RegisterCutMapPlugin()));
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("CutPlane", GMSH_RegisterCutPlanePlugin()));
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("CutSphere", GMSH_RegisterCutSpherePlugin()));
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("Skin", GMSH_RegisterSkinPlugin()));
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("Extract", GMSH_RegisterExtractPlugin()));
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("DecomposeInSimplex", GMSH_RegisterDecomposeInSimplexPlugin()));
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("Smooth", GMSH_RegisterSmoothPlugin()));
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("Transform", GMSH_RegisterTransformPlugin()));
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("SphericalRaise", GMSH_RegisterSphericalRaisePlugin()));
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("DisplacementRaise", GMSH_RegisterDisplacementRaisePlugin()));
+  if(CTX.post.plugins){
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("StreamLines", GMSH_RegisterStreamLinesPlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("CutGrid", GMSH_RegisterCutGridPlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("CutMap", GMSH_RegisterCutMapPlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("CutPlane", GMSH_RegisterCutPlanePlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("CutSphere", GMSH_RegisterCutSpherePlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("Skin", GMSH_RegisterSkinPlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("Extract", GMSH_RegisterExtractPlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("DecomposeInSimplex", GMSH_RegisterDecomposeInSimplexPlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("Smooth", GMSH_RegisterSmoothPlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("Transform", GMSH_RegisterTransformPlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("SphericalRaise", GMSH_RegisterSphericalRaisePlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("DisplacementRaise", GMSH_RegisterDisplacementRaisePlugin()));
 #if defined(HAVE_TRIANGLE)
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("Triangulate", GMSH_RegisterTriangulatePlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("Triangulate", GMSH_RegisterTriangulatePlugin()));
 #endif
 #if defined(HAVE_MATH_EVAL)
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("Evaluate", GMSH_RegisterEvaluatePlugin()));
-  allPlugins.insert(std::pair < char *, GMSH_Plugin * >
-		    ("CutParametric", GMSH_RegisterCutParametricPlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("Evaluate", GMSH_RegisterEvaluatePlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("CutParametric", GMSH_RegisterCutParametricPlugin()));
 #endif
+  }
 
 #if defined(HAVE_FLTK)
   struct dirent **list;
-- 
GitLab