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 selected_shape_info(self): if self.selectMode == 'Face': print(self.shape_selected) surf = BRepAdaptor_Surface(self.shape_selected, True) if surf.GetType() == GeomAbs_Plane: gp_pln = surf.Plane() normal = gp_pln.Axis().Direction() print('plane normal: (%.3f, %.3f, %.3f)' % (normal.X(), normal.Y(), normal.Z())) elif surf.GetType() == GeomAbs_Cylinder: gp_cyl = surf.Cylinder() axis = gp_cyl.Axis().Direction() location = gp_cyl.Location() print('cylinder axis direction: (%.3f, %.3f, %.3f)' % (axis.X(), axis.Y(), axis.Z())) print('cylinder axis location: (%.3f, %.3f, %.3f)' % (location.X(), location.Y(), location.Z())) else: typeList = ['Plane', 'Cylinder', 'Cone', 'Sphere', 'Torus', 'BezierSurface', 'BSplineSurface', 'SurfaceOfRevolution', 'SurfaceOfExtrusion', 'OffsetSurface', 'OtherSurface'] print('This surface type "%s" is not implemented !!' % typeList[surf.GetType()]) elif self.selectMode == 'Edge': print(self.shape_selected) edge = BRepAdaptor_Curve(self.shape_selected) curveType = edge.GetType() if curveType == GeomAbs_Line: gp_lin = edge.Line() direction = gp_lin.Direction() print('Line direction: (%.3f, %.3f, %.3f)' % (direction.X(), direction.Y(), direction.Z())) elif curveType == GeomAbs_Circle: gp_circ = edge.Circle() center = gp_circ.Location() print('Center of circle: (%.3f, %.3f, %.3f)' % (center.X(), center.Y(), center.Z())) print('Radius of circle:', gp_circ.Radius()) else: typeList = ['Line', 'Circle', 'Ellipse', 'Parabola', 'BezierCurve', 'BSplineCurve', 'OffsetCurve or OtherCurve?', 'OtherCurve'] print('This edge type is not implemented !!') print('This surface type "%s" is not implemented !!' % typeList[surf.GetType()])
def on_select(shapes): if len(shapes) < 1: return s = shapes[0] if s.ShapeType() == TopAbs_EDGE: if s.Orientation() == TopAbs_FORWARD: print('FORWARD') else: print('REVERSED') tmp = BRepAdaptor_Curve(s) # display start and endpoints of curve start_point = tmp.Value(tmp.FirstParameter()) end_point = tmp.Value(tmp.LastParameter()) if s.Orientation() == TopAbs_FORWARD: display.DisplayColoredShape( BRepBuilderAPI_MakeVertex(start_point).Vertex(), "BLUE") display.DisplayColoredShape( BRepBuilderAPI_MakeVertex(end_point).Vertex(), "RED") else: display.DisplayColoredShape( BRepBuilderAPI_MakeVertex(start_point).Vertex(), "RED") display.DisplayColoredShape( BRepBuilderAPI_MakeVertex(end_point).Vertex(), "BLUE") if tmp.GetType() == GeomAbs_Line: t = tmp.Line() gcode = f'G01 X{end_point.X():.6f} Y{end_point.Y():.6f}' print( f'line: ({start_point.X():.6f}, {start_point.Y():.6f}) → ({end_point.X():.6f}, {end_point.Y():.6f})' ) # print(gcode) print( f'line parameters: {tmp.FirstParameter():.6f}, {tmp.LastParameter():.6f}' ) elif tmp.GetType() == GeomAbs_Circle: t = tmp.Circle() center_point = t.Location() # make two line segments, both from the centerpoint, and one to each of the endpoints # the cross product of the lines determines the direction. positive = CCW, negative = CW # assume for now the arc is in the XY plane, so only check the sign of z # assume clockwise for now # center format arc v1 = gp_Vec(center_point, start_point) v2 = gp_Vec(center_point, end_point) # angle > 0 if acute, < 0 if obtuse angle = v1.AngleWithRef(v2, gp_Vec(0, 0, 1)) # use cross product to determine direction v1.Cross(v2) v1 *= angle # TODO: verify CCW = True if v1.Z() > 0 else False gcode = "G0{0} X{1:.6f} Y{2:.6f} I{3:.6f} J{4:.6f}".format( 2 if CCW else 3, end_point.X(), end_point.Y(), center_point.X() - start_point.X(), center_point.Y() - start_point.Y()) print( "circle: start (%.6f, %.6f), end (%.6f, %.6f), center (%.6f, %.6f), radius %.6f" % (start_point.X(), start_point.Y(), end_point.X(), end_point.Y(), center_point.X(), center_point.Y(), t.Radius())) print("circle parameters: %.6f, %.6f" % (tmp.FirstParameter() / math.pi, tmp.LastParameter() / math.pi)) # print(gcode) elif tmp.GetType() == GeomAbs_Ellipse: t = tmp.Ellipse() x = t.XAxis() y = t.YAxis() print("ellipse") elif tmp.GetType() == GeomAbs_Hyperbola: t = tmp.Hyperbola() print("hyperbola") elif tmp.GetType() == GeomAbs_Parabola: t = tmp.Parabola() print("parabola") elif tmp.GetType() == GeomAbs_BezierCurve: t = tmp.Bezier() print("bezier") elif tmp.GetType() == GeomAbs_BSplineCurve: t = tmp.BSpline() print("bspline") elif tmp.GetType() == GeomAbs_OffsetCurve: t = tmp.OffsetCurve() print("offset") elif tmp.GetType() == GeomAbs_OtherCurve: print("other")
def prop_edge(self, edge=TopoDS_Edge()): edge_adaptor = BRepAdaptor_Curve(edge) edge_line = edge_adaptor.Line() return edge_line