a
    «ˆcÆB  ã                   @   sÚ   d Z ddlZddlZddlmZmZ ddlmZ ddlmZ ddl	m
Z
mZmZ ddlmZmZmZmZ ddlmZ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 G dd„ deƒZG dd„ deeƒZdS )zaA VTK interactor scene widget for the PyFace PyQt backend.  See the class
docs for more details.
é    N)ÚQtCoreÚQtGui)Útvtk)Ú	messenger)ÚInstanceÚButtonÚAny)ÚViewÚGroupÚItemÚInstanceEditor)ÚWidgetÚGUI)Úpicker)Úlight_manager)Ú
popup_save)Ú	TVTKSceneé   )ÚQVTKRenderWindowInteractorc                   @   sP   e Zd Z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S )Ú_VTKRenderWindowInteractorzE This is a thin wrapper around the standard VTK PyQt interactor.
    c                 K   s$   t j| |fi |¤Ž || _d| _d S ©NF)r   Ú__init__Ú_sceneÚ_interacting)ÚselfÚsceneÚparentÚkwargs© r   ú[/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/tvtk/pyface/ui/qt4/scene.pyr   1   s    z#_VTKRenderWindowInteractor.__init__c                 C   s   t  | |¡ | jj ¡  dS )zC Reimplemented to refresh the traits of the render window.
        N)r   ÚresizeEventr   Ú_renwinÚupdate_traits)r   Úer   r   r   r    7   s    z&_VTKRenderWindowInteractor.resizeEventc                 C   s€   t  | |¡ | j}|jdu r|t |¡|_|j}| ¡  t |¡}| 	dt
j¡ t
 |d| j¡ | 	dt
j¡ t
 |d| j¡ dS )aJ   Reimplemented to create the light manager only when needed.  This
        is necessary because it makes sense to create the light manager only
        when the widget is realized.  Only when the widget is realized is the
        VTK render window created and only then are the default lights all
        setup correctly.
        NZ
StartEventZEndEvent)r   Ú
paintEventr   r   ZLightManagerr!   r"   r   Zto_vtkZadd_observerr   ÚsendÚconnectÚ_start_event_callbackÚ_end_event_callback)r   r#   r   ÚrenwinZvtk_rwr   r   r   r$   >   s    

z%_VTKRenderWindowInteractor.paintEventc                 C   sÌ  |  ¡ }| ¡ }| j}|j}|tjjfv rJ| d¡ | ¡  | 	d¡ dS |tjj
tjjfv r~| d¡ | ¡  | 	d¡ dS |tjjtjjtjjfv r®| ¡  |j ¡  dS |tjjfv rÀdS |tjjfv rÜ| 	d¡ dS |tjjfv �r@|tjjk�r@|  tj ¡ ¡}| ¡ }|  ¡ | ¡  }|j || j || j ¡ dS |tjjfv �rÔ|tjjk�rÔ|  tj ¡ ¡}| ¡ }|  ¡ | ¡  }|j  || j || j ¡}	|	j!}
|
du�rÐ|
|_"| ¡  | 	dt#|
ƒ ¡ dS |tjj$fv �r |tjjk�r |j% &¡  dS |tjj'fv �rH|tjjk�rHt(|  )¡ ƒ}t*|ƒdk�rD| j +|¡ dS |tjj,@ tjj,k}|tjj-k�r°|�r†| .d	¡ | 	d
¡ n| /d¡ | 	d¡ | ¡  | 	d¡ dS |tjj0k�r|�rÚ| .d¡ | 	d¡ n| /d	¡ | 	d¡ | ¡  | 	d¡ dS |tjj1k�r`|�r.| 2d	¡ | 	d¡ n| 3d	¡ | 	d¡ | 4¡  | ¡  | 	d¡ dS |tjj5k�r¼|�rŠ| 2d¡ | 	d¡ n| 3d¡ | 	d¡ | 4¡  | ¡  | 	d¡ dS t6 7| |¡ dS )zâ This method is overridden to prevent the 's'/'w'/'e'/'q' keys from
        doing the default thing which is generally useless.  It also handles
        the 'p' and 'l' keys so the picker and light manager are called.
        gš™™™™™é?zcamera.zoom(0.8)
render()Ng      ô?zcamera.zoom(1.25)
render()zreset_zoom()z camera.focal_point = %r
render()r   éûÿÿÿzcamera.yaw(-5)é   zcamera.azimuth(5)zrender()zcamera.yaw(5)zcamera.azimuth(-5)zcamera.pitch(-5)zcamera.elevation(-5)z'camera.orthogonalize_view_up()
render()zcamera.pitch(5)zcamera.elevation(5))8ÚkeyÚ	modifiersr   Úcamerar   ÚQtZ	Key_MinusZzoomÚrenderZ_record_methodsZ	Key_EqualZKey_PlusZKey_EZKey_QZ
Key_EscapeÚ_disable_fullscreenr   Zclose_pickerZKey_WZKey_RZKey_PZ
NoModifierZmapFromGlobalr   ZQCursorÚposÚxÚheightÚyZpickZ_pixel_ratioZKey_FZ
pick_worldZ
coordinateZfocal_pointÚlistZKey_Lr   Ú	configureZKey_Sr   r   ÚlenÚsaveZShiftModifierZKey_LeftZyawZazimuthZ	Key_RightZKey_UpZpitchZ	elevationZorthogonalize_view_upZKey_Downr   ÚkeyPressEvent)r   r#   r,   r-   r   r.   r2   r3   r5   ÚdataZcoordÚfnameÚshiftr   r   r   r:   S   s´    






ÿ
















z(_VTKRenderWindowInteractor.keyPressEventc                 C   s   d| _ t | |¡ dS )zOverride for mouse presses.TN)r   r   ÚmousePressEvent©r   Zevr   r   r   r>   Ê   s    z*_VTKRenderWindowInteractor.mousePressEventc                 C   s   d| _ t | |¡ dS )zOverride for mouse releases.FN)r   r   ÚmouseReleaseEventr?   r   r   r   r@   Ï   s    z,_VTKRenderWindowInteractor.mouseReleaseEventc                 C   s   | j r
d S d| j_d S )NT©r   r   Úbusy©r   ÚobjÚeventr   r   r   r'   Ô   s    z0_VTKRenderWindowInteractor._start_event_callbackc                 C   s   | j r
d S d| j_d S r   rA   rC   r   r   r   r(   Ú   s    z._VTKRenderWindowInteractor._end_event_callbackN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r$   r:   r>   r@   r'   r(   r   r   r   r   r   .   s   wr   c                       sš  e Zd ZdZdZedƒZeej	ƒZe
edd�edd�ddd	�Zee
e
ed
d�edd�edd�edd�edd�edd�edd�edd�edd�eddd�ƒ
e
edddeeeƒd�dd�ƒd d�e
edddd�dd�e
edddd�d d�e
ed!ddd�d"d�d#d$gd%�ZeeƒZedƒZdC‡ fd'd(„	Z‡ fd)d*„Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Z‡ fd7d8„Zd9d:„ Zd;d<„ Zd=d>„ Zd?d@„ Z dAdB„ Z!‡  Z"S )DÚSceneaŠ  A VTK interactor scene widget for pyface and PyQt.

    This widget uses a RenderWindowInteractor and therefore supports
    interaction with VTK widgets.  The widget uses TVTK.  In addition
    to the features that the base TVTKScene provides this widget
    supports:

    - saving the rendered scene to the clipboard.

    - picking data on screen.  Press 'p' or 'P' when the mouse is over
      a point that you need to pick.

    - The widget also uses a light manager to manage the lighting of
      the scene.  Press 'l' or 'L' to activate a GUI configuration
      dialog for the lights.

    - Pressing the left, right, up and down arrow let you rotate the
      camera in those directions.  When shift-arrow is pressed then
      the camera is panned.  Pressing the '+' (or '=')  and '-' keys
      let you zoom in and out.

    - full screen rendering via the full_screen button on the UI.

    r   zFull ScreenÚstereo_render)ÚnameÚstereo_typeTzStereo rendering)Zshow_borderÚlabelÚ
backgroundZ
foregroundÚparallel_projectionÚdisable_renderÚoff_screen_renderingZjpeg_qualityZjpeg_progressiveZmagnificationZanti_aliasing_framesÚfull_screenF)rL   Ú
show_labelÚrender_windowZcustomzobject.stereo)Úview)rL   ÚstyleZvisible_whenZeditorrT   )rN   r   )rL   rW   rT   ÚPickerr   ZLightsZmovie_makerZMovieÚOKZCancel)ZbuttonsNc                    s8   t t| ƒj|fi |¤Ž t | ¡| _d| _tjj| _	dS )z Initializes the object. N)
ÚsuperrJ   r   r   rX   r   r   r/   ZArrowCursorÚ_cursor)r   r   Ztraits©Ú	__class__r   r   r   B  s    zScene.__init__c                    s(   t t| ƒ ¡ }dD ]}| |d¡ q|S )zAllows us to pickle the scene.)Ú_vtk_controlÚ_fullscreenr[   N)rZ   rJ   Ú__get_pure_state__Úpop)r   Údr3   r\   r   r   r`   P  s    zScene.__get_pure_state__c                 C   s   | j s| j ¡  dS )zf Force the scene to be rendered. Nothing is done if the
        `disable_render` trait is set to True.N)rQ   r^   ZRender©r   r   r   r   r0   \  s    zScene.renderc                 C   s   | j  ¡ }| ¡ | ¡ fS )z!Return size of the render window.)r^   ÚsizeÚwidthr4   )r   Úszr   r   r   Úget_sizeb  s    
zScene.get_sizec                 C   s   | j j|Ž  dS )zSet the size of the window.N)r^   Úresize)r   rd   r   r   r   Úset_sizeh  s    zScene.set_sizec                 C   s$   | j  ¡  ¡ | _| j  tjj¡ dS )zHide the cursor.N)r^   ÚcursorÚshaper[   Ú	setCursorr   r/   ZBlankCursorrc   r   r   r   Úhide_cursorl  s    zScene.hide_cursorc                 C   s   | j  | j¡ dS )zShow the cursor.N)r^   rl   r[   rc   r   r   r   Úshow_cursorq  s    zScene.show_cursorc                 C   sD   t  ¡ \}}|  |¡ tj ¡  t |¡¡ t 	|¡ t 
|¡ dS )z-Saves a bitmap of the scene to the clipboard.N)ÚtempfileÚmkstempZsave_bmpr   ZQApplicationZ	clipboardZsetImageZQImageÚosÚcloseÚunlink)r   ÚhandlerrL   r   r   r   Úsave_to_clipboardx  s
    

zScene.save_to_clipboardc                    s$   t t| ƒ ¡  d | _d | _d | _d S ©N)rZ   rJ   Ú_closed_firedr   r^   Úcontrolrc   r\   r   r   rw   ƒ  s    zScene._closed_firedc                 C   s  t | || jd� | _}| ¡  ¡  t | ¡ ¡ }| _|j	| j
| j| jd� t ¡ | _| | j¡ | j| _| j| j_|  d| j¡ | j | jd¡ | j|_| j| j_|  d| j¡ |  d| j¡ | j | jd¡ | j | jd¡ | j | jd¡ | j | jd¡ t |j¡| _|S )zA Create the toolkit-specific control that represents the widget. )Ústereo)Úpoint_smoothingÚline_smoothingÚpolygon_smoothingrO   rP   rR   rK   rM   )r   ry   r^   ZGetInteractorStyleZ SetCurrentStyleToTrackballCamerar   Zto_tvtkZGetRenderWindowr!   Z	trait_setrz   r{   r|   ZRendererZ	_rendererZadd_rendererr.   Z_camerarO   Z
sync_traitZrendererZon_trait_changer0   rR   rP   rU   Z_IrenZ_interactor)r   r   Úwindowr)   r   r   r   Ú_create_controlŒ  s2    ÿþ


zScene._create_controlc                 C   s(   | j jrdS | j ¡  ¡  tj ¡  dS )zJLift the window to the top. Useful when saving screen to an
        image.N)rU   rR   r^   r}   Zraise_r   ZQCoreApplicationZprocessEventsrc   r   r   r   Ú_lift³  s    zScene._liftc                 C   s8   | j }|r | j ¡  ¡  d| _ n| j ¡  ¡  d| _ d S )NFT)r_   r^   r}   Ú
showNormalZshowFullScreen©r   Úfsr   r   r   Ú_full_screen_fired½  s    zScene._full_screen_firedc                 C   s"   | j }|r| j ¡  ¡  d| _ d S r   )r_   r^   r}   r€   r�   r   r   r   r1   Æ  s    zScene._disable_fullscreenc                 C   s   t  |¡ d S rv   )r   Zset_busy)r   Úvalr   r   r   Ú_busy_changedÌ  s    zScene._busy_changed)N)#rF   rG   rH   rI   Ú__version__r   rS   r   r   rX   r
   r   Z_stereo_viewr	   r   Zdefault_viewr   r^   r   r_   r   r`   r0   rg   ri   rm   rn   ru   rw   r~   r   rƒ   r1   r…   Ú__classcell__r   r   r\   r   rJ   å   s„   

ý
ÿ÷üíÿþÿþþûà&	'
	rJ   )rI   rq   ro   Z	pyface.qtr   r   Ztvtk.apir   r   Z
traits.apir   r   r   Ztraitsui.apir	   r
   r   r   Z
pyface.apir   r   Ztvtk.pyfacer   r   Ztvtk.pyface.utilsr   Ztvtk.pyface.tvtk_scener   r   r   rJ   r   r   r   r   Ú<module>   s    	 8