3
5Ad]ZK  ã               @   s^  d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	m
Z
 ddlmZ ddlmZ dZdadd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdejdd… ks¬dejdd… krìddlmZ x*d1D ]"Zeejdd… kr¾ejjeƒ q¾W ejƒ  dejdd… k�sdejdd… k�r(eeƒ ƒ ejdƒ dejdd… k�sPdejdd… k�rfede ƒ ejdƒ x4eejdd… ƒd D ]\ZZed2k�r~dZP �q~W d3\ZZ[[yddlZW n< e k
�rð Z! zde!dd  f Z"e e"ƒ‚W Y ddZ![!X nX dd!l#m$Z$m%Z% G d"d#„ d#e$ƒZ&G d$d%„ d%e&ƒZ'd&d'„ Z(d(d)„ Z)d*d+„ Z*d,d-„ Zd.d/„ Z+e,d0k�rZeƒ  dS )4a  The Mayavi application standalone script.

This script parses the command line arguments and launches Mayavi2
suitably.  It is meant to be used by those using Mayavi2 as a
standalone application.

Mayavi2: http://docs.enthought.com/mayavi/mayavi/overview.html

é    )Úprint_functionN)ÚsplitextÚexistsÚjoinÚabspath)Ú__version__)Úget_data_dirFc              C   s   d} | S )Na‹  Usage:

mayavi2 [options] ... [arg1] [arg2] ...

Where arg1, arg2 ... are optional file names that correspond to saved
Mayavi2 visualizations (file.mv2) or Mayavi2 scripts (file.py) or any
data files supported by Mayavi.  Valid options are one or more of the
following:

-d datafile.ext
--data datafile.ext

     datafile.ext can be any of the supported data file formats.  This
     includes VTK file formats (*.vtk, *.xml, *.vt[i,p,r,s,u],
     *.pvt[i,p,r,s,u]), VRML2 (*.wrl), 3D Studio (*.3ds), PLOT3D
     (*.xyz), STL, BYU, RAW, PLY,  PDB,  SLC,  FACET,  OBJ,  AVSUCD
     (*.inp),  GAMBIT (*.neu),  Exodus  (*.exii),  PNG,  JPEG,  BMP,
     PNM, DCM, DEM, MHA, MHD, MINC, XIMG, TIFF, and various others that
     are supported.  datafile.ext can also be a source object not
     associated with a file, for example ParametricSurface or PointLoad
     will load the corresponding data sources into Mayavi.

--filter filter-name
-f filter-name

     The passed filter name is loaded with respect to the current
     source/filter object.  The filter name must be a valid one if not
     you will get an error message.

     If the filter is specified as 'package.sub.filter.SomeFilter'
     then the filter (`SomeFilter`) is imported from
     'package.sub.filter'.  Standard modules provided with mayavi2 do
     not need the full path specification.

     Example::
         mayavi2 -d data.vtk -f ExtractVectorNorm -f m2_user_filters.TestFilter

     In this example 'ExtractVectorNorm' is a standard filter and
     'm2_user_filters.TestFilter' is some user defined filter.

-m module-name
--module module-name

     The passed module name is loaded in the current ModuleManager.
     The module name must be a valid one if not you will get an error
     message.

     If a module is specified as 'package.sub.module.SomeModule' then
     the module (`SomeModule`) is imported from 'package.sub.module'.
     Standard modules provided with mayavi2 do not need the full path
     specification.

     Example::
         mayavi2 -d data.vtk -m Outline -m m2_user_modules.TestModule

     In this example 'Outline' is a standard module and
     'm2_user_modules.TestModule' is some user defined module.

-M
--module-mgr

     Starts up a new module manager on the Mayavi pipeline.

-n
--new-scene

     Creates a new TVTK scene.  Any options passed after this will
     apply to this newly created scene.

-o
--offscreen

     Run Mayavi in offscreen mode without any graphical user interface.
     This is most useful for scripts that need to render images
     offscreen.

-x script-file
--exec script-file

     This executes the given script in a namespace where we guarantee
     that the name 'mayavi' is Mayavi's script instance -- just like
     in the embedded Python interpreter.

     **WARNING**: Note that this uses `execfile`, so please note that
                  this can be dangerous if the script does something
                  nasty!

-s python-expression
--set python-expression

     Execute the expression on the last created object.  For example,
     lets say the previous object was a module.  If you want to set the
     color of that object and save the scene you may do::

      $ mayavi2 [...] -m Outline -s"actor.property.color = (1,0,0)"         -s "scene.save('test.png', size=(800, 800))"

     You should use quotes for the expression.

     **WARNING**: Note that this uses `exec`, so please note that
                  this can be dangerous!

-z saved-visualization-file
--viz saved-visualization-file
--visualization saved-visualization-file

     Loads a previously saved Mayavi2 visualization file passed as the
     argument.

-t
--test

     Runs the mayavi2 test suite and exits.  If run as such, this runs
     both the TVTK and Mayavi2 unittests.  If any additional arguments
     are passed they are passed along to the test runner.  So this may
     be used to run other tests as well.  For example::

        mayavi2 -t apptools.persistence

     This will run just the tests inside the apptools.persistence
     package.  You can also specify a directory with test files to run
     with this, for example::

        mayavi2 -t relative_path_to/integrationtests/mayavi

     will run the integration tests from the mayavi sources.

-v
--verbose

     Prints verbose logs on the console.

-V
--version

     Prints the Mayavi version.

-h
--help

     Prints this help message.

Examples::

     mayavi2 test.mv2 (or mayavi2 -z test.mv2)

     mayavi2 test.py (or mayavi2 -x test.py)

     mayavi2 test.mv2 other.mv2 (or mayavi2 -z test.mv2 -z other.mv2)

     mayavi2 -d test.vtk -m Axes -m GridPlane \
     -f Threshold -m IsoSurface \
     -n -d heart.vtk -m Outline -m ContourGridPlane
© )Úmsgr	   r	   ú}/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/mayavi-4.7.1-py3.6-linux-x86_64.egg/mayavi/scripts/mayavi2.pyÚusage%   s     r   c             C   s¦   t | ƒtkr| jƒ } d}dddddddd	d
ddg}ytj| ||ƒ\}}W nT tjk
rœ } z6t|ƒ ttƒ ƒ tdd ƒ t|ƒ tjdƒ W Y dd}~X nX ||fS )a
  Returns the options and arguments parsed via getopts.

    Due to the special needs (order of args is important and repeated
    options will be supplied) of this command line parser we must use
    getopts and not optparse.

    Input Arguments:
      arguments -- This can be either a list of arguments as in
                   sys.argv[1:] or a string that is similar to the one
                   passed on the command line.  If it is a string the
                   string is split to create a list of arguments.
    zd:m:f:z:x:s:nMvozdata=zmodule=zfilter=zvisualization=zviz=zexec=zset=Úverbosez
module-mgrz	new-sceneZ	offscreenú-éF   é   N)	ÚtypeÚstrÚsplitÚgetoptÚerrorÚprintr   ÚsysÚexit)Ú	argumentsÚoptionsÚ	long_optsÚoptsÚargsr
   r	   r	   r   Úparse_cmd_lineÁ   s&    

r   c              C   sH   ddl m}  i }x2| jD ](}t|jƒdkr|jdd… }|||< qW |S )zƒReturns a dict indexed on the name of non-file related sources
    ids with the value being the corresponding metadata object.
    r   )ÚregistryNé   iúÿÿÿ)Úmayavi.core.registryr   ÚsourcesÚlenÚ
extensionsÚid)r   ÚdataÚsrcÚnamer	   r	   r   Ú_get_non_file_sourcesç   s    r)   c       "   7   C   sF  ddl m}m} ddlm} tƒ }| j}d}|jjdkrzd}	t	|ƒdkrZt	|ƒdkrnd}	n|d d d)krnd}	|	rz|j
ƒ }�xh|D �]^\}
}|
d*k� rðt|ƒ\}}t|ƒr¶|j|ƒ}n:||krà|| }|jƒ ƒ }|j|ƒ |}n|d| ƒ dS |
d+k�r²d|k�r,|jdƒ}|d|… }||d d… }nd||ƒ }|}yt|tƒ tƒ |gƒ}W n. tk
�r‚ } z|t|ƒƒ dS d}~X n0X t||ƒƒ }|dk�r¤|jj|_|j|ƒ |}|
d,k�rüd|k�rî|jdƒ}|d|… }||d d… }nx|dd… dk�rRd}d}|dd… }ddlm} yt||ƒƒ }W n ttfk
�rN   d}Y nX nd||ƒ }|}d}yt|tƒ tƒ |gƒ}W n. tk
�r¬ } z|t|ƒƒ dS d}~X nPX t||ƒ}|dk�rÊ|ƒ }n$|dk	�rà||d�}n|ƒ }|jƒ  |j|ƒ |}|
d-k�r&dd"l m!} |ƒ }|j|ƒ |}|
d.k�rZ|j
ƒ  |j}|j"d/ }|j#||d#� |}|
d0k�rxt$||ƒ}|�rxdS |
d1k�rÐyd&| } t%| tƒ tƒ ƒ W n0 t&k
�rÎ } z|t|ƒƒ W Y dd}~X nX |
d2kr‚|j'|ƒ q‚W xZ|D ]R}!t|!ƒ\}}|d'k�r|j'|!ƒ n*|d(k�r2t$||!ƒ}|�r<dS n
|j|!ƒ �qìW dS )3zæ Processes the passed command line arguments.

    Input Arguments:
      app -- A Mayavi application instance.

      opts -- The list of options returned by getopt.

      args -- The remaining arguments returned by getopt.
    r   )r   Ú	exception)Úcamel2enthoughtNFTú-nú--new-sceneú-zú--visualizationú--vizú-xú--execú-dú--datazFile/Source %s does not exist!ú-mú--moduleÚ.r   zmayavi.modules.%sZLabelsú-fú--filteré   zUserDefined:zmayavi.filters.user_definedZUserDefined)Útvtkzmayavi.filters.%s)Úfilterú-Mú--module-mgr)ÚModuleManager)Úcurrent_sceneÚcurrent_objectú-sú--setz	last_obj.z.mv2z.py)r,   r-   r.   r/   r0   r1   r2   )r3   r4   )r5   r6   )r8   r9   )r=   r>   )r,   r-   éÿÿÿÿ)r1   r2   )rB   rC   )r.   r/   r0   )(Úmayavi.core.commonr   r*   Ztvtk.commonr+   r)   ÚscriptÚenginer@   r#   Ú	new_scener   r   ÚopenZget_callableZ
add_sourceÚrfindÚ
__import__ÚglobalsÚlocalsÚImportErrorr   ÚgetattrrA   ÚobjectZ
add_moduleZtvtk.apir;   ÚAttributeErrorÚ	TypeErrorZsetup_filterZ
add_filterZmayavi.core.module_managerr?   ZscenesZ	trait_setÚ
run_scriptÚexecÚ	ExceptionZload_visualization)"Úappr   r   r   r*   r+   r"   rF   Zlast_objrH   ÚoÚaÚbaseÚextZmdr'   ÚidxÚmodnameÚ	classnameÚmodr
   ÚmÚfnamer;   ÚextraÚklassÚfr?   ÚmmÚeÚsÚerrÚstmtÚargr	   r	   r   Úprocess_cmd_lineô   sØ    
 


























rj   c             C   s–   ddl m} tjd j}d|kr2| |d< | j|d< ||d< d}y ttt|ƒj	ƒ |dƒ||ƒ W n2 t
k
r� } z|t|ƒƒ d	}W Y d
d
}~X nX |S )aT  Execfiles a given script.  The name `mayavi` is bound to the
    mayavi script instance just like in the embedded interpreter.
    `script_name` is the name of the script to execute.

    Note that this function uses `execfile`. You should be careful
    when using this.

    It returns `False` if everything was OK and `True` if not.
    r   )r*   Ú__main__ÚmayavirG   Ú__file__FrT   TN)rE   r*   r   ÚmodulesÚ__dict__rG   rT   ÚcompilerI   ÚreadrU   r   )rl   Úscript_namer*   Úgr   r
   r	   r	   r   rS   ‡  s    

 rS   ú-tr   ú--test)Úruntestsz-hz--helpz-Vz	--versionz	Mayavi %sú-oú--offscreenTzo%s
%s
Do you have vtk installed properly?
VTK (and build instructions) can be obtained from http://www.vtk.org
Ú_éP   )ÚMayaviÚsetup_loggerc               @   s   e Zd Zdd„ Zdd„ ZdS )Ú	MayaviAppc             C   s>   t |ƒ\}}||f| _x"|D ]\}}|dkrtj| _P qW dS )zParse command line options.ú-vú	--verboseN)r~   r   )r   Úcmd_line_optsÚloggingÚDEBUGÚlog_mode)ÚselfÚargvr   r   r   r	   r	   r   Úparse_command_line×  s    
zMayaviApp.parse_command_linec             C   s   | j \}}t| ||ƒ dS )zZProcess the command line options and setup mayavi as per
        the users needs.
        N)r€   rj   )r„   r   r   r	   r	   r   Úrunã  s    
zMayaviApp.runN)Ú__name__Ú
__module__Ú__qualname__r†   r‡   r	   r	   r	   r   r}   Ö  s   r}   c               @   s*   e Zd ZdZdd„ Zdd„ Zd	dd„ZdS )
ÚMayaviOffscreenz>
    The mayavi application used for offscreen rendering.
    c             C   s4   ddl m} ddlm} |ƒ }|jƒ  ||d�}|S )Nr   )ÚScript)ÚOffScreenEngine)rG   )Úmayavi.plugins.scriptrŒ   Zmayavi.core.off_screen_enginer�   Ústart)r„   rŒ   r�   rG   rf   r	   r	   r   Ú_script_defaultô  s    
zMayaviOffscreen._script_defaultc             C   s>   ddl m} t|jddƒ}t|ƒ}tjƒ }t||| jd� d S )Nr   )Ú	ETSConfigZ	mayavi_e3z
mayavi.log)Úmode)	Ztraits.etsconfig.apir‘   r   Zapplication_datar   r�   Ú	getLoggerr|   rƒ   )r„   r‘   ÚpathÚloggerr	   r	   r   r|   ü  s    zMayaviOffscreen.setup_loggerNc             C   s*   |d krg }| j |ƒ | jƒ  | jƒ  d S )N)r†   r|   r‡   )r„   r…   r	   r	   r   Úmain  s
    
zMayaviOffscreen.main)N)rˆ   r‰   rŠ   Ú__doc__r�   r|   r–   r	   r	   r	   r   r‹   ï  s   r‹   c              C   sV   ddl m}  ddlm} ddlm} x,| jjƒ D ]\}}t||ƒr0|j	j
|ƒS q0W dS )zwReturn the mayavi Script instance from the first available set of
    envisage engines registered in the registry.
    r   )r   )ÚEnvisageEngine)rŒ   N)r!   r   Zmayavi.plugins.envisage_enginer˜   rŽ   rŒ   ZenginesÚitemsÚ
isinstanceÚwindowZget_service)r   r˜   rŒ   r(   rG   r	   r	   r   Úget_mayavi_script_instance  s    
rœ   c             C   s,   ddl m} d| kr(t| jdƒ|ƒr(dS dS )zcReturns if the given namespace contains a 'mayavi' name bound to
    a mayavi script instance.
    r   )rŒ   rl   TF)rŽ   rŒ   rš   Úget)Ú	namespacerŒ   r	   r	   r   Úcontains_mayavi  s
    rŸ   c                s   ‡ fdd„}|S )a  A decorator to run a function from within mayavi.  This lets
    users write a normal Python function and have that run from within
    mayavi.  It implicitly assumes that the name 'mayavi' refers the the
    Script instance and will overwrite it if not.
    c                 st   t ƒ }|d krtd k	rtj}|d krP‡ ‡‡fdd„}tƒ }|j|dƒ |jƒ  n ˆj}t|ƒsf||d< ˆˆ ˆŽ d S )Nc                s*   | ˆj d< | jjj}|jˆfˆ žˆŽ dS )zFCallback that runs the function inside the mayavi
                app.rl   N)Ú__globals__r›   ZapplicationÚguiZinvoke_later)rF   rs   )r   ÚfuncÚkwr	   r   Úcaller3  s    

z+standalone.<locals>.wrapper.<locals>.callerrF   rl   )rœ   rl   rF   r{   Zon_trait_changer–   r    rŸ   )r   r£   rF   r¤   r_   Úns)r¢   )r   r£   r   Úwrapper.  s    
zstandalone.<locals>.wrapperr	   )r¢   r¦   r	   )r¢   r   Ú
standalone(  s    r§   c               C   sB   dt jkrt jjddƒ tr$tƒ antƒ atjt jdd… ƒ dS )z,This starts up the mayavi2 application.
    Ú r   r   N)	r   r”   ÚinsertÚ	OFFSCREENr‹   rl   r}   r–   r…   r	   r	   r	   r   r–   M  s    
r–   c               C   s   t dk	rt rt jjƒ  dS )z* This closes the mayavi2 application.
    N)rl   rª   r›   Úcloser	   r	   r	   r   r«   ]  s    r«   rk   )rt   ru   )rw   rx   )NN)-r—   Ú
__future__r   r   r   r�   Úos.pathr   r   r   r   Zmayavi.__version__r   Zmayavi.scripts.utilr   rª   rl   r   r   r)   rj   rS   r…   Zmayavi.testsrv   ri   Úremover–   r   r   ÚoptÚvtkrN   r_   r
   Zmayavi.plugins.appr{   r|   r}   r‹   rœ   rŸ   r§   r«   rˆ   r	   r	   r	   r   Ú<module>
   sd    & $
(

(
 
!%
