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