Ejemplo n.º 1
0
    def draw_composite_entity(self, entity: DXFGraphic,
                              properties: Properties) -> None:
        def set_opaque(entities: Iterable[DXFGraphic]):
            for child in entities:
                # todo: defaults to 1.0 (fully transparent)???
                child.transparency = 0.0
                yield child

        dxftype = entity.dxftype()
        if dxftype == 'INSERT':
            entity = cast(Insert, entity)
            self.ctx.push_state(properties)
            # draw_entities() includes the visibility check:
            self.draw_entities(entity.attribs)
            self.draw_entities(entity.virtual_entities())
            self.ctx.pop_state()

        # DIMENSION, ARC_DIMENSION, LARGE_RADIAL_DIMENSION, LEADER
        # todo: ACAD_TABLE, MLINE, MLEADER
        elif hasattr(entity, 'virtual_entities'):
            # draw_entities() includes the visibility check:
            self.draw_entities(set_opaque(entity.virtual_entities()))

        else:
            raise TypeError(dxftype)
Ejemplo n.º 2
0
    def draw_composite_entity(self, entity: DXFGraphic,
                              properties: Properties) -> None:
        def set_opaque(entities: Iterable[DXFGraphic]):
            for child in entities:
                # todo: defaults to 1.0 (fully transparent)???
                child.transparency = 0.0
                yield child

        def draw_insert(insert: Insert):
            self.draw_entities(insert.attribs)
            # draw_entities() includes the visibility check:
            self.draw_entities(
                insert.virtual_entities(
                    skipped_entity_callback=self.skip_entity))

        dxftype = entity.dxftype()
        if dxftype == 'INSERT':
            entity = cast(Insert, entity)
            self.ctx.push_state(properties)
            if entity.mcount > 1:
                for virtual_insert in entity.multi_insert():
                    draw_insert(virtual_insert)
            else:
                draw_insert(entity)
            self.ctx.pop_state()

        elif hasattr(entity, 'virtual_entities'):
            # draw_entities() includes the visibility check:
            self.draw_entities(set_opaque(entity.virtual_entities()))
        else:
            raise TypeError(dxftype)
Ejemplo n.º 3
0
    def draw_composite_entity(self, entity: DXFGraphic) -> None:
        dxftype = entity.dxftype()
        if dxftype == 'INSERT':
            entity = cast(Insert, entity)
            self.ctx.push_state(self._resolve_properties(entity))
            self.parent_stack.append(entity)
            # visibility check is required:
            self.draw_entities(entity.attribs)
            try:
                children = list(entity.virtual_entities())
            except Exception as e:
                print(
                    f'Exception {type(e)}({e}) failed to get children of insert entity: {e}'
                )
                return
            # visibility check is required:
            self.draw_entities(children)
            self.parent_stack.pop()
            self.ctx.pop_state()

        # DIMENSION, ARC_DIMENSION, LARGE_RADIAL_DIMENSION and ACAD_TABLE
        # All these entities have an associated anonymous geometry block.
        elif hasattr(entity, 'virtual_entities'):
            children = []
            try:
                for child in entity.virtual_entities():
                    child.transparency = 0.0  # todo: defaults to 1.0 (fully transparent)???
                    children.append(child)
            except Exception as e:
                print(
                    f'Exception {type(e)}({e}) failed to get children of entity: {str(entity)}'
                )
                return

            self.parent_stack.append(entity)
            # visibility check is required:
            self.draw_entities(children)
            self.parent_stack.pop()

        else:
            raise TypeError(dxftype)
Ejemplo n.º 4
0
    def draw_polyline_entity(self, entity: DXFGraphic):
        dxftype = entity.dxftype()

        if dxftype == 'POLYLINE':
            e = cast(Polyface, entity)
            if e.is_polygon_mesh or e.is_poly_face_mesh:
                self.draw_mesh_builder_entity(
                    MeshBuilder.from_polyface(e),
                    self._resolve_properties(entity),
                )
                return

        entity = cast(Union[LWPolyline, Polyline], entity)
        if not entity.has_arc:
            properties = self._resolve_properties(entity)
            if dxftype == 'LWPOLYLINE':
                self.out.draw_line_string(Vector.generate(
                    entity.vertices_in_wcs()),
                                          close=entity.closed,
                                          properties=properties)
            else:  # POLYLINE
                if entity.is_2d_polyline:
                    ocs = entity.ocs()
                    elevation = Vector(entity.dxf.elevation).z
                    vertices = ocs.points_to_wcs(
                        Vector(p[0], p[1], elevation) for p in entity.points())
                else:
                    vertices = Vector.generate(entity.points())
                self.out.draw_line_string(vertices,
                                          close=entity.is_closed,
                                          properties=properties)
            return

        self.parent_stack.append(entity)
        self.out.set_current_entity(entity, tuple(self.parent_stack))
        # todo: end points of virtual entities are not in correct order
        #  can't use self.out.start_path()
        for child in entity.virtual_entities():
            # all child entities have the same properties as the parent,
            # no visibility check required:
            self.draw_entity(child)
        # self.out.end_path()
        self.parent_stack.pop()
        self.out.set_current_entity(None)