gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Plugin.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef PLUGIN_H
7 #define PLUGIN_H
8 
9 // To create a plugin:
10 // 1) Create a dynamic lib containing GMSH_RegisterPlugin();
11 // 2) When there is an unacceptable error in the plugin, just throw
12 // this, the plugin manager will be able to catch the exception.
13 // Some Plugins are default gmsh plugins and are insterted directly
14 // in the executable. I think that it's a good way to start.
15 
16 #include <string>
17 #include "Options.h"
18 #include "GmshMessage.h"
19 #include "PView.h"
20 #include "PViewDataList.h"
21 
22 class PluginDialogBox;
23 class Vertex;
24 template <class scalar> class fullMatrix;
25 
26 class GMSH_Plugin {
27 public:
28  // 4 kinds of plugins
29  typedef enum {
35 
36  // a dialog box for the user interface
37  PluginDialogBox *dialogBox;
38 
39  // for internal use by PluginManager
40  void *hlib;
41 
42  GMSH_Plugin() : dialogBox(nullptr), hlib(nullptr) {}
43  virtual ~GMSH_Plugin() {}
44 
45  // return plugin type, name and info
46  virtual GMSH_PLUGIN_TYPE getType() const = 0;
47  virtual std::string getName() const = 0;
48  virtual std::string getShortHelp() const = 0;
49  virtual std::string getHelp() const = 0;
50  virtual std::string getAuthor() const { return "C. Geuzaine, J.-F. Remacle"; }
51  virtual std::string getCopyright() const
52  {
53  return "C. Geuzaine, J.-F. Remacle";
54  }
55 
56  // when an error is thrown by the plugin, the plugin manager will
57  // show the message and hopefully continue
58  virtual void catchErrorMessage(char *errorMessage) const;
59 
60  // gmsh-style numeric options
61  virtual int getNbOptions() const { return 0; }
62  virtual StringXNumber *getOption(int iopt) { return nullptr; };
63 
64  // gmsh-style string options
65  virtual int getNbOptionsStr() const { return 0; }
66  virtual StringXString *getOptionStr(int iopt) { return nullptr; }
67 
68  // serialize plugin options into a string
69  std::string serialize();
70 
71  // run the plugin
72  virtual int run() = 0;
73 
74  // dynamic pointer to a drawing function
75  static void setDrawFunction(void (*fct)(void *));
76 #ifndef SWIG
77  static void (*draw)(void *);
78 #endif
79 };
80 
81 // The base class for post-processing plugins. The user can either
82 // modify or duplicate a post-processing view
83 class GMSH_PostPlugin : public GMSH_Plugin {
84 public:
85  inline GMSH_PLUGIN_TYPE getType() const
86  {
88  }
89  // run the plugin
90  virtual int run()
91  {
92  PView *v = execute(nullptr);
93  if(v) return v->getTag();
94  return 0;
95  }
96  // if the returned pointer is the same as the argument, then the
97  // view is simply modified, else, a new view is added in the view
98  // list
99  virtual PView *execute(PView *) = 0;
100  // excute on a remote dataset
101  virtual PView *executeRemote(PView *);
102  // get the view given an index and a default value (if index < 0 use
103  // the default view if available; otherwise use the last view in the
104  // list)
105  virtual PView *getView(int index, PView *view);
106  // get the data in list format
107  virtual PViewDataList *getDataList(PView *view, bool showError = true);
108  // get the the adapted data (i.e. linear, on refined mesh) if
109  // available, otherwise get the original data
110  virtual PViewData *getPossiblyAdaptiveData(PView *view);
111  virtual void assignSpecificVisibility() const {}
112  virtual bool geometricalFilter(fullMatrix<double> *) const { return true; }
113 };
114 
115 // The base class for solver plugins. The idea is to be able to
116 // associate some properties to physical entities, so that we can
117 // interface gmsh with a solver (ABAQUS...), i.e., create the input
118 // file for the solver
120 public:
121  inline GMSH_PLUGIN_TYPE getType() const
122  {
124  }
125  virtual int run() { return 0; }
126  // popup dialog box
127  virtual void popupPropertiesForPhysicalEntity(int dim) = 0;
128  // add the given group to the solver data
129  virtual void receiveNewPhysicalGroup(int dim, int id) = 0;
130  // load the solver input file related to the gmsh geo file
131  virtual void readSolverFile(const char *) = 0;
132  // save the solver file
133  virtual void writeSolverFile(const char *) const = 0;
134  // enhance graphics for a giver geo point
135  virtual bool GL_enhancePoint(Vertex *v) { return false; }
136  // enhance graphics for a giver geo line
137  virtual bool GL_enhanceLine(int CurveId, Vertex *v1, Vertex *v2)
138  {
139  return false;
140  }
141 };
142 
143 class GMSH_MeshPlugin : public GMSH_Plugin {
144  inline GMSH_PLUGIN_TYPE getType() const
145  {
147  }
148  virtual int run() { return 0; }
149 };
150 
151 #endif
GMSH_Plugin::hlib
void * hlib
Definition: Plugin.h:40
StringXString
Definition: Options.h:910
GMSH_SolverPlugin::receiveNewPhysicalGroup
virtual void receiveNewPhysicalGroup(int dim, int id)=0
GMSH_Plugin::getHelp
virtual std::string getHelp() const =0
PView
Definition: PView.h:27
GMSH_SolverPlugin::getType
GMSH_PLUGIN_TYPE getType() const
Definition: Plugin.h:121
GMSH_Plugin::GMSH_Plugin
GMSH_Plugin()
Definition: Plugin.h:42
GMSH_PostPlugin::getType
GMSH_PLUGIN_TYPE getType() const
Definition: Plugin.h:85
GMSH_PostPlugin::run
virtual int run()
Definition: Plugin.h:90
GMSH_Plugin
Definition: Plugin.h:26
PViewDataList
Definition: PViewDataList.h:17
GMSH_Plugin::draw
static void(* draw)(void *)
Definition: Plugin.h:77
StringXNumber
Definition: Options.h:918
Vertex
Definition: Geo.h:29
GMSH_SolverPlugin::run
virtual int run()
Definition: Plugin.h:125
PView.h
GMSH_Plugin::GMSH_PLUGIN_TYPE
GMSH_PLUGIN_TYPE
Definition: Plugin.h:29
GmshMessage.h
GMSH_Plugin::getType
virtual GMSH_PLUGIN_TYPE getType() const =0
GMSH_Plugin::getCopyright
virtual std::string getCopyright() const
Definition: Plugin.h:51
GMSH_SolverPlugin::readSolverFile
virtual void readSolverFile(const char *)=0
GMSH_Plugin::GMSH_CAD_PLUGIN
@ GMSH_CAD_PLUGIN
Definition: Plugin.h:30
GMSH_Plugin::run
virtual int run()=0
fullMatrix
Definition: MElement.h:27
GMSH_Plugin::serialize
std::string serialize()
Definition: Plugin.cpp:44
GMSH_SolverPlugin::popupPropertiesForPhysicalEntity
virtual void popupPropertiesForPhysicalEntity(int dim)=0
PView::getTag
int getTag()
Definition: PView.h:89
GMSH_Plugin::getNbOptions
virtual int getNbOptions() const
Definition: Plugin.h:61
GMSH_PostPlugin::execute
virtual PView * execute(PView *)=0
GMSH_MeshPlugin::getType
GMSH_PLUGIN_TYPE getType() const
Definition: Plugin.h:144
GMSH_Plugin::getName
virtual std::string getName() const =0
PViewDataList.h
GMSH_SolverPlugin::writeSolverFile
virtual void writeSolverFile(const char *) const =0
GMSH_PostPlugin::geometricalFilter
virtual bool geometricalFilter(fullMatrix< double > *) const
Definition: Plugin.h:112
GMSH_PostPlugin::executeRemote
virtual PView * executeRemote(PView *)
Definition: Plugin.cpp:57
GMSH_SolverPlugin::GL_enhanceLine
virtual bool GL_enhanceLine(int CurveId, Vertex *v1, Vertex *v2)
Definition: Plugin.h:137
GMSH_Plugin::getNbOptionsStr
virtual int getNbOptionsStr() const
Definition: Plugin.h:65
GMSH_PostPlugin::assignSpecificVisibility
virtual void assignSpecificVisibility() const
Definition: Plugin.h:111
PViewData
Definition: PViewData.h:29
GMSH_Plugin::catchErrorMessage
virtual void catchErrorMessage(char *errorMessage) const
Definition: Plugin.cpp:38
GMSH_Plugin::~GMSH_Plugin
virtual ~GMSH_Plugin()
Definition: Plugin.h:43
GMSH_Plugin::getAuthor
virtual std::string getAuthor() const
Definition: Plugin.h:50
GMSH_Plugin::setDrawFunction
static void setDrawFunction(void(*fct)(void *))
Definition: Plugin.cpp:21
GMSH_PostPlugin
Definition: Plugin.h:83
GMSH_SolverPlugin
Definition: Plugin.h:119
GMSH_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition: Plugin.cpp:81
GMSH_PostPlugin::getPossiblyAdaptiveData
virtual PViewData * getPossiblyAdaptiveData(PView *view)
Definition: Plugin.cpp:94
Options.h
GMSH_MeshPlugin
Definition: Plugin.h:143
GMSH_Plugin::getOptionStr
virtual StringXString * getOptionStr(int iopt)
Definition: Plugin.h:66
GMSH_Plugin::GMSH_POST_PLUGIN
@ GMSH_POST_PLUGIN
Definition: Plugin.h:32
GMSH_SolverPlugin::GL_enhancePoint
virtual bool GL_enhancePoint(Vertex *v)
Definition: Plugin.h:135
GMSH_Plugin::GMSH_SOLVER_PLUGIN
@ GMSH_SOLVER_PLUGIN
Definition: Plugin.h:33
GMSH_Plugin::GMSH_MESH_PLUGIN
@ GMSH_MESH_PLUGIN
Definition: Plugin.h:31
GMSH_Plugin::getShortHelp
virtual std::string getShortHelp() const =0
GMSH_Plugin::dialogBox
PluginDialogBox * dialogBox
Definition: Plugin.h:37
GMSH_Plugin::getOption
virtual StringXNumber * getOption(int iopt)
Definition: Plugin.h:62
GMSH_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition: Plugin.cpp:107
GMSH_MeshPlugin::run
virtual int run()
Definition: Plugin.h:148