3
îÈ‘[Õ%  ã               @   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   | |kr|S t |dƒr&t| |j|jƒS t |dƒrdx2t|j|jƒD ] \}}t| ||ƒ}|dk	r@|S q@W 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   )ZneedleZhaystackÚobjectÚhÚobjÚr© r   ú`/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/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_noneÚscalarÚvectorFc                s(   t t| ƒjƒ }| j|d< |j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| _ |jdd ƒ}|jdd ƒ}t| j|jƒ | j}tj| |ƒ |d k	r‚x4t|j|ƒD ]$\}}t|||ƒ}|d k	rZ|| _P qZW |d k	rÀx4t|j|ƒD ]$\}}t|||ƒ}	|	d k	r˜|	| _	P q˜W | j
ƒ  || _ d S )NFÚactorÚcontour)Úrunningr    r   r   r	   Ú	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.TFÚDockWindowShellz.name)Úuse_notebookÚ	deletableÚexportÚ	page_namer   Úcustom)ÚnameÚstyleÚ
show_labelÚeditorÚ	resizable)Úshow_labels)r6   )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 r$| j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krdS | jƒ  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_changed)r!   r   r   r   Úupdate_data±   s    zGenericModule.update_datac             C   s’   | j }|dkst| jƒdkr dS |j}| j}| jsz| jd }|g|_x.tdt|ƒƒD ]}|| }||d  g|_qTW d| _| jƒ  | j| j	ƒ dS )z$Sets up the objects in the pipeline.Nr   é   T)
r=   r;   r   Úsourcer   ÚinputsÚranger(   Ú_lut_mode_changedÚlut_mode)r!   r?   Zmy_inputr   ÚfirstÚiÚ	componentr   r   r   r>   ¾   s    
zGenericModule._setup_pipelinec                s’   t t| ƒj||ƒ x>|D ]6}t|jƒdkr4|jj|_| jd krt|t	ƒr|| _qW t| j
ƒdkrldg| j_n| jj| j
d jƒ d| _| jƒ  d S )Nr   ÚnoneF)r   r   Ú_handle_componentsr;   r2   r#   Ú__name__r$   Ú
isinstancer   r   Ú
input_infoÚdatasetsÚcopy_traitsr   r>   )r!   ÚremovedÚaddedrJ   )r#   r   r   rL   Ô   s    




z GenericModule._handle_componentsc             C   sB   | j }|dkrdS |j}|dkr&|j}| jdk	r>| jj|jƒ dS )zStatic traits listener.Nr   )r=   Zscalar_lut_managerZvector_lut_managerr$   Zset_lutZlut)r!   Úvaluer?   Zlmr   r   r   rF   å   s    
zGenericModule._lut_mode_changedc             C   s   | j | jƒ d S )N)rF   rG   )r!   ÚoldÚnewr   r   r   Ú_actor_changedñ   s    zGenericModule._actor_changedc             C   s4   | j dkrdS |rd| j j_n
d| j 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!   rT   r   r   r   Ú$_filled_contours_changed_for_contourô   s    

z2GenericModule._filled_contours_changed_for_contourc             C   s>   x8| j D ].}t|jƒdkrt|jd jƒdkr|jƒ  qW d S )Nr   )r   r;   rD   ÚoutputsÚstart)r!   rJ   r   r   r   r(     s    zGenericModule._start_components)rM   Ú
__module__Ú__qualname__Ú__doc__r   r%   r   r$   r   rG   r   r   r   r+   r:   r<   r@   rA   r>   rL   rF   rW   rZ   r(   Ú__classcell__r   r   )r#   r   r   7   s$   
'	r   N)r_   Ú
traits.apir   r   r   Útraitsui.apir   r   r   r   Zapptools.persistencer	   Zmayavi.core.moduler
   Úmayavi.core.commonr   Zmayavi.components.actorr   r   r   r   r   r   r   Ú<module>   s   