Skip to content

Commit

Permalink
Path: lgtm Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brad committed Jun 10, 2019
1 parent 58608df commit 4cbdf78
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 144 deletions.
17 changes: 10 additions & 7 deletions src/Mod/Path/PathCommands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-

# ***************************************************************************
# * *
# * Copyright (c) 2016 sliptonic <shopinthewoods@gmail.com> *
Expand Down Expand Up @@ -36,12 +35,12 @@
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtCore
from DraftTools import translate
# from DraftTools import translate
else:
def translate(ctxt, txt):
return txt

__title__="FreeCAD Path Commands"
__title__ = "FreeCAD Path Commands"
__author__ = "sliptonic"
__url__ = "http://www.freecadweb.org"

Expand Down Expand Up @@ -80,7 +79,7 @@ def IsActive(self):
return False

def Activated(self):
#from PathScripts.PathUtils import loopdetect
# from PathScripts.PathUtils import loopdetect
from PathScripts.PathUtils import horizontalEdgeLoop
from PathScripts.PathUtils import horizontalFaceLoop
sel = FreeCADGui.Selection.getSelectionEx()[0]
Expand All @@ -104,7 +103,7 @@ def Activated(self):
for e in elist:
for i in loopwire.Edges:
if e.hashCode() == i.hashCode():
FreeCADGui.Selection.addSelection(obj, "Edge"+str(elist.index(e)+1))
FreeCADGui.Selection.addSelection(obj, "Edge" + str(elist.index(e) + 1))

def formsPartOfALoop(self, obj, sub, names):
if names[0][0:4] != 'Edge':
Expand All @@ -117,9 +116,11 @@ def formsPartOfALoop(self, obj, sub, names):
return False
return True


if FreeCAD.GuiUp:
FreeCADGui.addCommand('Path_SelectLoop', _CommandSelectLoop())


class _ToggleOperation:
"command definition to toggle Operation Active state"
def GetResources(self):
Expand All @@ -135,17 +136,19 @@ def IsActive(self):
try:
obj = FreeCADGui.Selection.getSelectionEx()[0].Object
return isinstance(obj.Proxy, PathScripts.PathOp.ObjectOp)
except:
except(IndexError, AttributeError):
return False

def Activated(self):
obj = FreeCADGui.Selection.getSelectionEx()[0].Object
obj.Active = not(obj.Active)
FreeCAD.ActiveDocument.recompute()


if FreeCAD.GuiUp:
FreeCADGui.addCommand('Path_OpActiveToggle', _ToggleOperation())


class _CopyOperation:
"the Path Copy Operation command definition"
def GetResources(self):
Expand All @@ -160,7 +163,7 @@ def IsActive(self):
try:
obj = FreeCADGui.Selection.getSelectionEx()[0].Object
return isinstance(obj.Proxy, PathScripts.PathOp.ObjectOp)
except:
except(IndexError, AttributeError):
return False

def Activated(self):
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Path/PathScripts/PathArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def IsActive(self):
try:
obj = FreeCADGui.Selection.getSelectionEx()[0].Object
return isinstance(obj.Proxy, PathScripts.PathOp.ObjectOp)
except:
except(IndexError, AttributeError):
return False

def Activated(self):
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Path/PathScripts/PathComment.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import FreeCAD
import FreeCADGui
import Path
from PySide import QtCore, QtGui
from PySide import QtCore

# Qt translation handling
def translate(context, text, disambig=None):
Expand Down
30 changes: 17 additions & 13 deletions src/Mod/Path/PathScripts/PathDeburr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

import FreeCAD
import Part
import Path
# import Path
import PathScripts.PathEngraveBase as PathEngraveBase
import PathScripts.PathLog as PathLog
import PathScripts.PathOp as PathOp
import PathScripts.PathOpTools as PathOpTools
import PathScripts.PathUtil as PathUtil
# import PathScripts.PathUtil as PathUtil
import math

from PySide import QtCore
Expand All @@ -40,25 +40,28 @@
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())


# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)


def toolDepthAndOffset(width, extraDepth, tool):
'''toolDepthAndOffset(width, extraDepth, tool) ... return tuple for given parameters.'''
angle = tool.CuttingEdgeAngle
if 0 == angle:
angle = 180
tan = math.tan(math.radians(angle/2))
tan = math.tan(math.radians(angle / 2))

toolDepth = 0 if 0 == tan else width / tan
extraDepth = extraDepth
# extraDepth = extraDepth
depth = toolDepth + extraDepth
toolOffset = tool.FlatRadius
extraOffset = tool.Diameter/2 - width if 180 == angle else extraDepth / tan
extraOffset = tool.Diameter / 2 - width if 180 == angle else extraDepth / tan
offset = toolOffset + extraOffset
return (depth, offset)


class ObjectDeburr(PathEngraveBase.ObjectOp):
'''Proxy class for Deburr operation.'''

Expand All @@ -67,14 +70,14 @@ def opFeatures(self, obj):

def initOperation(self, obj):
PathLog.track(obj.Label)
obj.addProperty('App::PropertyDistance', 'Width', 'Deburr', QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'The desired width of the chamfer'))
obj.addProperty('App::PropertyDistance', 'ExtraDepth', 'Deburr', QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'The additional depth of the tool path'))
obj.addProperty('App::PropertyEnumeration', 'Join', 'Deburr', QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'How to join chamfer segments'))
obj.addProperty('App::PropertyDistance', 'Width', 'Deburr', QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'The desired width of the chamfer'))
obj.addProperty('App::PropertyDistance', 'ExtraDepth', 'Deburr', QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'The additional depth of the tool path'))
obj.addProperty('App::PropertyEnumeration', 'Join', 'Deburr', QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'How to join chamfer segments'))
obj.Join = ['Round', 'Miter']
obj.setEditorMode('Join', 2) # hide for now
obj.setEditorMode('Join', 2) # hide for now

def opOnDocumentRestored(self, obj):
obj.setEditorMode('Join', 2) # hide for now
obj.setEditorMode('Join', 2) # hide for now

def opExecute(self, obj):
PathLog.track(obj.Label)
Expand Down Expand Up @@ -125,7 +128,7 @@ def opExecute(self, obj):

def opRejectAddBase(self, obj, base, sub):
'''The chamfer op can only deal with features of the base model, all others are rejected.'''
return not base in self.model
return base not in self.model

def opSetDefaultValues(self, obj, job):
PathLog.track(obj.Label, job.Label)
Expand All @@ -135,16 +138,17 @@ def opSetDefaultValues(self, obj, job):
obj.setExpression('StepDown', '0 mm')
obj.StepDown = '0 mm'


def SetupProperties():
setup = []
setup.append('Width')
setup.append('ExtraDepth')
return setup

def Create(name, obj = None):

def Create(name, obj=None):
'''Create(name) ... Creates and returns a Deburr operation.'''
if obj is None:
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name)
proxy = ObjectDeburr(obj, name)
return obj

Loading

0 comments on commit 4cbdf78

Please sign in to comment.