コード例 #1
0
ファイル: face.py プロジェクト: psavine42/OCCUtilsExt
    def from_wire(cls, topo: Union[Topo, TopoDS_Shape], plane: Optional[gp_Pln] = None) -> TopoDS_Face:
        """ create face from compound of edges """
        # if topo.number_of_wires() == 0:
        from .Construct import assert_isdone

        wire_builder = BRepBuilderAPI_MakeWire()
        if isinstance(topo, TopoDS_Shape):
            top = Topo(topo)
        else:
            top = topo

        for edge in top.edges():
            wire_builder.Add(edge)

        with assert_isdone(wire_builder, 'wire'):
            wire_builder.Build()
            w = wire_builder.Wire()

            if plane is not None:
                bface = BRepBuilderAPI_MakeFace(plane)

            else:
                # todo - this doesnt work ----
                _face = TopoDS_Face()
                bface = BRepBuilderAPI_MakeFace(_face)

            bface.Add(w)
            with assert_isdone(bface, 'face'):
                bface.Build()
                face = bface.Shape()
                return face
コード例 #2
0
ファイル: Construct.py プロジェクト: psavine42/OCCUtilsExt
def face_normal(face: TopoDS_Face) -> gp_Dir:
    """

    :param face:
    :return:
    """
    umin, umax, vmin, vmax = breptools_UVBounds(face)
    surf = BRep_Tool().Surface(face)
    props = GeomLProp_SLProps(surf, (umin + umax) / 2., (vmin + vmax) / 2., 1,
                              TOLERANCE)
    norm = props.Normal()
    if face.Orientation() == TopAbs_REVERSED:
        norm.Reverse()
    return norm
コード例 #3
0
ファイル: face.py プロジェクト: psavine42/OCCUtilsExt
def get_faces(_shape):
    """ return the faces from `_shape`
    :param _shape: TopoDS_Shape, or a subclass like TopoDS_Solid
    :return: a list of faces found in `_shape`
    """
    topExp = TopExp_Explorer()
    topExp.Init(_shape, TopAbs_FACE)
    _faces = []

    while topExp.More():
        fc = TopoDS_Face(topExp.Current())
        _faces.append(fc)
        topExp.Next()

    return _faces
コード例 #4
0
def split_shape(event=None):
    S = BRepPrimAPI_MakeBox(gp_Pnt(-100, -60, -80), 150, 200, 170).Shape()
    asect = BRepAlgoAPI_Section(S, gp_Pln(1, 2, 1, -15), False)
    asect.ComputePCurveOn1(True)
    asect.Approximation(True)
    asect.Build()
    R = asect.Shape()

    asplit = BRepFeat_SplitShape(S)

    for edg in Topo(R).edges():
        face = TopoDS_Face()
        if asect.HasAncestorFaceOn1(edg, face):
            asplit.Add(edg, face)

    asplit.Build()
    display.EraseAll()
    display.DisplayShape(asplit.Shape())
    display.FitAll()
コード例 #5
0
ファイル: face.py プロジェクト: psavine42/OCCUtilsExt
    def from_topo_edges(cls, topo: Topo, plane: Optional[gp_Pln]=None) -> TopoDS_Face:
        """ create face from compound of edges """
        # if topo.number_of_wires() == 0:
        wire = BRepBuilderAPI_MakeWire()
        for edge in topo.edges():
            wire.Add(edge)
        wire.Build()
        w = wire.Wire()

        if plane is not None:
            bface = BRepBuilderAPI_MakeFace(plane)

        else:
            # todo - this doesnt work ----
            _face = TopoDS_Face()
            bface = BRepBuilderAPI_MakeFace(_face)

        bface.Add(w)
        bface.Build()
        face = bface.Shape()
        return face
コード例 #6
0
ファイル: face.py プロジェクト: psavine42/OCCUtilsExt
    def __init__(self, face:TopoDS_Face, **kwargs):
        """
        """
        assert isinstance(face, TopoDS_Face), 'need a TopoDS_Face, got a %s' % face.__class__
        assert not face.IsNull()
        super(Face, self).__init__()
        BaseObject.__init__(self, 'face', **kwargs)
        # we need to copy the base shape using the following three
        # lines
        assert self.IsNull()
        self.TShape(face.TShape())
        self.Location(face.Location())
        self.Orientation(face.Orientation())
        assert not self.IsNull()

        # cooperative classes
        self.DiffGeom = DiffGeomSurface(self)

        # STATE; whether cooperative classes are yet initialized
        self._curvature_initiated = False
        self._geometry_lookup_init = False

        # ===================================================================
        # properties
        # ===================================================================
        self._h_srf = None
        self._srf = None
        self._adaptor = None
        self._adaptor_handle = None
        self._classify_uv = None  # cache the u,v classifier, no need to rebuild for every sample
        self._topo = None

        # aliasing of useful methods
        def is_u_periodic(self):
            return self.adaptor.IsUPeriodic()

        def is_v_periodic(self):
            return self.adaptor.IsVPeriodic()

        def is_u_closed(self):
            return self.adaptor.IsUClosed()

        def is_v_closed(self):
            return self.adaptor.IsVClosed()

        def is_u_rational(self):
            return self.adaptor.IsURational()

        def is_v_rational(self):
            return self.adaptor.IsVRational()

        def u_degree(self):
            return self.adaptor.UDegree()

        def v_degree(self):
            return self.adaptor.VDegree()

        def u_continuity(self):
            return self.adaptor.UContinuity()

        def v_continuity(self):
            return self.adaptor.VContinuity()