Exemplo n.º 1
0
def curves2d_from_offset(event=None):
    '''
    @param display:
    '''
    pnt2d_array = TColgp_Array1OfPnt2d(1, 5)
    pnt2d_array.SetValue(1, gp_Pnt2d(-4, 0))
    pnt2d_array.SetValue(2, gp_Pnt2d(-7, 2))
    pnt2d_array.SetValue(3, gp_Pnt2d(-6, 3))
    pnt2d_array.SetValue(4, gp_Pnt2d(-4, 3))
    pnt2d_array.SetValue(5, gp_Pnt2d(-3, 5))

    spline_1 = Geom2dAPI_PointsToBSpline(pnt2d_array).Curve()

    dist = 1
    offset_curve1 = Geom2d_OffsetCurve(spline_1, dist)
    result = offset_curve1.IsCN(2)
    print("Offset curve yellow is C2: %r" % result)
    dist2 = 1.5
    offset_curve2 = Geom2d_OffsetCurve(spline_1, dist2)
    result2 = offset_curve2.IsCN(2)
    print("Offset curve blue is C2: %r" % result2)

    display.DisplayShape(spline_1)
    display.DisplayShape(offset_curve1, color='YELLOW')
    display.DisplayShape(offset_curve2, color='BLUE', update=True)
Exemplo n.º 2
0
def convert_2dcurve(curve, convert_2bs=False):
    curve_t = curve.Edge()
    d1_feat = {
        "type": edge_map[curve.GetType()],
        "interval": [curve.FirstParameter(),
                     curve.LastParameter()]
    }
    c_type = d1_feat["type"]

    if c_type == "Line":
        c = curve.Line()
        d1_feat["location"] = list(c.Location().Coord())
        d1_feat["direction"] = list(c.Direction().Coord())
    elif c_type == "Circle":
        c = curve.Circle()
        d1_feat["location"] = list(c.Location().Coord())
        d1_feat["radius"] = c.Radius()
        d1_feat["x_axis"] = list(c.XAxis().Direction().Coord())
        d1_feat["y_axis"] = list(c.YAxis().Direction().Coord())
    elif c_type == "Ellipse":
        c = curve.Ellipse()
        d1_feat["focus1"] = list(c.Focus1().Coord())
        d1_feat["focus2"] = list(c.Focus2().Coord())
        d1_feat["x_axis"] = list(c.XAxis().Direction().Coord())
        d1_feat["y_axis"] = list(c.YAxis().Direction().Coord())
        d1_feat["maj_radius"] = c.MajorRadius()
        d1_feat["min_radius"] = c.MinorRadius()
    elif c_type == "BSpline":
        if not convert_2bs:
            c = curve.BSpline()
        else:
            c = curve
        c.SetNotPeriodic()
        d1_feat["rational"] = c.IsRational()
        d1_feat["closed"] = c.IsClosed()
        d1_feat["continuity"] = c.Continuity()
        d1_feat["degree"] = c.Degree()
        p = TColgp_Array1OfPnt2d(1, c.NbPoles())
        c.Poles(p)
        points = []
        for pi in range(p.Length()):
            points.append(list(p.Value(pi + 1).Coord()))
        d1_feat["poles"] = points

        k = TColStd_Array1OfReal(1, c.NbPoles() + c.Degree() + 1)
        c.KnotSequence(k)
        knots = []
        for ki in range(k.Length()):
            knots.append(k.Value(ki + 1))
        d1_feat["knots"] = knots

        w = TColStd_Array1OfReal(1, c.NbPoles())
        c.Weights(w)
        weights = []
        for wi in range(w.Length()):
            weights.append(w.Value(wi + 1))
        d1_feat["weights"] = weights
    else:
        print("Unsupported type 2d", c_type)
    return d1_feat
Exemplo n.º 3
0
def variable_filleting(event=None):
    a_pnt = gp_Pnt(350, 0, 0)
    box_2 = BRepPrimAPI_MakeBox(a_pnt, 200, 200, 200).Shape()
    a_fillet = BRepFilletAPI_MakeFillet(box_2)

    tab_point = TColgp_Array1OfPnt2d(1, 6)
    p_1 = gp_Pnt2d(0., 8.)
    p_2 = gp_Pnt2d(0.2, 16.)
    p_3 = gp_Pnt2d(0.4, 25.)
    p_4 = gp_Pnt2d(0.6, 55.)
    p_5 = gp_Pnt2d(0.8, 28.)
    p_6 = gp_Pnt2d(1., 20.)
    tab_point.SetValue(1, p_1)
    tab_point.SetValue(2, p_2)
    tab_point.SetValue(3, p_3)
    tab_point.SetValue(4, p_4)
    tab_point.SetValue(5, p_5)
    tab_point.SetValue(6, p_6)

    expl3 = list(TopologyExplorer(box_2).edges())

    a_fillet.Add(tab_point, expl3[9])
    a_fillet.Build()
    if a_fillet.IsDone():
        law_evolved_box = a_fillet.Shape()
        display.DisplayShape(law_evolved_box)
    else:
        print("aFillet not done.")
    display.FitAll()
Exemplo n.º 4
0
 def gen_data_spline_2d(self, dat, ratio=1.0):
     num = dat.shape[0]
     pts = TColgp_Array1OfPnt2d(1, num)
     for i, xyz in enumerate(dat):
         pnt = gp_Pnt2d(xyz[0], xyz[1])
         pts.SetValue(i+1, pnt)
     geo_spl = Geom2dAPI_PointsToBSpline(pts)
     return geo_spl
def bspline():
    # the first bspline
    array = TColgp_Array1OfPnt2d(1, 5)
    array.SetValue(1, gp_Pnt2d(0, 0))
    array.SetValue(2, gp_Pnt2d(1, 2))
    array.SetValue(3, gp_Pnt2d(2, 3))
    array.SetValue(4, gp_Pnt2d(4, 3))
    array.SetValue(5, gp_Pnt2d(5, 5))
    bspline_1 = Geom2dAPI_PointsToBSpline(array).Curve()

    # the second one
    harray = TColgp_HArray1OfPnt2d(1, 5)
    harray.SetValue(1, gp_Pnt2d(0, 0))
    harray.SetValue(2, gp_Pnt2d(1, 2))
    harray.SetValue(3, gp_Pnt2d(2, 3))
    harray.SetValue(4, gp_Pnt2d(4, 3))
    harray.SetValue(5, gp_Pnt2d(5, 5))

    anInterpolation = Geom2dAPI_Interpolate(harray, False, 0.01)
    anInterpolation.Perform()
    bspline_2 = anInterpolation.Curve()

    harray2 = TColgp_HArray1OfPnt2d(1, 5)
    harray2.SetValue(1, gp_Pnt2d(11, 0))
    harray2.SetValue(2, gp_Pnt2d(12, 2))
    harray2.SetValue(3, gp_Pnt2d(13, 3))
    harray2.SetValue(4, gp_Pnt2d(15, 3))
    harray2.SetValue(5, gp_Pnt2d(16, 5))

    anInterpolation2 = Geom2dAPI_Interpolate(harray, True, 0.01)
    anInterpolation2.Perform()
    bspline_3 = anInterpolation2.Curve()

    for j in range(array.Lower(), array.Upper() + 1):
        p = array.Value(j)
        display.DisplayShape(p, update=False)
    for j in range(harray.Lower(), harray.Upper() + 1):
        p = harray.Value(j)
        display.DisplayShape(p, update=False)

    display.DisplayShape(bspline_1, update=False)
    display.DisplayShape(bspline_2, update=False, color='GREEN')
    display.DisplayShape(bspline_3, update=True, color='BLUE')
    def __init__(self):
        super(Sketch_CommandBezierCurve, self).__init__("BezierCurve.")
        self.IndexCounter = 1
        self.tempPnt2d = gp.Origin2d()
        self.myFirstgp_Pnt = gp.Origin()
        self.tempPnt = gp.Origin()
        self.curEdge = TopoDS_Edge()

        self.myBezierCurveAction = BezierCurveAction.Nothing
        curgp_Array1CurvePoles2d = TColgp_Array1OfPnt2d(1, 2)
        curgp_Array1CurvePoles2d.SetValue(1, gp.Origin2d())
        curgp_Array1CurvePoles2d.SetValue(2, gp.Origin2d())
        self.myGeom2d_BezierCurve = Geom2d_BezierCurve(
            curgp_Array1CurvePoles2d)

        curgp_Array1CurvePoles = TColgp_Array1OfPnt(1, 2)
        curgp_Array1CurvePoles.SetValue(1, gp.Origin())
        curgp_Array1CurvePoles.SetValue(2, gp.Origin())
        self.myGeom_BezierCurve = Geom_BezierCurve(curgp_Array1CurvePoles)

        self.myRubberAIS_Shape = AIS_Shape(self.curEdge)
 def CloseBezierCurve(self):
     self.myContext.Remove(self.myRubberAIS_Shape, True)
     self.bezier_curve.Compute()
     self.bezierNode = BezierNode(self.bezier_curve.GetName(),
                                  self.rootNode)
     self.bezierNode.setSketchObject(self.bezier_curve)
     self.AddObject(self.bezier_curve.GetGeometry2d(),
                    self.bezier_curve.GetAIS_Object(),
                    Sketch_GeometryType.CurveSketchObject)
     # create new object
     curgp_Array1CurvePoles2d = TColgp_Array1OfPnt2d(1, 2)
     curgp_Array1CurvePoles2d.SetValue(1, gp.Origin2d())
     curgp_Array1CurvePoles2d.SetValue(2, gp.Origin2d())
     self.myGeom2d_BezierCurve = Geom2d_BezierCurve(
         curgp_Array1CurvePoles2d)
     curgp_Array1CurvePoles = TColgp_Array1OfPnt(1, 2)
     curgp_Array1CurvePoles.SetValue(1, gp.Origin())
     curgp_Array1CurvePoles.SetValue(2, gp.Origin())
     self.myGeom_BezierCurve = Geom_BezierCurve(curgp_Array1CurvePoles)
     self.IndexCounter = 1
     self.myBezierCurveAction = BezierCurveAction.Input_1Point
Exemplo n.º 8
0
def to_tcolgp_array1_pnt2d(pnts):
    """
    Convert the 1-D array of point_like entities to OCC data.

    :param array_like pnts: Array of points to convert.

    :return: OCC array of points.
    :rtype: TColgp_Array1OfPnt2d
    """
    gp_pnts = []
    for gp in pnts:
        gp = to_gp_pnt2d(gp)
        if not gp:
            continue
        gp_pnts.append(gp)

    n = len(gp_pnts)
    array = TColgp_Array1OfPnt2d(1, n)
    for i, gp in enumerate(gp_pnts, 1):
        array.SetValue(i, gp)

    return array
Exemplo n.º 9
0
def fillet_cylinder(event=None):
    display.EraseAll()
    # Create Cylinder
    cylinder = BRepPrimAPI_MakeCylinder(
        gp_Ax2(gp_Pnt(-300, 0, 0), gp_Dir(0, 0, 1)), 100, 200).Shape()
    fillet = BRepFilletAPI_MakeFillet(cylinder)
    display.DisplayShape(cylinder, update=True)
    tab_point_2 = TColgp_Array1OfPnt2d(0, 20)
    for i in range(0, 20):
        point_2d = gp_Pnt2d(i * 2 * pi / 19,
                            60 * cos(i * pi / 19 - pi / 2) + 10)
        tab_point_2.SetValue(i, point_2d)
        display.DisplayShape(point_2d)

    expl2 = TopologyExplorer(cylinder).edges()
    fillet.Add(tab_point_2, next(expl2))
    fillet.Build()
    if fillet.IsDone():
        law_evolved_cylinder = fillet.Shape()
        display.DisplayShape(law_evolved_cylinder, update=True)
    else:
        print("fillet not done.")
Exemplo n.º 10
0
def point_list_to_TColgp_Array1OfPnt2d(li):
    pts = TColgp_Array1OfPnt2d(1, len(li))
    for n, i in enumerate(li):
        pts.SetValue(n + 1, i)
    return pts
def variable_filleting(event=None):
    display.EraseAll()
    # Create Box
    Box = BRepPrimAPI_MakeBox(200, 200, 200).Shape()
    # Fillet
    Rake = BRepFilletAPI_MakeFillet(Box)
    ex = TopologyExplorer(Box).edges()
    next(ex)
    next(ex)
    next(ex)

    Rake.Add(8, 50, next(ex))
    Rake.Build()
    if Rake.IsDone():
        evolvedBox = Rake.Shape()
        display.DisplayShape(evolvedBox)
    else:
        print("Rake not done.")
    # Create Cylinder
    Cylinder = BRepPrimAPI_MakeCylinder(
        gp_Ax2(gp_Pnt(-300, 0, 0), gp_Dir(0, 0, 1)), 100, 200).Shape()
    fillet_ = BRepFilletAPI_MakeFillet(Cylinder)

    TabPoint2 = TColgp_Array1OfPnt2d(0, 20)
    for i in range(0, 20):
        Point2d = gp_Pnt2d(i * 2 * pi / 19,
                           60 * cos(i * pi / 19 - pi / 2) + 10)
        TabPoint2.SetValue(i, Point2d)

    exp2 = TopologyExplorer(Cylinder).edges()
    fillet_.Add(TabPoint2, next(exp2))
    fillet_.Build()
    if fillet_.IsDone():
        LawEvolvedCylinder = fillet_.Shape()
        display.DisplayShape(LawEvolvedCylinder)
    else:
        print("fillet not done.")  ## TODO : fillet not done
    P = gp_Pnt(350, 0, 0)
    Box2 = BRepPrimAPI_MakeBox(P, 200, 200, 200).Shape()
    afillet = BRepFilletAPI_MakeFillet(Box2)

    TabPoint = TColgp_Array1OfPnt2d(1, 6)
    P1 = gp_Pnt2d(0., 8.)
    P2 = gp_Pnt2d(0.2, 16.)
    P3 = gp_Pnt2d(0.4, 25.)
    P4 = gp_Pnt2d(0.6, 55.)
    P5 = gp_Pnt2d(0.8, 28.)
    P6 = gp_Pnt2d(1., 20.)
    TabPoint.SetValue(1, P1)
    TabPoint.SetValue(2, P2)
    TabPoint.SetValue(3, P3)
    TabPoint.SetValue(4, P4)
    TabPoint.SetValue(5, P5)
    TabPoint.SetValue(6, P6)

    exp = TopologyExplorer(Box2).edges()
    next(exp)
    next(exp)
    next(exp)

    afillet.Add(TabPoint, next(exp))
    afillet.Build()
    if afillet.IsDone():
        LawEvolvedBox = afillet.Shape()
        display.DisplayShape(LawEvolvedBox)
    else:
        print("aFillet not done.")
    display.FitAll()
Exemplo n.º 12
0
    opt, argc = parser.parse_args(argvs)
    print(opt, argc)

    obj = plotocc()
    #
    # https://www.opencascade.com/doc/occt-7.4.0/overview/html/occt_user_guides__modeling_algos.html#occt_modalg_6
    # https://www.opencascade.com/doc/occt-7.5.0/overview/html/occt_user_guides__modeling_algos.html#occt_modalg_6
    #

    axs = gp_Ax3()
    box = make_box(200, 200, 200)
    chf = BRepFilletAPI_MakeChamfer(box)
    # chf.Build()
    fil = BRepFilletAPI_MakeFillet(box)
    fil.SetFilletShape(ChFi3d_Rational)
    par = TColgp_Array1OfPnt2d(1, 2)
    par.SetValue(1, gp_Pnt2d(-1000, 10))
    par.SetValue(2, gp_Pnt2d(1000, 10))
    top = TopExp_Explorer(box, TopAbs_EDGE)

    fil.Add(par, top.Current())
    top.Next()
    fil.Add(par, top.Current())
    top.Next()
    fil.Add(par, top.Current())

    write_step_file(box, obj.tmpdir + "box.stp")
    write_step_file(fil.Shape(), obj.tmpdir + "box_fillet.stp", "AP214IS")
    write_stl_file(fil.Shape(), obj.tmpdir + "box_fillet.stl")
    write_stl_file_mesh1(fil.Shape(),
                         obj.tmpdir + "box_fillet_mesh1.stl",
Exemplo n.º 13
0
def TColgp_Array1OfPnt2d_to_point_list(li: TColgp_Array1OfPnt2d):
    pts = []
    for i in range(li.Length()):
        point = li.Value(i + 1)
        pts.append(point)
    return pts
from OCC.Core.GeomAPI import GeomAPI_PointsToBSpline
from enum import Enum
from OCC.Core.TopoDS import TopoDS_Edge
from OCC.Core.TColgp import TColgp_Array1OfPnt2d, TColgp_Array1OfPnt
from OCC.Core.TColStd import TColStd_Array1OfReal,TColStd_Array1OfInteger
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge,BRepBuilderAPI_MakeEdge2d
from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()

myFirstgp_Pnt2d=gp.Origin2d()
mySecondgp_Pnt2d=gp_Pnt2d(-10,2)
myThirdgp_Pnt2d=gp_Pnt2d(5,7)
myFourthgp_Pnt2d=gp_Pnt2d(5,15)
myDegree=2

curgp_Array1CurvePoles2d = TColgp_Array1OfPnt2d(1, 4)
curgp_Array1CurvePoles2d.SetValue(1, myFirstgp_Pnt2d)
curgp_Array1CurvePoles2d.SetValue(2, mySecondgp_Pnt2d)
curgp_Array1CurvePoles2d.SetValue(3, myThirdgp_Pnt2d)
curgp_Array1CurvePoles2d.SetValue(4, myFourthgp_Pnt2d)

curgp_Array1CurveWeights2d = TColStd_Array1OfReal(1, 4)
curgp_Array1CurveWeights2d.SetValue(1, 1.0)
curgp_Array1CurveWeights2d.SetValue(2, 1.0)
curgp_Array1CurveWeights2d.SetValue(3, 1.0)
curgp_Array1CurveWeights2d.SetValue(4, 1.0)

curgp_Array1CurveMulti2d = TColStd_Array1OfInteger(1, 3)
curgp_Array1CurveMulti2d.SetValue(1, 3)
curgp_Array1CurveMulti2d.SetValue(2, 1)
curgp_Array1CurveMulti2d.SetValue(3, 3)