
    Og$                    n   d dl mZ d dlmZmZmZmZ d dlmZ d dl	Z	d dl
Z
d dlZd dlZd dlm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mZ d dlmZ  G d	 d
e	j6                        ZdZej<                  Zej@                  Z!ejD                  Z#ddZ$ddZ%dddZ&ddZ'	 d	 	 	 	 	 ddZ( G d d      Z)ddZ*y)    )annotations)UnionIterableSequenceOptional)PathN)uuid4)Matrix44UVecVec3Vec2)MeshBuilderMeshTransformer)meshexc                      e Zd ZdZdZdZy)	Operationr         N)__name__
__module____qualname__union
differenceintersection     Z/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/addons/openscad.pyr   r      s    EJLr   r   openscadc                     t        j                         dv rt        S t        j                  j                  dd      j                  d      S )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                     t        j                         dv rt        j                  t              duS t        t                     j                         S )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_installedr1   &   s@     //||C ,,!#$++--r   c           	        |
t               }t        t        j                               }t	        t                     }|d| dz  }|d| dz  }|j                  |        t        j                  |ddt	        |      t	        |      g       |j                  d       t               }|j                         r#t        j                  |j                               }|j                  d       |S )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   r0   r   	off_loads	read_text)script	exec_pathworkdiruuidoff_path	scad_pathnew_meshs          r   runrE   4   s     %'	8&&()Guw<D6$t,,HF4&..I OOM	N	
 % H##H$6$6$89 OOtO$Or   c                    dd l dfd}dj                  | j                         D cg c]  }t        t	         ||                   c}      }d| dS c c}w )Nr   c              3  l   K   | D ]*  }t        |j                        rt        |       '| , y wN)
isinstancefloat64float)valuesvaluenps     r   cleanupzstr_matrix44.<locals>.cleanupb   s3      	E%,El"		s   14, [])rL   r   returnr   )numpyjoincolumnsr7   list)mrO   csrN   s       @r   str_matrix44r[   ^   sL     			!))+>Q3tGAJ'(>?Aqc8O ?s   !Ac                   fd}g  ||       g}||D ]  }|j                   ||              dg}|j                         |j                  d       |G|j                  d       |D ]   }|j                  dt        |       d       " |j                  d       |j                  d       dj                  |      S )	a}  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                8   t              }g }t        j                  |       }|d   j                  |d         s|j	                  |d          |D ]F  }|j	                  |       j	                  d|j
                  dd|j                  dd       |dz  }H |S )Nr   z  [grP   ],r   )lenr   rW   iscloseappendxy)verticesindexindicesvlistvpointss        r   add_verticesz!str_polygon.<locals>.add_vertices}   s    F		(#Qxb	*LLq" 	ANN5!MMCAwbQr23QJE	 r   zpolygon(points = [r`   z	paths = [z  ,zconvexity = 10);
)rc   extendr7   rU   )pathholesrl   pathsholelinesrh   rk   s          @r   str_polygonru   m   s      F$ E 	-DLLd+,	-!"E	LL	LL[! 	/GLL2c'l^1-.	/T	LL#$99Ur   c                      e Zd ZddZddZddZ	 d	 	 	 	 	 ddZddZddZddZ	dd	Z
dd
Z	 d	 	 	 	 	 	 	 	 	 ddZddZddZy)Scriptc                    g | _         y rH   )dataselfs    r   __init__zScript.__init__   s	    !	r   c                :    | j                   j                  |       y)zAdd a string.N)ry   rc   )r{   ry   s     r   addz
Script.add   s    		r   c                L    | j                  t        j                  |             y)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_polyhedronzScript.add_polyhedron   s     	""4()r   Nc                :    | j                  t        ||             y)a  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~   ru   )r{   rp   rq   s      r   add_polygonzScript.add_polygon   s      	T5)*r   c                @    | j                  dt        |       d       y)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{   rX   s     r   add_multmatrixzScript.add_multmatrix   s     	?<?"3156r   c           	         t        |      }| j                  d|j                  dd|j                  dd|j                  dd       y)zAdd a ``translate()`` operation.

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

        Args:
            v: translation vector

        ztranslate(v = [r_   rP   ])Nr   r~   rd   re   z)r{   rj   vecs      r   add_translatezScript.add_translate   s@     1g?355)2ceeAYbq	DEr   c           	     @    | j                  d|dd|dd|dd       y)a9  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 = [r_   rP   r   Nr~   )r{   axayazs       r   
add_rotatezScript.add_rotate   s+     	<1vR1vR1vR89r   c                    t        |      }| j                  d|dd|j                  dd|j                  dd|j                  dd	       y)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 = r_   z, v = [rP   r   Nr   )r{   arj   r   s       r   add_rotate_about_axiszScript.add_rotate_about_axis   sH     1g;qe7355)2ceeAYbq	LMr   c           	     @    | j                  d|dd|dd|dd       y)a   Add 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 = [r_   rP   r   Nr   )r{   sxsyszs       r   	add_scalezScript.add_scale   s+     	;r!fBr!fBr!fB78r   c                V   d|dd|dd|dd}|| j                  |dz          yt        |t              rt        |      j	                         }n<dj                  |D cg c]  }t        |      j	                          c}      }d| d}| j                  |d| dz          yc c}w )	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 = [r_   rP   rR   Nr   rQ   z	, auto = )r~   rI   boolr7   lowerrU   )r{   nxnynzautomainflagsr   s           r   
add_resizezScript.add_resize   s    ( $Bq6Bq6Bq6;<HHTCZ d#IOO%EIIt<!s1v||~<=EwaLE)E7!,,- =s     B&c           	         t        |      j                         }| j                  d|j                  dd|j                  dd|j
                  dd       y)a  Add 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 = [r_   rP   r   N)r   	normalizer~   rd   re   r   )r{   rj   ns      r   
add_mirrorzScript.add_mirror  sI     G<AwbQr!##a;<r   c                8    dj                  | j                        S )z"Returns the OpenSCAD build script.rn   )rU   ry   rz   s    r   
get_stringzScript.get_string%  s    yy##r   )rS   None)ry   r7   rS   r   )r   r   rS   r   rH   )rp   Iterable[UVec]rq   "Optional[Sequence[Iterable[UVec]]]rS   r   )rX   r
   rS   r   )rj   r   rS   r   )r   rK   r   rK   r   rK   rS   r   )r   rK   rj   r   rS   r   )r   rK   r   rK   r   rK   rS   r   )
r   rK   r   rK   r   rK   r   z.Optional[Union[bool, tuple[bool, bool, bool]]]rS   r   rS   r7   )r   r   r   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   rw   rw      s    "* 59++ 2+ 
	+$7
F:N9$ @D.. . 	.
 =. 
.>=$r   rw   c                   t        | t              sJ d       t               }|j                  | j                   d       |j                  |       |j                  |       |j                  d       |j                         S )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() {})rI   r   rw   r~   namer   r   )opmesh1mesh2r>   s       r   boolean_operationr   *  sn     b)$G&GG$XF
JJ"''% !
% 
% 
JJsOr   r   )rS   r   rH   )r>   r7   r?   zOptional[str]rS   r   )rX   r
   rS   r7   )rp   r   rq   r   rS   r7   )r   r   r   r   r   r   rS   r7   )+
__future__r   typingr   r   r   r   pathlibr   enumr%   r.   r9   rA   r	   r5   r(   
ezdxf.mathr
   r   r   r   ezdxf.renderr   r   ezdxf.addonsr   Enumr   r'   r   UNIONr   
DIFFERENCEr   INTERSECTIONr,   r1   rE   r[   ru   rw   r   r   r   r   <module>r      s    # 6 6         1 1 5 		  !!
%%O.'T" 15+
+-+ 	+\L$ L$^r   