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