3
ÌœŸWî.  ã               @   sh   d 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 G dd„ deƒZG dd„ deƒZd	S )
zò
TODO:

 * We need a cleaner way to manipulate the camera  and other things as a model.
   The current approach will be far from perfect but should work.

Caveats:

 * You can't have multiple views of the model.  This will not be supported.

é    )ÚDictÚEventÚInstanceÚListÚProperty)ÚViewÚGroupÚItemÚInstanceEditor)Ú	TVTKScenec               @   s   e Zd ZdS )ÚSceneModelErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   úZ/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/tvtk/pyface/scene_model.pyr      s   r   c                   sð  e Zd ZeZeƒ Zeƒ Ze	e
ƒZeƒ Zeƒ Zeƒ ZeZeedd�edd�ddd�Zeeeedd�edd�ed	d�ed
d�edd�edd�edd�edd�edd�ƒ	eedddeeeƒd�dd�ƒdd�eeddeƒ dd�dd�ƒZeƒ ZdX‡ fdd„	Zdd„ Zd d!„ Zd"d#„ ZeZeZdYd$d%„Zd&d'„ Zd(d)„ Z dZd*d+„Z!d,d-„ Z"d.d/„ Z#d0d1„ Z$d2d3„ Z%d[d4d5„Z&d6d7„ Z'd8d9„ Z(d:d;„ Z)d\d>d?„Z*d@dA„ Z+d]dBdC„Z,dDdE„ Z-dFdG„ Z.dHdI„ Z/dJdK„ Z0dLdM„ Z1dNdO„ Z2dPdQ„ Z3dRdS„ Z4dTdU„ Z5dVdW„ Z6‡  Z7S )^Ú
SceneModelZstereo_render)ÚnameZstereo_typeTzStereo rendering)Úshow_borderÚlabelÚ
backgroundÚ
foregroundZparallel_projectionÚdisable_renderZoff_screen_renderingZjpeg_qualityZjpeg_progressiveÚmagnificationZanti_aliasing_framesZrender_windowÚcustomzobject.stereo)ÚviewF)r   ÚstyleÚvisible_whenÚeditorÚ
show_labelÚScene)r   Úlight_manager)r   r   r   r   ZLightsNc                s   t t| ƒjf |Ž d| _dS )z Initializes the object. N)Úsuperr   Ú__init__Úcontrol)ÚselfÚparentÚtraits)Ú	__class__r   r   r#   i   s    zSceneModel.__init__c             C   s
   d| _ dS )zf Force the scene to be rendered. Nothing is done if the
        `disable_render` trait is set to True.TN)Ú	do_render)r%   r   r   r   Úrendert   s    zSceneModel.renderc             C   s(   t |dƒr| jj|ƒ n| jj|ƒ dS )zJ Adds a single actor or a tuple or list of actors to the
        renderer.Ú__iter__N)ÚhasattrÚ
actor_listÚextendÚappend)r%   Úactorsr   r   r   Ú
add_actorsz   s    
zSceneModel.add_actorsc             C   s8   | j }t|dƒr*x"|D ]}|j|ƒ qW n
|j|ƒ dS )zO Removes a single actor or a tuple or list of actors from
        the renderer.r+   N)r-   r,   Úremove)r%   r0   Z	my_actorsZactorr   r   r   Úremove_actors‚   s
    

zSceneModel.remove_actorsc             C   s6   t |dƒs|g}x|D ]}|| j|< qW | j|ƒ dS )z&Adds widgets to the renderer.
        r+   N)r,   Úenabled_infor1   )r%   ÚwidgetsÚenabledÚwidgetr   r   r   Úadd_widgets�   s
    

zSceneModel.add_widgetsc             C   s4   t |dƒs|g}| j|ƒ x|D ]}| j|= q W dS )z"Removes widgets from the renderer.r+   N)r,   r3   r4   )r%   r5   r7   r   r   r   Úremove_widgets™   s
    


zSceneModel.remove_widgetsc             C   s   | j dk	r| j jƒ  dS )z1Reset the camera so everything in the scene fits.N)Úscene_editorÚ
reset_zoom)r%   r   r   r   r;   ¡   s    
zSceneModel.reset_zoomc             K   s   | j ƒ  | jj||f|Ž dS )aw  Saves rendered scene to one of several image formats
        depending on the specified extension of the filename.

        If an additional size (2-tuple) argument is passed the window
        is resized to the specified size in order to produce a
        suitably sized output image.  Please note that when the window
        is resized, the window may be obscured by other widgets and
        the camera zoom is not reset which is likely to produce an
        image that does not reflect what is seen on screen.

        Any extra keyword arguments are passed along to the respective
        image format's save method.
        N)Ú_check_scene_editorr:   Úsave)r%   Ú	file_nameÚsizeÚkw_argsr   r   r   r=   ¦   s    zSceneModel.savec             C   s   | j ƒ  | jj|ƒ dS )zqSaves the rendered scene to a rasterized PostScript image.
        For vector graphics use the save_gl2ps method.N)r<   r:   Úsave_ps)r%   r>   r   r   r   rA   ·   s    zSceneModel.save_psc             C   s   | j ƒ  | jj|ƒ dS )zSave to a BMP image file.N)r<   r:   Úsave_bmp)r%   r>   r   r   r   rB   ½   s    zSceneModel.save_bmpc             C   s   | j ƒ  | jj|ƒ dS )zSave to a TIFF image file.N)r<   r:   Ú	save_tiff)r%   r>   r   r   r   rC   Â   s    zSceneModel.save_tiffc             C   s   | j ƒ  | jj|ƒ dS )zSave to a PNG image file.N)r<   r:   Úsave_png)r%   r>   r   r   r   rD   Ç   s    zSceneModel.save_pngc             C   s   | j ƒ  | jj|||ƒ dS )z§Arguments: file_name if passed will be used, quality is the
        quality of the JPEG(10-100) are valid, the progressive
        arguments toggles progressive jpegs.N)r<   r:   Úsave_jpg)r%   r>   ÚqualityZprogressiver   r   r   rE   Ì   s    zSceneModel.save_jpgc             C   s   | j ƒ  | jj|ƒ dS )zSave to an OpenInventor file.N)r<   r:   Úsave_iv)r%   r>   r   r   r   rG   Ó   s    zSceneModel.save_ivc             C   s   | j ƒ  | jj|ƒ dS )zSave to a VRML file.N)r<   r:   Ú	save_vrml)r%   r>   r   r   r   rH   Ø   s    zSceneModel.save_vrmlc             C   s   | j ƒ  | jj|ƒ dS )zHSaves the scene to a Geomview OOGL file. Requires VTK 4 to
        work.N)r<   r:   Ú	save_oogl)r%   r>   r   r   r   rI   Ý   s    zSceneModel.save_ooglr   ç      ð?c             C   s   | j ƒ  | jj||||ƒ dS )a  Save scene to a RenderMan RIB file.

        Keyword Arguments:

        file_name -- File name to save to.

        bg -- Optional background option.  If 0 then no background is
        saved.  If non-None then a background is saved.  If left alone
        (defaults to None) it will result in a pop-up window asking
        for yes/no.

        resolution -- Specify the resolution of the generated image in
        the form of a tuple (nx, ny).

        resfactor -- The resolution factor which scales the resolution.
        N)r<   r:   Úsave_rib)r%   r>   ÚbgÚ
resolutionZ	resfactorr   r   r   rK   ã   s    zSceneModel.save_ribc             C   s   | j ƒ  | jj|ƒ dS )a  Save scene to a Wavefront OBJ file.  Two files are
        generated.  One with a .obj extension and another with a .mtl
        extension which contains the material proerties.

        Keyword Arguments:

        file_name -- File name to save to
        N)r<   r:   Úsave_wavefront)r%   r>   r   r   r   rN   ÷   s    	zSceneModel.save_wavefrontc             C   s   | j ƒ  | jj||ƒ dS )a  Save scene to a vector PostScript/EPS/PDF/TeX file using
        GL2PS.  If you choose to use a TeX file then note that only
        the text output is saved to the file.  You will need to save
        the graphics separately.

        Keyword Arguments:

        file_name -- File name to save to.

        exp -- Optionally configured vtkGL2PSExporter object.
        Defaults to None and this will use the default settings with
        the output file type chosen based on the extention of the file
        name.
        N)r<   r:   Ú
save_gl2ps)r%   r>   Úexpr   r   r   rO     s    zSceneModel.save_gl2psc             C   s   | j ƒ  | jj|ƒ d S )N)r<   r:   Úsave_povray)r%   r>   r   r   r   rQ     s    zSceneModel.save_povrayc             C   s   | j ƒ  | jjtƒ d S )N)r<   r:   Úsave_x3dr>   )r%   Úfilenamer   r   r   rR     s    zSceneModel.save_x3dc             C   s   | j ƒ  | jjƒ S )z!Return size of the render window.)r<   r:   Úget_size)r%   r   r   r   rT     s    zSceneModel.get_sizec             C   s   | j ƒ  | jj|ƒ dS )zSet the size of the window.N)r<   r:   Úset_size)r%   r?   r   r   r   rU   "  s    zSceneModel.set_sizec             C   s$   | j dk	r | j j||||||ƒ dS )z Used internally to set the view.N)r:   Ú_update_view)r%   ÚxÚyÚzÚvxÚvyÚvzr   r   r   rV   '  s    
zSceneModel._update_viewc             C   s   | j d krd}t|ƒ‚d S )Nzø
            This method requires that there be an active scene editor.
            To do this, you will typically need to invoke::
              object.edit_traits()
            where object is the object that contains the SceneModel.
            )r:   r   )r%   Úmsgr   r   r   r<   ,  s    
zSceneModel._check_scene_editorc             C   s8   |d krd | _ d | _d | _n|j | _ |j| _|j| _d S )N)Ú	_rendererZ_renwinZ_interactor)r%   ÚoldÚnewr   r   r   Ú_scene_editor_changed6  s    z SceneModel._scene_editor_changedc             C   s"   | j }|dk	rt|dƒr|jS dS )zGetter for the picker.NÚpicker)r:   r,   rb   )r%   Úser   r   r   Ú_get_picker@  s    zSceneModel._get_pickerc             C   s   | j }|dk	r|jS dS )zGetter for the light manager.N)r:   r!   )r%   rc   r   r   r   Ú_get_light_managerG  s    zSceneModel._get_light_managerc             C   s   | S )zGetter for the scene property.r   )r%   r   r   r   Ú
_get_sceneQ  s    zSceneModel._get_scene)N)T)N)NN)r   NrJ   )N)8r   r   r   r   rb   r   Z	actor_mapr   r-   r   r   r:   r   r)   Ú	activatedÚclosingÚscener   r	   Z_stereo_viewr   r
   Zdefault_viewr4   r#   r*   r1   r3   Z	add_actorZremove_actorr8   r9   r;   r=   rA   rB   rC   rD   rE   rG   rH   rI   rK   rN   rO   rQ   rR   rT   rU   rV   r<   ra   rd   re   rf   Ú__classcell__r   r   )r(   r   r   !   s€   




	






r   N)Ú__doc__Ú
traits.apir   r   r   r   r   Útraitsui.apir   r   r	   r
   Ztvtk.pyface.tvtk_scener   Ú	Exceptionr   r   r   r   r   r   Ú<module>   s
   