Exemple #1
0
 def _get_seed_point_index(self, hatch_tags: Tags) -> int:
     try:
         seed_count_index = hatch_tags.tag_index(98)  # find index of 'Number of seed points'
     except DXFValueError:
         raise DXFStructureError("HATCH: Missing required DXF tag 'Number of seed points' (code=98).")
     try:
         first_seed_point_index = hatch_tags.tag_index(10, seed_count_index + 1)
     except DXFValueError:
         raise DXFStructureError("HATCH: Missing required DXF tags 'seed point X value' (code=10).")
     return first_seed_point_index
Exemple #2
0
 def from_tags(tags: Tags) -> 'GradientData':
     gdata = GradientData()
     try:
         index = tags.tag_index(
             450)  # required tag if hatch has gradient data
     except DXFValueError:
         raise DXFStructureError(
             "HATCH: Missing required DXF tag for gradient data (code=450)."
         )
     # if tags[index].value == 0 hatch is a solid ????
     first_color_value = True
     for code, value in tags[index:]:
         if code == 460:
             gdata.rotation = (value / math.pi) * 180.  # radians to grad
         elif code == 461:
             gdata.centered = value
         elif code == 452:
             gdata.one_color = value
         elif code == 462:
             gdata.tint = value
         elif code == 470:
             gdata.name = value
         elif code == 421:
             # code == 63 color as ACI, can be ignored
             if first_color_value:
                 gdata.color1 = int2rgb(value)
                 first_color_value = False
             else:
                 gdata.color2 = int2rgb(value)
     return gdata
Exemple #3
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
Exemple #4
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
Exemple #5
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
Exemple #6
0
 def store_acad_xdata(tags: Tags):
     try:
         index = tags.tag_index(291)
     except IndexError:
         return None
     else:  # store tags after 291
         index += 1
         xdata = tags[index:]
         del tags[index:]  # remove xdata from subclass
         return xdata
Exemple #7
0
    def load_gradient(self, tags: Tags) -> Tags:
        try:
            index = tags.tag_index(450)
        except const.DXFValueError:
            # no gradient data present
            return tags

        # gradient data is always at the end of the AcDbHatch subclass
        self.gradient = Gradient.load_tags(tags[index:])
        # remove gradient data
        del tags[index:]
        return tags
Exemple #8
0
    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
Exemple #9
0
    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
Exemple #10
0
    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
def load_proxy_data(tags: Tags,
                    length_code: int,
                    data_code: int = 310) -> Optional[bytes]:
    try:
        index = tags.tag_index(length_code)
    except const.DXFValueError:
        return None
    binary_data = []
    for code, value in tags[index + 1:]:
        if code == data_code:
            binary_data.append(value)
        else:
            break  # at first tag with group code != data_code
    return b"".join(binary_data)
Exemple #12
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]
Exemple #13
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