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