Esempio n. 1
0
File: hatch.py Progetto: ptmcg/ezdxf
 def load_tags(cls, tags: Tags) -> 'EdgePath':
     edge_path = cls()
     edge_path.source_boundary_objects = pop_source_boundary_objects_tags(tags)
     edge_groups = group_tags(tags, splitcode=72)
     for edge_tags in edge_groups:
         edge_path.edges.append(edge_path.load_edge(edge_tags))
     return edge_path
Esempio n. 2
0
    def _build(self, tags: Iterator[DXFTag]) -> None:
        section_tag = next(tags)
        name_tag = next(tags)

        if section_tag != (0, 'SECTION') or name_tag != (2, 'HEADER'):
            raise DXFStructureError(
                "Critical structure error in HEADER section.")

        groups = group_tags(header_validator(tags), splitcode=9)
        custom_property_stack = []  # collect $CUSTOMPROPERTY/TAG
        for group in groups:
            name = group[0].value
            value = group[1]
            if name in ('$CUSTOMPROPERTYTAG', '$CUSTOMPROPERTY'):
                custom_property_stack.append(value.value)
            else:
                self.hdrvars[name] = HeaderVar(value)

        custom_property_stack.reverse()
        while len(custom_property_stack):
            try:
                self.custom_vars.append(tag=custom_property_stack.pop(),
                                        value=custom_property_stack.pop())
            except IndexError:  # internal exception
                break
Esempio n. 3
0
    def _setup_paths(self, tags):
        paths = []
        try:
            self.start_index = tags.tag_index(
                91)  # code 91=Number of boundary paths (loops)
            n_paths = tags[self.start_index].value
        except DXFValueError:
            raise DXFStructureError(
                "HATCH: Missing required DXF tag 'Number of boundary paths (loops)' (code=91)."
            )

        self.end_index = self.start_index + 1  # + 1 for Tag(91, Number of boundary paths)
        if n_paths == 0:  # created by ezdxf from template without path data
            return paths

        all_path_tags = tags.collect_consecutive_tags(PATH_CODES,
                                                      start=self.start_index +
                                                      1)
        self.end_index = self.start_index + len(
            all_path_tags) + 1  # + 1 for Tag(91, Number of boundary paths)
        # end_index: stored for Hatch._set_boundary_path_data()
        grouped_path_tags = group_tags(all_path_tags, splitcode=92)
        for path_tags in grouped_path_tags:
            path_type_flags = path_tags[0].value
            is_polyline_path = bool(path_type_flags & 2)
            path = PolylinePath.from_tags(
                path_tags) if is_polyline_path else EdgePath.from_tags(
                    path_tags)
            path.path_type_flags = path_type_flags
            paths.append(path)
        return paths
Esempio n. 4
0
    def load_tags(self, tags: Iterator[DXFTag]) -> None:
        """
        Constructor to generate header variables loaded from DXF files (untrusted environment)

        Args:
            tags: DXF tags as Tags() or ExtendedTags()

        """
        tags = tags or self.MIN_HEADER_TAGS
        section_tag = next(tags)
        name_tag = next(tags)

        if section_tag != (0, 'SECTION') or name_tag != (2, 'HEADER'):
            raise DXFStructureError("Critical structure error in HEADER section.")

        groups = group_tags(header_validator(tags), splitcode=9)
        custom_property_stack = []  # collect $CUSTOMPROPERTY/TAG
        for group in groups:
            name = group[0].value
            value = group[1]
            if name in ('$CUSTOMPROPERTYTAG', '$CUSTOMPROPERTY'):
                custom_property_stack.append(value.value)
            else:
                self.hdrvars[name] = HeaderVar(value)

        custom_property_stack.reverse()
        while len(custom_property_stack):
            try:
                self.custom_vars.append(tag=custom_property_stack.pop(), value=custom_property_stack.pop())
            except IndexError:  # internal exception
                break
Esempio n. 5
0
 def __init__(self, tags: Tags):
     self._dxftype = tags[0]
     self.flags = tags[1]
     self.sections = [
         Section(tags)
         for tags in group_tags(islice(tags, 2, None), splitcode=2)
     ]
Esempio n. 6
0
File: hatch.py Progetto: ptmcg/ezdxf
 def load_tags(cls, tags: Tags) -> 'BoundaryPaths':
     paths = []
     assert tags[0].code == 92
     grouped_path_tags = group_tags(tags, splitcode=92)
     for path_tags in grouped_path_tags:
         path_type_flags = path_tags[0].value
         is_polyline_path = bool(path_type_flags & 2)
         path = PolylinePath.load_tags(path_tags) if is_polyline_path else EdgePath.load_tags(path_tags)
         path.path_type_flags = path_type_flags
         paths.append(path)
     return cls(paths)
Esempio n. 7
0
    def _setup_pattern_lines(self, tags: Tags) -> List['PatternDefinitionLine']:
        try:
            self.existing_pattern_start_index = tags.tag_index(78)  # code 78=Number of patter definition lines
        except DXFValueError:  # no pattern definition lines found
            self.existing_pattern_start_index = 0
            self.existing_pattern_end_index = 0
            return []

        all_pattern_tags = tags.collect_consecutive_tags(PATTERN_DEFINITION_LINE_CODES,
                                                         start=self.existing_pattern_start_index + 1)
        self.existing_pattern_end_index = self.existing_pattern_start_index + len(
            all_pattern_tags) + 1  # + 1 for Tag(78, Number of boundary paths)
        # existing_pattern_end_index: stored for Hatch._set_pattern_data()
        grouped_line_tags = group_tags(all_pattern_tags, splitcode=53)
        return [PatternDefinitionLine.from_tags(line_tags) for line_tags in grouped_line_tags]
Esempio n. 8
0
 def test_add(self):
     for group in group_tags(internal_tag_compiler(TESTENTITIES)):
         self.space.store_tags(group)
     self.assertEqual(4, len(self.space))
Esempio n. 9
0
 def load_vertices(self, tags: Tags) -> None:
     self.vertices.extend(
         MLineVertex.load(tags) for tags in group_tags(tags, splitcode=11)
     )
Esempio n. 10
0
 def groups(tags: Iterable[DXFTag]) -> Iterable[str]:
     for group in group_tags(tags, splitcode=0):
         yield '<div class="dxf-tag-group">\n{content}\n</div>'.format(
             content=tags2html(group))
Esempio n. 11
0
def test_add_to_entity_space(space):
    for group in group_tags(internal_tag_compiler(TESTENTITIES)):
        space.store_tags(group)
    assert 4 == len(space)
Esempio n. 12
0
 def _setup_path(self, tags):
     self.source_boundary_objects = pop_source_boundary_objects_tags(tags)
     edge_groups = group_tags(tags, splitcode=72)
     for edge_tags in edge_groups:
         self.edges.append(self._setup_edge(edge_tags))
Esempio n. 13
0
 def load_tags(cls, tags: Tags) -> 'Pattern':
     grouped_line_tags = group_tags(tags, splitcode=53)
     return cls([
         PatternLine.load_tags(line_tags) for line_tags in grouped_line_tags
     ])
Esempio n. 14
0
 def _build_section_dict(d: Dict) -> None:
     for name, section in d.items():
         if name in const.MANAGED_SECTIONS:
             self.section_dict[name] = list(group_tags(section, 0))
Esempio n. 15
0
def groups():
    return list(group_tags(internal_tag_compiler(TESTTAGS)))
Esempio n. 16
0
def section():
    entities = group_tags(internal_tag_compiler(ACDSSECTION))
    return AcDsDataSection(None, entities)
Esempio n. 17
0
 def groups(tags):
     for group in group_tags(tags, splitcode=0):
         yield '<div class="dxf-tag-group">\n{content}\n</div>'.format(
             content=tags2html(group))