a
    «ˆcÕ%  ã                   @   s|   d 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 ddlmZ ddlmZ ddlmZ dd	„ ZG d
d„ deƒZdS )z•
Defines a GenericModule which is a collection of mayavi
filters/components put together.  This is very convenient and useful to
create new modules.
é    )ÚBoolÚEnumÚInstance)ÚItemÚGroupÚViewÚ
ListEditor)Ústate_pickler)ÚModule)Úhandle_children_state)ÚActorc                 C   sh   | |u r|S t |dƒr&t| |j|jƒS t |dƒrdt|j|jƒD ]$\}}t| ||ƒ}|dur>|  S q>dS )ag  
    Find the object which corrsponds to given state instance (`needle`)
    in the given state (`haystack`) and object representing that
    haystack.

    Parameters
    ----------

    `needle` -- The `State` instance to find
    haystack -- The source State in which we are to find the state
    `object` -- the object corresponding to the `haystack`
    ÚfilterÚfiltersN)ÚhasattrÚfind_object_given_stater   Úzipr   )ÚneedleZhaystackÚobjectÚhÚobjÚr© r   ú`/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/modules/generic_module.pyr      s    
þ

r   c                       s¦   e Zd ZdZeddd�Zeedd�ZeddƒZ	e
dƒZ‡ fdd	„Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡ fdd„Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS ) ÚGenericModulea  
    Defines a GenericModule which is a collection of mayavi
    filters/components put together.  This is very convenient and useful
    to create new modules.

    Note that all components including the actor must be passed as a
    list to set the components trait.
    z!mayavi.components.contour.ContourT)Ú
allow_noneZscalarÚvectorFc                    s(   t t| ƒ ¡ }| j|d< | dd ¡ |S )NÚ
componentsÚ_pipeline_ready)Úsuperr   Ú__get_pure_state__r   Úpop)ÚselfÚd©Ú	__class__r   r   r   Y   s    
z GenericModule.__get_pure_state__c           
      C   sÎ   | j }d| _ | dd ¡}| dd ¡}t| j|jƒ | j}t | |¡ |d ur€t|j|ƒD ]&\}}t|||ƒ}|d urX|| _ q€qX|d ur¼t|j|ƒD ]&\}}t|||ƒ}	|	d ur”|	| _	 q¼q”|  
¡  || _ d S )NFÚactorÚcontour)Úrunningr    r   r   r	   Z	set_stater   r   r%   r&   Ú_start_components)
r!   Ústater'   Zactor_stZ
contour_str   ZcstÚcr%   r&   r   r   r   Ú__set_pure_state__`   s*    z GenericModule.__set_pure_state__c              	   C   s6   t ddddd�}tttddd|dd�dd	�dd
�}|S )z0Returns the default traits view for this object.TFZDockWindowShellz.name)Zuse_notebookZ	deletableÚexportZ	page_namer   Zcustom)ÚnameÚstyleZ
show_labelZeditorÚ	resizable)Zshow_labels)r/   )r   r   r   r   )r!   ÚleÚviewr   r   r   Údefault_traits_view‡   s     ýüûúz!GenericModule.default_traits_viewc                 C   s&   t | jƒdkr"| js"|  g | j¡ dS )zSetup the pipeline.r   N)Úlenr   r   Z_components_changed©r!   r   r   r   Úsetup_pipeline™   s    zGenericModule.setup_pipelinec                 C   s$   | j }|du rdS |  ¡  d| _dS )zÎThis method *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.
        NT)Úmodule_managerÚ_setup_pipelineZpipeline_changed)r!   Úmmr   r   r   Úupdate_pipeline¢   s
    zGenericModule.update_pipelinec                 C   s
   d| _ dS )z¼This method does what is necessary when upstream data
        changes.

        This method is invoked (automatically) when any of the inputs
        sends a `data_changed` event.
        TN)Zdata_changedr4   r   r   r   Úupdate_data±   s    zGenericModule.update_datac                 C   sŽ   | j }|du st| jƒdkr dS |j}| j}| jsv| jd }|g|_tdt|ƒƒD ]}|| }||d  g|_qRd| _|  ¡  |  | j	¡ dS )z$Sets up the objects in the pipeline.Nr   é   T)
r6   r3   r   Úsourcer   ÚinputsÚranger(   Ú_lut_mode_changedÚlut_mode)r!   r8   Zmy_inputr   ÚfirstÚiÚ	componentr   r   r   r7   ¾   s    
zGenericModule._setup_pipelinec                    sŽ   t t| ƒ ||¡ |D ]6}t|jƒdkr2|jj|_| jd u rt|t	ƒr|| _qt| j
ƒdkrhdg| j_n| j | j
d j¡ d| _|  ¡  d S )Nr   ÚnoneF)r   r   Ú_handle_componentsr3   r-   r$   Ú__name__r%   Ú
isinstancer   r   Z
input_infoZdatasetsZcopy_traitsr   r7   )r!   ÚremovedÚaddedrC   r#   r   r   rE   Ô   s    


z GenericModule._handle_componentsc                 C   sB   | j }|du rdS |j}|dkr&|j}| jdur>| j |j¡ dS )zStatic traits listener.Nr   )r6   Zscalar_lut_managerZvector_lut_managerr%   Zset_lutZlut)r!   Úvaluer8   Zlmr   r   r   r?   å   s    
zGenericModule._lut_mode_changedc                 C   s   |   | j¡ d S )N)r?   r@   )r!   ÚoldÚnewr   r   r   Ú_actor_changedñ   s    zGenericModule._actor_changedc                 C   s4   | j du rdS |rd| j j_n
d| j j_|  ¡  dS )z”When filled contours are enabled, the mapper should use the
        the cell data, otherwise it should use the default scalar
        mode.
        NZuse_cell_dataÚdefault)r%   ZmapperZscalar_modeÚrender)r!   rJ   r   r   r   Ú$_filled_contours_changed_for_contourô   s    

z2GenericModule._filled_contours_changed_for_contourc                 C   s:   | j D ].}t|jƒdkrt|jd jƒdkr| ¡  qd S )Nr   )r   r3   r=   ÚoutputsÚstart)r!   rC   r   r   r   r(     s
    
ÿzGenericModule._start_components)rF   Ú
__module__Ú__qualname__Ú__doc__r   r&   r   r%   r   r@   r   r   r   r+   r2   r5   r9   r:   r7   rE   r?   rM   rP   r(   Ú__classcell__r   r   r#   r   r   7   s&   ÿ
'	r   N)rU   Z
traits.apir   r   r   Ztraitsui.apir   r   r   r   Zapptools.persistencer	   Zmayavi.core.moduler
   Zmayavi.core.commonr   Zmayavi.components.actorr   r   r   r   r   r   r   Ú<module>   s   