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_Director_h__
00025 #define __OP_Director_h__
00026
00027 #include <UT/UT_IntArray.h>
00028 #include <UT/UT_PtrArray.h>
00029 #include <UT/UT_LHSTuple.h>
00030 #include <UT/UT_Thread.h>
00031 #include <UT/UT_ThreadSpecificValue.h>
00032 #include "OP_API.h"
00033 #include "OP_CommandManager.h"
00034 #include "OP_OTLManager.h"
00035 #include "OP_OperatorTable.h"
00036 #include "OP_Node.h"
00037 #include "OP_Network.h"
00038
00039 #define OP_POSTLOAD_SCRIPT "456.cmd"
00040
00041 class UT_WorkArgs;
00042 class UT_WorkBuffer;
00043 class UT_Args;
00044 class OP_SaveCallback;
00045 class OP_ExprFunc;
00046 class op_ShopClerkInfo;
00047 class OP_BundleList;
00048 class OP_Take;
00049 class OP_FileResolver;
00050 class OP_GlobContext;
00051 class PI_EditScriptedParms;
00052 class PRM_ScriptPage;
00053
00054 typedef void (*OP_GlobalOpChangedCallback)(OP_Node *node, OP_EventType reason,
00055 void *data, void *cbdata);
00056 typedef UT_PtrArray<OP_GlobalOpChangedCallback> OP_GlobalOpChangedCallbacks;
00057
00058 class OP_API OP_Director : public OP_Network, public OP_OTLManagerSink
00059 {
00060 public:
00061 OP_Director(const char *name, const float version,
00062 int load_dsos = 1);
00063 virtual ~OP_Director();
00064
00065 virtual OP_OpTypeId getOpTypeID() const { return DIR_OPTYPE_ID; }
00066 virtual const char *getOpType() const { return DIR_OPTYPE_NAME; }
00067 virtual OP_DATA_TYPE getCookedDataType() const { return OP_NO_DATA; }
00068 virtual void *getCookedData(OP_Context &) { return 0; }
00069 virtual void deleteCookedData() { }
00070 virtual int saveCookedData(ostream &, OP_Context &,
00071 int = 0) { return 1; }
00072 virtual bool loadCookedData(UT_IStream &, const char * =0)
00073 { return true; }
00074 virtual int saveCookedData(const char *,
00075 OP_Context &) { return 1; }
00076 virtual OP_OpTypeId getChildTypeID() const { return MGR_OPTYPE_ID; }
00077 virtual const char *getChildType() const { return MGR_OPTYPE_NAME; }
00078
00079 OP_Network *getManager(const char *name) const;
00080 CH_Manager *getChannelManager() { return &myCommandManager; }
00081 OP_CommandManager *getCommandManager() { return &myCommandManager; }
00082 float getVersion() const { return myVersion; }
00083
00084
00085
00086 bool loadChannelManagerOptions();
00087 bool saveChannelManagerOptions();
00088
00089 virtual void enable(int state);
00090
00091 OP_ERROR saveNetwork(ostream &os, const OP_SaveFlags &options);
00092 bool loadNetwork(UT_IStream &is, int merge=0,
00093 const char *mergePattern=0,
00094 int overwrite=0);
00095 virtual void clearNetwork( int clear_aliases );
00096
00097
00098
00099
00100 virtual void opUpdateAllExports();
00101
00102 void setOldCHOPOverrideFlag()
00103 { myOldCHOPOverrideFlag = true; }
00104 bool getOldCHOPOverrideFlag()
00105 { return myOldCHOPOverrideFlag; }
00106 void clearOldCHOPOverrideFlag()
00107 { myOldCHOPOverrideFlag = false; }
00108
00109 OP_Node *getCwd()
00110 { return getCwd(UTgetSTID()); }
00111 void getCwd(UT_String &str)
00112 { getCwd(UTgetSTID(), str); }
00113
00114 OP_Node *getCwd(int thread);
00115 void getCwd(int thread, UT_String &str);
00116 void setCwd(int thread, const OP_Node *node,
00117 int eval_collection=-1);
00118
00119
00120
00121
00122 void pushCwd(int thread, const OP_Node *new_cwd = NULL);
00123 void popCwd(int thread);
00124
00125 bool getPickedNodes(OP_NodeList &picked_nodes,
00126 bool include_hidden=false,
00127 bool append_to_list=false) const;
00128 const UT_IntArray & getPickedNodeIds() const
00129 { return myPickedNodeIds; }
00130 OP_Node * getLastPickedNode(OP_Node *parent = NULL) const;
00131
00132 void clearPickedItems();
00133
00134
00135
00136
00137 void makeOnlyPickedCurrent(OP_NetworkBoxItem &item);
00138
00139 void setEditNetworkUI(OP_Network *net);
00140
00141
00142
00143
00144
00145
00146 void addPickedNode(const OP_Node &node, bool edit);
00147 void removePickedNode(const OP_Node &node, bool edit);
00148 void makePickedNodeLast(const OP_Node &node, bool edit);
00149
00150
00151
00152
00153
00154
00155 void addPickedNetworkBox(const OP_NetworkBox &netbox);
00156 void removePickedNetworkBox(const OP_NetworkBox &netbox);
00157
00158 void addPickedPostItNote(const OP_PostIt &pnote);
00159 void removePickedPostItNote(const OP_PostIt &pnote);
00160
00161 void setTime(double time);
00162 void setFPS(float fps);
00163 void setNFrames(float nframes);
00164 void setTimeRange(float tstart, float tend);
00165
00166
00167
00168
00169
00170
00171
00172 void setSaveCallback(OP_ERROR (*cb)(ostream &, void *),
00173 void *callbackData);
00174 void removeSaveCallback(OP_ERROR (*cb)(ostream &, void *),
00175 void *callbackData);
00176
00177
00178 void setCustomPanelSaveCallback(
00179 OP_ERROR (*cb)(ostream &, void *),
00180 void *callbackData);
00181 void setUserDisplayOptionSaveCallback(
00182 OP_ERROR (*cb)(ostream &, void *),
00183 void *callbackData);
00184 void addBadLoadData(char *str, int len);
00185 virtual int isManager() const;
00186
00187 int isLoading() const { return (myInLoadCount > 0); }
00188 void beginLoading();
00189 void endLoading();
00190 bool getIsLoadingHip() const
00191 { return myIsLoadingHip; }
00192 bool getIsQuitting() const
00193 { return myIsQuitting; }
00194 void setIsDoingExplicitSave(bool value)
00195 { myIsDoingExplicitSave = value; }
00196 bool getIsDoingExplicitSave() const
00197 { return myIsDoingExplicitSave; }
00198
00199 bool getIsMantra() const { return myIsMantra; }
00200 void setIsMantra(bool v) { myIsMantra = v; }
00201
00202 void destroyFileResolver();
00203
00204 void beginTakeSwitch();
00205 void endTakeSwitch();
00206 bool isSwitchingTake() const
00207 { return mySwitchingTake; }
00208
00209 virtual int renameNode(OP_Node *, const char *,
00210 OP_RenameAction);
00211
00212
00213 void saveChannelGroups(ostream &os, int binary);
00214 bool loadChannelGroups(UT_IStream &is, const char *path);
00215 void saveTimeGroups(ostream &os, int binary);
00216 bool loadTimeGroups(UT_IStream &is, const char *path);
00217 void saveScriptedOpLibrary(ostream &os);
00218 bool loadScriptedOpLibrary(UT_IStream &is, int modtime);
00219 bool loadScriptedOpDefs(UT_IStream &is);
00220 void saveInternalOpLibraries(ostream &os);
00221 bool loadInternalOpLibraries(UT_IStream &is);
00222 void saveLibraryPreferences(ostream &os);
00223 bool loadLibraryPreferences(UT_IStream &is);
00224 bool loadHOMSessionModuleSource(UT_IStream &is);
00225 void saveUnselectedFilePatterns(ostream &os);
00226 bool loadUnselectedFilePatterns(UT_IStream &is);
00227
00228 void saveOTLBackupInformation(ostream &os);
00229
00230 OP_ExprFunc *getExprFunctions();
00231 void saveExprFunctions(ostream &os);
00232 bool loadExprFunctions(UT_IStream &is, const char *path);
00233
00234 OP_BundleList *getBundles() { return myBundles; }
00235
00236 int incrPasteCount() { return ++myPasteCount; }
00237 void resetPasteCount() { myPasteCount = 0; }
00238
00239
00240
00241
00242 int getAuthorId(const char *name=0);
00243 const char *getAuthorName(int id);
00244
00245
00246 int cookEnabled() const
00247 { return myCookEnabled; }
00248 void setCookEnabled(int state)
00249 { myCookEnabled = state; }
00250
00251
00252 int simulationEnabled() const
00253 { return mySimulationEnabled; }
00254 void setSimulationEnabled(int state)
00255 { mySimulationEnabled = state; }
00256
00257
00258
00259 bool skipPlaybarBasedSimulationReset() const
00260 { return mySkipPlaybarBasedSimulationReset > 0; }
00261 void bumpSkipPlaybarBasedSimulationReset(int inc)
00262 { mySkipPlaybarBasedSimulationReset += inc; }
00263
00264
00265 bool addShopClerk(const char *type);
00266 int getNShopClerks() const
00267 { return myShopInfo.entries(); }
00268 const char *getShopClerkName(int clerk) const;
00269 int getShopClerkVisibility(int clerk) const;
00270 void setShopClerkVisibility(int clerk, int onoff);
00271
00272
00273
00274
00275 virtual void findInternalScriptOperators(
00276 const char * ,
00277 OP_OTLDefinitionArray & )
00278 { }
00279 virtual OP_Node *linkInternalScriptOperator(
00280 const char * ,
00281 OP_Operator * )
00282 { return 0; }
00283 virtual void getInternalScriptDefinition(
00284 OP_Node * ,
00285 UT_String & )
00286 { }
00287
00288
00289
00290
00291 virtual OP_ERROR saveNodeSpareParms(OP_Parameters *,
00292 bool,
00293 ostream &) const
00294 { return UT_ERROR_NONE; }
00295
00296
00297
00298 virtual bool loadNodeSpareParms(OP_Parameters *,
00299 UT_IStream &,
00300 UT_String &) const
00301 { return true; }
00302
00303
00304
00305
00306 virtual bool addNodeSpareParm(OP_Parameters * ,
00307 PRM_Template * ) const
00308 { return false; }
00309
00310
00311
00312
00313 virtual bool removeNodeSpareParm(OP_Parameters * ,
00314 const char * ,
00315 UT_StringArray * = NULL,
00316 UT_StringArray * = NULL
00317 ) const
00318 { return false; }
00319
00320
00321
00322 virtual void changeNodeSpareParms(OP_Parameters *,
00323 PI_EditScriptedParms &,
00324 UT_String &) const
00325 { }
00326
00327
00328 virtual void saveNodeSpareParmCommands(OP_Parameters *,
00329 ostream &,
00330 const char *,
00331 bool) const
00332 { }
00333
00334
00335 virtual void deleteNodeSpareParmLayout(OP_Parameters *) const
00336 { }
00337
00338 virtual void deleteAllNodeSpareParms(OP_Parameters *) const
00339 { }
00340
00341 virtual PRM_ScriptPage *allocateSpareScriptPage(OP_Operator *)
00342 { return 0; }
00343
00344
00345
00346 virtual void saveNodeCompiledCode(OP_Node *, ostream &)
00347 { }
00348 virtual bool loadNodeCompiledCode(OP_Node *, UT_IStream &)
00349 { return true; }
00350 virtual void saveNodeCompiledDs(OP_Node *, ostream &)
00351 { }
00352 virtual bool loadNodeCompiledDs(OP_Node *, UT_IStream &)
00353 { return true; }
00354
00355 OP_Take *getTakeManager() { return myTakeManager; }
00356
00357
00358 virtual void addExtraInput(OP_Node *op, OP_InterestType type);
00359
00360
00361
00362 static int globAllArguments(OP_Node *node, UT_Args &args,
00363 UT_WorkBuffer &workbuf,
00364 UT_WorkArgs &argv,
00365 OP_ItemTypeMask item_type,
00366 OP_GlobContext *context,
00367 int startitem = 1);
00368
00369
00370
00371
00372 static void globAllArgumentsAsArray(OP_Node &relative_to_node,
00373 const char *pattern,
00374 OP_ItemTypeMask item_type,
00375 OP_GlobContext &glob_context,
00376 UT_PtrArray<OP_NetworkBoxItem *> &result);
00377
00378
00379
00380 virtual void definitionsAdded(int libindex,
00381 UT_IntArray &defindex);
00382 virtual void definitionsRemoved(int libindex,
00383 UT_IntArray &defindex,
00384 OP_OTLLibrary *&preserve);
00385
00386
00387
00388
00389
00390
00391
00392 void getTableAndOperator(const char *path,
00393 OP_OperatorTable *&table,
00394 OP_Operator *&op,
00395 const OP_Node *relativetonode = 0);
00396 OP_OTLManager &getOTLManager()
00397 { return myOTLManager; }
00398 const OP_OTLManager &getOTLManager() const
00399 { return myOTLManager; }
00400
00401
00402
00403
00404 void runDeleteScriptsOnQuit();
00405
00406
00407
00408 void addGlobalOpChangedCallback(
00409 OP_GlobalOpChangedCallback cb, void *cbdata);
00410 void removeGlobalOpChangedCallback(
00411 OP_GlobalOpChangedCallback cb, void *cbdata);
00412
00413
00414
00415 void globalOpChanged(OP_Node *node,
00416 OP_EventType reason,
00417 void *data);
00418
00419
00420
00421
00422
00423 static bool createBackupFile(const char *filename);
00424
00425
00426
00427 static void autoIncrementRename(const char *filename,
00428 UT_String &errorstring,
00429 bool movefile,
00430 bool autosave);
00431
00432
00433
00434 void runScript(CMD_Manager *cman, const char *filename);
00435 boost::tuple<bool, int> runPython(CMD_Manager *cman, const char *filename);
00436 boost::tuple<bool, int> runPython(CMD_Manager *cman, int argc,
00437 char *argv[]);
00438 boost::tuple<bool, int> runDefaultStartupScripts(CMD_Manager *cman,
00439 const char *startup_script,
00440 const char *postload_script);
00441
00442
00443
00444 static void destroyDirector(OP_Director *opdir);
00445
00446 protected:
00447 virtual OP_ERROR cookMe(OP_Context &) { return UT_ERROR_NONE; }
00448 virtual OP_ERROR bypassMe(OP_Context &, int &) { return UT_ERROR_NONE; }
00449 virtual const char *getFileExtension(int binary) const
00450 { return binary ? ".bhip" : ".hip"; }
00451 void clearUnsupportedCommands() const;
00452
00453
00454
00455
00456 virtual void clearHandleSettings(OP_Operator *) { }
00457
00458
00459 virtual bool changeSpareParms(UT_IStream &, UT_String &errors)
00460 {
00461 errors += "Spare parameters are not alowed on ";
00462 errors += "the root node.";
00463 return false;
00464 }
00465
00466
00467
00468 void runPostLoadScript();
00469
00470 private:
00471
00472
00473 OP_Director(const OP_Director ©);
00474 OP_Director &operator =(const OP_Director ©);
00475
00476 void installCommands();
00477 void installMoreCommands();
00478 void installCHCommands();
00479 void installOTLCommands();
00480 void savePreCommands(ostream &os);
00481 void savePostCommands(ostream &os);
00482
00483
00484
00485
00486
00487
00488
00489 void getFirstFoundScriptFile(UT_String &outputpath,
00490 const char *inputpath);
00491
00492 int myPasteCount;
00493 char *myBadLoadData;
00494 int myBadLoadDataLen;
00495 OP_CommandManager myCommandManager;
00496 float myVersion;
00497 int myInLoadCount;
00498
00499 struct CwdContext
00500 {
00501 CwdContext() : myCwdId(-1)
00502 {
00503 }
00504 int myCwdId;
00505 UT_IntArray myCwdStack;
00506 UT_IntArray myEvalCollectionStack;
00507 };
00508 UT_ThreadSpecificValue<CwdContext> myCwdContext;
00509
00510 UT_IntArray myPickedNodeIds;
00511 UT_IntArray myPickedNetworkBoxIds;
00512 UT_IntArray myPickedPostItIds;
00513
00514 OP_SaveCallback *myCallbacks;
00515 OP_SaveCallback *myCustomPanelCallback;
00516 OP_SaveCallback *myUserDisplayOptionCallback;
00517 OP_BundleList *myBundles;
00518 OP_Take *myTakeManager;
00519 OP_FileResolver *myFileResolver;
00520
00521 int myCookEnabled;
00522 int mySimulationEnabled;
00523 int mySkipPlaybarBasedSimulationReset;
00524 UT_PtrArray<op_ShopClerkInfo *> myShopInfo;
00525
00526 OP_OTLManager myOTLManager;
00527 OP_OperatorTableList myTablesToReload;
00528 UT_SymbolTable *myDummyDefinitionActivations;
00529
00530 OP_GlobalOpChangedCallbacks myGlobalOpChangedCallbacks;
00531 UT_PtrArray<void *> myGlobalOpChangedCallbackData;
00532
00533
00534
00535
00536 bool myOldCHOPOverrideFlag;
00537
00538
00539
00540 bool myIsLoadingHip;
00541 bool mySwitchingTake;
00542
00543
00544
00545 bool myIsDoingExplicitSave;
00546
00547 bool myIsQuitting;
00548
00549
00550
00551
00552 bool myIsMantra;
00553 };
00554
00555 OP_API extern OP_Director *OPgetDirector();
00556 OP_API extern OP_Director *OPsetDirector(OP_Director *boss);
00557
00558 #endif