def smoothChordCommands(self, inChord, outChord, side, smooth): if smooth == 0: return [inChord.g1Command(), outChord.g1Command()] debugPrint("(%.2f, %.2f) -> (%.2f, %.2f) -> (%.2f, %.2f)" % (inChord.Start.x, inChord.Start.y, inChord.End.x, inChord.End.y, outChord.End.x, outChord.End.y)) inAngle = inChord.getAngleXY() outAngle = outChord.getAngleXY() debugPrint(" inAngle = %.2f outAngle = %.2f" % (inAngle / math.pi, outAngle / math.pi)) if inAngle == outAngle: # straight line, outChord includes inChord debugPrint(" ---> (%.2f, %.2f)" % (outChord.End.x, outChord.End.y)) return [outChord.g1Command()] debugPrint("%s :: %s" % (inChord, outChord)) inEdge = DraftGeomUtils.edg(inChord.Start, inChord.End) outEdge = DraftGeomUtils.edg(outChord.Start, outChord.End) #wire = Part.Wire([inEdge, outEdge]) #debugPrint(" => %s" % wire) #wire = wire.makeOffset2D(self.toolRadius) #debugPrint(" ==> %s" % wire) #wire = wire.makeOffset2D(-self.toolRadius) #debugPrint(" ===> %s" % wire) radius = self.toolRadius while radius > 0: lastpt = None commands = "" edges = DraftGeomUtils.fillet([inEdge, outEdge], radius) if DraftGeomUtils.isSameLine(edges[0], inEdge) or DraftGeomUtils.isSameLine( edges[1], inEdge): debugPrint("Oh, we got a problem, try smaller radius") radius = radius - 0.1 * self.toolRadius continue debugPrint("we're good") #for edge in wire.Edges[:-1]: # makeOffset2D closes the wire for edge in edges: if not lastpt: lastpt = edge.Vertexes[0].Point lastpt, cmds = PathUtils.edge_to_path(lastpt, edge, inChord.Start.z) commands += cmds path = Path.Path(commands) return path.Commands return [inChord.g1Command(), outChord.g1Command()]
def smoothChordCommands(self, inChord, outChord, side, smooth): if smooth == 0: return [ inChord.g1Command(), outChord.g1Command() ] debugPrint("(%.2f, %.2f) -> (%.2f, %.2f) -> (%.2f, %.2f)" % (inChord.Start.x, inChord.Start.y, inChord.End.x, inChord.End.y, outChord.End.x, outChord.End.y)) inAngle = inChord.getAngleXY() outAngle = outChord.getAngleXY() debugPrint(" inAngle = %.2f outAngle = %.2f" % (inAngle/math.pi, outAngle/math.pi)) if inAngle == outAngle: # straight line, outChord includes inChord debugPrint(" ---> (%.2f, %.2f)" %(outChord.End.x, outChord.End.y)) return [ outChord.g1Command() ] debugPrint("%s :: %s" % (inChord, outChord)) inEdge = DraftGeomUtils.edg(inChord.Start, inChord.End) outEdge = DraftGeomUtils.edg(outChord.Start, outChord.End) #wire = Part.Wire([inEdge, outEdge]) #debugPrint(" => %s" % wire) #wire = wire.makeOffset2D(self.toolRadius) #debugPrint(" ==> %s" % wire) #wire = wire.makeOffset2D(-self.toolRadius) #debugPrint(" ===> %s" % wire) radius = self.toolRadius while radius > 0: lastpt = None commands = "" edges = DraftGeomUtils.fillet([inEdge, outEdge], radius) if DraftGeomUtils.isSameLine(edges[0], inEdge) or DraftGeomUtils.isSameLine(edges[1], inEdge): debugPrint("Oh, we got a problem, try smaller radius") radius = radius - 0.1 * self.toolRadius continue debugPrint("we're good") #for edge in wire.Edges[:-1]: # makeOffset2D closes the wire for edge in edges: if not lastpt: lastpt = edge.Vertexes[0].Point lastpt, cmds = PathUtils.edge_to_path(lastpt, edge, inChord.Start.z) commands += cmds path = Path.Path(commands) return path.Commands return [ inChord.g1Command(), outChord.g1Command() ]
def makeFillet(objs, radius=100, chamfer=False, delete=False): """Create a fillet between two lines or edges. Parameters ---------- objs : list List of two objects of type wire, or edges. radius : float, optional It defaults to 100 mm. The curvature of the fillet. chamfer : bool, optional It defaults to `False`. If it is `True` it no longer produces a rounded fillet but a chamfer (straight edge) with the value of the `radius`. delete : bool, optional It defaults to `False`. If it is `True` it will delete the pair of objects that are used to create the fillet. Otherwise, the original objects will still be there. Returns ------- Part::Part2DObject The object of type `'Fillet'`. It returns `None` if it fails producing the object. """ if len(objs) != 2: FCC.PrintError("makeFillet: " + translate("draft", "two elements needed") + "\n") return None e1, e2 = _extract_edges(objs) edges = DraftGeomUtils.fillet([e1, e2], radius, chamfer) if len(edges) < 3: FCC.PrintError("makeFillet: " + translate("draft", "radius too large")) FCC.PrintError(", r=" + str(radius) + "\n") return None _d = translate("draft", "length: ") FCC.PrintMessage("e1, " + _d + str(edges[0].Length) + "\n") FCC.PrintMessage("e2, " + _d + str(edges[1].Length) + "\n") FCC.PrintMessage("e3, " + _d + str(edges[2].Length) + "\n") try: wire = Part.Wire(edges) except Part.OCCError: return None obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython", "Fillet") Fillet(obj) obj.Shape = wire obj.Length = wire.Length obj.Start = wire.Vertexes[0].Point obj.End = wire.Vertexes[-1].Point obj.FilletRadius = radius if delete: FreeCAD.ActiveDocument.removeObject(objs[0].Name) FreeCAD.ActiveDocument.removeObject(objs[1].Name) _r = translate("draft", "removed original objects") FCC.PrintMessage("makeFillet: " + _r + "\n") if FreeCAD.GuiUp: Draft._ViewProviderWire(obj.ViewObject) Draft.formatObject(obj) Draft.select(obj) return obj
def makeFillet(edge_list, radius=100, chamfer=False): """Create a fillet between two lines or edges. Parameters ---------- edge_list : list List of two objects of type wire, or edges. radius : float, optional It defaults to 100 mm. The curvature of the fillet. chamfer : bool Defaults to `False`. If `True` it corrects the value of the `radius` so that the chamfer is exactly the radius. Returns ------- Part::Feature The objects of type Fillet. """ if len(edge_list) != 2: FCC.PrintError("makeFillet: two elements needed" + "\n") return None e1, e2 = edge_list if "Proxy" in e1.PropertiesList: if hasattr(e1.Proxy, "Type"): if e1.Proxy.Type in "Wire": FCC.PrintMessage("e1 : " + e1.Label + "\n") e1 = e1.Shape.Edges[0] elif "Shape" in e1.PropertiesList: if e1.Shape.ShapeType in "Edge": e1 = e1.Shape if "Proxy" in e2.PropertiesList: if hasattr(e2.Proxy, "Type"): if e2.Proxy.Type in "Wire": FCC.PrintMessage("e2 : " + e2.Label + "\n") e2 = e2.Shape.Edges[0] elif "Shape" in e2.PropertiesList: if e2.Shape.ShapeType in "Edge": e2 = e2.Shape edges = DraftGeomUtils.fillet([e1, e2], radius, chamfer) FCC.PrintMessage("E1 :" + str(edges[0]) + "\n") FCC.PrintMessage("E2 :" + str(edges[1]) + "\n") FCC.PrintMessage("E3 :" + str(edges[2]) + "\n") # add, delete = Draft.upgrade(edges, delete=True) try: wire = Part.Wire(edges) except Part.OCCError: return None obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython", "Fillet") Fillet(obj) obj.Shape = wire obj.Length = wire.Length obj.Start = wire.Vertexes[0].Point obj.End = wire.Vertexes[-1].Point obj.FilletRadius = radius if FreeCAD.GuiUp: Draft._ViewProviderWire(obj.ViewObject) Draft.formatObject(obj) Draft.select(obj) return obj
def make_fillet(objs, radius=100, chamfer=False, delete=False): """Create a fillet between two lines or Part.Edges. Parameters ---------- objs: list List of two objects of type wire, or edges. radius: float, optional It defaults to 100. The curvature of the fillet. chamfer: bool, optional It defaults to `False`. If it is `True` it no longer produces a rounded fillet but a chamfer (straight edge) with the value of the `radius`. delete: bool, optional It defaults to `False`. If it is `True` it will delete the pair of objects that are used to create the fillet. Otherwise, the original objects will still be there. Returns ------- Part::Part2DObjectPython The object of Proxy type `'Fillet'`. It returns `None` if it fails producing the object. """ _name = "make_fillet" utils.print_header(_name, "Fillet") if len(objs) != 2: _err(_tr("Two elements are needed.")) return None e1, e2 = _extract_edges(objs) edges = DraftGeomUtils.fillet([e1, e2], radius, chamfer) if len(edges) < 3: _err(_tr("Radius is too large") + ", r={}".format(radius)) return None lengths = [edges[0].Length, edges[1].Length, edges[2].Length] _msg(_tr("Segment") + " 1, " + _tr("length:") + " {}".format(lengths[0])) _msg(_tr("Segment") + " 2, " + _tr("length:") + " {}".format(lengths[1])) _msg(_tr("Segment") + " 3, " + _tr("length:") + " {}".format(lengths[2])) try: wire = Part.Wire(edges) except Part.OCCError: return None _doc = App.activeDocument() obj = _doc.addObject("Part::Part2DObjectPython", "Fillet") fillet.Fillet(obj) obj.Shape = wire obj.Length = wire.Length obj.Start = wire.Vertexes[0].Point obj.End = wire.Vertexes[-1].Point obj.FilletRadius = radius if delete: _doc.removeObject(objs[0].Name) _doc.removeObject(objs[1].Name) _msg(_tr("Removed original objects.")) if App.GuiUp: view_fillet.ViewProviderFillet(obj.ViewObject) gui_utils.format_object(obj) gui_utils.select(obj) gui_utils.autogroup(obj) return obj