def MouseInputEvent(self, thePnt2d: gp_Pnt2d, buttons, modifier): if self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Nothing: pass elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_CenterPoint: self.curPnt2d = self.myAnalyserSnap.MouseInput(thePnt2d) self.myFirstgp_Pnt2d = gp_Pnt2d(self.curPnt2d.X(), self.curPnt2d.Y()) self.myFirstPoint.SetPnt( elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d)) self.myCircleAx2d.SetLocation(self.myFirstgp_Pnt2d) self.tempGeom_Circle.SetLocation(self.myFirstPoint.Pnt()) self.tempGeom_Circle.SetRadius(SKETCH_RADIUS) self.myRubberCircle.SetCircle(self.tempGeom_Circle) self.myContext.Display(self.myRubberCircle, True) self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Input_RadiusPoint elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_RadiusPoint: self.curPnt2d = self.myAnalyserSnap.MouseInputException( self.myFirstgp_Pnt2d, thePnt2d, TangentType.Circle_CenterPnt, True) self.radius = self.myFirstgp_Pnt2d.Distance(self.curPnt2d) self.tempGeom2d_Circle = Geom2d_Circle.DownCast( geomapi_To2d(self.tempGeom_Circle, gp_Pln(self.curCoordinateSystem))) self.myContext.Remove(self.myRubberCircle, True) nurbs = self.ToNurbs_Square(self.myFirstgp_Pnt2d, self.radius) self.bspline_node = BsplineNode(nurbs.GetName(), self.rootNode) self.bspline_node.setSketchObject(nurbs) self.AddObject(self.tempGeom2d_Circle, nurbs.GetAIS_Object(), Sketch_GeometryType.CircleSketchObject) self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Nothing return False
def __init__(self): super(Sketch_CommandArc3P, self).__init__("Arc3P.") self.myArc3PAction = Arc3PAction.Nothing self.tempGeom_Circle = Geom_Circle(self.curCoordinateSystem.Ax2(), SKETCH_RADIUS) self.myRubberCircle = AIS_Circle(self.tempGeom_Circle) self.myRubberCircle.SetColor(Quantity_Color(Quantity_NOC_LIGHTPINK1)) self.temp2d_Circ = gp_Circ2d() self.temp_Circ = gp_Circ(self.curCoordinateSystem.Ax2(), SKETCH_RADIUS) self.temp2dAdaptor_Curve = Geom2dAdaptor_Curve() self.mySecondgp_Pnt2d = gp.Origin2d() self.third_Pnt = gp.Origin() self.midpoint2d = gp.Origin2d() self.tempu1_pnt2d = gp.Origin2d() self.tempu2_pnt2d = gp.Origin2d() self.tempGeom2d_Line = Geom2d_Line(self.tempu1_pnt2d, gp.DX2d()) self.tempGeom2d_Circle = Geom2d_Circle(self.temp2d_Circ) self.FirstGeom2d_Point = Geom2d_CartesianPoint(self.tempu1_pnt2d) self.TempGeom2d_Point = Geom2d_CartesianPoint(self.tempu2_pnt2d) self.u1 =0 self.u2 = 0 self.temp_u1=0 self.temp_u2 = 0 self.dist1=0 self.dist2 = 0
def test_circles2d_from_curves(self): '''Test: circles2d from curves''' P1 = gp_Pnt2d(9, 6) P2 = gp_Pnt2d(10, 4) P3 = gp_Pnt2d(6, 7) C = gce_MakeCirc2d(P1, P2, P3).Value() QC = gccent_Outside(C) P4 = gp_Pnt2d(-2, 7) P5 = gp_Pnt2d(12, -3) L = GccAna_Lin2d2Tan(P4, P5, precision_Confusion()).ThisSolution(1) QL = gccent_Unqualified(L) radius = 2. TR = GccAna_Circ2d2TanRad(QC, QL, radius, precision_Confusion()) if TR.IsDone(): NbSol = TR.NbSolutions() for k in range(1, NbSol + 1): circ = TR.ThisSolution(k) # find the solution circle pnt1 = gp_Pnt2d() parsol, pararg = TR.Tangency1(k, pnt1) self.assertGreater(parsol, 0.) self.assertGreater(pararg, 0.) # find the first tangent point pnt2 = gp_Pnt2d() parsol, pararg = TR.Tangency2(k, pnt2) self.assertGreater(parsol, 0.) self.assertGreater(pararg, 0.) # find the second tangent point aLine = GCE2d_MakeSegment(L, -2, 20).Value() self.assertIsInstance(aLine, Geom2d_TrimmedCurve) if TR.IsDone(): NbSol = TR.NbSolutions() for k in range(1, NbSol + 1): circ = TR.ThisSolution(k) aCircle = Geom2d_Circle(circ) self.assertIsInstance(aCircle, Geom2d_Circle) # find the solution circle (index, outvalue, outvalue, gp_Pnt2d) pnt3 = gp_Pnt2d() parsol, pararg = TR.Tangency1(k, pnt3) self.assertGreater(parsol, 0.) self.assertGreater(pararg, 0.) # find the first tangent point pnt4 = gp_Pnt2d() parsol, pararg = TR.Tangency2(k, pnt4) self.assertGreater(parsol, 0.) self.assertGreater(pararg, 0.)
def test_point_from_curve(self): '''Test: point from curve''' radius, abscissa = 5., 3. C = Geom2d_Circle(gp_OX2d(), radius, True) GAC = Geom2dAdaptor_Curve(C) UA = GCPnts_UniformAbscissa(GAC, abscissa) aSequence = [] if UA.IsDone(): N = UA.NbPoints() for count in range(1, N + 1): P = gp_Pnt2d() C.D0(UA.Parameter(count), P) Parameter = UA.Parameter(count) self.assertIsInstance(Parameter, float) aSequence.append(P) Abscissa = UA.Abscissa() self.assertEqual(Abscissa, abscissa)
def MouseInputEvent(self, thePnt2d: gp_Pnt2d, buttons, modifier): if self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Nothing: pass elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_CenterPoint: self.curPnt2d = self.myAnalyserSnap.MouseInput(thePnt2d) self.myFirstgp_Pnt2d = gp_Pnt2d(self.curPnt2d.X(), self.curPnt2d.Y()) self.myFirstPoint.SetPnt( elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d)) self.myCircleAx2d.SetLocation(self.myFirstgp_Pnt2d) self.tempGeom_Circle.SetLocation(self.myFirstPoint.Pnt()) self.tempGeom_Circle.SetRadius(SKETCH_RADIUS) self.myRubberCircle.SetCircle(self.tempGeom_Circle) self.myContext.Display(self.myRubberCircle, True) self.myRubberLine.SetPoints(self.myFirstPoint, self.myFirstPoint) self.myContext.Display(self.myRubberLine, True) self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Input_RadiusPoint elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_RadiusPoint: self.curPnt2d = self.myAnalyserSnap.MouseInputException( self.myFirstgp_Pnt2d, thePnt2d, TangentType.Circle_CenterPnt, True) self.radius = self.myFirstgp_Pnt2d.Distance(self.curPnt2d) myGeom2d_Circle = Geom2d_Circle(self.myCircleAx2d, self.radius) Geom_Circle1 = Geom_Circle( elclib.To3d(self.curCoordinateSystem.Ax2(), myGeom2d_Circle.Circ2d())) myAIS_Circle = AIS_Circle(Geom_Circle1) self.AddObject(myGeom2d_Circle, myAIS_Circle, Sketch_GeometryType.CircleSketchObject) self.myContext.Remove(self.myRubberCircle, True) self.myContext.Remove(self.myRubberLine, True) self.myContext.Display(myAIS_Circle, True) self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Input_CenterPoint return False
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 convert_circ_to_geom2dCirc(self, circ): (cx, cy), r = circ return Geom2d_Circle( gp_Circ2d(gp_Ax2d(gp_Pnt2d(cx, cy), gp_Dir2d(1, 0)), r))