black reformat

This commit is contained in:
sliptonic
2022-01-10 15:32:45 -06:00
parent b0ece7585a
commit 783518dd34
2 changed files with 244 additions and 101 deletions

View File

@@ -33,7 +33,8 @@ from PySide import QtCore
# lazily loaded modules
from lazy_loader.lazy_loader import LazyLoader
Part = LazyLoader('Part', globals(), 'Part')
Part = LazyLoader("Part", globals(), "Part")
__title__ = "Path Deburr Operation"
__author__ = "sliptonic (Brad Collette), Schildkroet"
@@ -50,33 +51,45 @@ def translate(context, text, disambig=None):
def toolDepthAndOffset(width, extraDepth, tool, printInfo):
'''toolDepthAndOffset(width, extraDepth, tool) ... return tuple for given\n
parameters.'''
"""toolDepthAndOffset(width, extraDepth, tool) ... return tuple for given\n
parameters."""
if not hasattr(tool, 'Diameter'):
raise ValueError('Deburr requires tool with diameter\n')
if not hasattr(tool, "Diameter"):
raise ValueError("Deburr requires tool with diameter\n")
suppressInfo = False
if hasattr(tool, 'CuttingEdgeAngle'):
if hasattr(tool, "CuttingEdgeAngle"):
angle = float(tool.CuttingEdgeAngle)
if PathGeom.isRoughly(angle, 180) or PathGeom.isRoughly(angle, 0):
angle = 180
toolOffset = float(tool.Diameter) / 2
else:
if hasattr(tool, 'TipDiameter'):
if hasattr(tool, "TipDiameter"):
toolOffset = float(tool.TipDiameter) / 2
elif hasattr(tool, 'FlatRadius'):
elif hasattr(tool, "FlatRadius"):
toolOffset = float(tool.FlatRadius)
else:
toolOffset = 0.0
if printInfo and not suppressInfo:
FreeCAD.Console.PrintMessage(translate('PathDeburr', "The selected tool has no FlatRadius and no TipDiameter property. Assuming {}\n".format("Endmill" if angle == 180 else "V-Bit")))
FreeCAD.Console.PrintMessage(
translate(
"PathDeburr",
"The selected tool has no FlatRadius and no TipDiameter property. Assuming {}\n".format(
"Endmill" if angle == 180 else "V-Bit"
),
)
)
suppressInfo = True
else:
angle = 180
toolOffset = float(tool.Diameter) / 2
if printInfo:
FreeCAD.Console.PrintMessage(translate('PathDeburr', 'The selected tool has no CuttingEdgeAngle property. Assuming Endmill\n'))
FreeCAD.Console.PrintMessage(
translate(
"PathDeburr",
"The selected tool has no CuttingEdgeAngle property. Assuming Endmill\n",
)
)
suppressInfo = True
tan = math.tan(math.radians(angle / 2))
@@ -90,40 +103,78 @@ def toolDepthAndOffset(width, extraDepth, tool, printInfo):
class ObjectDeburr(PathEngraveBase.ObjectOp):
'''Proxy class for Deburr operation.'''
"""Proxy class for Deburr operation."""
def opFeatures(self, obj):
return PathOp.FeatureTool | PathOp.FeatureHeights | PathOp.FeatureStepDown | PathOp.FeatureBaseEdges | PathOp.FeatureBaseFaces | PathOp.FeatureCoolant | PathOp.FeatureBaseGeometry
return (
PathOp.FeatureTool
| PathOp.FeatureHeights
| PathOp.FeatureStepDown
| PathOp.FeatureBaseEdges
| PathOp.FeatureBaseFaces
| PathOp.FeatureCoolant
| PathOp.FeatureBaseGeometry
)
def initOperation(self, obj):
PathLog.track(obj.Label)
obj.addProperty('App::PropertyDistance', 'Width', 'Deburr',
QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'The desired width of the chamfer'))
obj.addProperty('App::PropertyDistance', 'ExtraDepth', 'Deburr',
QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'The additional depth of the tool path'))
obj.addProperty('App::PropertyEnumeration', 'Join', 'Deburr',
QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'How to join chamfer segments'))
obj.Join = ['Round', 'Miter']
obj.setEditorMode('Join', 2) # hide for now
obj.addProperty('App::PropertyEnumeration', 'Direction', 'Deburr',
QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'Direction of Operation'))
obj.Direction = ['CW', 'CCW']
obj.addProperty('App::PropertyEnumeration', 'Side', 'Deburr',
QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'Side of Operation'))
obj.Side = ['Outside', 'Inside']
obj.setEditorMode('Side', 2) # Hide property, it's calculated by op
obj.addProperty('App::PropertyInteger', 'EntryPoint', 'Deburr',
QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'Select the segment, there the operations starts'))
obj.addProperty(
"App::PropertyDistance",
"Width",
"Deburr",
QtCore.QT_TRANSLATE_NOOP("PathDeburr", "The desired width of the chamfer"),
)
obj.addProperty(
"App::PropertyDistance",
"ExtraDepth",
"Deburr",
QtCore.QT_TRANSLATE_NOOP(
"PathDeburr", "The additional depth of the tool path"
),
)
obj.addProperty(
"App::PropertyEnumeration",
"Join",
"Deburr",
QtCore.QT_TRANSLATE_NOOP("PathDeburr", "How to join chamfer segments"),
)
obj.Join = ["Round", "Miter"]
obj.setEditorMode("Join", 2) # hide for now
obj.addProperty(
"App::PropertyEnumeration",
"Direction",
"Deburr",
QtCore.QT_TRANSLATE_NOOP("PathDeburr", "Direction of Operation"),
)
obj.Direction = ["CW", "CCW"]
obj.addProperty(
"App::PropertyEnumeration",
"Side",
"Deburr",
QtCore.QT_TRANSLATE_NOOP("PathDeburr", "Side of Operation"),
)
obj.Side = ["Outside", "Inside"]
obj.setEditorMode("Side", 2) # Hide property, it's calculated by op
obj.addProperty(
"App::PropertyInteger",
"EntryPoint",
"Deburr",
QtCore.QT_TRANSLATE_NOOP(
"PathDeburr", "Select the segment, there the operations starts"
),
)
def opOnDocumentRestored(self, obj):
obj.setEditorMode('Join', 2) # hide for now
obj.setEditorMode("Join", 2) # hide for now
def opExecute(self, obj):
PathLog.track(obj.Label)
if not hasattr(self, 'printInfo'):
if not hasattr(self, "printInfo"):
self.printInfo = True
try:
(depth, offset, extraOffset, suppressInfo) = toolDepthAndOffset(obj.Width.Value, obj.ExtraDepth.Value, self.tool, self.printInfo)
(depth, offset, extraOffset, suppressInfo) = toolDepthAndOffset(
obj.Width.Value, obj.ExtraDepth.Value, self.tool, self.printInfo
)
self.printInfo = not suppressInfo
except ValueError as e:
msg = "{} \n No path will be generated".format(e)
@@ -147,13 +198,15 @@ class ObjectDeburr(PathEngraveBase.ObjectOp):
for f in subs:
sub = base.Shape.getElement(f)
if type(sub) == Part.Edge: # Edge
if type(sub) == Part.Edge: # Edge
edges.append(sub)
elif type(sub) == Part.Face and sub.normalAt(0, 0) != FreeCAD.Vector(0, 0, 1): # Angled face
elif type(sub) == Part.Face and sub.normalAt(0, 0) != FreeCAD.Vector(
0, 0, 1
): # Angled face
# If an angled face is selected, the lower edge is projected to the height of the upper edge,
# to simulate an edge
# Find z value of upper edge
for edge in sub.Edges:
for p0 in edge.Vertexes:
@@ -161,7 +214,7 @@ class ObjectDeburr(PathEngraveBase.ObjectOp):
max_h = p0.Point.z
# Find biggest radius for top/bottom
for edge in sub.Edges:
for edge in sub.Edges:
if Part.Circle == type(edge.Curve):
if edge.Vertexes[0].Point.z == max_h:
if edge.Curve.Radius > radius_top:
@@ -169,63 +222,139 @@ class ObjectDeburr(PathEngraveBase.ObjectOp):
else:
if edge.Curve.Radius > radius_bottom:
radius_bottom = edge.Curve.Radius
# Search for lower edge and raise it to height of upper edge
for edge in sub.Edges:
if Part.Circle == type(edge.Curve): # Edge is a circle
if Part.Circle == type(edge.Curve): # Edge is a circle
if edge.Vertexes[0].Point.z < max_h:
if edge.Closed: # Circle
if edge.Closed: # Circle
# New center
center = FreeCAD.Vector(edge.Curve.Center.x, edge.Curve.Center.y, max_h)
new_edge = Part.makeCircle(edge.Curve.Radius, center, FreeCAD.Vector(0, 0, 1))
center = FreeCAD.Vector(
edge.Curve.Center.x, edge.Curve.Center.y, max_h
)
new_edge = Part.makeCircle(
edge.Curve.Radius,
center,
FreeCAD.Vector(0, 0, 1),
)
edges.append(new_edge)
# Modify offset for inner angled faces
if radius_bottom < radius_top:
offset -= 2 * extraOffset
break
else: # Arc
if edge.Vertexes[0].Point.z == edge.Vertexes[1].Point.z:
else: # Arc
if (
edge.Vertexes[0].Point.z
== edge.Vertexes[1].Point.z
):
# Arc vertexes are on same layer
l1 = math.sqrt((edge.Vertexes[0].Point.x - edge.Curve.Center.x)**2 + (edge.Vertexes[0].Point.y - edge.Curve.Center.y)**2)
l2 = math.sqrt((edge.Vertexes[1].Point.x - edge.Curve.Center.x)**2 + (edge.Vertexes[1].Point.y - edge.Curve.Center.y)**2)
l1 = math.sqrt(
(
edge.Vertexes[0].Point.x
- edge.Curve.Center.x
)
** 2
+ (
edge.Vertexes[0].Point.y
- edge.Curve.Center.y
)
** 2
)
l2 = math.sqrt(
(
edge.Vertexes[1].Point.x
- edge.Curve.Center.x
)
** 2
+ (
edge.Vertexes[1].Point.y
- edge.Curve.Center.y
)
** 2
)
# New center
center = FreeCAD.Vector(edge.Curve.Center.x, edge.Curve.Center.y, max_h)
center = FreeCAD.Vector(
edge.Curve.Center.x,
edge.Curve.Center.y,
max_h,
)
# Calculate angles based on x-axis (0 - PI/2)
start_angle = math.acos((edge.Vertexes[0].Point.x - edge.Curve.Center.x) / l1)
end_angle = math.acos((edge.Vertexes[1].Point.x - edge.Curve.Center.x) / l2)
start_angle = math.acos(
(
edge.Vertexes[0].Point.x
- edge.Curve.Center.x
)
/ l1
)
end_angle = math.acos(
(
edge.Vertexes[1].Point.x
- edge.Curve.Center.x
)
/ l2
)
# Angles are based on x-axis (Mirrored on x-axis) -> negative y value means negative angle
if edge.Vertexes[0].Point.y < edge.Curve.Center.y:
if (
edge.Vertexes[0].Point.y
< edge.Curve.Center.y
):
start_angle *= -1
if edge.Vertexes[1].Point.y < edge.Curve.Center.y:
if (
edge.Vertexes[1].Point.y
< edge.Curve.Center.y
):
end_angle *= -1
# Create new arc
new_edge = Part.ArcOfCircle(Part.Circle(center, FreeCAD.Vector(0,0,1), edge.Curve.Radius), start_angle, end_angle).toShape()
new_edge = Part.ArcOfCircle(
Part.Circle(
center,
FreeCAD.Vector(0, 0, 1),
edge.Curve.Radius,
),
start_angle,
end_angle,
).toShape()
edges.append(new_edge)
# Modify offset for inner angled faces
if radius_bottom < radius_top:
offset -= 2 * extraOffset
break
else: # Line
if edge.Vertexes[0].Point.z == edge.Vertexes[1].Point.z and edge.Vertexes[0].Point.z < max_h:
new_edge = Part.Edge(Part.LineSegment(FreeCAD.Vector(edge.Vertexes[0].Point.x, edge.Vertexes[0].Point.y, max_h), FreeCAD.Vector(edge.Vertexes[1].Point.x, edge.Vertexes[1].Point.y, max_h)))
else: # Line
if (
edge.Vertexes[0].Point.z == edge.Vertexes[1].Point.z
and edge.Vertexes[0].Point.z < max_h
):
new_edge = Part.Edge(
Part.LineSegment(
FreeCAD.Vector(
edge.Vertexes[0].Point.x,
edge.Vertexes[0].Point.y,
max_h,
),
FreeCAD.Vector(
edge.Vertexes[1].Point.x,
edge.Vertexes[1].Point.y,
max_h,
),
)
)
edges.append(new_edge)
elif sub.Wires:
basewires.extend(sub.Wires)
else: # Flat face
else: # Flat face
basewires.append(Part.Wire(sub.Edges))
self.edges = edges # pylint: disable=attribute-defined-outside-init
@@ -244,7 +373,7 @@ class ObjectDeburr(PathEngraveBase.ObjectOp):
wires.append(wire)
# Set direction of op
forward = (obj.Direction == 'CW')
forward = obj.Direction == "CW"
# Set value of side
obj.Side = side[0]
@@ -258,7 +387,7 @@ class ObjectDeburr(PathEngraveBase.ObjectOp):
while z + obj.StepDown.Value < depth:
z = z + obj.StepDown.Value
zValues.append(z)
zValues.append(depth)
PathLog.track(obj.Label, depth, zValues)
@@ -269,30 +398,30 @@ class ObjectDeburr(PathEngraveBase.ObjectOp):
self.buildpathocc(obj, wires, zValues, True, forward, obj.EntryPoint)
def opRejectAddBase(self, obj, base, sub):
'''The chamfer op can only deal with features of the base model, all others are rejected.'''
"""The chamfer op can only deal with features of the base model, all others are rejected."""
return base not in self.model
def opSetDefaultValues(self, obj, job):
PathLog.track(obj.Label, job.Label)
obj.Width = '1 mm'
obj.ExtraDepth = '0.5 mm'
obj.Join = 'Round'
obj.setExpression('StepDown', '0 mm')
obj.StepDown = '0 mm'
obj.Direction = 'CW'
obj.Width = "1 mm"
obj.ExtraDepth = "0.5 mm"
obj.Join = "Round"
obj.setExpression("StepDown", "0 mm")
obj.StepDown = "0 mm"
obj.Direction = "CW"
obj.Side = "Outside"
obj.EntryPoint = 0
def SetupProperties():
setup = []
setup.append('Width')
setup.append('ExtraDepth')
setup.append("Width")
setup.append("ExtraDepth")
return setup
def Create(name, obj=None, parentJob=None):
'''Create(name) ... Creates and returns a Deburr operation.'''
"""Create(name) ... Creates and returns a Deburr operation."""
if obj is None:
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name)
obj.Proxy = ObjectDeburr(obj, name, parentJob)

View File

@@ -43,7 +43,7 @@ def translate(context, text, disambig=None):
class TaskPanelBaseGeometryPage(PathOpGui.TaskPanelBaseGeometryPage):
'''Enhanced base geometry page to also allow special base objects.'''
"""Enhanced base geometry page to also allow special base objects."""
def super(self):
return super(TaskPanelBaseGeometryPage, self)
@@ -53,29 +53,33 @@ class TaskPanelBaseGeometryPage(PathOpGui.TaskPanelBaseGeometryPage):
class TaskPanelOpPage(PathOpGui.TaskPanelPage):
'''Page controller class for the Deburr operation.'''
"""Page controller class for the Deburr operation."""
def getForm(self):
return FreeCADGui.PySideUic.loadUi(":/panels/PageOpDeburrEdit.ui")
def initPage(self, obj):
self.opImagePath = "{}Mod/Path/Images/Ops/{}".format(FreeCAD.getHomePath(), 'chamfer.svg') # pylint: disable=attribute-defined-outside-init
self.opImage = QtGui.QPixmap(self.opImagePath) # pylint: disable=attribute-defined-outside-init
self.opImagePath = "{}Mod/Path/Images/Ops/{}".format(
FreeCAD.getHomePath(), "chamfer.svg"
) # pylint: disable=attribute-defined-outside-init
self.opImage = QtGui.QPixmap(
self.opImagePath
) # pylint: disable=attribute-defined-outside-init
self.form.opImage.setPixmap(self.opImage)
iconMiter = QtGui.QIcon(':/icons/edge-join-miter-not.svg')
iconMiter.addFile(':/icons/edge-join-miter.svg', state=QtGui.QIcon.On)
iconRound = QtGui.QIcon(':/icons/edge-join-round-not.svg')
iconRound.addFile(':/icons/edge-join-round.svg', state=QtGui.QIcon.On)
iconMiter = QtGui.QIcon(":/icons/edge-join-miter-not.svg")
iconMiter.addFile(":/icons/edge-join-miter.svg", state=QtGui.QIcon.On)
iconRound = QtGui.QIcon(":/icons/edge-join-round-not.svg")
iconRound.addFile(":/icons/edge-join-round.svg", state=QtGui.QIcon.On)
self.form.joinMiter.setIcon(iconMiter)
self.form.joinRound.setIcon(iconRound)
def getFields(self, obj):
PathGui.updateInputField(obj, 'Width', self.form.value_W)
PathGui.updateInputField(obj, 'ExtraDepth', self.form.value_h)
PathGui.updateInputField(obj, "Width", self.form.value_W)
PathGui.updateInputField(obj, "ExtraDepth", self.form.value_h)
if self.form.joinRound.isChecked():
obj.Join = 'Round'
obj.Join = "Round"
elif self.form.joinMiter.isChecked():
obj.Join = 'Miter'
obj.Join = "Miter"
if obj.Direction != str(self.form.direction.currentText()):
obj.Direction = str(self.form.direction.currentText())
@@ -84,20 +88,26 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage):
self.updateCoolant(obj, self.form.coolantController)
def setFields(self, obj):
self.form.value_W.setText(FreeCAD.Units.Quantity(obj.Width.Value, FreeCAD.Units.Length).UserString)
self.form.value_h.setText(FreeCAD.Units.Quantity(obj.ExtraDepth.Value, FreeCAD.Units.Length).UserString)
self.form.value_W.setText(
FreeCAD.Units.Quantity(obj.Width.Value, FreeCAD.Units.Length).UserString
)
self.form.value_h.setText(
FreeCAD.Units.Quantity(
obj.ExtraDepth.Value, FreeCAD.Units.Length
).UserString
)
self.setupToolController(obj, self.form.toolController)
self.setupCoolant(obj, self.form.coolantController)
self.form.joinRound.setChecked('Round' == obj.Join)
self.form.joinMiter.setChecked('Miter' == obj.Join)
self.form.joinRound.setChecked("Round" == obj.Join)
self.form.joinMiter.setChecked("Miter" == obj.Join)
self.form.joinFrame.hide()
self.selectInComboBox(obj.Direction, self.form.direction)
def updateWidth(self):
PathGui.updateInputField(self.obj, 'Width', self.form.value_W)
PathGui.updateInputField(self.obj, "Width", self.form.value_W)
def updateExtraDepth(self):
PathGui.updateInputField(self.obj, 'ExtraDepth', self.form.value_h)
PathGui.updateInputField(self.obj, "ExtraDepth", self.form.value_h)
def getSignalsForUpdate(self, obj):
signals = []
@@ -114,16 +124,20 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage):
self.form.value_h.editingFinished.connect(self.updateExtraDepth)
def taskPanelBaseGeometryPage(self, obj, features):
'''taskPanelBaseGeometryPage(obj, features) ... return page for adding base geometries.'''
"""taskPanelBaseGeometryPage(obj, features) ... return page for adding base geometries."""
return TaskPanelBaseGeometryPage(obj, features)
Command = PathOpGui.SetupOperation('Deburr',
PathDeburr.Create,
TaskPanelOpPage,
'Path_Deburr',
QtCore.QT_TRANSLATE_NOOP("PathDeburr", "Deburr"),
QtCore.QT_TRANSLATE_NOOP("PathDeburr", "Creates a Deburr Path along Edges or around Faces"),
PathDeburr.SetupProperties)
Command = PathOpGui.SetupOperation(
"Deburr",
PathDeburr.Create,
TaskPanelOpPage,
"Path_Deburr",
QtCore.QT_TRANSLATE_NOOP("PathDeburr", "Deburr"),
QtCore.QT_TRANSLATE_NOOP(
"PathDeburr", "Creates a Deburr Path along Edges or around Faces"
),
PathDeburr.SetupProperties,
)
FreeCAD.Console.PrintLog("Loading PathDeburrGui... done\n")