Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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)
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
0
 def __init__(self, p1: numpy, p2: numpy):
     super().__init__()
     self.done = False
     self.edge = None
     gp1 = gp_Pnt(p1[0], p1[1], p1[2])
     gp2 = gp_Pnt(p2[0], p2[1], p2[2])
     edge = BRepBuilderAPI_MakeEdge(gp1, gp2)
     if not edge.IsDone():
         OCCWrapper.OccError('OccEdge', edge)
     else:
         self.done = True
     self.edge = edge.Edge()
 def CancelEvent(self):
     if self.myBezierCurveAction == BezierCurveAction.Nothing:
         pass
     elif self.myBezierCurveAction == BezierCurveAction.Input_1Point:
         pass
     elif self.myBezierCurveAction == BezierCurveAction.Input_2Point:
         # self.myContext.Remove(self.myRubberLine, True)
         self.bezier_curve.RemoveDisplay()
     elif self.myBezierCurveAction == BezierCurveAction.Input_OtherPoints:
         self.myGeom2d_BezierCurve.RemovePole(self.IndexCounter)
         self.myGeom_BezierCurve.RemovePole(self.IndexCounter)
         ME = BRepBuilderAPI_MakeEdge(self.myGeom_BezierCurve,
                                      self.myFirstgp_Pnt, self.tempPnt)
         if ME.IsDone():
             self.curEdge = ME.Edge()
             self.IndexCounter -= 1
             self.CloseBezierCurve()
     self.myBezierCurveAction = BezierCurveAction.Nothing
Ejemplo n.º 8
0
def simple_mesh():
    #
    # Create the shape
    #
    theBox = BRepPrimAPI_MakeBox(200, 60, 60).Shape()
    theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape()
    shape = BRepAlgoAPI_Fuse(theSphere, theBox).Shape()
    #
    # Mesh the shape
    #
    BRepMesh_IncrementalMesh(shape, 0.8)
    builder = BRep_Builder()
    comp = TopoDS_Compound()
    builder.MakeCompound(comp)

    bt = BRep_Tool()
    ex = TopExp_Explorer(shape, TopAbs_FACE)
    while ex.More():
        face = topods_Face(ex.Current())
        location = TopLoc_Location()
        facing = (bt.Triangulation(face, location)).GetObject()
        tab = facing.Nodes()
        tri = facing.Triangles()
        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():
                    builder.Add(comp, me.Edge())
        ex.Next()
    display.EraseAll()
    display.DisplayShape(shape)
    display.DisplayShape(comp, update=True)
Ejemplo n.º 9
0
 def __init__(self, p1: numpy, p2: numpy, p3: numpy):
     # p1: StartPoint
     # p2: EndPoint
     # p3: IntermediatePoint
     super().__init__()
     self.edge = TopAbs_EDGE
     gp1 = OccPoint(p1)
     gp2 = OccPoint(p2)
     gp3 = OccPoint(p3)
     mkarc = GC_MakeArcOfCircle(
         gp1.Value(), gp3.Value(),
         gp2.Value())  # Sequence: StartPoint, IntermediatePoint, EndPoint
     if not mkarc.IsDone():
         OCCWrapper.OccError(mkarc.Error())
     else:
         mkedge = BRepBuilderAPI_MakeEdge(mkarc.Value())
         if not mkedge.IsDone():
             OCCWrapper.OccError(mkedge.Error())
         else:
             self.done = True
             self.edge = mkedge.Edge()
     return
    def MouseInputEvent(self, thePnt2d: gp_Pnt2d, buttons, modifier):
        self.curPnt2d = self.myAnalyserSnap.MouseInput(thePnt2d)

        if self.myBezierCurveAction == BezierCurveAction.Nothing:
            pass
        elif self.myBezierCurveAction == BezierCurveAction.Input_1Point:
            # calculate first 2d and 3d point
            self.myFirstgp_Pnt2d = gp_Pnt2d(self.curPnt2d.X(),
                                            self.curPnt2d.Y())
            self.myFirstgp_Pnt = elclib.To3d(self.curCoordinateSystem.Ax2(),
                                             self.curPnt2d)
            # save first point
            self.myFirstPoint.SetPnt(self.myFirstgp_Pnt)
            # draw first point
            # self.myRubberLine.SetPoints(self.myFirstPoint, self.myFirstPoint)
            # initialize bezier curve data structure created in sketch geometry
            self.bezier_curve = Sketch_BezierCurve(self.myContext,
                                                   self.curCoordinateSystem)
            # render the first point and auxiliry line
            self.bezier_curve.AddPoles(self.curPnt2d)
            # render the rubber line
            # self.myContext.Display(self.myRubberLine, True)
            # ready for 2nd point input
            self.myBezierCurveAction = BezierCurveAction.Input_2Point
            self.IndexCounter = 2

        elif self.myBezierCurveAction == BezierCurveAction.Input_2Point:
            self.myGeom2d_BezierCurve.SetPole(1, self.myFirstgp_Pnt2d)
            self.myGeom2d_BezierCurve.SetPole(self.IndexCounter, self.curPnt2d)

            self.tempPnt = elclib.To3d(self.curCoordinateSystem.Ax2(),
                                       self.curPnt2d)
            self.myGeom_BezierCurve.SetPole(1, self.myFirstgp_Pnt)
            self.myGeom_BezierCurve.SetPole(self.IndexCounter, self.tempPnt)

            self.mySecondPoint.SetPnt(self.tempPnt)
            ME = BRepBuilderAPI_MakeEdge(self.myGeom_BezierCurve,
                                         self.myFirstgp_Pnt, self.tempPnt)
            if ME.IsDone():
                self.bezier_curve.AddPoles(self.curPnt2d)
                self.curEdge = ME.Edge()
                self.myRubberAIS_Shape.Set(self.curEdge)
                # self.myContext.Remove(self.myRubberLine, True)
                self.myContext.Display(self.myRubberAIS_Shape, True)

                self.myGeom2d_BezierCurve.InsertPoleAfter(
                    self.IndexCounter, self.curPnt2d)
                self.myGeom_BezierCurve.InsertPoleAfter(
                    self.IndexCounter, self.tempPnt)

                self.IndexCounter += 1
                self.myBezierCurveAction = BezierCurveAction.Input_OtherPoints
        elif self.myBezierCurveAction == BezierCurveAction.Input_OtherPoints:
            self.myGeom2d_BezierCurve.SetPole(self.IndexCounter, self.curPnt2d)

            self.tempPnt = elclib.To3d(self.curCoordinateSystem.Ax2(),
                                       self.curPnt2d)
            self.myGeom_BezierCurve.SetPole(self.IndexCounter, self.tempPnt)

            self.mySecondPoint.SetPnt(self.tempPnt)
            ME = BRepBuilderAPI_MakeEdge(self.myGeom_BezierCurve)
            if ME.IsDone():
                self.bezier_curve.AddPoles(self.curPnt2d)
                self.curEdge = ME.Edge()
                if self.IndexCounter > MAXIMUMPOLES:
                    self.CloseBezierCurve()
                else:
                    self.myRubberAIS_Shape.Set(self.curEdge)
                    self.myContext.Redisplay(self.myRubberAIS_Shape, True)

                    self.myGeom2d_BezierCurve.InsertPoleAfter(
                        self.IndexCounter, self.curPnt2d)
                    self.myGeom_BezierCurve.InsertPoleAfter(
                        self.IndexCounter, self.tempPnt)
                    self.tempPnt2d = gp_Pnt2d(self.curPnt2d.X(),
                                              self.curPnt2d.Y())
                    self.IndexCounter += 1
        return False
Ejemplo n.º 11
0
    def MouseInputEvent(self, thePnt2d: gp_Pnt2d, buttons, modifier):
        self.curPnt2d = self.myAnalyserSnap.MouseInput(thePnt2d)

        if self.myBSplineCurveAction == BSplineCurveAction.Nothing:
            pass
        elif self.myBSplineCurveAction == BSplineCurveAction.Input_1Point:
            self.myFirstgp_Pnt2d = gp_Pnt2d(self.curPnt2d.X(),
                                            self.curPnt2d.Y())
            self.myFirstgp_Pnt = elclib.To3d(self.curCoordinateSystem.Ax2(),
                                             self.curPnt2d)
            self.myFirstPoint.SetPnt(self.myFirstgp_Pnt)
            # self.myRubberLine.SetPoints(self.myFirstPoint, self.myFirstPoint)

            self.Poles2d[0] = gp_Pnt2d(self.curPnt2d.X(), self.curPnt2d.Y())
            self.Poles[0] = gp_Pnt(self.myFirstgp_Pnt.X(),
                                   self.myFirstgp_Pnt.Y(),
                                   self.myFirstgp_Pnt.Z())
            self.CreateBspline()

            self.bspline = Sketch_Bspline(self.myContext,
                                          self.curCoordinateSystem)
            self.bspline.AddPoles(self.curPnt2d)

            # self.myContext.Display(self.myRubberLine, True)
            self.myBSplineCurveAction = BSplineCurveAction.Input_2Point
            self.IndexCounter = 2

        elif self.myBSplineCurveAction == BSplineCurveAction.Input_2Point:
            self.Poles2d[1] = gp_Pnt2d(self.curPnt2d.X(), self.curPnt2d.Y())
            self.tempPnt = elclib.To3d(self.curCoordinateSystem.Ax2(),
                                       self.curPnt2d)
            self.Poles[1] = gp_Pnt(self.tempPnt.X(), self.tempPnt.Y(),
                                   self.tempPnt.Z())
            self.mySecondPoint.SetPnt(self.tempPnt)
            self.CreateBspline()

            ME = BRepBuilderAPI_MakeEdge(self.myFirstgp_Pnt,
                                         self.mySecondPoint.Pnt())
            if ME.IsDone():
                self.bspline.AddPoles(self.curPnt2d)
                self.curEdge = ME.Edge()
                self.myRubberAIS_Shape.Set(self.curEdge)
                # self.myContext.Remove(self.myRubberLine, True)
                self.myContext.Display(self.myRubberAIS_Shape, True)

                self.IndexCounter += 1

                self.Poles2d.append(self.curPnt2d)
                self.Poles.append(self.tempPnt)
                self.Multi, self.Knots = setQuasiUniformKnots(
                    len(self.Poles), self.myDegree)
                self.CreateBspline()

                self.myBSplineCurveAction = BSplineCurveAction.Input_OtherPoints
        elif self.myBSplineCurveAction == BSplineCurveAction.Input_OtherPoints:
            self.Poles2d[self.IndexCounter - 1] = gp_Pnt2d(
                self.curPnt2d.X(), self.curPnt2d.Y())
            self.tempPnt = elclib.To3d(self.curCoordinateSystem.Ax2(),
                                       self.curPnt2d)
            self.Poles[self.IndexCounter - 1] = gp_Pnt(self.tempPnt.X(),
                                                       self.tempPnt.Y(),
                                                       self.tempPnt.Z())
            self.CreateBspline()

            self.mySecondPoint.SetPnt(self.tempPnt)
            ME = BRepBuilderAPI_MakeEdge(self.myGeom_BSplineCurve)
            if ME.IsDone():
                self.bspline.AddPoles(self.curPnt2d)
                self.curEdge = ME.Edge()
                if self.IndexCounter > MAXIMUMPOLES:
                    self.closeBSpline()
                else:
                    self.myRubberAIS_Shape.Set(self.curEdge)
                    self.myContext.Redisplay(self.myRubberAIS_Shape, True)

                    self.Poles2d.append(self.curPnt2d)
                    self.Poles.append(self.tempPnt)
                    self.Multi, self.Knots = setQuasiUniformKnots(
                        len(self.Poles), self.myDegree)
                    self.CreateBspline()
                    self.tempPnt2d = gp_Pnt2d(self.curPnt2d.X(),
                                              self.curPnt2d.Y())
                    self.IndexCounter += 1
        return False