示例#1
0
文件: hatch.py 项目: 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
示例#2
0
文件: header.py 项目: ols3er/ezdxf
    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
示例#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
示例#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
示例#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)
     ]
示例#6
0
文件: hatch.py 项目: 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)
示例#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]
示例#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))
示例#9
0
 def load_vertices(self, tags: Tags) -> None:
     self.vertices.extend(
         MLineVertex.load(tags) for tags in group_tags(tags, splitcode=11)
     )
示例#10
0
文件: rawpp.py 项目: suffrajet/ezdxf
 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))
示例#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)
示例#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))
示例#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
     ])
示例#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))
示例#15
0
def groups():
    return list(group_tags(internal_tag_compiler(TESTTAGS)))
示例#16
0
def section():
    entities = group_tags(internal_tag_compiler(ACDSSECTION))
    return AcDsDataSection(None, entities)
示例#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))