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