
    h>                       S SK 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rS SK	r	S SK
r
S SKJr  S SKJr  S SKrS SKJr  S SKJrJrJrJr  \R.                  " S5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r0 SS_SS_SS_SS_SS_SS _S!S"_S#S$_S%S&_S'S(_S)S*_S+S_S,S_S-S_S.S_S/S_S0S _S"S$S&S1.Er 1 S2kr!S3r"S4r#S5r$SIS6 jr%SIS7 jr&SJS8 jr'SKS9 jr( SLS:S;.       SMS< jjjr) SLS:S:S=.           SNS> jjjr* SOS%S?S:S@.   SPSA jjjr+SQSB jr,   SR             SSSC jjr-STSD jr.\SE 5       r/        SUSF jr0SVSG jr1SWSH jr2g)X    )annotations)OptionalN)contextmanager)Path)Drawing)is_dxf_filedxf_infois_binary_dxf_filedwg_versionezdxfc                      \ rS rSrSrg)
ODAFCError    N__name__
__module____qualname____firstlineno____static_attributes__r       D/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/odafc.pyr   r          r   r   c                      \ rS rSrSrg)UnknownODAFCError    r   Nr   r   r   r   r   r       r   r   r   c                      \ rS rSrSrg)ODAFCNotInstalledError$   r   Nr   r   r   r   r   r   $   r   r   r   c                      \ rS rSrSrg)UnsupportedFileFormat(   r   Nr   r   r   r   r!   r!   (   r   r   r!   c                      \ rS rSrSrg)UnsupportedPlatform,   r   Nr   r   r   r   r$   r$   ,   r   r   r$   c                      \ rS rSrSrg)UnsupportedVersion0   r   Nr   r   r   r   r'   r'   0   r   r   r'   R12ACAD12R13ACAD13R14ACAD14R2000ACAD2000R2004ACAD2004R2007ACAD2007R2010ACAD2010R2013ACAD2013R2018ACAD2018AC1004ACAD9AC1006ACAD10AC1009AC1012AC1014AC1015AC1018AC1021)AC1024AC1027AC1032>   r<   r>   r*   r,   r.   r0   r2   r4   r6   r8   r:   WindowsLinuxDarwinc                 `    [         R                  R                  SS5      R                  S5      $ )Nodafc-addonwin_exec_path"r   optionsgetstripr   r   r   get_win_exec_pathrS   ^   s$    ==]O<BB3GGr   c                 `    [         R                  R                  SS5      R                  S5      $ )NrL   unix_exec_pathrN   rO   r   r   r   get_unix_exec_pathrV   b   s%    ==],<=CCCHHr   c                 &   [         R                  " 5       [        [        4;   aH  [	        5       n U (       a  [        U 5      R                  5       (       a  g[        R                  " S5      SL$ [        R                  R                  [        5       5      $ )z6Returns ``True`` if the ODAFileConverter is installed.TODAFileConverterN)platformsystemLINUXDARWINrV   r   is_fileshutilwhichospathexistsrS   )rU   s    r   is_installedrc   f   sb    UFO++-d>2::<<||./t;;77>>+-..r   c                f    [         R                  U R                  5       U R                  5       5      $ N)VERSION_MAPrQ   upper)versions    r   map_versionri   q   s    ??7==?GMMO<<r   F)auditc          
        [        U 5      R                  5       nUR                  5       (       d  [        SU S35      e[	        U[
        5      (       a  [        U5      nO[        U 5      n[        R                  " SS9 n[        UR                  [        UR                  5      USUUS9n[        U5        [        U5      UR                  S5      R                  -  nUR                  5       (       aI  [         R"                  " [        U5      5      n[        UR                  S5      5      Ul        UsSSS5        $  SSS5        ['        S	5      e! , (       d  f       N= f)
a  Uses an installed `ODA File Converter`_ to convert a DWG/DXB/DXF file
into a temporary DXF file and load this file by `ezdxf`.

Args:
    filename: file to load by ODA File Converter
    version: load file as specific DXF version, by default the same version
        as the source file or if not detectable the latest by `ezdxf`
        supported version.
    audit: audit source file before loading

Raises:
    FileNotFoundError: source file not found
    odafc.UnknownODAFCError: conversion failed for unknown reasons
    odafc.UnsupportedVersion: invalid DWG version specified
    odafc.UnsupportedFileFormat: unsupported file extension
    odafc.ODAFCNotInstalledError: ODA File Converter not installed

zNo such file: ''odafc_prefixDXFoutput_formatrh   rj   .dxfNz%Failed to convert file: Unknown Error)r   absoluter]   FileNotFoundError
isinstancestrri   _detect_versiontempfileTemporaryDirectory_odafc_argumentsnameparent_execute_odafcwith_suffixrb   r   readfilefilenamer   )r   rh   rj   infiletmp_dirargsout_filedocs           r   r   r   u   s   * (^$$&F>>/& ;<<'3g&!(+		$	$H	5KK
 	t=6#5#5f#=#B#BB??..X/Cv11&9:CL 
6	5  
6 C
DD 
6	5s   >B2E
E)rj   replacec          
        Uc  U R                   n[        U   n[        U5      R                  5       n[        UR                  5      nUR                  5       (       a&  U(       a  UR                  5         O[        SU 35      eUR                  5       (       a  [        R                  " SS9 n[        U5      UR                  S5      R                  -  n	U R                  n
U R                  U	5        Xl        [        U	R                  U[        U5      SUUS9n[!        U5        SSS5        g[#        S[        U5       S	35      e! , (       d  f       g= f)
a  Uses an installed `ODA File Converter`_ to export the DXF document `doc`
as a DWG file.

A temporary DXF file will be created and converted to DWG by the
ODA File Converter. If `version` is not specified the DXF version of the
source document is used.

Args:
    doc: `ezdxf` DXF document as :class:`~ezdxf.drawing.Drawing` object
    filename: output DWG filename, the extension will be set to ".dwg"
    version: DWG version to export, by default the same version as
        the source document.
    audit: audit source file by ODA File Converter at exporting
    replace: replace existing DWG file if ``True``

Raises:
    FileExistsError: target file already exists, and argument `replace` is
        ``False``
    FileNotFoundError: parent directory of target file does not exist
    odafc.UnknownODAFCError: exporting DWG failed for unknown reasons
    odafc.ODAFCNotInstalledError: ODA File Converter not installed

NzFile already exists: rm   rn   rs   DWGrq   zNo such file or directory: 'rl   )
dxfversionrf   r   rt   r}   rb   unlinkFileExistsErrorry   rz   r   r|   r   saveasr{   rw   r~   ru   )r   r   rh   rj   r   export_versiondwg_file
out_folderr   dxf_fileold_filename	argumentss               r   
export_dwgr      s   > .. )NH~&&(Hhoo&JOO!$9("DEE((9WG}x';';F'C'H'HHH <<LJJx 'L(J#&I 9%! :9$  ">s:>Oq QRR% :9s   +A7E
ET)rh   rj   r   c          
        [        U5      nU[        ;  a  [        SU S35      e[        U 5      R	                  5       R                  5       nUR                  5       (       d  [        SU  S35      eU(       a  [        U5      nOYUR                  R                  5       nUS:X  a  UR                  S5      nO'US:X  a  UR                  S5      nO[        SU S35      eUR                  5       (       a  U(       d  [        SU S35      eUR                  nUR                  5       (       a  UR                  5       (       d  [        SU S35      eUR                  nUR                  5       S	S
 n	U	S;  a  [        SU S35      e[         R"                  " SS9 n
[%        UR&                  [)        UR                  5      [)        U
5      U	UUS9n[+        U5        [-        [        U
5      R/                  5       5      nU(       a   [0        R2                  " US   U5        O[9        SU	 S35        S
S
S
5        g
! [4         a    [0        R6                  " US   U5         N/f = f! , (       d  f       g
= f)a  Convert `source` file to `dest` file.

The file extension defines the target format
e.g. :code:`convert("test.dxf", "Test.dwg")` converts the source file to a
DWG file.
If `dest` is an empty string the conversion depends on the source file
format and is DXF to DWG or DWG to DXF.
To convert DXF to DXF an explicit destination filename is required:
:code:`convert("r12.dxf", "r2013.dxf", version="R2013")`

Args:
    source: source file
    dest: destination file, an empty string uses the source filename with
        the extension of the target format e.g. "test.dxf" -> "test.dwg"
    version: output DXF/DWG version e.g. "ACAD2018", "R2018", "AC1032"
    audit: audit files
    replace: replace existing destination file

Raises:
    FileNotFoundError: source file or destination folder does not exist
    FileExistsError: destination file already exists and argument `replace`
        is ``False``
    odafc.UnsupportedVersion: invalid DXF version specified
    odafc.UnsupportedFileFormat: unsupported file extension
    odafc.UnknownODAFCError: conversion failed for unknown reasons
    odafc.ODAFCNotInstalledError: ODA File Converter not installed

zInvalid version: 'rl   zSource file not found: '.dwgrs   Unsupported file format: 'zTarget file already exists: 'z$Destination folder does not exist: '   N)rp   r   rm   rn   )	in_folderr   rr   rh   rj   r   zUnknown error: no z file was created)ri   VALID_VERSIONSr'   r   
expanduserrt   rb   ru   suffixlowerr   r!   r   r}   is_dirrg   ry   rz   r{   r|   rw   r~   listiterdirr^   moveIOErrorcopyr   )sourcedestrh   rj   r   src_path	dest_pathext
parent_dirfmtr   r   results                r   convertr      s(   H '"Gn$ #5gYa!@AAF|&&(113H??":6(! DEEJ	oo##%&= ,,V4IF] ,,V4I'*DSE(KLL' =i[JKK!!Jj&7&7&9&9"FzlRS TUU


C
))+ab/C
. #&@Q$GHH		$	$H	5$MM(//*7|
	 	y!d7m++-.2F1Iy1  23%7HIJ# 
6	5  2F1Iy12 
6	5s1   A)I>H1I1$IIII
I)c                   Sn[         R                  R                  U 5      S   R                  5       nUS:X  aV  [	        U 5      (       a  Ot[        U 5      (       a4  [        U S5       n[        U5      n[        UR                     nSSS5        O0O/US:X  a  [        U 5      nUc  [        S5      eO[        SU S	35      e[        U5      $ ! , (       d  f       N= f)
zReturns the DXF/DWG version of file `path` as ODAFC compatible version
string.

Raises:
    odafc.UnsupportedVersion: unknown or unsupported DWG version
    odafc.UnsupportedFileFormat; unsupported file extension

r:   r   rs   rtNr   z#Unknown or unsupported DWG version.r   rl   )r`   ra   splitextr   r
   r   openr	   rf   rh   r   r'   r!   ri   )ra   rh   r   fpinfos        r   rx   rx   6  s     G
''

4
 
#
)
)
+C
f}d##dD!R|%dll3 "!  
d#?$%JKK  $&@Q$GHHw "!s   &C		
Cc                .    SnU(       a  SOSnUUUUUUU /$ )aw  ODA File Converter command line format:

ODAFileConverter "Input Folder" "Output Folder" version type recurse audit [filter]

    - version: output version: "ACAD9" - "ACAD2018"
    - type: output file type: "DWG", "DXF", "DXB"
    - recurse: recurse Input Folder: "0" or "1"
    - audit: audit each file: "0" or "1"
    - optional Input files filter: default "*.DWG,*.DXF"

01r   )r   r   r   rr   rh   rj   recurse	audit_strs           r   r{   r{   R  s1    & G#I r   c                t   [        5       nU [        :w  a@  U(       a9  [        U5      R                  5       (       a  U$ [        R                  SU S35        [        R                  " S5      nU(       d4  U [        :X  a*  [        5       n[        U5      R                  5       (       d  SnU(       d  [        S5      eU$ )ziGet ODAFC application path.

Raises:
    odafc.ODAFCNotInstalledError: ODA File Converter not installed

z	command 'z%' not found, using 'ODAFileConverter'rX   Nz~Could not find ODAFileConverter in the path. Install application from https://www.opendesign.com/guestfiles/oda_file_converter)
rV   WINDOWSr   r]   loggerwarningr^   r_   rS   r   )rZ   rU   ra   s      r   _get_odafc_pathr   r  s     ()N^''))!!NNN++PQ <<*+DFg% "Dz!!##D$`
 	
 Kr   c               #    #    [         R                  " S5      (       a  S[        R                  " 5        3n [        R
                  " SU SSS/[        R                  [        R                  S9n[        R                  " S5        U v    UR                  5         UR                  5         g
[        R                  S5        [        R                  S	   v   g
! [         a     g
f = f7f)zCSee xvbfwrapper library for a more feature complete xvfb interface.Xvfb:z-screenr   
800x600x24)stdoutstderrg?z=Install xvfb to prevent the ODAFileConverter GUI from openingDISPLAYN)r^   r_   r`   getpid
subprocessPopenDEVNULLtimesleep	terminatewaitOSErrorr   r   environ)displayprocs     r   _linux_dummy_displayr     s      ||Fbiik]#Wil;%%%%

 	

3	NNIIK 	VXjj##	  		s*   BC$ C (,C$
C!C$ C!!C$c                   U [         :X  aR  [        5        n[        R                  R	                  5       nX4S'   [
        R                  " U/U-   SSUS9nSSS5        U$ U [        :X  a  [
        R                  " U/U-   SSS9nU$ U [        :X  a  [
        R                  " 5       n[
        R                  [
        R                  -  Ul        [
        R                  Ul        [
        R                  " U/U-   [
        R                   [
        R                   US9nUR#                  5         U$ [%        SU  35      e! , (       d  f       W$ = f)a4  Execute ODAFC application without launching the GUI.

Args:
    system: "Linux", "Windows" or "Darwin"
    command: application to execute
    arguments: ODAFC argument list

Raises:
    odafc.UnsupportedPlatform: for unsupported platforms
    odafc.ODAFCNotInstalledError: ODA File Converter not installed

r   T)textcapture_outputenvN)r   r   )r   r   startupinfozUnsupported platform: )r[   r   r`   r   r   r   runr\   r   STARTUPINFOCREATE_NEW_CONSOLESTARTF_USESHOWWINDOWdwFlagsSW_HIDEwShowWindowr   PIPEr   r$   )rZ   commandr   r   r   r   r   s          r   _run_with_no_guir     s$    !#w**//#C$	N>>	I%D3D $: K- 
6	~~wi)3$tT( K% 
7	 ,,.))J,K,KK 	 #-"4"4I	!????#	
 			
 K "$:6("CDD9 $#: Ks   >D44
Ec                p    UR                  5       nU [        :X  a  US:g  =(       a    US:g  $ US:w  a  gUS:g  $ )N zQuit (core dumped)r   T)rR   r[   )rZ   
returncoder   s      r   _odafc_failedr     s=    \\^F|>*> >>	q|r   c                   [         R                  SU  35        [        R                  " 5       n[	        U5      n[        XU 5      nUR                  nU[        :X  aS  UR                  R                  5       R                  S5      nUR                  R                  5       R                  S5      nOUR                  nUR                  n[        XU5      (       a+  SU SU SU 3n[         R                  U5        [        U5      eU$ )a  Execute ODAFC application.

Args:
    arguments: ODAFC argument list

Raises:
    odafc.ODAFCNotInstalledError: ODA File Converter not installed
    odafc.UnknownODAFCError: execution failed for unknown reasons
    odafc.UnsupportedPlatform: for unsupported platforms

z)Running ODAFileConverter with arguments: zutf-8z)ODA File Converter failed: return code = z
.
stdout: z	
stderr: )r   debugrY   rZ   r   r   r   r   r   readdecoder   r   r   )r   rZ   oda_fcr   r   r   r   msgs           r   r~   r~     s     LL<YKHI__FV$FFI6DJ!!#**73!!#**73V007
| Dhj2 	 	S$$Mr   )returnrw   )r   bool)rh   rw   r   rw   re   )r   str | os.PathLikerh   Optional[str]rj   r   r   r   )r   r   r   r   rh   r   rj   r   r   r   r   None)r   )r   r   r   r   )ra   rw   r   rw   )rp   r8   F)r   rw   r   rw   r   rw   rr   rw   rh   rw   rj   r   r   	list[str])rZ   rw   r   rw   )rZ   rw   r   rw   r   r   r   zsubprocess.Popen)rZ   rw   r   intr   rw   r   r   )r   r   r   zOptional[bytes])3
__future__r   typingr   loggingr`   rY   r^   r   ry   r   
contextlibr   pathlibr   r   ezdxf.documentr   ezdxf.lldxf.validatorr   r	   r
   r   	getLoggerr   r   r   r   r   r!   r$   r'   rf   r   r   r[   r\   rS   rV   rc   ri   r   r   r   rx   r{   r   r   r   r   r~   r   r   r   <module>r      s   #   	      %   "  
		7	#	 		
 		Z 		J 		* 		 		8	8 
8 Z	
 Z Z Z Z Z g h h h h j  j!" j#$ ). 	HI/=
 ;?,EQV,E,E*7,EJN,E,Ed "<S
 <S	<S<S <S
 <S <S 
<SB !PK 
PKPK
PKf @   	
   @ F $ $*---*3--`	r   