
    h$                    ~   S SK Jr  S SKJrJrJrJr  S SKJr  S SK	r	S SK
r
S SKrS SKrS SKJr  S SKrS SKrS SKJrJrJrJr  S SKJrJr  S SKJr   " S	 S
\	R6                  5      rSr\R<                  r\R@                  r!\RD                  r#SS jr$SS jr%SSS jjr&SS jr' S     SS jjr( " S S5      r)SS jr*g)    )annotations)UnionIterableSequenceOptional)PathN)uuid4)Matrix44UVecVec3Vec2)MeshBuilderMeshTransformer)meshexc                       \ rS rSrSrSrSrSrg)	Operation   r          N)__name__
__module____qualname____firstlineno__union
differenceintersection__static_attributes__r       G/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/openscad.pyr   r      s    EJLr   r   openscadc                     [         R                  " 5       S;   a  [        $ [        R                  R                  SS5      R                  S5      $ )NLinuxDarwinzopenscad-addonwin_exec_path")platformsystemCMDezdxfoptionsgetstripr   r   r    get_openscad_pathr/      s:    //
}}  !1?CII#NNr   c                     [         R                  " 5       S;   a  [        R                  " [        5      SL$ [        [        5       5      R                  5       $ )a  Returns ``True`` if OpenSCAD is installed.

Searches on Windows the path stored in the options as "win_exec_path" in section
"[openscad-addon]" which is "C:\Program Files\OpenSCAD\openscad.exe" by default.

Searches the "openscad" command on Linux and macOS.

r#   N)r(   r)   shutilwhichr*   r   r/   existsr   r   r    is_installedr4   &   s@     //||C ,,!#$++--r   c           	        Uc
  [        5       n[        [        R                  " 5       5      n[	        [        5       5      nUSU S3-  nUSU S3-  nUR                  U 5        [        R                  " USS[	        U5      [	        U5      /5        UR                  SS9  [        5       nUR                  5       (       a$  [        R                  " UR                  5       5      nUR                  SS9  U$ )a
  Executes the given `script` by OpenSCAD and returns the result mesh as
:class:`~ezdxf.render.MeshTransformer`.

Args:
    script: the OpenSCAD script as string
    exec_path: path to the executable as string or ``None`` to use the
        default installation path

ezdxf_z.offz.scadz--quietz-oT)
missing_ok)r/   r   tempfile
gettempdirstrr	   
write_text
subprocesscallunlinkr   r3   r   	off_loads	read_text)script	exec_pathworkdiruuidoff_path	scad_pathnew_meshs          r    runrH   4   s     %'	8&&()Guw<D6$t,,HF4&..I OOM	N	
 % H##H$6$6$89 OOtO$Or   c                   ^ SS K mSU4S jjnSR                  U R                  5        Vs/ s H  n[        [	        U" U5      5      5      PM     sn5      nSU S3$ s  snf )Nr   c              3  |   >#    U  H1  n[        UTR                  5      (       a  [        U5      v   M-  Uv   M3     g 7fN)
isinstancefloat64float)valuesvaluenps     r    cleanupstr_matrix44.<locals>.cleanupb   s0     E%,,El"	 s   9<, [])rO   r   returnr   )numpyjoincolumnsr:   list)mrR   csrQ   s       @r    str_matrix44r_   ^   sP     			!))+>+Q3tGAJ'(+>?Aqc8O ?s   $Ac                  ^ U4S jn/ mU" U 5      /nUb   U H  nUR                  U" U5      5        M     S/nUR                  T5        UR                  S5        UbI  UR                  S5        U H!  nUR                  S[        U5       S35        M#     UR                  S5        UR                  S5        SR                  U5      $ )	aa  Returns a ``polygon()`` command as string. This is a 2D command, all
z-axis values of the input vertices are ignored and all paths and holes
are closed automatically.

OpenSCAD docs: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#polygon

Args:
    path: exterior path
    holes: a sequences of one or more holes as vertices

c                H  > [        T5      n/ n[        R                  " U 5      nUS   R                  US   5      (       d  UR	                  US   5        U HG  nUR	                  U5        TR	                  SUR
                  S SUR                  S S35        US-  nMI     U$ )Nr   z  [grT   ],r   )lenr   r[   iscloseappendxy)verticesindexindicesvlistvpointss        r    add_vertices!str_polygon.<locals>.add_vertices}   s    F		(#Qxb	**LLq"ANN5!MMCAwbQr23QJE  r   zpolygon(points = [rd   z	paths = [z  ,zconvexity = 10);
)rg   extendr:   rY   )pathholesrp   pathsholelinesrl   ro   s          @r    str_polygonrz   m   s      F$ EDLLd+, !"E	LL	LL[!GLL2c'l^1-. T	LL#$99Ur   c                      \ rS rSrSS jrSS jrSS jr S     SS jjrSS jrSS jr	SS	 jr
SS
 jrSS jr S         SS jjrSS jrSS jrSrg)Script   c                    / U l         g rK   dataselfs    r    __init__Script.__init__   s	    !	r   c                :    U R                   R                  U5        g)zAdd a string.N)r   rg   )r   r   s     r    add
Script.add   s    		r   c                N    U R                  [        R                  " U5      5        g)zAdd `mesh` as ``polyhedron()`` command.

OpenSCAD docs: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#polyhedron

N)r   r   
scad_dumps)r   meshs     r    add_polyhedronScript.add_polyhedron   s     	""4()r   Nc                8    U R                  [        X5      5        g)al  Add a ``polygon()`` command. This is a 2D command, all
z-axis values of the input vertices are ignored and all paths and holes
are closed automatically.

OpenSCAD docs: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#polygon

Args:
    path: exterior path
    holes: a sequence of one or more holes as vertices, or ``None`` for no holes

N)r   rz   )r   ru   rv   s      r    add_polygonScript.add_polygon   s      	T)*r   c                @    U R                  S[        U5       S35        g)zAdd a transformation matrix of type :class:`~ezdxf.math.Matrix44` as
``multmatrix()`` operation.

OpenSCAD docs: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#multmatrix

zmultmatrix(m = )N)r   r_   )r   r\   s     r    add_multmatrixScript.add_multmatrix   s     	?<?"3156r   c           	         [        U5      nU R                  SUR                  S SUR                  S SUR                  S S35        g)zAdd a ``translate()`` operation.

OpenSCAD docs: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#translate

Args:
    v: translation vector

ztranslate(v = [rc   rT   ])Nr   r   rh   ri   z)r   rn   vecs      r    add_translateScript.add_translate   s@     1g?355)2ceeAYbq	DEr   c           	     @    U R                  SUS SUS SUS S35        g)a	  Add a ``rotation()`` operation.

OpenSCAD docs: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#rotate

Args:
    ax: rotation about the x-axis in degrees
    ay: rotation about the y-axis in degrees
    az: rotation about the z-axis in degrees

zrotate(a = [rc   rT   r   Nr   )r   axayazs       r    
add_rotateScript.add_rotate   s+     	<1vR1vR1vR89r   c                    [        U5      nU R                  SUS SUR                  S SUR                  S SUR                  S S3	5        g)a  Add a ``rotation()`` operation about the given axis `v`.

OpenSCAD docs: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#rotate

Args:
    a: rotation angle about axis `v` in degrees
    v: rotation axis as :class:`ezdxf.math.UVec` object

zrotate(a = rc   z, v = [rT   r   Nr   )r   arn   r   s       r    add_rotate_about_axisScript.add_rotate_about_axis   sH     1g;qe7355)2ceeAYbq	LMr   c           	     @    U R                  SUS SUS SUS S35        g)zAdd a ``scale()`` operation.

OpenSCAD docs: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#scale

Args:
    sx: scaling factor for the x-axis
    sy: scaling factor for the y-axis
    sz: scaling factor for the z-axis

zscale(v = [rc   rT   r   Nr   )r   sxsyszs       r    	add_scaleScript.add_scale   s+     	;r!fBr!fBr!fB78r   c                h   SUS SUS SUS S3nUc  U R                  US-   5        g[        U[        5      (       a  [        U5      R	                  5       nO?SR                  U Vs/ s H  n[        U5      R	                  5       PM     sn5      nSU S3nU R                  USU S3-   5        gs  snf )	a  Add a ``resize()`` operation.

OpenSCAD docs: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#resize

Args:
    nx: new size in x-axis
    ny: new size in y-axis
    nz: new size in z-axis
    auto: If the `auto` argument is set to ``True``, the operation
        auto-scales any 0-dimensions to match. Set the `auto` argument
        as a  3-tuple of bool values to auto-scale individual axis.

zresize(newsize = [rc   rT   rV   Nr   rU   z	, auto = )r   rL   boolr:   lowerrY   )r   nxnynzautomainflagsr   s           r    
add_resizeScript.add_resize   s    ( $Bq6Bq6Bq6;<HHTCZ d##IOO%EIIt<t!s1v||~t<=EwaLE)E7!,,- =s   &#B/c           	         [        U5      R                  5       nU R                  SUR                  S SUR                  S SUR
                  S S35        g)zAdd a ``mirror()`` operation.

OpenSCAD docs: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#mirror

Args:
    v: the normal vector of a plane intersecting the origin through
        which to mirror the object

zmirror(v = [rc   rT   r   N)r   	normalizer   rh   ri   r   )r   rn   ns      r    
add_mirrorScript.add_mirror  sI     G<AwbQr!##a;<r   c                8    SR                  U R                  5      $ )z"Returns the OpenSCAD build script.rs   )rY   r   r   s    r    
get_stringScript.get_string%  s    yy##r   r   )rW   None)r   r:   rW   r   )r   r   rW   r   rK   )ru   Iterable[UVec]rv   "Optional[Sequence[Iterable[UVec]]]rW   r   )r\   r
   rW   r   )rn   r   rW   r   )r   rN   r   rN   r   rN   rW   r   )r   rN   rn   r   rW   r   )r   rN   r   rN   r   rN   rW   r   )
r   rN   r   rN   r   rN   r   z.Optional[Union[bool, tuple[bool, bool, bool]]]rW   r   rW   r:   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r|   r|      s    "* 59++ 2+ 
	+$7
F:N9$ @D.. . 	.
 =. 
.>=$r   r|   c                   [        U [        5      (       d   S5       e[        5       nUR                  U R                   S35        UR                  U5        UR                  U5        UR                  S5        UR                  5       $ )zReturns an `OpenSCAD`_ script to apply the given boolean operation to the
given meshes.

The supported operations are:

    - UNION
    - DIFFERENCE
    - INTERSECTION

zenum of type Operation expectedz() {})rL   r   r|   r   namer   r   )opmesh1mesh2rA   s       r    boolean_operationr   *  sq     b)$$G&GG$XF
JJ"''% !
% 
% 
JJsOr   r   )rW   r   rK   )rA   r:   rB   zOptional[str]rW   r   )r\   r
   rW   r:   )ru   r   rv   r   rW   r:   )r   r   r   r   r   r   rW   r:   )+
__future__r   typingr   r   r   r   pathlibr   enumr(   r1   r<   rD   r	   r8   r+   
ezdxf.mathr
   r   r   r   ezdxf.renderr   r   ezdxf.addonsr   Enumr   r*   r   UNIONr   
DIFFERENCEr   INTERSECTIONr/   r4   rH   r_   rz   r|   r   r   r   r    <module>r      s    # 6 6         1 1 5 		  !!
%%O.'T" 15+
+-+ 	+\L$ L$^r   