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