From 3afbbfa3daa809ef17faa94b8a4ae03e220c6f8c Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Sat, 7 Oct 2017 16:09:00 -0700 Subject: [PATCH] Dwngraded isHorizontal/isVertical error messages for unsuppported types to warnings and cache loop detection result to get a single message - rather than one per second. --- src/Mod/Path/PathCommands.py | 40 +++++++++++++++++++--------- src/Mod/Path/PathScripts/PathGeom.py | 8 +++--- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/Mod/Path/PathCommands.py b/src/Mod/Path/PathCommands.py index a21671c2c6..3f593776e0 100644 --- a/src/Mod/Path/PathCommands.py +++ b/src/Mod/Path/PathCommands.py @@ -24,6 +24,9 @@ import FreeCAD import PathScripts +import PathScripts.PathLog as PathLog +import traceback + from PathScripts.PathUtils import loopdetect from PathScripts.PathUtils import horizontalEdgeLoop from PathScripts.PathUtils import horizontalFaceLoop @@ -45,6 +48,11 @@ __url__ = "http://www.freecadweb.org" class _CommandSelectLoop: "the Path command to complete loop selection definition" + def __init__(self): + self.obj = None + self.sub = [] + self.active = False + def GetResources(self): return {'Pixmap': 'Path-SelectLoop', 'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_SelectLoop", "Finish Selecting Loop"), @@ -56,18 +64,15 @@ class _CommandSelectLoop: return False try: sel = FreeCADGui.Selection.getSelectionEx()[0] - sub1 = sel.SubElementNames[0] - if sub1[0:4] != 'Edge': - if sub1[0:4] == 'Face' and horizontalFaceLoop(sel.Object, sel.SubObjects[0], sel.SubElementNames): - return True - return False - if len(sel.SubElementNames) == 1 and horizontalEdgeLoop(sel.Object, sel.SubObjects[0]): - return True - sub2 = sel.SubElementNames[1] - if sub2[0:4] != 'Edge': - return False - return True - except: + if sel.Object == self.obj and sel.SubElementNames == self.sub: + return self.active + self.obj = sel.Object + self.sub = sel.SubElementNames + self.active = self.formsPartOfALoop(sel.Object, sel.SubObjects[0], sel.SubElementNames) + return self.active + except Exception as exc: + PathLog.error(exc) + traceback.print_exc(exc) return False def Activated(self): @@ -94,6 +99,17 @@ class _CommandSelectLoop: if e.hashCode() == i.hashCode(): FreeCADGui.Selection.addSelection(obj, "Edge"+str(elist.index(e)+1)) + def formsPartOfALoop(self, obj, sub, names): + if names[0][0:4] != 'Edge': + if names[0][0:4] == 'Face' and horizontalFaceLoop(obj, sub, names): + return True + return False + if len(sel.SubElementNames) == 1 and horizontalEdgeLoop(obj, sub): + return True + if names[1][0:4] != 'Edge': + return False + return True + if FreeCAD.GuiUp: FreeCADGui.addCommand('Path_SelectLoop', _CommandSelectLoop()) diff --git a/src/Mod/Path/PathScripts/PathGeom.py b/src/Mod/Path/PathScripts/PathGeom.py index a6ecd25049..c8f0cb873e 100644 --- a/src/Mod/Path/PathScripts/PathGeom.py +++ b/src/Mod/Path/PathScripts/PathGeom.py @@ -147,7 +147,7 @@ class PathGeom: return True if type(obj.Surface) == Part.SurfaceOfExtrusion: return cls.isVertical(obj.Surface.Direction) - PathLog.error(translate('PathGeom', "face isVertical(%s) not supported") % type(obj.Surface)) + PathLog.warning(translate('PathGeom', "face %s not handled, assuming not vertical") % type(obj.Surface)) return None if obj.ShapeType == 'Edge': if type(obj.Curve) == Part.Line or type(obj.Curve) == Part.LineSegment: @@ -157,7 +157,7 @@ class PathGeom: if type(obj.Curve) == Part.BezierCurve: # the current assumption is that a bezier curve is vertical if its end points are vertical return cls.isVertical(obj.Curve.EndPoint - obj.Curve.StartPoint) - PathLog.error(translate('PathGeom', "edge isVertical(%s) not supported") % type(obj.Curve)) + PathLog.warning(translate('PathGeom', "edge %s not handled, assuming not vertical") % type(obj.Curve)) return None PathLog.error(translate('PathGeom', "isVertical(%s) not supported") % obj) return None @@ -176,7 +176,7 @@ class PathGeom: return True if type(obj.Surface) == Part.SurfaceOfExtrusion: return cls.isHorizontal(obj.Surface.Direction) - PathLog.error(translate('PathGeom', "face isHorizontal(%s) not supported") % type(obj.Surface)) + PathLog.warning(translate('PathGeom', "face %s not handled, assuming not horizontal") % type(obj.Surface)) return None if obj.ShapeType == 'Edge': if type(obj.Curve) == Part.Line or type(obj.Curve) == Part.LineSegment: @@ -185,7 +185,7 @@ class PathGeom: return cls.isVertical(obj.Curve.Axis) if type(obj.Curve) == Part.BezierCurve: return cls.isRoughly(obj.BoundBox.ZLength, 0) - PathLog.error(translate('PathGeom', "edge isHorizontal(%s) not supported") % type(obj.Curve)) + PathLog.warning(translate('PathGeom', "edge %s not handled, assuming not horizontal") % type(obj.Curve)) return None PathLog.error(translate('PathGeom', "isHorizontal(%s) not supported") % obj) return None