a
    «ˆcŠ  ã                   @   s8   d Z ddlZddlZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )zLMiscellaneous functions and classes that don't fit into specific
categories.é    Nc                    sR   ddl m} d|j|j|j|j|j|jg}ˆ |vrBtdˆ |f ƒ‚‡ fdd„}|S )aW  set_call_data_type(type) -- convenience decorator to easily set the CallDataType attribute
    for python function used as observer callback.
    For example:

    import vtkmodules.util.calldata_type
    import vtkmodules.util.vtkConstants
    import vtkmodules.vtkCommonCore import vtkCommand, vtkLookupTable

    @calldata_type(vtkConstants.VTK_STRING)
    def onError(caller, event, calldata):
        print("caller: %s - event: %s - msg: %s" % (caller.GetClassName(), event, calldata))

    lt = vtkLookupTable()
    lt.AddObserver(vtkCommand.ErrorEvent, onError)
    lt.SetTableRange(2,1)
    r   )ÚvtkCommonCoreZstring0zC'%s' is not a supported VTK call data type. Supported types are: %sc                    s
   ˆ | _ | S )N)ZCallDataType)Úf©Útype© úW/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/vtkmodules/util/misc.pyÚwrap   s    zcalldata_type.<locals>.wrap)	Z
vtkmodulesr   Z
VTK_STRINGZ
VTK_OBJECTZVTK_INTZVTK_LONGZ
VTK_DOUBLEZ	VTK_FLOATÚ	TypeError)r   r   Zsupported_call_data_typesr   r   r   r   Úcalldata_type   s    þr
   c                  C   sZ   d} t tjƒD ]0\}}|dkr|d ttjƒk rtj|d  } q| du rVtj dd¡} | S )z5vtkGetDataRoot() -- return vtk example data directoryNz-Dé   ZVTK_DATA_ROOTz../../../../VTKData)Ú	enumerateÚsysÚargvÚlenÚosÚenvironÚget)ZdataRootÚir   r   r   r   ÚvtkGetDataRoot(   s    r   c                  C   sP   d} t tjƒD ]0\}}|dkr|d ttjƒk rtj|d  } q| du rLd} | S )z.vtkGetTempDir() -- return vtk testing temp dirNz-Tr   Ú.)r   r   r   r   )ZtempDirr   r   r   r   r   ÚvtkGetTempDir4   s    r   c                 C   s*  ddl m} ddlm} ddlm} d}ttjƒD ]<\}}|dkr2|d t	tjƒk r2t
j tƒ tj|d  ¡}q2|du r|dS |ƒ }| | ¡ t
j |¡sÂtƒ }| |¡ | | ¡ ¡ | ¡  d}|ƒ }	|	 |¡ |ƒ }
|
 | ¡ ¡ |
 |	 ¡ ¡ |
 ¡  |
 ¡ d	k�rdS tj d
|
 ¡  ¡ dS dS )zÇvtkRegressionTestImage(renWin) -- produce regression image for window

    This function writes out a regression .png file for a vtkWindow.
    Does anyone involved in testing care to elaborate?
    r   )ÚvtkWindowToImageFilter)ÚvtkPNGReader)ÚvtkImageDifferenceNz-Vr   é   é
   zFailed image test: %f
)Zvtkmodules.vtkRenderingCorer   Zvtkmodules.vtkIOImager   Zvtkmodules.vtkImagingCorer   r   r   r   r   r   ÚpathÚjoinr   ZSetInputÚisfileZvtkPNGWriterZSetFileNameZSetInputConnectionZGetOutputPortZWriteZSetImageConnectionZUpdateZGetThresholdedErrorÚstderrÚwrite)ZrenWinr   r   r   Úfnamer   r   Zrt_w2ifZrt_pngwZrt_pngZrt_idr   r   r   ÚvtkRegressionTestImage@   s:    


ÿr"   )Ú__doc__r   r   r
   r   r   r"   r   r   r   r   Ú<module>   s
   "