a
    «ˆcK'  ã                   @   sp   d Z ddlZddl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 G d	d
„ d
e
ƒZdS )zA simple actor component.

é    N)ÚInstanceÚBoolÚEnum)Útvtk)ÚDelegatesTo)Ú	Component)ÚSource)Úget_new_outputc                       s2  e Zd ZdZeejdd�Zeejdd�Z	eej
dd�Zeddd�ZeeƒZeejdd�Zeddd	d
dd�Zeejdd�Zeejƒ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$‡ fd'd(„Z%d)d*„ Z&d+d,„ Z'd-d.„ Z(d/d0„ Z)d1d2„ Z*d3d4„ Z+‡  Z,S )5ÚActorr   T)ÚrecordFzif texturing is enabled)ÚdescÚnoneÚcylinderÚsphereÚplanez%the mode for texture coord generation)Ú
allow_nonec                    s(   t t| ƒ ¡ }dD ]}| |d ¡ q|S )N)ÚtextureÚtexture_source_objectÚenable_textureÚtcoord_generator_modeÚtcoord_generator)Úsuperr
   Ú__get_pure_state__Úpop)ÚselfÚdÚattr©Ú	__class__© úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/components/actor.pyr   ?   s    zActor.__get_pure_state__c                 C   s0   t jdd�| _t  ¡ | _| jj| _t  ¡ | _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.
        é   )Zuse_lookup_table_scalar_rangeN)r   ZPolyDataMapperÚmapperr
   ÚactorÚpropertyÚTexturer   ©r   r   r   r    Úsetup_pipelineK   s    

zActor.setup_pipelinec                 C   sd   t | jƒdks"t | jd jƒdkr&dS | jd jd }|du rBdS |  |¡ |  | j¡ |  ¡  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   N)ÚlenÚinputsÚoutputsÚ_connect_mapperÚ_tcoord_generator_mode_changedr   Úrender)r   Úinputr   r   r    Úupdate_pipeline[   s    ÿ
zActor.update_pipelinec                 C   sZ   ddl m} ddlm} | jd }t||ƒs6t||ƒrD| j d¡ n
| j ¡  |  ¡  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.
        r   )ÚOutline)ÚGlyphN)	Zmayavi.modules.outliner0   Zmayavi.components.glyphr1   r)   Ú
isinstancer"   Úupdater-   )r   r0   r1   r.   r   r   r    Úupdate_datan   s    

zActor.update_datac                 C   s   || j _|j| j _dS )zSet the Lookup table to use.N)r"   Úlookup_tableZtable_rangeZscalar_range)r   Zlutr   r   r    Úset_lutƒ   s    zActor.set_lutc                 C   s(   |d ur|j | jdd� |  | j¡ d S )NT©Úremove)Úon_trait_changer-   ©r   ÚoldÚnewr   r   r    Ú_setup_handlersŽ   s    zActor._setup_handlersc                 C   s,   t |ƒ}| d¡r$| j}|j|_|S |S d S )NZvtkCompositeDataSet)r	   Úis_aÚcomp_data_geom_filterZoutput_portÚinput_connection)r   r.   ZdoZcdgfr   r   r    Ú_get_correct_input“   s    
zActor._get_correct_inputc                 C   s   t  ¡ S ©N)r   ÚCompositeDataGeometryFilterr&   r   r   r    Ú_comp_data_geom_filter_defaultœ   s    z$Actor._comp_data_geom_filter_defaultc                 C   s(   |d u rd S |   |¡}|  | j|¡ d S rB   )rA   Zconfigure_inputr"   )r   r.   Úinpr   r   r    r+   Ÿ   s    
zActor._connect_mapperc                 C   sx   |   ||¡ |d ur |  |j¡ t| jƒdkrXt| jd jƒdkrX|  | jd jd ¡ | j}|d url||_|  	¡  d S )Nr   )
r=   r6   r5   r(   r)   r*   r+   r#   r"   r-   ©r   r;   r<   r#   r   r   r    Ú_mapper_changed¥   s    "zActor._mapper_changedc                 C   s@   |   ||¡ | j}|d ur ||_| j}|d ur4||_|g| _d S rB   )r=   r"   r$   Zactors)r   r;   r<   r"   Úpropr   r   r    Ú_actor_changed´   s    zActor._actor_changedc                 C   s&   |   ||¡ | j}||jur"||_d S rB   )r=   r#   r$   rF   r   r   r    Ú_property_changedÂ   s    
zActor._property_changedc                 C   s   || j _|  ¡  d S rB   )r$   Úcolorr-   r:   r   r   r    Ú_foreground_changed_for_sceneÊ   s    z#Actor._foreground_changed_for_scenec                    s$   t t| ƒ ||¡ |  d |j¡ d S rB   )r   r
   Ú_scene_changedrL   Z
foregroundr:   r   r   r    rM   Ï   s    zActor._scene_changedc                 C   s2   | j d u rd | j_d S |r&| j| j_nd | j_d S rB   )r   r#   r   )r   Úvaluer   r   r    Ú_enable_texture_changedÓ   s    
zActor._enable_texture_changedc                 C   s0   |d u rdS t |tƒsdS | ¡  d¡r,dS dS )NFZvtkImageDataT)r2   r   Zget_output_datasetr>   )r   Úsourcer   r   r    Ú_can_object_give_image_dataÜ   s    
z!Actor._can_object_give_image_datac                 C   s2   |   | j¡r(|  | j| j¡ | j| j_nd | _d S rB   )rQ   r   Úconfigure_connectionr   r#   r&   r   r   r    Ú_change_texture_inputå   s    ÿzActor._change_texture_inputc                 C   s^   |d ur|j | jddd� |d ur0|  | jd¡ |d urB|  ¡  nd | j_d | j_d | j_d S )NZpipeline_changedTr7   )r9   rS   r#   r   r.   r@   r:   r   r   r    Ú_texture_source_object_changedî   s    þÿ
z$Actor._texture_source_object_changedc                 C   sB   | j }|d ur6|jd us"|jd ur6||_| j | j¡ |  ¡  d S rB   )r#   r.   r@   r   r9   r-   )r   rN   r#   r   r   r    Ú_texture_changedþ   s    ÿzActor._texture_changedc                 C   sà   | j }t|ƒdks$t|d jƒdkr(d S | j}|d urF|j| jdd� |dkrjd | _|  |d jd ¡ nPtjtj	tj
dœ}|| ƒ }|| _|  |d jd ¡}|  ||¡ |  | j|¡ | j}|d urÔ| | j¡ |  ¡  d S )Nr   Tr7   r   )r   r   r   )r)   r(   r*   r   r9   r-   r+   r   ZTextureMapToCylinderZTextureMapToSphereZTextureMapToPlanerA   rR   r"   )r   rN   rE   Zold_tgZtg_dictÚtgZactual_inputr   r   r    r,     s0    ÿþ
z$Actor._tcoord_generator_mode_changed)-Ú__name__Ú
__module__Ú__qualname__Ú__version__r   r   ZMapperr"   r
   r#   ZPropertyr$   r   r   r   r   r%   r   r   r   ZObjectr   rC   r?   r   r'   r/   r4   r6   r=   rA   rD   r+   rG   rI   rJ   rL   rM   rO   rQ   rS   rT   rU   r,   Ú__classcell__r   r   r   r    r
      s@   
ÿ
				
r
   )Ú__doc__ZvtkZ
traits.apir   r   r   Ztvtk.apir   r   Zmayavi.core.componentr   Zmayavi.core.sourcer   Zmayavi.core.utilsr	   r
   r   r   r   r    Ú<module>   s   