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