Esempio n. 1
0
    def _setup_paths(self, tags: Tags) -> List['PolylinePath']:
        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. 2
0
    def extract_block_attribs(data: Tags) -> List[AttribData]:
        def store_attrib():
            attribs.append(
                AttribData(
                    collector.get(330, '0'),  # ATTDEF handle
                    collector.get(177, 0),  # ATTDEF index
                    collector.get(44, 1.0),  # ATTDEF width
                    collector.get(302, ''),  # ATTDEF text (content)
                ))
            collector.clear()

        attribs = []
        try:
            start = data.tag_index(330)
        except const.DXFValueError:
            return attribs

        end = start
        collector = dict()
        for code, value in data.collect_consecutive_tags({330, 177, 44, 302},
                                                         start):
            end += 1
            if code == 330 and len(collector):
                store_attrib()
            collector[code] = value
        if len(collector):
            store_attrib()

        # Remove processed tags:
        del data[start:end]
        return attribs
Esempio n. 3
0
    def extract_arrow_heads(data: Tags) -> List[ArrowHeadData]:
        def store_head():
            heads.append(
                ArrowHeadData(
                    collector.get(94, 0),  # arrow head index
                    collector.get(345, '0'),  # arrow head handle
                ))
            collector.clear()

        heads = []
        try:
            start = data.tag_index(94)
        except const.DXFValueError:
            return heads

        end = start
        collector = dict()
        for code, value in data.collect_consecutive_tags({94, 345}, start):
            end += 1
            collector[code] = value
            if code == 345:
                store_head()

        # Remove processed tags:
        del data[start:end]
        return heads
Esempio n. 4
0
File: hatch.py Progetto: ptmcg/ezdxf
    def load_pattern(self, tags: Tags) -> Tags:
        try:
            index = tags.tag_index(78)  # code 78=Number of patter definition lines
        except const.DXFValueError:  # no pattern definition lines found
            return tags

        pattern_tags = tags.collect_consecutive_tags(PATTERN_DEFINITION_LINE_CODES, start=index + 1)
        self.pattern = Pattern.load_tags(pattern_tags)

        # delete pattern data including length tag 78
        del tags[index: index + len(pattern_tags) + 1]
        return tags
Esempio n. 5
0
File: hatch.py Progetto: ptmcg/ezdxf
    def load_seeds(self, tags: Tags) -> Tags:
        try:
            start_index = tags.tag_index(98)
        except const.DXFValueError:
            return tags
        seed_data = tags.collect_consecutive_tags({98, 10, 20}, start=start_index)

        # remove seed data from tags
        del tags[start_index: start_index + len(seed_data) + 1]

        # just process vertices with group code 10
        self.seeds = [value for code, value in seed_data if code == 10]

        return tags
Esempio n. 6
0
File: hatch.py Progetto: ptmcg/ezdxf
    def load_paths(self, tags: Tags) -> Tags:
        # find first group code 91 = count of loops, Spline data also contains group code 91!
        try:
            start_index = tags.tag_index(91)
        except const.DXFValueError:
            raise const.DXFStructureError(
                "HATCH: Missing required DXF tag 'Number of boundary paths (loops)' (code=91).")

        path_tags = tags.collect_consecutive_tags(PATH_CODES, start=start_index + 1)
        if len(path_tags):
            self.paths = BoundaryPaths.load_tags(path_tags)
        end_index = start_index + len(path_tags) + 1
        del tags[start_index: end_index]
        return tags
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 load_arrow_heads(data: Tags) -> List[ArrowHeadData]:
        def store_head():
            heads.append(ArrowHeadData(
                collector.get(94, 0),  # arrow head index
                collector.get(345, '0'),  # arrow head handle
            ))
            collector.clear()

        heads = []
        try:
            start = data.tag_index(94)
        except const.DXFValueError:
            return heads

        collector = dict()
        for code, value in data.collect_consecutive_tags({94, 345}, start):
            collector[code] = value
            if code == 345:
                store_head()
        return heads
Esempio n. 9
0
 def test_emtpy_tags(self):
     tags = Tags()
     collected_tags = tags.collect_consecutive_tags([0, 1, 2, 3, 4])
     self.assertEqual(0, len(collected_tags))
Esempio n. 10
0
 def test_emtpy_tags(self):
     tags = Tags()
     collected_tags = tags.collect_consecutive_tags([0, 1, 2, 3, 4])
     assert 0 == len(collected_tags)