HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MOT_Director.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: MOT library (C++)
7  *
8  * COMMENTS: This is the OP_Director class for all of MOT files
9  *
10  */
11 
12 #ifndef __MOT_Director_h__
13 #define __MOT_Director_h__
14 
15 #include "MOT_API.h"
16 #include <OP/OP_Director.h>
17 #include <UT/UT_UniquePtr.h>
18 
19 class MGR_Node;
20 class LOP_Network;
21 class CHOP_Node;
22 class CMD_Args;
23 class MOT_ScriptNodeResolver;
24 
26 {
27 public:
28  MOT_Director(const char *appname, bool alloptypes = true,
29  bool exec_pythonrc = true,
30  bool exec_startup_scripts = false);
31  virtual ~MOT_Director();
32 
33  virtual OP_Node *getChild(const char *name, int *hint=0) const;
34  virtual OP_Node *getChild(int index) const;
35 
36  static const char *theChildTableName;
37 
38  virtual void clearNetwork( int clear_aliases );
39 
40  MGR_Node *getObjectManager() { return myObjects; }
41  MGR_Node *getCopManager() { return myCop; }
42  MGR_Node *getRenderManager() { return myRops; }
43  MGR_Node *getParticleManager() { return myParticles; }
44  MGR_Node *getChopNetManager() { return myChopNet; }
45  MGR_Node *getShopManager() { return myShops; }
46  MGR_Node *getVopManager() { return myVops; }
47  MGR_Node *getMatManager() { return myMats; }
48  LOP_Network *getLopManager() { return myLops; }
49 
50  const UT_String &getFileName() const { return myFileName; }
51  void setFileName(const char *nm);
52  void bumpFileName();
53  void setSaveTime();
54 
55  // A simple wrapper around OP_Director::autoIncrementRename() to avoid
56  // doing anything when we don't have write access to our filename. It
57  // returns false in this case, and true if autoIncrementRename() was
58  // called, whether or not it succeeded.
59  bool moveFileNameToNumberedBackup(UT_String &errorstring,
60  bool autosave);
61 
62  // Clean up for the new file. We don't call runPostNewScript automatically
63  // to give the caller time to perform additional cleanup first, so be sure
64  // to call it later.
65  void resetForNewFile();
66 
67  // Call after resetForNewFile() and any additional related cleanup. The
68  // script execution will not change our state to modified.
69  void runPostNewScript();
70 
71  // Called prior to and after loading a hip file.
72  virtual void beginLoading();
73  virtual void endLoading();
74 
75  // This function does nothing at this level, but it is meant to be
76  // overridden to create new OP_OperatorInfos for the given table based
77  // on the existance of VOP networks.
78  virtual void findInternalScriptOperators(const char *indexPath,
79  OP_OTLDefinitionArray &defs);
80  virtual OP_Node *linkInternalScriptOperator(const char *definitionOp,
81  OP_Operator *op);
82  virtual void getInternalScriptDefinition(OP_Node *definitionOp,
83  UT_String &definition);
84  virtual void updateExportedParms(OP_Node *definitionOp);
85 
86  // Here we actually implement the saving and loading of the spare parms
87  // definition sections for a node.
89  bool compiled,
90  std::ostream &os) const;
91  virtual bool loadNodeSpareParms(OP_Parameters *node,
92  UT_IStream &is,
93  UT_String &errors) const;
94  // Here we implement the functions for adding and removing a single
95  // spare parameter from a node. By implementing the functions here we
96  // have access to the PI_EditScriptedParms class.
97  virtual bool addNodeSpareParm(OP_Parameters *node,
98  PRM_Template *parmtemplate) const;
99  virtual bool removeNodeSpareParm(OP_Parameters *node,
100  const char *parmname,
101  UT_StringArray *errs = NULL,
102  UT_StringArray *warn = NULL) const;
103  // Implement the OP_Director convenience function for changing the
104  // spare parameters of a node to match a PI_EditScriptedParms.
105  virtual void changeNodeSpareParms(OP_Parameters *node,
106  PI_EditScriptedParms &parms,
107  UT_String &errors) const;
108  // Implement saving out commands for replicating the spare parameters
109  // of a node for use by the opscript command.
110  virtual void saveNodeSpareParmCommands(OP_Parameters *node,
111  std::ostream &os,
112  const char *nodename,
113  bool saveempty) const;
114  // Delete spare parameter/base parameter mixing layout. This puts the
115  // spare parameters on their own page.
116  virtual void deleteNodeSpareParmLayout(OP_Parameters *node) const;
117  // Delete all spare parameters on a node.
118  virtual void deleteAllNodeSpareParms(OP_Parameters *node) const;
119 
120  // Implement allocation of the PRM_ScriptPage. This is done when the node
121  // parses the spare parameters from a dialog script. However, for
122  // callbacks and other features, we need to parse a script page from PI.
124 
125  // Functions for saving and loading compiled VEX and RSL code for nodes
126  // with VOP_CodeGenerators in a compiled hip file.
127  virtual void saveNodeCompiledCode(OP_Node *node, std::ostream &os,
128  bool is_source_code = false);
129  virtual bool loadNodeCompiledCode(OP_Node *node, UT_IStream &is,
130  bool is_source_code = false);
131  virtual void saveNodeCompiledDs(OP_Node *node, std::ostream &os);
132  virtual bool loadNodeCompiledDs(OP_Node *node, UT_IStream &is);
133 
134  // createNewOp does NOT call runCreateScript for the Op
135  static OP_Node *createNewOp(const OP_Network *net, const char *opname,
136  const char *node_name=NULL);
137  // If the current network has a sub-network operator the method
138  // hasSubNetworks returns the name of that operator. This is used
139  // to determine if the createSubNetwork method can be used in order
140  // to build sub-nets from selected nodes.
141  static const char *hasSubNetworks(OP_Network *net);
142 
143  // The buildSubNetwork callback does all the cutting and pasting
144  // required to convert the selected nodes into a sub-network.
145  // OPUI_App::clearDialogPointers() should be called before buildSubNetwork.
146  // This returns the created subnetwork, if any. It has been made
147  // current, so the caller will likely want to do pathNodeChanged
148  // on it.
149  // If from_nodes is provided, those nodes are used instead of the selected
150  // nodes. The from_nodes array may be modified to remove illegal nodes.
151  // If subnet_type_name is provided, that't the subnet type that will
152  // be created, instead of the primary subnet operator type.
153  static OP_Network *buildSubNetwork(OP_Network *net, UT_String &err,
154  const OP_NodeList *from_nodes = nullptr,
155  const OP_NetworkBoxItemList *from_items=nullptr,
156  const char *preferred_subnet_name = nullptr,
157  const char *subnet_type_name = nullptr);
158 
159  // The extractSubNetwork callback does all the cutting and pasting
160  // required to convert the selected sub-network into a set of nodes.
161  static void extractSubNetwork(OP_Network *subnet,
162  OP_NetworkBoxItemList &extracted_items,
163  UT_String &err);
164 
165  // This will go through the entire hip file and cook all the CHOPs
166  // that have their export flags set and cook them with CookOverride
167  // turned on.
168  virtual void opUpdateAllExports();
169 
170  // Called when we become (or stop being) the main director.
171  virtual void enable(int state);
172 
173  // Returns false if an error has occurred and writes error messages to
174  // warnings_or_errors.
175  // Returns true if file loaded or merged successfully, but
176  // warnings_or_errors may contain warning messages.
177  bool loadOrMergeHipFile(const char *file_name,
178  bool merge, const char *pattern,
179  bool overwrite,
180  UT_String &warnings_or_errors);
181 
182  // Returns an error message if an error has occurred
183  // Returns an empty string if file opened/checked successfully
184  void getCollisionsIfMerged(const char *file_name,
185  OP_NodeList &node_collisions,
187  &netbox_collisions,
189  &pnote_collisions,
190  const char *pattern,
191  UT_String &errors);
192 
193  // Saves the current hip file to the given file name
194  void saveHipFile(const char *file_name,
195  bool channels_only, UT_String &errors);
196 
197  // Returns the status of MOT_Director: true if MOT_Director is
198  // loading hip file, doing explicit save, or shutting down.
199  // This method should be used for verifying MOT_Director is not busy
200  // before calling loadOrMergeHipFile, getCollisionsIfMerged,
201  // and saveHipFile methods.
202  bool isBusy(UT_String *msgs = nullptr);
203 
204 protected:
205  // Clears out the saved PI settings when we update our definition.
206  virtual void clearHandleSettings(OP_Operator *op);
207 
208 private:
209  void findInternalScriptOperators(const char *indexPath,
210  OP_OTLDefinitionArray &defs,
211  OP_Network *net);
212  void layoutManagers();
213  void execPythonRCFiles();
214  void installCommands();
215  void loadOpCustomizeFile();
216  void cacheChopnetOperators();
217  bool forceChopnetToExport(OP_Node &chop_network);
218 
219  MGR_Node *myObjects;
220  MGR_Node *myCop;
221  MGR_Node *myRops;
222  MGR_Node *myParticles;
223  MGR_Node *myChopNet;
224  MGR_Node *myShops;
225  MGR_Node *myVops;
226  MGR_Node *myMats;
227  LOP_Network *myLops;
228 
229  UT_String myFileName;
230 
231  // We cache the chopnet operators to speed up the process of forcing
232  // chop overrides to update when a node is added/renamed.
233  OP_OperatorList myChopnetOperators;
234 
235  UT_UniquePtr<MOT_ScriptNodeResolver> myScriptNodeResolver;
236 
238  mySpareParmsCache;
239 };
240 
241 #endif
virtual bool addNodeSpareParm(OP_Parameters *, PRM_Template *) const
Definition: OP_Director.h:341
MGR_Node * getRenderManager()
Definition: MOT_Director.h:42
MGR_Node * getCopManager()
Definition: MOT_Director.h:41
Unsorted map container.
Definition: UT_Map.h:83
virtual void enable(int state)
virtual void findInternalScriptOperators(const char *, OP_OTLDefinitionArray &)
Definition: OP_Director.h:307
virtual bool loadNodeSpareParms(OP_Parameters *, UT_IStream &, UT_String &) const
Definition: OP_Director.h:333
UT_ErrorSeverity
Definition: UT_Error.h:25
virtual void beginLoading()
MGR_Node * getVopManager()
Definition: MOT_Director.h:46
virtual void clearHandleSettings(OP_Operator *)
Definition: OP_Director.h:527
virtual void deleteAllNodeSpareParms(OP_Parameters *) const
Definition: OP_Director.h:373
MGR_Node * getObjectManager()
Definition: MOT_Director.h:40
virtual void opUpdateAllExports()
LOP_Network * getLopManager()
Definition: MOT_Director.h:48
virtual void updateExportedParms(OP_Node *)
Definition: OP_Director.h:319
virtual void clearNetwork(int clear_aliases)
virtual bool loadNodeCompiledDs(OP_Node *, UT_IStream &)
Definition: OP_Director.h:389
virtual bool loadNodeCompiledCode(OP_Node *, UT_IStream &, bool is_source_code=false)
Definition: OP_Director.h:384
#define MOT_API
Definition: MOT_API.h:10
MGR_Node * getShopManager()
Definition: MOT_Director.h:45
virtual OP_ERROR saveNodeSpareParms(OP_Parameters *, bool, std::ostream &) const
Definition: OP_Director.h:326
virtual bool removeNodeSpareParm(OP_Parameters *, const char *, UT_StringArray *=NULL, UT_StringArray *=NULL) const
Definition: OP_Director.h:348
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual OP_Node * linkInternalScriptOperator(const char *, OP_Operator *)
Definition: OP_Director.h:311
virtual void getInternalScriptDefinition(OP_Node *, UT_String &)
Definition: OP_Director.h:315
virtual void deleteNodeSpareParmLayout(OP_Parameters *) const
Definition: OP_Director.h:370
Create an evaluation context scope with a new node.
Definition: OP_Director.h:60
virtual void endLoading()
virtual void saveNodeSpareParmCommands(OP_Parameters *, std::ostream &, const char *, bool) const
Definition: OP_Director.h:363
GLuint index
Definition: glcorearb.h:785
virtual void saveNodeCompiledDs(OP_Node *, std::ostream &)
Definition: OP_Director.h:387
MGR_Node * getMatManager()
Definition: MOT_Director.h:47
virtual PRM_ScriptPage * allocateSpareScriptPage(OP_Operator *)
Definition: OP_Director.h:376
MGR_Node * getChopNetManager()
Definition: MOT_Director.h:44
virtual void saveNodeCompiledCode(OP_Node *, std::ostream &, bool is_source_code=false)
Definition: OP_Director.h:381
virtual void changeNodeSpareParms(OP_Parameters *, PI_EditScriptedParms &, UT_String &) const
Definition: OP_Director.h:357
MGR_Node * getParticleManager()
Definition: MOT_Director.h:43
const UT_String & getFileName() const
Definition: MOT_Director.h:50
static const char * theChildTableName
Definition: MOT_Director.h:36
virtual OP_Node * getChild(const char *name=0, int *hint=0) const
friend class MOT_Director
Definition: OP_Network.h:1044