コード例 #1
0
def project_point_on_curve():
    '''
    '''
    point_to_project = gp_Pnt(1., 2., 3.)
    radius = 5.

    # create a circle, centered at origin with a given radius
    circle = Geom_Circle(gp_XOY(), radius)
    display.DisplayShape(circle)
    display.DisplayShape(point_to_project, update=True)
    display.DisplayMessage(point_to_project, "P")

    # project the point P on the circle
    projection = GeomAPI_ProjectPointOnCurve(point_to_project,
                                             circle.GetHandle())
    # get the results of the projection
    # the point
    projected_point = projection.NearestPoint()
    # the number of possible results
    nb_results = projection.NbPoints()
    print("NbResults : %i" % nb_results)

    pstring = "N : at Distance : %f" % projection.LowerDistance()
    display.DisplayMessage(projected_point, pstring)

    # thre maybe many different possible solutions
    if nb_results > 0:
        for i in range(1, nb_results + 1):
            Q = projection.Point(i)
            distance = projection.Distance(i)
            pstring = "Q%i: at Distance :%f" % (i, distance)
            display.DisplayShape(Q)
            display.DisplayMessage(Q, pstring)
コード例 #2
0
    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
コード例 #3
0
ファイル: workplane.py プロジェクト: ponsingh/cadviewer
 def convert_circ_to_geomCirc(self, circ):
     """Convert 2d circle ((cx, cy), r) to type <Geom_Circle>"""
     (cx, cy), rad = circ
     cntrPt = gp_Pnt(cx, cy, 0)
     ax2 = gp_Ax2(cntrPt, gp_Dir(0, 0, 1))
     geomCirc = Geom_Circle(ax2, rad)
     geomCirc.Transform(self.Trsf)
     return geomCirc
 def __init__(self):
     super(Sketch_CommandCircleCenterRadius, self).__init__("CircleCR.")
     self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Nothing
     self.radius = 0.0
     self.tempGeom_Circle = Geom_Circle(self.curCoordinateSystem.Ax2(),
                                        SKETCH_RADIUS)
     self.myRubberCircle = AIS_Circle(self.tempGeom_Circle)
     self.myCircleAx2d = gp_Ax2d()
コード例 #5
0
 def __init__(self):
     super(Sketch_CommandNurbCircle, self).__init__("NURBS Circle.")
     self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Nothing
     self.radius = 0.0
     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.myCircleAx2d = gp_Ax2d()
コード例 #6
0
 def circ(self, cntr, rad, constr=False):
     """Create a construction circle """
     cx, cy = cntr
     cntrPt = gp_Pnt(cx, cy, 0)
     ax2 = gp_Ax2(cntrPt, gp_Dir(0, 0, 1))
     geomCirc = Geom_Circle(ax2, rad)
     geomCirc.Transform(self.Trsf)
     if constr:
         self.ccircList.append(geomCirc)
     else:
         edge = BRepBuilderAPI_MakeEdge(Geom_Curve(geomCirc))
         self.wire = BRepBuilderAPI_MakeWire(edge.Edge()).Wire()
         self.wireList.append(self.wire)
コード例 #7
0
    def test_project_point_on_curve(self):
        '''Test: project point on curve'''
        P = gp_Pnt(1., 2., 3.)
        radius = 5.

        C = Geom_Circle(gp_XOY(), radius)
        PPC = GeomAPI_ProjectPointOnCurve(P, C)
        N = PPC.NearestPoint()
        self.assertIsInstance(N, gp_Pnt)
        NbResults = PPC.NbPoints()
        edg = make_edge(C)
        self.assertFalse(edg.IsNull())

        if NbResults > 0:
            for i in range(1, NbResults + 1):
                Q = PPC.Point(i)
                self.assertIsInstance(Q, gp_Pnt)
                distance = PPC.Distance(i)
                # in any case, it should be > 1
                self.assertGreater(distance, 1.)

        pstring = "N : at Distance : " + repr(PPC.LowerDistance())

        for i in range(1, NbResults + 1):
            Q = PPC.Point(i)
            self.assertIsInstance(Q, gp_Pnt)
            distance = PPC.Distance(i)
            # in any case, it should be > 1
            self.assertGreater(distance, 1.)
            pstring = "Q" + repr(i) + ": at Distance :" + repr(PPC.Distance(i))
            print(pstring)
コード例 #8
0
    def __init__(self):
        plotocc.__init__(self)
        self.axs = gp_Ax3()

        self.circle = Geom_Circle(gp_Circ(self.axs.Ax2(), 100))
        p0, v1, v2 = gp_Pnt(), gp_Vec(), gp_Vec()
        GeomLProp_CurveTool.D2(self.circle, 0, p0, v1, v2)
        self.poly_axs = gp_Ax3(p0, vec_to_dir(v1))
        for num in range(4, 9):
            self.poly = self.make_PolyWire(
                num=num, radi=20.0, axs=self.poly_axs)

            self.base = self.make_Thru(50)
            self.display.DisplayShape(
                self.base, transparency=0.7, color="BLUE")
            write_step_file(self.base, self.tmpdir +
                            "ThruSurf_{:d}.stp".format(num))
コード例 #9
0
 def FindGeometry(self, object: AIS_InteractiveObject):
     if object.Type() == AIS_KOI_Shape:
         shape = self.myContext.SelectedShape()
         if shape.ShapeType() == TopAbs_VERTEX:
             pass
         elif shape.ShapeType() == TopAbs_EDGE:
             curve = BRepAdaptor_Curve(shape)
             curve_type = curve.GetType()
             if curve_type == GeomAbs_BezierCurve:
                 return curve.Bezier()
             elif curve_type == GeomAbs_BSplineCurve:
                 return curve.BSpline()
             elif curve_type == GeomAbs_Circle:
                 return Geom_Circle(curve.Circle())
             elif curve_type == GeomAbs_Line:
                 return Geom_Line(curve.Line())
         elif shape.ShapeType() == TopAbs_FACE:
             pass
    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
コード例 #11
0
 def recognize_edge(self, a_edge):
     """ Takes a TopoDS shape and tries to identify its nature
     whether it is a plane a cylinder a torus etc.
     if a plane, returns the normal
     if a cylinder, returns the radius
     """
     curve = BRepAdaptor_Curve(a_edge)
     curve_type = curve.GetType()
     if curve_type == GeomAbs_BezierCurve:
         print("--> Bezier")
         self._selectedShape = curve.Bezier()
     elif curve_type == GeomAbs_BSplineCurve:
         print("--> BSpline")
         self._selectedShape = curve.BSpline()
     elif curve_type == GeomAbs_Circle:
         print("--> Circle")
         self._selectedShape = Geom_Circle(curve.Circle())
     else:
         # TODO there are plenty other type that can be checked
         # see documentation for the BRepAdaptor class
         # https://www.opencascade.com/doc/occt-6.9.1/refman/html/class_b_rep_adaptor___surface.html
         print("not implemented")
コード例 #12
0
    def face_rotate(self, face=TopoDS_Face(), axs=gp_Ax1()):
        plan = self.pln_on_face(face)
        plan_axs = plan.Position()
        self.display.DisplayShape(plan_axs.Location())

        v0 = dir_to_vec(self.tmp_axis.Direction())
        v1 = dir_to_vec(plan_axs.Direction())
        print(v0.Dot(v1))

        lin_vec = gp_Vec(axs.Location(), plan_axs.Location())
        edg_circl = Geom_Circle(
            gp_Circ(
                gp_Ax2(axs.Location(), axs.Direction(), vec_to_dir(lin_vec)),
                5))
        rim_u0, rim_u1 = edg_circl.FirstParameter(), edg_circl.LastParameter()
        rim_p0 = edg_circl.Value(rim_u0)

        pln_angle = self.tmp_axis.Angle(plan_axs)
        ref_angle = self.tmp_axis.Direction().AngleWithRef(
            plan_axs.Direction(), axs.Direction())
        print(np.rad2deg(pln_angle), np.rad2deg(ref_angle))

        rim_u2 = -ref_angle
        rim_p2 = edg_circl.Value(rim_u2)
        rim_angle = Geom_TrimmedCurve(edg_circl, rim_u0, rim_u2)

        trf = gp_Trsf()
        #trf.SetRotation(axs, 2*np.pi - ref_angle)
        if np.abs(ref_angle) >= np.pi / 2:
            trf.SetRotation(axs, -ref_angle)
        elif 0 < ref_angle < np.pi / 2:
            trf.SetRotation(axs, np.pi - ref_angle)
        elif -np.pi / 2 < ref_angle < 0:
            trf.SetRotation(axs, -ref_angle - np.pi)
        else:
            trf.SetRotation(axs, -ref_angle)
        #trf.SetTransformation(axs3.Rotated(axs, angle), axs3)
        loc_face = TopLoc_Location(trf)
        new_face = face.Moved(loc_face)
        self.display.DisplayShape(new_face, transparency=0.5)
        self.display.DisplayShape(rim_angle)
        self.display.DisplayShape(rim_p0)
        self.display.DisplayShape(rim_p2)
        return new_face
コード例 #13
0
    def MakeCircleFace(self, Radius: float) -> TopoDS_Face:
        circle  = Geom_Circle( gp_XOY(), Radius )
        ed      = make_edge( circle )
        wire    = make_wire( ed )

        return make_face( wire )
class Sketch_CommandNurbCircleTriangle(Sketch_Command):
    def __init__(self):
        super(Sketch_CommandNurbCircleTriangle, self).__init__("NURBS Circle.")
        self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Nothing
        self.radius = 0.0
        self.tempGeom_Circle = Geom_Circle(self.curCoordinateSystem.Ax2(), SKETCH_RADIUS)
        self.myRubberCircle = AIS_Circle(self.tempGeom_Circle)
        self.myRubberCircle.SetColor(Quantity_Color(Quantity_NOC_BLUE1))
        self.myCircleAx2d = gp_Ax2d()

    def Action(self):
        self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Input_CenterPoint
        self.tempGeom_Circle.SetAxis(self.curCoordinateSystem.Axis())
        # if self.curCoordinateSystem.XDirection():
        #     self.myCircleAx2d.SetDirection(gp_Dir2d(self.curCoordinateSystem.XDirection().X(), self.curCoordinateSystem.XDirection().Y()))

    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)
            self.tempGeom2d_Circle = Geom2d_Circle.DownCast(
                geomapi_To2d(self.tempGeom_Circle, gp_Pln(self.curCoordinateSystem)))
            self.myContext.Remove(self.myRubberCircle, True)

            nurbs = self.ToNurbs_Triangle()
            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 MouseMoveEvent(self, thePnt2d: gp_Pnt2d, buttons, modifiers):
        if self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Nothing:
            pass
        elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_CenterPoint:
            self.curPnt2d = self.myAnalyserSnap.MouseMove(thePnt2d)
        elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_RadiusPoint:
            self.curPnt2d = self.myAnalyserSnap.MouseMoveException(self.myFirstgp_Pnt2d, thePnt2d,
                                                                   TangentType.Circle_CenterPnt, True)
            self.radius = self.myFirstgp_Pnt2d.Distance(self.curPnt2d)
            if self.radius == 0.0:
                self.radius = 1.0
            self.tempGeom_Circle.SetRadius(self.radius)
            self.myContext.Redisplay(self.myRubberCircle, True)
            self.mySecondPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
            # self.myRubberLine.SetPoints(self.myFirstPoint, self.mySecondPoint)
            # self.myContext.Redisplay(self.myRubberLine, True)

    def CancelEvent(self):
        if self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Nothing:
            pass
        elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_CenterPoint:
            pass
        elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_RadiusPoint:
            self.myContext.Remove(self.myRubberCircle, True)
        self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Nothing

    def GetTypeOfMethod(self):
        return Sketch_ObjectTypeOfMethod.NurbsCircleTriangle_Method

    def ToNurbs_Triangle(self):
        nurbsCircle = Sketch_Bspline(self.myContext, self.curCoordinateSystem)
        convert: Geom_BSplineCurve = geomconvert_CurveToBSplineCurve(self.tempGeom_Circle)
        poles = TColgp_Array1OfPnt2d_to_point_list(convert.Poles())
        weights = convert.Weights()
        knots = convert.Knots()
        multiplicity = convert.Multiplicities()

        for pole in poles:
            x, y = pole.X(), pole.Y()
            nurbsCircle.AddPoles(gp_Pnt2d(x, y))
        nurbsCircle.AddPoles(gp_Pnt2d(poles[0].X(), poles[0].Y()))

        nurbsCircle.SetWeights([1.0, 0.5000000000000001, 1.0, 0.5000000000000001, 1.0, 0.5000000000000001, 1.0])
        nurbsCircle.SetKnots(TColStd_Array1OfNumber_to_list(knots))
        nurbsCircle.SetMultiplicities([3, 2, 2, 3])
        nurbsCircle.SetDegree(convert.Degree())

        nurbsCircle.Compute()
        return nurbsCircle
class Sketch_CommandCircleCenterRadius(Sketch_Command):
    """
    @attention: This command is not used in the program.
    """
    def __init__(self):
        super(Sketch_CommandCircleCenterRadius, self).__init__("CircleCR.")
        self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Nothing
        self.radius = 0.0
        self.tempGeom_Circle = Geom_Circle(self.curCoordinateSystem.Ax2(),
                                           SKETCH_RADIUS)
        self.myRubberCircle = AIS_Circle(self.tempGeom_Circle)
        self.myCircleAx2d = gp_Ax2d()

    def Action(self):
        self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Input_CenterPoint
        self.tempGeom_Circle.SetAxis(self.curCoordinateSystem.Axis())
        self.myCircleAx2d.SetDirection(
            gp_Dir2d(self.curCoordinateSystem.XDirection().X(),
                     self.curCoordinateSystem.XDirection().Y()))

    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 MouseMoveEvent(self, thePnt2d: gp_Pnt2d, buttons, modifiers):
        if self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Nothing:
            pass
        elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_CenterPoint:
            self.curPnt2d = self.myAnalyserSnap.MouseMove(thePnt2d)
        elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_RadiusPoint:
            self.curPnt2d = self.myAnalyserSnap.MouseMoveException(
                self.myFirstgp_Pnt2d, thePnt2d, TangentType.Circle_CenterPnt,
                True)
            self.radius = self.myFirstgp_Pnt2d.Distance(self.curPnt2d)
            self.tempGeom_Circle.SetRadius(self.radius)
            self.myContext.Redisplay(self.myRubberCircle, True)

            self.mySecondPoint.SetPnt(
                elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
            self.myRubberLine.SetPoints(self.myFirstPoint, self.mySecondPoint)
            self.myContext.Redisplay(self.myRubberLine, True)

    def CancelEvent(self):
        if self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Nothing:
            pass
        elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_CenterPoint:
            pass
        elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_RadiusPoint:
            self.myContext.Remove(self.myRubberCircle, True)
            self.myContext.Remove(self.myRubberLine, True)
        self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Nothing

    def GetTypeOfMethod(self):
        return Sketch_ObjectTypeOfMethod.CircleCenterRadius_Method
コード例 #16
0
##Copyright 2009-2014 Jelle Feringa ([email protected])
##
##This file is part of pythonOCC.
##
##pythonOCC is free software: you can redistribute it and/or modify
##it under the terms of the GNU Lesser General Public License as published by
##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 __future__ import print_function

from OCC.Core.gp import gp_Pnt2d, gp_Pnt, gp_Circ2d, gp_Ax2d
from OCC.Core.Geom import Geom_Circle
from OCC.Core.TColgp import TColgp_Array1OfPnt
from OCC.Display.SimpleGui import init_display
from OCC.Core.Convert import Convert_CircleToBSplineCurve, Convert_TgtThetaOver2
display, start_display, add_menu, add_function_to_menu = init_display()

circle = Geom_Circle(gp_Circ2d(gp_Ax2d(), 1.0))
display.DisplayShape(circle, update=True, color='RED')
start_display()
コード例 #17
0
ファイル: geom_proj.py プロジェクト: tnakaicode/OCCGO
    obj.display.DisplayShape(rim_v, color="BLUE")
    print(api.GaussianCurvature())
    print(api.MinCurvature(), api.MeanCurvature(), api.MaxCurvature())
    print(dir_to_vec(api.Normal()))
    du, dv = gp_Dir(), gp_Dir()
    api.TangentU(du)
    api.TangentV(dv)
    print(dir_to_vec(du))
    print(dir_to_vec(dv))
    dx, dy = gp_Dir(), gp_Dir()
    api.CurvatureDirections(dx, dy)
    print(dir_to_vec(dx))
    print(dir_to_vec(dy))
    axs_x = gp_Ax3(pnt, dx, api.Normal())
    axs_x = obj.prop_axs(axs_x, -np.abs(1 / api.MaxCurvature()), xyz="x")
    rim_x = Geom_TrimmedCurve(Geom_Circle(axs_x.Ax2(), np.abs(1 / api.MaxCurvature())),
                              -np.pi / 2 / 10, np.pi / 2 / 10)
    # obj.display.DisplayShape(rim_x)
    axs_y = gp_Ax3(pnt, dy, api.Normal())
    axs_y = obj.prop_axs(axs_y, -np.abs(1 / api.MinCurvature()), xyz="x")
    rim_y = Geom_TrimmedCurve(Geom_Circle(axs_y.Ax2(), np.abs(1 / api.MinCurvature())),
                              -np.pi / 2 / 10, np.pi / 2 / 10)
    # obj.display.DisplayShape(rim_y)

    obj.show_axs_pln(ax0, scale=100, name="axis-0")
    obj.show_axs_pln(ax1, scale=100, name="axis-1")
    obj.show_axs_pln(ax2, scale=25, name="axis-2")
    obj.display.DisplayShape(surf, color="BLUE", transparency=0.9)
    obj.show_axs_pln(scale=100)
    obj.show()
コード例 #18
0
def _circle(radius) -> Curve:
    return Curve(Geom_Circle(gp.XOY(), radius))
コード例 #19
0
class Sketch_CommandNurbCircleSquare(Sketch_Command):
    def __init__(self):
        super(Sketch_CommandNurbCircleSquare, self).__init__("NURBS Circle.")
        self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Nothing
        self.radius = 0.0
        self.tempGeom_Circle = Geom_Circle(self.curCoordinateSystem.Ax2(),
                                           SKETCH_RADIUS)
        self.myRubberCircle = AIS_Circle(self.tempGeom_Circle)
        self.myRubberCircle.SetColor(Quantity_Color(Quantity_NOC_BLUE1))
        self.myCircleAx2d = gp_Ax2d()

    def Action(self):
        self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Input_CenterPoint
        self.tempGeom_Circle.SetAxis(self.curCoordinateSystem.Axis())
        # if self.curCoordinateSystem.XDirection():
        #     self.myCircleAx2d.SetDirection(gp_Dir2d(self.curCoordinateSystem.XDirection().X(), self.curCoordinateSystem.XDirection().Y()))

    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 MouseMoveEvent(self, thePnt2d: gp_Pnt2d, buttons, modifiers):
        if self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Nothing:
            pass
        elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_CenterPoint:
            self.curPnt2d = self.myAnalyserSnap.MouseMove(thePnt2d)
        elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_RadiusPoint:
            self.curPnt2d = self.myAnalyserSnap.MouseMoveException(
                self.myFirstgp_Pnt2d, thePnt2d, TangentType.Circle_CenterPnt,
                True)
            self.radius = self.myFirstgp_Pnt2d.Distance(self.curPnt2d)
            if self.radius == 0.0:
                self.radius = 1.0
            self.tempGeom_Circle.SetRadius(self.radius)
            self.myContext.Redisplay(self.myRubberCircle, True)
            self.mySecondPoint.SetPnt(
                elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
            # self.myRubberLine.SetPoints(self.myFirstPoint, self.mySecondPoint)
            # self.myContext.Redisplay(self.myRubberLine, True)

    def CancelEvent(self):
        if self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Nothing:
            pass
        elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_CenterPoint:
            pass
        elif self.myCircleCenterRadiusAction == CircleCenterRadiusAction.Input_RadiusPoint:
            self.myContext.Remove(self.myRubberCircle, True)
        self.myCircleCenterRadiusAction = CircleCenterRadiusAction.Nothing

    def GetTypeOfMethod(self):
        return Sketch_ObjectTypeOfMethod.NurbsCircleSquare_Method

    def ToNurbs_Square(self, center: gp_Pnt2d, radius: float):
        nurbsCircle = Sketch_Bspline(self.myContext, self.curCoordinateSystem)
        # calculate the 9 vertices of square that can enclose circle
        # top
        nurbsCircle.AddPoles(gp_Pnt2d(center.X(), center.Y() + radius))
        # right top
        nurbsCircle.AddPoles(gp_Pnt2d(center.X() + radius,
                                      center.Y() + radius))
        # right
        nurbsCircle.AddPoles(gp_Pnt2d(center.X() + radius, center.Y()))
        # right bottom
        nurbsCircle.AddPoles(gp_Pnt2d(center.X() + radius,
                                      center.Y() - radius))
        # bottom
        nurbsCircle.AddPoles(gp_Pnt2d(center.X(), center.Y() - radius))
        # left bottom
        nurbsCircle.AddPoles(gp_Pnt2d(center.X() - radius,
                                      center.Y() - radius))
        # left
        nurbsCircle.AddPoles(gp_Pnt2d(center.X() - radius, center.Y()))
        # left top
        nurbsCircle.AddPoles(gp_Pnt2d(center.X() - radius,
                                      center.Y() + radius))
        # top
        nurbsCircle.AddPoles(gp_Pnt2d(center.X(), center.Y() + radius))
        weights = [
            1, 2**0.5 / 2, 1, 2**0.5 / 2, 1, 2**0.5 / 2, 1, 2**0.5 / 2, 1
        ]
        knots = [0, 1, 2, 3, 4]
        multiplicity = [3, 2, 2, 2, 3]
        nurbsCircle.SetWeights(weights)
        nurbsCircle.SetKnots(knots)
        nurbsCircle.SetMultiplicities(multiplicity)
        nurbsCircle.SetDegree(2)
        nurbsCircle.Compute()
        return nurbsCircle
コード例 #20
0
class Sketch_CommandArc3P(Sketch_Command):
    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 Action(self):
        self.myArc3PAction = Arc3PAction.Input_1ArcPoint
        self.temp_Circ.SetPosition(self.curCoordinateSystem.Ax2())

    def MouseInputEvent(self, thePnt2d: gp_Pnt2d, buttons, modifier):
        self.curPnt2d = self.myAnalyserSnap.MouseInput(thePnt2d)
        if self.myArc3PAction == Arc3PAction.Nothing:
            pass
        elif self.myArc3PAction == Arc3PAction.Input_1ArcPoint:
            self.myFirstgp_Pnt2d = gp_Pnt2d(self.curPnt2d.X(),self.curPnt2d.Y())
            self.myFirstPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
            if not self.myPolylineMode:
                self.myRubberLine.SetPoints(self.myFirstPoint, self.myFirstPoint)
                self.myContext.Display(self.myRubberLine, True)
                self.myArc3PAction = Arc3PAction.Input_2ArcPoint
            else:
                self.findlastSObject()
                self.myContext.Display(self.myRubberCircle, True)
        elif self.myArc3PAction == Arc3PAction.Input_2ArcPoint:
            self.mySecondgp_Pnt2d =  gp_Pnt2d(self.curPnt2d.X(),self.curPnt2d.Y())
            self.mySecondPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
            self.temp_Circ.SetLocation(self.myFirstPoint.Pnt().Scaled(self.mySecondPoint.Pnt(), 0.5))
            self.temp_Circ.SetRadius(self.myFirstgp_Pnt2d.Distance(self.curPnt2d) / 2)

            self.tempGeom_Circle.SetCirc(self.temp_Circ)
            self.myRubberCircle.SetCircle(self.tempGeom_Circle)

            self.u1 = elclib.Parameter(self.temp_Circ, self.myFirstPoint.Pnt())
            self.u2 = elclib.Parameter(self.temp_Circ, self.mySecondPoint.Pnt())

            if self.u1 > self.u2:
                self.myRubberCircle.SetFirstParam(self.u2)
                self.myRubberCircle.SetLastParam(self.u1)
            else:
                self.myRubberCircle.SetFirstParam(self.u1)
                self.myRubberCircle.SetLastParam(self.u2)

            self.myContext.Remove(self.myRubberLine, True)
            self.myContext.Display(self.myRubberCircle, True)
            self.myContext.Redisplay(self.myRubberCircle, True)
            self.myArc3PAction = Arc3PAction.Input_3ArcPoint

        elif self.myArc3PAction == Arc3PAction.Input_3ArcPoint:
            Geom2d_Point1 = Geom2d_CartesianPoint(self.myFirstgp_Pnt2d)
            Geom2d_Point2 = Geom2d_CartesianPoint(self.mySecondgp_Pnt2d)
            Geom2d_Point3 = Geom2d_CartesianPoint(self.curPnt2d)
            tempGcc_Circ2d3Tan = Geom2dGcc_Circ2d3Tan(Geom2d_Point1, Geom2d_Point2, Geom2d_Point3, 1.0e-10)
            if tempGcc_Circ2d3Tan.IsDone() and tempGcc_Circ2d3Tan.NbSolutions() > 0:
                myGeom2d_Arc = Geom2d_Arc(tempGcc_Circ2d3Tan.ThisSolution(1))
                myGeom2d_Arc.SetParam(self.myFirstgp_Pnt2d, self.mySecondgp_Pnt2d, self.curPnt2d)

                Geom_Circle1 = Geom_Circle(elclib.To3d(self.curCoordinateSystem.Ax2(), myGeom2d_Arc.Circ2d()))
                myAIS_Circle = AIS_Circle(Geom_Circle1)

                myAIS_Circle.SetFirstParam(myGeom2d_Arc.FirstParameter())
                myAIS_Circle.SetLastParam(myGeom2d_Arc.LastParameter())

                self.AddObject(myGeom2d_Arc, myAIS_Circle, Sketch_GeometryType.ArcSketchObject)
                self.myContext.Remove(self.myRubberCircle, True)
                self.myContext.Display(myAIS_Circle, True)

                self.myArc3PAction = Arc3PAction.Input_1ArcPoint
            # self.third_Pnt = elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d)
            # tempMakeCirc = gce_MakeCirc(self.myFirstPoint.Pnt(), self.mySecondPoint.Pnt(), self.third_Pnt)
            # if tempMakeCirc.Status() == gce_Done:
            #
            #     Geom_Circle1 = Geom_Circle(tempMakeCirc.Value())
            #     myAIS_Circle = AIS_Circle(Geom_Circle1)
            #
            #     myAIS_Circle.SetFirstParam(
            #         elclib.Parameter(Geom_Circle1.Circ(), self.myFirstPoint.Pnt()))
            #     myAIS_Circle.SetLastParam(elclib.Parameter(Geom_Circle1.Circ(), self.third_Pnt))
            #
            #     self.AddObject(Geom_Circle, myAIS_Circle, Sketch_ObjectTypeOfMethod.Arc3P_Method)
            #     self.myContext.Remove(self.myRubberCircle, True)
            #     self.myContext.Display(myAIS_Circle, True)
            #     self.myArc3PAction = Arc3PAction.Input_1ArcPoint

        elif self.myArc3PAction == Arc3PAction.Input_PolylineArc:
            self.TempGeom2d_Point.SetPnt2d(self.curPnt2d)
            temp2d_QualifiedCurve = Geom2dGcc_QualifiedCurve(self.temp2dAdaptor_Curve, gccent_Unqualified)
            tempGcc_Circ2d3Tan = Geom2dGcc_Circ2d3Tan(temp2d_QualifiedCurve, self.FirstGeom2d_Point,
                                                      self.TempGeom2d_Point, 1.0e-6, 0)
            if (tempGcc_Circ2d3Tan.IsDone() and tempGcc_Circ2d3Tan.NbSolutions() > 0):
                self.temp2d_Circ = tempGcc_Circ2d3Tan.ThisSolution(1)
                self.u1 = elclib.Parameter(self.temp2d_Circ, self.myFirstgp_Pnt2d)
                self.u2 = elclib.Parameter(self.temp2d_Circ, self.curPnt2d)

                self.temp_u1 = self.u1 + (self.u2 - self.u1) / 100
                self.temp_u2 = self.u1 - (self.u2 - self.u1) / 100

                self.tempu1_pnt2d = elclib.Value(self.temp_u1, self.temp2d_Circ)
                self.tempu2_pnt2d = elclib.Value(self.temp_u2, self.temp2d_Circ)

                self.dist1 = self.tempu1_pnt2d.Distance(self.midpoint2d)
                self.dist2 = self.tempu2_pnt2d.Distance(self.midpoint2d)

                if self.dist1 < self.dist2:
                    self.tempu1_pnt2d = self.tempu2_pnt2d
                myGeom2d_Arc = Geom2d_Arc(self.temp2d_Circ)
                myGeom2d_Arc.SetParam(self.myFirstgp_Pnt2d, self.tempu1_pnt2d, self.curPnt2d)

                Geom_Circle1 = Geom_Circle(elclib.To3d(self.curCoordinateSystem.Ax2(), myGeom2d_Arc.Circ2d()))
                myAIS_Circle = AIS_Circle(Geom_Circle1)
                myAIS_Circle.SetFirstParam(myGeom2d_Arc.FirstParameter())
                myAIS_Circle.SetLastParam(myGeom2d_Arc.LastParameter())
                self.myContext.Display(myAIS_Circle, True)

                self.AddObject(myGeom2d_Arc, myAIS_Circle, Sketch_GeometryType.ArcSketchObject)

                self.midpoint2d = myGeom2d_Arc.MiddlePnt()
                self.tempGeom2d_Circle.SetCirc2d(myGeom2d_Arc.Circ2d())
                self.temp2dAdaptor_Curve.Load(self.tempGeom2d_Circle)

                self.myFirstgp_Pnt2d = self.curPnt2d
                self.FirstGeom2d_Point.SetPnt2d(self.myFirstgp_Pnt2d)
                self.myFirstPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))

                self.tempGeom_Circle.SetRadius(0)
                self.myRubberCircle.SetCircle(self.tempGeom_Circle)
                self.myContext.Redisplay(self.myRubberCircle, True)
        return False

    def MouseMoveEvent(self, thePnt2d: gp_Pnt2d, buttons, modifiers):
        self.curPnt2d = self.myAnalyserSnap.MouseMove(thePnt2d)
        if self.myArc3PAction == Arc3PAction.Nothing:
            pass
        elif self.myArc3PAction == Arc3PAction.Input_1ArcPoint:
            self.curPnt2d = self.myAnalyserSnap.MouseMove(thePnt2d)
        elif self.myArc3PAction == Arc3PAction.Input_2ArcPoint:
            self.mySecondPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
            self.myRubberLine.SetPoints(self.myFirstPoint, self.mySecondPoint)
            self.myContext.Redisplay(self.myRubberLine, True)
        elif self.myArc3PAction == Arc3PAction.Input_3ArcPoint:
            self.third_Pnt = elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d)
            tempMakeCirc = gce_MakeCirc(self.myFirstPoint.Pnt(), self.mySecondPoint.Pnt(), self.third_Pnt)
            if tempMakeCirc.Status() == gce_Done:
                self.tempGeom_Circle.SetCirc(tempMakeCirc.Value())
                self.myRubberCircle.SetCircle(self.tempGeom_Circle)
                self.myRubberCircle.SetFirstParam(
                    elclib.Parameter(self.tempGeom_Circle.Circ(), self.myFirstPoint.Pnt()))
                self.myRubberCircle.SetLastParam(elclib.Parameter(self.tempGeom_Circle.Circ(), self.third_Pnt))
                self.myContext.Redisplay(self.myRubberCircle, True)
        elif self.myArc3PAction == Arc3PAction.Input_PolylineArc:
            self.third_Pnt = elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d)
            self.TempGeom2d_Point.SetPnt2d(self.curPnt2d)
            temp2d_QualifiedCurve = Geom2dGcc_QualifiedCurve(self.temp2dAdaptor_Curve, gccent_Unqualified)
            tempGcc_Circ2d3Tan = Geom2dGcc_Circ2d3Tan(temp2d_QualifiedCurve, self.FirstGeom2d_Point,
                                                      self.TempGeom2d_Point, 1.0e-6, 0)
            if (tempGcc_Circ2d3Tan.IsDone() and tempGcc_Circ2d3Tan.NbSolutions() > 0):
                self.temp2d_Circ = tempGcc_Circ2d3Tan.ThisSolution(1)
                self.u1 = elclib.Parameter(self.temp2d_Circ, self.myFirstgp_Pnt2d)
                self.u2 = elclib.Parameter(self.temp2d_Circ, self.mySecondgp_Pnt2d)

                self.temp_u1 = self.u1 + (self.u2 - self.u1) / 100
                self.temp_u2 = self.u1 - (self.u2 - self.u1) / 100

                self.tempu1_pnt2d = elclib.Value(self.temp_u1, self.temp2d_Circ)
                self.tempu2_pnt2d = elclib.Value(self.temp_u2, self.temp2d_Circ)

                self.dist1 = self.tempu1_pnt2d.Distance(self.midpoint2d)
                self.dist2 = self.tempu2_pnt2d.Distance(self.midpoint2d)

                if self.dist1 < self.dist2:
                    self.tempu1_pnt2d = self.tempu2_pnt2d
                tempMakeCirc = gce_MakeCirc(self.myFirstPoint.Pnt(),
                                            elclib.To3d(self.curCoordinateSystem.Ax2(), self.tempu1_pnt2d),
                                            self.third_Pnt)
                if tempMakeCirc.Status() == gce_Done:
                    self.tempGeom_Circle.SetCirc(tempMakeCirc.Value())
                    self.myRubberCircle.SetFirstParam(
                        elclib.Parameter(self.tempGeom_Circle.Circ(), self.myFirstPoint.Pnt()))
                    self.myRubberCircle.SetLastParam(elclib.Parameter(self.tempGeom_Circle.Circ(), self.third_Pnt))
                    self.myContext.Redisplay(self.myRubberCircle, True)

    def CancelEvent(self):
        if self.myArc3PAction == Arc3PAction.Nothing:
            pass
        elif self.myArc3PAction == Arc3PAction.Input_1ArcPoint:
            pass
        elif self.myArc3PAction == Arc3PAction.Input_2ArcPoint:
            self.myContext.Remove(self.myRubberLine, True)
        elif self.myArc3PAction == Arc3PAction.Input_3ArcPoint:
            self.myContext.Remove(self.myRubberCircle, True)
        elif self.myArc3PAction == Arc3PAction.Input_PolylineArc:
            self.myContext.Remove(self.myRubberCircle, True)
        self.myArc3PAction = Arc3PAction.Nothing

    def findlastSObject(self):
        self.midpoint2d = gp.Origin2d()
        if len(self.data) > 0:
            lastSObject: Sketch_Object = self.data[-1]
            if lastSObject.GetGeometryType() == Sketch_GeometryType.LineSketchObject:
                last2d_Edge: Geom2d_Edge = lastSObject.GetGeometry()
                if last2d_Edge.GetStart_Pnt().IsEqual(self.myFirstgp_Pnt2d, 1.0e-6) or last2d_Edge.GetEnd_Pnt().IsEqual(
                        self.myFirstgp_Pnt2d, 1.0e-6):
                    self.midpoint2d = last2d_Edge.MiddlePnt()
                    self.tempGeom2d_Line.SetLin2d(last2d_Edge.Lin2d())
                    self.temp2dAdaptor_Curve.Load(self.tempGeom2d_Line)
                else:
                    self.setTempLine()
            elif lastSObject.GetGeometryType() == Sketch_GeometryType.ArcSketchObject:
                last2d_Arc: Geom2d_Arc = lastSObject.GetGeometry()
                if last2d_Arc.FirstPnt().IsEqual(self.myFirstgp_Pnt2d, 1.0e-6) or last2d_Arc.LastPnt().IsEqual(
                        self.myFirstgp_Pnt2d, 1.0e-6):
                    self.midpoint2d = last2d_Arc.MiddlePnt()
                    self.tempGeom2d_Circle.SetCirc2d(last2d_Arc.Circ2d())
                    self.temp2dAdaptor_Curve.Load(self.tempGeom2d_Circle)
                else:
                    self.setTempLine()
            else:
                self.setTempLine()
        else:
            self.setTempLine()
        self.FirstGeom2d_Point.SetPnt2d(self.myFirstgp_Pnt2d)
        self.tempGeom_Circle.SetRadius(0.0)
        self.myRubberCircle.SetCircle(self.tempGeom_Circle)
        self.myArc3PAction = Arc3PAction.Input_PolylineArc

    def SetPolylineFirstPnt(self, p1):
        self.myFirstgp_Pnt2d = p1
        self.myFirstPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), p1))
        self.findlastSObject()
        self.myContext.Display(self.myRubberCircle, True)

    def GetPolylineFirstPnt(self, p1):
        if self.myArc3PAction == Arc3PAction.Input_PolylineArc and self.myPolylineMode == True:
            p1 = self.myFirstgp_Pnt2d
            return True
        else:
            return False

    def SetPolylineMode(self, mode):
        self.myPolylineMode = mode
        if self.myArc3PAction == Arc3PAction.Nothing:
            pass
        elif self.myArc3PAction == Arc3PAction.Input_1ArcPoint:
            pass
        elif self.myArc3PAction == Arc3PAction.Input_2ArcPoint:
            self.findlastSObject()
            self.myContext.Remove(self.myRubberLine, True)
            self.myContext.Display(self.myRubberCircle, True)
        elif self.myArc3PAction == Arc3PAction.Input_3ArcPoint:
            self.findlastSObject()
            self.myContext.Redisplay(self.myRubberCircle, True)
        elif self.myArc3PAction == Arc3PAction.Input_PolylineArc:
            self.mySecondPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
            self.myContext.Remove(self.myRubberCircle, True)
            self.myContext.Display(self.myRubberLine, True)
            self.myArc3PAction = Arc3PAction.Input_2ArcPoint

    def setTempLine(self):
        self.tempGeom2d_Line.SetLocation(self.myFirstgp_Pnt2d)
        self.tempGeom2d_Line.SetDirection(gp.DX2d())
        self.temp2dAdaptor_Curve.Load(self.tempGeom2d_Line)

    def GetTypeOfMethod(self):
        return Sketch_ObjectTypeOfMethod.Arc3P_Method
コード例 #21
0
    def MouseInputEvent(self, thePnt2d: gp_Pnt2d, buttons, modifier):
        self.curPnt2d = self.myAnalyserSnap.MouseInput(thePnt2d)
        if self.myArc3PAction == Arc3PAction.Nothing:
            pass
        elif self.myArc3PAction == Arc3PAction.Input_1ArcPoint:
            self.myFirstgp_Pnt2d = gp_Pnt2d(self.curPnt2d.X(),self.curPnt2d.Y())
            self.myFirstPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
            if not self.myPolylineMode:
                self.myRubberLine.SetPoints(self.myFirstPoint, self.myFirstPoint)
                self.myContext.Display(self.myRubberLine, True)
                self.myArc3PAction = Arc3PAction.Input_2ArcPoint
            else:
                self.findlastSObject()
                self.myContext.Display(self.myRubberCircle, True)
        elif self.myArc3PAction == Arc3PAction.Input_2ArcPoint:
            self.mySecondgp_Pnt2d =  gp_Pnt2d(self.curPnt2d.X(),self.curPnt2d.Y())
            self.mySecondPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
            self.temp_Circ.SetLocation(self.myFirstPoint.Pnt().Scaled(self.mySecondPoint.Pnt(), 0.5))
            self.temp_Circ.SetRadius(self.myFirstgp_Pnt2d.Distance(self.curPnt2d) / 2)

            self.tempGeom_Circle.SetCirc(self.temp_Circ)
            self.myRubberCircle.SetCircle(self.tempGeom_Circle)

            self.u1 = elclib.Parameter(self.temp_Circ, self.myFirstPoint.Pnt())
            self.u2 = elclib.Parameter(self.temp_Circ, self.mySecondPoint.Pnt())

            if self.u1 > self.u2:
                self.myRubberCircle.SetFirstParam(self.u2)
                self.myRubberCircle.SetLastParam(self.u1)
            else:
                self.myRubberCircle.SetFirstParam(self.u1)
                self.myRubberCircle.SetLastParam(self.u2)

            self.myContext.Remove(self.myRubberLine, True)
            self.myContext.Display(self.myRubberCircle, True)
            self.myContext.Redisplay(self.myRubberCircle, True)
            self.myArc3PAction = Arc3PAction.Input_3ArcPoint

        elif self.myArc3PAction == Arc3PAction.Input_3ArcPoint:
            Geom2d_Point1 = Geom2d_CartesianPoint(self.myFirstgp_Pnt2d)
            Geom2d_Point2 = Geom2d_CartesianPoint(self.mySecondgp_Pnt2d)
            Geom2d_Point3 = Geom2d_CartesianPoint(self.curPnt2d)
            tempGcc_Circ2d3Tan = Geom2dGcc_Circ2d3Tan(Geom2d_Point1, Geom2d_Point2, Geom2d_Point3, 1.0e-10)
            if tempGcc_Circ2d3Tan.IsDone() and tempGcc_Circ2d3Tan.NbSolutions() > 0:
                myGeom2d_Arc = Geom2d_Arc(tempGcc_Circ2d3Tan.ThisSolution(1))
                myGeom2d_Arc.SetParam(self.myFirstgp_Pnt2d, self.mySecondgp_Pnt2d, self.curPnt2d)

                Geom_Circle1 = Geom_Circle(elclib.To3d(self.curCoordinateSystem.Ax2(), myGeom2d_Arc.Circ2d()))
                myAIS_Circle = AIS_Circle(Geom_Circle1)

                myAIS_Circle.SetFirstParam(myGeom2d_Arc.FirstParameter())
                myAIS_Circle.SetLastParam(myGeom2d_Arc.LastParameter())

                self.AddObject(myGeom2d_Arc, myAIS_Circle, Sketch_GeometryType.ArcSketchObject)
                self.myContext.Remove(self.myRubberCircle, True)
                self.myContext.Display(myAIS_Circle, True)

                self.myArc3PAction = Arc3PAction.Input_1ArcPoint
            # self.third_Pnt = elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d)
            # tempMakeCirc = gce_MakeCirc(self.myFirstPoint.Pnt(), self.mySecondPoint.Pnt(), self.third_Pnt)
            # if tempMakeCirc.Status() == gce_Done:
            #
            #     Geom_Circle1 = Geom_Circle(tempMakeCirc.Value())
            #     myAIS_Circle = AIS_Circle(Geom_Circle1)
            #
            #     myAIS_Circle.SetFirstParam(
            #         elclib.Parameter(Geom_Circle1.Circ(), self.myFirstPoint.Pnt()))
            #     myAIS_Circle.SetLastParam(elclib.Parameter(Geom_Circle1.Circ(), self.third_Pnt))
            #
            #     self.AddObject(Geom_Circle, myAIS_Circle, Sketch_ObjectTypeOfMethod.Arc3P_Method)
            #     self.myContext.Remove(self.myRubberCircle, True)
            #     self.myContext.Display(myAIS_Circle, True)
            #     self.myArc3PAction = Arc3PAction.Input_1ArcPoint

        elif self.myArc3PAction == Arc3PAction.Input_PolylineArc:
            self.TempGeom2d_Point.SetPnt2d(self.curPnt2d)
            temp2d_QualifiedCurve = Geom2dGcc_QualifiedCurve(self.temp2dAdaptor_Curve, gccent_Unqualified)
            tempGcc_Circ2d3Tan = Geom2dGcc_Circ2d3Tan(temp2d_QualifiedCurve, self.FirstGeom2d_Point,
                                                      self.TempGeom2d_Point, 1.0e-6, 0)
            if (tempGcc_Circ2d3Tan.IsDone() and tempGcc_Circ2d3Tan.NbSolutions() > 0):
                self.temp2d_Circ = tempGcc_Circ2d3Tan.ThisSolution(1)
                self.u1 = elclib.Parameter(self.temp2d_Circ, self.myFirstgp_Pnt2d)
                self.u2 = elclib.Parameter(self.temp2d_Circ, self.curPnt2d)

                self.temp_u1 = self.u1 + (self.u2 - self.u1) / 100
                self.temp_u2 = self.u1 - (self.u2 - self.u1) / 100

                self.tempu1_pnt2d = elclib.Value(self.temp_u1, self.temp2d_Circ)
                self.tempu2_pnt2d = elclib.Value(self.temp_u2, self.temp2d_Circ)

                self.dist1 = self.tempu1_pnt2d.Distance(self.midpoint2d)
                self.dist2 = self.tempu2_pnt2d.Distance(self.midpoint2d)

                if self.dist1 < self.dist2:
                    self.tempu1_pnt2d = self.tempu2_pnt2d
                myGeom2d_Arc = Geom2d_Arc(self.temp2d_Circ)
                myGeom2d_Arc.SetParam(self.myFirstgp_Pnt2d, self.tempu1_pnt2d, self.curPnt2d)

                Geom_Circle1 = Geom_Circle(elclib.To3d(self.curCoordinateSystem.Ax2(), myGeom2d_Arc.Circ2d()))
                myAIS_Circle = AIS_Circle(Geom_Circle1)
                myAIS_Circle.SetFirstParam(myGeom2d_Arc.FirstParameter())
                myAIS_Circle.SetLastParam(myGeom2d_Arc.LastParameter())
                self.myContext.Display(myAIS_Circle, True)

                self.AddObject(myGeom2d_Arc, myAIS_Circle, Sketch_GeometryType.ArcSketchObject)

                self.midpoint2d = myGeom2d_Arc.MiddlePnt()
                self.tempGeom2d_Circle.SetCirc2d(myGeom2d_Arc.Circ2d())
                self.temp2dAdaptor_Curve.Load(self.tempGeom2d_Circle)

                self.myFirstgp_Pnt2d = self.curPnt2d
                self.FirstGeom2d_Point.SetPnt2d(self.myFirstgp_Pnt2d)
                self.myFirstPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))

                self.tempGeom_Circle.SetRadius(0)
                self.myRubberCircle.SetCircle(self.tempGeom_Circle)
                self.myContext.Redisplay(self.myRubberCircle, True)
        return False