Orientation along an edge.
This commit is contained in:
@@ -377,9 +377,29 @@ class TaskPanel:
|
||||
item.setText("%g" % getattr(tc, prop).Value)
|
||||
|
||||
def orientSelected(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
|
||||
r = axis.cross(n) # rotation axis
|
||||
a = DraftVecUtils.angle(n, axis, 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():
|
||||
for sub in sel.SubObjects:
|
||||
if hasattr(sub, 'Surface'):
|
||||
selObject = sel.Object
|
||||
for feature in sel.SubElementNames:
|
||||
selFeature = feature
|
||||
sub = sel.Object.Shape.getElement(feature)
|
||||
if 'Face' == sub.ShapeType:
|
||||
n = sub.Surface.Axis
|
||||
if sub.Orientation == 'Reversed':
|
||||
n = FreeCAD.Vector() - n
|
||||
@@ -390,17 +410,21 @@ class TaskPanel:
|
||||
if PathGeom.pointsCoincide(axis, n):
|
||||
PathLog.debug("face properly oriented (%.2f, %.2f, %.2f)" % (n.x, n.y, n.z))
|
||||
else:
|
||||
p = sel.Object.Placement
|
||||
loc = sel.Object.Placement.Base
|
||||
if PathGeom.pointsCoincide(axis, FreeCAD.Vector() - n):
|
||||
PathLog.debug("flip")
|
||||
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))
|
||||
flipSel(sel)
|
||||
else:
|
||||
r = axis.cross(n) # rotation axis
|
||||
a = DraftVecUtils.angle(n, axis, 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)
|
||||
rotateSel(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)
|
||||
else:
|
||||
rotateSel(sel, n)
|
||||
if selObject and selFeature:
|
||||
FreeCADGui.Selection.clearSelection()
|
||||
FreeCADGui.Selection.addSelection(selObject, selFeature)
|
||||
|
||||
def setupUi(self):
|
||||
self.setFields()
|
||||
|
||||
Reference in New Issue
Block a user