HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HOM_Module.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  * COMMENTS:
7  * This class is not directly wrapped by swig. However, when creating
8  * the swig wrapper modules we wrap each of the methods of this class
9  * in functions. This way, the methods of this class appear as the
10  * top-level parts of the hou module.
11  */
12 
13 #ifndef __HOM_Module_h__
14 #define __HOM_Module_h__
15 
16 #include "HOM_API.h"
17 #include "HOM_BinaryString.h"
18 #include "HOM_Defines.h"
19 #include "HOM_Errors.h"
20 #include "HOM_ElemPtr.h"
21 #include "HOM_EnumModules.h"
23 #include <UT/UT_Lock.h>
24 #include <UT/UT_NonCopyable.h>
25 #include <UT/UT_Notifier.h>
26 #include <UT/UT_TaskLock.h>
27 #include <UT/UT_Thread.h>
28 #include <UT/UT_UniquePtr.h>
29 #include <UT/UT_OptionEntry.h>
30 #include <SYS/SYS_Types.h>
31 #include <typeinfo>
32 #include <string>
33 #include <vector>
34 #include <map>
35 #include <hboost/any.hpp>
36 
37 class OP_Node;
38 class STORUI_OrboltURLHandler;
39 
41 class HOM_AgentClip;
43 class HOM_AgentLayer;
44 class HOM_AgentMetadata;
45 class HOM_AgentRig;
46 class HOM_AgentShape;
51 class HOM_AttribDataId;
52 class HOM_anonstats;
53 class HOM_audio;
55 class HOM_ChopNode;
56 class HOM_Clip;
57 class HOM_Color;
58 class HOM_crowds;
60 class HOM_SimpleDrawable;
61 class HOM_dop;
62 class HOM_DopData;
63 class HOM_DopSimulation;
64 class HOM_Edge;
65 class HOM_EnumValue;
69 class HOM_GadgetContext;
70 class HOM_GadgetDrawable;
71 class HOM_galleries;
72 class HOM_Geometry;
75 class HOM_Handle;
76 class HOM_hda;
77 class HOM_HDADefinition;
78 class HOM_HDAModule;
79 class HOM_HDAOptions;
80 class HOM_hipFile;
81 class HOM_hmath;
82 class HOM_ik;
85 class HOM_Keyframe;
87 class HOM_logging;
91 class HOM_lop;
95 class HOM_Matrix4;
97 class HOM_NetworkBox;
98 class HOM_NetworkDot;
100 class HOM_Node;
101 class HOM_NodeBundle;
102 class HOM_NodeConnection;
103 class HOM_NodeType;
106 class HOM_Parm;
107 class HOM_ParmTemplate;
109 class HOM_ParmTuple;
110 class HOM_perfMon;
112 class HOM_pypanel;
113 class HOM_playbar;
114 class HOM_Point;
115 class HOM_Prim;
116 class HOM_properties;
117 class HOM_qt;
119 class HOM_RedrawBlock;
120 #ifndef SWIG
122 #endif
123 class HOM_SceneViewer;
125 class HOM_Selection;
127 class HOM_shelves;
128 class HOM_StickyNote;
129 class HOM_StringKeyframe;
131 class HOM_styles;
132 class HOM_StyleSheet;
134 class HOM_takes;
135 class HOM_text;
136 class HOM_TextDrawable;
138 class HOM_ui;
139 class HOM_hotkeys;
140 class HOM_UIEvent;
141 class HOM_UIEventDevice;
142 class HOM_undos;
143 class HOM_Vector3;
144 class HOM_Vertex;
145 class HOM_VexContext;
146 class HOM_ViewerEvent;
148 class HOM_ViewerDragger;
154 class HOM_ViewerStateMenu;
158 
159 #define HOM_SESSION_MODULE_NAME "hou.session"
160 #define HOM_SESSION_MODULE_CPIO_NAME "." HOM_SESSION_MODULE_NAME
161 
162 // Use this function to access the HOM module from C++ in Houdini. This
163 // is equivalent to writing "hou" in python. It will only throw an exception
164 // if the python module could not be imported, which should not happen.
165 class HOM_Module;
167 
169 {
170 public:
171  static void setHOMCreator(void (*homCreator)());
172 
173  virtual ~HOM_Module() {}
174 
175  virtual std::vector<std::string> _getArgumentAutoComplete(
176  const char *method_name, const char *arguments,
177  bool meta_info_only = false) = 0;
178 
179  // This method is called by the expression editor to force autocompletion
180  // to be relative to the node containing the expression. It is not
181  // wrapped by swig.
182  virtual void setRelativeNodeForAutoComplete(OP_Node *node) = 0;
183 
184  virtual HOM_ui& ui() = 0;
185  virtual HOM_qt& qt() = 0;
186  virtual HOM_hotkeys& hotkeys() = 0;
187  virtual HOM_audio& audio() = 0;
188  virtual bool isUIAvailable() = 0;
189  virtual bool _isExperimentalActive() = 0;
190  virtual bool _isCurrentThreadHoldingHOMLock() = 0;
191 
192  virtual HOM_galleries& galleries() = 0;
193  virtual HOM_hda& hda() = 0;
194  virtual HOM_hipFile& hipFile() = 0;
195  virtual HOM_perfMon& perfMon() = 0;
196  virtual HOM_playbar& playbar() = 0;
197  virtual HOM_pypanel& pypanel() = 0;
198  virtual HOM_hmath& hmath() = 0;
199  virtual HOM_dop& dop() = 0;
200  virtual HOM_properties& properties() = 0;
201  virtual HOM_shelves& shelves() = 0;
202  virtual HOM_styles& styles() = 0;
203  virtual HOM_takes& takes() = 0;
204  virtual HOM_undos& undos() = 0;
205  virtual HOM_viewportVisualizers& viewportVisualizers() = 0;
206  virtual HOM_anonstats& anonstats() = 0;
207  virtual HOM_crowds& crowds() = 0;
208  virtual HOM_ik& ik() = 0;
209  virtual HOM_logging& logging() = 0;
210  virtual HOM_lop& lop() = 0;
211  virtual HOM_text& text() = 0;
212 
213  virtual bool _assertWrapper(
214  const char *file, int linenum, const char *function,
215  const char *condition, const char *reason) = 0;
216 
217  virtual void exit(int exit_code=0, bool suppress_save_prompt=false) = 0;
218 
219  // isExiting() will return true if the program is actually Houdini (not
220  // mplay) and the UI queue is closed. This method is wrapped by swig, but
221  // only so houdiniInterpreter can call it.
222  virtual bool isExiting() = 0;
223 
224  virtual void addPreloadIcon(const char *name, int w, int h) = 0;
225  virtual void rasterizePreloadIcons() = 0;
226 
227  virtual std::string applicationName() = 0;
228  virtual std::vector<int> applicationVersion(bool include_patch=false) = 0;
229  virtual std::string applicationVersionString() = 0;
230  virtual std::string applicationCompilationDate() = 0;
231  virtual std::string applicationPlatformInfo() = 0;
232  virtual HOM_EnumValue &licenseCategory() = 0;
233  virtual bool isApprentice() = 0;
234  virtual void releaseLicense() = 0;
235 
236  // Threading controls
237  virtual int maxThreads() = 0;
238  virtual void setMaxThreads(int max_threads) = 0;
239 
240  // These methods return a new HOM_Node object.
241  virtual HOM_Node* root() = 0;
242  virtual HOM_Node* pwd() = 0;
243  virtual HOM_Node* parent() = 0;
244 
245  virtual void setPwd(HOM_Node &newpwd) = 0;
246  virtual void cd(const char *path) = 0;
247 
248  // Calling phm() is a shortcut for calling pwd().hdaModule().
249  virtual HOM_HDAModule* phm() = 0;
250 
251  // This method returns a new HOM_DopNetNode object or None.
252  virtual HOM_Node* currentDopNet() = 0;
253  virtual void setCurrentDopNet(HOM_Node &dopnet) = 0;
254 
255  // Gets or sets the simulation enabled state.
256  virtual bool simulationEnabled() = 0;
257  virtual void setSimulationEnabled(bool enabled) = 0;
258 
259  // These methods return a new HOM_Node object or null if the node couldn't
260  // be found.
261  virtual HOM_Node *node(const char *path) = 0;
262  virtual HOM_NetworkMovableItem* item(const char *path) = 0;
263 
264  virtual std::vector<HOM_ElemPtr<HOM_Node> > nodes(const std::vector<std::string> &paths) = 0;
265  virtual std::vector<HOM_ElemPtr<HOM_NetworkMovableItem> > items(const std::vector<std::string> &paths) = 0;
266 
267  virtual HOM_Node *nodeBySessionId(int session_id) = 0;
268  virtual HOM_NetworkBox *networkBoxBySessionId(int session_id) = 0;
269  virtual HOM_StickyNote *stickyNoteBySessionId(int session_id) = 0;
270  virtual HOM_SubnetIndirectInput *subnetIndirectInputBySessionId(
271  int64 session_id) = 0;
272  virtual HOM_NetworkDot *networkDotBySessionId(int session_id) = 0;
273  virtual HOM_NetworkMovableItem *itemBySessionId(
274  HOM_EnumValue &item_type, int64 session_id) = 0;
275  virtual HOM_NodeConnection *nodeConnectionBySessionId(
276  int node_session_id, int input_index) = 0;
277 
278  // Functions for configuring default colors on network elements.
279  virtual HOM_Color defaultColor(HOM_EnumValue &color_item) = 0;
280  virtual void setDefaultColor(HOM_EnumValue &color_item, HOM_Color *color) = 0;
281 
282  // Return HOM_Nodes for all selected nodes in the session.
283  virtual std::vector<HOM_ElemPtr<HOM_Node> > selectedNodes(
284  bool include_hidden = false) = 0;
285  virtual std::vector<HOM_ElemPtr<HOM_NetworkMovableItem> > selectedItems(
286  bool include_hidden = false) = 0;
287  virtual std::vector<HOM_ElemPtr<HOM_NodeConnection> > selectedConnections() = 0;
288  virtual void clearAllSelected() = 0;
289 
290  // Copy nodes to and paste from clipboard.
291  virtual void copyNodesToClipboard(const std::vector<HOM_Node *> &nodes) = 0;
292  virtual void pasteNodesFromClipboard(HOM_Node &destination_node) = 0;
293 
294  // These methods return new HOM_Parm/HOM_ParmTuple objects or null if the
295  // parm couldn't be found.
296  virtual HOM_Parm* parm(const char *path) = 0;
297  SWIGOUT(%ignore newParm;)
298  virtual HOM_Parm* newParm(OP_Node &node, int parm_index, int vector_index) = 0;
299  virtual HOM_ParmTuple* parmTuple(const char *path) = 0;
300  virtual HOM_Parm *evaluatingParm() = 0;
301 
302  virtual HOM_ScriptEvalContext * newScriptEvalContext(HOM_Node &node) = 0;
303  virtual HOM_ScriptEvalContext * newScriptEvalContext(HOM_Parm &parm) = 0;
304 
305  // Access to the contents of the parm clipboard
306  virtual std::vector< std::map<std::string, std::string> >
307  parmClipboardContents() = 0;
308 
309  // These methods return a new HOM_NodeType object or null if it couldn't
310  // be found.
311  virtual HOM_NodeType *nodeType(
312  HOM_NodeTypeCategory &category, const char *name) = 0;
313  virtual HOM_NodeType *nodeType(const char *name) = 0;
314 
315  virtual HOM_NodeType *preferredNodeType(
316  const char *name, HOM_Node *parentNode = NULL) = 0;
317 
318  virtual HOM_NodeTypeCategory &objNodeTypeCategory() = 0;
319  virtual HOM_NodeTypeCategory &sopNodeTypeCategory() = 0;
320 #if 0
321  virtual HOM_NodeTypeCategory &popNodeTypeCategory() = 0;
322 #endif
323  virtual HOM_NodeTypeCategory &dopNodeTypeCategory() = 0;
324  virtual HOM_NodeTypeCategory &cop2NodeTypeCategory() = 0;
325  virtual HOM_NodeTypeCategory &shopNodeTypeCategory() = 0;
326  virtual HOM_NodeTypeCategory &vopNodeTypeCategory() = 0;
327  virtual HOM_NodeTypeCategory &ropNodeTypeCategory() = 0;
328  virtual HOM_NodeTypeCategory &chopNodeTypeCategory() = 0;
329  virtual HOM_NodeTypeCategory &topNodeTypeCategory() = 0;
330  virtual HOM_NodeTypeCategory &lopNodeTypeCategory() = 0;
331 #if 0
332  virtual HOM_NodeTypeCategory &popNetNodeTypeCategory() = 0;
333 #endif
334  virtual HOM_NodeTypeCategory &cop2NetNodeTypeCategory() = 0;
335  virtual HOM_NodeTypeCategory &vopNetNodeTypeCategory() = 0;
336  virtual HOM_NodeTypeCategory &chopNetNodeTypeCategory() = 0;
337  virtual HOM_NodeTypeCategory &topNetNodeTypeCategory() = 0;
338  virtual HOM_NodeTypeCategory &managerNodeTypeCategory() = 0;
339  virtual HOM_NodeTypeCategory &rootNodeTypeCategory() = 0;
340  virtual std::map<std::string, HOM_NodeTypeCategory *>
341  nodeTypeCategories() = 0;
342 
343  virtual std::vector<HOM_ElemPtr<HOM_Node> > copyNodesTo(
344  const std::vector<HOM_Node *> &nodes,
345  HOM_Node &destination_node) = 0;
346  virtual std::vector<HOM_ElemPtr<HOM_Node> > moveNodesTo(
347  const std::vector<HOM_Node *> &nodes,
348  HOM_Node &destination_node) = 0;
349 
350  virtual HOM_NodeBundle *addNodeBundle(const char *name = NULL) = 0;
351  virtual std::vector<HOM_ElemPtr<HOM_NodeBundle> > nodeBundles() = 0;
352  virtual std::vector<HOM_ElemPtr<HOM_NodeBundle> > selectedNodeBundles() = 0;
353  virtual HOM_NodeBundle *nodeBundle(const char *name) = 0;
354 
355  virtual HOM_HDADefinition *hdaDefinition(
356  HOM_NodeTypeCategory &category, const char *name,
357  const char *file_path) = 0;
358 
359  // Note that getTimeWithoutAddingDependency is not wrapped by swig.
360  virtual fpreal getTimeWithoutAddingDependency() = 0;
361  virtual double time() = 0;
362  virtual void setTime(double time) = 0;
363  virtual double frame() = 0;
364  virtual int intFrame() = 0;
365  virtual void setFrame(double frame) = 0;
366  virtual double fps() = 0;
367  virtual void setFps(double fps) = 0;
368  virtual double timeToFrame(double time) = 0;
369  virtual double frameToTime(double frame) = 0;
370 
371  /// Private methods for ensuring that the current eval context
372  /// (including global time) is in-sync with the main thread's eval
373  /// context.
374  virtual void _syncFromMainContext() = 0;
375  virtual void _syncToMainContext() = 0;
376 
377  // Computes a scale factor given units
378  virtual fpreal scaleFromMKS(const char *units) = 0;
379  virtual fpreal scaleToMKS(const char *units) = 0;
380 
381  virtual double bezier() = 0;
382  virtual double constant() = 0;
383  virtual double cubic() = 0;
384  virtual double cycle(double start_frame, double end_frame) = 0;
385  virtual double cyclet(double start_time, double end_time) = 0;
386  virtual double cycleoffset(double start_frame, double end_frame) = 0;
387  virtual double cycleoffsett(double start_time, double end_time) = 0;
388  virtual double ease() = 0;
389  virtual double easein() = 0;
390  virtual double easeinp(double ease_speed) = 0;
391  virtual double easeout() = 0;
392  virtual double easeoutp(double ease_speed) = 0;
393  virtual double easep(double ease_bias) = 0;
394  virtual double linear() = 0;
395  virtual double match() = 0;
396  virtual double matchin() = 0;
397  virtual double matchout() = 0;
398  virtual double qlinear() = 0;
399  virtual double quintic() = 0;
400  virtual double repeat(double start_frame, double end_frame) = 0;
401  virtual double repeatt(double start_time, double end_time) = 0;
402  virtual double spline() = 0;
403  virtual double vmatch() = 0;
404  virtual double vmatchin() = 0;
405  virtual double vmatchout() = 0;
406 
407  virtual std::string chopExportConflictResolutionPattern() = 0;
408  virtual void setChopExportConflictResolutionPattern( const char *pattern) = 0;
409 
410  virtual std::vector<HOM_ElemPtr<HOM_VexContext> >
411  vexContexts() = 0;
412 
413  virtual HOM_VexContext* vexContextForShaderType(HOM_EnumValue &shader_type) = 0;
414 
415  virtual HOM_VexContext* vexContextForNodeTypeCategory(
416  HOM_NodeTypeCategory &node_type_category) = 0;
417 
418  virtual std::string helpServerUrl() = 0;
419 
420  virtual std::string hscriptCommandHelp(const char *command_name) = 0;
421 
422  // This method returns a pair of strings: one for stdout and one for
423  // stderr.
424  virtual std::vector<std::string> hscript(const char *command) = 0;
425 
426  // Compare if two numbers are almost equal.
427  virtual bool almostEqual(double x, double y) = 0;
428 
429  virtual std::vector<std::pair<HOM_ElemPtr<HOM_Parm>, std::string> >
430  fileReferences(
431  const char *project_dir_variable="HIP", bool include_all_refs=true) = 0;
432 
433  // Find files in $HOUDINI_PATH.
434  virtual std::string findFile(const char *file_name) = 0;
435  virtual std::vector<std::string> findFiles(
436  const char *file_name) = 0;
437  virtual std::vector<std::string> findFilesWithExtension(
438  const char *file_extension, const char *subdirectory = NULL) = 0;
439 
440  // Find directories in $HOUDINI_PATH.
441  virtual std::string findDirectory(const char *directory_name) = 0;
442  virtual std::vector<std::string> findDirectories(
443  const char *directory_name) = 0;
444 
445  virtual std::vector<std::string> houdiniPath(const char *pathvar = nullptr) = 0;
446 
447  virtual std::string homeHoudiniDirectory() = 0;
448 
449 #if defined(USE_PYTHON3)
450  virtual std::string readFile(const char *file_path) = 0;
451  virtual HOM_BinaryString readBinaryFile(const char *file_path) = 0;
452 #else
453  virtual HOM_BinaryString readFile(const char *file_path) = 0;
454 #endif
455 
456  virtual std::map<std::string, HOM_BinaryString> loadIndexDataFromString(
457  const char *data, int length) = 0;
458 
459  virtual std::map<std::string, HOM_BinaryString> loadIndexDataFromFile(
460  const char *file_path) = 0;
461 
462 #if defined(USE_PYTHON3)
463  virtual HOM_BinaryString saveIndexDataToString(
464  const std::map<std::string, HOM_BinaryString> &index_data) = 0;
465 
466  virtual void saveIndexDataToFile(
467  const char *file_path,
468  const std::map<std::string, HOM_BinaryString> &index_data) = 0;
469 #else
470  virtual HOM_BinaryString saveIndexDataToString(
471  const std::map<std::string, std::string> &index_data) = 0;
472 
473  virtual void saveIndexDataToFile(
474  const char *file_path,
475  const std::map<std::string, std::string> &index_data) = 0;
476 #endif
477 
478  // Note that, when wrapped by swig, this function takes a single string
479  // parameter.
480  virtual std::vector<std::pair<std::string, HOM_BinaryString> >
481  loadCPIODataFromString(const char *data, int length) = 0;
482 
483 #if defined(USE_PYTHON3)
484  virtual HOM_BinaryString saveCPIODataToString(
485  const std::vector<std::pair<std::string, HOM_BinaryString> >
486  &data) = 0;
487 #else
488  virtual HOM_BinaryString saveCPIODataToString(
489  const std::vector<std::pair<std::string, std::string> > &data) = 0;
490 #endif
491 
492  // These 3 methods are not wrapped by swig. They are used to notify
493  // interested parties that a change to the module source code was made and
494  // that they should forcefully update to match the change. The third
495  // is used to load the session module source from a hip file, even though
496  // that source might generate an exception.
497  virtual UT_NotifierImpl<int> &getSessionModuleSourceForceUpdateNotifier()=0;
498  virtual void forceUpdateFromSessionModuleSource() = 0;
499  virtual void forceSetSessionModuleSource(const char *source) = 0;
500 
501  virtual void setSessionModuleSource(const char *source) = 0;
502  virtual void appendSessionModuleSource(const char *source) = 0;
503  virtual std::string sessionModuleSource() = 0;
504  // This method is not wrapped by swig:
505  virtual int sessionModuleSourceChangeCount() = 0;
506 
507  // This static method lets you know if the HOM implementation is set,
508  // so you can check if it's safe to call the HOM() function. This method
509  // should only be called in rare cases.
510  static bool isImplementationSet()
511  { return theImplementation != NULL; }
512 
513  // Evaluates a parameter as if it was an OPpath parameter
514  virtual std::string chsop(const char *path) = 0;
515 
516  // Evaluates a parameter as if it was an OPlist parameter
517  virtual std::string chsoplist(const char *path) = 0;
518 
519  // Sorts a list of node paths using topological order from the graph.
520  virtual std::vector<std::string>
521  sortedNodePaths(const std::vector<std::string> &paths) = 0;
522 
523  // Sorts a list of HOM_Node using topological order from the graph.
524  virtual std::vector<HOM_ElemPtr<HOM_Node> >
525  sortedNodes(const std::vector<HOM_Node*> &nodes) = 0;
526 
527  // deprecated in favour of hou.text.patternMatch
528  virtual int patternMatch(
529  const char *pattern, const char *str,
530  bool ignore_case = false,
531  bool path_match = false) = 0;
532 
533  // hscriptExpression() will return different types, according to
534  // the return value of the expression.
535  virtual hboost::any hscriptExpression(const char *expression) = 0;
536  virtual double hscriptFloatExpression(const char *expression) = 0;
537  virtual std::string hscriptStringExpression(const char *expression) = 0;
538  virtual std::vector<double>hscriptVectorExpression(
539  const char *expression) = 0;
540  virtual std::vector<std::vector<double> > hscriptMatrixExpression(
541  const char *expression) = 0;
542 
543  virtual hboost::any lvar(const char *name) = 0;
544 
545  virtual char *getenv(const char *name, const char *default_value=NULL) = 0;
546 
547  virtual void putenv(const char *name, const char *value) = 0;
548 
549  virtual void unsetenv(const char *name) = 0;
550 
551  virtual void allowEnvironmentToOverwriteVariable(
552  const char *name, bool onoff) = 0;
553 
554  virtual void *expressionGlobals() = 0;
555 
556  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
557 
558  // This method is used to interact with the global interrupt object.
559  virtual bool updateProgressAndCheckForInterrupt(int percentage=-1) = 0;
560 
561  virtual std::map<std::string, hboost::any> runVex(
562  const char *vex_file,
563  const std::map<std::string, hboost::any> &inputs,
564  const char *precision = "32") = 0;
565 
566  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
567 
568  virtual void saveImageDataToFile(
569  const std::vector<float> &color_and_alpha_data,
570  int width, int height,
571  const char *file_name) = 0;
572 
573  virtual void saveImageDataToFile(
574  const std::string &color_and_alpha_data,
575  int width, int height,
576  const char *file_name) = 0;
577 
578  virtual HOM_BinaryString loadImageDataFromFile(
579  const char *image_file_name,
580  HOM_EnumValue &image_depth = HOM_imageDepth::Int8) = 0;
581 
582  virtual std::vector<int> imageResolution(const char *image_file_name) = 0;
583 
584  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
585 
586  virtual HOM_EnumValue &updateModeSetting() = 0;
587  virtual void setUpdateMode(HOM_EnumValue &mode) = 0;
588 
589  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
590 
591  virtual HOM_OrboltURLHandler *orboltURLHandler() = 0;
592 
593  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
594 
595  virtual void *opaqueRunCallbackAndCatchCrashes(void *opaque_callback) = 0;
596 
597  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
598 
599  // These methods are used to grant functions defined in an asset's
600  // PythonModule enhanced privileges. They are not wrapped by swig.
601  virtual void pushAccessPrivilege(const char *key) = 0;
602  virtual void popAccessPrivilege(const char *key) = 0;
603 
604  virtual std::string currentPythonModuleKey() = 0;
605 
606  virtual void registerAccessPrivilegePyClient(void *opaque_python_object) = 0;
607 
608  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
609 
610  // These methods are used to instantiate HOMF objects from the HOM
611  // library level. They are not wrapped by swig.
612  virtual HOM_FloatParmTemplate *newFloatParmTemplate(
613  const char *name,
614  const char *label,
615  int num_components,
616  const std::vector<double> &default_value,
617  double min, double max,
618  bool min_is_strict, bool max_is_strict,
619  HOM_EnumValue &look,
620  HOM_EnumValue &naming_scheme,
621  const char *disable_when,
622  bool is_hidden,
623  bool is_label_hidden,
624  bool join_with_next,
625  const char *help,
626  const char *script_callback,
627  HOM_EnumValue &script_callback_language,
628  const std::map<std::string, std::string> &tags,
629  const std::map<HOM_EnumValue *, std::string> &conditionals,
630  const std::vector<std::string> &default_expression,
631  const std::vector<HOM_EnumValue *> &default_expression_language) = 0;
632 
633  virtual HOM_IntParmTemplate *newIntParmTemplate(
634  const char *name,
635  const char *label,
636  int num_components,
637  const std::vector<int> &default_value,
638  int min, int max,
639  bool min_is_strict, bool max_is_strict,
640  HOM_EnumValue &naming_scheme,
641  const std::vector<std::string> &menu_items,
642  const std::vector<std::string> &menu_labels,
643  const std::vector<std::string> &icon_names,
644  const std::string &item_generator_script,
645  HOM_EnumValue *item_generator_script_language,
646  HOM_EnumValue &menu_type,
647  bool menu_use_token,
648  const char *disable_when,
649  bool is_hidden,
650  bool is_label_hidden,
651  bool join_with_next,
652  const char *help,
653  const char *script_callback,
654  HOM_EnumValue &script_callback_language,
655  const std::map<std::string, std::string> &tags,
656  const std::map<HOM_EnumValue *, std::string> &conditionals,
657  const std::vector<std::string> &default_expression,
658  const std::vector<HOM_EnumValue *> &default_expression_language) = 0;
659 
660  virtual HOM_StringParmTemplate *newStringParmTemplate(
661  const char *name,
662  const char *label,
663  int num_components,
664  const std::vector<std::string> &default_value,
665  HOM_EnumValue &naming_scheme,
666  HOM_EnumValue &string_type,
667  HOM_EnumValue &file_type,
668  const std::vector<std::string> &menu_items,
669  const std::vector<std::string> &menu_labels,
670  const std::vector<std::string> &icon_names,
671  const std::string &item_generator_script,
672  HOM_EnumValue *item_generator_script_language,
673  HOM_EnumValue &menu_type,
674  const char *disable_when,
675  bool is_hidden,
676  bool is_label_hidden,
677  bool join_with_next,
678  const char *help,
679  const char *script_callback,
680  HOM_EnumValue &script_callback_language,
681  const std::map<std::string, std::string> &tags,
682  const std::map<HOM_EnumValue *, std::string> &conditionals,
683  const std::vector<std::string> &default_expression,
684  const std::vector<HOM_EnumValue *> &default_expression_language) = 0;
685 
686  virtual HOM_DataParmTemplate *newDataParmTemplate(
687  const char *name,
688  const char *label,
689  int num_components,
690  HOM_EnumValue &look,
691  HOM_EnumValue &naming_scheme,
692  HOM_EnumValue &data_parm_type,
693  const char *disable_when,
694  bool is_hidden,
695  bool is_label_hidden,
696  bool join_with_next,
697  const char *help,
698  const char *script_callback,
699  HOM_EnumValue &script_callback_language,
700  const std::map<std::string, std::string> &tags,
701  const std::map<HOM_EnumValue *, std::string> &conditionals,
702  const std::vector<std::string> &default_expression,
703  const std::vector<HOM_EnumValue *> &default_expression_language) = 0;
704 
705  virtual HOM_ToggleParmTemplate *newToggleParmTemplate(
706  const char *name,
707  const char *label,
708  bool default_value,
709  const char *disable_when,
710  bool is_hidden,
711  bool is_label_hidden,
712  bool join_with_next,
713  const char *help,
714  const char *script_callback,
715  HOM_EnumValue &script_callback_language,
716  const std::map<std::string, std::string> &tags,
717  const std::map<HOM_EnumValue *, std::string> &conditionals,
718  const std::string &default_expression,
719  const HOM_EnumValue &default_expression_language) = 0;
720 
721  virtual HOM_MenuParmTemplate *newMenuParmTemplate(
722  const char *name,
723  const char *label,
724  const std::vector<std::string> &menu_items,
725  const std::vector<std::string> &menu_labels,
726  int default_value,
727  const std::vector<std::string> &icon_names,
728  const std::string &item_generator_script,
729  HOM_EnumValue *item_generator_script_language,
730  HOM_EnumValue &menu_type,
731  bool menu_use_token,
732  const char *disable_when,
733  bool is_hidden,
734  bool is_label_hidden,
735  bool join_with_next,
736  const char *help,
737  const char *script_callback,
738  HOM_EnumValue &script_callback_language,
739  const std::map<std::string, std::string> &tags,
740  const std::map<HOM_EnumValue *, std::string> &conditionals,
741  const std::string &default_expression,
742  const HOM_EnumValue &default_expression_language,
743  bool store_default_value_as_string,
744  bool is_button_strip,
745  bool strip_uses_icons
746  ) = 0;
747 
748  virtual HOM_ButtonParmTemplate *newButtonParmTemplate(
749  const char *name,
750  const char *label,
751  const char *disable_when,
752  bool is_hidden,
753  bool is_label_hidden,
754  bool join_with_next,
755  const char *help,
756  const char *script_callback,
757  HOM_EnumValue &script_callback_language,
758  const std::map<std::string, std::string> &tags,
759  const std::map<HOM_EnumValue *, std::string> &conditionals ) = 0;
760 
761  virtual HOM_LabelParmTemplate *newLabelParmTemplate(
762  const char *name,
763  const char *label,
764  const std::vector<std::string> &column_labels,
765  bool is_hidden,
766  bool is_label_hidden,
767  bool join_with_next,
768  const char *help,
769  const std::map<std::string, std::string> &tags,
770  const std::map<HOM_EnumValue *, std::string> &conditionals) = 0;
771 
772  virtual HOM_SeparatorParmTemplate *newSeparatorParmTemplate(
773  const char *name,
774  bool is_hidden,
775  const std::map<std::string, std::string> &tags,
776  const std::map<HOM_EnumValue *, std::string> &conditionals) = 0;
777 
778  virtual HOM_FolderSetParmTemplate *newFolderSetParmTemplate(
779  const char *name,
780  const std::vector<std::string> &folder_names,
781  HOM_EnumValue &folder_type,
782  const std::map<std::string, std::string> &tags) = 0;
783 
784  virtual HOM_FolderParmTemplate *newFolderParmTemplate(
785  const char *name,
786  const char *label,
787  const std::vector<HOM_ParmTemplate *> &parm_templates,
788  HOM_EnumValue &folder_type,
789  int default_value,
790  bool is_hidden,
791  bool ends_tab_group,
792  const char *script_callback,
793  HOM_EnumValue &script_callback_language,
794  const std::map<std::string, std::string> &tags,
795  const std::map<HOM_EnumValue *, std::string> &conditionals,
796  const std::map<HOM_EnumValue *, std::string> &tab_conditionals) = 0;
797 
798  virtual HOM_RampParmTemplate *newRampParmTemplate(
799  const char *name,
800  const char *label,
801  HOM_EnumValue &ramp_parm_type,
802  int default_value,
803  HOM_EnumValue *default_basis,
804  bool show_controls,
805  HOM_EnumValue *color_type,
806  const char *disable_when,
807  bool is_hidden,
808  const char *help,
809  const char *script_callback,
810  HOM_EnumValue &script_callback_language,
811  const std::map<std::string, std::string> &tags,
812  const std::map<HOM_EnumValue *, std::string> &conditionals,
813  const std::string &default_expression,
814  const HOM_EnumValue &default_expression_language) = 0;
815 
816  virtual HOM_ParmTemplateGroup *newParmTemplateGroup(
817  const std::vector<HOM_ParmTemplate *> &parm_templates) = 0;
818 
819  virtual HOM_PerfMonRecordOptions *newPerfMonRecordOptions(
820  bool cook_stats, bool pdg_cook_stats, bool solve_stats,
821  bool draw_stats, bool gpu_draw_stats, bool viewport_stats,
822  bool script_stats, bool render_stats, bool thread_stats,
823  bool frame_stats, bool memory_stats, bool errors,
824  bool pane_stats) = 0;
825 
826  virtual HOM_Keyframe *newKeyframe() = 0;
827  virtual HOM_Keyframe *newKeyframe(double value) = 0;
828  virtual HOM_Keyframe *newKeyframe(double value, double time) = 0;
829  virtual HOM_Keyframe *newKeyframe(const HOM_Keyframe &keyframe) = 0;
830 
831  virtual HOM_StringKeyframe *newStringKeyframe() = 0;
832  virtual HOM_StringKeyframe *newStringKeyframe(
833  const std::string &value, HOM_EnumValue &language) = 0;
834  virtual HOM_StringKeyframe *newStringKeyframe(
835  const std::string &value, double time, HOM_EnumValue &language) = 0;
836  virtual HOM_StringKeyframe *newStringKeyframe(
837  const HOM_StringKeyframe &string_keyframe) = 0;
838 
839  virtual HOM_HDAOptions *newHDAOptions() = 0;
840  virtual HOM_LopViewportLoadMasks *newLopViewportLoadMasks() = 0;
841  virtual HOM_LopInstanceIdRule *newLopInstanceIdRule() = 0;
842  virtual HOM_LopSelectionRule *newLopSelectionRule(
843  const char *pattern = nullptr) = 0;
844 
845  virtual HOM_InterruptableOperation *newInterruptableOperation(
846  const char *operation_name, const char *long_operation_name,
847  bool open_interrupt_dialog) = 0;
848 
849  virtual HOM_RedrawBlock *newRedrawBlock() = 0;
850 #ifndef SWIG
851  virtual HOM_RedrawResumeBlock *newRedrawResumeBlock() = 0;
852 #endif
853 
854  virtual HOM_StyleSheet *newStyleSheet() = 0;
855  virtual HOM_StyleSheet *newStyleSheet(const char *json_text) = 0;
856 
857  virtual HOM_Selection *newSelection(HOM_EnumValue &selection_type,
858  HOM_Geometry *geo, const char *selection_string) = 0;
859  virtual HOM_Selection *newSelection(
860  const std::vector<HOM_EnumValue *> &selection_types,
861  HOM_Geometry *geo, const char *selection_string) = 0;
862  virtual HOM_Selection *newSelection(
863  const std::vector<HOM_Prim *> &prims) = 0;
864  virtual HOM_Selection *newSelection(
865  const std::vector<HOM_Point *> &points) = 0;
866  virtual HOM_Selection *newSelection(
867  const std::vector<HOM_Vertex *> &vertices) = 0;
868  virtual HOM_Selection *newSelection(
869  const std::vector<HOM_Edge *> &edges) = 0;
870 
871  // This method returns a new HOM_Geometry object.
872  virtual HOM_Geometry *newGeometry(HOM_Geometry *geo = nullptr,
873  bool clone_data_ids = false) = 0;
874 
875  virtual HOM_GeometryRayCache *newGeometryRayCache() = 0;
876 
877  virtual HOM_DopSimulation *newDopSimulation() = 0;
878 
879  virtual HOM_Clip *newClip() = 0;
880 
881  virtual HOM_AgentDefinition *newAgentDefinition(
882  const HOM_AgentRig *rig, const HOM_AgentShapeLibrary *shapelib) = 0;
883 
884  virtual HOM_AgentClip *newAgentClip(
885  const char *name, const char *path, const HOM_AgentRig &rig,
886  bool keep_external_ref, bool delay_load) = 0;
887 
888  virtual HOM_AgentClip *newAgentClip(
889  const char *name, HOM_ChopNode &chop, const HOM_AgentRig &rig,
890  double frame) = 0;
891 
892  virtual HOM_AgentClip *newAgentClip(
893  const char *name, const HOM_AgentRig &rig, int sample_count) = 0;
894 
895  virtual HOM_AgentClip *newAgentClip(
896  const HOM_AgentClip &clip, const HOM_AgentRig &rig,
897  const char *name) = 0;
898 
899  virtual HOM_AgentRig *newAgentRig(const char *path, bool keep_external_ref) = 0;
900 
901  virtual HOM_AgentRig *newAgentRig(
902  const char *name, const std::vector<std::string> &transform_names,
903  const std::vector<std::vector<int>> &hierarchy) = 0;
904 
905  virtual HOM_AgentTransformGroup *newAgentTransformGroup(
906  const char *path, const HOM_AgentRig &rig,
907  bool keep_external_ref = true) = 0;
908 
909  virtual HOM_AgentTransformGroup *newAgentTransformGroup(
910  const char *name, const std::vector<int> &transforms,
911  const HOM_AgentRig &rig, const std::vector<double> &weights,
912  const std::vector<int> &channels) = 0;
913 
914  virtual HOM_AgentShapeLibrary *newAgentShapeLibrary() = 0;
915  virtual HOM_AgentShapeLibrary *newAgentShapeLibrary(
916  HOM_Geometry &geometry, const char *name) = 0;
917  virtual HOM_AgentShapeLibrary *newAgentShapeLibrary(
918  const char *path, bool keep_external_ref) = 0;
919 
920  virtual HOM_AgentShapeBinding *
921  newAgentShapeBinding(int transform, const HOM_AgentShape &shape,
922  bool deforming, double bounds_scale) = 0;
923 
924  virtual HOM_AgentShapeBinding *
925  newAgentShapeBinding(int transform, const HOM_AgentShape &shape,
926  const HOM_AgentShapeDeformer *deformer,
927  const HOM_Vector3 &bounds_scale) = 0;
928 
929  virtual HOM_AgentShapeDeformer *
930  newAgentShapeDeformer(const char *name) = 0;
931 
932  virtual HOM_AgentShapeDeformer *
933  newAgentShapeDeformer(const HOM_EnumValue &deformer_type) = 0;
934 
935  virtual HOM_AgentLayer *newAgentLayer(
936  const char *name, const HOM_AgentRig &rig,
937  const HOM_AgentShapeLibrary &shapelib,
938  const std::vector<HOM_AgentShapeBinding *> &shape_bindings,
939  const HOM_AgentLayer *source_layer = 0) = 0;
940 
941  virtual HOM_AgentLayer *
942  newAgentLayer(const char *path, const HOM_AgentRig &rig,
943  const HOM_AgentShapeLibrary &shapelib,
944  bool keep_external_ref = true) = 0;
945 
946  virtual HOM_AgentMetadata *newAgentMetadata(
947  const char *path,
948  bool keep_external_ref = true) = 0;
949  virtual HOM_AgentMetadata *newAgentMetadata(
950  const std::map<std::string, hboost::any> &data) = 0;
951 
952  virtual bool compareNode(const char *path, const char *dest = NULL) = 0;
953  virtual bool compareNodeBackup(const char *path, int index,
954  const char *dest = NULL) = 0;
955  virtual bool compareHDA(const char *path_left, const char *path_right,
956  const char *dest = NULL) = 0;
957  virtual bool compareHDABackup(const char *path, int index,
958  const char *dest = NULL) = 0;
959  virtual bool compareHip(const char *dest = NULL) = 0;
960  virtual bool compareHipBackup(int index, const char *dest = NULL) = 0;
961 
962  virtual bool hasContextOption(const char *opt) = 0;
963  virtual UT_OptionEntryPtr contextOption(const char *opt) = 0;
964  virtual std::vector<std::string> contextOptionNames() = 0;
965  virtual void setContextOption(const char *opt, const char *value) =0;
966  virtual void setContextOption(const char *opt, double value) = 0;
967  virtual void removeContextOption(const char *opt) = 0;
968  virtual std::string contextOptionConfig(const char *opt) = 0;
969  virtual void setContextOptionConfig(const char *opt,
970  const char *config) = 0;
971 
972  SWIGOUT(%ignore addOpaqueContextOptionChangeCallback;)
973  virtual void addOpaqueContextOptionChangeCallback(void *callback) = 0;
974  SWIGOUT(%ignore removeOpaqueContextOptionChangeCallback;)
975  virtual void removeOpaqueContextOptionChangeCallback(void *callback) = 0;
976  virtual void removeAllContextOptionChangeCallbacks() = 0;
977 
978  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
979 
980  // This method is called when orbolt_url runs. It is not wrapped by swig.
981  virtual void setOrboltURLHandler(
982  STORUI_OrboltURLHandler &orbolt_url_handler) = 0;
983 
984  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
985 
986  // These methods are used to help debug HOM to make sure no objects
987  // get allocated that don't get deallocated.
988  virtual void constructObject(void *pointer, const std::type_info &type) = 0;
989  virtual void destructObject(void *pointer, const std::type_info &type) = 0;
990  virtual std::map<std::string, int> objectCounts() = 0;
991 
992  // Preferences
993  virtual std::vector<std::string> getPreferenceNames() = 0;
994  virtual std::string getPreference(const char *name) = 0;
995  virtual bool setPreference(const char *name, const char* value) = 0;
996  virtual bool addPreference(const char *name, const char* value) = 0;
997  virtual bool removePreference(const char *name) = 0;
998 
999  virtual HOM_ViewerStateTemplate * newViewerStateTemplate(
1000  std::string const & type_name,
1001  std::string const & label,
1002  HOM_NodeTypeCategory const & category,
1003  std::vector<HOM_NodeTypeCategory*> const & contexts) = 0;
1004 
1005  virtual HOM_ViewerHandleTemplate * newViewerHandleTemplate(
1006  std::string const & type_name,
1007  std::string const & label,
1008  std::vector<HOM_NodeTypeCategory*> const & categories) = 0;
1009 
1010  virtual HOM_ViewerStateMenu * newViewerStateMenu(std::string const & handle, std::string const & label) = 0;
1011 
1012  virtual HOM_SimpleDrawable * newSimpleDrawable( HOM_SceneViewer& scene_viewer, HOM_EnumValue const &prim_type, std::string const &name) = 0;
1013  virtual HOM_SimpleDrawable * newSimpleDrawable( HOM_SceneViewer& scene_viewer, HOM_Geometry const &geometry, std::string const &name) = 0;
1014 
1015  virtual HOM_ViewerHandleDragger * newViewerHandleDragger(std::string const & name) = 0;
1016  virtual HOM_ViewerStateDragger * newViewerStateDragger(std::string const & name, HOM_Matrix4 const & xform, HOM_Matrix4 const & inv_xform) = 0;
1017 
1018  virtual HOM_UIEvent * newUIEvent( int64 val ) = 0;
1019  virtual HOM_ViewerEvent * newViewerEvent( HOM_SceneViewer& sceneViewer, int64 val ) = 0;
1020  virtual HOM_UIEventDevice * newUIEventDevice(int64 val, int64 val2) = 0;
1021 
1022  virtual HOM_Handle * newHandle(HOM_SceneViewer& scene_viewer, std::string const &name ) = 0;
1023  virtual HOM_ViewerHandleContext * newViewerHandleContext(int64 val) = 0;
1024 
1025  virtual HOM_ViewerStateContext * newViewerStateContext(int64 val) = 0;
1026 
1027  virtual HOM_TextDrawable * newTextDrawable(
1028  HOM_SceneViewer& scene_viewer,
1029  std::string const & name,
1030  std::map<std::string, hboost::any> const & params,
1031  std::string const & label) = 0;
1032 
1033  virtual HOM_GeometryDrawable * newGeometryDrawable(
1034  HOM_SceneViewer& scene_viewer,
1035  HOM_EnumValue const & geo_type,
1036  std::string const & name,
1037  HOM_Geometry * geometry,
1038  std::map<std::string, hboost::any> const & params,
1039  std::string const & label) = 0;
1040 
1041  virtual HOM_GeometryDrawableGroup* newGeometryDrawableGroup(std::string const & name, std::string const & label) = 0;
1042 
1043  virtual HOM_GadgetDrawable * newGadgetDrawable(int64 widget, int64 gadget_context) = 0;
1044 
1045  virtual void startHoudiniEngineDebugger(unsigned short port) = 0;
1046  virtual void startHoudiniEngineDebugger(const char *pipe_name) = 0;
1047 
1048  virtual HOM_GeometrySelection * newGeometrySelection() = 0;
1049  virtual HOM_GeometrySelection * newGeometrySelection(int64 val) = 0;
1050 
1051  virtual HOM_logging_MemorySink * newMemorySink() = 0;
1052  virtual HOM_logging_FileSink * newFileSink(const char *filepath) = 0;
1053 
1054  virtual HOM_BinaryString convertClipData(HOM_BinaryString data,
1055  bool from_binary,
1056  bool from_blosc_compression,
1057  bool to_binary,
1058  bool to_blosc_compression) = 0;
1059 
1060  virtual HOM_BinaryString convertKeyframesToClipData(
1061  const std::map<std::string, std::vector<HOM_Keyframe *>> &keyframe_map,
1062  bool binary = true, bool use_blosc_compression = true) = 0;
1063 
1064  virtual std::string _clipInfo(HOM_BinaryString data, bool binary = true,
1065  bool blosc_compressed = true) = 0;
1066 
1067  virtual std::vector<HOM_ElemPtr<HOM_Node> > _nodesFromOPNodeList(int64 val) = 0;
1068  virtual std::vector<HOM_ElemPtr<HOM_DopData> >
1069  _dopDataList(int64 val) = 0;
1070  virtual std::vector<std::pair<HOM_ElemPtr<HOM_DopData>, HOM_ElemPtr<HOM_GeometrySelection> > >
1071  _dopDataPointList(int64 val) = 0;
1072  virtual std::vector<std::pair<HOM_ElemPtr<HOM_DopData>, HOM_ElemPtr<HOM_GeometrySelection> > >
1073  _dopDataPolyList(int64 val) = 0;
1074 
1075  virtual HOM_AttribDataId * newAttribDataId() = 0;
1076 
1077  virtual std::string userName(bool alpha=true) = 0;
1078 
1079  virtual std::string machineName(bool alpha=true) = 0;
1080 
1081  virtual HOM_GeometryDrawable * _newGeometryDrawable(int64 val) = 0;
1082 
1083  virtual HOM_Node * createAnimationLayers(const std::string &path) = 0;
1084  virtual HOM_Node * addAnimationLayer(HOM_Node &layermixer, const std::string &layername) = 0;
1085  virtual bool removeAnimationLayer(HOM_Node &layermixer, const std::string &layername, bool merge=false) = 0;
1086  virtual HOM_Node* createAnimationClip(const std::string &path, bool set_export) = 0;
1087 
1088  virtual void* _sceneViewerWindow(int64 val) = 0;
1089 private:
1090  // HOMF_Module::createHOMModule() uses this to create the HOM_Module.
1091  static void (*theHOMCreator)();
1092 
1093  // A subclass of HOM_Module in the HOMF library will define the
1094  // implementation of HOM. Importing the python module will set the
1095  // implementation, so this function should only be called by HOMF_Module::
1096  // createHOMModule().
1097  friend class HOMF_Module;
1098  static void setImplementation(HOM_Module* implementation);
1099 
1100  // We could add a static method to access the implementation, but we
1101  // want to make it easy to access the HOM module from C++. So, the
1102  // global function HOM() needs access to the implementation.
1103  friend HOM_API HOM_Module& HOM();
1104  static HOM_Module *theImplementation;
1105 };
1106 
1107 
1108 // Use this function to automatically delete objects for functions that
1109 // return new objects. This lets you, for example, write code like
1110 // HOMdel(HOM().findNode("/obj/geo1"))->setName("geo2")
1111 template <typename T>
1113 { return UT_UniquePtr<T>(hom_object); }
1114 
1115 
1116 // This lock is used to synchronize HOM scripts running in a separate
1117 // thread and Houdini. Houdini's UI queue will give up the lock when it's
1118 // waiting for events and reacquire it when it handles an event.
1119 //
1120 // Note that this lock allows multiple threads in the same thread group to hold
1121 // it at the same time. By default, a thread started from Houdini is added to
1122 // the group containing the main thread. This way, since Houdini started the
1123 // thread, we can be confident that it will use other locks to synchronize
1124 // access to Houdini. This approach allows, for example, a volume SOP to
1125 // cook using multiple threads, evaluating Python in each thread while the
1126 // main thread holds the HOM lock, without deadlocking and without allowing
1127 // non-Houdini threads to acquire the HOM lock. (Note that the GIL will
1128 // synchronize access to Python's internals.)
1131 {
1132  // This is not thread-safe but should be ok because HOMgetLock() is called
1133  // pretty early on during startup when there is only one thread executing.
1134  if (!HOM_theHOMLock)
1135  HOM_theHOMLock = new UT_TaskRootLock();
1136 
1137  UT_ASSERT(HOM_theHOMLock);
1138  return *HOM_theHOMLock;
1139 }
1140 
1141 // The HOM implementation uses the HOM_AutoLock to make sure Houdini isn't busy
1142 // when they make calls into the Houdini libraries. Note that constructing
1143 // a HOM_AutoLock will release the python global interpreter lock (GIL) if
1144 // it was held before acquiring the HOM lock. This way, other python threads
1145 // can run if it needs to block waiting for the HOM lock.
1147 {
1148 public:
1150  {
1151  if (!HOMgetLock().hasLock())
1152  {
1153  HOMgetLock().lock();
1154  myLocked = true;
1155  }
1156  else
1157  myLocked = false;
1158  }
1159 
1161  {
1162  if (myLocked)
1163  HOMgetLock().unlock();
1164  }
1165 
1166 private:
1167 
1168  // It is important that we release the python global interpreter lock
1169  // (GIL) for the duration of waiting for, acquiring and holding onto
1170  // the HOM lock. This gives other threads that are either blocked
1171  // on the GIL or that will try to acquire the GIL a chance to continue
1172  // execution.
1173  //
1174  // If the current thread needs to access the Python API,
1175  // then it should explicitly acquire the GIL by creating a
1176  // PY_InterpreterAutoLock object. The PY_InterpreterAutoLock must be
1177  // constructed *after* the HOM_AutoLock or it will have no effect.
1178  //
1179  // This prevents deadlocks that occur when the current thread
1180  // spawns other threads which access the Python API and try to
1181  // acquire the GIL.
1182  //
1183  // Note that we will reacquire the GIL when the HOM auto lock is destructed.
1184  PY_InterpreterAutoUnlock myPyInterpAutoUnlock;
1185 
1186  // Boolean to determine if the auto lock actually locked the HOM lock.
1187  bool myLocked;
1188 };
1189 
1190 // The HOM implementation uses HOM_AutoUnlock to allow the main thread to
1191 // run while waiting for something to happen. Constructing a HOM_AutoUnlock
1192 // instance will release the HOM lock but not the Python GIL. When it's
1193 // destructed it will reacquire the HOM lock. Since it releases the HOM lock,
1194 // it's important that a HOM_AutoLock was already created in a containing
1195 // scope.
1196 //
1197 // Use HOM_AutoUnlock in conjunction with PY_InterpreterAutoUnlock to
1198 // also release the Python GIL. Be sure to create the HOM_AutoUnlock *after*
1199 // the PY_InterpreterAutoUnlock, so that when the auto locks are destructed
1200 // the HOM lock is reacquired before the Python GIL. Otherwise, it will grab
1201 // the GIL and then try to grab the HOM lock, and if another thread with the
1202 // HOM lock tries to run Python we'll end up with deadlock.
1204 {
1205 public:
1207  {
1208  if (HOMgetLock().hasLock())
1209  {
1210  HOMgetLock().unlock();
1211  myUnlocked = true;
1212  }
1213  else
1214  {
1215  myUnlocked = false;
1216  }
1217  }
1218 
1220  {
1221  if (myUnlocked)
1222  HOMgetLock().lock();
1223  }
1224 
1225 private:
1226  bool myUnlocked;
1227 };
1228 
1229 
1230 // These macros are used to help detect memory leaks when debugging is enabled.
1231 #ifdef HOM_DEBUG
1232 #define HOM_CONSTRUCT_OBJECT(pointer) \
1233  HOM().constructObject(pointer, typeid(*pointer));
1234 #define HOM_DESTRUCT_OBJECT(pointer) \
1235  HOM().destructObject(pointer, typeid(*pointer));
1236 #else
1237 #define HOM_CONSTRUCT_OBJECT(pointer)
1238 #define HOM_DESTRUCT_OBJECT(pointer)
1239 #endif
1240 
1241 // NOTE: These typedefs cannot actually be used in any method declaration
1242 // that SWIG needs to generate code for because it doesn't understand
1243 // them.
1244 // gcc gets a parse error if we try to give a default map value in the
1245 // signature, and the typedef avoids the error.
1246 typedef std::map<std::string, std::string> HOM_StdMapStringString;
1247 typedef std::map<HOM_EnumValue *, std::string> HOM_StdMapEnumString;
1248 
1249 
1250 // Houdini will call HOMextendLibrary() in HDK dso's so the user can install
1251 // C++ HOM extensions.
1252 extern "C" {
1254 }
1255 
1256 #endif //__HOM_Module_h__
OIIO_API string_view getenv(string_view name)
GLsizei GLenum * categories
Definition: glew.h:2586
#define SYS_VISIBILITY_EXPORT
void
Definition: png.h:1083
UT_TaskRootLock & HOMgetLock()
Definition: HOM_Module.h:1130
GT_API const UT_StringHolder time
GLuint color
Definition: glcorearb.h:1260
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
#define SWIGOUT(x)
Definition: HOM_Defines.h:24
UT_UniquePtr< T > HOMdel(T *hom_object)
Definition: HOM_Module.h:1112
Definition: HOM_ik.h:21
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glcorearb.h:2538
GLuint const GLchar * name
Definition: glcorearb.h:785
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
GLint GLenum GLint x
Definition: glcorearb.h:408
Definition: HOM_qt.h:20
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
GLuint GLenum GLenum transform
Definition: glew.h:15055
UT_TaskLockT< false > UT_TaskRootLock
Definition: UT_TaskLock.h:287
HOM_API UT_TaskRootLock * HOM_theHOMLock
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool any(const vbool4 &v)
Definition: simd.h:3446
#define HOM_API
Definition: HOM_API.h:13
virtual ~HOM_Module()
Definition: HOM_Module.h:173
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
Definition: HOM_ui.h:44
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
long long int64
Definition: SYS_Types.h:116
GLint GLsizei width
Definition: glcorearb.h:102
GLint GLsizei GLsizei height
Definition: glcorearb.h:102
GLenum mode
Definition: glcorearb.h:98
GLuint GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glew.h:3460
GLenum GLint GLint * precision
Definition: glcorearb.h:1924
GLubyte * pattern
Definition: glew.h:5741
std::map< HOM_EnumValue *, std::string > HOM_StdMapEnumString
Definition: HOM_Module.h:1247
GLboolean * data
Definition: glcorearb.h:130
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794
GLuint GLfloat * val
Definition: glcorearb.h:1607
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
SYS_VISIBILITY_EXPORT void HOMextendLibrary()
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER T clip(const T &p, const Box< T > &box)
Definition: ImathBoxAlgo.h:89
std::string OIIO_API repeat(string_view str, int n)
Repeat a string formed by concatenating str n times.
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint index
Definition: glcorearb.h:785
GLbyte * weights
Definition: glew.h:7581
GLsizei const GLfloat * value
Definition: glcorearb.h:823
virtual bool readFile(GA_Detail &g, const char *filename, const GA_LoadOptions *opts, UT_StringArray *errors) const
Class which defines an I/O interface to save/load geometry.
GLenum const GLfloat * params
Definition: glcorearb.h:104
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:171
SYS_VISIBILITY_EXPORT void newHandle(BM_ResourceManager *m)
GLenum condition
Definition: glew.h:13027
void unlock()
Definition: UT_TaskLock.h:259
GLfloat units
Definition: glcorearb.h:407
Quat< T > spline(const Quat< T > &q0, const Quat< T > &q1, const Quat< T > &q2, const Quat< T > &q3, T t)
Definition: ImathQuat.h:545
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:111
HOM_API HOM_Module & HOM()
GLenum void ** pointer
Definition: glcorearb.h:809
GLint y
Definition: glcorearb.h:102
static bool isImplementationSet()
Definition: HOM_Module.h:510
std::map< std::string, std::string > HOM_StdMapStringString
Definition: HOM_Module.h:1246
UT_UniquePtr< UT_OptionEntry > UT_OptionEntryPtr
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)
GLenum const void * paths
Definition: glew.h:13872