a
    «ˆcž.  ã                   @   s”   d Z ddlmZ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 ddlmZ ddlmZ dd	lmZ G d
d„ deƒZdS )zbA component that provides a selection of poly data source widgets
to be used by various modules.

é    )ÚEventÚInstanceÚListÚTraitÚBool)ÚViewÚGroupÚItemÚInstanceEditor)Útvtk)Ú
PrefixList)Ú	set_state)Úhandle_children_state)Ú	Component)ÚDataSetHelperc                	       s  e Zd ZdZeejdd�Zeg d¢ddd�Z	e
ejdd�Zeejd	d
�ZedƒZedƒZedƒZe
Zeeedddedd�d�ddd�dd�Z‡ f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&‡ fd/d0„Z'‡  Z(S )1ÚSourceWidgetr   T)Úrecord)Úinteractiveúsemi-interactiveúnon-interactiver   z+the speed at which the poly data is updated)Údefault_valueÚdescF© )ÚargsÚwidgetZcustomÚwidget_list)Úname)r   ÚstyleÚ	resizableZeditorzSource Widget)ÚlabelZshow_labels)r   c                    s(   t t| ƒ ¡ }dD ]}| |d ¡ q|S )N)Ú	poly_dataÚ_unpicklingÚ_firstÚ_busy)Úsuperr   Ú__get_pure_state__Úpop)ÚselfÚdÚattr©Ú	__class__r   úb/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/components/source_widget.pyr%   H   s    zSourceWidget.__get_pure_state__c                 C   s@  d| _ t| j|jƒ t| |dgdgd� dd„ | jD ƒ}|jjd }| j| |¡  }| _t| jƒdkr€|  	|| jd j
d ¡ |d	kr�| ¡  t| |dgd
� | ¡  |dkrä|jj|_|jj|_|jj|_| ¡  | | j¡ nJ|dk�r"tj|j|j|j|jdd�}| ¡  | j |j¡ n| | j¡ d| _ |g| _d S )NTr   Ú*)ÚfirstÚignorec                 S   s   g | ]}|j j‘qS r   )r+   Ú__name__©Ú.0Úxr   r   r,   Ú
<listcomp>U   ó    z3SourceWidget.__set_pure_state__.<locals>.<listcomp>Ú
class_namer   ÚPointWidget)r/   ÚPlaneWidgetÚSphereWidget)ÚcenterÚradiusÚtheta_resolutionÚphi_resolutionZlat_long_tessellationF)r!   r   r   r   r   Ú__metadata__ÚindexÚlenÚinputsÚconfigure_inputÚoutputsÚplace_widgetÚupdate_traitsÚoriginÚnormalr:   Zupdate_placementÚget_poly_datar    r   ZSphereSourcer;   r<   r=   ÚupdateZshallow_copyÚoutputÚwidgets)r'   ÚstateÚmZw_c_nameÚwÚsr   r   r,   Ú__set_pure_state__N   s:    



ýzSourceWidget.__set_pure_state__c              	   C   sX   t jddd�t jdd�t  ¡ t jddddd�g}|| _|d | _|D ]}|  |¡ qDdS )	a  Override this method so that it *creates* the 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.  You should also
        set the `actors` attribute up at this point.
        é   é   )r<   r=   F)Úclamp_to_bounds)ÚoutlineZ	x_shadowsZ	y_shadowsZ	z_shadowsr   N)r   r9   Ú
LineWidgetr8   r7   r   r   Ú_connect)r'   ÚsourcesrO   r   r   r,   Úsetup_pipeline}   s    
ÿý
zSourceWidget.setup_pipelinec           	      C   s  t | jƒdkrdS | jd jd }| j}|  ||¡ t| jd jd ƒ}| ¡ }t|ƒ| _| j	rp| 
|¡ d| _	|d |d  |d |d  |d |d  g}t|ƒ}t|ƒD ]<\}}|| d	k r®| jd  }| _d
|_g d¢| |_ qìq®| | j¡ | jg| _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 any of the inputs
        sends a `pipeline_changed` event.
        r   NFé   é   é   é   é   g�íµ ÷Æ°>T)Úz_axisr^   Zy_axis)r@   rA   rC   r   rB   r   Z
get_boundsÚlistÚ_boundsr"   rD   ÚmaxÚ	enumerater   rS   ÚalignrH   r    Zpipeline_changed)	r'   ÚinprN   ZdshÚbÚlZmax_lÚir3   r   r   r,   Úupdate_pipeline—   s,    

.
zSourceWidget.update_pipelinec                 C   s
   d| _ dS )zÌOverride this method so that it flushes the vtk pipeline if
        that is necessary.

        This method is invoked (automatically) when any of the inputs
        sends a `data_changed` event.
        TN)Zdata_changed©r'   r   r   r,   Úupdate_data»   s    zSourceWidget.update_datac                 C   s   | j  | j¡ d S ©N)r   rH   r    ri   r   r   r,   Úupdate_poly_dataÇ   s    zSourceWidget.update_poly_datac           	      C   sî   | j r
d S || jvrZdd„ | jD ƒ}|j}|  |¡ ||v rN|| j| |¡< n| j |¡ | j}|d ur¤| j |¡}| | ¡}d| }d||f }| d||f ¡ t	| j
ƒdkrÖ|  || j
d jd ¡ | | j¡ | | j¡ |g| _d S )Nc                 S   s   g | ]
}|j ‘qS r   r*   )r2   Úor   r   r,   r4   Ò   r5   z0SourceWidget._widget_changed.<locals>.<listcomp>z	%s.widgetz%s.widget_list[%d]z%s = %sr   )r!   r   r+   rV   r?   ÚappendÚrecorderZget_script_idr   r@   rA   rB   rC   rD   r`   Úon_trait_changeÚrenderrK   )	r'   ÚvalueÚclassesZvcro   Úidxr   ÚlhsÚrhsr   r   r,   Ú_widget_changedÍ   s*    


zSourceWidget._widget_changedc                 C   s   |dv r|   ¡  |  ¡  d S )N)r   r   )rl   rq   )r'   rr   r   r   r,   Ú_update_mode_changedé   s    z!SourceWidget._update_mode_changedc                 C   s(   | j s$| jdkr$d| _ |  ¡  d| _ d S )Nr   TF)r#   Úupdate_moderl   )r'   ÚobjÚeventr   r   r,   Ú_on_interaction_eventî   s    z"SourceWidget._on_interaction_eventc                 C   s0   | j s,| jdkr,d| _ |  ¡  |  ¡  d| _ d S )Nr   TF)r#   ry   rq   rl   ri   r   r   r,   Ú_on_widget_trait_changedô   s
    z%SourceWidget._on_widget_trait_changedc                 C   s   | j }| | j¡ | ¡  d S rk   )r   rD   r`   rE   )r'   rN   r   r   r,   Ú_on_alignment_setþ   s    zSourceWidget._on_alignment_setc                 C   sž   |  d| j¡ t|tjƒrF| | jd¡ | | jd¡ | | jd¡ nt|tjƒr`| | jd¡ d}| jdurv| jj	}|  
||¡ | | j¡ | | j¡ dS )z Wires up all the event handlers.ZInteractionEventZnormal_to_x_axisZnormal_to_y_axisZnormal_to_z_axisrc   )rY   rY   rY   N)Zadd_observerr|   Ú
isinstancer   r8   rp   r~   rU   ZsceneÚ
foregroundÚ_setup_widget_colorsr}   rq   )r'   rz   Zfgr   r   r,   rV     s    ÿ
zSourceWidget._connectc                 C   sŒ   |  ¡ }dd„ |D ƒ}dd„ |D ƒ}|D ](}tt||ƒd|ƒ tt||ƒddƒ q(|D ](}tt||ƒddƒ tt||ƒddƒ qV|  ¡  d S )Nc                 S   s    g | ]}d |v rd|vr|‘qS ©ÚpropertyÚselectedr   r1   r   r   r,   r4     s   ÿz5SourceWidget._setup_widget_colors.<locals>.<listcomp>c                 S   s    g | ]}d |v rd|v r|‘qS r‚   r   r1   r   r   r,   r4     s   ÿÚcolorÚ
line_widthr[   )rY   r   r   )Útrait_namesÚsetattrÚgetattrrq   )r'   r   r…   r‡   ÚpropsZ	sel_propsÚpr   r   r,   r�     s    z!SourceWidget._setup_widget_colorsc                 C   s$   | j D ]}|  ||¡ q|  ¡  d S rk   )r   r�   rq   )r'   ÚoldÚnewrN   r   r   r,   Ú_foreground_changed_for_scene&  s    
z*SourceWidget._foreground_changed_for_scenec                    s$   t t| ƒ ||¡ |  d |j¡ d S rk   )r$   r   Ú_scene_changedrŽ   r€   )r'   rŒ   r�   r*   r   r,   r�   ,  s    zSourceWidget._scene_changed))r0   Ú
__module__Ú__qualname__Ú__version__r   r   ZThreeDWidgetr   r   ry   r   ZObjectr   ZPolyDatar    r   r"   r#   r!   r`   r   r   r	   r
   Úviewr%   rP   rX   rh   rj   rl   rw   rx   r|   r}   r~   rV   r�   rŽ   r�   Ú__classcell__r   r   r*   r,   r      sH   	ýÿýû/$
r   N)Ú__doc__Z
traits.apir   r   r   r   r   Ztraitsui.apir   r   r	   r
   Ztvtk.apir   Ztvtk.tvtk_baser   Z"apptools.persistence.state_picklerr   Zmayavi.core.commonr   Zmayavi.core.componentr   Zmayavi.core.utilsr   r   r   r   r   r,   Ú<module>   s   	