From d440a3dd64e63afad3bb15b80f9b040cc1dde02a Mon Sep 17 00:00:00 2001 From: Jean-Francois Remacle <jean-francois.remacle@uclouvain.be> Date: Thu, 26 Jul 2001 19:14:34 +0000 Subject: [PATCH] *** empty log message *** --- Plugin/CutMap.cpp | 12 +++++---- Plugin/CutMap.h | 4 +-- Plugin/CutPlane.cpp | 8 +++--- Plugin/CutPlane.h | 4 +-- Plugin/CutSphere.cpp | 6 ++--- Plugin/CutSphere.h | 4 +-- Plugin/LevelsetPlugin.cpp | 5 +++- Plugin/LevelsetPlugin.h | 2 +- Plugin/Plugin.cpp | 53 ++++++++++++++++++++++++++++++++++++--- Plugin/Plugin.h | 9 +++++-- Plugin/PluginManager.h | 20 ++++++++++----- 11 files changed, 95 insertions(+), 32 deletions(-) diff --git a/Plugin/CutMap.cpp b/Plugin/CutMap.cpp index 949c3a39f0..0848736d73 100644 --- a/Plugin/CutMap.cpp +++ b/Plugin/CutMap.cpp @@ -14,7 +14,7 @@ extern "C" { GMSH_Plugin *GMSH_RegisterCutMapPlugin () { - return new GMSH_CutMapPlugin (1.0,1); + return new GMSH_CutMapPlugin (1.5,1); } } @@ -41,9 +41,9 @@ int GMSH_CutMapPlugin::getNbOptions() const return 2; } -void GMSH_CutMapPlugin:: GetOption (int iopt, StringXNumber *option) const +StringXNumber *GMSH_CutMapPlugin:: GetOption (int iopt) { - *option = CutMapOptions_Number[iopt]; + return &CutMapOptions_Number[iopt]; } void GMSH_CutMapPlugin::CatchErrorMessage (char *errorMessage) const @@ -51,10 +51,12 @@ void GMSH_CutMapPlugin::CatchErrorMessage (char *errorMessage) const strcpy(errorMessage,"CutMap Failed..."); } -double GMSH_CutMapPlugin :: levelset (double x, double y, double z) const +double GMSH_CutMapPlugin :: levelset (double x, double y, double z, double val) const { // we must look into the map for A - Map(x,y,z) - return A; + // this is the case when the map is the same as the view, + // the result is the extraction of isovalue A + return A - val; } diff --git a/Plugin/CutMap.h b/Plugin/CutMap.h index 84b004ff3f..db42070d6a 100644 --- a/Plugin/CutMap.h +++ b/Plugin/CutMap.h @@ -11,7 +11,7 @@ class GMSH_CutMapPlugin : public GMSH_LevelsetPlugin /*we cut the othe map by the iso A of the View iView */ double A; int iView; - virtual double levelset (double x, double y, double z) const; + virtual double levelset (double x, double y, double z, double val) const; public: GMSH_CutMapPlugin(double A, int IVIEW); virtual void getName (char *name) const; @@ -20,6 +20,6 @@ public: char *help_text) const; virtual void CatchErrorMessage (char *errorMessage) const; virtual int getNbOptions() const; - virtual void GetOption (int iopt, StringXNumber *option) const; + virtual StringXNumber* GetOption (int iopt); }; #endif diff --git a/Plugin/CutPlane.cpp b/Plugin/CutPlane.cpp index 04b1b0a540..34c49bcba0 100644 --- a/Plugin/CutPlane.cpp +++ b/Plugin/CutPlane.cpp @@ -49,9 +49,9 @@ int GMSH_CutPlanePlugin::getNbOptions() const return 4; } -void GMSH_CutPlanePlugin:: GetOption (int iopt, StringXNumber *option) const +StringXNumber* GMSH_CutPlanePlugin:: GetOption (int iopt) { - *option = CutPlaneOptions_Number[iopt]; + return &CutPlaneOptions_Number[iopt]; } void GMSH_CutPlanePlugin::CatchErrorMessage (char *errorMessage) const @@ -59,7 +59,7 @@ void GMSH_CutPlanePlugin::CatchErrorMessage (char *errorMessage) const strcpy(errorMessage,"CutPlane Failed..."); } -double GMSH_CutPlanePlugin :: levelset (double x, double y, double z) const +double GMSH_CutPlanePlugin :: levelset (double x, double y, double z, double val) const { return a * x + b * y + c * z + d; } @@ -68,5 +68,3 @@ double GMSH_CutPlanePlugin :: levelset (double x, double y, double z) const - - diff --git a/Plugin/CutPlane.h b/Plugin/CutPlane.h index 784c5fdcae..814afb2161 100644 --- a/Plugin/CutPlane.h +++ b/Plugin/CutPlane.h @@ -11,7 +11,7 @@ class GMSH_CutPlanePlugin : public GMSH_LevelsetPlugin { /*Plane a x + b y + c z + d = 0*/ double a,b,c,d; - virtual double levelset (double x, double y, double z) const; + virtual double levelset (double x, double y, double z, double val) const; public: GMSH_CutPlanePlugin(double A, double B, double C, double D); virtual void getName (char *name) const; @@ -20,6 +20,6 @@ public: char *help_text) const; virtual void CatchErrorMessage (char *errorMessage) const; virtual int getNbOptions() const; - virtual void GetOption (int iopt, StringXNumber *option) const; + virtual StringXNumber *GetOption (int iopt); }; #endif diff --git a/Plugin/CutSphere.cpp b/Plugin/CutSphere.cpp index c2ec163448..3c94cc63f0 100644 --- a/Plugin/CutSphere.cpp +++ b/Plugin/CutSphere.cpp @@ -45,9 +45,9 @@ int GMSH_CutSpherePlugin::getNbOptions() const return 4; } -void GMSH_CutSpherePlugin:: GetOption (int iopt, StringXNumber *option) const +StringXNumber* GMSH_CutSpherePlugin:: GetOption (int iopt) { - *option = CutSphereOptions_Number[iopt]; + return &CutSphereOptions_Number[iopt]; } void GMSH_CutSpherePlugin::CatchErrorMessage (char *errorMessage) const @@ -55,7 +55,7 @@ void GMSH_CutSpherePlugin::CatchErrorMessage (char *errorMessage) const strcpy(errorMessage,"CutSphere Failed..."); } -double GMSH_CutSpherePlugin :: levelset (double x, double y, double z) const +double GMSH_CutSpherePlugin :: levelset (double x, double y, double z, double val) const { return (x-a)*(x-a) + (y-b)*(y-b) + (z-c)*(z-c) - r*r; } diff --git a/Plugin/CutSphere.h b/Plugin/CutSphere.h index 2bd20a206e..4c5907d917 100644 --- a/Plugin/CutSphere.h +++ b/Plugin/CutSphere.h @@ -10,7 +10,7 @@ class GMSH_CutSpherePlugin : public GMSH_LevelsetPlugin { /*Sphere (x-a)^2 + (y-b)^2 + (z-c)^2 - r^2 = 0*/ double a,b,c,r; - virtual double levelset (double x, double y, double z) const; + virtual double levelset (double x, double y, double z, double val) const; public: GMSH_CutSpherePlugin(double A, double B, double C, double R); virtual void getName (char *name) const; @@ -19,6 +19,6 @@ public: char *help_text) const; virtual void CatchErrorMessage (char *errorMessage) const; virtual int getNbOptions() const; - virtual void GetOption (int iopt, StringXNumber *option) const; + virtual StringXNumber* GetOption (int iopt); }; #endif diff --git a/Plugin/LevelsetPlugin.cpp b/Plugin/LevelsetPlugin.cpp index 63025f1025..75e90a9d16 100644 --- a/Plugin/LevelsetPlugin.cpp +++ b/Plugin/LevelsetPlugin.cpp @@ -24,8 +24,8 @@ Post_View *GMSH_LevelsetPlugin::execute (Post_View *v) double *X = (double*)List_Pointer_Fast(v->SS,i); double *Y = (double*)List_Pointer_Fast(v->SS,i+4); double *Z = (double*)List_Pointer_Fast(v->SS,i+8); - for(int j=0;j<4;j++)levels[j] = levelset(X[j],Y[j],Z[j]); double *VAL = (double*)List_Pointer_Fast(v->SS,i+12); + for(int j=0;j<4;j++)levels[j] = levelset(X[j],Y[j],Z[j],VAL[j]); int nx = 0; for(k=0;k<6;k++) { @@ -69,8 +69,11 @@ Post_View *GMSH_LevelsetPlugin::execute (Post_View *v) sprintf(name,"cut-%s",v->Name); sprintf(filename,"cut-%s",v->FileName); EndView(1, filename, name); + Msg(INFO, "new %s view with %d tris\n",name,List_Nbr(ActualView->ST)); return ActualView; } + Msg(INFO, "nothing ta da\n"); + return 0; } diff --git a/Plugin/LevelsetPlugin.h b/Plugin/LevelsetPlugin.h index f4fa0d0e9e..c0f69fec3b 100644 --- a/Plugin/LevelsetPlugin.h +++ b/Plugin/LevelsetPlugin.h @@ -4,7 +4,7 @@ class GMSH_LevelsetPlugin : public GMSH_Post_Plugin { - virtual double levelset (double x, double y, double z) const = 0; + virtual double levelset (double x, double y, double z, double val) const = 0; public: virtual Post_View *execute (Post_View *); }; diff --git a/Plugin/Plugin.cpp b/Plugin/Plugin.cpp index da9e814dfe..5a7da7e57d 100644 --- a/Plugin/Plugin.cpp +++ b/Plugin/Plugin.cpp @@ -37,6 +37,53 @@ GMSH_PluginManager::~GMSH_PluginManager() ++it)delete (*it).second; } +GMSH_Plugin* GMSH_PluginManager::find (char *pluginName) +{ + iter it = allPlugins.find(pluginName); + if ( it == allPlugins.end()) return 0; + return (*it).second; +} + +void GMSH_PluginManager::Action( char *pluginName, char *action, void *data) +{ + GMSH_Plugin * plugin = find(pluginName); + if(!plugin) + { + throw 1; + } + if(!strcmp(action,"Run")) + { + plugin->Run(); + } + else if(!strcmp(action,"Save")) + { + plugin->Save(); + } + else + { + throw 1; + } +} + +void GMSH_PluginManager::SetPluginOption (char *pluginName, char *option, double value) +{ + GMSH_Plugin *plugin = find(pluginName); + if(!plugin)throw "Unknown Plugin Name"; + for(int i=0 ; i<plugin->getNbOptions();i++) + { + StringXNumber *sxn; + // get the ith option of the plugin + sxn = plugin->GetOption(i); + // look if it's the good option name + if(!strcmp (sxn->str,option)) + { + sxn->def = value; + return; + } + } + throw "Unknown Plugin Option Name"; +} + GMSH_PluginManager* GMSH_PluginManager::Instance() { if(!instance) @@ -51,9 +98,9 @@ void GMSH_PluginManager::RegisterDefaultPlugins() struct dirent **list; char ext[6]; - allPlugins.insert(std::pair<char*,GMSH_Plugin*>("Cut Plane" ,GMSH_RegisterCutPlanePlugin())); - allPlugins.insert(std::pair<char*,GMSH_Plugin*>("Cut Sphere" ,GMSH_RegisterCutSpherePlugin())); - allPlugins.insert(std::pair<char*,GMSH_Plugin*>("Cut Map" ,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*>("CutMap" ,GMSH_RegisterCutMapPlugin())); char *homeplugins = getenv ("GMSHPLUGINSHOME"); if(!homeplugins)return; diff --git a/Plugin/Plugin.h b/Plugin/Plugin.h index f70eea08aa..eb645babe4 100644 --- a/Plugin/Plugin.h +++ b/Plugin/Plugin.h @@ -46,7 +46,9 @@ public : virtual void CatchErrorMessage (char *errorMessage) const = 0; /* gmsh style option, ca be loaded, saved and set*/ virtual int getNbOptions() const = 0; - virtual void GetOption (int iopt, StringXNumber *option) const = 0; + virtual StringXNumber *GetOption (int iopt) = 0; + virtual void Save() const = 0; + virtual void Run() const = 0; }; /* Base class for Post-Processing Plugins @@ -55,9 +57,12 @@ public : class GMSH_Post_Plugin : public GMSH_Plugin { public: - GMSH_PLUGIN_TYPE getType() const {return GMSH_Plugin::GMSH_POST_PLUGIN;} + inline GMSH_PLUGIN_TYPE getType() const + {return GMSH_Plugin::GMSH_POST_PLUGIN;} /* If returned pointer is the same as the argument, then view is simply modified, else, a new view is added in the view list */ + virtual void Run() const {}; + virtual void Save() const {}; virtual Post_View *execute (Post_View *) = 0; }; diff --git a/Plugin/PluginManager.h b/Plugin/PluginManager.h index 103259de71..a934e2a51c 100644 --- a/Plugin/PluginManager.h +++ b/Plugin/PluginManager.h @@ -37,12 +37,20 @@ public : static GMSH_PluginManager *Instance(); /** Dynamically add a plugin pluginName.so in dirName*/ void AddPlugin(char *dirName, char *pluginName); - void CallPlugin (char *name); - void DestroyPlugin (char *name); - void StPluginOption (char *pluginName, char *option, void *value); - iter begin() {return allPlugins.begin();} - iter end() {return allPlugins.end();} - iter find(char *c) {return allPlugins.find(c);} + // uninstall a given plugin + void UninstallPlugin (char *pluginName); + // set an option to a value in plugin named pluginName + void SetPluginOption (char *pluginName, char *option, double value); + void SetPluginOption (char *pluginName, char *option, char * value); + // iterator on plugins + inline iter begin() {return allPlugins.begin();} + inline iter end() {return allPlugins.end();} + // find a plugin named pluginName + GMSH_Plugin *find(char *pluginName); + // perform an action on the plugin + // default action are Run and Save + // other plugins may perform other actions + void Action (char *pluginMane , char *action , void *data); }; #endif -- GitLab