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)
def extrusion(event=None):
    # Make a box
    Box = BRepPrimAPI_MakeBox(400., 250., 300.)
    S = Box.Shape()

    # Choose the first Face of the box
    F = next(TopologyExplorer(S).faces())
    surf = BRep_Tool_Surface(F)

    #  Make a plane from this face
    Pln = Geom_Plane.DownCast(surf)

    # Get the normal of this plane. This will be the direction of extrusion.
    D = Pln.Axis().Direction()

    # Inverse normal
    D.Reverse()

    # Create the 2D planar sketch
    MW = BRepBuilderAPI_MakeWire()
    p1 = gp_Pnt2d(200., -100.)
    p2 = gp_Pnt2d(100., -100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    Edge1 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))
    MW.Add(Edge1.Edge())
    p1 = p2
    p2 = gp_Pnt2d(100., -200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    Edge2 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))
    MW.Add(Edge2.Edge())
    p1 = p2
    p2 = gp_Pnt2d(200., -200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    Edge3 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))
    MW.Add(Edge3.Edge())
    p1 = p2
    p2 = gp_Pnt2d(200., -100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    Edge4 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))
    MW.Add(Edge4.Edge())

    #  Build Face from Wire. NB: a face is required to generate a solid.
    MKF = BRepBuilderAPI_MakeFace()
    MKF.Init(surf, False, 1e-6)
    MKF.Add(MW.Wire())
    FP = MKF.Face()
    breplib_BuildCurves3d(FP)

    MKP = BRepFeat_MakePrism(S, FP, F, D, False, True)
    MKP.Perform(200.)
    # TODO MKP completes, seeing a split operation but no extrusion
    assert MKP.IsDone()
    res1 = MKP.Shape()

    display.EraseAll()
    display.DisplayColoredShape(res1, 'BLUE')
    display.FitAll()
def bisect_pnt(event=None):
    display.EraseAll()
    p1 = gp_Pnt2d(1, 0.5)
    p2 = gp_Pnt2d(0, 1e5)
    bi = GccAna_Pnt2dBisec(p1, p2)
    bisec = bi.ThisSolution()
    # enum GccInt_Lin, GccInt_Cir, GccInt_Ell, GccInt_Par, GccInt_Hpr, GccInt_Pnt
    p1_ = make_vertex(gp_Pnt(p1.X(), p1.Y(), 0))
    p2_ = make_vertex(gp_Pnt(p2.X(), p2.Y(), 0))
    display.DisplayShape([p1_, p2_])
    display.DisplayColoredShape(make_edge2d(bisec), 'BLUE')
    display.FitAll()
def bisect_lineline(event=None):
    display.EraseAll()
    li1 = gp_Lin2d(gp_Pnt2d(), gp_Dir2d(1, 0))
    li2 = gp_Lin2d(gp_Pnt2d(), gp_Dir2d(0, 1))

    bi = GccAna_Lin2dBisec(li1, li2)
    bi_li1 = bi.ThisSolution(1)
    bi_li2 = bi.ThisSolution(2)

    for i in [li1, li2]:
        display.DisplayShape(make_edge2d(i))
    for i in [bi_li1, bi_li2]:
        display.DisplayColoredShape(make_edge2d(i), 'BLUE')
    display.FitAll()
Exemplo n.º 5
0
def faircurve(event=None):
    pt1 = gp_Pnt2d(0., 0.)
    pt2 = gp_Pnt2d(0., 120.)
    height = 100.
    pl = Geom_Plane(gp_Pln())
    for i in range(0, 40):
        # TODO: the parameter slope needs to be visualized
        slope = i / 100.
        bc = batten_curve(pt1, pt2, height, slope, math.radians(i),
                          math.radians(-i))
        display.EraseAll()
        edge = BRepBuilderAPI_MakeEdge(bc, pl).Edge()
        display.DisplayShape(edge, update=True)
        time.sleep(0.21)
Exemplo n.º 6
0
    def update_shape(self, change=None):
        d = self.declaration
        # Get the shape to apply the fillet to
        child = self.get_first_child()

        # Ignore this operation
        if d.disabled:
            self.shape = child.shape
            return

        fillet = BRepFilletAPI_MakeFillet(child.shape)
        operations = d.operations if d.operations else child.topology.edges
        for item in operations:
            if not isinstance(item, (list, tuple)):
                fillet.Add(d.radius, item)
                continue

            # If an array of points is create a changing radius fillet
            n = len(item)
            if n == 2 and isinstance(item[0], (list, tuple)):
                pts, edge = item
                array = TColgp_Array1OfPnt2d(1, len(pts))
                for i, pt in enumerate(pts):
                    array.SetValue(i + 1, gp_Pnt2d(*pt))
                fillet.Add(array, edge)
                continue
            if n == 2 and isinstance(item[1], TopoDS_Face):
                r, face = item
                for edge in Topology(shape=face).edges_from_face(face):
                    fillet.Add(r, edge)
                continue
            # custom radius or r1 and r2 radius fillets
            fillet.Add(*item)
        self.shape = fillet.Shape()
Exemplo n.º 7
0
def to_gp_pnt2d(p):
    """
    Convert the point_like entity to a gp_Pnt2d.
    """
    if isinstance(p, gp_Pnt2d):
        return p
    if is_array_like(p) and len(p) == 2:
        return gp_Pnt2d(*p)
    return None
def bisect_crvcrv(event=None):
    display.EraseAll()
    ax = gp_Ax22d(gp_Pnt2d(), gp_Dir2d(1, 0), gp_Dir2d(0, -1))
    circ = gp_Circ2d(ax, 5)
    crv1 = GCE2d_MakeCircle(circ).Value()
    edg1 = make_edge2d(crv1, -1.0, 1.0)
    display.DisplayColoredShape(edg1, 'BLUE')

    p1 = gp_Pnt2d(-10, 0)
    p2 = gp_Pnt2d(-10, 10)
    crv2 = GCE2d_MakeLine(p1, p2).Value()
    edg2 = make_edge2d(crv2, -10.0, 10.0)
    display.DisplayColoredShape(edg2, 'GREEN')

    bi = Bisector_BisecCC(crv1, crv2, 50, -5, gp_Pnt2d(0, 0))
    crv_bi = bi.Curve(1)
    edg3 = make_edge2d(crv_bi, -1.0, 1.0)
    display.DisplayColoredShape(edg3, 'RED')
    display.FitAll()
Exemplo n.º 9
0
 def on_trimmed(self, u, v):
     '''tests whether the surface at the u,v parameter has been trimmed
     '''
     if self._classify_uv is None:
         self._classify_uv = BRepTopAdaptor_FClass2d(self, 1e-9)
     uv = gp_Pnt2d(u, v)
     if self._classify_uv.Perform(uv) == TopAbs_IN:
         return True
     else:
         return False
def bisect_linecircle(event=None):
    display.EraseAll()
    ci1 = gp_Circ2d(gp_Ax22d(), 10000)
    li1 = gp_Lin2d(gp_Pnt2d(2000000, 20), gp_Dir2d(0, 1))
    bi = GccAna_CircLin2dBisec(ci1, li1)
    if not bi.IsDone():
        raise AssertionError("Bisec is not Done")
    bisec = bi.ThisSolution(1)
    pb = bisec.Parabola()
    display.DisplayShape([make_edge2d(ci1), make_edge2d(li1)])
    display.DisplayColoredShape(make_edge2d(pb), 'BLUE')
    display.FitAll()
def brep_feat_local_revolution(event=None):
    S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape()
    faces = list(TopologyExplorer(S).faces())
    F1 = faces[2]
    surf = BRep_Tool_Surface(F1)

    D = gp_OX()

    MW1 = BRepBuilderAPI_MakeWire()
    p1 = gp_Pnt2d(100., 100.)
    p2 = gp_Pnt2d(200., 100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())

    p1 = gp_Pnt2d(200., 100.)
    p2 = gp_Pnt2d(150., 200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())

    p1 = gp_Pnt2d(150., 200.)
    p2 = gp_Pnt2d(100., 100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())

    MKF1 = BRepBuilderAPI_MakeFace()
    MKF1.Init(surf, False, 1e-6)
    MKF1.Add(MW1.Wire())
    FP = MKF1.Face()
    breplib_BuildCurves3d(FP)
    MKrev = BRepFeat_MakeRevol(S, FP, F1, D, 1, True)
    F2 = faces[4]
    MKrev.Perform(F2)
    display.EraseAll()
    display.DisplayShape(MKrev.Shape())
    display.FitAll()
Exemplo n.º 12
0
    def make_shape(self):
        # 1 - retrieve the data from the UIUC airfoil data page
        foil_dat_url = 'http://m-selig.ae.illinois.edu/ads/coord_seligFmt/%s.dat' % self.profile
        print("Connecting to m-selig, retrieving foil data")
        f = urllib2.urlopen(foil_dat_url)
        print("Building foil geometry")
        plan = gp_Pln(gp_Pnt(0., 0., 0.), gp_Dir(0., 0.,
                                                 1.))  # Z=0 plan / XY plan
        section_pts_2d = []

        for line in f.readlines()[1:]:  # The first line contains info only
            # 2 - do some cleanup on the data (mostly dealing with spaces)
            data = line.split()
            # 3 - create an array of points
            if len(data) == 2:  # two coordinates for each point
                section_pts_2d.append(
                    gp_Pnt2d(
                        float(data[0]) * self.chord,
                        float(data[1]) * self.chord))

        # 4 - use the array to create a spline describing the airfoil section
        spline_2d = Geom2dAPI_PointsToBSpline(
            point2d_list_to_TColgp_Array1OfPnt2d(section_pts_2d),
            len(section_pts_2d) - 1,  # order min
            len(section_pts_2d))  # order max
        spline = geomapi.To3d(spline_2d.Curve(), plan)

        # 5 - figure out if the trailing edge has a thickness or not,
        # and create a Face
        try:
            # first and last point of spline -> trailing edge
            trailing_edge = make_edge(
                gp_Pnt(section_pts_2d[0].X(), section_pts_2d[0].Y(), 0.0),
                gp_Pnt(section_pts_2d[-1].X(), section_pts_2d[-1].Y(), 0.0))
            face = BRepBuilderAPI_MakeFace(
                make_wire([make_edge(spline), trailing_edge]))
        except AssertionError:
            # the trailing edge segment could not be created, probably because
            # the points are too close
            # No need to build a trailing edge
            face = BRepBuilderAPI_MakeFace(make_wire(make_edge(spline)))

        # 6 - extrude the Face to create a Solid
        return BRepPrimAPI_MakePrism(
            face.Face(), gp_Vec(gp_Pnt(0., 0., 0.),
                                gp_Pnt(0., 0., self.span))).Shape()
Exemplo n.º 13
0
def parabola(event=None):
    # P is the vertex point
    # P and D give the axis of symmetry
    # 6 is the focal length of the parabola
    a_pnt = gp_Pnt2d(2, 3)
    a_dir = gp_Dir2d(4, 5)
    an_ax = gp_Ax22d(a_pnt, a_dir, True)
    para = gp_Parab2d(an_ax, 6)
    display.DisplayShape(a_pnt)
    display.DisplayMessage(a_pnt, "P")

    aParabola = GCE2d_MakeParabola(para)
    gParabola = aParabola.Value()

    aTrimmedCurve = Geom2d_TrimmedCurve(gParabola, -100, 100, True)

    display.DisplayShape(aTrimmedCurve, update=True)
def brepfeat_prism(event=None):
    box = BRepPrimAPI_MakeBox(400, 250, 300).Shape()
    faces = TopologyExplorer(box).faces()

    for i in range(5):
        face = next(faces)

    srf = BRep_Tool_Surface(face)

    c = gp_Circ2d(gp_Ax2d(gp_Pnt2d(200, 130), gp_Dir2d(1, 0)), 75)

    circle = Geom2d_Circle(c)

    wire = BRepBuilderAPI_MakeWire()
    wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, 0., pi).Edge())
    wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, pi, 2. * pi).Edge())
    wire.Build()

    display.DisplayShape(wire.Wire())

    mkf = BRepBuilderAPI_MakeFace()
    mkf.Init(srf, False, 1e-6)
    mkf.Add(wire.Wire())
    mkf.Build()

    new_face = mkf.Face()
    breplib_BuildCurves3d(new_face)

    display.DisplayShape(new_face)

    prism = BRepFeat_MakeDPrism(box, mkf.Face(), face, 100, True, True)

    prism.Perform(400)
    assert prism.IsDone()
    display.EraseAll()
    display.DisplayShape(prism.Shape())
    display.DisplayColoredShape(wire.Wire(), 'RED')
    display.FitAll()
def points_from_curve():
    radius = 5.
    abscissa = 3.
    circle = Geom2d_Circle(gp_OX2d(), radius, True)
    gac = Geom2dAdaptor_Curve(circle)
    ua = GCPnts_UniformAbscissa(gac, abscissa)
    a_sequence = []
    if ua.IsDone():
        n = ua.NbPoints()
        for count in range(1, n + 1):
            p = gp_Pnt2d()
            circle.D0(ua.Parameter(count), p)
            a_sequence.append(p)
    # convert analytic to bspline
    display.DisplayShape(circle, update=True)
    i = 0
    for p in a_sequence:
        i = i + 1
        pstring = 'P%i : parameter %f' % (i, ua.Parameter(i))
        pnt = gp_Pnt(p.X(), p.Y(), 0)
        # display points
        display.DisplayShape(pnt, update=True)
        display.DisplayMessage(pnt, pstring)
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')
Exemplo n.º 17
0
 def as_2d(self):
     '''returns a gp_Pnt2d version of self'''
     return gp_Pnt2d(*self._pnt.Coord()[:2])
def brep_feat_extrusion_protrusion(event=None):
    # Extrusion
    S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape()
    faces = TopologyExplorer(S).faces()
    F = next(faces)
    surf1 = BRep_Tool_Surface(F)

    Pl1 = Geom_Plane.DownCast(surf1)

    D1 = Pl1.Pln().Axis().Direction().Reversed()
    MW = BRepBuilderAPI_MakeWire()
    p1, p2 = gp_Pnt2d(200., -100.), gp_Pnt2d(100., -100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge())

    p1, p2 = gp_Pnt2d(100., -100.), gp_Pnt2d(100., -200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge())

    p1, p2 = gp_Pnt2d(100., -200.), gp_Pnt2d(200., -200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge())

    p1, p2 = gp_Pnt2d(200., -200.), gp_Pnt2d(200., -100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge())

    MKF = BRepBuilderAPI_MakeFace()
    MKF.Init(surf1, False, 1e-6)
    MKF.Add(MW.Wire())
    FP = MKF.Face()
    breplib_BuildCurves3d(FP)

    display.EraseAll()
    MKP = BRepFeat_MakePrism(S, FP, F, D1, 0, True)
    MKP.PerformThruAll()

    res1 = MKP.Shape()
    display.DisplayShape(res1)

    # Protrusion
    next(faces)
    F2 = next(faces)
    surf2 = BRep_Tool_Surface(F2)
    Pl2 = Geom_Plane.DownCast(surf2)
    D2 = Pl2.Pln().Axis().Direction().Reversed()
    MW2 = BRepBuilderAPI_MakeWire()
    p1, p2 = gp_Pnt2d(100., 100.), gp_Pnt2d(200., 100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge())

    p1, p2 = gp_Pnt2d(200., 100.), gp_Pnt2d(150., 200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge())

    p1, p2 = gp_Pnt2d(150., 200.), gp_Pnt2d(100., 100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge())

    MKF2 = BRepBuilderAPI_MakeFace()
    MKF2.Init(surf2, False, 1e-6)
    MKF2.Add(MW2.Wire())
    MKF2.Build()

    FP = MKF2.Face()
    breplib_BuildCurves3d(FP)
    MKP2 = BRepFeat_MakePrism(res1, FP, F2, D2, 0, True)
    MKP2.PerformThruAll()
    display.EraseAll()

    trf = gp_Trsf()
    trf.SetTranslation(gp_Vec(0, 0, 300))
    gtrf = gp_GTrsf()
    gtrf.SetTrsf(trf)
    tr = BRepBuilderAPI_GTransform(MKP2.Shape(), gtrf, True)

    fused = BRepAlgoAPI_Fuse(tr.Shape(), MKP2.Shape())
    fused.Build()

    display.DisplayShape(fused.Shape())
    display.FitAll()
def face():
    p1 = gp_Pnt()
    p2 = gp_Pnt()
    p3 = gp_Pnt()
    p4 = gp_Pnt()
    p5 = gp_Pnt()
    p6 = gp_Pnt()

    # The white Face
    sphere = gp_Sphere(gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 150)
    green_face = BRepBuilderAPI_MakeFace(sphere, 0.1, 0.7, 0.2, 0.9)

    # The red face
    p1.SetCoord(-15, 200, 10)
    p2.SetCoord(5, 204, 0)
    p3.SetCoord(15, 200, 0)
    p4.SetCoord(-15, 20, 15)
    p5.SetCoord(-5, 20, 0)
    p6.SetCoord(15, 20, 35)
    array = TColgp_Array2OfPnt(1, 3, 1, 2)
    array.SetValue(1, 1, p1)
    array.SetValue(2, 1, p2)
    array.SetValue(3, 1, p3)
    array.SetValue(1, 2, p4)
    array.SetValue(2, 2, p5)
    array.SetValue(3, 2, p6)
    curve = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2,
                                           0.001).Surface()
    red_face = BRepBuilderAPI_MakeFace(curve, 1e-6)

    #The brown face
    circle = gp_Circ(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 80)
    Edge1 = BRepBuilderAPI_MakeEdge(circle, 0, math.pi)
    Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, -80), gp_Pnt(0, -10, 40))
    Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, -10, 40), gp_Pnt(0, 0, 80))

    ##TopoDS_Wire YellowWire
    MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge())
    if not MW1.IsDone():
        raise AssertionError("MW1 is not done.")
    yellow_wire = MW1.Wire()
    brown_face = BRepBuilderAPI_MakeFace(yellow_wire)

    #The pink face
    p1.SetCoord(35, -200, 40)
    p2.SetCoord(50, -204, 30)
    p3.SetCoord(65, -200, 30)
    p4.SetCoord(35, -20, 45)
    p5.SetCoord(45, -20, 30)
    p6.SetCoord(65, -20, 65)
    array2 = TColgp_Array2OfPnt(1, 3, 1, 2)
    array2.SetValue(1, 1, p1)
    array2.SetValue(2, 1, p2)
    array2.SetValue(3, 1, p3)
    array2.SetValue(1, 2, p4)
    array2.SetValue(2, 2, p5)
    array2.SetValue(3, 2, p6)
    BSplineSurf = GeomAPI_PointsToBSplineSurface(array2, 3, 8, GeomAbs_C2,
                                                 0.001)
    aFace = BRepBuilderAPI_MakeFace(BSplineSurf.Surface(), 1e-6).Face()
    ##
    ##//2d lines
    P12d = gp_Pnt2d(0.9, 0.1)
    P22d = gp_Pnt2d(0.2, 0.7)
    P32d = gp_Pnt2d(0.02, 0.1)
    ##
    line1 = Geom2d_Line(P12d, gp_Dir2d((0.2 - 0.9), (0.7 - 0.1)))
    line2 = Geom2d_Line(P22d, gp_Dir2d((0.02 - 0.2), (0.1 - 0.7)))
    line3 = Geom2d_Line(P32d, gp_Dir2d((0.9 - 0.02), (0.1 - 0.1)))
    ##
    ##//Edges are on the BSpline surface
    Edge1 = BRepBuilderAPI_MakeEdge(line1, BSplineSurf.Surface(), 0,
                                    P12d.Distance(P22d)).Edge()
    Edge2 = BRepBuilderAPI_MakeEdge(line2, BSplineSurf.Surface(), 0,
                                    P22d.Distance(P32d)).Edge()
    Edge3 = BRepBuilderAPI_MakeEdge(line3, BSplineSurf.Surface(), 0,
                                    P32d.Distance(P12d)).Edge()
    ##
    Wire1 = BRepBuilderAPI_MakeWire(Edge1, Edge2, Edge3).Wire()
    Wire1.Reverse()
    pink_face = BRepBuilderAPI_MakeFace(aFace, Wire1).Face()
    breplib_BuildCurves3d(pink_face)

    display.DisplayColoredShape(green_face.Face(), 'GREEN')
    display.DisplayColoredShape(red_face.Face(), 'RED')
    display.DisplayColoredShape(pink_face, Quantity_Color(Quantity_NOC_PINK))
    display.DisplayColoredShape(brown_face.Face(), 'BLUE')
    display.DisplayColoredShape(yellow_wire, 'YELLOW', update=True)
def build_tooth():
    base_center = gp_Pnt2d(pitch_circle_radius + (tooth_radius - roller_radius), 0)
    base_circle = gp_Circ2d(gp_Ax2d(base_center, gp_Dir2d()), tooth_radius)
    trimmed_base = GCE2d_MakeArcOfCircle(base_circle,
                                         M_PI - (roller_contact_angle / 2.),
                                         M_PI).Value()
    trimmed_base.Reverse()  # just a trick
    p0 = trimmed_base.StartPoint()
    p1 = trimmed_base.EndPoint()

    # Determine the center of the profile circle
    x_distance = cos(roller_contact_angle / 2.) * (profile_radius + tooth_radius)
    y_distance = sin(roller_contact_angle / 2.) * (profile_radius + tooth_radius)
    profile_center = gp_Pnt2d(pitch_circle_radius - x_distance, y_distance)

    # Construct the profile circle gp_Circ2d
    profile_circle = gp_Circ2d(gp_Ax2d(profile_center, gp_Dir2d()),
                               profile_center.Distance(p1))
    geom_profile_circle = GCE2d_MakeCircle(profile_circle).Value()

    # Construct the outer circle gp_Circ2d
    outer_circle = gp_Circ2d(gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d()), top_radius)
    geom_outer_circle = GCE2d_MakeCircle(outer_circle).Value()

    inter = Geom2dAPI_InterCurveCurve(geom_profile_circle, geom_outer_circle)
    num_points = inter.NbPoints()
    assert isinstance(p1, gp_Pnt2d)
    if num_points == 2:
        if p1.Distance(inter.Point(1)) < p1.Distance(inter.Point(2)):
            p2 = inter.Point(1)
        else:
            p2 = inter.Point(2)
    elif num_points == 1:
        p2 = inter.Point(1)
    else:
        sys.exit(-1)

    # Trim the profile circle and mirror
    trimmed_profile = GCE2d_MakeArcOfCircle(profile_circle, p1, p2).Value()

    # Calculate the outermost point
    p3 = gp_Pnt2d(cos(tooth_angle / 2.) * top_radius,
                  sin(tooth_angle / 2.) * top_radius)

    # and use it to create the third arc
    trimmed_outer = GCE2d_MakeArcOfCircle(outer_circle, p2, p3).Value()

    # Mirror and reverse the three arcs
    mirror_axis = gp_Ax2d(gp_Origin2d(), gp_DX2d().Rotated(tooth_angle / 2.))

    mirror_base = Geom2d_TrimmedCurve.DownCast(trimmed_base.Copy())
    mirror_profile = Geom2d_TrimmedCurve.DownCast(trimmed_profile.Copy())
    mirror_outer = Geom2d_TrimmedCurve.DownCast(trimmed_outer.Copy())

    mirror_base.Mirror(mirror_axis)
    mirror_profile.Mirror(mirror_axis)
    mirror_outer.Mirror(mirror_axis)

    mirror_base.Reverse()
    mirror_profile.Reverse()
    mirror_outer.Reverse()

    # Replace the two outer arcs with a single one
    outer_start = trimmed_outer.StartPoint()
    outer_mid = trimmed_outer.EndPoint()
    outer_end = mirror_outer.EndPoint()

    outer_arc = GCE2d_MakeArcOfCircle(outer_start, outer_mid, outer_end).Value()

    # Create an arc for the inside of the wedge
    inner_circle = gp_Circ2d(gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d()),
                             top_radius - roller_diameter)
    inner_start = gp_Pnt2d(top_radius - roller_diameter, 0)
    inner_arc = GCE2d_MakeArcOfCircle(inner_circle, inner_start, tooth_angle).Value()
    inner_arc.Reverse()

    # Convert the 2D arcs and two extra lines to 3D edges
    plane = gp_Pln(gp_Origin(), gp_DZ())
    arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_base, plane)).Edge()
    arc2 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_profile, plane)).Edge()
    arc3 = BRepBuilderAPI_MakeEdge(geomapi_To3d(outer_arc, plane)).Edge()
    arc4 = BRepBuilderAPI_MakeEdge(geomapi_To3d(mirror_profile, plane)).Edge()
    arc5 = BRepBuilderAPI_MakeEdge(geomapi_To3d(mirror_base, plane)).Edge()

    p4 = mirror_base.EndPoint()
    p5 = inner_arc.StartPoint()

    lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0),
                                   gp_Pnt(p5.X(), p5.Y(), 0)).Edge()
    arc6 = BRepBuilderAPI_MakeEdge(geomapi_To3d(inner_arc, plane)).Edge()

    p6 = inner_arc.EndPoint()
    lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p6.X(), p6.Y(), 0),
                                   gp_Pnt(p0.X(), p0.Y(), 0)).Edge()

    wire = BRepBuilderAPI_MakeWire(arc1)
    wire.Add(arc2)
    wire.Add(arc3)
    wire.Add(arc4)
    wire.Add(arc5)
    wire.Add(lin1)
    wire.Add(arc6)
    wire.Add(lin2)

    face = BRepBuilderAPI_MakeFace(wire.Wire())

    wedge = BRepPrimAPI_MakePrism(face.Shape(), gp_Vec(0.0, 0.0, thickness))

    return wedge.Shape()
def round_tooth(wedge):
    round_x = 2.6
    round_z = 0.06 * pitch
    round_radius = pitch

    # Determine where the circle used for rounding has to start and stop
    p2d_1 = gp_Pnt2d(top_radius - round_x, 0)
    p2d_2 = gp_Pnt2d(top_radius, round_z)

    # Construct the rounding circle
    round_circle = GccAna_Circ2d2TanRad(p2d_1, p2d_2, round_radius, 0.01)
    if (round_circle.NbSolutions() != 2):
        sys.exit(-2)

    round_circle_2d_1 = round_circle.ThisSolution(1)
    round_circle_2d_2 = round_circle.ThisSolution(2)

    if (round_circle_2d_1.Position().Location().Coord()[1] >= 0):
        round_circle_2d = round_circle_2d_1
    else:
        round_circle_2d = round_circle_2d_2

    # Remove the arc used for rounding
    trimmed_circle = GCE2d_MakeArcOfCircle(round_circle_2d, p2d_1, p2d_2).Value()

    # Calculate extra points used to construct lines
    p1 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y())
    p2 = gp_Pnt(p2d_2.X(), 0, p2d_2.Y())
    p3 = gp_Pnt(p2d_2.X() + 1, 0, p2d_2.Y())
    p4 = gp_Pnt(p2d_2.X() + 1, 0, p2d_1.Y() - 1)
    p5 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y() - 1)

    # Convert the arc and four extra lines into 3D edges
    plane = gp_Pln(gp_Ax3(gp_Origin(), gp_DY().Reversed(), gp_DX()))
    arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_circle, plane)).Edge()
    lin1 = BRepBuilderAPI_MakeEdge(p2, p3).Edge()
    lin2 = BRepBuilderAPI_MakeEdge(p3, p4).Edge()
    lin3 = BRepBuilderAPI_MakeEdge(p4, p5).Edge()
    lin4 = BRepBuilderAPI_MakeEdge(p5, p1).Edge()

    # Make a wire composed of the edges
    round_wire = BRepBuilderAPI_MakeWire(arc1)
    round_wire.Add(lin1)
    round_wire.Add(lin2)
    round_wire.Add(lin3)
    round_wire.Add(lin4)

    # Turn the wire into a face
    round_face = BRepBuilderAPI_MakeFace(round_wire.Wire()).Shape()

    # Revolve the face around the Z axis over the tooth angle
    rounding_cut_1 = BRepPrimAPI_MakeRevol(round_face, gp_OZ(), tooth_angle).Shape()

    # Construct a mirrored copy of the first cutting shape
    mirror = gp_Trsf()
    mirror.SetMirror(gp_XOY())
    mirrored_cut_1 = BRepBuilderAPI_Transform(rounding_cut_1, mirror, True).Shape()

    # and translate it so that it ends up on the other side of the wedge
    translate = gp_Trsf()
    translate.SetTranslation(gp_Vec(0, 0, thickness))
    rounding_cut_2 = BRepBuilderAPI_Transform(mirrored_cut_1, translate, False).Shape()

    # Cut the wedge using the first and second cutting shape
    cut_1 = BRepAlgoAPI_Cut(wedge, rounding_cut_1).Shape()
    cut_2 = BRepAlgoAPI_Cut(cut_1, rounding_cut_2).Shape()

    return cut_2
##the Free Software Foundation, either version 3 of the License, or
##(at your option) any later version.
##
##pythonOCC is distributed in the hope that it will be useful,
##but WITHOUT ANY WARRANTY; without even the implied warranty of
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##GNU Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.
from math import pi

from OCCT.gp import gp_Pnt2d, gp_XOY, gp_Lin2d, gp_Ax3, gp_Dir2d
from OCCT.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
from OCCT.Geom import Geom_CylindricalSurface
from OCCT.GCE2d import GCE2d_MakeSegment

from OCC.Display.WebGl import threejs_renderer

# First buil an helix
aCylinder = Geom_CylindricalSurface(gp_Ax3(gp_XOY()), 6.0)
aLine2d = gp_Lin2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(1.0, 1.0))
aSegment = GCE2d_MakeSegment(aLine2d, 0.0, pi * 2.0)

helix_edge = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCylinder, 0.0,
                                     6.0 * pi).Edge()

display = threejs_renderer.ThreejsRenderer()
display.DisplayShape(helix_edge, color=(1, 0, 0), line_width=1.)
display.render()
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.º 24
0
            faceToRemove = aFace

    aFaceExplorer.Next()

facesToRemove = TopTools_ListOfShape()
facesToRemove.Append(faceToRemove)

myBody = BRepOffsetAPI_MakeThickSolid(myBody.Shape(), facesToRemove, -thickness / 50.0, 0.001)

# Set up our surfaces for the threading on the neck
neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ())
aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99)
aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05)

# Set up the curves for the threads on the bottle's neck
aPnt = gp_Pnt2d(2.0 * math.pi, myNeckHeight / 2.0)
aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0)
anAx2d = gp_Ax2d(aPnt, aDir)

aMajor = 2.0 * math.pi
aMinor = myNeckHeight / 10.0

anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor)
anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0)

anArc1 = Geom2d_TrimmedCurve(anEllipse1, 0, math.pi)
anArc2 = Geom2d_TrimmedCurve(anEllipse2, 0, math.pi)

anEllipsePnt1 = anEllipse1.Value(0)
anEllipsePnt2 = anEllipse1.Value(math.pi)