def process_freecad(self, sv_curve1, sv_curve2): fc_curve1 = curve_to_freecad(sv_curve1)[0] fc_curve2 = curve_to_freecad(sv_curve2)[0] points = fc_curve1.curve.intersectCC(fc_curve2.curve) points = [(p.X, p.Y, p.Z) for p in points] pts = [] for p in points: t1 = fc_curve1.curve.parameter(Base.Vector(*p)) t2 = fc_curve2.curve.parameter(Base.Vector(*p)) pts.append((t1, t2, p)) return self._filter(pts)
def curves_to_face(sv_curves, planar=True, force_nurbs=True): """ Make a Part.Face from a list of SvCurve. Curves must have NURBS representation, must form a closed loop, and it must be planar, otherwise an exception will be raised. input: * list of SvCurve. * planar: True to make a flat face; in this case, all curves must lie exactly in one plane * force_nurbs: True if you want NURBS surface as output even when curves are not NURBS output: * SvSolidFaceSurface for face's surface; SvFreeCadNurbsSurface if force_nurbs == True. """ # Check sv_curves = [curve_to_freecad(curve) for curve in sv_curves] all_nurbs = all( isinstance(curve, SvFreeCadNurbsCurve) for curve in sv_curves) edges = [Part.Edge(curve.curve) for curve in sv_curves] try: wire = Part.Wire(edges) except Part.OCCError as e: fc_curves = [edge.Curve for edge in edges] raise Exception(f"Can't build a Wire out of edges: {fc_curves}: {e}") if not wire.isClosed(): last_point = None distance = None for i, edge in enumerate(wire.Edges): p1, p2 = get_edge_endpoints(edge) if last_point is not None: distance = last_point.distanceToPoint(p1) print( f"#{i-1}-{i}: distance={distance}: ({last_point.x}, {last_point.y}, {last_point.z}) - ({p1.x}, {p1.y}, {p1.z})" ) last_point = p2 p1 = get_edge_endpoints(wire.Edges[-1])[1] p2 = get_edge_endpoints(wire.Edges[0])[0] distance = p1.distanceToPoint(p2) print(f"Last - first distance = {distance}") raise Exception(f"The wire is not closed: {sv_curves}") if planar: try: fc_face = Part.Face(wire) except Part.OCCError as e: raise Exception( f"Can't create a Face from {sv_curves}: {e}\nProbably these curves are not all lying in the same plane?" ) surface = SvSolidFaceSurface(fc_face) else: fc_face = Part.makeFilledFace(edges) surface = SvSolidFaceSurface(fc_face) if all_nurbs or force_nurbs: surface = surface.to_nurbs() return surface
def to_solid(ob): if isinstance(ob, Part.Shape): return ob elif isinstance(ob, SvCurve): return [c.curve.toShape() for c in curve_to_freecad(ob)] elif isinstance(ob, SvSurface): if is_solid_face_surface(ob): return ob.face else: return surface_to_freecad(ob, make_face=True).face else: raise TypeError(f"Unknown data type in input: {ob}")