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