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