Ejemplo n.º 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
Ejemplo n.º 2
0
 def from_tags(tags):
     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
Ejemplo n.º 3
0
 def _setup_edge(self, tags):
     edge_type = tags[0].value
     if 0 < edge_type < 5:
         return EDGE_CLASSES[edge_type].from_tags(tags[1:])
     else:
         raise DXFStructureError(
             "HATCH: unknown edge type: {}".format(edge_type))
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def _build(self, entities: Iterator['DXFEntity']) -> None:
        section_head: 'DXFTagStorage' = next(entities)
        if section_head.dxftype(
        ) != 'SECTION' or section_head.base_class[1] != (2, 'ENTITIES'):
            raise DXFStructureError(
                "Critical structure error in ENTITIES section.")

        def add(entity: 'DXFGraphic'):
            handle = entity.dxf.owner
            # higher priority for owner handle
            if handle == msp_layout_key:
                paperspace = 0
            elif handle == psp_layout_key:
                paperspace = 1
            else:  # paperspace flag as fallback
                paperspace = entity.dxf.paperspace

            if paperspace:
                psp.add_entity(entity)
            else:
                msp.add_entity(entity)

        msp: 'BlockRecord' = self.doc.block_records.get('*Model_Space')
        psp: 'BlockRecord' = self.doc.block_records.get('*Paper_Space')
        msp_layout_key = msp.dxf.handle
        psp_layout_key = psp.dxf.handle
        linked_entities = entity_linker()
        # Don't store linked entities (VERTEX, ATTRIB, SEQEND) in entity space
        for entity in entities:
            if not linked_entities(entity):
                add(entity)
Ejemplo n.º 6
0
 def _set_pattern_data(self, new_pattern_data: 'PatternData') -> None:
     start_index = new_pattern_data.existing_pattern_start_index
     end_index = new_pattern_data.existing_pattern_end_index
     pattern_tags = new_pattern_data.dxftags()
     if start_index == 0:  # no existing pattern data
         try:
             start_index = self.AcDbHatch.tag_index(77) + 1  # hatch pattern double flag, used as insertion point
             end_index = start_index
         except DXFValueError:
             raise DXFStructureError("HATCH: Missing required DXF tag 'Hatch pattern double flag' (code=77).")
     # replace existing pattern data
     self.AcDbHatch[start_index: end_index] = pattern_tags
Ejemplo n.º 7
0
    def _build(self, entities: Iterator['ExtendedTags']) -> None:
        section_head = next(entities)

        if section_head[0] != (0, 'SECTION') or section_head[1] != (
                2, self.name.upper()):
            raise DXFStructureError(
                "Critical structure error in {} section.".format(
                    self.name.upper()))

        linked_tags = get_xtags_linker()
        for entity in entities:
            if not linked_tags(
                    entity
            ):  # don't store linked entities (VERTEX, ATTRIB, SEQEND) in entity space
                self._entity_space.store_tags(entity)
Ejemplo n.º 8
0
    def set_pattern_fill(self,
                         name,
                         color=7,
                         angle=0.,
                         scale=1.,
                         double=0,
                         style=1,
                         pattern_type=1,
                         definition=None):
        self._remove_gradient_data()
        self.dxf.solid_fill = 0
        self.dxf.pattern_name = name
        self.dxf.color = color
        self.dxf.hatch_style = style
        self.dxf.pattern_type = pattern_type

        # safe version of adding pattern fill specific DXF tags:
        self.AcDbHatch.remove_tags(
            (52, 41, 77)
        )  # remove pattern angle, pattern scale & pattern double flag if exists
        try:
            index = self.AcDbHatch.tag_index(
                76
            ) + 1  # find position of pattern type (76); + 1: insert after tag 76
        except DXFValueError:
            raise DXFStructureError(
                "HATCH: Missing required DXF tag 'Hatch pattern type' (code=76)."
            )
        # insert pattern angle, pattern scale & pattern double flag behind pattern type
        self.AcDbHatch[index:index] = [
            DXFTag(52, angle),
            DXFTag(41, scale),
            DXFTag(77, double)
        ]
        # place pattern definition right behind pattern double flag (77)
        if definition is None:
            # get pattern definition from acad standard pattern, default is 'ANSI31'
            definition = PATTERN.get(name, PATTERN['ANSI31'])
        self.set_pattern_definition(definition)