a
    «ˆcm%  ã                   @   s˜   d Z ddlmZ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 )zUA component that allows creates the source for the glyphs and
handle transformation.
é    )ÚInstanceÚListÚTraitÚBoolÚPropertyÚDict)ÚViewÚGroupÚItemÚInstanceEditor)Útvtk)Úcamel2enthought)Ú
PrefixList)Ú	set_state)Úhandle_children_state)Ú	Componentc                       sú   e Zd ZdZeg d¢ddd�Zeejddd�Z	e
d	dd
�Zeeejƒdd�Zeejdd�ZedƒZeeeedd�ƒ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‡ fd!d"„Zd#d$„ Zd%d&„ Zd'd(„ Z d)d*„ Z!‡  Z"S )+ÚGlyphSourceé   )ÚheadÚtailÚcenterr   z#position of glyph w.r.t. data point)Údefault_valueÚdescFT)Ú
allow_noneÚrecordz the glyph sources to select from)r   r   )r   © )ÚargsÚglyph_position)ÚnameÚglyph_sourceZcustomÚ
glyph_list)r   ÚstyleÚ	resizableZeditorzGlyph Source)ÚlabelZshow_labels)r"   c                    s(   t t| ƒ ¡ }dD ]}| |d ¡ q|S )N)Ú	_updatingr    )Úsuperr   Ú__get_pure_state__Úpop)ÚselfÚdÚattr©Ú	__class__r   úa/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/components/glyph_source.pyr&   Q   s    zGlyphSource.__get_pure_state__c           	      C   s°   d|v r$t | |dgdgd� dg}nZ| j}| j}t||jƒ t||jƒD ].\}}t|jjƒ}||vrl|||< t ||ƒ qHdg}|jj	d }t|ƒ}| j| | _t | ||d� d S )NÚ
glyph_dictÚ*)ÚfirstÚignorer    Ú
class_name)r1   )
r   r.   r    r   Úzipr   r,   Ú__name__r   Ú__metadata__)	r(   Ústater1   ÚgdÚglÚgZgsr   Zg_namer   r   r-   Ú__set_pure_state__W   s     zGlyphSource.__set_pure_state__c                 C   s   t  ¡ | j_| jd | _d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.
        Úglyph_source2dN)r   Z	TransformÚ_trfmÚ	transformr.   r   ©r(   r   r   r-   Úsetup_pipelineq   s    zGlyphSource.setup_pipelinec                 C   s   |   | j¡ 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.
        TN)Ú_glyph_position_changedr   Zpipeline_changedr>   r   r   r-   Úupdate_pipeline‚   s    zGlyphSource.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_changedr>   r   r   r-   Úupdate_dataŒ   s    zGlyphSource.update_datac                    s   | j stt| ƒ ¡  d S )N)r$   r%   r   Úrenderr>   r+   r   r-   rC   •   s    zGlyphSource.renderc                 C   sÈ   | j r
d S | j}t|jjƒ}|| ¡ vr0|||< d| _ | j}|d urt| | ¡}d| }d||f }| d||f ¡ |jj}|dkrŽ|g| _	n|  
| j|¡ | jg| _	| | j¡ d| _ |  | j¡ d S )NTz%s.glyph_sourcez%s.glyph_dict[%r]z%s = %sÚGlyphSource2DF)r$   r.   r   r,   r4   ÚvaluesÚrecorderZget_script_idr   ÚoutputsZconfigure_inputr<   Zon_trait_changerC   r@   r   )r(   Úvaluer7   Z	value_clsrF   r   ÚlhsÚrhsr   r   r-   Ú_glyph_source_changedœ   s*    


z!GlyphSource._glyph_source_changedc                 C   s~  | j r
d S d| _ | jj}| ¡  | j}|jj}|dkrB|jd }n>|dkrX|j d }n(|dkrl|jd }n|dkr||j	}nd}|dkrÐ|d	kr˜d
|_
n6|dkr¢n,|dkr¸d|df|_
nt|dƒrÎ|ddf|_
nˆ|dk�r.|d	krêd|_
nB|dk�r| ddd¡ n(|dk�rd| df|_
n| ddf|_
n*|dk�rH| ddd¡ n|dk�rXd|_
|dk�rl| d¡ d| _ |  ¡  d S )NTÚ
CubeSourceg       @ÚCylinderSourceÚ
ConeSourceÚSphereSourceç      ð?r   rD   )g      à?ç        rQ   ÚArrowSourcer   rQ   r   r   )ç      à¿rQ   rQ   éÿÿÿÿrS   ÚAxes)rQ   rQ   rQ   éZ   F)r$   r<   r=   Úidentityr   r,   r4   Zx_lengthÚheightÚradiusr   ÚhasattrÚ	translateZrotate_zrC   )r(   rH   Útrr9   r   Z	tr_factorr   r   r-   r@   »   sR    







z#GlyphSource._glyph_position_changedc                    s<   g d¢}| j ‰ ˆ D ]}||vr| |¡ q‡ fdd„|D ƒS )N©r;   Zarrow_sourceZcone_sourceZcylinder_sourceZsphere_sourceZcube_sourceZaxesc                    s   g | ]}ˆ | ‘qS r   r   )Ú.0Úkey©r7   r   r-   Ú
<listcomp>ù   ó    z/GlyphSource._get_glyph_list.<locals>.<listcomp>)r.   Úappend)r(   Úorderr_   r   r`   r-   Ú_get_glyph_listï   s    zGlyphSource._get_glyph_listc              	   C   sN   t jddd�t  ¡ t jdddd�t jddd	d�t  ¡ t  ¡ t jd
d�dœ}|S )NZarrowF)Z
glyph_typeZfilledrP   gš™™™™™É?é   )rX   rY   Ú
resolutiong333333Ã?é
   r   )Z	symmetricr]   )r   rD   rR   rN   rM   rO   rL   rU   )r(   r9   r   r   r-   Ú_glyph_dict_defaultû   s    ÿÿÿ
÷
zGlyphSource._glyph_dict_default)#r4   Ú
__module__Ú__qualname__Ú__version__r   r   r   r   ZObjectr   r   r.   r   r   r    ZTransformFilterr<   r   r$   r   r	   r
   r   Úviewr&   r:   r?   rA   rB   rC   rK   r@   re   ri   Ú__classcell__r   r   r+   r-   r      sN   ýÿüøþô
	4r   N)Ú__doc__Z
traits.apir   r   r   r   r   r   Ztraitsui.apir   r	   r
   r   Ztvtk.apir   Ztvtk.commonr   Ztvtk.tvtk_baser   Z"apptools.persistence.state_picklerr   Zmayavi.core.commonr   Zmayavi.core.componentr   r   r   r   r   r-   Ú<module>   s    