3
1ßL]¼M  ã            Ö   @   sö  d Z yddlZejjZW n ek
r,   Y nX dZyddlZejjZW n ek
rZ   Y nX edkrÞyddlZdZW nh ek
rÜ   yddlZdZW nB ek
rÖ   yddl	Z	dZW n ek
rÐ   edƒ‚Y nX Y nX Y nX edk�r`edkrüdd	l
mZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ �nedk�râedk�r€dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ n’edk�rdedk�rdd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ nedeeƒ ƒ‚edk�r„eZnedk�r”eZnede ƒ‚G dd„ deƒZdd„ Zej dej!dej"dej#dej$dej%dej&dej'dej(dej)dej*d ej+d!ej,d"ej-d#ej.d$ej/d%ej0d&ej1d'ej2d(ej3d)ej4d*ej5d+ej6d,ej7d-ej8d.ej9d/ej:d0ej;d1ej<d2ej=d3ej>d4ej?d5ej@d6ejAd7ejBd8ejCd9ejDd:ejEd;ejFd<ejGd=ejHd>ejId?ejJd@ejKdAejLdBejMdCejNdDejOdEejPdFejQdGejRdHejSdIejTdJejUdKejVdLejWdMejXdNejYdOejZdPej[dQej\dRej]dSej^dTej_dUej`dVejadWejbdXejcdYejddZejed[ejfd\ejgd]ejhd^ejid_ejjd`ejkdaejldbejmdcejnddejodeejpdfejqdgejrdhejsdiejtdjejudkejvdlejwdmejxdniYZydodp„ Zze{dqk�ròe|eƒ eƒ  dS )raQ  
A simple VTK widget for PyQt or PySide.
See http://www.trolltech.com for Qt documentation,
http://www.riverbankcomputing.co.uk for PyQt, and
http://pyside.github.io for PySide.

This class is based on the vtkGenericRenderWindowInteractor and is
therefore fairly powerful.  It should also play nicely with the
vtk3DWidget code.

Created by Prabhu Ramachandran, May 2002
Based on David Gobbi's QVTKRenderWidget.py

Changes by Gerard Vermeulen Feb. 2003
 Win32 support.

Changes by Gerard Vermeulen, May 2003
 Bug fixes and better integration with the Qt framework.

Changes by Phil Thompson, Nov. 2006
 Ported to PyQt v4.
 Added support for wheel events.

Changes by Phil Thompson, Oct. 2007
 Bug fixes.

Changes by Phil Thompson, Mar. 2008
 Added cursor support.

Changes by Rodrigo Mologni, Sep. 2013 (Credit to Daniele Esposti)
 Bug fix to PySide: Converts PyCObject to void pointer.

Changes by Greg Schussman, Aug. 2014
 The keyPressEvent function now passes keysym instead of None.

Changes by Alex Tsui, Apr. 2015
 Port from PyQt4 to PyQt5.

Changes by Fabian Wenzel, Jan. 2016
 Support for Python3
é    NÚQWidgetÚPyQt5ÚPyQt4ÚPySidez!Cannot load either PyQt or PySideÚ	QGLWidget)r   )r   )ÚQSizePolicy)ÚQApplication)ÚQt)ÚQTimer)ÚQObject)ÚQSize)ÚQEventzUnknown PyQt implementation z2Unknown base class for QVTKRenderWindowInteractor c               @   s  e Zd ZdZejejejejejejejej	ej
ejejdœZd6dd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Z d*d+„ Z!d,d-„ Z"d.d/„ Z#d0d1„ Z$d2d3„ Z%d4d5„ Z&dS )7ÚQVTKRenderWindowInteractora   A QVTKRenderWindowInteractor for Python and Qt.  Uses a
    vtkGenericRenderWindowInteractor to handle the interactions.  Use
    GetRenderWindow() to get the vtkRenderWindow.  Create with the
    keyword stereo=1 in order to generate a stereo-capable window.

    The user interface is summarized in vtkInteractorStyle.h:

    - Keypress j / Keypress t: toggle between joystick (position
    sensitive) and trackball (motion sensitive) styles. In joystick
    style, motion occurs continuously as long as a mouse button is
    pressed. In trackball style, motion occurs when the mouse button
    is pressed and the mouse pointer moves.

    - Keypress c / Keypress o: toggle between camera and object
    (actor) modes. In camera mode, mouse events affect the camera
    position and focal point. In object mode, mouse events affect
    the actor that is under the mouse pointer.

    - Button 1: rotate the camera around its focal point (if camera
    mode) or rotate the actor around its origin (if actor mode). The
    rotation is in the direction defined from the center of the
    renderer's viewport towards the mouse position. In joystick mode,
    the magnitude of the rotation is determined by the distance the
    mouse is from the center of the render window.

    - Button 2: pan the camera (if camera mode) or translate the actor
    (if object mode). In joystick mode, the direction of pan or
    translation is from the center of the viewport towards the mouse
    position. In trackball mode, the direction of motion is the
    direction the mouse moves. (Note: with 2-button mice, pan is
    defined as <Shift>-Button 1.)

    - Button 3: zoom the camera (if camera mode) or scale the actor
    (if object mode). Zoom in/increase scale if the mouse position is
    in the top half of the viewport; zoom out/decrease scale if the
    mouse position is in the bottom half. In joystick mode, the amount
    of zoom is controlled by the distance of the mouse pointer from
    the horizontal centerline of the window.

    - Keypress 3: toggle the render window into and out of stereo
    mode.  By default, red-blue stereo pairs are created. Some systems
    support Crystal Eyes LCD stereo glasses; you have to invoke
    SetStereoTypeToCrystalEyes() on the rendering window.  Note: to
    use stereo you also need to pass a stereo=1 keyword argument to
    the constructor.

    - Keypress e: exit the application.

    - Keypress f: fly to the picked point

    - Keypress p: perform a pick operation. The render window interactor
    has an internal instance of vtkCellPicker that it uses to pick.

    - Keypress r: reset the camera view along the current view
    direction. Centers the actors and moves the camera so that all actors
    are visible.

    - Keypress s: modify the representation of all actors so that they
    are surfaces.

    - Keypress u: invoke the user-defined function. Typically, this
    keypress will bring up an interactor that you can type commands in.

    - Keypress w: modify the representation of all actors so that they
    are wireframe.
    )r   é   é   é   é   é   é   é   é   é	   é
   Nc             K   s®  t j| _d| _d| _t j| _t j| _d| _yt	|d ƒ}W n t
k
rR   d}Y nX y|d }W n t
k
rx   d }Y nX tdkr²d|kr”|d }nt jƒ }tj| ||t jB ƒ ntdkrÆtj| |ƒ |rÒ|| _n
tjƒ | _| jƒ }t|ƒjdk�r&dd	lm}m}m}	 ||j_|	g|j_|j|ƒ}ndt|ƒjd
k�rŠddlm}m}m}	m}
 |
|j_|	g|j_|j|ƒ}||j _|	|
g|j _|j ||ƒ}| jj!t"t#|ƒƒƒ |�r¸| jj$ƒ  | jj%ƒ  y|d | _&W n. t
k
�rô   tj'ƒ | _&| j&j(| jƒ Y nX | j)t j*ƒ | j)t j+ƒ | j,dƒ | j-t j.ƒ | j/t0t0j1t0j1ƒƒ t2| ƒ| _3| j3j4j5| j6ƒ | j&j7d| j8ƒ | j&j7d| j9ƒ | j&j:ƒ j7d| j;ƒ t| ƒ| _<| j<j=ƒ  | j<j>j5| j?ƒ d S )Nr   ÚstereoFÚrwr   Úwflagsr   Z	PyCObject)Ú	pythonapiÚc_void_pÚ	py_objectZ	PyCapsule)r   r   r   Úc_char_pZirenTZCreateTimerEventZDestroyTimerEventÚCursorChangedEvent)@r	   ZNoButtonÚ_ActiveButtonÚ"_QVTKRenderWindowInteractor__saveXÚ"_QVTKRenderWindowInteractor__saveYZ
NoModifierÚ*_QVTKRenderWindowInteractor__saveModifiersÚ(_QVTKRenderWindowInteractor__saveButtonsÚ'_QVTKRenderWindowInteractor__wheelDeltaÚboolÚKeyErrorÚQVTKRWIBaseZWindowFlagsr   Ú__init__ZMSWindowsOwnDCr   Ú_RenderWindowÚvtkÚvtkRenderWindowZwinIdÚtypeÚ__name__Úctypesr   r   r   ZPyCObject_AsVoidPtrÚrestypeÚargtypesr   ZPyCapsule_GetNameZPyCapsule_GetPointerZSetWindowInfoÚstrÚintZStereoCapableWindowOnZSetStereoTypeToCrystalEyesÚ_IrenZ vtkGenericRenderWindowInteractorZSetRenderWindowZsetAttributeZWA_OpaquePaintEventZWA_PaintOnScreenZsetMouseTrackingZsetFocusPolicyZ
WheelFocusZsetSizePolicyr   Z	Expandingr
   Ú_TimerÚtimeoutÚconnectÚ
TimerEventÚAddObserverÚCreateTimerÚDestroyTimerÚGetRenderWindowr    Z_hiddenZhideZ	destroyedÚFinalize)ÚselfÚparentÚkwr   r   r   ZWIdr   r   r   r   Úname© rC   úB/tmp/pip-install-5sebvq2j/vtk/vtk/qt/QVTKRenderWindowInteractor.pyr*   Ë   sz    













z#QVTKRenderWindowInteractor.__init__c             C   sF   |dkr| j fdd„S t| j |ƒr.t| j |ƒS t| jjd | ƒ‚dS )z?Makes the object behave like a vtkGenericRenderWindowInteractorZ__vtk__c             S   s   | S )NrC   )ÚtrC   rC   rD   Ú<lambda>0  s    z8QVTKRenderWindowInteractor.__getattr__.<locals>.<lambda>z has no attribute named N)r5   ÚhasattrÚgetattrÚAttributeErrorÚ	__class__r/   )r?   ÚattrrC   rC   rD   Ú__getattr__-  s    z&QVTKRenderWindowInteractor.__getattr__c             C   s   | j jƒ  dS )z=
        Call internal cleanup method on VTK objects
        N)r+   r>   )r?   rC   rC   rD   r>   7  s    z#QVTKRenderWindowInteractor.Finalizec             C   s   | j jdƒ d S )Nr   )r6   Ústart)r?   ÚobjÚevtrC   rC   rD   r;   =  s    z&QVTKRenderWindowInteractor.CreateTimerc             C   s   | j jƒ  dS )Nr   )r6   Ústop)r?   rN   rO   rC   rC   rD   r<   @  s    
z'QVTKRenderWindowInteractor.DestroyTimerc             C   s   | j jƒ  d S )N)r5   r9   )r?   rC   rC   rD   r9   D  s    z%QVTKRenderWindowInteractor.TimerEventc             C   s   t jd| jƒ dS )z>Called when the CursorChangedEvent fires on the render window.r   N)r
   Z
singleShotÚ
ShowCursor)r?   rN   rO   rC   rC   rD   r    G  s    z-QVTKRenderWindowInteractor.CursorChangedEventc             C   s   | j tjƒ dS )zHides the cursor.N)Ú	setCursorr	   ZBlankCursor)r?   rC   rC   rD   Ú
HideCursorN  s    z%QVTKRenderWindowInteractor.HideCursorc             C   s,   | j jƒ jƒ }| jj|tjƒ}| j|ƒ dS )zShows the cursor.N)r5   r=   ZGetCurrentCursorÚ_CURSOR_MAPÚgetr	   ÚArrowCursorrR   )r?   Z
vtk_cursorZ	qt_cursorrC   rC   rD   rQ   R  s    z%QVTKRenderWindowInteractor.ShowCursorc             C   s   | j ƒ  d S )N)r>   )r?   rO   rC   rC   rD   Ú
closeEventX  s    z%QVTKRenderWindowInteractor.closeEventc             C   s
   t ddƒS )Ni�  )r   )r?   rC   rC   rD   ÚsizeHint[  s    z#QVTKRenderWindowInteractor.sizeHintc             C   s   d S )NrC   )r?   rC   rC   rD   ÚpaintEngine^  s    z&QVTKRenderWindowInteractor.paintEnginec             C   s   | j jƒ  d S )N)r5   ÚRender)r?   ÚevrC   rC   rD   Ú
paintEventa  s    z%QVTKRenderWindowInteractor.paintEventc             C   sF   | j ƒ }| jƒ }tjj| j||ƒ | jj||ƒ | jjƒ  | jƒ  d S )N)	ÚwidthÚheightr,   r-   ZSetSizer+   r5   ZConfigureEventÚupdate)r?   r[   ÚwÚhrC   rC   rD   ÚresizeEventd  s    
z&QVTKRenderWindowInteractor.resizeEventc             C   s`   d }}t |dƒr8|jƒ tj@ r$d}|jƒ tj@ rXd}n | jtj@ rHd}| jtj@ rXd}||fS )NFÚ	modifiersT)rG   rc   r	   ZShiftModifierZControlModifierr$   )r?   r[   ÚctrlÚshiftrC   rC   rD   Ú_GetCtrlShiftl  s    
z(QVTKRenderWindowInteractor._GetCtrlShiftc             C   s<   | j |ƒ\}}| jj| j| j||tdƒdd ƒ | jjƒ  d S )Nr   )rf   r5   ÚSetEventInformationFlipYr"   r#   ÚchrZ
EnterEvent)r?   r[   rd   re   rC   rC   rD   Ú
enterEvent|  s    z%QVTKRenderWindowInteractor.enterEventc             C   s<   | j |ƒ\}}| jj| j| j||tdƒdd ƒ | jjƒ  d S )Nr   )rf   r5   rg   r"   r#   rh   Z
LeaveEvent)r?   r[   rd   re   rC   rC   rD   Ú
leaveEvent‚  s    z%QVTKRenderWindowInteractor.leaveEventc             C   sœ   | j |ƒ\}}d}|jƒ tjkr$d}| jj|jƒ |jƒ ||tdƒ|d ƒ |j	ƒ | _
| j
tjkrj| jjƒ  n.| j
tjkr‚| jjƒ  n| j
tjkr˜| jjƒ  d S )Nr   r   )rf   r.   r   ZMouseButtonDblClickr5   rg   ÚxÚyrh   Úbuttonr!   r	   Ú
LeftButtonZLeftButtonPressEventÚRightButtonZRightButtonPressEventÚ	MidButtonZMiddleButtonPressEvent)r?   r[   rd   re   ÚrepeatrC   rC   rD   ÚmousePressEventˆ  s    
z*QVTKRenderWindowInteractor.mousePressEventc             C   s|   | j |ƒ\}}| jj|jƒ |jƒ ||tdƒdd ƒ | jtjkrJ| jj	ƒ  n.| jtj
krb| jjƒ  n| jtjkrx| jjƒ  d S )Nr   )rf   r5   rg   rk   rl   rh   r!   r	   rn   ZLeftButtonReleaseEventro   ZRightButtonReleaseEventrp   ZMiddleButtonReleaseEvent)r?   r[   rd   re   rC   rC   rD   ÚmouseReleaseEvent™  s    z,QVTKRenderWindowInteractor.mouseReleaseEventc             C   sh   |j ƒ | _|jƒ | _|jƒ | _|jƒ | _| j|ƒ\}}| j	j
|jƒ |jƒ ||tdƒdd ƒ | j	jƒ  d S )Nr   )rc   r$   Zbuttonsr%   rk   r"   rl   r#   rf   r5   rg   rh   ZMouseMoveEvent)r?   r[   rd   re   rC   rC   rD   ÚmouseMoveEvent¥  s    



z)QVTKRenderWindowInteractor.mouseMoveEventc             C   s�   | j |ƒ\}}|jƒ dk r(t|jƒ ƒ}ntdƒ}t|jƒ ƒ}|r\t|ƒdkr\|jƒ r\|jƒ }| j	j
| j| j|||d|ƒ | j	jƒ  | j	jƒ  d S )Né   r   r   )rf   Úkeyr3   Útextrh   Ú_qt_key_to_key_symÚlenÚisalphaÚupperr5   rg   r"   r#   ZKeyPressEventZ	CharEvent)r?   r[   rd   re   rv   ZkeySymrC   rC   rD   ÚkeyPressEvent°  s    
z(QVTKRenderWindowInteractor.keyPressEventc             C   sZ   | j |ƒ\}}|jƒ dk r(t|jƒ ƒ}ntdƒ}| jj| j| j|||dd ƒ | jjƒ  d S )Nru   r   )rf   rv   rh   r5   rg   r"   r#   ZKeyReleaseEvent)r?   r[   rd   re   rv   rC   rC   rD   ÚkeyReleaseEventÀ  s    z*QVTKRenderWindowInteractor.keyReleaseEventc             C   sn   t |dƒr|  j|jƒ 7  _n|  j|jƒ jƒ 7  _| jdkrP| jjƒ  d| _n| jdkrj| jjƒ  d| _d S )NÚdeltaéx   r   iˆÿÿÿ)rG   r&   r~   Z
angleDeltarl   r5   ZMouseWheelForwardEventZMouseWheelBackwardEvent)r?   r[   rC   rC   rD   Ú
wheelEventË  s    




z%QVTKRenderWindowInteractor.wheelEventc             C   s   | j S )N)r+   )r?   rC   rC   rD   r=   Ø  s    z*QVTKRenderWindowInteractor.GetRenderWindowc             C   s   | j ƒ  d S )N)r_   )r?   rC   rC   rD   rZ   Û  s    z!QVTKRenderWindowInteractor.Render)N)'r/   Ú
__module__Ú__qualname__Ú__doc__r	   rV   ZSizeBDiagCursorZSizeFDiagCursorZSizeVerCursorZSizeHorCursorZSizeAllCursorZPointingHandCursorZCrossCursorrT   r*   rL   r>   r;   r<   r9   r    rS   rQ   rW   rX   rY   r\   rb   rf   ri   rj   rr   rs   rt   r|   r}   r€   r=   rZ   rC   rC   rC   rD   r   w   sJ   C

b
r   c              C   s¢   t dgƒ} tƒ }|jƒ  |jƒ  |jd| fdd„ƒ tjƒ }|jƒ j|ƒ tj	ƒ }|j
dƒ tjƒ }|j|jƒ ƒ tjƒ }|j|ƒ |j|ƒ |jƒ  | jƒ  dS )z@A simple example that uses the QVTKRenderWindowInteractor class.r   Z	ExitEventc             S   s   |j ƒ S )N)Úquit)ÚoÚeÚarC   rC   rD   rF   ê  s    z-QVTKRenderWidgetConeExample.<locals>.<lambda>r   N)r   r   Z
InitializeZStartr:   r,   ZvtkRendererr=   ZAddRendererZvtkConeSourceZSetResolutionZvtkPolyDataMapperZSetInputConnectionZGetOutputPortZvtkActorZ	SetMapperZAddActorÚshowÚexec_)ZappZwidgetZrenZconeZ
coneMapperZ	coneActorrC   rC   rD   ÚQVTKRenderWidgetConeExampleß  s     



rŠ   Z	BackSpaceZTabÚReturnZShift_LZ	Control_LZAlt_LZPauseZ	Caps_LockZEscapeÚspaceZEndZHomeZLeftZUpZRightZDownZSnapshotZInsertÚDeleteZHelpÚ0Ú1Ú2Ú3Ú4Ú5Ú6Ú7Ú8Ú9r‡   ÚbÚcÚdr†   ÚfÚgra   ÚiÚjÚkÚlÚmÚnr…   ÚpÚqÚrÚsrE   ÚuÚvr`   rk   rl   ÚzZasteriskÚplusÚminusZperiodZslashZF1ZF2ZF3ZF4ZF5ZF6ZF7ZF8ZF9ZF10ZF11ZF12ZF13ZF14ZF15ZF16ZF17ZF18ZF19ZF20ZF21ZF22ZF23ZF24ZNum_LockZScroll_Lockc             C   s   | t krdS t |  S )z• Convert a Qt key into a vtk keysym.

    This is essentially copied from the c++ implementation in
    GUISupport/Qt/QVTKInteractorAdapter.cxx.
    N)Ú_keysyms)rv   rC   rC   rD   rx   _  s    rx   Ú__main__)}rƒ   Zvtk.qtr,   ZqtZPyQtImplÚImportErrorr)   r   r   r   ZPyQt5.QtOpenGLr   ZPyQt5.QtWidgetsr   r   r   ZPyQt5.QtCorer	   r
   r   r   r   ZPyQt4.QtOpenGLZPyQt4.QtGuiZPyQt4.QtCoreZPySide.QtOpenGLZPySide.QtGuiZPySide.QtCoreÚreprZQVTKRWIBaseClassr   rŠ   ZKey_BackspaceZKey_TabZKey_BacktabZ
Key_ReturnZ	Key_EnterZ	Key_ShiftZKey_ControlZKey_AltZ	Key_PauseZKey_CapsLockZ
Key_EscapeZ	Key_SpaceZKey_EndZKey_HomeZKey_LeftZKey_UpZ	Key_RightZKey_DownZ
Key_SysReqZ
Key_InsertZ
Key_DeleteZKey_HelpZKey_0ZKey_1ZKey_2ZKey_3ZKey_4ZKey_5ZKey_6ZKey_7ZKey_8ZKey_9ZKey_AZKey_BZKey_CZKey_DZKey_EZKey_FZKey_GZKey_HZKey_IZKey_JZKey_KZKey_LZKey_MZKey_NZKey_OZKey_PZKey_QZKey_RZKey_SZKey_TZKey_UZKey_VZKey_WZKey_XZKey_YZKey_ZZKey_AsteriskZKey_PlusZ	Key_MinusZ
Key_PeriodZ	Key_SlashZKey_F1ZKey_F2ZKey_F3ZKey_F4ZKey_F5ZKey_F6ZKey_F7ZKey_F8ZKey_F9ZKey_F10ZKey_F11ZKey_F12ZKey_F13ZKey_F14ZKey_F15ZKey_F16ZKey_F17ZKey_F18ZKey_F19ZKey_F20ZKey_F21ZKey_F22ZKey_F23ZKey_F24ZKey_NumLockZKey_ScrollLockr¬   rx   r/   ÚprintrC   rC   rC   rD   Ú<module>)   sB  






  j"

