diff options
Diffstat (limited to 'io_import_dxf/dxfgrabber')
-rw-r--r-- | io_import_dxf/dxfgrabber/__init__.py | 2 | ||||
-rw-r--r-- | io_import_dxf/dxfgrabber/dxfentities.py | 4 | ||||
-rwxr-xr-x | io_import_dxf/dxfgrabber/sections.py | 4 | ||||
-rw-r--r-- | io_import_dxf/dxfgrabber/tags.py | 31 |
4 files changed, 28 insertions, 13 deletions
diff --git a/io_import_dxf/dxfgrabber/__init__.py b/io_import_dxf/dxfgrabber/__init__.py index 2581a404..5fe0fefa 100644 --- a/io_import_dxf/dxfgrabber/__init__.py +++ b/io_import_dxf/dxfgrabber/__init__.py @@ -3,7 +3,7 @@ # Created: 21.07.2012 # License: MIT License -version = (0, 8, 1) +version = (0, 8, 4) VERSION = "%d.%d.%d" % version __author__ = "mozman <mozman@gmx.at>" diff --git a/io_import_dxf/dxfgrabber/dxfentities.py b/io_import_dxf/dxfgrabber/dxfentities.py index 5c83a882..4dfcd3c9 100644 --- a/io_import_dxf/dxfgrabber/dxfentities.py +++ b/io_import_dxf/dxfgrabber/dxfentities.py @@ -190,8 +190,8 @@ class Text(DXFEntity): self.halign = 0 self.valign = 0 self.align_point = None - self.font = "" - self.big_font = "" + self.font = None + self.big_font = None def setup_attributes(self, tags): for code, value in super(Text, self).setup_attributes(tags): diff --git a/io_import_dxf/dxfgrabber/sections.py b/io_import_dxf/dxfgrabber/sections.py index 286ebf09..697263db 100755 --- a/io_import_dxf/dxfgrabber/sections.py +++ b/io_import_dxf/dxfgrabber/sections.py @@ -33,14 +33,12 @@ class Sections(object): def name(section): return section[1].value - bootstrap = True for section in iterchunks(tagreader, stoptag='EOF', endofchunk='ENDSEC'): - if bootstrap: + if name(section) == 'HEADER': new_section = HeaderSection.from_tags(section) drawing.dxfversion = new_section.get('$ACADVER', 'AC1009') codepage = new_section.get('$DWGCODEPAGE', 'ANSI_1252') drawing.encoding = toencoding(codepage) - bootstrap = False else: section_name = name(section) if section_name in SECTIONMAP: diff --git a/io_import_dxf/dxfgrabber/tags.py b/io_import_dxf/dxfgrabber/tags.py index b406bd02..89354b8c 100644 --- a/io_import_dxf/dxfgrabber/tags.py +++ b/io_import_dxf/dxfgrabber/tags.py @@ -38,6 +38,23 @@ def is_point_tag(tag): return tag[0] in POINT_CODES +infinite = float('inf') +neg_infinite = float('-inf') + + +def to_float_with_infinite(value): + try: + return float(value) + except ValueError: + value = value.lower().strip() + if value.startswith('inf'): + return infinite + if value.startswith('-inf'): + return neg_infinite + else: + raise + + class TagCaster: def __init__(self): self._cast = self._build() @@ -74,14 +91,14 @@ class TagCaster: TYPES = [ (tostr, range(0, 10)), (point_tuple, range(10, 20)), - (float, range(20, 60)), + (to_float_with_infinite, range(20, 60)), (int, range(60, 100)), (tostr, range(100, 106)), (point_tuple, range(110, 113)), - (float, range(113, 150)), + (to_float_with_infinite, range(113, 150)), (int, range(170, 180)), (point_tuple, [210]), - (float, range(211, 240)), + (to_float_with_infinite, range(211, 240)), (int, range(270, 290)), (int, range(290, 300)), # bool 1=True 0=False (tostr, range(300, 370)), @@ -92,12 +109,12 @@ TYPES = [ (int, range(420, 430)), (tostr, range(430, 440)), (int, range(440, 460)), - (float, range(460, 470)), + (to_float_with_infinite, range(460, 470)), (tostr, range(470, 480)), (tostr, range(480, 482)), (tostr, range(999, 1010)), (point_tuple, range(1010, 1020)), - (float, range(1020, 1060)), + (to_float_with_infinite, range(1020, 1060)), (int, range(1060, 1072)), ] @@ -121,8 +138,8 @@ def stream_tagger(stream, assure_3d_coords=False): value = stream.readline() line.counter += 2 if code and value: # StringIO(): empty strings indicates EOF - return DXFTag(int(code[:-1]), value[:-1]) # without '\n' - else: # StringIO(): missing '\n' indicates EOF + return DXFTag(int(code.rstrip('\r\n')), value.rstrip('\r\n')) # without line ending + else: # StringIO(): empty lines indicates EOF raise EOFError() while True: |