Fixed aligning path model along an axis.
This commit is contained in:
@@ -59,17 +59,11 @@ def translate(context, text, disambig=None):
|
||||
return QtCore.QCoreApplication.translate(context, text, disambig)
|
||||
|
||||
|
||||
LOGLEVEL = False
|
||||
|
||||
if LOGLEVEL:
|
||||
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) # lgtm [py/unreachable-statement]
|
||||
PathLog.trackModule(PathLog.thisModule()) # lgtm [py/unreachable-statement]
|
||||
else:
|
||||
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
|
||||
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
|
||||
#PathLog.trackModule(PathLog.thisModule())
|
||||
|
||||
|
||||
def _OpenCloseResourceEditor(obj, vobj, edit):
|
||||
# pylint: disable=unused-argument
|
||||
job = PathUtils.findParentJob(obj)
|
||||
if job and job.ViewObject and job.ViewObject.Proxy:
|
||||
if edit:
|
||||
@@ -171,7 +165,6 @@ class ViewProvider:
|
||||
return hasattr(self, 'deleteOnReject') and self.deleteOnReject
|
||||
|
||||
def setEdit(self, vobj=None, mode=0):
|
||||
# pylint: disable=unused-argument
|
||||
PathLog.track(mode)
|
||||
if 0 == mode:
|
||||
self.openTaskPanel()
|
||||
@@ -190,7 +183,6 @@ class ViewProvider:
|
||||
self.taskPanel = None
|
||||
|
||||
def unsetEdit(self, arg1, arg2):
|
||||
# pylint: disable=unused-argument
|
||||
if self.taskPanel:
|
||||
self.taskPanel.reject(False)
|
||||
|
||||
@@ -204,7 +196,6 @@ class ViewProvider:
|
||||
return self.openTaskPanel()
|
||||
|
||||
def uneditObject(self, obj=None):
|
||||
# pylint: disable=unused-argument
|
||||
self.unsetEdit(None, None)
|
||||
|
||||
def getIcon(self):
|
||||
@@ -250,7 +241,6 @@ class ViewProvider:
|
||||
base.ViewObject.Visibility = True
|
||||
|
||||
def forgetBaseVisibility(self, obj, base):
|
||||
# pylint: disable=unused-argument
|
||||
if self.baseVisibility.get(base.Name):
|
||||
visibility = self.baseVisibility[base.Name]
|
||||
visibility[0].ViewObject.Visibility = visibility[1]
|
||||
@@ -274,7 +264,6 @@ class ViewProvider:
|
||||
obj.Stock.ViewObject.Visibility = self.stockVisibility
|
||||
|
||||
def setupContextMenu(self, vobj, menu):
|
||||
# pylint: disable=unused-argument
|
||||
PathLog.track()
|
||||
for action in menu.actions():
|
||||
menu.removeAction(action)
|
||||
@@ -308,7 +297,7 @@ class StockEdit(object):
|
||||
widget.hide()
|
||||
if select:
|
||||
self.form.stock.setCurrentIndex(self.Index)
|
||||
editor = self.editorFrame() # pylint: disable=assignment-from-none
|
||||
editor = self.editorFrame()
|
||||
showHide(self.form.stockFromExisting, editor)
|
||||
showHide(self.form.stockFromBase, editor)
|
||||
showHide(self.form.stockCreateBox, editor)
|
||||
@@ -370,7 +359,7 @@ class StockFromBaseBoundBoxEdit(StockEdit):
|
||||
stock.ExtZneg = FreeCAD.Units.Quantity(self.form.stockExtZneg.text())
|
||||
if 'zpos' in fields:
|
||||
stock.ExtZpos = FreeCAD.Units.Quantity(self.form.stockExtZpos.text())
|
||||
except Exception: # pylint: disable=broad-except
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def getFields(self, obj, fields=None):
|
||||
@@ -467,7 +456,7 @@ class StockCreateBoxEdit(StockEdit):
|
||||
obj.Stock.Height = FreeCAD.Units.Quantity(self.form.stockBoxHeight.text())
|
||||
else:
|
||||
PathLog.error(translate('PathJob', 'Stock not a box!'))
|
||||
except Exception: # pylint: disable=broad-except
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def setFields(self, obj):
|
||||
@@ -503,7 +492,7 @@ class StockCreateCylinderEdit(StockEdit):
|
||||
obj.Stock.Height = FreeCAD.Units.Quantity(self.form.stockCylinderHeight.text())
|
||||
else:
|
||||
PathLog.error(translate('PathJob', 'Stock not a cylinder!'))
|
||||
except Exception: # pylint: disable=broad-except
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def setFields(self, obj):
|
||||
@@ -680,7 +669,7 @@ class TaskPanel:
|
||||
if self.form.wcslist.item(i).checkState() == QtCore.Qt.CheckState.Checked:
|
||||
flist.append(self.form.wcslist.item(i).text())
|
||||
self.obj.Fixtures = flist
|
||||
except Exception: # pylint: disable=broad-except
|
||||
except Exception:
|
||||
FreeCAD.Console.PrintWarning("The Job was created without fixture support. Please delete and recreate the job\r\n")
|
||||
|
||||
self.updateTooltips()
|
||||
@@ -894,7 +883,7 @@ class TaskPanel:
|
||||
elif 'Number' == prop:
|
||||
try:
|
||||
tc.ToolNumber = int(item.text())
|
||||
except Exception: # pylint: disable=broad-except
|
||||
except Exception:
|
||||
pass
|
||||
item.setText("%d" % tc.ToolNumber)
|
||||
elif 'Spindle' == prop:
|
||||
@@ -906,7 +895,7 @@ class TaskPanel:
|
||||
speed = -speed
|
||||
tc.SpindleDir = rot
|
||||
tc.SpindleSpeed = speed
|
||||
except Exception: # pylint: disable=broad-except
|
||||
except Exception:
|
||||
pass
|
||||
item.setText("%s%g" % ('+' if tc.SpindleDir == 'Forward' else '-', tc.SpindleSpeed))
|
||||
elif 'HorizFeed' == prop or 'VertFeed' == prop:
|
||||
@@ -918,58 +907,69 @@ class TaskPanel:
|
||||
elif FreeCAD.Units.Unit() == val.Unit:
|
||||
val = FreeCAD.Units.Quantity(item.text() + vUnit)
|
||||
setattr(tc, prop, val)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
except Exception:
|
||||
pass
|
||||
item.setText("%g" % getattr(tc, prop).getValueAs(vUnit))
|
||||
else:
|
||||
try:
|
||||
val = FreeCAD.Units.Quantity(item.text())
|
||||
setattr(tc, prop, val)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
except Exception:
|
||||
pass
|
||||
item.setText("%g" % getattr(tc, prop).Value)
|
||||
|
||||
self.template.updateUI()
|
||||
|
||||
def modelSetAxis(self, axis):
|
||||
def alignSel(sel, n, flip=False):
|
||||
PathLog.debug("alignSel")
|
||||
PathLog.track(axis)
|
||||
|
||||
def alignSel(sel, normal, flip=False):
|
||||
PathLog.track("Vector(%.2f, %.2f, %.2f)" % (normal.x, normal.y, normal.z), flip)
|
||||
vector = axis
|
||||
if flip:
|
||||
vector = n.negative()
|
||||
r = axis.cross(n) # rotation axis
|
||||
a = DraftVecUtils.angle(n, vector, r) * 180 / math.pi
|
||||
vector = axis.negative()
|
||||
r = axis.cross(normal) # rotation axis
|
||||
a = DraftVecUtils.angle(normal, vector, r) * 180 / math.pi
|
||||
PathLog.debug("oh boy: (%.2f, %.2f, %.2f) -> %.2f" % (r.x, r.y, r.z, a))
|
||||
Draft.rotate(sel.Object, a, axis=r)
|
||||
|
||||
selObject = None
|
||||
selFeature = None
|
||||
for sel in FreeCADGui.Selection.getSelectionEx():
|
||||
selObject = sel.Object
|
||||
for feature in sel.SubElementNames:
|
||||
selFeature = feature
|
||||
sub = sel.Object.Shape.getElement(feature)
|
||||
if 'Face' == sub.ShapeType:
|
||||
n = sub.normalAt(0, 0).negative()
|
||||
if sub.Orientation == 'Reversed':
|
||||
n = FreeCAD.Vector() - n
|
||||
PathLog.debug("(%.2f, %.2f, %.2f) -> reversed (%s)" % (n.x, n.y, n.z, sub.Orientation))
|
||||
else:
|
||||
PathLog.debug("(%.2f, %.2f, %.2f) -> forward (%s)" % (n.x, n.y, n.z, sub.Orientation))
|
||||
with selectionEx() as selection:
|
||||
for sel in selection:
|
||||
selObject = sel.Object
|
||||
for feature in sel.SubElementNames:
|
||||
selFeature = feature
|
||||
PathLog.track(selObject.Label, feature)
|
||||
sub = sel.Object.Shape.getElement(feature)
|
||||
|
||||
if PathGeom.pointsCoincide(axis, n) or PathGeom.pointsCoincide(axis, FreeCAD.Vector() - n):
|
||||
alignSel(sel, n, True)
|
||||
else:
|
||||
alignSel(sel, n)
|
||||
if 'Face' == sub.ShapeType:
|
||||
normal = sub.normalAt(0, 0)
|
||||
if sub.Orientation == 'Reversed':
|
||||
normal = FreeCAD.Vector() - normal
|
||||
PathLog.debug("(%.2f, %.2f, %.2f) -> reversed (%s)" % (normal.x, normal.y, normal.z, sub.Orientation))
|
||||
else:
|
||||
PathLog.debug("(%.2f, %.2f, %.2f) -> forward (%s)" % (normal.x, normal.y, normal.z, sub.Orientation))
|
||||
|
||||
if PathGeom.pointsCoincide(axis, normal):
|
||||
alignSel(sel, normal, True)
|
||||
elif PathGeom.pointsCoincide(axis, FreeCAD.Vector() - normal):
|
||||
alignSel(sel, FreeCAD.Vector() - normal, True)
|
||||
else:
|
||||
alignSel(sel, normal)
|
||||
|
||||
elif 'Edge' == sub.ShapeType:
|
||||
normal = (sub.Vertexes[1].Point - sub.Vertexes[0].Point).normalize()
|
||||
if PathGeom.pointsCoincide(axis, normal) or PathGeom.pointsCoincide(axis, FreeCAD.Vector() - normal):
|
||||
# Don't really know the orientation of an edge, so let's just flip the object
|
||||
# and if the user doesn't like it they can flip again
|
||||
alignSel(sel, normal, True)
|
||||
else:
|
||||
alignSel(sel, normal)
|
||||
|
||||
if 'Edge' == sub.ShapeType:
|
||||
n = (sub.Vertexes[1].Point - sub.Vertexes[0].Point).normalize()
|
||||
if PathGeom.pointsCoincide(axis, n) or PathGeom.pointsCoincide(axis, FreeCAD.Vector() - n):
|
||||
# Don't really know the orientation of an edge, so let's just flip the object
|
||||
# and if the user doesn't like it they can flip again
|
||||
alignSel(sel, n, True)
|
||||
else:
|
||||
alignSel(sel, n)
|
||||
PathLog.track(sub.ShapeType)
|
||||
|
||||
if selObject and selFeature:
|
||||
FreeCADGui.Selection.clearSelection()
|
||||
FreeCADGui.Selection.addSelection(selObject, selFeature)
|
||||
@@ -980,10 +980,13 @@ class TaskPanel:
|
||||
FreeCADGui.Selection.addSelection(sel.Object, sel.SubElementNames)
|
||||
|
||||
def modelSet0(self, axis):
|
||||
PathLog.track(axis)
|
||||
with selectionEx() as selection:
|
||||
for sel in selection:
|
||||
selObject = sel.Object
|
||||
PathLog.track(selObject.Label)
|
||||
for name in sel.SubElementNames:
|
||||
PathLog.track(selObject.Label, name)
|
||||
feature = selObject.Shape.getElement(name)
|
||||
bb = feature.BoundBox
|
||||
offset = FreeCAD.Vector(axis.x * bb.XMax, axis.y * bb.YMax, axis.z * bb.ZMax)
|
||||
@@ -1216,7 +1219,7 @@ class TaskPanel:
|
||||
|
||||
# first remove all obsolete base models
|
||||
for model, count in PathUtil.keyValueIter(obsolete):
|
||||
for i in range(count): # pylint: disable=unused-variable
|
||||
for i in range(count):
|
||||
# it seems natural to remove the last of all the base objects for a given model
|
||||
base = [b for b in obj.Model.Group if proxy.baseObject(obj, b) == model][-1]
|
||||
self.vproxy.forgetBaseVisibility(obj, base)
|
||||
@@ -1338,19 +1341,15 @@ class TaskPanel:
|
||||
|
||||
# SelectionObserver interface
|
||||
def addSelection(self, doc, obj, sub, pnt):
|
||||
# pylint: disable=unused-argument
|
||||
self.updateSelection()
|
||||
|
||||
def removeSelection(self, doc, obj, sub):
|
||||
# pylint: disable=unused-argument
|
||||
self.updateSelection()
|
||||
|
||||
def setSelection(self, doc):
|
||||
# pylint: disable=unused-argument
|
||||
self.updateSelection()
|
||||
|
||||
def clearSelection(self, doc):
|
||||
# pylint: disable=unused-argument
|
||||
self.updateSelection()
|
||||
|
||||
|
||||
@@ -1366,7 +1365,7 @@ def Create(base, template=None):
|
||||
obj.Document.recompute()
|
||||
obj.ViewObject.Proxy.editObject(obj.Stock)
|
||||
return obj
|
||||
except Exception as exc: # pylint: disable=broad-except
|
||||
except Exception as exc:
|
||||
PathLog.error(exc)
|
||||
traceback.print_exc()
|
||||
FreeCAD.ActiveDocument.abortTransaction()
|
||||
|
||||
Reference in New Issue
Block a user