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  void bumpFileName();
80  void setSaveTime();
81 
82  // The following filename getters are for internal use only.
83  // They are here to support adding the "old_hip_file" and "new_hip_file"
84  // python kwargs to python scene event callbacks.
85  const UT_StringHolder &getLastFileName() const { return myLastFilename; }
86  const UT_StringHolder &getNextFileName() const { return myNextFilename; }
87 
88  /// Move the current .hip file to a numbered backup .hip file.
89  /// A simple wrapper around OP_Director::autoIncrementRename() to avoid
90  /// doing anything when we don't have write access to our filename. It
91  /// returns false in this case, and true if autoIncrementRename() was
92  /// called, whether or not it succeeded.
93  bool moveFileNameToNumberedBackup(
94  UT_String &errorstring, bool autosave);
95  /// Move the current .hip file to a numbered backup .hip file.
96  /// Overload of the previous function that has the same behaviour, except
97  /// it also stores the filename of the backup in "backup_filename". If the
98  /// function fails, "backup_filename" stores an empty string.
99  bool moveFileNameToNumberedBackup(
100  UT_String &backup_filename, UT_String &errorstring,
101  bool autosave);
102 
103  /// Copy the current .hip file to a numbered backup .hip file.
104  /// A simple wrapper around OP_Director::autoIncrementRename() to avoid
105  /// doing anything when we don't have write access to our filename. It
106  /// returns false in this case, and true if autoIncrementRename() was
107  /// called, whether or not it succeeded.
108  bool copyFileNameToNumberedBackup(
109  UT_String &errorstring, bool autosave);
110 
111  // Copy the current .hip file to a numbered backup .hip file.
112  // Overload of the previous function that has the same behaviour, except
113  // it also stores the filename of the backup in "backup_filename". If the
114  // function fails, "backup_filename" stores an empty string.
115  bool copyFileNameToNumberedBackup(
116  UT_String &backup_filename, UT_String &errorstring,
117  bool autosave);
118 
119  // Clean up for the new file. We don't call runPostNewScript automatically
120  // to give the caller time to perform additional cleanup first, so be sure
121  // to call it later.
122  void resetForNewFile();
123 
124  // Call after resetForNewFile() and any additional related cleanup. The
125  // script execution will not change our state to modified.
126  void runPostNewScript();
127 
128  // Called prior to and after loading a hip file.
129  void beginLoading() override;
130  void endLoading() override;
131 
132  // This function does nothing at this level, but it is meant to be
133  // overridden to create new OP_OperatorInfos for the given table based
134  // on the existance of VOP networks.
136  const char *indexPath,
137  OP_OTLDefinitionArray &defs) override;
138  OP_Node *linkInternalScriptOperator(const char *definitionOp,
139  OP_Operator *op) override;
140  void getInternalScriptDefinition(OP_Node *definitionOp,
141  UT_String &definition) override;
142  void updateExportedParms(OP_Node *definitionOp) override;
143 
144  // Here we actually implement the saving and loading of the spare parms
145  // definition sections for a node.
147  bool compiled,
148  std::ostream &os) const override;
150  UT_IStream &is,
151  UT_String &errors) const override;
152  // Here we implement the functions for adding and removing a single
153  // spare parameter from a node. By implementing the functions here we
154  // have access to the PI_EditScriptedParms class.
155  bool addNodeSpareParm(
156  OP_Parameters *node,
157  PRM_Template *parmtemplate) const override;
158  bool removeNodeSpareParm(
159  OP_Parameters *node,
160  const char *parmname,
161  UT_StringArray *errs=nullptr,
162  UT_StringArray *warn=nullptr) const override;
163  // Implement the OP_Director convenience function for changing the
164  // spare parameters of a node to match a PI_EditScriptedParms.
167  UT_String &errors) const override;
168  // Implement saving out commands for replicating the spare parameters
169  // of a node for use by the opscript command.
171  OP_Parameters *node,
172  std::ostream &os,
173  const char *nodename,
174  bool saveempty) const override;
175  // Delete spare parameter/base parameter mixing layout. This puts the
176  // spare parameters on their own page.
178  OP_Parameters *node) const override;
179  // Delete all spare parameters on a node.
181  OP_Parameters *node) const override;
182 
183  // Implement allocation of the PRM_ScriptPage. This is done when the node
184  // parses the spare parameters from a dialog script. However, for
185  // callbacks and other features, we need to parse a script page from PI.
187 
188  // Functions for saving and loading compiled VEX and RSL code for nodes
189  // with VOP_CodeGenerators in a compiled hip file.
190  void saveNodeCompiledCode(OP_Node *node, std::ostream &os,
191  bool is_source_code = false) override;
192  bool loadNodeCompiledCode(OP_Node *node, UT_IStream &is,
193  bool is_source_code = false) override;
194  void saveNodeCompiledDs(
195  OP_Node *node,
196  std::ostream &os) override;
197  bool loadNodeCompiledDs(
198  OP_Node *node,
199  UT_IStream &is) override;
200 
201  // createNewOp does NOT call runCreateScript for the Op
202  static OP_Node *createNewOp(const OP_Network *net, const char *opname,
203  const char *node_name=nullptr);
204  // If the current network has a sub-network operator the method
205  // hasSubNetworks returns the name of that operator. This is used
206  // to determine if the createSubNetwork method can be used in order
207  // to build sub-nets from selected nodes.
208  static const char *hasSubNetworks(OP_Network *net);
209 
210  // The buildSubNetwork callback does all the cutting and pasting
211  // required to convert the selected nodes into a sub-network.
212  // OPUI_App::clearDialogPointers() should be called before buildSubNetwork.
213  // This returns the created subnetwork, if any. It has been made
214  // current, so the caller will likely want to do pathNodeChanged
215  // on it.
216  // If from_nodes is provided, those nodes are used instead of the selected
217  // nodes. The from_nodes array may be modified to remove illegal nodes.
218  // If subnet_type_name is provided, that't the subnet type that will
219  // be created, instead of the primary subnet operator type.
220  static OP_Network *buildSubNetwork(OP_Network *net, UT_String &err,
221  const OP_NodeList *from_nodes = nullptr,
222  const OP_NetworkBoxItemList *from_items=nullptr,
223  const char *preferred_subnet_name = nullptr,
224  const char *subnet_type_name = nullptr);
225 
226  // The extractSubNetwork callback does all the cutting and pasting
227  // required to convert the selected sub-network into a set of nodes.
228  static void extractSubNetwork(OP_Network *subnet,
229  OP_NetworkBoxItemList &extracted_items,
230  UT_String &err);
231 
232  // This will go through the entire hip file and cook all the CHOPs
233  // that have their export flags set and cook them with CookOverride
234  // turned on.
235  void opUpdateAllExports() override;
236 
237  // Called when we become (or stop being) the main director.
238  void enable(int state) override;
239 
240  // Returns false if an error has occurred and writes error messages to
241  // warnings_or_errors.
242  // Returns true if file loaded or merged successfully, but
243  // warnings_or_errors may contain warning messages.
244  bool loadOrMergeHipFile(const char *file_name,
245  bool merge, const char *pattern,
246  bool overwrite,
247  UT_String &warnings_or_errors);
248 
249  // Returns an error message if an error has occurred
250  // Returns an empty string if file opened/checked successfully
251  void getCollisionsIfMerged(const char *file_name,
252  OP_NodeList &node_collisions,
254  &netbox_collisions,
256  &pnote_collisions,
257  const char *pattern,
258  UT_String &errors);
259 
260  // Saves the current hip file to the given file name.
261  OP_ERROR saveHipFile(const char *file_name,
262  bool channels_only, UT_String &errors,
263  bool autosave = false);
264 
265  // Saves the network to a file. Handles implied compression.
266  OP_ERROR saveNetworkToFile(const char *file_name,
267  const OP_SaveFlags &flags,
268  UT_String &errors);
269 
270  // Returns the status of MOT_Director: true if MOT_Director is
271  // loading hip file, doing explicit save, or shutting down.
272  // This method should be used for verifying MOT_Director is not busy
273  // before calling loadOrMergeHipFile, getCollisionsIfMerged,
274  // and saveHipFile methods.
275  bool isBusy(UT_String *msgs = nullptr);
276 
278  { return myGeometryChannelsManager; }
279 
280  bool runDSO(const char* lib_path);
281 
282  void clearHOMSessionModuleSource() override;
283  void saveHOMSessionModuleSource(std::ostream &os) override;
284  bool loadHOMSessionModuleSource(UT_IStream &is) override;
285 
286 protected:
287  // Clears out the saved PI settings when we update our definition.
288  void clearHandleSettings(OP_Operator *op) override;
289 
290 private:
291  void findInternalScriptOperators(const char *indexPath,
292  OP_OTLDefinitionArray &defs,
293  OP_Network *net);
294  void layoutManagers();
295  void execPythonRCFiles();
296  void execReadyFiles();
297  void installCommands();
298  void loadOpCustomizeFile();
299  void cacheChopnetOperators();
300  bool forceChopnetToExport(OP_Node &chop_network);
301 
302  MGR_Node *myObjects;
303  MGR_Node *myCop2;
304  MGR_Node *myRops;
305 #if 0
306  MGR_Node *myParticles;
307 #endif
308  MGR_Node *myChopNet;
309  MGR_Node *myShops;
310  MGR_Node *myVops;
311  MGR_Node *myMats;
312  LOP_Network *myLops;
313  MGR_Node *myTopNet;
314 
315  UT_String myFileName;
316  UT_StringHolder myLastFilename;
317  UT_StringHolder myNextFilename;
318 
319  // We cache the chopnet operators to speed up the process of forcing
320  // chop overrides to update when a node is added/renamed.
321  OP_OperatorList myChopnetOperators;
322 
323  UT_UniquePtr<MOT_ScriptNodeResolver> myScriptNodeResolver;
324 
326  mySpareParmsCache;
327 
328  MOT_GeometryChannelsManager myGeometryChannelsManager;
329 };
330 
331 #endif
MOT_GeometryChannelsManager & getGeometryChannelsManager()
Definition: MOT_Director.h:277
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:114
const UT_StringHolder & getNextFileName() const
Definition: MOT_Director.h:86
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:85
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:623
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:1141