a
    «ˆc•'  ã                   @   s´   d Z ddlmZmZmZm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	lmZ dd
lmZmZ ddlmZ G dd„ deƒZdS )zLA PLOT3D file reader.  This reader does not support a timeseries of
files.

é    )ÚbasenameÚisfileÚexistsÚsplitext)ÚInstanceÚStrÚButton)ÚViewÚGroupÚItemÚ
FileEditor)Útvtk)Ú	PrefixMap)Ú	set_state)ÚFilePath)ÚSource)Úhandle_children_stateÚerror)ÚPipelineInfoc                       sx  e Zd ZdZdZeddd�Zeddd�Zeddd	d
dddddddœ
ddd�Z	edddddœddd�Z
eejdddd�Zed gd!�Zed"ƒZeeed#eƒ d$�ed%eƒ d$�ed&d'd(�ed)d*d(�ed+d,�d-d.�eed/d0dd1�dd d2�dd3�Zeedd4d5�Zeedd6d5�Z‡ fd7d8„Zd9d:„ ZdQd;d<„Zd=d>„ Zd?d@„ ZdAdB„ Z dCdD„ Z!dEdF„ Z"dGdH„ Z#dIdJ„ Z$dKdL„ Z%dMdN„ Z&dOdP„ Z'‡  Z(S )RÚPLOT3DReaderzSA PLOT3D file reader.  This reader does not support a
    timeseries of files.
    r   Ú zthe XYZ file)Údescz
the Q fileéd   én   éx   é‚   éŒ   é�   é™   é£   éª   é¸   )
ÚdensityZpressureZtemperatureZenthalpyzinternal energyzkinetic energyzvelocity magnitudezstagnation energyZentropyZswirlr"   zscalar data attribute to show)Údefault_valuer   éÈ   éÉ   éÊ   éÒ   )ZvelocityZ	vorticityÚmomentumzpressure gradientr(   zvector data attribute to show© FT)ÚargsÚ
allow_noneÚrecordZstructured_grid)ZdatasetszUpdate ReaderÚxyz_file_name)ZeditorÚq_file_nameÚscalars_namezlen(object.q_file_name) > 0)ÚnameZenabled_whenÚvectors_namezlen(object.q_file_name)>0Úupdate_reader)r0   ÚReader)ÚlabelÚreaderZcustom)r0   ÚstyleÚ	resizable)Zshow_labelsr4   )r7   zthe current XYZ file path)r*   r   zthe current Q file pathc                    s(   t t| ƒ ¡ }dD ]}| |d ¡ q|S )N)r/   r1   r-   r.   )Úsuperr   Ú__get_pure_state__Úpop)ÚselfÚdr0   ©Ú	__class__r)   ú_/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/sources/plot3d_reader.pyr9   k   s    zPLOT3DReader.__get_pure_state__c                 C   sŒ   |j j}|jj}t|ƒs0d| }|d7 }t|ƒ‚t| |dgdgd� | j||dd� t| |g d¢d	� t| j|jƒ t| |d
gdgd� d S )NzCould not find file at %s
z)Please move the file there and try again.r5   Ú*)ÚfirstÚignoreF)Ú	configure)ÚchildrenÚxyz_file_pathÚq_file_path)rB   rD   )	rE   Zabs_pthrF   r   ÚIOErrorr   Ú
initializer   rD   )r;   ÚstateZxyz_fnZq_fnÚmsgr)   r)   r?   Ú__set_pure_state__t   s    zPLOT3DReader.__set_pure_state__c                 C   sZ   t |ƒdkr,t|ƒd }|d }t|ƒr,|}|r>| jjdd� || _t |ƒdkrV|| _dS )a  Given an xyz filename and a Q filename which may or may not
        be part of a time series, this initializes the list of files.
        This method need not be called to initialize the data.

        If configure is True, it pops up a UI to configure the
        PLOT3DReader.
        r   z.qÚ	livemodal©ÚkindN)Úlenr   r   r5   Úedit_traitsr-   r.   )r;   r-   r.   rC   ÚbaseZqfr)   r)   r?   rH   ‹   s    zPLOT3DReader.initializec                 C   s,   t | j ¡ ƒdkrd S | j ¡  |  ¡  d S ©Nr   )rO   rE   Úgetr5   ÚupdateÚrender©r;   r)   r)   r?   rT   £   s    
zPLOT3DReader.updatec                 C   s   dS )z+ Return True as the reader has output port.Tr)   rV   r)   r)   r?   Úhas_output_port©   s    zPLOT3DReader.has_output_portc                 C   s   | j jS )z Return the reader output port.)r5   Zoutput_portrV   r)   r)   r?   Úget_output_object­   s    zPLOT3DReader.get_output_objectc                 C   s0   t |ƒdkrd S || j_| j |¡ |  ¡  d S rR   )rO   r5   r-   rE   ÚsetÚ_update_reader_output©r;   Úvaluer)   r)   r?   Ú_xyz_file_name_changed´   s
    z#PLOT3DReader._xyz_file_name_changedc                 C   s0   t |ƒdkrd S || j_| j |¡ |  ¡  d S rR   )rO   r5   r.   rF   rY   rZ   r[   r)   r)   r?   Ú_q_file_name_changed¼   s
    z!PLOT3DReader._q_file_name_changedc                 C   sü   | j }| ¡  |jdkr@zd| j _W n ty6   Y n
0 | ¡  |jdkrxz|jddd� W n tyn   Y n
0 | ¡  |jdkr¨z
d|_W n tyž   Y n
0 | ¡  |jdkrÆ|jdd� | ¡  |jdkràd}t|ƒ d S |g| _d| _	|  
¡ | _d S )Nr   TF)Ú
i_blankingÚbinary_filerL   rM   z�Unable to read file properly. Please check the settings of the reader on the UI and press the "Update Reader" button when done and try again!)r5   rT   Z
error_coder_   ÚAttributeErrorZ	trait_setrP   r   ÚoutputsÚdata_changedÚ	_get_namer0   )r;   ÚrrJ   r)   r)   r?   rZ   Ä   s<    





z"PLOT3DReader._update_reader_outputc                 C   s&   | j | j_| j ¡  |  ¡  d| _d S ©NT)Zscalars_name_r5   Zscalar_function_numberÚmodifiedrT   rc   r[   r)   r)   r?   Ú_scalars_name_changed   s    

z"PLOT3DReader._scalars_name_changedc                 C   s&   | j | j_| j ¡  |  ¡  d| _d S rf   )Zvectors_name_r5   Zvector_function_numberrg   rT   rc   r[   r)   r)   r?   Ú_vectors_name_changed  s    

z"PLOT3DReader._vectors_name_changedc                 C   s   | j  ¡  |  ¡  d| _d S rf   )r5   rg   rZ   Zpipeline_changedrV   r)   r)   r?   Ú_update_reader_fired  s    
z!PLOT3DReader._update_reader_firedc                 C   sV   t | j ¡ ƒ}t | j ¡ ƒ}t| jƒdkr8d||f }nd| }d| jv rR|d7 }|S )z4 Gets the name to display on the tree view.
        r   zPLOT3D:%s, %sz	PLOT3D:%sz[Hidden]z	 [Hidden])r   rE   rS   rF   rO   r.   r0   )r;   Z	xyz_fnameZq_fnameÚretr)   r)   r?   rd     s    
zPLOT3DReader._get_name)r   T))Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__version__r   r-   r.   r   r/   r1   r   r   ZMultiBlockPLOT3DReaderr5   r   Zoutput_infor   r2   r	   r
   r   r   Úviewr   rE   rF   r9   rK   rH   rT   rW   rX   r]   r^   rZ   rh   ri   rj   rd   Ú__classcell__r)   r)   r=   r?   r      s†   ÷
õýû
ÿÿÿù	ÿýòÿ	
<r   N)ro   Úos.pathr   r   r   r   Z
traits.apir   r   r   Ztraitsui.apir	   r
   r   r   Ztvtk.apir   Ztvtk.tvtk_baser   Z"apptools.persistence.state_picklerr   Zapptools.persistence.file_pathr   Zmayavi.core.sourcer   Zmayavi.core.commonr   r   Zmayavi.core.pipeline_infor   r   r)   r)   r)   r?   Ú<module>   s   
