COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coModule.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef _CO_FEATURE_MODULE_H_
9 #define _CO_FEATURE_MODULE_H_
10 
11 // 15.09.99
12 
13 #include <do/coDoPolygons.h>
14 #include <appl/ApplInterface.h>
15 #include "coBooleanParam.h"
16 #include "coFileBrowserParam.h"
17 #include "coChoiceParam.h"
18 #include "coMaterialParam.h"
19 #include "coColormapChoiceParam.h"
20 #include "coColormapParam.h"
21 #include "coColorParam.h"
22 #include "coFloatParam.h"
23 #include "coFloatSliderParam.h"
24 #include "coFloatVectorParam.h"
25 #include "coIntScalarParam.h"
26 #include "coIntSliderParam.h"
27 #include "coIntVectorParam.h"
28 #include "coStringParam.h"
29 #include "coTimerParam.h"
30 #include "coInputPort.h"
31 #include "coOutputPort.h"
32 
33 // forward declarations for pointers only
34 
35 namespace covise
36 {
37 
38 class coUifElem;
39 class coPort;
40 class coUifSwitch;
41 class coUifSwitchCase;
42 
47 class APIEXPORT coModule : public Covise
48 {
49 
50 private:
52  enum
53  {
54  MAX_LEVELS = 64
55  };
56 
58  enum
59  {
60  MAX_SOCKET = 256
61  };
62 
64  coModule(const coModule &);
65 
67  coModule &operator=(const coModule &);
68 
69  // if we are in an open case : pointer to active case
70  coUifSwitchCase *d_actCase[MAX_LEVELS];
72 
73  // if we are in an open switch : pointer to active case
74  coUifSwitch *d_actSwitch[MAX_LEVELS];
76 
77  // list of registered sockets, number in list and handler Obj
78  int d_socket[MAX_SOCKET];
80 
81  // static stubs for callback
82  static void quitCallback(void *userData, void *callbackData);
83  static void computeCallback(void *userData, void *callbackData);
84  static void paramCallback(bool inMapLoading, void *userData, void *callbackData);
85  static void feedbackCallback(void *userData, int len, const char *data);
86  static void portCallback(void *userData, void *callbackData);
87  static void addObjCallback(void *userData, void *callbackData);
88 
89  // our internal callback for changed parameters
90  void localParam(bool inMapLoading, void *callbackData);
91  // our internal callback connection changing ports
92  void localPort(void *callbackData);
93 
94  // whether we automatically fire up all parameters first to secure the order
96 
97  // When this flag has been set, fire an EXEC message after returning
98  // from this event
100 
101  // 'Grace period' to wait after self-exec to prevent overrinning next module
103 
104  // Title of the module
105  char *d_title;
106 
107  // initial Title of the module
109 
110  //send description to controller and UIF's
111  void initDescription();
112 
113 protected:
114  // register a parameter port at the module: return 0 if ok, -1 on error
115  int add_port(coPort *param);
116 
117  //should the module's name
118  //be propagated as attribute?
120 
121  // find element by name : derived classes might access directly
122  coUifElem *findElem(const char *name);
123 
124  // list of all UIF Elements and number of Elements in list
127 
128  // our internal 'pre-compute' sets all non-immediate parameters
129  virtual void localCompute(void *callbackData);
130 
131  // internal callback called if ADD_OBJECT messages arrive
132  virtual void localAddObject(void *callbackData);
133 
134 public:
136  enum
137  {
138  FAIL = -1,
139  SUCCESS = 0,
140  STOP_PIPELINE = -1,
141  CONTINUE_PIPELINE = 0
142  };
143 
144  // ------------------ Constructor / destructor --------------------------
145 
147  coModule(int argc, char *argv[], const char *desc = NULL, bool propagate = false);
148 
150  virtual ~coModule();
151 
152  // --------------------- Utility functions ------------------------------
153 
154  bool GoodOctTrees(const coDistributedObject *grid, const coDistributedObject *otree);
155 
157  void selfExec();
158 
160  void setExecGracePeriod(float gracePeriod);
161 
162  // --------------------- Parameter switching ----------------------------
163 
165  coChoiceParam *paraSwitch(const char *name, const char *desc);
166 
168  int paraEndSwitch();
169 
171  int paraCase(const char *name);
172 
174  int paraEndCase();
175 
177  void autoInitParam(int value = 0);
178 
179  // -------------------- add a socket to listen to -----------------------
180 
182  void addSocket(int socket);
183 
185  void removeSocket(int socket);
186 
187  // --------------------- Covise Main-Loop et al -------------------------
188 
190  virtual void init(int argc, char *argv[]);
191 
193  virtual void start(int argc, char *argv[]);
194 
196  // return either SUCCESS or FAIL
197  virtual int compute(const char *port);
198 
200  // return either SUCCESS or FAIL
201  virtual int addObject(const char *objectNameToAdd, const char *objectNameToDelete);
202 
204  virtual void param(const char *paramName, bool inMapLoading);
205 
207  virtual void sockData(int sockNo);
208 
210  virtual void feedback(int len, const char *data);
211 
213  virtual void quit(void);
214 
216  virtual void postInst();
217 
220  virtual float idle();
221 
223  virtual void handleMessages(float time);
224 
226  virtual void mainLoop();
227 
229  void stopPipeline();
230 
231  // --------------------- Covise Main-Loop et al -------------------------
232 
234  coBooleanParam *addBooleanParam(const char *name, const char *desc);
235 
237  coFileBrowserParam *addFileBrowserParam(const char *name, const char *desc);
238 
240  coChoiceParam *addChoiceParam(const char *name, const char *desc);
241 
243  coColormapChoiceParam *addColormapChoiceParam(const char *name, const char *desc);
244 
246  coMaterialParam *addMaterialParam(const char *name, const char *desc);
247 
249  coColormapParam *addColormapParam(const char *name, const char *desc);
250 
252  coColorParam *addColorParam(const char *name, const char *desc);
253 
255  coFloatParam *addFloatParam(const char *name, const char *desc);
256 
258  coFloatSliderParam *addFloatSliderParam(const char *name, const char *desc);
259 
261  coFloatVectorParam *addFloatVectorParam(const char *name, const char *desc, int length = 3);
262 
264  coIntScalarParam *addInt32Param(const char *name, const char *desc);
265 
267  coIntSliderParam *addIntSliderParam(const char *name, const char *desc);
268 
270  coIntVectorParam *addInt32VectorParam(const char *name, const char *desc, int length = 3);
271 
273  coStringParam *addStringParam(const char *name, const char *desc);
274 
276  coTimerParam *addTimerParam(const char *name, const char *desc);
277 
279  coInputPort *addInputPort(const char *name, const char *types, const char *desc);
280 
282  coOutputPort *addOutputPort(const char *name, const char *types, const char *desc);
283 
284  // ------------------------------ Mapeditor message
286  void setInfo(const char *value) const;
287 
289  void setTitle(const char *value);
291  {
292  return (strcmp(d_title, d_init_title) != 0);
293  };
294  const char *getTitle()
295  {
296  return d_title;
297  };
298 };
299 
301 {
302 public:
304  coFunctionModule(int argc, char *argv[], const char *desc = NULL, bool propagate = false)
305  : coModule(argc, argv, desc, propagate)
306  {
307  }
308 
311  {
312  }
313 };
314 
315 #define MODULE_MAIN(Category, Module) \
316  int main(int argc, char *argv[]) \
317  { \
318  coModule *app = new Module(argc, argv); \
319  app->start(argc, argv); \
320  }
321 
322 #define COMODULE
323 }
324 #endif
GLenum GLsizei len
Definition: khronos-glext.h:7440
single integer parameter
Definition: coIntScalarParam.h:29
Definition: coOutputPort.h:26
bool _propagateObjectName
Definition: coModule.h:119
GLuint const GLchar * name
Definition: khronos-glext.h:6722
Multiple float parameters.
Definition: coColorParam.h:24
int d_numActCase
Definition: coModule.h:71
parameter to choose values from a list
Definition: coColormapChoiceParam.h:24
#define SUCCESS
Definition: coColors.cpp:27
float slider parameter
Definition: coFloatSliderParam.h:29
Implements Covise string parameters.
Definition: coStringParam.h:29
int d_numSocket
Definition: coModule.h:79
Definition: coModule.h:47
Definition: CoviseBase.h:70
Definition: coUifElem.h:20
int d_numActSwitch
Definition: coModule.h:75
int d_numElem
Definition: coModule.h:126
File browser parameter.
Definition: coColormapParam.h:30
#define NULL
Definition: covise_list.h:22
GLfloat param
Definition: khronos-glext.h:6531
Definition: coUifSwitch.h:25
Data input Port.
Definition: coInputPort.h:27
File browser parameter.
Definition: coFileBrowserParam.h:29
int d_execFlag
Definition: coModule.h:99
Parameter for multiple integers.
Definition: coIntVectorParam.h:29
coFunctionModule(int argc, char *argv[], const char *desc=NULL, bool propagate=false)
YAC-compatible constructor.
Definition: coModule.h:304
int d_autoParamInit
Definition: coModule.h:95
GLsizei GLenum GLenum * types
Definition: khronos-glext.h:8471
single float parameter
Definition: coFloatParam.h:29
#define APIEXPORT
Definition: coExport.h:251
parameter to choose values from a list
Definition: coMaterialParam.h:24
Boolean value parameter.
Definition: coBooleanParam.h:29
float d_execGracePeriod
Definition: coModule.h:102
Definition: coModule.h:300
virtual ~coFunctionModule()
Destructor : virtual in case we derive objects.
Definition: coModule.h:310
char * d_title
Definition: coModule.h:105
GLuint start
Definition: khronos-glext.h:6343
parameter to choose values from a list
Definition: coChoiceParam.h:29
Definition: coPort.h:24
Integer slider parameter.
Definition: coIntSliderParam.h:29
Multiple float parameters.
Definition: coFloatVectorParam.h:29
Definition: coDistributedObject.h:295
Integer slider parameter.
Definition: coTimerParam.h:29
#define FAIL
Definition: coColors.cpp:26
bool titleChanged()
Definition: coModule.h:290
char * d_init_title
Definition: coModule.h:108
GLsizei const GLfloat * value
Definition: khronos-glext.h:6760
Definition: ApplInterface.h:48
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: khronos-glext.h:6354
const char * getTitle()
Definition: coModule.h:294
GLenum GLuint GLenum GLsizei length
Definition: khronos-glext.h:6279
Definition: coUifSwitchCase.h:23