3
îÈ‘[÷'  ã               @   s°   d Z ddlmZmZmZmZ ddl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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)ÚTraitÚInstanceÚStrÚTraitPrefixMapÚButton)ÚViewÚGroupÚItemÚ
FileEditor)Útvtk)Ú	set_state)ÚFilePath)ÚSource)Úhandle_children_stateÚerror)ÚPipelineInfoc                   s€  e Zd ZdZdZeddd�Zeddd�Zede	dd	d
ddddddddœ
ƒdd�Z
ede	dddddœƒdd�Zeejf 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-d.dd/�dd d0�dd1�Zeef d2d3�Zeef d4d3�Z‡ fd5d6„Zd7d8„ ZdOd9d:„Zd;d<„ Zd=d>„ Z d?d@„ Z!dAdB„ Z"dCdD„ Z#dEdF„ Z$dGdH„ Z%dIdJ„ Z&dKdL„ Z'dMdN„ Z(‡  Z)S )PÚPLOT3DReaderzSA PLOT3D file reader.  This reader does not support a
    timeseries of files.
    r   Ú zthe XYZ file)Údescz
the Q fileÚdensityéd   én   éx   é‚   éŒ   é�   é™   é£   éª   é¸   )
r   ZpressureZtemperatureZenthalpyzinternal energyzkinetic energyzvelocity magnitudezstagnation energyÚentropyZswirlzscalar data attribute to showÚmomentuméÈ   éÉ   éÊ   éÒ   )ZvelocityÚ	vorticityr%   zpressure gradientzvector data attribute to showFT)ÚargsÚ
allow_noneÚrecordÚstructured_grid)ÚdatasetszUpdate ReaderÚxyz_file_name)ÚeditorÚq_file_nameÚscalars_namezlen(object.q_file_name) > 0)ÚnameÚenabled_whenÚvectors_namezlen(object.q_file_name)>0Úupdate_reader)r4   ÚReader)ÚlabelÚreaderÚcustom)r4   ÚstyleÚ	resizable)Úshow_labelsr9   )r=   zthe current XYZ file path)r+   r   zthe current Q file pathc                s,   t t| ƒjƒ }xdD ]}|j|d ƒ qW |S )Nr3   r6   r0   r2   )r3   r6   r0   r2   )Úsuperr   Ú__get_pure_state__Úpop)ÚselfÚdr4   )Ú	__class__© ú_/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/mayavi/sources/plot3d_reader.pyr@   j   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| |dd	d
g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.r:   Ú*)ÚfirstÚignoreF)Ú	configureÚchildrenÚxyz_file_pathÚq_file_path)rI   )	rL   Úabs_pthrM   r   ÚIOErrorr   Ú
initializer   rK   )rB   ÚstateZxyz_fnZq_fnÚmsgrE   rE   rF   Ú__set_pure_state__s   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   r:   Úedit_traitsr0   r2   )rB   r0   r2   rJ   ÚbaseZqfrE   rE   rF   rP   Š   s    zPLOT3DReader.initializec             C   s,   t | jjƒ ƒdkrd S | jjƒ  | jƒ  d S )Nr   )rV   rL   Úgetr:   ÚupdateÚrender)rB   rE   rE   rF   rZ   ¢   s    
zPLOT3DReader.updatec             C   s   dS )z+ Return True as the reader has output port.TrE   )rB   rE   rE   rF   Úhas_output_port¨   s    zPLOT3DReader.has_output_portc             C   s   | j jS )z Return the reader output port.)r:   Úoutput_port)rB   rE   rE   rF   Úget_output_object¬   s    zPLOT3DReader.get_output_objectc             C   s0   t |ƒdkrd S || j_| jj|ƒ | jƒ  d S )Nr   )rV   r:   r0   rL   ÚsetÚ_update_reader_output)rB   ÚvaluerE   rE   rF   Ú_xyz_file_name_changed³   s
    z#PLOT3DReader._xyz_file_name_changedc             C   s0   t |ƒdkrd S || j_| jj|ƒ | jƒ  d S )Nr   )rV   r:   r2   rM   r_   r`   )rB   ra   rE   rE   rF   Ú_q_file_name_changed»   s
    z!PLOT3DReader._q_file_name_changedc             C   s  | j }|jƒ  |jdkrByd| j _W n tk
r8   Y n
X |jƒ  |jdkr|y|jddd� W n tk
rr   Y n
X |jƒ  |jdkr®y
d|_W n tk
r¤   Y n
X |jƒ  |jdkrÌ|jdd� |jƒ  |jdkræd}t|ƒ d S |g| _d| _	| j
ƒ | _d S )Nr   TF)Ú
i_blankingÚbinary_filerT   )rU   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!)r:   rZ   Z
error_coderd   ÚAttributeErrorÚ	trait_setrW   r   ÚoutputsÚdata_changedÚ	_get_namer4   )rB   ÚrrR   rE   rE   rF   r`   Ã   s<    





z"PLOT3DReader._update_reader_outputc             C   s&   | j | j_| jjƒ  | jƒ  d| _d S )NT)Zscalars_name_r:   Zscalar_function_numberÚmodifiedrZ   ri   )rB   ra   rE   rE   rF   Ú_scalars_name_changedÿ   s    

z"PLOT3DReader._scalars_name_changedc             C   s&   | j | j_| jjƒ  | jƒ  d| _d S )NT)Zvectors_name_r:   Zvector_function_numberrl   rZ   ri   )rB   ra   rE   rE   rF   Ú_vectors_name_changed  s    

z"PLOT3DReader._vectors_name_changedc             C   s   | j jƒ  | jƒ  d| _d S )NT)r:   rl   r`   Zpipeline_changed)rB   rE   rE   rF   Ú_update_reader_fired  s    
z!PLOT3DReader._update_reader_firedc             C   sV   t | jjƒ ƒ}t | jjƒ ƒ}t| jƒdkr8d||f }nd| }d| jk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   rL   rY   rM   rV   r2   r4   )rB   Z	xyz_fnameZq_fnameÚretrE   rE   rF   rj     s    
zPLOT3DReader._get_name)r   T)*Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__version__r   r0   r2   r   r	   r3   r6   r   r   ZMultiBlockPLOT3DReaderr:   r   Úoutput_infor
   r7   r   r   r   r   Úviewr   rL   rM   r@   rS   rP   rZ   r\   r^   rb   rc   r`   rm   rn   ro   rj   Ú__classcell__rE   rE   )rD   rF   r      sn   
	
<r   N)rt   Úos.pathr   r   r   r   Ú
traits.apir   r   r   r	   r
   Útraitsui.apir   r   r   r   Útvtk.apir   Ú"apptools.persistence.state_picklerr   Zapptools.persistence.file_pathr   Zmayavi.core.sourcer   Úmayavi.core.commonr   r   Úmayavi.core.pipeline_infor   r   rE   rE   rE   rF   Ú<module>   s   