From 2a5e71ad72ca36c12a8806de8b325f97a761ffc0 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 31 Jul 2001 09:51:36 +0000
Subject: [PATCH] Bug fixes and clean-ups in plugin code

---
 Common/DefaultOptions.h   |  2 +-
 Fltk/Callbacks.cpp        | 38 ++++++++++++++++++--------------
 Fltk/GUI.cpp              |  3 ++-
 Plugin/CutMap.cpp         | 41 ++++++++++++++++------------------
 Plugin/CutPlane.cpp       | 35 ++++++++++++++++-------------
 Plugin/CutPlane.h         |  2 ++
 Plugin/CutSphere.cpp      | 46 +++++++++++++++++++++++++++++----------
 Plugin/CutSphere.h        |  4 ++++
 Plugin/LevelsetPlugin.cpp | 19 ++++++++++------
 Plugin/Plugin.cpp         |  2 +-
 10 files changed, 117 insertions(+), 75 deletions(-)

diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index 07ee4658cf..b90f60319b 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -167,7 +167,7 @@ StringXNumber GeneralOptions_Number[] = {
     "Use trackball rotation mode" },
   { F|O, "ZoomFactor" , opt_general_zoom_factor , 1.1 ,
     "'Speed' of the middle mouse button zoom" },
-  { F|O, "DefaultPlugins" , opt_general_default_plugins , 0. ,
+  { F|O, "DefaultPlugins" , opt_general_default_plugins , 1. ,
     "Load default plugins on startup" },
   { F, "Clip0" , opt_general_clip0 , 0. ,
     "Enable clip plane 0" },
diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index 6076731ffc..3ee89a5b94 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.66 2001-07-30 18:34:26 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.67 2001-07-31 09:51:36 geuzaine Exp $
 
 #include <sys/types.h>
 #include <signal.h>
@@ -1585,25 +1585,31 @@ void view_options_cb(CALLBACK_ARGS){
 
 void view_plugin_cb(CALLBACK_ARGS){
   char name[256];
-  std::pair<int,GMSH_Plugin*> *pair =  (std::pair<int,GMSH_Plugin*>*)data;
+  std::pair<int,GMSH_Plugin*> *pair = (std::pair<int,GMSH_Plugin*>*)data;
   int iView = pair->first;
   GMSH_Post_Plugin *p = (GMSH_Post_Plugin*)pair->second;
   p->getName(name);
-  // here we should perhaps launch 
-  // a dialogbox for setting up Plugin 
-  // properties
-  try
-    {
-      Post_View *v = (Post_View*)List_Pointer(Post_ViewList,iView);
-      p->execute(v);
-      Msg(INFO,"Plugin %s was called win = %p",name,p->dialogBox);
-    }
-  catch (GMSH_Plugin *err)
-    {
-      p->CatchErrorMessage(name);
-      Msg(WARNING,"%s",name);
+
+  if(p->dialogBox){//Get the values from the GUI
+    int n = p->getNbOptions();
+    if(n > 20)Msg(GERROR,"Plugin has too much parameters");
+    for(int i=0;i<n;i++){
+      StringXNumber *sxn;
+      sxn = p->GetOption(i);
+      sxn->def = p->dialogBox->view_value[i]->value();
     }
-  //
+  }
+
+  try{
+    Post_View *v = (Post_View*)List_Pointer(Post_ViewList,iView);
+    p->execute(v);
+    Draw();
+    Msg(INFO,"Plugin %s was called win = %p",name,p->dialogBox);
+  }
+  catch (GMSH_Plugin *err){
+    p->CatchErrorMessage(name);
+    Msg(WARNING,"%s",name);
+  }
 }
 
 void view_options_plugin_cb(CALLBACK_ARGS){
diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index c7d65d6e54..d7d57a97e2 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -1,4 +1,4 @@
-// $Id: GUI.cpp,v 1.94 2001-07-31 07:51:42 geuzaine Exp $
+// $Id: GUI.cpp,v 1.95 2001-07-31 09:51:36 geuzaine Exp $
 
 // To make the interface as visually consistent as possible, please:
 // - use the BH, BW, WB, IW values for button heights/widths, window borders, etc.
@@ -1718,6 +1718,7 @@ PluginDialogBox * GUI::create_plugin_window(GMSH_Plugin *p, int iView)
       pdb->view_value[i]->textsize(CTX.fontsize);
       pdb->view_value[i]->type(FL_HORIZONTAL);
       pdb->view_value[i]->align(FL_ALIGN_RIGHT);
+      pdb->view_value[i]->value(sxn->def);
     }
 
   Fl_Button* cancel     = new Fl_Button(width-BB-WB, height-BH-WB, BB, BH, "Close");
diff --git a/Plugin/CutMap.cpp b/Plugin/CutMap.cpp
index 0186337139..638c2a733f 100644
--- a/Plugin/CutMap.cpp
+++ b/Plugin/CutMap.cpp
@@ -1,18 +1,19 @@
-// $Id: CutMap.cpp,v 1.7 2001-07-30 13:47:18 remacle Exp $
+// $Id: CutMap.cpp,v 1.8 2001-07-31 09:51:36 geuzaine Exp $
 
 #include "CutMap.h"
 #include "List.h"
 
 StringXNumber CutMapOptions_Number[] = {
-  { GMSH_FULLRC, "A" , NULL , 1. },
-  { GMSH_FULLRC, "iView" , NULL , 1. }
+  { GMSH_FULLRC, "Value" , NULL , 1. },
+  { GMSH_FULLRC, "View number" , NULL , 1. }
 };
 
 extern "C"
 {
   GMSH_Plugin *GMSH_RegisterCutMapPlugin ()
   {
-    return new GMSH_CutMapPlugin (1.5,1);
+    return new GMSH_CutMapPlugin (CutMapOptions_Number[0].def,
+				  (int)CutMapOptions_Number[1].def);
   }
 }
 
@@ -31,12 +32,13 @@ void GMSH_CutMapPlugin::getInfos(char *author, char *copyright, char *help_text)
 {
   strcpy(author,"J.-F. Remacle (remacle@scorec.rpi.edu)");
   strcpy(copyright,"DGR (www.multiphysics.com)");
-  strcpy(help_text,"This Plugins cuts a view \n with a plane (x-xc)^2 + (y-yc)^2 + (z-zc)^2  = r^20\n");
+  strcpy(help_text,
+	 "This Plugins extracts the isovalue surface of value 'Value'\n");
 }
 
 int GMSH_CutMapPlugin::getNbOptions() const
 {
-  return 5;
+  return sizeof(CutMapOptions_Number)/sizeof(StringXNumber);
 }
 
 StringXNumber *GMSH_CutMapPlugin:: GetOption (int iopt)
@@ -57,30 +59,25 @@ double GMSH_CutMapPlugin :: levelset (double x, double y, double z, double val)
   return A - val;
 }
 
- extern List_T *Post_ViewList;
+extern List_T *Post_ViewList;
 
 Post_View *GMSH_CutMapPlugin::execute (Post_View *v)
 {
 
-  printf("coucou 2\n");
-
   A = CutMapOptions_Number[0].def;
   iView = (int)CutMapOptions_Number[1].def;
   
-  printf("View %d iso %12.5E\n",iView,A);
-  if(v)return GMSH_LevelsetPlugin::execute(v);
-  else
-    {
-
-
-      if(List_Nbr(Post_ViewList) < iView)
-	{
-	  Msg(WARNING,"Plugin CutMap, view %d not loaded\n",iView);
-	  return 0;
-	}
-
-      return GMSH_LevelsetPlugin::execute((Post_View*)List_Pointer_Test(Post_ViewList,iView-1));
+  Msg(INFO, "View %d -> iso %g",iView, A);
+
+  if(v)
+    return GMSH_LevelsetPlugin::execute(v);
+  else{
+    if(List_Nbr(Post_ViewList) < iView){
+      Msg(WARNING,"Plugin CutMap, view %d not loaded\n",iView);
+      return 0;
     }
+    return GMSH_LevelsetPlugin::execute((Post_View*)List_Pointer_Test(Post_ViewList,iView-1));
+  }
 }
 
 
diff --git a/Plugin/CutPlane.cpp b/Plugin/CutPlane.cpp
index ba419f7406..ab3a201add 100644
--- a/Plugin/CutPlane.cpp
+++ b/Plugin/CutPlane.cpp
@@ -1,19 +1,24 @@
+// $Id: CutPlane.cpp,v 1.7 2001-07-31 09:51:36 geuzaine Exp $
+
 #include "CutPlane.h"
 #include "List.h"
 
 StringXNumber CutPlaneOptions_Number[] = {
   { GMSH_FULLRC, "A" , NULL , 1. },
-  { GMSH_FULLRC, "B" , NULL , 1. },
-  { GMSH_FULLRC, "C" , NULL , 1. },
-  { GMSH_FULLRC, "D" , NULL , 1. },
-  { GMSH_FULLRC, "iView" , NULL , 1. }
+  { GMSH_FULLRC, "B" , NULL , 0. },
+  { GMSH_FULLRC, "C" , NULL , 0. },
+  { GMSH_FULLRC, "D" , NULL , 0.01 },
+  { GMSH_FULLRC, "View number" , NULL , 1. }
 };
 
 extern "C"
 {
   GMSH_Plugin *GMSH_RegisterCutPlanePlugin ()
   {
-    return new GMSH_CutPlanePlugin (1.0,0.0,0.0,0.01);
+    return new GMSH_CutPlanePlugin (CutPlaneOptions_Number[0].def,
+				    CutPlaneOptions_Number[1].def,
+				    CutPlaneOptions_Number[2].def,
+				    CutPlaneOptions_Number[3].def);
   }
 }
 
@@ -37,7 +42,7 @@ void GMSH_CutPlanePlugin::getInfos(char *author, char *copyright, char *help_tex
 
 int GMSH_CutPlanePlugin::getNbOptions() const
 {
-  return 5;
+  return sizeof(CutPlaneOptions_Number)/sizeof(StringXNumber);
 }
 
 StringXNumber* GMSH_CutPlanePlugin:: GetOption (int iopt)
@@ -56,6 +61,7 @@ double GMSH_CutPlanePlugin :: levelset (double x, double y, double z, double val
 }
 
 extern List_T *Post_ViewList;
+
 Post_View *GMSH_CutPlanePlugin::execute (Post_View *v)
 {
 
@@ -65,16 +71,15 @@ Post_View *GMSH_CutPlanePlugin::execute (Post_View *v)
   d = CutPlaneOptions_Number[3].def;
   int iView = (int)CutPlaneOptions_Number[4].def;
 
-  if(v)return GMSH_LevelsetPlugin::execute(v);
-  else
-    {
-      if(List_Nbr(Post_ViewList) < iView)
-	{
-	  Msg(WARNING,"Plugin CutPlane, view %d not loaded\n",iView);
-	  return 0;
-	}
-      return GMSH_LevelsetPlugin::execute((Post_View*)List_Pointer_Test(Post_ViewList,iView-1));
+  if(v)
+    return GMSH_LevelsetPlugin::execute(v);
+  else{
+    if(List_Nbr(Post_ViewList) < iView){
+      Msg(WARNING,"Plugin CutPlane, view %d not loaded\n",iView);
+      return 0;
     }
+    return GMSH_LevelsetPlugin::execute((Post_View*)List_Pointer_Test(Post_ViewList,iView-1));
+  }
 }
 
 
diff --git a/Plugin/CutPlane.h b/Plugin/CutPlane.h
index 4a5d90910e..4575add1a9 100644
--- a/Plugin/CutPlane.h
+++ b/Plugin/CutPlane.h
@@ -1,5 +1,6 @@
 #ifndef _CUTPLANE_H_
 #define _CUTPLANE_H
+
 #include "LevelsetPlugin.h"
 
 extern "C"
@@ -23,4 +24,5 @@ public:
   virtual StringXNumber *GetOption (int iopt);  
   virtual Post_View *execute (Post_View *);
 };
+
 #endif
diff --git a/Plugin/CutSphere.cpp b/Plugin/CutSphere.cpp
index 830963df1c..a2eb1360fa 100644
--- a/Plugin/CutSphere.cpp
+++ b/Plugin/CutSphere.cpp
@@ -1,20 +1,25 @@
-// $Id: CutSphere.cpp,v 1.5 2001-07-30 13:22:21 geuzaine Exp $
+// $Id: CutSphere.cpp,v 1.6 2001-07-31 09:51:36 geuzaine Exp $
 
 #include <string.h>
 #include "CutSphere.h"
+#include "List.h"
 
 StringXNumber CutSphereOptions_Number[] = {
-  { GMSH_FULLRC, "Xc" , NULL , 1. },
-  { GMSH_FULLRC, "Yc" , NULL , 1. },
-  { GMSH_FULLRC, "Zc" , NULL , 1. },
-  { GMSH_FULLRC, "R" , NULL , 1. }
+  { GMSH_FULLRC, "Xc" , NULL , 0. },
+  { GMSH_FULLRC, "Yc" , NULL , 0. },
+  { GMSH_FULLRC, "Zc" , NULL , 0. },
+  { GMSH_FULLRC, "R" , NULL , 0.25 },
+  { GMSH_FULLRC, "View number" , NULL , 1. }
 };
 
 extern "C"
 {
   GMSH_Plugin *GMSH_RegisterCutSpherePlugin ()
   {
-    return new GMSH_CutSpherePlugin (0.0,0.0,0.0,.25);
+    return new GMSH_CutSpherePlugin (CutSphereOptions_Number[0].def,
+				     CutSphereOptions_Number[1].def,
+				     CutSphereOptions_Number[2].def,
+				     CutSphereOptions_Number[3].def);
   }
 }
 
@@ -33,12 +38,14 @@ void GMSH_CutSpherePlugin::getInfos(char *author, char *copyright, char *help_te
 {
   strcpy(author,"J.-F. Remacle (remacle@scorec.rpi.edu)");
   strcpy(copyright,"DGR (www.multiphysics.com)");
-  strcpy(help_text,"This Plugins cuts a view \n with a plane (x-xc)^2 + (y-yc)^2 + (z-zc)^2  = r^20\n");
+  strcpy(help_text,
+	 "This Plugins cuts a view\n"
+	 "with the sphere (x-xc)^2 + (y-yc)^2 + (z-zc)^2  = r^20\n");
 }
 
 int GMSH_CutSpherePlugin::getNbOptions() const
 {
-  return 4;
+  return sizeof(CutSphereOptions_Number)/sizeof(StringXNumber);
 }
 
 StringXNumber* GMSH_CutSpherePlugin:: GetOption (int iopt)
@@ -56,9 +63,24 @@ double GMSH_CutSpherePlugin :: levelset (double x, double y, double z, double va
   return (x-a)*(x-a) + (y-b)*(y-b) + (z-c)*(z-c) - r*r;
 }
 
+extern List_T *Post_ViewList;
 
+Post_View *GMSH_CutSpherePlugin::execute (Post_View *v)
+{
 
-
-
-
-
+  a = CutSphereOptions_Number[0].def;
+  b = CutSphereOptions_Number[1].def;
+  c = CutSphereOptions_Number[2].def;
+  r = CutSphereOptions_Number[3].def;
+  int iView = (int)CutSphereOptions_Number[4].def;
+
+  if(v)
+    return GMSH_LevelsetPlugin::execute(v);
+  else{
+    if(List_Nbr(Post_ViewList) < iView){
+      Msg(WARNING,"Plugin CutSphere, view %d not loaded\n",iView);
+      return 0;
+    }
+    return GMSH_LevelsetPlugin::execute((Post_View*)List_Pointer_Test(Post_ViewList,iView-1));
+  }
+}
diff --git a/Plugin/CutSphere.h b/Plugin/CutSphere.h
index 4c5907d917..bee21ba1e2 100644
--- a/Plugin/CutSphere.h
+++ b/Plugin/CutSphere.h
@@ -1,6 +1,8 @@
 #ifndef _CUTSPHERE_H_
 #define _CUTSPHERE_H
+
 #include "LevelsetPlugin.h"
+
 extern "C"
 {
   GMSH_Plugin *GMSH_RegisterCutSpherePlugin ();
@@ -20,5 +22,7 @@ public:
   virtual void CatchErrorMessage (char *errorMessage) const;
   virtual int getNbOptions() const;
   virtual StringXNumber* GetOption (int iopt);  
+  virtual Post_View *execute (Post_View *);
 };
+
 #endif
diff --git a/Plugin/LevelsetPlugin.cpp b/Plugin/LevelsetPlugin.cpp
index b5cd403c8b..7dd67e7fd4 100644
--- a/Plugin/LevelsetPlugin.cpp
+++ b/Plugin/LevelsetPlugin.cpp
@@ -1,3 +1,5 @@
+// $Id: LevelsetPlugin.cpp,v 1.7 2001-07-31 09:51:36 geuzaine Exp $
+
 #include "LevelsetPlugin.h"
 #include "List.h"
 #include "Views.h"
@@ -14,14 +16,17 @@ GMSH_LevelsetPlugin::GMSH_LevelsetPlugin()
 
 void GMSH_LevelsetPlugin::Save ()
 {
-  printf("coucou saving ...\n");
-  if(processed)
+  if(processed){
+    Msg(INFO, "Writing file '%s'", OutputFileName);
     Write_View(0, processed, OutputFileName);
+    Msg(INFO, "Levelset ouput complete '%s'", OutputFileName);
+    Msg(STATUS2, "Wrote '%s'", OutputFileName);
+  }
 }
 
 void GMSH_LevelsetPlugin::Run () 
 { 
-  printf("coucou running ...\n");
+  Msg(INFO, "Running Levelset plugin");
   execute (0);
 }
 
@@ -32,6 +37,7 @@ Post_View *GMSH_LevelsetPlugin::execute (Post_View *v)
     a cut of the actual view with a levelset.
    */
   int k,i,nb,edtet[6][2] = {{0,1},{0,2},{0,3},{1,2},{1,3},{2,3}};
+
   //   for all scalar simplices 
 
   if(v->NbSS)
@@ -94,14 +100,13 @@ Post_View *GMSH_LevelsetPlugin::execute (Post_View *v)
       sprintf(filename,"cut-%s",v->FileName);
       EndView(1, filename, name);
       
-      printf("okay\n");
-
-      Msg(INFO, "new %s view with %d tris\n",name,List_Nbr(ActualView->ST));
+      Msg(INFO, "Levelset plugin OK: created view '%s' (%d triangles)",
+	  name, List_Nbr(ActualView->ST));
       processed = ActualView;
       return ActualView;
     }
 
-  Msg(INFO, "nothing ta da\n");
+  Msg(INFO, "Levelset plugin: nothing to do");
 
   return 0;
 }
diff --git a/Plugin/Plugin.cpp b/Plugin/Plugin.cpp
index bfe3d55dd2..883712187b 100644
--- a/Plugin/Plugin.cpp
+++ b/Plugin/Plugin.cpp
@@ -150,7 +150,7 @@ void GMSH_PluginManager::RegisterDefaultPlugins()
 void GMSH_PluginManager::AddPlugin( char *dirName, char *pluginName)
 {
 #if ( defined(WIN32) && !defined(__CYGWIN__) ) || defined(_NODLL)
-  Msg(WARNING,"Plugins not yet implemented for WIN32 native compiler");
+  Msg(WARNING,"Plugins not yet implemented on this platform");
   return;
 #else
   char dynamic_lib[1024];
-- 
GitLab