1 # SPDX-License-Identifier: MIT
2 # Copyright 2012 Manfred Moitzi
4 # Purpose: handle tables section
5 # Created: 21.07.2012, taken from my ezdxf project
7 from __future__
import unicode_literals
8 __author__
= "mozman <mozman@gmx.at>"
10 from .defaultchunk
import iterchunks
, DefaultChunk
11 from .layers
import LayerTable
12 from .styles
import StyleTable
13 from .linetypes
import LinetypeTable
19 'dimstyle': 'dimstyles',
24 'block_record': 'block_records',
28 def tablename(dxfname
):
29 """ Translate DXF-table-name to attribute-name. ('LAYER' -> 'layers') """
30 name
= dxfname
.lower()
31 return TABLENAMES
.get(name
, name
+'s')
34 class DefaultDrawing(object):
39 class TablesSection(object):
44 self
._create
_default
_tables
()
46 def _create_default_tables(self
):
47 for cls
in TABLESMAP
.values():
49 self
._tables
[table
.name
] = table
52 def from_tags(tags
, drawing
):
53 tables_section
= TablesSection()
54 tables_section
._setup
_tables
(tags
)
57 def _setup_tables(self
, tags
):
61 def skiptags(tags
, count
):
62 for i
in range(count
):
66 itertags
= skiptags(iter(tags
), 2) # (0, 'SECTION'), (2, 'TABLES')
67 for table
in iterchunks(itertags
, stoptag
='ENDSEC', endofchunk
='ENDTAB'):
68 table_class
= table_factory(name(table
))
69 if table_class
is not None:
70 new_table
= table_class
.from_tags(table
)
71 self
._tables
[new_table
.name
] = new_table
73 def __getattr__(self
, key
):
75 return self
._tables
[key
]
77 raise AttributeError(key
)
79 # support for further tables types are possible
83 'LTYPE': LinetypeTable
,
87 def table_factory(name
):
88 return TABLESMAP
.get(name
, None)