3
îÈ‘[Ÿ  ã               @   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 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A grid plane component.

é    )ÚInstanceÚEnumÚIntÚRange)ÚViewÚGroupÚItem)Útvtk)Ústate_pickler)Ú	Component)Úerrorc             C   s.   | j }d|d d d|d d d|d d gS )z*Get the extents from the given input.
    r   é   é   )Ú
dimensions)ÚinpÚd© r   ú_/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/mayavi/components/grid_plane.pyÚ_get_extent   s    r   c                   sÐ   e Zd ZdZeejƒZeddddd�Z	e
dddd	d
d�ZedƒZedƒZeeedd�eddd�ƒƒ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‡  ZS )*Ú	GridPlaner   ÚxÚyÚzz+specifies the axis normal to the grid plane)ÚdescÚ_lowÚ_highTF)ÚvalueÚlowÚhighÚ	enter_setÚauto_seti'  Úaxis)ÚnameÚpositionz	_high > 0)r"   Úenabled_whenc                s,   t t| ƒjƒ }xdD ]}|j|d ƒ qW |S )NÚplaner   r   )r%   r   r   )Úsuperr   Ú__get_pure_state__Úpop)Úselfr   r"   )Ú	__class__r   r   r'   E   s    
zGridPlane.__get_pure_state__c             C   s   t j| |ƒ | j| jƒ d S )N)r
   Ú	set_stateÚ_position_changedr#   )r)   Ústater   r   r   Ú__set_pure_state__M   s    zGridPlane.__set_pure_state__c             C   s   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.
        Nr   )r)   r   r   r   Úsetup_pipelineT   s    zGridPlane.setup_pipelinec             C   s  t | jƒdkrdS | jd jƒ }d}|jdƒr8tjƒ }nL|jdƒsL|jdƒrVtjƒ }n.|jdƒrjtjƒ }nd|j }t	|ƒ t
|ƒ‚| j|| jd ƒ || _| jjƒ  |g| _| jƒ  | jƒ  tt|ƒƒ}dd	„ t|ddd
… |ddd
… ƒD ƒ}|jdƒdk�rdddg|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 the input fires a
        `pipeline_changed` event.
        r   NÚvtkStructuredGridÚvtkStructuredPointsÚvtkImageDataÚvtkRectilinearGridz8The GridPlane component does not support the %s dataset.c             S   s   g | ]\}}|| ‘qS r   r   )Ú.0r   r   r   r   r   ú
<listcomp>�   s    z-GridPlane.update_pipeline.<locals>.<listcomp>r   r   r   r   r   )ÚlenÚinputsZget_output_datasetÚis_ar	   ZStructuredGridGeometryFilterZImageDataGeometryFilterZRectilinearGridGeometryFilterÚ
class_namer   Ú	TypeErrorÚconfigure_connectionr%   ÚupdateÚoutputsÚ_update_limitsÚ_update_extentsÚlistr   ÚzipÚcountÚindexr!   )r)   Úinputr%   ÚmsgÚextentsÚdiffr   r   r   Úupdate_pipelinea   s0    





(zGridPlane.update_pipelinec             C   s   | j ƒ  | jƒ  d| _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.
        TN)r>   r?   Údata_changed)r)   r   r   r   Úupdate_data…   s    zGridPlane.update_datac             C   s   dS )z The filter has an output port.Tr   )r)   r   r   r   Úhas_output_port‘   s    zGridPlane.has_output_portc             C   s   | j jS )z Returns the output port.)r%   Úoutput_port)r)   r   r   r   Úget_output_object•   s    zGridPlane.get_output_objectc             C   s   ddddœ| j  S )Nr   r   r   )r   r   r   )r!   )r)   r   r   r   Ú_get_axis_indexœ   s    zGridPlane._get_axis_indexc             C   sp   | j j}tt|ƒƒ}| j}| jƒ }||d| < ||d| d < y| j j|ƒ W n tk
rj   || j _Y nX d S )Nr   r   )	r%   rD   r@   r   r#   rN   Z
set_extentÚAttributeErrorÚextent)r)   r   rF   Úposr!   r   r   r   r?   Ÿ   s    zGridPlane._update_extentsc             C   sB   t | jjƒ}| jƒ }t| j|d| d  ƒ}|d| d  | _|S )Nr   r   )r   r%   rD   rN   Úminr#   r   )r)   rF   r!   rQ   r   r   r   r>   «   s
    zGridPlane._update_limitsc             C   s>   t | jƒdkrd S | jƒ }| j|kr4| jƒ  d| _n|| _d S )Nr   T)r6   r7   r>   r#   r?   rI   )r)   ÚvalrQ   r   r   r   Ú_axis_changed²   s    
zGridPlane._axis_changedc             C   s$   t | jƒdkrd S | jƒ  d| _d S )Nr   T)r6   r7   r?   rI   )r)   rS   r   r   r   r,   ¼   s    zGridPlane._position_changed) Ú__name__Ú
__module__Ú__qualname__Ú__version__r   r	   ÚObjectr%   r   r!   r   r#   r   r   r   r   r   r   Úviewr'   r.   r/   rH   rJ   rK   rM   rN   r?   r>   rT   r,   Ú__classcell__r   r   )r*   r   r      s,   

$
r   N)Ú__doc__Ú
traits.apir   r   r   r   Útraitsui.apir   r   r   Útvtk.apir	   Zapptools.persistencer
   Zmayavi.core.componentr   Úmayavi.core.commonr   r   r   r   r   r   r   Ú<module>   s   
