Beispiel #1
0
def prism():
    # the bspline profile
    array = TColgp_Array1OfPnt(1, 5)
    array.SetValue(1, gp_Pnt(0, 0, 0))
    array.SetValue(2, gp_Pnt(1, 2, 0))
    array.SetValue(3, gp_Pnt(2, 3, 0))
    array.SetValue(4, gp_Pnt(4, 3, 0))
    array.SetValue(5, gp_Pnt(5, 5, 0))
    bspline = GeomAPI_PointsToBSpline(array).Curve()
    profile = BRepBuilderAPI_MakeEdge(bspline).Edge()

    # the linear path
    starting_point = gp_Pnt(0., 0., 0.)
    end_point = gp_Pnt(0., 0., 6.)
    vec = gp_Vec(starting_point, end_point)
    path = BRepBuilderAPI_MakeEdge(starting_point, end_point).Edge()

    # extrusion
    prism = BRepPrimAPI_MakePrism(profile, vec).Shape()

    display.DisplayShape(profile, update=False)
    display.DisplayShape(starting_point, update=False)
    display.DisplayShape(end_point, update=False)
    display.DisplayShape(path, update=False)
    display.DisplayShape(prism, update=True)
Beispiel #2
0
def _make_edge(crv, interval=None) -> Shape:
    aCurve = crv.Curve()
    if interval is None:
        return Shape(BRepBuilderAPI_MakeEdge(aCurve).Edge())
    else:
        return Shape(
            BRepBuilderAPI_MakeEdge(aCurve, interval[0], interval[1]).Edge())
def pipe():
    # the bspline path, must be a wire
    array2 = TColgp_Array1OfPnt(1, 3)
    array2.SetValue(1, gp_Pnt(0, 0, 0))
    array2.SetValue(2, gp_Pnt(0, 1, 2))
    array2.SetValue(3, gp_Pnt(0, 2, 3))
    bspline2 = GeomAPI_PointsToBSpline(array2).Curve()
    path_edge = BRepBuilderAPI_MakeEdge(bspline2).Edge()
    path_wire = BRepBuilderAPI_MakeWire(path_edge).Wire()

    # the bspline profile. Profile mist be a wire
    array = TColgp_Array1OfPnt(1, 5)
    array.SetValue(1, gp_Pnt(0, 0, 0))
    array.SetValue(2, gp_Pnt(1, 2, 0))
    array.SetValue(3, gp_Pnt(2, 3, 0))
    array.SetValue(4, gp_Pnt(4, 3, 0))
    array.SetValue(5, gp_Pnt(5, 5, 0))
    bspline = GeomAPI_PointsToBSpline(array).Curve()
    profile_edge = BRepBuilderAPI_MakeEdge(bspline).Edge()

    # pipe
    pipe = BRepOffsetAPI_MakePipe(path_wire, profile_edge).Shape()

    display.DisplayShape(profile_edge, update=False)
    display.DisplayShape(path_wire, update=False)
    display.DisplayShape(pipe, update=True)
Beispiel #4
0
def thicken_spline(event=None):
    # Creation of points for the spine
    array = TColgp_Array1OfPnt(1, 5)
    array.SetValue(1, gp_Pnt(1, 4, 0))
    array.SetValue(2, gp_Pnt(2, 2, 0))
    array.SetValue(3, gp_Pnt(3, 3, 0))
    array.SetValue(4, gp_Pnt(4, 3, 0))
    array.SetValue(5, gp_Pnt(5, 5, 0))

    # Creation of a Bezier Curve as the spine
    bz_curv = Geom_BezierCurve(array)
    bz_curv_edge = BRepBuilderAPI_MakeEdge(bz_curv).Edge()
    bz_curv_wire = BRepBuilderAPI_MakeWire(bz_curv_edge).Wire()
    display.DisplayShape(bz_curv_wire)

    # Creation of profile to sweep along the spine
    circle = gp_Circ(gp_ZOX(), 1)
    circle.SetLocation(array[0])
    circle_edge = BRepBuilderAPI_MakeEdge(circle).Edge()
    circle_wire = BRepBuilderAPI_MakeWire(circle_edge).Wire()

    # Creation of the law to dictate the evolution of the profile
    brep1 = BRepOffsetAPI_MakePipeShell(bz_curv_wire)
    law_f = Law_Linear()
    law_f.Set(0, 0.5, 1, 1)
    brep1.SetLaw(circle_wire, law_f, False, True)
    return brep1.Shape()
Beispiel #5
0
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()
Beispiel #6
0
    def __init__(self, crv1, crv2, itol=1.0e-7):
        super(IntersectCurveCurve, self).__init__(crv1, crv2)

        # Build edges from curve
        e1 = BRepBuilderAPI_MakeEdge(crv1.object).Edge()
        e2 = BRepBuilderAPI_MakeEdge(crv2.object).Edge()

        # Set tolerance to be half intersection tolerance
        shp_tol = ShapeFix_ShapeTolerance()
        tol = itol / 2.
        shp_tol.SetTolerance(e1, tol)
        shp_tol.SetTolerance(e2, tol)

        # Perform edge-edge intersection
        cci = IntTools_EdgeEdge(e1, e2)
        cci.Perform()

        # Gather results of point intersection only
        results = []
        common_parts = cci.CommonParts()
        for i in range(1, common_parts.Length() + 1):
            common_part = common_parts.Value(i)
            if not common_part.Type() == TopAbs_VERTEX:
                continue
            u1 = common_part.VertexParameter1()
            u2 = common_part.VertexParameter2()
            p1 = crv1.eval(u1)
            p2 = crv2.eval(u2)
            pi = mean([p1, p2], axis=0)
            pi = Point(*pi)
            results.append([(u1, u2), pi])

        npts = len(results)
        self._set_results(npts, results)
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
    Pl = Handle_Geom_Plane_DownCast(surf)
    Pln = Pl.GetObject()

    # 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 display_coord(pnt, vecx, vecy, vecz):
    rayx = BRepBuilderAPI_MakeEdge(
        pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vecx * 10).XYZ())).Edge()
    rayy = BRepBuilderAPI_MakeEdge(
        pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vecy * 10).XYZ())).Edge()
    rayz = BRepBuilderAPI_MakeEdge(
        pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vecz * 10).XYZ())).Edge()
    display.DisplayShape(rayx, color='RED', update=False)
    display.DisplayShape(rayy, color='GREEN', update=False)
    display.DisplayShape(rayz, color='BLUE1', update=False)
Beispiel #9
0
def makeLines():
    global aEdge1, aEdge2, aEdge3
    # Make type 'Geom_TrimmedCurve' from type 'gp_Pnt'
    aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
    aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
    aSegment2 = GC_MakeSegment(aPnt4, aPnt5)
    # Make type 'TopoDS_Edge' from type 'Geom_TrimmedCurve'
    aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
    aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
    aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())
    return (aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge())
 def display_coord(frames):
     for frame in frames:
         [pnt, vecx, vecy, vecz] = frame
         rayx = BRepBuilderAPI_MakeEdge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) +\
         vecx*30).XYZ())).Edge()
         rayy = BRepBuilderAPI_MakeEdge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) +\
          vecy*30).XYZ())).Edge()
         rayz = BRepBuilderAPI_MakeEdge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) +\
          vecz*30).XYZ())).Edge()
         display.DisplayShape(rayx, color='RED', update=False)
         display.DisplayShape(rayy, color='GREEN', update=False)
         display.DisplayShape(rayz, color='BLUE1', update=False)
def display_coord(pnts, vecx, vecy, vecz):
    for i in range(0, len(pnts)):
        rayx = BRepBuilderAPI_MakeEdge(
            pnts[i], gp_Pnt(
                (gp_Vec(pnts[i].XYZ()) + vecx[i] * 10).XYZ())).Edge()
        rayy = BRepBuilderAPI_MakeEdge(
            pnts[i], gp_Pnt(
                (gp_Vec(pnts[i].XYZ()) + vecy[i] * 10).XYZ())).Edge()
        rayz = BRepBuilderAPI_MakeEdge(
            pnts[i], gp_Pnt(
                (gp_Vec(pnts[i].XYZ()) + vecz[i] * 10).XYZ())).Edge()
        display.DisplayShape(rayx, color='RED', update=False)
        display.DisplayShape(rayy, color='GREEN', update=False)
        display.DisplayShape(rayz, color='BLUE1', update=False)
Beispiel #12
0
def makeLines(event=None):
    global aEdge1, aEdge2, aEdge3
    aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
    aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
    aSegment2 = GC_MakeSegment(aPnt4, aPnt5)
    # Display lines
    aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
    aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
    aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())
    display.DisplayColoredShape(aEdge1.Edge(), 'RED')
    display.DisplayColoredShape(aEdge2.Edge(), 'RED')
    display.DisplayColoredShape(aEdge3.Edge(), 'RED')
    display.Repaint()
    win.statusBar().showMessage('Make lines complete')
Beispiel #13
0
def dao_01_scene(r):

    #compute primitives

    r2 = r/2

    gpPntMinC = gp_Pnt(0,r2,0)

    p0 = gp_Pnt(0,0,0)
    p1 = getPntRotate(gpPntMinC , p0, -pi/4)
    p2 = gp_Pnt(-r2,r2,0)
    p3 = getPntRotate(gpPntMinC , p0, -pi/4*3)
    p4 = gp_Pnt(0,r,0)
    p5 = gp_Pnt(r,0,0)
    p6 = gp_Pnt(0,-r,0)
    p7 = gp_Pnt(r2,-r2,0)

    arc1 =  GC_MakeArcOfCircle(p0,p1,p2).Value()
    arc2 =  GC_MakeArcOfCircle(p2,p3,p4).Value()
    arc3 =  GC_MakeArcOfCircle(p4,p5,p6).Value()
    arc4 =  GC_MakeArcOfCircle(p6,p7,p0).Value()

    edge1 = BRepBuilderAPI_MakeEdge(arc1).Edge()
    edge2 = BRepBuilderAPI_MakeEdge(arc2).Edge()
    edge3 = BRepBuilderAPI_MakeEdge(arc3).Edge()
    edge4 = BRepBuilderAPI_MakeEdge(arc4).Edge()

    daoWire =  BRepBuilderAPI_MakeWire(edge1, edge2, edge3, edge4).Wire()

    # scene template
    sc = new Scene

    # scene transform
    sc.Circle('baseCircle',gp_Pnt(r,0,0), gp_Pnt(0,r,0), gp_Pnt(-r,0,0), 'stInfo')

    sc.Point('p0', p0)
    sc.Point('p1', p0)
    sc.Point('p2', p0)
    sc.Point('p3', p0)
    sc.Point('p4', p0)
    sc.Point('p5', p0)
    sc.Point('p6', p0)
    sc.Point('p7', p0)

    sc.Wire('daoWire', daoWire)

    # styling
    sc.Styling('baseCircle','stInfo')

    return sc
Beispiel #14
0
def edge(event=None):
    # The blud edge
    BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20),
                                       gp_Pnt(-30, -60, -60))
    V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30))
    V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25))
    YellowEdge = BRepBuilderAPI_MakeEdge(V1.Vertex(), V2.Vertex())

    #The white edge
    line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0)))
    WhiteEdge = BRepBuilderAPI_MakeEdge(line, -20, 10)

    #The red edge
    Elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30)
    RedEdge = BRepBuilderAPI_MakeEdge(Elips, 0, math.pi/2)

    # The green edge and the both extreme vertex
    P1 = gp_Pnt(-15, 200, 10)
    P2 = gp_Pnt(5, 204, 0)
    P3 = gp_Pnt(15, 200, 0)
    P4 = gp_Pnt(-15, 20, 15)
    P5 = gp_Pnt(-5, 20, 0)
    P6 = gp_Pnt(15, 20, 0)
    P7 = gp_Pnt(24, 120, 0)
    P8 = gp_Pnt(-24, 120, 12.5)
    array = TColgp_Array1OfPnt(1, 8)
    array.SetValue(1, P1)
    array.SetValue(2, P2)
    array.SetValue(3, P3)
    array.SetValue(4, P4)
    array.SetValue(5, P5)
    array.SetValue(6, P6)
    array.SetValue(7, P7)
    array.SetValue(8, P8)
    curve = Geom_BezierCurve(array)
    ME = BRepBuilderAPI_MakeEdge(curve)
    GreenEdge = ME
    V3 = ME.Vertex1()
    V4 = ME.Vertex2()

    display.DisplayColoredShape(BlueEdge.Edge(), 'BLUE')
    display.DisplayShape(V1.Vertex())
    display.DisplayShape(V2.Vertex())
    display.DisplayColoredShape(WhiteEdge.Edge(), 'WHITE')
    display.DisplayColoredShape(YellowEdge.Edge(), 'YELLOW')
    display.DisplayColoredShape(RedEdge.Edge(), 'RED')
    display.DisplayColoredShape(GreenEdge.Edge(), 'GREEN')
    display.DisplayShape(V3)
    display.DisplayShape(V4, update=True)
Beispiel #15
0
 def __init__(self, controlpoints: numpy, knots: numpy, m: int, degree: int,
              periodic: bool):
     super().__init__()
     self.edge = TopAbs_EDGE
     array = []
     for pnt in controlpoints:
         p = OccPoint(pnt)
         array.append(p.Value())
     poles = point_list_to_TColgp_Array1OfPnt(array)
     # Normalise the knots and find multiplicities
     multp = OCCWrapper.OccMultiplicities(knots)
     uknots = multp.knots()
     multiplicity = multp.multiplcity()
     knotvector = TColStd_Array1OfReal(1, len(uknots))
     i = 1
     for v in uknots:
         knotvector.SetValue(i, v)
         i = i + 1
     mult = TColStd_Array1OfInteger(1, len(multiplicity))
     i = 1
     for m in multiplicity:
         mult.SetValue(i, int(m))
         i = i + 1
     mknurbs = Geom_BSplineCurve(poles, knotvector, mult, degree, periodic)
     mkedge = BRepBuilderAPI_MakeEdge(mknurbs)
     if not mkedge.IsDone():
         OCCWrapper.OccError(type(self), mkedge)
     else:
         self.done = True
         self.edge = mkedge.Edge()
     return
 def test_Standard_Type(self) -> None:
     """ test that Standard_Type returns the correct type name
     """
     edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, 0), gp_Pnt(1, 0, 0)).Edge()
     curve, _, _ = BRep_Tool_Curve(edge)
     line = Geom_Line.DownCast(curve)
     self.assertEqual(line.DynamicType().Name(), "Geom_Line")
Beispiel #17
0
 def MouseMoveEvent(self, thePnt2d: gp_Pnt2d, buttons, modifiers):
     self.curPnt2d = self.myAnalyserSnap.MouseMove(thePnt2d)
     if self.myBSplineCurveAction == BSplineCurveAction.Nothing:
         pass
     elif self.myBSplineCurveAction == BSplineCurveAction.Input_1Point:
         pass
     elif self.myBSplineCurveAction == BSplineCurveAction.Input_2Point:
         # self.mySecondPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
         # self.myRubberLine.SetPoints(self.myFirstPoint, self.mySecondPoint)
         # self.myContext.Redisplay(self.myRubberLine, True)
         pass
     elif self.myBSplineCurveAction == BSplineCurveAction.Input_OtherPoints:
         self.myGeom2d_BSplineCurve.SetPole(self.IndexCounter,
                                            self.curPnt2d)
         self.mySecondPoint.SetPnt(
             elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
         self.myGeom_BSplineCurve.SetPole(self.IndexCounter,
                                          self.mySecondPoint.Pnt())
         ME = BRepBuilderAPI_MakeEdge(self.myGeom_BSplineCurve)
         if ME.IsDone():
             self.curEdge = ME.Edge()
             self.myRubberAIS_Shape.Set(self.curEdge)
             self.myContext.Redisplay(self.myRubberAIS_Shape, True)
         else:
             self.IndexCounter -= 1
Beispiel #18
0
 def CancelEvent(self):
     if self.myBSplineCurveAction == BSplineCurveAction.Nothing:
         pass
     elif self.myBSplineCurveAction == BSplineCurveAction.Input_1Point:
         pass
     elif self.myBSplineCurveAction == BSplineCurveAction.Input_2Point:
         self.bspline.RemoveLabel()
         del self.bspline
     elif self.myBSplineCurveAction == BSplineCurveAction.Input_OtherPoints:
         if len(self.Poles) <= 3:
             self.bspline.RemoveLabel()
             del self.bspline
             self.myContext.Remove(self.myRubberAIS_Shape, True)
         # remove the last pole
         del self.Poles2d[-1]
         del self.Poles[-1]
         self.Multi, self.Knots = setQuasiUniformKnots(
             len(self.Poles), self.myDegree)
         self.CreateBspline()
         ME = BRepBuilderAPI_MakeEdge(self.myGeom_BSplineCurve)
         if ME.IsDone():
             self.curEdge = ME.Edge()
             self.closeBSpline()
             self.IndexCounter -= 1
     self.myBSplineCurveAction = BSplineCurveAction.Nothing
    def test_inherit_topods_shape(self):
        at = self.assertTrue
        af = self.assertFalse

        class InheritEdge(TopoDS_Edge):
            def __init__(self, edge):
                # following constructor creates an empy TopoDS_Edge
                super(InheritEdge, self).__init__()
                # we need to copy the base shape using the following three
                # lines
                at(self.IsNull())
                self.TShape(edge.TShape())
                self.Location(edge.Location())
                self.Orientation(edge.Orientation())
                af(self.IsNull())
                # then it becomes possible to extend the base class

        # create a line, compute its length
        base_edge = BRepBuilderAPI_MakeEdge(gp_Pnt(100., 0., 0.),
                                            gp_Pnt(150., 0., 0.)).Edge()
        inherited_edge = InheritEdge(base_edge)
        g1 = GProp_GProps()
        brepgprop_LinearProperties(inherited_edge, g1)
        length = g1.Mass()
        self.assertEqual(length, 50.)
Beispiel #20
0
def occ_triangle_mesh(event=None):
    #
    # Mesh the shape
    #
    BRepMesh_IncrementalMesh(aShape, 0.1)
    builder = BRep_Builder()
    Comp = TopoDS_Compound()
    builder.MakeCompound(Comp)

    ex = TopExp_Explorer(aShape, TopAbs_FACE)
    while ex.More():
        F = topods_Face(ex.Current())
        L = TopLoc_Location()
        facing = (BRep_Tool().Triangulation(F, L))
        tab = facing.Nodes()
        tri = facing.Triangles()
        for i in range(1, facing.NbTriangles() + 1):
            trian = tri.Value(i)
            #print trian
            index1, index2, index3 = trian.Get()
            for j in range(1, 4):
                if j == 1:
                    M = index1
                    N = index2
                elif j == 2:
                    N = index3
                elif j == 3:
                    M = index2
                ME = BRepBuilderAPI_MakeEdge(tab.Value(M), tab.Value(N))
                if ME.IsDone():
                    builder.Add(Comp, ME.Edge())
        ex.Next()
    display.DisplayShape(Comp, update=True)
Beispiel #21
0
def extrude_polyline2d(polyline, frame, height):
    pol3d = polyline.to_frame(frame)
    lines = []
    yb_point = Point([frame[0][i] for i in range(3)])
    yb_vec = Vector([frame[1][0][i] for i in range(3)]).unit()
    print '*************'
    print yb_vec
    orig = gp_Pnt(frame[0][0], frame[0][1], frame[0][2])
    vec = gp_Dir(yb_vec[0], yb_vec[1], yb_vec[2])
    plane = gp_Pln(orig, vec)

    for i, p in enumerate(pol3d[:-1]):
        print p
        print 'zob'
        gp0 = gp_Pnt(p[0], p[1], p[2])
        gp1 = gp_Pnt(pol3d[i + 1][0], pol3d[i + 1][1], pol3d[i + 1][2])
        lines.append(BRepBuilderAPI_MakeEdge(gp0, gp1).Edge())

    wire = BRepBuilderAPI_MakeWire(lines[0])

    for l in lines[1:]:
        wire.Add(l)

    face = BRepBuilderAPI_MakeFace(wire.Wire())
    print 'normal'
    print[vec.X(), vec.Y(), vec.Z()]
    extrude = BRepPrimAPI_MakePrism(
        face.Shape(),
        gp_Vec(height * vec.X(), height * vec.Y(), height * vec.Z())).Shape()
    return extrude
Beispiel #22
0
def trimedge(lbound, ubound, occedge):
    """
    This function trims the OCCedge according to the specified lower and upper bound.
 
    Parameters
    ----------
    lbound : float
        The lower bound of the OCCedge.
        
    ubound : float
        The upper bound of the OCCedge.
        
    occedge : OCCedge
        The edge to be trimmed.

    Returns
    -------
    trimmed edge : OCCedge
        The trimmed OCCedge.
    """
    adaptor = BRepAdaptor_Curve(occedge)
    tr = Geom_TrimmedCurve(adaptor.Curve().Curve(), lbound, ubound)
    tr.SetTrim(lbound, ubound)
    bspline_handle = geomconvert_CurveToBSplineCurve(tr.BasisCurve())
    tr_edge = BRepBuilderAPI_MakeEdge(bspline_handle)

    return tr_edge.Edge()
Beispiel #23
0
def face_mesh_triangle(comp=TopoDS_Shape(), isR=0.1, thA=0.1):
    # Mesh the shape
    BRepMesh_IncrementalMesh(comp, isR, True, thA, True)
    bild1 = BRep_Builder()
    comp1 = TopoDS_Compound()
    bild1.MakeCompound(comp1)
    bt = BRep_Tool()
    ex = TopExp_Explorer(comp, TopAbs_FACE)
    while ex.More():
        face = topods_Face(ex.Current())
        location = TopLoc_Location()
        facing = bt.Triangulation(face, location)
        tab = facing.Nodes()
        tri = facing.Triangles()
        print(facing.NbTriangles(), facing.NbNodes())
        for i in range(1, facing.NbTriangles() + 1):
            trian = tri.Value(i)
            index1, index2, index3 = trian.Get()
            for j in range(1, 4):
                if j == 1:
                    m = index1
                    n = index2
                elif j == 2:
                    n = index3
                elif j == 3:
                    m = index2
                me = BRepBuilderAPI_MakeEdge(tab.Value(m), tab.Value(n))
                if me.IsDone():
                    bild1.Add(comp1, me.Edge())
        ex.Next()
    return comp1
Beispiel #24
0
def make_revolved_cylinder(pnt, height, revolve_angle, rotation, wall_thick):
    """
    This method demonstrates how to create a revolved shape from a drawn closed edge.
    It currently creates a hollow cylinder

    adapted from algotopia.com's opencascade_basic tutorial:
    http://www.algotopia.com/contents/opencascade/opencascade_basic

    :param pnt:
    :param height:
    :param revolve_angle:
    :param rotation:
    :param wall_thick:
    :type pnt: dict
    :type height: float
    :type revolve_angle: float
    :type rotation: float
    :type wall_thick: float
    """
    from OCC.Core.BRepBuilderAPI import (
        BRepBuilderAPI_MakeEdge,
        BRepBuilderAPI_MakeFace,
        BRepBuilderAPI_MakeWire,
    )
    from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeRevol
    from OCC.Core.gp import gp_Ax1, gp_Dir, gp_Pnt

    face_inner_radius = pnt["X"] + (17.0 - wall_thick / 2) * 1000
    face_outer_radius = pnt["X"] + (17.0 + wall_thick / 2) * 1000

    # point to create an edge from
    edg_points = [
        gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"]),
        gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"] + height),
        gp_Pnt(face_outer_radius, pnt["Y"], pnt["Z"] + height),
        gp_Pnt(face_outer_radius, pnt["Y"], pnt["Z"]),
        gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"]),
    ]

    # aggregate edges in wire
    hexwire = BRepBuilderAPI_MakeWire()

    for i in range(len(edg_points) - 1):
        hexedge = BRepBuilderAPI_MakeEdge(edg_points[i],
                                          edg_points[i + 1]).Edge()
        hexwire.Add(hexedge)

    hexwire_wire = hexwire.Wire()
    # face from wire
    hexface = BRepBuilderAPI_MakeFace(hexwire_wire).Face()
    revolve_axis = gp_Ax1(gp_Pnt(pnt["X"], pnt["Y"], pnt["Z"]),
                          gp_Dir(0, 0, 1))
    # create revolved shape
    revolved_shape_ = BRepPrimAPI_MakeRevol(hexface, revolve_axis,
                                            np.radians(
                                                float(revolve_angle))).Shape()
    revolved_shape_ = rotate_shp_3_axis(revolved_shape_, revolve_axis,
                                        rotation)

    return revolved_shape_
Beispiel #25
0
    def write_edge(points_edge, topo_edge):
        """
        Method to recreate an Edge associated to a geometric curve
        after the modification of its points.
        :param points_edge: the deformed points array.
        :param topo_edge: the Edge to be modified
        :return: Edge (Shape)

        :rtype: TopoDS_Edge

        """
        # convert Edge to Geom B-spline Curve
        nurbs_converter = BRepBuilderAPI_NurbsConvert(topo_edge)
        nurbs_converter.Perform(topo_edge)
        nurbs_curve = nurbs_converter.Shape()
        topo_curve = topods_Edge(nurbs_curve)
        h_geomcurve = BRep_Tool.Curve(topo_curve)[0]
        h_bcurve = geomconvert_CurveToBSplineCurve(h_geomcurve)
        bspline_edge_curve = h_bcurve

        # Edge geometric properties
        nb_cpt = bspline_edge_curve.NbPoles()
        # check consistency
        if points_edge.shape[0] != nb_cpt:
            raise ValueError("Input control points do not have not have the "
                             "same number as the geometric edge!")

        else:
            for i in range(1, nb_cpt + 1):
                cpt = points_edge[i - 1]
                bspline_edge_curve.SetPole(i, gp_Pnt(cpt[0], cpt[1], cpt[2]))

        new_edge = BRepBuilderAPI_MakeEdge(bspline_edge_curve)

        return new_edge.Edge()
Beispiel #26
0
    def display_vector(self, origin, direction):
        r"""Display a vector starting at origin and going in direction

        Parameters
        ----------
        origin : tuple(float)
            The origin coordinates (x, y, z) of the vector to display
        direction : tuple(float)
            The direction coordinates (x, y, z) of the vector to display

        """
        xo, yo, zo = origin
        xd, yd, zd = direction
        end = (xo + xd, yo + xd, zo + zd)
        xe, ye, ze = end

        # self.glarea.d3d.DisplayVector(gp_Vec(xd, yd, zd), gp_Pnt(xo, yo, zo))

        presentation = Prs3d_Presentation(self.glarea.occ_context.MainPrsMgr().
                                          GetObject().StructureManager())
        arrow = Prs3d_Arrow()
        arrow.Draw(presentation.GetHandle(), gp_Pnt(xe, ye, ze),
                   gp_Dir(gp_Vec(xd, yd, zd)), _math.radians(20),
                   gp_Vec(xd, yd, zd).Magnitude() / 4.)
        presentation.Display()

        e1 = BRepBuilderAPI_MakeEdge(gp_Pnt(xo, yo, zo), gp_Pnt(xe, ye, ze)).\
            Edge()
        self.display(e1, line_width=4)
Beispiel #27
0
def split_edge_with_face(event=None):
    display.EraseAll()
    p0 = gp_Pnt()
    vnorm = gp_Dir(1, 0, 0)
    pln = gp_Pln(p0, vnorm)
    face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
    p1 = gp_Pnt(0, 0, 15)
    p2 = gp_Pnt(0, 0, -15)
    edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
    # Initialize splitter
    splitter = BOPAlgo_Splitter()
    # Add the edge as an argument and the face as a tool. This will split
    # the edge with the face.
    splitter.AddArgument(edge)
    splitter.AddTool(face)
    splitter.Perform()

    edges = []
    exp = TopExp_Explorer(splitter.Shape(), TopAbs_EDGE)
    while exp.More():
        edges.append(exp.Current())
        exp.Next()
    print('Number of edges in split shape: ', len(edges))
    display.DisplayShape(edges[0], color='red')
    display.DisplayShape(edges[1], color='green')
    display.DisplayShape(edges[2], color='yellow')
    display.FitAll()
 def display_path(lay, col):
     wire = BRepBuilderAPI_MakeWire()
     for i in range(1, len(lay)):
         if lay[i - 1][0].Distance(lay[i][0]) < 50:
             ray = BRepBuilderAPI_MakeEdge(lay[i - 1][0], lay[i][0]).Edge()
             wire.Add(ray)
     display.DisplayShape(wire.Wire(), color=col, update=False)
Beispiel #29
0
def main():

    vertices = [gp_Pnt(p[0], p[1], p[2]) for p in mesh['vertices']]
    oFaces = []

    builder = BRep_Builder()
    shell = TopoDS_Shell()
    builder.MakeShell(shell)

    for face in mesh['faces']:
        edges = []
        face.reverse()
        for i in range(len(face)):
            cur = face[i]
            nxt = face[(i + 1) % len(face)]
            segment = GC_MakeSegment(vertices[cur], vertices[nxt])
            edges.append(BRepBuilderAPI_MakeEdge(segment.Value()))

        wire = BRepBuilderAPI_MakeWire()
        for edge in edges:
            wire.Add(edge.Edge())

        oFace = BRepBuilderAPI_MakeFace(wire.Wire())
        builder.Add(shell, oFace.Shape())
    write_stl_file(shell, "./cube_binding.stl")
Beispiel #30
0
  def generate_tool_targets(self):
    ba = BRepAdaptor_Curve(self.helix_edge)
    u_min = ba.FirstParameter()
    u_max = ba.LastParameter()
    u_step = 0.1
    u_now = u_min
    while u_now <= u_max:
      v_contact = gp_Vec(ba.Value(u_now).XYZ())
      if self.inside: # cut inside
        v_contact_to_ball_center = -gp_Vec(v_contact.X(),v_contact.Y(),0).Normalized()*self.ball_radius
      else: # cut outside
        v_contact_to_ball_center =  gp_Vec(v_contact.X(),v_contact.Y(),0).Normalized()*self.ball_radius
      trsf = gp_Trsf()
      trsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1)),pi/2)
      v_rotation_axis = v_contact_to_ball_center.Transformed(trsf)
      trsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(v_rotation_axis.XYZ())),radians(self.cutting_angle))
      v_ball_center_to_tool_tip = gp_Vec(0,0,-self.ball_radius)
      v_ball_center_to_tool_tip.Transform(trsf)
      v_tool_tip = v_contact+v_contact_to_ball_center+v_ball_center_to_tool_tip
      v_tool_orientation = - v_ball_center_to_tool_tip.Normalized() * (0.500+1e-8)

      if self.create_target_vis_edges:
        me = BRepBuilderAPI_MakeEdge(gp_Pnt(v_tool_tip.XYZ()),gp_Pnt((v_tool_tip+v_tool_orientation).XYZ()))
        self.target_edges.append(me.Edge())

      I = v_tool_tip.X() / 1000
      J = v_tool_tip.Y() / 1000
      K = v_tool_tip.Z() / 1000

      U = v_tool_orientation.X()
      V = v_tool_orientation.Y()
      W = v_tool_orientation.Z()


      x,y,z,a,b = self.ikSolver.solve((I,J,K,U,V,W),1e-6,False)

      x += self.output_offset[0]
      y += self.output_offset[1]
      z += self.output_offset[2]
      a += self.output_offset[3]
      b += self.output_offset[4]

      if self.v_previous_contact_point:
        cut_distance = (v_contact - self.v_previous_contact_point).Magnitude()
        f = self.feedrate / cut_distance
        self.gcode += "G01 X{:.6f} Y{:.6f} Z{:.6f} A{:.6f} B{:.6f} F{:.6f}\n".format(x,y,z,a,b,f)
      else:
        f = 0
        self.gcode += "G0 X{:.6f} Y{:.6f} Z{:.6f} A{:.6f} B{:.6f}\n".format(x,y,z,a,b)
      self.v_previous_contact_point = v_contact

      print(x,y,z,a,b)

      if u_now == u_max:
        break
      u_next = u_now + u_step
      if u_next > u_max:
        u_next = u_max
      u_now = u_next