From 9ca855476b49d156748636cd1ed68c38cf4b6be2 Mon Sep 17 00:00:00 2001 From: Russell Johnson <47639332+Russ4262@users.noreply.github.com> Date: Wed, 3 Jun 2020 18:42:19 -0500 Subject: [PATCH] Path: Clean up messaging and add `translation()` usage --- src/Mod/Path/PathScripts/PathSurface.py | 31 ++++--- .../Path/PathScripts/PathSurfaceSupport.py | 85 ++++++++++--------- 2 files changed, 65 insertions(+), 51 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathSurface.py b/src/Mod/Path/PathScripts/PathSurface.py index 315119788b..3c879430c3 100644 --- a/src/Mod/Path/PathScripts/PathSurface.py +++ b/src/Mod/Path/PathScripts/PathSurface.py @@ -38,7 +38,8 @@ from PySide import QtCore try: import ocl except ImportError: - msg = QtCore.QCoreApplication.translate("PathSurface", "This operation requires OpenCamLib to be installed.") + msg = QtCore.QCoreApplication.translate("PathSurface", + "This operation requires OpenCamLib to be installed.") FreeCAD.Console.PrintError(msg + "\n") raise ImportError # import sys @@ -575,18 +576,18 @@ class ObjectSurface(PathOp.ObjectOp): PathSurfaceSupport._prepareModelSTLs(self, JOB, obj, m, ocl) Mdl = JOB.Model.Group[m] - if FACES[m] is False: - PathLog.error('No data for model base: {}'.format(JOB.Model.Group[m].Label)) - else: + if FACES[m]: + PathLog.debug('Working on Model.Group[{}]: {}'.format(m, Mdl.Label)) if m > 0: # Raise to clearance between models CMDS.append(Path.Command('N (Transition to base: {}.)'.format(Mdl.Label))) CMDS.append(Path.Command('G0', {'Z': obj.ClearanceHeight.Value, 'F': self.vertRapid})) - PathLog.info('Working on Model.Group[{}]: {}'.format(m, Mdl.Label)) # make stock-model-voidShapes STL model for avoidance detection on transitions PathSurfaceSupport._makeSafeSTL(self, JOB, obj, m, FACES[m], VOIDS[m], ocl) # Process model/faces - OCL objects must be ready CMDS.extend(self._processCutAreas(JOB, obj, m, FACES[m], VOIDS[m])) + else: + PathLog.debug('No data for model base: {}'.format(JOB.Model.Group[m].Label)) # Save gcode produced self.commandlist.extend(CMDS) @@ -659,7 +660,8 @@ class ObjectSurface(PathOp.ObjectOp): exTime = str(tMins) + ' min. ' + str(round(tSecs, 5)) + ' sec.' else: exTime = str(round(execTime, 5)) + ' sec.' - FreeCAD.Console.PrintMessage('3D Surface operation time is {}\n'.format(exTime)) + msg = translate('PathSurface', 'operation time is') + FreeCAD.Console.PrintMessage('3D Surface ' + msg + '{}\n'.format(exTime)) if self.cancelOperation: FreeCAD.ActiveDocument.openTransaction(translate("PathSurface", "Canceled 3D Surface operation.")) @@ -751,13 +753,15 @@ class ObjectSurface(PathOp.ObjectOp): if obj.ProfileEdges != 'None': prflShp = self.profileShapes[mdlIdx][fsi] if prflShp is False: - PathLog.error('No profile shape is False.') + msg = translate('PathSurface', 'No profile geometry shape returned.') + PathLog.error(msg) return list() self.showDebugObject(prflShp, 'NewProfileShape') # get offset path geometry and perform OCL scan with that geometry pathOffsetGeom = self._offsetFacesToPointData(obj, prflShp) if pathOffsetGeom is False: - PathLog.error('No profile geometry returned.') + msg = translate('PathSurface', 'No profile path geometry returned.') + PathLog.error(msg) return list() profScan = [self._planarPerformOclScan(obj, pdc, pathOffsetGeom, True)] @@ -771,12 +775,14 @@ class ObjectSurface(PathOp.ObjectOp): self.tmpCOM = PGG.getCenterOfPattern() pathGeom = PGG.generatePathGeometry() if pathGeom is False: - PathLog.error('No path geometry returned.') + msg = translate('PathSurface', 'No clearing shape returned.') + PathLog.error(msg) return list() if obj.CutPattern == 'Offset': useGeom = self._offsetFacesToPointData(obj, pathGeom, profile=False) if useGeom is False: - PathLog.error('No profile geometry returned.') + msg = translate('PathSurface', 'No clearing path geometry returned.') + PathLog.error(msg) return list() geoScan = [self._planarPerformOclScan(obj, pdc, useGeom, True)] else: @@ -795,7 +801,8 @@ class ObjectSurface(PathOp.ObjectOp): SCANDATA.extend(profScan) if len(SCANDATA) == 0: - PathLog.error('No scan data to convert to Gcode.') + msg = translate('PathSuface', 'No scan data to convert to Gcode.') + PathLog.error(msg) return list() # Apply depth offset @@ -1165,7 +1172,6 @@ class ObjectSurface(PathOp.ObjectOp): # Manage step over transition and CircularZigZag direction if so > 0: - # PathLog.debug(' stepover index: {}'.format(so)) # Control ZigZag direction if obj.CutPattern == 'CircularZigZag': if odd is True: @@ -1187,7 +1193,6 @@ class ObjectSurface(PathOp.ObjectOp): for i in range(0, lenAdjPrts): prt = ADJPRTS[i] lenPrt = len(prt) - # PathLog.debug(' adj parts index - lenPrt: {} - {}'.format(i, lenPrt)) if prt == 'BRK' and prtsHasCmds is True: nxtStart = ADJPRTS[i + 1][0] minSTH = self._getMinSafeTravelHeight(safePDC, last, nxtStart, minDep=None) # Check safe travel height against fullSTL diff --git a/src/Mod/Path/PathScripts/PathSurfaceSupport.py b/src/Mod/Path/PathScripts/PathSurfaceSupport.py index ae891d3503..16865b2e38 100644 --- a/src/Mod/Path/PathScripts/PathSurfaceSupport.py +++ b/src/Mod/Path/PathScripts/PathSurfaceSupport.py @@ -92,7 +92,10 @@ class PathGeometryGenerator: if shape.BoundBox.ZMin != 0.0: shape.translate(FreeCAD.Vector(0.0, 0.0, 0.0 - shape.BoundBox.ZMin)) if shape.BoundBox.ZLength > 1.0e-8: - FreeCAD.Console.PrintWarning('Shape appears to not be horizontal planar. ZMax is {}.\n'.format(shape.BoundBox.ZMax)) + msg = translate('PathSurfaceSupport', + 'Shape appears to not be horizontal planar.') + msg += ' ZMax == {} mm.\n'.format(shape.BoundBox.ZMax) + FreeCAD.Console.PrintWarning(msg) else: self.shape = shape self._prepareConstants() @@ -117,8 +120,11 @@ class PathGeometryGenerator: fCnt += 1 zeroCOM = zeroCOM.add(FreeCAD.Vector(comF.x, comF.y, 0.0).multiply(areaF)) if fCnt == 0: - msg = translate(self.module, 'Cannot calculate the Center Of Mass. Using Center of Boundbox instead.') - FreeCAD.Console.PrintError(msg + '\n') + msg = translate('PathSurfaceSupport', + 'Cannot calculate the Center Of Mass.') + msg += ' ' + translate('PathSurfaceSupport', + 'Using Center of Boundbox instead.') + '\n' + FreeCAD.Console.PrintError(msg) bbC = self.shape.BoundBox.Center zeroCOM = FreeCAD.Vector(bbC.x, bbC.y, 0.0) else: @@ -155,11 +161,9 @@ class PathGeometryGenerator: '''generatePathGeometry()... Call this function to obtain the path geometry shape, generated by this class.''' if self.pattern == 'None': - # FreeCAD.Console.PrintWarning('PGG: No pattern set.\n') return False if self.shape is None: - # FreeCAD.Console.PrintWarning('PGG: No shape set.\n') return False cmd = 'self._' + self.pattern + '()' @@ -407,7 +411,6 @@ class PathGeometryGenerator: while cont: ofstArea = self._getFaceOffset(shape, ofst) if not ofstArea: - # FreeCAD.Console.PrintWarning('PGG: No offset clearing area returned.\n') cont = False True if cont else False # cont used for LGTM break @@ -425,9 +428,8 @@ class PathGeometryGenerator: '''_getFaceOffset(shape, offset) ... internal function. Original _buildPathArea() version copied from PathAreaOp.py module. This version is modified. Adjustments made based on notes by @sliptonic at this webpage: https://github.com/sliptonic/FreeCAD/wiki/PathArea-notes.''' - # PathLog.debug('_getFaceOffset()') - areaParams = {} + areaParams['Offset'] = offset areaParams['Fill'] = 1 # 1 areaParams['Coplanar'] = 0 @@ -438,7 +440,6 @@ class PathGeometryGenerator: areaParams['Project'] = True area = Path.Area() # Create instance of Area() class object - # area.setPlane(PathUtils.makeWorkplane(shape)) # Set working plane area.setPlane(PathUtils.makeWorkplane(self.wpc)) # Set working plane to normal at Z=1 area.add(shape) area.setParams(**areaParams) # set parameters @@ -474,7 +475,10 @@ class ProcessSelectedFaces: self.module = None self.radius = None self.depthParams = None - self.msgNoFaces = translate(self.module, 'Face selection is unavailable for Rotational scans. Ignoring selected faces.') + '\n' + self.msgNoFaces = translate('PathSurfaceSupport', + 'Face selection is unavailable for Rotational scans.') + '\n' + self.msgNoFaces += ' ' + translate('PathSurfaceSupport', + 'Ignoring selected faces.') + '\n' self.JOB = JOB self.obj = obj self.profileEdges = 'None' @@ -557,7 +561,6 @@ class ProcessSelectedFaces: self.modelSTLs[m] = True # Process each model base, as a whole, as needed - # PathLog.debug(' -Pre-processing all models in Job.') for m in range(0, lenGRP): if self.modelSTLs[m] and not fShapes[m]: PathLog.debug(' -Pre-processing {} as a whole.'.format(GRP[m].Label)) @@ -568,7 +571,9 @@ class ProcessSelectedFaces: pPEB = self._preProcessEntireBase(base, m) if pPEB is False: - FreeCAD.Console.PrintError(' -Failed to pre-process base as a whole.\n') + msg = translate('PathSurfaceSupport', + 'Failed to pre-process base as a whole.') + '\n' + FreeCAD.Console.PrintError(msg) else: (fcShp, prflShp) = pPEB if fcShp is not False: @@ -677,7 +682,8 @@ class ProcessSelectedFaces: PathLog.debug('Attempting to get cross-section of collective faces.') if len(outFCS) == 0: - msg = translate('PathSurfaceSupport', 'Cannot process selected faces. Check horizontal surface exposure.') + msg = translate('PathSurfaceSupport', + 'Cannot process selected faces. Check horizontal surface exposure.') FreeCAD.Console.PrintError(msg + '\n') cont = False else: @@ -693,7 +699,6 @@ class ProcessSelectedFaces: mFS = True cont = False else: - # FreeCAD.Console.PrintError(' -Failed to create profile geometry for selected faces.\n') cont = False if cont: @@ -705,8 +710,10 @@ class ProcessSelectedFaces: ofstVal = self._calculateOffsetValue(isHole) faceOfstShp = extractFaceOffset(cfsL, ofstVal, self.wpc) - if faceOfstShp is False: - FreeCAD.Console.PrintError(' -Failed to create offset face.\n') + if not faceOfstShp: + msg = translate('PathSurfaceSupport', + 'Failed to create offset face.') + '\n' + FreeCAD.Console.PrintError(msg) cont = False if cont: @@ -763,7 +770,6 @@ class ProcessSelectedFaces: mFS.append(True) cont = False else: - # PathLog.error(' -Failed to create profile geometry for Face{}.'.format(fNum)) cont = False if cont: @@ -824,7 +830,6 @@ class ProcessSelectedFaces: avoid = Part.makeCompound(outFCS) if self.showDebugObjects: - PathLog.debug('*** tmpAvoidArea') P = FreeCAD.ActiveDocument.addObject('Part::Feature', 'tmpVoidEnvelope') P.Shape = avoid P.purgeTouched() @@ -832,7 +837,6 @@ class ProcessSelectedFaces: if cont: if self.showDebugObjects: - PathLog.debug('*** tmpVoidCompound') P = FreeCAD.ActiveDocument.addObject('Part::Feature', 'tmpVoidCompound') P.Shape = avoid P.purgeTouched() @@ -840,13 +844,15 @@ class ProcessSelectedFaces: ofstVal = self._calculateOffsetValue(isHole, isVoid=True) avdOfstShp = extractFaceOffset(avoid, ofstVal, self.wpc) if avdOfstShp is False: - FreeCAD.Console.PrintError('Failed to create collective offset avoid face.\n') + msg = translate('PathSurfaceSupport', + 'Failed to create collective offset avoid face.') + FreeCAD.Console.PrintError(msg + '\n') cont = False if cont: avdShp = avdOfstShp - if self.obj.AvoidLastX_InternalFeatures is False and len(intFEAT) > 0: + if not self.obj.AvoidLastX_InternalFeatures and len(intFEAT) > 0: if len(intFEAT) > 1: ifc = Part.makeCompound(intFEAT) else: @@ -854,7 +860,9 @@ class ProcessSelectedFaces: ofstVal = self._calculateOffsetValue(isHole=True) ifOfstShp = extractFaceOffset(ifc, ofstVal, self.wpc) if ifOfstShp is False: - FreeCAD.Console.PrintError('Failed to create collective offset avoid internal features.\n') + msg = translate('PathSurfaceSupport', + 'Failed to create collective offset avoid internal features.') + '\n' + FreeCAD.Console.PrintError(msg) else: avdShp = avdOfstShp.cut(ifOfstShp) @@ -890,10 +898,10 @@ class ProcessSelectedFaces: if csFaceShape is False: csFaceShape = getSliceFromEnvelope(baseEnv) if csFaceShape is False: - PathLog.error('Failed to slice baseEnv shape.') + PathLog.debug('Failed to slice baseEnv shape.') cont = False - if cont is True and self.profileEdges != 'None': + if cont and self.profileEdges != 'None': PathLog.debug(' -Attempting profile geometry for model base.') ofstVal = self._calculateOffsetValue(isHole) psOfst = extractFaceOffset(csFaceShape, ofstVal, self.wpc) @@ -902,14 +910,13 @@ class ProcessSelectedFaces: return (True, psOfst) prflShp = psOfst else: - # FreeCAD.Console.PrintError(' -Failed to create profile geometry.\n') cont = False if cont: ofstVal = self._calculateOffsetValue(isHole) faceOffsetShape = extractFaceOffset(csFaceShape, ofstVal, self.wpc) if faceOffsetShape is False: - PathLog.error('extractFaceOffset() failed for entire base.') + PathLog.debug('extractFaceOffset() failed for entire base.') else: faceOffsetShape.translate(FreeCAD.Vector(0.0, 0.0, 0.0 - faceOffsetShape.BoundBox.ZMin)) return (faceOffsetShape, prflShp) @@ -1023,7 +1030,6 @@ def getProjectedFace(tempGroup, wire): else: pWire = Part.Wire(prj.Shape.Edges) if pWire.isClosed() is False: - # PathLog.debug(' -pWire.isClosed() is False') return False slc = Part.Face(pWire) slc.translate(FreeCAD.Vector(0.0, 0.0, 0.0 - slc.BoundBox.ZMin)) @@ -1068,7 +1074,7 @@ def getShapeEnvelope(shape): try: env = PathUtils.getEnvelope(partshape=shape, depthparams=dep_par) # Produces .Shape except Exception as ee: - FreeCAD.Console.PrintError('try: PathUtils.getEnvelope() failed.\n' + str(ee) + '\n') + FreeCAD.Console.PrintError('PathUtils.getEnvelope() failed.\n' + str(ee) + '\n') return False else: return env @@ -1195,7 +1201,9 @@ def _makeSafeSTL(self, JOB, obj, mdlIdx, faceShapes, voidShapes, ocl): adjStckWst = stckWst fuseShapes.append(adjStckWst) else: - PathLog.warning('Path transitions might not avoid the model. Verify paths.') + msg = translate('PathSurfaceSupport', + 'Path transitions might not avoid the model. Verify paths.') + FreeCAD.Console.PrintWarning(msg + '\n') else: # If boundbox is Job.Stock, add hidden pad under stock as base plate toolDiam = self.cutter.getDiameter() @@ -1318,7 +1326,6 @@ def pathGeomToLinesPointSet(obj, compGeoShp, cutClimb, toolDiam, closedGap, gaps closedGap = True True if closedGap else False # used closedGap for LGTM else: - # PathLog.debug('---- Gap: {} mm'.format(gap)) gap = round(gap, 6) if gap < gaps[0]: gaps.insert(0, gap) @@ -1651,7 +1658,6 @@ def pathGeomToCircularPointSet(obj, compGeoShp, cutClimb, toolDiam, closedGap, g arc = (vA, arc[1], vC) closedGap = True else: - # PathLog.debug('---- Gap: {} mm'.format(gap)) gap = round(gap, 6) if gap < gaps[0]: gaps.insert(0, gap) @@ -1837,7 +1843,9 @@ class FindUnifiedRegions: tfBB_Area = tfBB.XLength * tfBB.YLength # self._showShape(topFace, 'topFaceAlt_2_{}'.format(fNum)) if tfBB_Area < (fBB_Area * 0.9): - FreeCAD.Console.PrintError('Faild to extract processing region for Face{}.\n'.format(fNum)) + msg = translate('PathSurfaceSupport', + 'Faild to extract processing region for Face') + FreeCAD.Console.PrintError(msg + '{}.\n'.format(fNum)) cont = False if cont: @@ -2103,7 +2111,7 @@ class FindUnifiedRegions: remList.append(s) break else: - FreeCAD.Console.PrintWarning(' - No common area.\n') + PathLog.debug(' - No common area.\n') remList.sort(reverse=True) for ri in remList: @@ -2213,7 +2221,9 @@ class FindUnifiedRegions: of tuples (faceShape, faceIndex) received at instantiation of the class object.''' self.INTERNALS = list() if len(self.FACES) == 0: - FreeCAD.Console.PrintError('No (faceShp, faceIdx) tuples received at instantiation of class.') + msg = translate('PathSurfaceSupport', + 'No FACE data tuples received at instantiation of class.') + FreeCAD.Console.PrintError(msg + '\n') return [] self._extractTopFaces() @@ -2253,11 +2263,8 @@ class FindUnifiedRegions: return [topFace for (topFace, fcIdx) in self.topFaces] else: # Delete shared edges from edgeData list - # FreeCAD.Console.PrintWarning('self.sharedEdgeIdxs: {}\n'.format(self.sharedEdgeIdxs)) self.sharedEdgeIdxs.sort(reverse=True) for se in self.sharedEdgeIdxs: - # seShp = self.edgeData[se][2] - # self._showShape(seShp, 'SharedEdge') self.edgeData.pop(se) self._extractWiresFromEdges() @@ -2273,6 +2280,8 @@ class FindUnifiedRegions: after calling getUnifiedRegions().''' if self.INTERNALS: return self.INTERNALS - FreeCAD.Console.PrintError('getUnifiedRegions() must be called before getInternalFeatures().\n') + msg = translate('PathSurfaceSupport', + 'getUnifiedRegions() must be called before getInternalFeatures().') + FreeCAD.Console.PrintError(msg + '\n') return False # Eclass