00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __OP_Operator_h__
00025 #define __OP_Operator_h__
00026
00027 #include "OP_API.h"
00028 #include <UT/UT_String.h>
00029 #include <UT/UT_PtrArray.h>
00030 #include <UT/UT_StringArray.h>
00031 #include <VEX/VEX_VexOp.h>
00032 #include "OP_OTLDefinition.h"
00033 #include "OP_OTLLicenseType.h"
00034 #include "OP_Value.h"
00035 #include "OP_Node.h"
00036
00037
00038
00039
00040 #define ENGLISH_NAME "englishname"
00041 #define VOPNET_TAB_MENU_FLAG_NAME "tabmenuflag"
00042
00043 class UT_FileUtil;
00044 class UT_StringArray;
00045 class UT_InfoTree;
00046 class UT_WorkBuffer;
00047 class UT_Options;
00048 class PY_EvaluationContext;
00049 class PY_CompiledCode;
00050 class FS_IndexFile;
00051 class CH_LocalVariable;
00052 class PRM_Template;
00053 class PRM_SimpleParm;
00054 class PRM_PresetInfo;
00055 class PRM_ScriptImports;
00056 class OP_Network;
00057 class OP_Node;
00058 class OP_OperatorTable;
00059 class OP_Operator;
00060 class OP_OTLLibrary;
00061 class OP_SpareParmCache;
00062 class OP_SpareParms;
00063 class OP_UpdateTemplatesSink;
00064
00065
00066 #define OP_FLAG_NETWORK 0x01
00067 #define OP_FLAG_GENERATOR 0x02
00068 #define OP_FLAG_UNORDERED 0x04
00069 #define OP_FLAG_SCRIPTDEF 0x08
00070 #define OP_FLAG_MANAGER 0x10
00071 #define OP_FLAG_PRIMARYSUBNET 0x20
00072
00073
00074 #define OP_MAX_INPUT_LABELS 4
00075
00076 typedef UT_PtrArray<OP_Operator *> OP_OperatorList;
00077 typedef OP_Node *(*OP_Constructor)(OP_Network *, const char *, OP_Operator *);
00078
00079
00080 typedef enum {
00081 RSL_INVALID_CONTEXT = 0x00000000,
00082 RSL_SURFACE_CONTEXT = 0x00000001,
00083 RSL_DISPLACE_CONTEXT = 0x00000002,
00084 RSL_LIGHT_CONTEXT = 0x00000004,
00085 RSL_VOLUME_CONTEXT = 0x00000008
00086 } RSL_ContextType;
00087
00088
00089 typedef enum {
00090 OP_EVENTSCRIPT_GLOBAL,
00091 OP_EVENTSCRIPT_OPTYPE,
00092 OP_EVENTSCRIPT_NODE
00093 } OP_EventScriptType;
00094
00095 class OP_API OP_SpecificData
00096 {
00097 public:
00098 OP_SpecificData() { }
00099 virtual ~OP_SpecificData() { }
00100
00101 virtual void saveToDialogScript(ostream &os) const = 0;
00102 };
00103
00104 class OP_API OP_TemplatePair
00105 {
00106 public:
00107 OP_TemplatePair(PRM_Template *templates,
00108 OP_TemplatePair *parent_pair = 0)
00109 {
00110 myTemplate = templates;
00111 myBaseTemplatePair = parent_pair;
00112 }
00113 PRM_Template *myTemplate;
00114 OP_TemplatePair *myBaseTemplatePair;
00115 };
00116
00117 class OP_API OP_VariablePair
00118 {
00119 public:
00120 OP_VariablePair(CH_LocalVariable *variables,
00121 OP_VariablePair *parent_pair = 0)
00122 {
00123 myVariables = variables;
00124 myBaseVariablePair = parent_pair;
00125 }
00126 CH_LocalVariable *myVariables;
00127 OP_VariablePair *myBaseVariablePair;
00128 };
00129
00130 class OP_API OP_Operator
00131 {
00132 public:
00133 OP_Operator(const char *name,
00134 const char *english,
00135 OP_Constructor construct,
00136 PRM_Template *templates,
00137 unsigned min_sources,
00138 unsigned max_sources = 9999,
00139 CH_LocalVariable *variables = 0,
00140 unsigned flags = 0,
00141 const char **inputlabels = 0);
00142
00143 OP_Operator(const char *name,
00144 const char *english,
00145 OP_Constructor construct,
00146 OP_TemplatePair *template_pair,
00147 unsigned min_sources,
00148 unsigned max_sources = 9999,
00149 OP_VariablePair *variable_pair = 0,
00150 unsigned flags = 0,
00151 const char **inputlabels = 0);
00152
00153 virtual ~OP_Operator();
00154
00155 OP_Node *constructNode(OP_Network *net, const char *name);
00156 int getNumActiveNodes() const;
00157 OP_Node *getActiveNode(int i) const;
00158 void nodeDestroyed(OP_Node *node);
00159
00160
00161
00162
00163 virtual OP_SpecificData *getOpSpecificData()
00164 { return 0; }
00165 virtual const OP_SpecificData *getOpSpecificData() const
00166 { return 0; }
00167
00168 const UT_String &getName() const
00169 { return myOTLDefinition.getName(); }
00170
00171
00172
00173 void getTableAndName(UT_String &name) const
00174 { myOTLDefinition.getTableAndName(name); }
00175
00176 const UT_String &getEnglish() const
00177 { return myOTLDefinition.getLabel(); }
00178
00179 virtual bool getHDKHelp(UT_String & ) const
00180 { return false; }
00181
00182 virtual bool getOpHelpURL(UT_String &url);
00183
00184 bool getOTLHelp(UT_String &str);
00185 void getEditableSubNodes(UT_String &pattern);
00186
00187 void getComment(UT_String &comment);
00188 void getVersion(UT_String &version);
00189
00190 void getHelpFileDirAndName(UT_String & script_dir,
00191 UT_String & name);
00192
00193 void getDefinitionSource(UT_String &defsource) const;
00194
00195 static void clearOperatorHelpCache()
00196 { ourLastHelpOp = 0; }
00197 OP_Node *getDefiningNetwork() const;
00198
00199
00200
00201
00202 const UT_String &getIndexPath() const
00203 { return myOTLDefinition.getIndexPath(); }
00204 const UT_String &getIndexFile() const
00205 { return myOTLDefinition.getIndexFile(); }
00206 bool getScriptIsSubnet() const
00207 { return myOTLDefinition.getIsSubnet(); }
00208 bool getScriptIsVex() const
00209 { return (myVexContextType != VEX_INVALID_CONTEXT); }
00210 bool getScriptIsRsl() const
00211 { return (myRslContextType != RSL_INVALID_CONTEXT); }
00212 VEX_ContextType getVexContextType() const
00213 { return myVexContextType; }
00214 RSL_ContextType getRslContextType() const
00215 { return myRslContextType; }
00216 int getModTime() const
00217 { return myOTLDefinition.getModTime(); }
00218 bool getIsDummyDefinition() const
00219 { return myOTLDefinition.getIsDummyDefinition(); }
00220
00221
00222 bool getScriptIsPython() const
00223 { return myOTLDefinition.getIsPython(); }
00224 void setScriptIsPython(bool is_python)
00225 { myOTLDefinition.setIsPython(is_python); }
00226
00227
00228 const UT_String &getExtraInfo() const
00229 { return myOTLDefinition.getExtraInfo(); }
00230
00231
00232 void setOTLDefinition(const OP_OTLDefinition &definition);
00233 void getOTLDefinition(OP_OTLDefinition &definition) const
00234 { definition = myOTLDefinition; }
00235
00236
00237 void setOTLLibrary(OP_OTLLibrary *library)
00238 { myOTLLibrary = library; }
00239 OP_OTLLibrary *getOTLLibrary()
00240 { return myOTLLibrary; }
00241
00242
00243 FS_IndexFile *getOTLIndexFile();
00244 bool hasContentsSection();
00245
00246
00247
00248 void clearOTLIndexFile();
00249
00250
00251
00252 virtual void forceUpdateParmTemplates();
00253
00254
00255
00256
00257 FS_IndexFile *createDefaultOTLIndexFile() const;
00258 FS_IndexFile *createOTLIndexFile(bool reservedsectionsonly,
00259 UT_StringArray *externalfiles);
00260
00261
00262
00263 const char *getIconName() const;
00264 void setIconName(const char *name);
00265 void setDefaultIconName();
00266
00267 unsigned minInputs() const
00268 { return myOTLDefinition.getMinInputs(); }
00269 unsigned maxInputs() const
00270 { return myOTLDefinition.getMaxInputs(); }
00271
00272
00273
00274 virtual unsigned maxOutputs()
00275 { return isManagementOp() ? 0 : 1; }
00276
00277 OP_SpareParms *loadSpareParms(UT_IStream &is);
00278
00279 virtual bool hasLoadedParmTemplates() const;
00280 virtual int updateParmTemplates();
00281
00282 virtual PRM_Template *getParmTemplates() { return myParmTemplates; }
00283 virtual PRM_ScriptImports *getParmTemplateImports() { return NULL; }
00284 virtual PRM_Template *getLayoutParmTemplates() { return NULL; }
00285 virtual PRM_ScriptImports *getLayoutParmTemplateImports() { return NULL; }
00286 virtual const PRM_Template *getBaseParmTemplates() { return NULL; }
00287
00288 virtual PRM_Template *getObsoleteTemplates()
00289 { return myObsoleteTemplates; }
00290 void setObsoleteTemplates(PRM_Template *tmpl)
00291 { myObsoleteTemplates = tmpl; }
00292
00293 CH_LocalVariable *getVariable(int i) const;
00294 CH_LocalVariable *getVariable(const char *name) const;
00295 CH_LocalVariable *getVariables() const { return myVariables; }
00296 int getVariableCount() const { return myNvariables; }
00297
00298 unsigned isNetwork() const
00299 {
00300 return (myFlags & OP_FLAG_NETWORK) != 0;
00301 }
00302 unsigned isGenerator() const
00303 {
00304 return (myFlags & OP_FLAG_GENERATOR) != 0;
00305 }
00306 unsigned isScriptedOp() const
00307 {
00308 return (myFlags & OP_FLAG_SCRIPTDEF) != 0;
00309 }
00310 bool isCustomDSO() const;
00311 unsigned unorderedInputs() const
00312 {
00313 return (myFlags & OP_FLAG_UNORDERED) != 0;
00314 }
00315 unsigned isManagementOp() const
00316 {
00317 return (myFlags & OP_FLAG_MANAGER) != 0;
00318 }
00319
00320
00321
00322 bool getIsPrimarySubnetType() const
00323 {
00324 return (myFlags & OP_FLAG_PRIMARYSUBNET) != 0;
00325 }
00326 bool isCreatingNode() const
00327 {
00328 return myCreatingNode;
00329 }
00330 bool isChangingParmTemplates() const
00331 {
00332 return myChangingParmTemplates;
00333 }
00334
00335 enum OP_OperatorCompare {
00336 OP_COMPARE_GEN_ENGLISH = 0,
00337 OP_COMPARE_GEN_NAME = 1,
00338 OP_COMPARE_ENGLISH = 2,
00339 OP_COMPARE_NAME = 3
00340 };
00341
00342
00343
00344 virtual int compareOperator(const OP_Operator *other,
00345 int method) const;
00346
00347
00348 void changeParmTemplate(PRM_Template *tp);
00349
00350 const UT_String &getInputLabel(int idx);
00351 const UT_StringArray &getInputLabels() const
00352 { return myInputLabels; }
00353
00354 unsigned getPermissionMask() const;
00355
00356
00357
00358 virtual void getRefreshPICommands(OP_Node *, ostream &) { }
00359
00360
00361
00362 virtual bool wantsParametersAnimatable() const;
00363
00364
00365 virtual bool wantsInputEditor() const;
00366
00367
00368 virtual bool wantsParmOrderEditor() const;
00369
00370
00371 virtual bool wantsOutputNameEditor() const;
00372
00373
00374
00375 virtual const char *getOperatorShortHelpString();
00376
00377
00378
00379
00380 virtual void getOperatorSpecificInfoText(int verbose,
00381 UT_WorkBuffer &text);
00382
00383
00384
00385
00386 void fillInfoTree(UT_InfoTree &tree);
00387
00388
00389
00390
00391 virtual void fillInfoTreeOperatorSpecific(UT_InfoTree &tree);
00392
00393
00394 static int loadFromOpType(const char *fname, const char *savedir);
00395 static int uninstallOpType(const char *path,
00396 const char *tablename, const char *opname,
00397 const char *indexpath, const char *indexfile);
00398
00399 static void removeHelpCardOverrides(UT_FileUtil *fu,
00400 const char *path, const char *tablename,
00401 const char *opname, int flags);
00402 static void removeRenameOverrides(UT_FileUtil *fu,
00403 const char *path, const char *tablename,
00404 const char *opname, int flags);
00405 static void removeIconOverrides(UT_FileUtil *fu,
00406 const char *path, const char *tablename,
00407 const char *opname, int flags);
00408 static void removeCmdOverrides(UT_FileUtil *fu,
00409 const char *path, const char *tablename,
00410 const char *opname, int flags);
00411
00412 static void getDefaultIconName(const char *tablename,
00413 const char *opname,
00414 UT_String &iconname);
00415
00416
00417
00418
00419 const char *getTableName() const;
00420
00421
00422 OP_OperatorTable *getTable() const;
00423
00424
00425 OP_OTLLicenseType getLicense();
00426
00427
00428
00429
00430
00431 void setDefinition(const char *def);
00432
00433 void setEnglish(const char *english);
00434
00435
00436
00437 void informOfTabMenuFlagChange();
00438
00439
00440
00441 virtual void setName(const char *name);
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452 void setMinInputs(int inputs);
00453 void setMaxInputs(int inputs);
00454 void setIsGenerator(bool isgen);
00455
00456
00457
00458 void updatePresetInfo();
00459 PRM_PresetInfo *getPresetInfo();
00460
00461
00462
00463
00464
00465 bool runEventScript(
00466 const char *event,
00467 OP_Node *node_arg = NULL,
00468 bool full_path = false,
00469 UT_Options *extra_args = NULL,
00470 bool *node_deleted_by_script = NULL);
00471
00472
00473
00474
00475 PY_EvaluationContext *getPythonModuleDicts()
00476 { return myPythonModuleDicts; }
00477
00478 static const char *getCurrentPythonModuleKey();
00479 static const OP_Operator *mapSecurityKeyToOperator(const char *key);
00480 static void registerPythonModuleKeyClient(void *client);
00481 static bool verifyPythonModuleKeyClient(
00482 const OP_Operator *op, void *client);
00483
00484 static PRM_Template *getEmptyTemplateList();
00485
00486 protected:
00487
00488
00489 void notifyUpdateTemplatesSinksOfUpdate();
00490
00491 void notifyUpdateTemplatesSinksOfDelete();
00492
00493
00494 static PRM_Template *addTemplates(OP_TemplatePair *);
00495 static CH_LocalVariable *addVariables(OP_VariablePair *);
00496
00497 PRM_Template *myParmTemplates;
00498 PRM_Template *myObsoleteTemplates;
00499 UT_StringArray myInputLabels;
00500 CH_LocalVariable *myVariables;
00501 int myNvariables;
00502
00503 OP_OTLDefinition myOTLDefinition;
00504 VEX_ContextType myVexContextType;
00505 RSL_ContextType myRslContextType;
00506 PY_CompiledCode *myCachedCompiledPythonCookCode;
00507 unsigned myFlags;
00508 bool myHasContentsSection;
00509
00510 private:
00511 unsigned operator<(const OP_Operator &);
00512 void uniqueName(OP_Network *);
00513 void addUpdateTemplatesSink(OP_UpdateTemplatesSink *);
00514 void removeUpdateTemplatesSink(OP_UpdateTemplatesSink *);
00515
00516
00517 static void handleDefiningNetworkChange(OP_Node *caller,
00518 void *callee,
00519 OP_EventType type,
00520 void *data);
00521
00522 CH_ScriptLanguage eventScriptLanguage(
00523 FS_IndexFile &def_file, const char *event);
00524 bool runEventScript(
00525 const char *event,
00526 OP_Node *node_arg,
00527 bool full_path,
00528 UT_Options *extra_args,
00529 bool &node_deleted_by_script,
00530 OP_EventScriptType eventtype);
00531 void runHscriptEventScript(
00532 const char *script,
00533 const char *script_path,
00534 OP_Node *node,
00535 bool full_path,
00536 const char *extra_args);
00537 void runPythonEventScript(
00538 const char *script,
00539 const char *script_path,
00540 PY_EvaluationContext &evaluation_context,
00541 const char *kwargs_dict, OP_Node *node);
00542 void loadPythonModuleSection();
00543
00544
00545 OP_Constructor myConstructor;
00546
00547 OP_NodeList myActiveNodes;
00548
00549 OP_OTLLibrary *myOTLLibrary;
00550 FS_IndexFile *myOTLIndexFile;
00551 OP_OperatorTable *myOperatorTable;
00552 OP_Node *myDefiningNetwork;
00553 PRM_PresetInfo *myPresetInfo;
00554 OP_SpareParmCache *mySpareParmCache;
00555 bool myCreatingNode;
00556 bool myChangingParmTemplates;
00557
00558 UT_PtrArray<OP_UpdateTemplatesSink *> myUpdateTemplatesSinks;
00559
00560 PY_EvaluationContext *myPythonModuleDicts;
00561
00562 friend class OP_OperatorTable;
00563 friend class SHOP_ScriptOperator;
00564 friend class OP_UpdateTemplatesSink;
00565
00566 static const OP_Operator *ourLastHelpOp;
00567 static int ourLastHelpLevel;
00568 static UT_String ourHelp;
00569 static bool ourHelpIsHtml;
00570 static const char *theNonScriptDef;
00571
00572 };
00573
00574 class OP_API OP_UpdateTemplatesSink
00575 {
00576 public:
00577 OP_UpdateTemplatesSink() { }
00578 virtual ~OP_UpdateTemplatesSink()
00579 { removeAllTemplatesSinks(); }
00580
00581 virtual void templatesUpdated(OP_Operator *op) = 0;
00582 virtual void operatorDeleted(OP_Operator *op)
00583 { removeUpdateTemplatesSink(op); }
00584
00585 protected:
00586 void addUpdateTemplatesSink(OP_Operator *op)
00587 {
00588 if( !op ) return;
00589 op->addUpdateTemplatesSink(this);
00590 myOperators.append(op, 1);
00591 }
00592 void removeUpdateTemplatesSink(OP_Operator *op)
00593 {
00594 if( !op ) return;
00595 op->removeUpdateTemplatesSink(this);
00596 myOperators.remove(op);
00597 }
00598 void removeAllTemplatesSinks()
00599 {
00600 for( int i = myOperators.entries(); i --> 0; )
00601 removeUpdateTemplatesSink(myOperators(i));
00602 }
00603
00604 private:
00605 OP_OperatorList myOperators;
00606 };
00607
00608 #endif