3
y<ï[âG  ã               @   s|  d Z ddl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mZ ddlmZmZmZmZ ddlmZ dd	lmZ dd
lmZmZmZmZ ddlmZ ddlmZ dd„ Z e ƒ Z!G dd„ deƒZ"G dd„ deƒZ#G dd„ deƒZ$G dd„ deƒZ%dd„ Z&G dd„ de
ƒZ'G dd„ deƒZ(G dd„ deƒZ)G dd „ d e	ƒZ*G d!d"„ d"e	ƒZ+d*d%d&„Z,d'd(„ Z-e.d)k�rxe-ƒ  dS )+a­  ivtk - Interactive TVTK.

A utility module that makes VTK/TVTK easier to use from the Python
interpreter.  For a standalone application simply run this file.  To
use this under IPython (with --gui=qt) use the `viewer()` helper
function or use the `IVTK` class.  The widget can also make use of the
tvtk pipeline browser.

Here is example usage of the viewer along with tvtk under IPython:

    >>> from tvtk.tools import ivtk
    >>> from tvtk.api import tvtk
    >>> cs = tvtk.ConeSource()
    >>> m = tvtk.PolyDataMapper()
    >>> m.input = cs.output
    >>> a = tvtk.Actor()
    >>> a.mapper = m
    >>> v = ivtk.viewer()
    >>> v.scene.add_actors(a)
    >>> v.scene.reset_zoom()

é    N)Ú
FileDialogÚGUIÚOKÚPythonShell)ÚSplitApplicationWindowÚApplicationWindow)Ú
SplitPanel)ÚSceneÚDecoratedScene)ÚActionÚMenuBarManagerÚMenuManagerÚ	Separator)ÚImageResource)Úresource_path)ÚFloatÚStrÚInstanceÚCallable)Útvtk)ÚPipelineBrowserc              C   s   t jjtƒ ddƒ} t| ƒS )NÚimagesz	scene.ico)ÚosÚpathÚjoinr   r   )Ú	icon_path© r   úR/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/tvtk/tools/ivtk.pyÚmk_scene_icon2   s    r   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
ExitActionz Exits the application. c             C   s   || _ d| _dS )z Creates a new action. zE&xitN)Ú_windowÚname)ÚselfÚwindowr   r   r   Ú__init__=   s    zExitAction.__init__c             C   s   | j jƒ  dS )z Performs the action. N)r    Úclose)r"   r   r   r   ÚperformB   s    zExitAction.performN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   r&   r   r   r   r   r   ;   s   r   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚSaveImageActionz%Saves the rendered scene to an image.c             C   s   || _ d| _d S )NzS&ave Scene)r    r!   )r"   r#   r   r   r   r$   L   s    zSaveImageAction.__init__c             C   s²   ddddddddd	d
ddddddg}dddddddddddddddd g}d!}x(t ||ƒD ]\}}|d"j|||ƒ7 }qXW |d#7 }t| jjd$|d%d&�}|jƒ tkr®| jjj|j	ƒ d'S )(z4Pops up a dialog used to save the scene to an image.z*.pngz*.jpgz*.tiffz*.bmpz*.psz*.epsz*.pdfz*.texz*.ribz*.wrlz*.ooglz*.vrmlz*.objz*.ivz*.povz*.x3dZPNGZJPGZTIFFZBitmapZ
PostScriptZEPSZPDFZTexZRIBZWRLZGeomviewZVRMLZ	WavefrontzOpen InventorZPovrayÚX3DÚ z{} ({})|{}|z"Determine by extension (*.*)|(*.*)zsave aszSave scene to image)ÚparentÚactionÚwildcardÚtitleN)
ÚzipÚformatr   r    ÚcontrolÚopenr   ÚsceneÚsaver   )r"   Ú
extensionsÚdescriptionsr0   ÚdescriptionÚ	extensionZdlgr   r   r   r&   P   s$    






zSaveImageAction.performN)r'   r(   r)   r*   r$   r&   r   r   r   r   r+   J   s   r+   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚSaveToClipboardActionz( Saves rendered scene to the Clipboard. c             C   s   || _ d| _dS )z Creates a new action. z&CopyN)r    r!   )r"   r#   r   r   r   r$   l   s    zSaveToClipboardAction.__init__c             C   s   | j jjƒ  dS )z Performs the action. N)r    r6   Zsave_to_clipboard)r"   r   r   r   r&   q   s    zSaveToClipboardAction.performN)r'   r(   r)   r*   r$   r&   r   r   r   r   r<   j   s   r<   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚSpecialViewActionz$Sets the scene to a particular view.c             C   s   || _ || _|| _dS )z Creates a new action. N)r    r!   Úview)r"   r#   r!   r>   r   r   r   r$   {   s    zSpecialViewAction.__init__c             C   s4   yt | jj| jƒ}|ƒ  W n tk
r.   Y nX dS )z Performs the action. N)Úgetattrr    r6   r>   ÚAttributeError)r"   Úmethr   r   r   r&   �   s
    
zSpecialViewAction.performN)r'   r(   r)   r*   r$   r&   r   r   r   r   r=   y   s   r=   c             C   sŒ   t tt| ƒtƒ t| ƒdd�tt| ƒdd�tt| ddƒtƒ t| ddƒt| dd	ƒt| d
dƒt| ddƒt| ddƒt| ddƒt| ddƒdd�
ƒ}|S )z¸Creates a menu bar suitable for all IVTK windows.

    Parameters
    ----------

    - obj : A Pyface application window.

      This is the window which requires the menu items.
    z&File)r!   z&Editz&Reset ZoomÚ
reset_zoomz
&IsometricZisometric_viewz&X positiveZx_plus_viewz
X negativeZx_minus_viewz&Y positiveZy_plus_viewz
Y negativeZy_minus_viewz&Z positiveZz_plus_viewz
Z negativeZz_minus_viewz&View)r   r   r+   r   r   r<   r=   )ÚobjÚmenu_bar_managerr   r   r   Úcreate_ivtk_menu‹   s$    







rE   c                   sX   e Zd ZdZedƒZedƒZee	ƒZ
eeƒZ‡ fdd„Zdd„ Zdd	„ Zd
d„ Z‡  ZS )ÚSceneWithBrowserzy Provides an Scene along with an embedded PyCrust Python shell.
    In the shell, 'scene' and 's' are bound to the Scene.g333333Ó?Úverticalc                s&   | j d k	r| j jƒ  tt| ƒjƒ  d S )N)r6   r%   ÚsuperrF   Údestroy)r"   )Ú	__class__r   r   rI   Ä   s    

zSceneWithBrowser.destroyc             C   s>   | j |ƒ t| jƒ| _|dk	r&|jƒ  | jj|d� | jjjS )z; Creates the left hand side or top depending on the style. N)r.   )Ú_create_scener   r6   ÚbrowserÚshowÚ_uir4   )r"   r.   r   r   r   Ú_create_lhsÌ   s    
zSceneWithBrowser._create_lhsc             C   s   | j |ƒ d| jj_| jjS )zx Creates the right hand side or bottom depending on the
        style.  's' and 'scene' are bound to the Scene instance.ç      à?)rP   rP   rP   )rK   r6   ÚrendererÚ
backgroundr4   )r"   r.   r   r   r   Ú_create_rhsÕ   s    

zSceneWithBrowser._create_rhsc             C   s   | j dkrt|ƒ| _ dS )z, Make sure that the scene has been created. N)r6   r
   )r"   r.   r   r   r   rK   ß   s    
zSceneWithBrowser._create_scene)r'   r(   r)   r*   r   Úratior   Ú	directionr   r	   r6   r   rL   rI   rO   rS   rK   Ú__classcell__r   r   )rJ   r   rF   ±   s   	
rF   c                   s\   e Zd ZdZedƒZedƒZee	ƒZ
eeƒZ‡ fdd„Z‡ fdd„Zdd	„ Zd
d„ Z‡  ZS )ÚIVTKWithCrustzy Provides an Scene along with an embedded PyCrust Python shell.
    In the shell, 'scene' and 's' are bound to the Scene.gffffffæ?Ú
horizontalc                s&   t t| ƒjf |Ž d| _t| ƒ| _dS )z Creates a new window. z
TVTK SceneN)rH   rW   r$   r1   rE   rD   )r"   Útraits)rJ   r   r   r$   û   s    zIVTKWithCrust.__init__c                s&   | j d k	r| j jƒ  tt| ƒjƒ  d S )N)r6   r%   rH   rW   )r"   )rJ   r   r   r%     s    

zIVTKWithCrust.closec             C   s   t |ƒ| _d| jj_| jjS )z; Creates the left hand side or top depending on the style. ç      à?)rZ   rZ   rZ   )r
   r6   rQ   rR   r4   )r"   r.   r   r   r   rO     s    

zIVTKWithCrust._create_lhsc             C   s@   t |ƒ| _| jjd| jƒ | jjd| jƒ | jjdtƒ | jjS )zx Creates the right hand side or bottom depending on the
        style.  's' and 'scene' are bound to the Scene instance.r6   Úsr   )r   Úpython_shellÚbindr6   r   r4   )r"   r.   r   r   r   rS     s
    
zIVTKWithCrust._create_rhs)r'   r(   r)   r*   r   rT   r   rU   r   r	   r6   r   r\   r$   r%   rO   rS   rV   r   r   )rJ   r   rW   è   s   rW   c                   sv   e Zd ZdZedƒZedƒZee	ƒZ
eeƒZeeƒZeeƒZ‡ fdd„Z‡ fdd„ZeeeƒZdd	„ Zd
d„ Z‡  ZS )ÚIVTKWithCrustAndBrowserzy Provides an Scene along with an embedded PyCrust Python shell.
    In the shell, 'scene' and 's' are bound to the Scene.gffffffæ?rX   c                s&   t t| ƒjf |Ž d| _t| ƒ| _dS )z Creates a new window. z
TVTK SceneN)rH   r^   r$   r1   rE   rD   )r"   rY   )rJ   r   r   r$   >  s    z IVTKWithCrustAndBrowser.__init__c                s&   | j d k	r| j jƒ  tt| ƒjƒ  d S )N)r6   r%   rH   r^   )r"   )rJ   r   r   r%   J  s    

zIVTKWithCrustAndBrowser.closec             C   s&   t |ƒ| _| jj| _| jj| _| jjS )z; Creates the left hand side or top depending on the style. )rF   Úbrowser_scener6   rL   r4   )r"   r.   r   r   r   rO   V  s    


z#IVTKWithCrustAndBrowser._create_lhsc             C   s`   t |ƒ| _| jjd| jƒ | jjd| jƒ | jjd| jƒ | jjd| jƒ | jjdtƒ | jjS )zx Creates the right hand side or bottom depending on the
        style.  's' and 'scene' are bound to the Scene instance.r6   r[   rL   Úbr   )r   r\   r]   r6   rL   r   r4   )r"   r.   r   r   r   rS   ]  s    
z#IVTKWithCrustAndBrowser._create_rhs)r'   r(   r)   r*   r   rT   r   rU   r   r	   r6   r   rL   rF   r_   r   r\   r$   r%   r   Ú
scene_iconÚiconrO   rS   rV   r   r   )rJ   r   r^   %  s   

r^   c                   sN   e Zd ZdZeeƒZeeƒZ	‡ fdd„Z
‡ fdd„ZeeeƒZdd„ Z‡  ZS )ÚIVTKz� Provides an Scene along without an embedded Python shell.
    This is useful when scripting from the vanilla Python or IPython
    interpreter.c                s&   t t| ƒjf |Ž d| _t| ƒ| _dS )z# Creates a new application window. z
TVTK SceneN)rH   rc   r$   r1   rE   rD   )r"   rY   )rJ   r   r   r$   |  s    zIVTK.__init__c                s&   | j d k	r| j jƒ  tt| ƒjƒ  d S )N)r6   r%   rH   rc   )r"   )rJ   r   r   r%   ‡  s    

z
IVTK.closec             C   s   | j |ƒ| _| jjS )z$ Create the contents of the window. )Ú_scene_factoryr6   r4   )r"   r.   r   r   r   Ú_create_contents“  s    zIVTK._create_contents)r'   r(   r)   r*   r   r	   r6   r   r
   rd   r$   r%   r   ra   rb   re   rV   r   r   )rJ   r   rc   n  s   

rc   c                   sV   e Zd ZdZeeƒZeeƒZee	ƒZ
‡ fdd„Z‡ fdd„ZeeeƒZdd„ Z‡  ZS )ÚIVTKWithBrowserz� Provides an Scene along without an embedded Python shell.
    This is useful when scripting from the vanilla Python or IPython
    interpreter.c                s&   t t| ƒjf |Ž d| _t| ƒ| _dS )z# Creates a new application window. z
TVTK SceneN)rH   rf   r$   r1   rE   rD   )r"   rY   )rJ   r   r   r$   ®  s    zIVTKWithBrowser.__init__c                s&   | j d k	r| j jƒ  tt| ƒjƒ  d S )N)r6   r%   rH   rf   )r"   )rJ   r   r   r%   ¹  s    

zIVTKWithBrowser.closec             C   s&   t |ƒ| _| jj| _| jj| _| jjS )z$ Create the contents of the window. )rF   r_   r6   rL   r4   )r"   r.   r   r   r   re   Å  s    


z IVTKWithBrowser._create_contents)r'   r(   r)   r*   r   r	   r6   r   rL   rF   r_   r$   r%   r   ra   rb   re   rV   r   r   )rJ   r   rf   �  s   

rf   TFc             C   s0   |r
t ƒ }| rtdd�}n
tdd�}|jƒ  |S )a«  Creates an IVTK instance, opens the window and returns the
    embedded scene inside it.  This is useful from an IPython/vanilla
    Python shell.  It returns the viewer window instance.

    Parameters
    ----------

    - browser : `bool` (default, True)

      If True, creates an IVTK scene with an embedded PipelineBrowser.
      If False, does not create it.

    - instantiate_gui : `bool` (default: False)

      If True, create an instance of GUI().  This is useful when this
      function is invoked from within an IPython shell.  OTOH, if this
      is called from within a wxPython app (or with ipython --gui=qt)
      you don't want to start another GUI instance.
    éX  )Úsize)rg   rg   )rg   rg   )r   rf   rc   r5   )rL   Zinstantiate_guiÚguiÚvr   r   r   ÚviewerÑ  s    
rk   c              C   s$   t ƒ } tdd�}|jƒ  | jƒ  d S )Né   éX  )rh   )rl   rm   )r   r^   r5   Zstart_event_loop)ri   r#   r   r   r   Úmainï  s    
rn   Ú__main__)TF)/r*   Úos.pathr   Ú
pyface.apir   r   r   r   r   r   r   Ztvtk.pyface.apir	   r
   Úpyface.action.apir   r   r   r   Úpyface.image_resourcer   Úpyface.resource.apir   Ú
traits.apir   r   r   r   Útvtk.apir   Ztvtk.pipeline.browserr   r   ra   r   r+   r<   r=   rE   rF   rW   r^   rc   rf   rk   rn   r'   r   r   r   r   Ú<module>   s6    &7=I/4


