Skip to content

Commit

Permalink
[Path] Enable Face selection for axis selection (JobSetUp)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubstar-04 committed Oct 27, 2020
1 parent 0f87516 commit 811fa90
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions src/Mod/Path/PathScripts/PathJobGui.py
Expand Up @@ -916,18 +916,13 @@ def toolControllerChanged(self, item):
self.template.updateUI()

def modelSetAxis(self, axis):
def flipSel(sel):
PathLog.debug("flip")
p = sel.Object.Placement
loc = sel.Object.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(1 - axis.x, 1 - axis.y, 1 - axis.z), 180)
sel.Object.Placement = FreeCAD.Placement(loc, p.Rotation.multiply(rot))

def rotateSel(sel, n):
# p = sel.Object.Placement
# loc = sel.Object.Placement.Base
def alignSel(sel, n, flip=False):
PathLog.debug("alignSel")
vector = axis
if flip:
vector = n.negative()
r = axis.cross(n) # rotation axis
a = DraftVecUtils.angle(n, axis, r) * 180 / math.pi
a = DraftVecUtils.angle(n, 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)

Expand All @@ -939,28 +934,26 @@ def rotateSel(sel, n):
selFeature = feature
sub = sel.Object.Shape.getElement(feature)
if 'Face' == sub.ShapeType:
n = sub.Surface.Axis
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))

if PathGeom.pointsCoincide(axis, n):
PathLog.debug("face properly oriented (%.2f, %.2f, %.2f)" % (n.x, n.y, n.z))
if PathGeom.pointsCoincide(axis, n) or PathGeom.pointsCoincide(axis, FreeCAD.Vector() - n):
alignSel(sel, n, True)
else:
if PathGeom.pointsCoincide(axis, FreeCAD.Vector() - n):
flipSel(sel)
else:
rotateSel(sel, n)
alignSel(sel, n)

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
flipSel(sel)
alignSel(sel, n, True)
else:
rotateSel(sel, n)
alignSel(sel, n)
if selObject and selFeature:
FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(selObject, selFeature)
Expand Down Expand Up @@ -1134,33 +1127,39 @@ def isValidDatumSelection(self, sel):
# no valid selection
return False

def isValidAxisSelection(self, sel):
if sel.ShapeType in ['Vertex', 'Edge', 'Face']:
if hasattr(sel, 'Curve') and type(sel.Curve) in [Part.Circle]:
return False
if hasattr(sel, 'Surface') and sel.Surface.curvature(0,0,"Max") != 0:
return False
return True

# no valid selection
return False

def updateSelection(self):
# Remove Job object if present in Selection: source of phantom paths
if self.obj in FreeCADGui.Selection.getSelection():
FreeCADGui.Selection.removeSelection(self.obj)

sel = FreeCADGui.Selection.getSelectionEx()

self.form.setOrigin.setEnabled(False)
self.form.moveToOrigin.setEnabled(False)
self.form.modelSetXAxis.setEnabled(False)
self.form.modelSetYAxis.setEnabled(False)
self.form.modelSetZAxis.setEnabled(False)

if len(sel) == 1 and len(sel[0].SubObjects) == 1:
subObj = sel[0].SubObjects[0]
if self.isValidDatumSelection(subObj):
self.form.modelSetXAxis.setEnabled(False)
self.form.modelSetYAxis.setEnabled(False)
self.form.modelSetZAxis.setEnabled(False)
self.form.setOrigin.setEnabled(True)
self.form.moveToOrigin.setEnabled(True)
else:
if self.isValidAxisSelection(subObj):
self.form.modelSetXAxis.setEnabled(True)
self.form.modelSetYAxis.setEnabled(True)
self.form.modelSetZAxis.setEnabled(True)
self.form.setOrigin.setEnabled(False)
self.form.moveToOrigin.setEnabled(False)
else:
self.form.modelSetXAxis.setEnabled(False)
self.form.modelSetYAxis.setEnabled(False)
self.form.modelSetZAxis.setEnabled(False)
self.form.setOrigin.setEnabled(False)
self.form.moveToOrigin.setEnabled(False)

if len(sel) == 0 or self.obj.Stock in [s.Object for s in sel]:
self.form.centerInStock.setEnabled(False)
Expand Down

0 comments on commit 811fa90

Please sign in to comment.