Ë
    £èh&  ã                  ó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© ó    ú5lib/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ÜŒu‹w‹<€Dà˜6 $  tÐ,Ñ,€HØ˜F 4 &¨Ð.Ñ.€Ià×Ñ˜Ô Ü‡O�OàØØÜ�‹MÜ�	‹Nð	
ôð ×Ñ ÐÔ%äÓ €Hà‡�ÔÜ×#Ñ# H×$6Ñ$6Ó$8Ó9ˆð ‡O�O˜t€OÔ$Ø€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   s.   øè ø€ ÛˆEÜ˜% §¡Ô,Ü˜E“lÓ"à“ñ	 ùs   ƒ14ú, Ú[Ú])rL   r   Úreturnr   )ÚnumpyÚjoinÚcolumnsr7   Úlist)ÚmrO   ÚcÚsrN   s       @r   Ústr_matrix44r[   ^   sP   ø€ ãõð 	�	‰	°!·)±)´+Ó>±+¨Q”3”t™G A›JÓ'Õ(°+Ñ>Ó?€AØˆqˆc�ˆ8€Oùò ?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“ˆØˆÜ—	‘	˜(Ó#ˆØ�Q‰x×Ñ  b¡	Ô*Ø�L‰L˜˜q™Ô"ãˆAØ�N‰N˜5Ô!Ø�M‰M˜C §¡ A˜w b¨¯©¨Q¨¨rÐ2Ô3Ø�Q‰J‰Eð ð ˆ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Ø�L‰L™ dÓ+Õ,ð à!Ð"€EØ	‡L�L�ÔØ	‡L�L�ÔØÐØ�‰�[Ô!ÛˆGØ�L‰L˜2œc '›l˜^¨1Ð-Õ.ð à�‰�TÔØ	‡L�LÐ#Ô$Ø�9‰9�UÓÐ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)z˜Add `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   € ð  	�‰”˜T 5Ó)Õ*r   c                ó@   — | j                  dt        |«      › d�«       y)zØAdd 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   € ð 	�‰�?¤<°£?Ð"3°1Ð5Õ6r   c           	     ó’   — t        |«      }| j                  d|j                  d›d|j                  d›d|j                  d›d�«       y)zÀAdd 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@   € ô �1‹gˆØ�‰�? 3§5¡5¨ )¨2¨c¯e©e°A¨Y°b¸¿¹¸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+   € ð 	�‰�<  1˜v R¨¨1 v¨R°°1¨v°RÐ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   € ô �1‹gˆØ�‰�;˜q ˜e 7¨3¯5©5°¨)°2°c·e±e¸A°Y¸bÀÇÁÀ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 !˜f B r¨! f¨B¨r°!¨f°BÐ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©   € ð( $ B q 6¨¨B¨q¨6°°B°q°6¸Ð;ˆØˆ<Ø�H‰H�T˜C‘ZÔ ØÜ˜œdÔ#Ü˜“I—O‘OÓ%‰Eà—I‘I±tÓ<±t°!œs 1›vŸ|™|�~°tÑ<Ó=ˆEØ˜�w˜a�LˆEØ�‰�˜) E 7¨!Ð,Ñ,Õ-ùò =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×ÑÓˆØ�‰�< §¡ A˜w b¨¯©¨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   € à�y‰y˜Ÿ™Ó#Ð#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 )zÁReturns 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Ð$Ü‹X€FØ
‡J�J�"—'‘'�˜%Ð Ô!Ø
×Ñ˜%Ô Ø
×Ñ˜%Ô Ø
‡J�Jˆs„OØ×ÑÓÐ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   