Exemple #1
0
 def split_run(self, num=5):
     for i in range(num):
         pnt = gp_Pnt(*np.random.rand(3) * 100)
         vec = gp_Vec(*np.random.randn(3))
         pln = gp_Pln(pnt, vec_to_dir(vec))
         fce = make_face(pln, -10000, 10000, -10000, 10000)
         self.splitter.AddTool(fce)
     self.splitter.Perform()
Exemple #2
0
def surface_from_curves():
    '''
    @param display:
    '''
    # First spline
    array = []
    array.append(gp_Pnt(-4, 0, 2))
    array.append(gp_Pnt(-7, 2, 2))
    array.append(gp_Pnt(-6, 3, 1))
    array.append(gp_Pnt(-4, 3, -1))
    array.append(gp_Pnt(-3, 5, -2))

    pt_list1 = point_list_to_TColgp_Array1OfPnt(array)
    SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve()

    # Second spline
    a2 = []
    a2.append(gp_Pnt(-4, 0, 2))
    a2.append(gp_Pnt(-2, 2, 0))
    a2.append(gp_Pnt(2, 3, -1))
    a2.append(gp_Pnt(3, 7, -2))
    a2.append(gp_Pnt(4, 9, -1))
    pt_list2 = point_list_to_TColgp_Array1OfPnt(a2)
    SPL2 = GeomAPI_PointsToBSpline(pt_list2).Curve()

    # Fill with StretchStyle
    aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle)

    SPL3 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(10, 0, 0)))
    SPL4 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(10, 0, 0)))
    # Fill with CoonsStyle
    aGeomFill2 = GeomFill_BSplineCurves(SPL3, SPL4, GeomFill_CoonsStyle)
    SPL5 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(20, 0, 0)))
    SPL6 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(20, 0, 0)))
    # Fill with CurvedStyle
    aGeomFill3 = GeomFill_BSplineCurves(SPL5, SPL6, GeomFill_CurvedStyle)

    aBSplineSurface1 = aGeomFill1.Surface()
    aBSplineSurface2 = aGeomFill2.Surface()
    aBSplineSurface3 = aGeomFill3.Surface()

    display.DisplayShape(make_face(aBSplineSurface1, 1e-6))
    display.DisplayShape(make_face(aBSplineSurface2, 1e-6))
    display.DisplayShape(make_face(aBSplineSurface3, 1e-6), update=True)
Exemple #3
0
def extrude_closed_wire(wire: TopoDS_Wire, origin, normal,
                        height) -> TopoDS_Shape:
    """Extrude a closed wire into a solid"""
    p1 = origin + normal * height
    starting_point = gp_Pnt(origin[0], origin[1], origin[2])
    end_point = gp_Pnt(*p1.tolist())
    vec = gp_Vec(starting_point, end_point)

    solid = make_extrusion(make_face(wire), height, vec)

    return solid
Exemple #4
0
def cross_sec_face(sec_profile: SectionProfile, placement: Placement,
                   solid_repre) -> Union[TopoDS_Face, TopoDS_Wire]:

    inner_shape = None

    if sec_profile.sec.type in SectionCat.tubular:
        outer_shape = make_wire(
            [make_circle(placement.origin, placement.zdir, sec_profile.sec.r)])
        inner_shape = make_wire([
            make_circle(placement.origin, placement.zdir,
                        sec_profile.sec.r - sec_profile.sec.wt)
        ])
    elif sec_profile.sec.type in SectionCat.circular:
        outer_shape = make_wire(
            [make_circle(placement.origin, placement.zdir, sec_profile.sec.r)])
    elif sec_profile.sec.type in SectionCat.general:
        radius = np.sqrt(sec_profile.sec.properties.Ax / np.pi)
        outer_shape = make_wire(
            [make_circle(placement.origin, placement.zdir, radius)])
    else:
        if sec_profile.disconnected is False:
            outer_curve = sec_profile.outer_curve
            inner_curve = sec_profile.inner_curve
            outer_curve.placement = placement
            outer_shape = outer_curve.face
            if inner_curve is not None:
                inner_curve.placement = placement
                inner_shape = inner_curve.wire
        else:
            outer_shape = []
            for curve in sec_profile.outer_curve_disconnected:
                curve.placement = placement
                outer_shape.append(curve.wire)

    if inner_shape is not None and solid_repre is True:
        try:
            face = make_face(outer_shape) if type(
                outer_shape) is not TopoDS_Face else outer_shape
            shape = make_face_w_cutout(face, inner_shape)
        except TypeError as e:
            raise TypeError(e)
        except AssertionError as e:
            raise AssertionError(e)
    else:
        shape = outer_shape
    if shape is None:
        raise ValueError("Shape cannot be None")
    return shape
def build_geom_plate(edges):
    bpSrf = GeomPlate_BuildPlateSurface(3, 9, 12)

    # add curve constraints
    for edg in edges:
        c = BRepAdaptor_HCurve()
        print('edge:', edg)
        c.ChangeCurve().Initialize(edg)
        constraint = BRepFill_CurveConstraint(c.GetHandle(), 0)
        bpSrf.Add(constraint.GetHandle())

    # add point constraint
    try:
        bpSrf.Perform()
    except RuntimeError:
        print('failed to build the geom plate surface ')

    srf = bpSrf.Surface()
    plate = GeomPlate_MakeApprox(srf, 0.01, 10, 5, 0.01, 0, GeomAbs_C0)

    uMin, uMax, vMin, vMax = srf.GetObject().Bounds()
    face = make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-6)
    return face
    def MakeEllipsFace(self, Major: float, Minor: float) -> TopoDS_Face:
        elip    = gp_Elips( gp_XOY(), Major, Minor )
        ed      = make_edge( elip )
        wire    = make_wire( ed )

        return make_face( wire )
    def MakeCircleFace(self, Radius: float) -> TopoDS_Face:
        circle  = Geom_Circle( gp_XOY(), Radius )
        ed      = make_edge( circle )
        wire    = make_wire( ed )

        return make_face( wire )