Draft: DraftFillet, changed some things about the implementation.

This commit is contained in:
vocx-fc
2019-08-21 01:08:00 -05:00
committed by Yorik van Havre
parent 12746d6148
commit 271929016a
2 changed files with 74 additions and 36 deletions

View File

@@ -2,13 +2,13 @@ import FreeCAD
from FreeCAD import Console as FCC
import Draft
import DraftGeomUtils
import Part
if FreeCAD.GuiUp:
import FreeCADGui
import DraftGui
from PySide.QtCore import QT_TRANSLATE_NOOP
from DraftTools import translate
from DraftTools import Line
import DraftTools
else:
def QT_TRANSLATE_NOOP(context, text):
return text
@@ -27,19 +27,23 @@ def makeFillet(edge_list, radius=100, chamfer=False):
radius : float, optional
It defaults to 100 mm. The curvature of the fillet.
chamfer : bool
Create the chamfer.
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: edge_list too many elements")
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":
@@ -47,18 +51,32 @@ def makeFillet(edge_list, radius=100, chamfer=False):
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)
add, delete = Draft.upgrade(edges, delete=True)
newobj = add[0]
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",
"LineFillet")
"Fillet")
Fillet(obj)
obj.Shape = newobj.Shape
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)
@@ -75,46 +93,66 @@ class Fillet(Draft._DraftObject):
obj.addProperty("App::PropertyVectorDistance", "End", "Draft", QT_TRANSLATE_NOOP("App::Property", "The end point of this line"))
obj.addProperty("App::PropertyLength", "Length", "Draft", QT_TRANSLATE_NOOP("App::Property", "The length of this line"))
obj.addProperty("App::PropertyLength", "FilletRadius", "Draft", QT_TRANSLATE_NOOP("App::Property", "Radius to use to fillet the corners"))
obj.setEditorMode("Start", 1)
obj.setEditorMode("End", 1)
obj.setEditorMode("Length", 1)
# Change to 0 to make it editable
obj.setEditorMode("FilletRadius", 1)
def execute(self, obj):
pass
if hasattr(obj, "Length"):
obj.Length = obj.Shape.Length
if hasattr(obj, "Start"):
obj.Start = obj.Shape.Vertexes[0].Point
if hasattr(obj, "End"):
obj.End = obj.Shape.Vertexes[-1].Point
def onChanged(self, obj, prop):
# Change the radius of fillet
pass
# Change the radius of fillet. NOT IMPLEMENTED.
if prop in "FilletRadius":
pass
class CommandFillet(Line):
class CommandFillet(DraftTools.Line):
def __init__(self):
Line.__init__(self, wiremode=True)
DraftTools.Line.__init__(self, wiremode=True)
def GetResources(self):
return {'Pixmap': 'Draft_Fillet.svg',
'MenuText': QT_TRANSLATE_NOOP("draft", "Fillet"),
'ToolTip': QT_TRANSLATE_NOOP("draft", "Creates a fillet between two wires or edges.")
}
}
def Activated(self):
if len(FreeCADGui.Selection.getSelection()) > 1:
edges = []
edges = FreeCADGui.Selection.getSelection()
for o in edges:
# Choose only Wires
if Draft.getType(o) != "Wire":
edges = []
break
# edges.extend(o.Shape.Edges)
FCC.PrintMessage("makeFillet: " + Draft.getType(o) + "\n")
if edges:
if len(edges) > 2:
FCC.PrintError("CommandFillet: too many elements")
doc = 'FreeCAD.ActiveDocument.'
_edges = '[' + doc + edges[0].Name + ', ' + doc + edges[1].Name + ']'
rems = [doc + 'removeObject("' + o.Name + '")' for o in FreeCADGui.Selection.getSelection()]
FreeCADGui.addModule("Draft")
func = translate("draft", "Create fillet")
arg = ['arc = DraftFillet.makeFillet(' + _edges + ')'] + rems + ['Draft.autogroup(arc)', 'FreeCAD.ActiveDocument.recompute()']
DraftGui.todo.delayCommit([(func, arg)])
wires = FreeCADGui.Selection.getSelection()
if not wires:
FCC.PrintError("CommandFillet: two elements needed" + "\n")
return
if len(wires) != 2:
FCC.PrintError("CommandFillet: two elements needed" + "\n")
return
for o in wires:
FCC.PrintMessage("CommandFillet: " + Draft.getType(o) + "\n")
# Choose only wires.
# A test could be used to chose edges in general.
if Draft.getType(o) not in "Wire":
FCC.PrintError("CommandFillet: wires needed" + "\n")
return
doc = 'FreeCAD.ActiveDocument.'
_wires = '[' + doc + wires[0].Name + ', ' + doc + wires[1].Name + ']'
rems = [doc + 'removeObject("' + o.Name + '")' for o in wires]
FreeCADGui.addModule("Draft")
func = DraftTools.translate("draft", "Create fillet")
arg = ['arc = DraftFillet.makeFillet(' + _wires + ')',
*rems,
'Draft.autogroup(arc)',
'FreeCAD.ActiveDocument.recompute()']
DraftGui.todo.delayCommit([(func, arg)])
if FreeCAD.GuiUp:

View File

@@ -51,7 +51,7 @@ from pivy import coin
#---------------------------------------------------------------------------
import DraftEdit
#import DraftFillet
# import DraftFillet
#---------------------------------------------------------------------------
# Preflight stuff