예제 #1
0
def read(stream: BinaryIO,
         errors: str = 'surrogateescape') -> Tuple['Drawing', 'Auditor']:
    """ Read a DXF document from a binary-stream similar to :func:`ezdxf.read`,
    but this function will detect the text encoding automatically and repair
    as much flaws as possible, runs the required audit process afterwards
    and returns the DXF document and the :class:`Auditor`.

    Args:
        stream: data stream to load in binary read mode
        errors: specify decoding error handler

            - "surrogateescape" to preserve possible binary data (default)
            - "ignore" to use the replacement char U+FFFD "\ufffd" for invalid data
            - "strict" to raise an :class:`UnicodeDecodeError` exception for invalid data

    Raises:
        DXFStructureError: for invalid or corrupted DXF structures
        UnicodeDecodeError: if `errors` is "strict" and a decoding error occurs

    """
    from ezdxf.document import Drawing
    recover_tool = Recover.run(stream, errors=errors)
    doc = Drawing()
    doc._load_section_dict(recover_tool.section_dict)

    auditor = Auditor(doc)
    for code, msg in recover_tool.errors:
        auditor.add_error(code, msg)
    for code, msg in recover_tool.fixes:
        auditor.fixed_error(code, msg)
    auditor.run()
    return doc, auditor
예제 #2
0
def _load_and_audit_document(recover_tool) -> Tuple['Drawing', 'Auditor']:
    from ezdxf.document import Drawing

    doc = Drawing()
    doc._load_section_dict(recover_tool.section_dict)

    auditor = Auditor(doc)
    for code, msg in recover_tool.errors:
        auditor.add_error(code, msg)
    for code, msg in recover_tool.fixes:
        auditor.fixed_error(code, msg)
    auditor.run()
    return doc, auditor
예제 #3
0
def read(stream: BinaryIO) -> 'Drawing':
    """ Read a DXF document from a binary-stream similar to :func:`ezdxf.read`,
    But this function will detect the text encoding automatically and repair
    as much flaws as possible to take the document to a state, where the
    :class:`~ezdxf.audit.Auditor` could start his journey to repair further issues.

    Args:
        stream: data stream to load in binary read mode

    """
    from ezdxf.document import Drawing
    recover_tool = Recover.run(stream)
    doc = Drawing()
    doc._load_section_dict(recover_tool.section_dict)
    return doc
예제 #4
0
파일: recover.py 프로젝트: ericgcc/ezdxf
def read(stream: BinaryIO) -> Tuple['Drawing', 'Auditor']:
    """ Read a DXF document from a binary-stream similar to :func:`ezdxf.read`,
    but this function will detect the text encoding automatically and repair
    as much flaws as possible, runs the required audit process afterwards
    and returns the DXF document and the :class:`Auditor`.

    Args:
        stream: data stream to load in binary read mode

    """
    from ezdxf.document import Drawing
    recover_tool = Recover.run(stream)
    doc = Drawing()
    doc._load_section_dict(recover_tool.section_dict)
    return doc, doc.audit()
예제 #5
0
def read(stream: TextIO,
         legacy_mode: bool = True,
         dxfversion: str = None) -> 'Drawing':
    """
    Read DXF drawing from a text stream, which only needs a readline() method.

    Supported DXF versions:

    - pre AC1009 DXF versions will be upgraded to AC1009, requires encoding set by header var $DWGCODEPAGE
    - AC1009: AutoCAD R12 (DXF R12), requires encoding set by header var $DWGCODEPAGE
    - AC1012: AutoCAD R13 upgraded to AC1015, requires encoding set by header var $DWGCODEPAGE
    - AC1014: AutoCAD R14 upgraded to AC1015, requires encoding set by header var $DWGCODEPAGE
    - AC1015: AutoCAD 2000, requires encoding set by header var $DWGCODEPAGE
    - AC1018: AutoCAD 2004, requires encoding set by header var $DWGCODEPAGE
    - AC1021: AutoCAD 2007, requires encoding='utf-8'
    - AC1024: AutoCAD 2010, requires encoding='utf-8'
    - AC1027: AutoCAD 2013, requires encoding='utf-8'
    - AC1032: AutoCAD 2018, requires encoding='utf-8'

    To detect the required encoding, use the helper function info=dxf_stream_info(stream)
    and reopen the stream with the detected info.encoding.

    Args:
        stream: input text stream opened with correct encoding, requires only a readline() method.
        legacy_mode:  True - adds an extra trouble shooting import layer; False - requires DXF file from modern CAD apps
        dxfversion: DXF version, None = auto detect, just important for legacy mode.

    """
    from ezdxf.drawing import Drawing

    return Drawing.read(stream, legacy_mode=legacy_mode, dxfversion=dxfversion)
예제 #6
0
def new(dxfversion: str = 'AC1009',
        setup: Union[str, bool, Sequence[str]] = None) -> 'Drawing':
    """
    Create a new DXF drawing.

    new() can create drawings for following DXF versions:

    - AC1009 or R12: AutoCAD R12 (DXF R12)
    - AC1015 or R2000: AutoCAD 2000 (DXF R2000)
    - AC1018 or R2004: AutoCAD 2004 (DXF R2004)
    - AC1021 or R2007: AutoCAD 2007 (DXF R2007)
    - AC1024 or R2010: AutoCAD 2010 (DXF R2010)
    - AC1027 or R2013: AutoCAD 2013 (DXF R2013)
    - AC1032 or R2018: AutoCAD 2018 (DXF R2018)

    Args:
        dxfversion: DXF version specifier, default is AC1009
        setup: setup drawing standard for linetypes, text styles, dimension styles
               None or False: no setup
               'all' or True: setup all
               list of topics as strings:
                  - 'linetypes' ... setup line types
                  - 'styles'  ... setup text styles
                  - 'dimstyles ... setup all dimension styles
                  - 'dimstyles:metric' ... setup metric dimension styles
                  - 'dimstyles:imperial' ... setup imperial dimension styles (not implemented yet)

    """
    from ezdxf.drawing import Drawing

    dwg = Drawing.new(dxfversion)
    if dwg.dxfversion > 'AC1009':
        dwg.reset_fingerprintguid()
        dwg.reset_versionguid()
    if setup:
        setup_drawing(dwg, topics=setup)
    return dwg