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