def is_edge_line(occedge): """ This function checks if an OCCedge contains a line. Parameters ---------- occedge : OCCedge The OCCedge to be examined. Returns ------- True or False : bool True or False if the edge contains a line. """ adaptor = BRepAdaptor_Curve(occedge) #GeomAbs_Line 0 #GeomAbs_Circle 1 #GeomAbs_Ellipse 2 #GeomAbs_Hyperbola 3 #GeomAbs_Parabola 4 #GeomAbs_BezierCurve 5 #GeomAbs_BSplineCurve 6 #GeomAbs_OtherCurve 7 ctype = adaptor.GetType() if ctype == 0: return True else: return False
def is_edge_line(occedge): adaptor = BRepAdaptor_Curve(occedge) ''' GeomAbs_Line 0 GeomAbs_Circle 1 GeomAbs_Ellipse 2 GeomAbs_Hyperbola 3 GeomAbs_Parabola 4 GeomAbs_BezierCurve 5 GeomAbs_BSplineCurve 6 GeomAbs_OtherCurve 7 ''' ctype = adaptor.GetType() if ctype == 0: return True else: return False
tp = Topo(s) for face in tp.faces(): ifcopenshell.geom.utils.display_shape(face) for edge in list(Topo(face).edges()): curve_handle, first, last = BRep_Tool.CurveOnSurface( edge, section_face) plane = Geom_Plane(section_plane) e = BRepBuilderAPI_MakeEdge(curve_handle, plane.GetHandle(), first, last).Edge() # handle_adaptor = Geom2dAdaptor_Curve(curve_handle) curve_adapt = BRepAdaptor_Curve(e) if curve_adapt.GetType() == GeomAbs_Line: v = list(Topo(e).vertices()) y1, z1 = BRep_Tool.Pnt(v[0]).Y(), BRep_Tool.Pnt(v[0]).Z() y2, z2 = BRep_Tool.Pnt(v[-1]).Y(), BRep_Tool.Pnt(v[-1]).Z() plt.plot([y1, y2], [z1, z2], color="red", alpha=0.2) ifcopenshell.geom.utils.display_shape(e, clr=RED) # line = curve_adapt.Line() ## r = GCPnts_AbscissaPoint(handle_adaptor) ## length = r.Parameter() # curve_adapt = BRepAdaptor_Curve(e) # length = GCPnts_AbscissaPoint().Length(curve_adapt, curve_adapt.FirstParameter(), # curve_adapt.LastParameter(), 1e-6) # # y1, z1 = line.Location().X(), line.Location().Y()
def EdgeOnSurface(edge, section_plane, lim_coord1, lim_coord2, XYZ): section_face = BRepBuilderAPI_MakeFace(section_plane, lim_coord1[0], lim_coord1[1], lim_coord2[0], lim_coord2[1]).Face() curve_handle, first, last = BRep_Tool.CurveOnSurface(edge, section_face) plane = Geom_Plane(section_plane) edge_on_surface = BRepBuilderAPI_MakeEdge(curve_handle, plane.GetHandle(), first, last).Edge() curve_adaptor = BRepAdaptor_Curve(edge_on_surface) if curve_adaptor.GetType() == GeomAbs_Line: v = list(Topo(edge_on_surface).vertices()) v1 = BRep_Tool.Pnt(v[0]).X(), BRep_Tool.Pnt(v[0]).Y(), BRep_Tool.Pnt( v[0]).Z() v2 = BRep_Tool.Pnt(v[-1]).X(), BRep_Tool.Pnt(v[-1]).Y(), BRep_Tool.Pnt( v[-1]).Z() obj = Line3D(v1, v2) elif curve_adaptor.GetType() == GeomAbs_Circle: v = list(Topo(edge_on_surface).vertices()) v1 = BRep_Tool.Pnt(v[0]).X(), BRep_Tool.Pnt(v[0]).Y(), BRep_Tool.Pnt( v[0]).Z() v2 = BRep_Tool.Pnt(v[-1]).X(), BRep_Tool.Pnt(v[-1]).Y(), BRep_Tool.Pnt( v[-1]).Z() start = [v1[i] for i in range(len(XYZ)) if XYZ[i]] end = [v2[i] for i in range(len(XYZ)) if XYZ[i]] circle = curve_adaptor.Circle() center = [] for i in range(len(XYZ)): if XYZ[i] and i == 0: center.append(circle.Location().X()) elif XYZ[i] and i == 1: center.append(circle.Location().Y()) elif XYZ[i] and i == 2: center.append(circle.Location().Z()) else: center.append(0.5 * (v1[i] + v2[i])) radius = circle.Radius() vec_start = (start[0] - center[0], start[1] - center[1]) vec_end = (end[0] - center[0], end[1] - center[1]) t1 = angle360(vec_start) t2 = angle360(vec_end) if not XYZ[0]: axis = circle.Axis().Direction().X() elif not XYZ[1]: axis = circle.Axis().Direction().Y() elif not XYZ[2]: axis = circle.Axis().Direction().Z() if axis < 0: t1, t2 = t2, t1 obj = Arc3D(v1, v2, t1, t2, center, radius) elif curve_adaptor.GetType() == GeomAbs_BSplineCurve: bspline = curve_adaptor.BSpline().GetObject() degree = bspline.Degree() knots = [ bspline.Knot(index) for index in range(1, bspline.NbKnots() + 1) ] mults = [ bspline.Multiplicity(index) for index in range(1, bspline.NbKnots() + 1) ] poles = [(bspline.Pole(index).X(), bspline.Pole(index).Y(), bspline.Pole(index).Z()) for index in range(1, bspline.NbPoles() + 1)] periodic = bspline.IsPeriodic() obj = BSpline3D(poles, mults, knots, degree, periodic) else: print(curve_adaptor.GetType()) warnings.warn("Not recognized curve!") return obj