a
    «ˆc‚  ã                   @   sl   d Z ddlmZmZ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 G dd„ deƒZd	S )
z0A component to manage an implicit plane widget.
é    )ÚInstanceÚBoolÚPropertyÚAny)ÚViewÚGroupÚItemÚInstanceEditor)Útvtk)Ú	Component)ÚDataSetHelperc                   @   s2  e Zd ZdZeejddddddœdd�Zeejddd	d
œdd�Z	e
Ze
ZedƒZedƒZeZ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�ƒ
Zeeeddeeeƒd�d�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/d0„ Z"d1S )2ÚImplicitPlaner   © Fg333333ó?)Zkey_press_activationZplace_factorÚ
draw_planeÚoutline_translationT)ÚargsÚkwÚrecord)ç        r   r   )r   r   é   )ÚoriginÚnormalZenabled)ÚnameÚnormal_to_x_axisÚnormal_to_y_axisÚnormal_to_z_axisr   Zscale_enabledZtubingr   r   r   ÚwidgetZcustom)Úview)r   ÚstyleZeditor)Zshow_labelsc                 C   s   | j g| _|  ¡  dS )aÖ  Override this method so that it *creates* its tvtk
        pipeline.

        This method is invoked when the object is initialized via
        `__init__`.  Note that at the time this method is called, the
        tvtk data pipeline will *not* yet be setup.  So upstream data
        will not be available.  The idea is that you simply create the
        basic objects and setup those parts of the pipeline not
        dependent on upstream sources and filters.
        N)r   ZwidgetsÚ_connect©Úselfr   r   úc/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/components/implicit_plane.pyÚsetup_pipelineK   s    
zImplicitPlane.setup_pipelinec                 C   sÒ   t | jƒdks"t | jd jƒdkr&dS | jd jd }| j}|  ||¡ | jrŠt| jd jd ƒ}| ¡ | _|j	| jŽ  | 
¡ | _d| _n(| j}|d |d |d d f| _|| _| j|gkrÈ|g| _nd| _dS )zâOverride this method so that it *updates* the tvtk pipeline
        when data upstream is known to have changed.

        This method is invoked (automatically) when the input fires a
        `pipeline_changed` event.
        r   NFr   é   gü©ñÒMbP?T)ÚlenÚinputsÚoutputsr   Zconfigure_inputÚ_firstr   Z
get_boundsÚ_boundsÚplace_widgetZ
get_centerr   r   Údata_changed)r!   ÚinpÚwZdshÚnr   r   r"   Úupdate_pipelineZ   s"    "


zImplicitPlane.update_pipelinec                 C   s
   d| _ dS )zÆOverride this method to do what is necessary when upstream
        data changes.

        This method is invoked (automatically) when any of the inputs
        sends a `data_changed` event.
        TN)r+   r    r   r   r"   Úupdate_dataz   s    zImplicitPlane.update_datac                 C   s   | j  | j¡ |  ¡  dS )zSConvenience method to update the plane once the widget is
        changed.
        N)r   Z	get_planeÚplaner0   r    r   r   r"   Úupdate_planeƒ   s    zImplicitPlane.update_planec                 C   s   | j jS ©N)r   r   r    r   r   r"   Ú_get_normal�   s    zImplicitPlane._get_normalc                 C   s,   | j }|j}||_|  d||¡ |  ¡  d S )Nr   )r   r   Útrait_property_changedr2   ©r!   Úvaluer-   Úoldr   r   r"   Ú_set_normal�   s
    zImplicitPlane._set_normalc                 C   s   | j jS r3   )r   r   r    r   r   r"   Ú_get_origin—   s    zImplicitPlane._get_originc                 C   s<   t  | j¡}| ¡ }| t|ƒ¡ |  d||¡ |  ¡  d S )Nr   )r
   Zto_vtkr   Z	GetOriginZ	SetOriginÚlistr5   r2   r6   r   r   r"   Ú_set_origin™   s
    zImplicitPlane._set_originc                 C   s   | j sd| _ |  ¡  d| _ d S )NTF)Ú_busyr2   )r!   ÚobjÚeventr   r   r"   Ú_on_interaction_event¡   s    z#ImplicitPlane._on_interaction_eventc                 C   s   | j }|j| jŽ  | ¡  d S r3   )r   r*   r)   Zupdate_traits)r!   r-   r   r   r"   Ú_on_normal_set§   s    zImplicitPlane._on_normal_setc                 C   sj   | j }| d| j¡ | | jd¡ | | jd¡ | | jd¡ | | j¡ | j|fD ]}| | j¡ qTdS )z Wires up all the event handlers.ZInteractionEventr   r   r   N)r   Zadd_observerr@   Zon_trait_changerA   r1   Úrender)r!   r-   r>   r   r   r"   r   ¬   s    ÿzImplicitPlane._connectN)#Ú__name__Ú
__module__Ú__qualname__Ú__version__r   r
   ZImplicitPlaneWidgetr   ZPlaner1   r   r   r   r   r(   r=   r   r)   r   r   Z_widget_groupr   r	   r   r#   r/   r0   r2   r4   r9   r:   r<   r@   rA   r   r   r   r   r"   r      s^   ýû	ÿý
÷
ÿþ 	
r   N)Ú__doc__Z
traits.apir   r   r   r   Ztraitsui.apir   r   r   r	   Ztvtk.apir
   Zmayavi.core.componentr   Zmayavi.core.utilsr   r   r   r   r   r"   Ú<module>   s   