From 7cee97bd5895ccf7414fce22d904f20738acd17f Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 6 Aug 2001 09:44:22 +0000
Subject: [PATCH] Fix interactive plugin calling

---
 Fltk/Callbacks.cpp   | 14 ++++++--------
 Fltk/GUI.cpp         | 12 +++++-------
 Fltk/GUI.h           |  3 ++-
 Plugin/CutMap.cpp    |  4 ++--
 Plugin/CutPlane.cpp  |  4 ++--
 Plugin/CutSphere.cpp |  4 ++--
 Plugin/Skin.cpp      |  4 ++--
 Plugin/Smooth.cpp    |  5 +++--
 Plugin/Transform.cpp |  4 ++--
 9 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index efbf569173..f736e251de 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.74 2001-08-04 01:16:58 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.75 2001-08-06 09:44:22 geuzaine Exp $
 
 #include <sys/types.h>
 #include <signal.h>
@@ -1635,7 +1635,6 @@ void view_plugin_cb(CALLBACK_ARGS){
     Post_View *v = (Post_View*)List_Pointer(Post_ViewList,iView);
     p->execute(v);
     Draw();
-    Msg(DEBUG, "Plugin %s was called win = %p",name,p->dialogBox);
   }
   catch (GMSH_Plugin *err){
     p->CatchErrorMessage(name);
@@ -1645,17 +1644,16 @@ void view_plugin_cb(CALLBACK_ARGS){
 
 void view_options_plugin_cb(CALLBACK_ARGS){
   std::pair<int,GMSH_Plugin*> *pair =  (std::pair<int,GMSH_Plugin*>*)data;
-  int iView = pair->first;
   GMSH_Plugin *p = pair->second;
 
-  if(!p->dialogBox)p->dialogBox = WID->create_plugin_window(p,iView);
+  if(!p->dialogBox)p->dialogBox = WID->create_plugin_window(p);
 
-  Fl_Window *pwindow = p->dialogBox->main_window;
+  p->dialogBox->run_button->callback(view_plugin_cb, (void*)pair);
 
-  if(pwindow->shown())
-    pwindow->redraw();
+  if(p->dialogBox->main_window->shown())
+    p->dialogBox->main_window->redraw();
   else
-    pwindow->show();    
+    p->dialogBox->main_window->show();    
 }
 
 void view_options_custom_cb(CALLBACK_ARGS){
diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index 63747aaf4d..ebf86a0dfb 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -1,4 +1,4 @@
-// $Id: GUI.cpp,v 1.103 2001-08-04 01:16:58 geuzaine Exp $
+// $Id: GUI.cpp,v 1.104 2001-08-06 09:44:22 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.
@@ -542,7 +542,7 @@ void GUI::wait(){
 //********************************* Create the menu window *****************************
 
 
-void GUI::add_post_plugins ( Fl_Menu_Button *button , int iView){
+void GUI::add_post_plugins (Fl_Menu_Button *button , int iView){
   char name[256],menuname[256];
   for(GMSH_PluginManager::iter it = GMSH_PluginManager::Instance()->begin();
       it != GMSH_PluginManager::Instance()->end();
@@ -1702,7 +1702,7 @@ void GUI::add_multiline_in_browser(Fl_Browser *o, char* prefix, char *str){
   }
 }
 
-PluginDialogBox * GUI::create_plugin_window(GMSH_Plugin *p, int iView){
+PluginDialogBox * GUI::create_plugin_window(GMSH_Plugin *p){
   char buffer[1024],namep[1024],copyright[256],author[256],help[1024];
 
   // get plugin info
@@ -1710,7 +1710,6 @@ PluginDialogBox * GUI::create_plugin_window(GMSH_Plugin *p, int iView){
   int n = p->getNbOptions();
   p->getName(namep);
   p->getInfos(author,copyright,help);
-  std::pair<int,GMSH_Plugin*> *pair = new std::pair<int,GMSH_Plugin*>(iView,p);
 
   // create window
 
@@ -1772,9 +1771,8 @@ PluginDialogBox * GUI::create_plugin_window(GMSH_Plugin *p, int iView){
   cancel->labelsize(CTX.fontsize);
   cancel->callback(cancel_cb, (void*)pdb->main_window);
 
-  Fl_Button* ok = new Fl_Return_Button(width-2*BB-2*WB, height-BH-WB, BB, BH, "Run");
-  ok->labelsize(CTX.fontsize);
-  ok->callback(view_plugin_cb, (void*)pair);
+  pdb->run_button = new Fl_Return_Button(width-2*BB-2*WB, height-BH-WB, BB, BH, "Run");
+  pdb->run_button->labelsize(CTX.fontsize);
 
   if(CTX.center_windows)
     pdb->main_window->position(m_window->x()+m_window->w()/2-width/2,
diff --git a/Fltk/GUI.h b/Fltk/GUI.h
index 1f9079073d..79c601a8ac 100644
--- a/Fltk/GUI.h
+++ b/Fltk/GUI.h
@@ -71,6 +71,7 @@ class GMSH_Plugin;
 struct PluginDialogBox
 {
   Fl_Window *main_window;
+  Fl_Return_Button *run_button;
   int nb_viewvalue;
   Fl_Value_Input *view_value[20];
 };
@@ -194,7 +195,7 @@ public:
   void create_mesh_options_window();
   void create_solver_options_window();
   void create_post_options_window();
-  PluginDialogBox *create_plugin_window(GMSH_Plugin *, int);
+  PluginDialogBox *create_plugin_window(GMSH_Plugin *p);
   void create_view_options_window(int numview);
   void create_statistics_window();
   void create_message_window();
diff --git a/Plugin/CutMap.cpp b/Plugin/CutMap.cpp
index 6b25544945..79a04fb841 100644
--- a/Plugin/CutMap.cpp
+++ b/Plugin/CutMap.cpp
@@ -1,4 +1,4 @@
-// $Id: CutMap.cpp,v 1.14 2001-08-06 08:09:51 geuzaine Exp $
+// $Id: CutMap.cpp,v 1.15 2001-08-06 09:44:22 geuzaine Exp $
 
 #include "CutMap.h"
 #include "List.h"
@@ -74,7 +74,7 @@ Post_View *GMSH_CutMapPlugin::execute (Post_View *v)
     return GMSH_LevelsetPlugin::execute(v);
   else{
     if(List_Nbr(Post_ViewList) < iView){
-      Msg(WARNING,"Plugin CutMap, view %d not loaded\n",iView);
+      Msg(WARNING,"Plugin CutMap, view %d not loaded",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 7a22a20f21..b1406c1e68 100644
--- a/Plugin/CutPlane.cpp
+++ b/Plugin/CutPlane.cpp
@@ -1,4 +1,4 @@
-// $Id: CutPlane.cpp,v 1.12 2001-08-06 08:09:51 geuzaine Exp $
+// $Id: CutPlane.cpp,v 1.13 2001-08-06 09:44:22 geuzaine Exp $
 
 #include "CutPlane.h"
 #include "List.h"
@@ -78,7 +78,7 @@ Post_View *GMSH_CutPlanePlugin::execute (Post_View *v)
     return GMSH_LevelsetPlugin::execute(v);
   else{
     if(List_Nbr(Post_ViewList) < iView){
-      Msg(WARNING,"Plugin CutPlane, view %d not loaded\n",iView);
+      Msg(WARNING,"Plugin CutPlane, view %d not loaded",iView);
       return 0;
     }
     return GMSH_LevelsetPlugin::execute((Post_View*)List_Pointer_Test(Post_ViewList,iView-1));
diff --git a/Plugin/CutSphere.cpp b/Plugin/CutSphere.cpp
index 025a2025bd..9429fb624c 100644
--- a/Plugin/CutSphere.cpp
+++ b/Plugin/CutSphere.cpp
@@ -1,4 +1,4 @@
-// $Id: CutSphere.cpp,v 1.11 2001-08-06 08:09:51 geuzaine Exp $
+// $Id: CutSphere.cpp,v 1.12 2001-08-06 09:44:22 geuzaine Exp $
 
 #include <string.h>
 #include "CutSphere.h"
@@ -79,7 +79,7 @@ Post_View *GMSH_CutSpherePlugin::execute (Post_View *v)
     return GMSH_LevelsetPlugin::execute(v);
   else{
     if(List_Nbr(Post_ViewList) < iView){
-      Msg(WARNING,"Plugin CutSphere, view %d not loaded\n",iView);
+      Msg(WARNING,"Plugin CutSphere, view %d not loaded",iView);
       return 0;
     }
     return GMSH_LevelsetPlugin::execute((Post_View*)List_Pointer_Test(Post_ViewList,iView-1));
diff --git a/Plugin/Skin.cpp b/Plugin/Skin.cpp
index 4e0ec205de..aafa1024e2 100644
--- a/Plugin/Skin.cpp
+++ b/Plugin/Skin.cpp
@@ -1,4 +1,4 @@
-// $Id: Skin.cpp,v 1.1 2001-08-06 08:12:00 geuzaine Exp $
+// $Id: Skin.cpp,v 1.2 2001-08-06 09:44:22 geuzaine Exp $
 
 #include "Plugin.h"
 #include "Skin.h"
@@ -120,7 +120,7 @@ Post_View *GMSH_SkinPlugin::execute (Post_View *v)
     vv = v;
   else{
     if(List_Nbr(Post_ViewList) < iView){
-      Msg(WARNING,"Plugin CutPlane, view %d not loaded\n",iView);
+      Msg(WARNING,"Plugin CutPlane, view %d not loaded",iView);
       return 0;
     }
     vv = (Post_View*)List_Pointer_Test(Post_ViewList,iView-1);
diff --git a/Plugin/Smooth.cpp b/Plugin/Smooth.cpp
index 4e5458f752..9fe472f112 100644
--- a/Plugin/Smooth.cpp
+++ b/Plugin/Smooth.cpp
@@ -1,4 +1,4 @@
-// $Id: Smooth.cpp,v 1.1 2001-08-06 08:12:00 geuzaine Exp $
+// $Id: Smooth.cpp,v 1.2 2001-08-06 09:44:22 geuzaine Exp $
 
 #include "Plugin.h"
 #include "Smooth.h"
@@ -63,12 +63,13 @@ Post_View *GMSH_SmoothPlugin::execute (Post_View *v)
     vv = v;
   else{
     if(List_Nbr(Post_ViewList) < iView){
-      Msg(WARNING,"Plugin Smooth, view %d not loaded\n",iView);
+      Msg(WARNING,"Plugin Smooth, view %d not loaded",iView);
       return 0;
     }
     vv = (Post_View*)List_Pointer_Test(Post_ViewList,iView-1);
   }
 
+  Msg(INFO, "Executing Smooth on View num %d", vv->Num);
   vv->smooth();
   return vv;
 }
diff --git a/Plugin/Transform.cpp b/Plugin/Transform.cpp
index 81f1eb0cb9..18bcba2a45 100644
--- a/Plugin/Transform.cpp
+++ b/Plugin/Transform.cpp
@@ -1,4 +1,4 @@
-// $Id: Transform.cpp,v 1.1 2001-08-06 08:12:00 geuzaine Exp $
+// $Id: Transform.cpp,v 1.2 2001-08-06 09:44:22 geuzaine Exp $
 
 #include "Plugin.h"
 #include "Transform.h"
@@ -97,7 +97,7 @@ Post_View *GMSH_TransformPlugin::execute (Post_View *v)
     vv = v;
   else{
     if(List_Nbr(Post_ViewList) < iView){
-      Msg(WARNING,"Plugin CutTransform, view %d not loaded\n",iView);
+      Msg(WARNING,"Plugin CutTransform, view %d not loaded",iView);
       return 0;
     }
     vv = (Post_View*)List_Pointer_Test(Post_ViewList,iView-1);
-- 
GitLab