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