1 # SPDX-FileCopyrightText: 2012 Manfred Moitzi (mozman)
3 # SPDX-License-Identifier: MIT
5 # Purpose: handle tables section
6 # Created: 21.07.2012, taken from my ezdxf project
8 from __future__
import unicode_literals
9 __author__
= "mozman <mozman@gmx.at>"
11 from .defaultchunk
import iterchunks
, DefaultChunk
12 from .layers
import LayerTable
13 from .styles
import StyleTable
14 from .linetypes
import LinetypeTable
20 'dimstyle': 'dimstyles',
25 'block_record': 'block_records',
29 def tablename(dxfname
):
30 """ Translate DXF-table-name to attribute-name. ('LAYER' -> 'layers') """
31 name
= dxfname
.lower()
32 return TABLENAMES
.get(name
, name
+'s')
35 class DefaultDrawing(object):
40 class TablesSection(object):
45 self
._create
_default
_tables
()
47 def _create_default_tables(self
):
48 for cls
in TABLESMAP
.values():
50 self
._tables
[table
.name
] = table
53 def from_tags(tags
, drawing
):
54 tables_section
= TablesSection()
55 tables_section
._setup
_tables
(tags
)
58 def _setup_tables(self
, tags
):
62 def skiptags(tags
, count
):
63 for i
in range(count
):
67 itertags
= skiptags(iter(tags
), 2) # (0, 'SECTION'), (2, 'TABLES')
68 for table
in iterchunks(itertags
, stoptag
='ENDSEC', endofchunk
='ENDTAB'):
69 table_class
= table_factory(name(table
))
70 if table_class
is not None:
71 new_table
= table_class
.from_tags(table
)
72 self
._tables
[new_table
.name
] = new_table
74 def __getattr__(self
, key
):
76 return self
._tables
[key
]
78 raise AttributeError(key
)
80 # support for further tables types are possible
84 'LTYPE': LinetypeTable
,
88 def table_factory(name
):
89 return TABLESMAP
.get(name
, None)