Package mrv :: Package maya :: Package nt :: Module util
[hide private]
[frames] | no frames]

Source Code for Module mrv.maya.nt.util

 1  # -*- coding: utf-8 -*- 
 2  """General utility methods""" 
 3  __docformat__ = "restructuredtext" 
 4   
 5  import maya.OpenMaya as api 
 6  import mrv.maya.undo as undo 
 7   
 8  MScriptUtil = api.MScriptUtil 
 9  #{ Decorators 
10   
11  #} END decorators 
12   
13   
14  #{ Conversion Methods 
15 -def in_double3_out_vector(function):
16 """ 17 :return: MVector containing result of function with signature 18 function(double [3])""" 19 su = MScriptUtil() 20 su.createFromDouble(0.0, 0.0, 0.0) 21 ptr = su.asDoublePtr() 22 function(ptr) 23 24 return api.MVector(su.getDoubleArrayItem(ptr,0), su.getDoubleArrayItem(ptr,1), su.getDoubleArrayItem(ptr,2))
25
26 -def in_two_floats_out_tuple(function):
27 """ 28 :return: tuple containing result of function with signature 29 function(float& f1, float& f2)""" 30 suf1 = MScriptUtil() # keep it, otherwise it might deinitialize its memory 31 suf2 = MScriptUtil() 32 pf1 = suf1.asFloatPtr() 33 pf2 = suf2.asFloatPtr() 34 35 function(pf1, pf2) 36 37 return (MScriptUtil.getFloat(pf1), MScriptUtil.getFloat(pf2))
38
39 -def in_double3_as_vector(function, vec_value):
40 """Set the value in vec_value to passed in function as double [3] and 41 return the result""" 42 su = MScriptUtil() 43 su.createFromList([vec_value.x, vec_value.y, vec_value.z], 3) 44 ptr = su.asDoublePtr() 45 return function(ptr)
46 47
48 -def undoable_in_double3_as_vector(function, vec_old_value, vec_new_value):
49 """function supports the signature function(double [3] const) and will 50 change the underlying instance to the respective values as retrieved 51 from the passed in vector. 52 The calling method must be enclosed in an undoable decorator. 53 54 :param vec_old_value: vector with the old value of the corresponding getX method 55 :param vec_new_value: vector with new value that is to be set""" 56 op = undo.GenericOperation() 57 op.setDoitCmd( in_double3_as_vector, function, vec_new_value) 58 op.setUndoitCmd( in_double3_as_vector, function, vec_old_value ) 59 return op.doIt()
60 61 62 #}END conversion methods 63