
    Og3h                       U d dl mZ d dlmZmZmZmZmZmZ d dl	Z	d dl
mZ d dlmZmZ d dlmZmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZmZ er(d dlmZ d dlmZ d dlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( d dl)m*Z*  e	jV                  d      Z, G d d      Z-g dZ.i dddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6iZ/d7e0d8<    G d9 d:      Z1y);    )annotations)IterableIteratorOptionalTYPE_CHECKINGUnioncastN)
Dictionary)factoryis_dxf_object)const	validator)EntitySpaceEntityDB)EntityQuery)UnderlayKeyGenerator)Auditor
AuditError)Drawing)AbstractTagWriter)	GeoDataDictionaryVarDXFTagStorage	DXFObjectImageDefUnderlayDefinitionDictionaryWithDefaultXRecordPlaceholder)ImageDefReactorezdxfc                     e Zd Zd&d'dZed(d       Zd)dZd fd*dZd+dZd,dZ	d-d	Z
d.d
Zd/dZd0dZd1dZd.dZd2dZd Zed0d       Zd3dZd4dZd5dZd Zd6d7dZd8dZd9d:dZ	 d;	 	 	 d<dZd=d>dZd?d@dZd?dAdZ	 dB	 	 	 	 	 	 	 dCdZdDdZdEdFdZ d3d Z!	 d&	 	 	 	 	 	 	 dGd!Z"dHd"Z#	 dI	 	 	 	 	 	 	 dJd#Z$dKdLd$Z%d&dMd%Z&y)NObjectsSectionNc                    || _         t               | _        t               | _        || j                  t        |             y y N)docr   underlay_key_generatorr   _entity_space_builditer)selfr&   entitiess      [/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/sections/objects.py__init__zObjectsSection.__init__*   s9    &:&<#(]KKX'      c                .    | j                   j                  S )z/Returns drawing entity database. (internal API))r&   entitydbr+   s    r-   r1   zObjectsSection.entitydb1   s     xx   r/   c                    | j                   S )z$Returns entity space. (internal API)r(   r2   s    r-   get_entity_spacezObjectsSection.get_entity_space6   s    !!!r/   c                     yNT )ks    r-   <lambda>zObjectsSection.<lambda>:   s    r/   c                N    	 | j                   j                         } ||      r|S %r%   )r'   next)r+   	checkfunckeys      r-   next_underlay_keyz ObjectsSection.next_underlay_key:   s*    --224C~
 r/   c                    t        dt        |            }|j                         dk7  s|j                  d   dk7  rt	        j
                  d      |D ]  }| j                  j                  |        y )Nr   SECTION   )   OBJECTSz0Critical structure error in the OBJECTS section.)r	   r<   dxftype
base_classr   DXFStructureErrorr(   add)r+   r,   section_headentitys       r-   r)   zObjectsSection._build@   sz    OT(^<!Y.,2I2I!2L Q
 3
 ))B   	+F ""6*	+r/   c                    |j                  d       | j                  j                  |       |j                  dd       y)z0Export DXF entity by `tagwriter`. (internal API)z  0
SECTION
  2
OBJECTS
r   ENDSECN)	write_strr(   
export_dxf
write_tag2)r+   	tagwriters     r-   rN   zObjectsSection.export_dxfP   s5    :;%%i0Q)r/   c                ~    t        j                  ||| j                        }| j                  j	                  |       |S )zCreate new DXF object, add it to the entity database and to the
        entity space.

        Args:
             _type: DXF type like `DICTIONARY`
             dxfattribs: DXF attributes as dict

        (internal API)
        )r   create_db_entryr&   r(   rH   )r+   _type
dxfattribs
dxf_entitys       r-   
new_entityzObjectsSection.new_entityV   s6     ,,UJI
z*r/   c                p    | j                   j                  |       | j                  j                  |       y)zDRemove `entity` from entity space and destroy object. (internal API)N)r(   remover1   delete_entityr+   rJ   s     r-   rY   zObjectsSection.delete_entityd   s(    !!&)##F+r/   c                    | j                   }| j                  D ]  }|j                  |        | j                  j                          y)z&Delete all DXF objects. (internal API)N)r1   r(   rY   clear)r+   dbrJ   s      r-   delete_all_entitiesz"ObjectsSection.delete_all_entitiesi   s@    ]](( 	%FV$	%  "r/   c                    t        |       rt        j                  d      t        j	                  d       | j                  dd      S )zcCreate a root dictionary. Has to be the first object in the objects
        section. (internal API)z=Can not create root dictionary in none empty objects section.zCreating ROOT dictionary.0Fowner
hard_owned)lenr   rG   loggerdebugadd_dictionaryr2   s    r-   setup_rootdictzObjectsSection.setup_rootdictp   sF     t9))O  	01"""??r/   c                P     fd}d
 fd}t         D ]  }j                  |      }t        |t              r%t        j                  d| d       |dk(  r |        nj                  |d       t        |t              sot        j                  |      s |||        y	)z0Setup required management tables. (internal API)c                     j                  j                  j                  d      } j                  | j                  j                        }| j	                  |       || d<   | d<   y )NFra   )rb   NormalACAD_PLOTSTYLENAME)add_dictionary_with_defaultdxfhandleadd_placeholderset_default)plot_style_name_dictplaceholderrootdictr+   s     r-   setup_plot_style_name_tablezRObjectsSection.setup_object_management_tables.<locals>.setup_plot_style_name_table~   sp    #'#C#Cll))  $D $  ..5I5M5M5T5T.UK ,,[9-8 *-AH)*r/   c                    j                  |       }t        |t              rCj                  j                  j                  ||      rt        j                  d|  d|        y y y )Nzreset handle of table z to #)get
isinstancer
   r&   r1   reset_handlere   rf   )
table_namero   	new_tablert   r+   s      r-   restore_table_handlezKObjectsSection.setup_object_management_tables.<locals>.restore_table_handle   s]     !Z0I)Z0TXX5F5F5S5S66 5j\vhOP60r/   z	creating z dictionaryrl   F)rc   )ro   N)rz   strro   r}   returnNone)
_OBJECT_TABLE_NAMESrw   rx   r
   re   infoadd_new_dictr}   r   	is_handle)r+   rt   ru   r|   nametables   ``    r-   setup_object_management_tablesz-ObjectsSection.setup_object_management_tables{   s    	B	Q ( 	9D2:,,t2DE %,KK)D656+++-%%du%=%%)*=*=e*D$T%8	9r/   c                    t        |      r| j                  j                  |       yt        j                  d|j                          d      )z/Add `entity` to OBJECTS section. (internal API)zinvalid DXF type z for OBJECTS sectionN)r   r(   rH   r   DXFTypeErrorrE   rZ   s     r-   
add_objectzObjectsSection.add_object   sF     ""6*$$#FNN$4#55IJ r/   c                T    | j                  ||      }|j                  |d   g       |S )z+Add DXF object with reactor. (internal API)rb   )rV   set_reactors)r+   rE   rT   	dxfobjects       r-   add_dxf_object_with_reactorz*ObjectsSection.add_dxf_object_with_reactor   s.    OOGZ8	
7 345r/   c                8    | j                   j                          y r%   )r(   purger2   s    r-   r   zObjectsSection.purge   s      "r/   c                V    t        |       r| j                  d   S | j                         S )z[Returns the root DICTIONARY, or as AutoCAD calls it:
        the named DICTIONARY.
        r   )rd   r(   rh   r2   s    r-   rt   zObjectsSection.rootdict   s+    
 t9%%a((&&((r/   c                ,    t        | j                        S )z<Returns the count of all DXF objects in the OBJECTS section.)rd   r(   r2   s    r-   __len__zObjectsSection.__len__   s    4%%&&r/   c                ,    t        | j                        S )z>Returns an iterator of all DXF objects in the OBJECTS section.)r*   r(   r2   s    r-   __iter__zObjectsSection.__iter__   s    D&&''r/   c                     | j                   |   S )a  Get entity at `index`.

        The underlying data structure for storing DXF objects is organized like
        a standard Python list, therefore `index` can be any valid list indexing
        or slicing term, like a single index ``objects[-1]`` to get the last
        entity, or an index slice ``objects[:10]`` to get the first 10 or fewer
        objects as ``list[DXFObject]``.

        r4   )r+   indexs     r-   __getitem__zObjectsSection.__getitem__   s     !!%((r/   c                |    t        |t              r	 | j                  |   }|| j                  v S # t        $ r Y yw xY w)zReturns ``True`` if `entity` stored in OBJECTS section.

        Args:
             entity: :class:`DXFObject` or handle as hex string

        F)rx   r}   r1   KeyErrorr(   rZ   s     r-   __contains__zObjectsSection.__contains__   sH     fc"v. ++++  s   / 	;;c                ,    t        t        |       |      S )z<Get all DXF objects matching the :ref:`entity query string`.)r   r*   )r+   querys     r-   r   zObjectsSection.query   s    4:u--r/   c                R   | j                   |j                   u sJ d       | j                  D ]M  }t        |      r|j                  t        j
                  dt        |       d       |j                  |       O | j                  |       | j                  j                  |       y)aD  Audit and repair OBJECTS section.

        .. important::

            Do not delete entities while auditing process, because this
            would alter the entity database while iterating, instead use::

                auditor.trash(entity)

            to delete invalid entities after auditing automatically.

        z#Auditor for different DXF document.zRemoved invalid DXF entity z from OBJECTS section.codemessageN)
r&   r(   r   fixed_errorr   REMOVED_INVALID_DXF_OBJECTr}   trashreorgaudit)r+   auditorrJ   s      r-   r   zObjectsSection.audit   s     xx7;;&M(MM&(( 	&F (###>>9#f+ G, - $ 
 f%	& 	

7  )r/   c                N    | j                  d||d      }t        t        |      S )zAdd new :class:`~ezdxf.entities.Dictionary` object.

        Args:
            owner: handle to owner as hex string.
            hard_owned: ``True`` to treat entries as hard owned.

        
DICTIONARYra   rT   )rV   r	   r
   )r+   rb   rc   rJ   s       r-   rg   zObjectsSection.add_dictionary  s4     ( ! 
 J''r/   c                H    | j                  d|||d      }t        d|      S )zAdd new :class:`~ezdxf.entities.DictionaryWithDefault` object.

        Args:
            owner: handle to owner as hex string.
            default: handle to default entry.
            hard_owned: ``True`` to treat entries as hard owned.

        ACDBDICTIONARYWDFLT)rb   defaultrc   r   r   rV   r	   )r+   rb   r   rc   rJ   s        r-   rm   z*ObjectsSection.add_dictionary_with_default  s8     !"( ! 
 +V44r/   c                .    | j                  d||d      S )zAdd a new :class:`~ezdxf.entities.DictionaryVar` object.

        Args:
            owner: handle to owner as hex string.
            value: value as string

        DICTIONARYVAR)rb   valuer   rV   )r+   rb   r   s      r-   add_dictionary_varz!ObjectsSection.add_dictionary_var'  s$     %%(H  
 	
r/   c                ,    | j                  dd|i      S )z}Add a new :class:`~ezdxf.entities.XRecord` object.

        Args:
            owner: handle to owner as hex string.

        XRECORDrb   r   r   r+   rb   s     r-   add_xrecordzObjectsSection.add_xrecord3  s     ygu5EFFr/   c                ,    | j                  dd|i      S )zAdd a new :class:`~ezdxf.entities.Placeholder` object.

        Args:
            owner: handle to owner as hex string.

        ACDBPLACEHOLDERrb   r   r   r   s     r-   rp   zObjectsSection.add_placeholder<  s$     7E*:  
 	
r/   c           	        t         j                  j                  |d      }	 | j                  d   }||j                  _        ||j                  _        ||j                  _        y# t         j                  $ rH | j                  d| j                  j                  j                  |||d      }|| j                  d<   Y yw xY w)ay  Set raster variables.

        Args:
            frame: ``0`` = do not show image frame; ``1`` = show image frame
            quality: ``0`` = draft; ``1`` = high
            units: units for inserting images. This defines the real world unit for one
                drawing unit for the purpose of inserting and scaling images with an
                associated resolution.

                   ===== ===========================
                   mm    Millimeter
                   cm    Centimeter
                   m     Meter (ezdxf default)
                   km    Kilometer
                   in    Inch
                   ft    Foot
                   yd    Yard
                   mi    Mile
                   none  None
                   ===== ===========================

        (internal API), public interface :meth:`~ezdxf.drawing.Drawing.set_raster_variables`

        r   ACAD_IMAGE_VARSRASTERVARIABLES)rb   framequalityunitsr   N)r   RASTER_UNITSrw   rt   rn   r   r   r   DXFKeyErrorr   ro   )r+   r   r   r   units_raster_varss         r-   set_raster_variablesz#ObjectsSection.set_raster_variablesI  s    6 ((,,UA6	+--(9:K %*KOO!&-KOO#$*KOO!    
	;::!!]]..55"&#	 ; K 0;DMM+,
	;s   A% %AC ?C c                   	 | j                   d   }|j                  j                  |j                  j
                  t        j                  j                  |j                  j                  d      fS # t        j                  $ r Y yw xY w)Nr   )r   rB   noner   )	rt   r   r   rn   r   r   REVERSE_RASTER_UNITSrw   r   )r+   r   s     r-   get_raster_variablesz#ObjectsSection.get_raster_variablesw  sv    	 --(9:K OO!!OO##&&**;??+@+@&I
 	
    	 	 s   A0 0BBc                "   	 | j                   d   }t        |      |j                  _        y# t        j
                  $ rO | j                  d| j                   j                  j                  t        |      d      }|| j                   d<   Y yw xY w)zSet wipeout variables.

        Args:
            frame: ``0`` = do not show image frame; ``1`` = show image frame

        (internal API)
        ACAD_WIPEOUT_VARSWIPEOUTVARIABLES)rb   r   r   N)rt   intrn   r   r   r   r   ro   )r+   r   wipeout_varss      r-   set_wipeout_variablesz$ObjectsSection.set_wipeout_variables  s    	0==)<=L &)ZL"    	>;;"!]]..55 Z < L 2>DMM-.	>s   , ABBc                    	 | j                   d   }|j                  j                  S # t        j                  $ r Y yw xY w)Nr   r   )rt   r   r   rn   r   )r+   r   s     r-   get_wipeout_frame_settingz(ObjectsSection.get_wipeout_frame_setting  sD    	==)<=L %%%    		s   ' ==c                    ||}| j                   j                  d      }| j                  d|j                  j                  ||d      }|||<   t        d|      S )a  Add an image definition to the objects section.

        Add an :class:`~ezdxf.entities.image.ImageDef` entity to the drawing
        (objects section). `filename` is the image file name as relative or
        absolute path and `size_in_pixel` is the image size in pixel as (x, y)
        tuple. To avoid dependencies to external packages, `ezdxf` can not
        determine the image size by itself. Returns a :class:`~ezdxf.entities.image.ImageDef`
        entity which is needed to create an image reference. `name` is the
        internal image name, if set to ``None``, name is auto-generated.

        Absolute image paths works best for AutoCAD but not really good, you
        have to update external references manually in AutoCAD, which is not
        possible in TrueView. If the drawing units differ from 1 meter, you also
        have to use: :meth:`set_raster_variables`.

        Args:
            filename: image file name (absolute path works best for AutoCAD)
            size_in_pixel: image size in pixel as (x, y) tuple
            name: image name for internal use, None for using filename as name
                (best for AutoCAD)

        ACAD_IMAGE_DICTIMAGEDEF)rb   filename
image_sizer   r   )rt   get_required_dictr   rn   ro   r	   )r+   r   size_in_pixelr   
image_dict	image_defs         r-   add_image_defzObjectsSection.add_image_def  sl    8 <D]]445FG
44#..$+ 5 
	 %
4J	**r/   c                F    | j                  d||d      }t        d|      S )zZAdd required IMAGEDEF_REACTOR object for IMAGEDEF object.

        (internal API)
        IMAGEDEF_REACTOR)rb   image_handler   r    r   )r+   r   image_def_reactors      r-   add_image_def_reactorz$ObjectsSection.add_image_def_reactor  s7    
 !OO% , , 
 %'899r/   c                t   |j                         }|dv rd| d}| d}nt        j                  d| d      ||dk(  rd}n
|d	k(  rd
}nd}| j                  j	                  |      | j                  |j                  j                  ||d      }| j                  fd      }||<   t        d|      S )a  Add an :class:`~ezdxf.entities.underlay.UnderlayDefinition` entity
        to the drawing (OBJECTS section). `filename` is the underlay file name
        as relative or absolute path and `fmt` as string (pdf, dwf, dgn).
        The underlay definition is required to create an underlay reference.

        Args:
            filename: underlay file name
            fmt: file format as string ``'pdf'|'dwf'|'dgn'``
            name: pdf format = page number to display; dgn format = ``'default'``; dwf: ????

        )PDFDWFDGNACAD_DEFINITIONS
DEFINITIONzUnsupported file format: ''r   1r   r   Model)rb   r   r   r   c                    | vS r%   r8   )r9   underlay_dicts    r-   r:   z1ObjectsSection.add_underlay_def.<locals>.<lambda>  s    q/E r/   r   )
upperr   DXFValueErrorrt   r   rV   rn   ro   r?   r	   )	r+   r   fmtr   underlay_dict_nameunderlay_def_entityunderlay_defr>   r   s	           @r-   add_underlay_defzObjectsSection.add_underlay_def  s     iik''#([!9%(E"4%%(B3%q&IJJ<e| 778JK&**11$ ' 
 $$%EF)c(,77r/   c                L    |i }||d<   t        d| j                  d|            S )a  Creates a new :class:`GeoData` entity and replaces existing ones.
        The GEODATA entity resides in the OBJECTS section and NOT in the layout
        entity space, and it is linked to the layout by an extension dictionary
        located in BLOCK_RECORD of the layout.

        The GEODATA entity requires DXF version R2010+. The DXF Reference does
        not document if other layouts than model space supports geo referencing,
        so getting/setting geo data may only make sense for the model space
        layout, but it is also available in paper space layouts.

        Args:
            owner: handle to owner as hex string
            dxfattribs: DXF attributes for :class:`~ezdxf.entities.GeoData` entity

        rb   r   GEODATA)r	   r   )r+   rb   rT   s      r-   add_geodatazObjectsSection.add_geodata  s3      J#
7It??	:VWWr/   c                    |(| j                   J d       t        | j                         }t        ||       }|j                          |S )z;Validate and recreate the integrity of the OBJECTS section.zvalid document required)r&   r   
_Sanitizerexecute)r+   r   	sanitizers      r-   r   zObjectsSection.reorg  sH    ?88'B)BB'dhh'Gw-	r/   r%   )r&   r   r,   zOptional[Iterable[DXFObject]])r~   r   )r~   r   )r~   r}   )r,   Iterator[DXFObject]r~   r   )rP   r   r~   r   )rS   r}   rT   dictr~   r   )rJ   r   r~   r   r~   r   )r~   r
   )rt   r
   r~   r   )rE   r}   r~   r   )r~   r   )r~   r   )r~   r   )*)r   r}   r~   r   )r   r   r~   r   )r`   T)rb   r}   rc   boolr~   r
   )r`   r`   T)rc   r   r~   r   )r`    )rb   r}   r   r}   r~   r   )r`   )rb   r}   r~   r   )rb   r}   r~   r   )r   rB   m)r   r   r   r   r   r}   r~   r   )r~   ztuple[int, int, str])r   )r   r   r~   r   )r   r}   r   ztuple[int, int]r   Optional[str]r~   r   )r   r}   r~   r    )pdfN)r   r}   r   r}   r   r   r~   r   )r`   N)rb   r}   r~   r   )r   zOptional[Auditor]r~   r   )'__name__
__module____qualname__r.   propertyr1   r5   r?   r)   rN   rV   rY   r^   rh   r   r   r   r   rt   r   r   r   r   r   r   rg   rm   r   r   rp   r   r   r   r   r   r   r   r   r   r8   r/   r-   r#   r#   )   sh   ( ! !" +9 + *,
#	@'9R#
 ) )'(
),.*2($ :>5265	5*

G	
 >A,+,+'*,+7:,+	,+\	
0,& #	(+(+ '(+ 	(+
 
(+T: FJ*8*8"%*85B*8	*8XX*r/   r#   )
ACAD_COLOR
ACAD_GROUPACAD_LAYOUTACAD_MATERIALACAD_MLEADERSTYLEACAD_MLINESTYLEACAD_PLOTSETTINGSrl   ACAD_SCALELISTACAD_TABLESTYLEACAD_VISUALSTYLEr  DBCOLORr  GROUPr   r   ACAD_DETAILVIEWSTYLEACDBDETAILVIEWSTYLEr  LAYOUTr	  MATERIALr
  MLEADERSTYLEr  
MLINESTYLEr  PLOTSETTINGSACAD_RENDER_ACTIVE_SETTINGSMENTALRAYRENDERSETTINGSr  SCALEACAD_SECTIONVIEWSTYLEACDBSECTIONVIEWSTYLEr  
TABLESTYLEACAD_PDFDEFINITIONSPDFDEFINITIONACAD_DWFDEFINITIONSDWFDEFINITIONACAD_DGNDEFINITIONSDGNDEFINITIONr  VISUALSTYLEAcDbVariableDictionaryr   zdict[str, str]KNOWN_DICT_CONTENTc                  P    e Zd ZddZddZdddZddZddZddZd Z	d Z
d	 Zy
)r   c                P    || _         || _        |j                  | _        d| _        y r7   )objectsr   rt   removed_entity)r+   r   r*  s      r-   r.   z_Sanitizer.__init__G  s%    (("r/   c              #  X   K   | j                   D ]  }t        |t              s|  y wr%   )r*  rx   r
   )r+   ds     r-   dictionariesz_Sanitizer.dictionariesM  s(      	A!Z(	s    **c                   | j                          | j                          d}d| _        | j                  rC||k  r>|dz  }d| _        | j                          | j	                          | j                  r||k  r>| j                          y )Nr   TrB   F)+restore_owner_handles_of_dictionary_entriesvalidate_known_dictionariesr+  remove_orphaned_dictionariesaudit_objectscreate_required_structures)r+   	max_loopsloopss      r-   r   z_Sanitizer.executeR  s    88:((*"!!ei&7QJE"'D--/   !!ei&7 	'')r/   c                
   	
 d fd}	
 fd} j                   j                  } j                         D ]  g 
j                  j                  j                         D ]  \  	t        t              r |        j                  j                  d      }|k(  r?|j                  |      }t        |t              r|j                        r |        y |         
D ]  	j                  	         y )Nc                      j                   _        j                  j                  t        j
                  d d       y )NzFixed invalid owner handle of .)rn   rb   r   r   r   INVALID_OWNER_HANDLE)dict_handlerJ   r+   s   r-   reclaim_entityzN_Sanitizer.restore_owner_handles_of_dictionary_entries.<locals>.reclaim_entitya  s6    *FJJLL$$//0:r/   c            	         j                         j                  j                  t        j                  d dt                d       y )NzRemoved invalid key z in r9  )appendr   r   r   r:  r}   )
dictionaryr>   r   r+   s   r-   	purge_keyzI_Sanitizer.restore_owner_handles_of_dictionary_entries.<locals>.purge_keyh  sA    LLLL$$//&se4J/@Br/   rb   r   )r   r1   r.  rn   ro   itemsrx   r}   rw   r
   find_keydiscard)r+   r<  r@  r1   owner_handleparent_dictr;  r?  rJ   r>   r   s   `     @@@@@r-   r0  z6_Sanitizer.restore_owner_handles_of_dictionary_entries`  s    		 <<((++- 	(J!E$..//K)//1 %Vfc*K%zz~~g6;.&ll<8k:6;;O;OPV;WK"$%  (""3'(#	(r/   c                L   fd}| j                   j                  | j                  }| j                         D ]g  |u rj	                  j
                  j	                  d            }| |        <t        |t              sM|j                        }|ra |        i y )Nc                 H    j                           j                          y r%   )rC  _silent_kill)r?  r1   s   r-   kill_dictionaryz@_Sanitizer.remove_orphaned_dictionaries.<locals>.kill_dictionary  s    Z(##%r/   rb   )	r   r1   rt   r.  rw   rn   rx   r
   rB  )r+   rI  rt   rb   r>   r?  r1   s        @@r-   r2  z'_Sanitizer.remove_orphaned_dictionaries  s    	& <<((==++- 	"JX%LL!3!3G!<=E}  !eZ0..,C!!	"r/   c                   ddl m} | j                  }t        j	                         D ]  \  }}| j
                  j                  |      }t        |t              s2g }|j	                         D ]t  \  }}t        ||      s|j                         |k7  s'|j                  t        j                  d| d| d| d|        |j                  |       |j                  |       v |D ]  }|j                  |         y )Nr   )	DXFEntityzRemoved invalid type z from <z>, expected type )ezdxf.entitiesrK  r   r'  rA  rt   rw   rx   r
   rE   r   r   r   r>  r   rC  )	r+   rK  r   	dict_nameexpected_typeobject_dict
purge_keysr>   entrys	            r-   r1  z&_Sanitizer.validate_known_dictionaries  s    ,,,(:(@(@(B 	)$I}--++I6Kk:6$&J)//1 )
UeY/EMMO}4T''"==/wf[M9+ V))69
 %%c*MM%() " )##C()	)r/   c                   | j                   j                  | j                         | j                   j                  }|j                  j                          |j                  j                          |j                  j                          |j                  j                          |j                  j                          |j                  j                          |j                  j                          y r%   )
r*  r   rt   r&   	materialsupdate_object_dictcreate_required_entriesmline_stylesmleader_stylesgroups)r+   r&   s     r-   r4  z%_Sanitizer.create_required_structures  s    33DMMBll((*--/++-002--/224

%%'r/   c                    | j                   j                          | j                   j                  j                          y r%   )r   empty_trashcanr1   r   r2   s    r-   cleanup_entitydbz_Sanitizer.cleanup_entitydb  s(    ##%##%r/   c                   | j                          | j                  }t        |j                        }| j                  D ]  }|j
                  j                  d      s@|j                  t        j                  dt        |       d       |j                  |       ^|j                  |       |j                  |        |j                          |t        |j                        k7  rd| _        y y )Nrb   zDeleted z entity without owner handle.r   T)r\  r   rd   r1   r*  rn   hasattrr   r   r:  r}   r   check_owner_existr   r[  r+  )r+   r   current_db_sizerJ   s       r-   r3  z_Sanitizer.audit_objects  s    ,,g../ll 
	"F::%%g.###88&s6{m3PQ $  f%%%f-LL!
	" 	 c'"2"233"&D 4r/   N)r   r   r*  r#   r~   r   )r~   zIterator[Dictionary])d   r   )r  r  r  r.   r.  r   r0  r2  r1  r4  r\  r3  r8   r/   r-   r   r   F  s0    #
*"(H"2)*
(&'r/   r   )2
__future__r   typingr   r   r   r   r   r	   loggingezdxf.entities.dictionaryr
   rM  r   r   ezdxf.lldxfr   r   ezdxf.entitydbr   r   ezdxf.queryr   ezdxf.tools.handler   ezdxf.auditr   r   ezdxf.documentr   ezdxf.lldxf.tagwriterr   r   r   r   r   r   r   r   r   r   ezdxf.entities.imager    	getLoggerre   r#   r   r'  __annotations__r   r8   r/   r-   <module>rp     sd   #   0 1 ( 0 # 3 +&7
 
 
 5			7	#v vr &)&'& z& 1	&
 8& Z& & |& & "#<& g& 3& |& ?& ?&  ?!&" #&$ o%& N ,O' O'r/   