Added automatic side selection based on Base object.

This commit is contained in:
ml 2016-10-06 22:59:22 -07:00 committed by Markus Lampert
parent bc38ecccba
commit bc696aa84a
2 changed files with 27 additions and 18 deletions

View File

@ -24,7 +24,7 @@
import FreeCAD
import FreeCADGui
import Path
import PathScripts.PathUtils as PathUtils
from PathScripts import PathUtils
from PySide import QtCore, QtGui
import math
@ -135,12 +135,9 @@ class ObjectDressup:
def __init__(self, obj):
obj.addProperty("App::PropertyLink", "Base","Path", "The base path to modify")
obj.addProperty("App::PropertyEnumeration", "side", "Side", "side of path to insert dog-bones")
obj.side = ['Left', 'Right']
# Setting the default value here makes it available regardless of how and when the
# receiver is invoked. And once it's set here it's not needed in Command::Activated
# TODO: figure out a better default depending on Base (which isn't set yet)
obj.side = 'Right'
obj.addProperty("App::PropertyEnumeration", "Side", "Side", "side of path to insert dog-bones")
obj.Side = ['Left', 'Right']
obj.Side = 'Right'
obj.Proxy = self
def __getstate__(self):
@ -159,7 +156,7 @@ class ObjectDressup:
return cmd.Name in movestraight and not chord.isAPlungeMove()
def shouldInsertDogbone(self, obj, inChord, outChord):
return outChord.foldsBackOrTurns(inChord, self.theOtherSideOf(obj.side))
return outChord.foldsBackOrTurns(inChord, self.theOtherSideOf(obj.Side))
# draw circles where dogbones go, easier to spot during testing
def debugCircleBone(self, inChord, outChord):
@ -231,7 +228,18 @@ class ObjectDressup:
obj.Path = path
def setup(self, obj):
#print( "Here we go ...")
if not hasattr(self, 'toolRadius'):
print("Here we go ... ")
# By default the side for dogbones is opposite of the base path side
if obj.Base.Direction == 'CCW':
obj.Side = obj.Base.Side
else:
if obj.Base.Side == 'Left':
obj.Side = 'Right'
elif obj.Base.Side == 'Right':
obj.Side = 'Left'
else:
obj.Side = 'On'
self.toolRadius = 5
toolLoad = PathUtils.getLastToolLoad(obj)
@ -310,14 +318,12 @@ class CommandDogboneDressup:
FreeCADGui.addModule("PathScripts.DogboneDressup")
FreeCADGui.addModule("PathScripts.PathUtils")
FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "DogboneDressup")')
FreeCADGui.doCommand('PathScripts.DogboneDressup.ObjectDressup(obj)')
FreeCADGui.doCommand('dbo = PathScripts.DogboneDressup.ObjectDressup(obj)')
FreeCADGui.doCommand('obj.Base = FreeCAD.ActiveDocument.' + selection[0].Name)
FreeCADGui.doCommand('PathScripts.DogboneDressup.ViewProviderDressup(obj.ViewObject)')
FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)')
FreeCADGui.doCommand('Gui.ActiveDocument.getObject(obj.Base.Name).Visibility = False')
# If I set the default value here and not in __init__ then FreeCAD uses the first
# entry in the enumeration array ...
#FreeCADGui.doCommand('obj.side = "Right"')
FreeCADGui.doCommand('dbo.setup(obj)')
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()

View File

@ -86,6 +86,9 @@ class ObjectContour:
obj.addProperty("App::PropertyEnumeration", "Direction", "Contour", QtCore.QT_TRANSLATE_NOOP("App::Property","The direction that the toolpath should go around the part ClockWise CW or CounterClockWise CCW"))
obj.Direction = ['CW', 'CCW'] # this is the direction that the Contour runs
obj.addProperty("App::PropertyBool", "UseComp", "Contour", QtCore.QT_TRANSLATE_NOOP("App::Property","make True, if using Cutter Radius Compensation"))
obj.addProperty("App::PropertyEnumeration", "Side", "Contour", QtCore.QT_TRANSLATE_NOOP("App::Property", "Side of edge that tool should cut"))
obj.Side = ['Left', 'Right', 'On'] # side of profile that cutter is on in relation to direction of profile
obj.setEditorMode('Side', 2) # hide
obj.addProperty("App::PropertyDistance", "RollRadius", "Contour", QtCore.QT_TRANSLATE_NOOP("App::Property","Radius at start and end"))
obj.addProperty("App::PropertyDistance", "OffsetExtra", "Contour", QtCore.QT_TRANSLATE_NOOP("App::Property","Extra value to stay away from final Contour- good for roughing toolpath"))
@ -170,12 +173,12 @@ class ObjectContour:
lead_out_line_len = 0.0
if obj.UseComp is False:
side = 'On'
obj.Side = 'On'
else:
if obj.Direction == 'CW':
side = 'Left'
obj.Side = 'Left'
else:
side = 'Right'
obj.Side = 'Right'
PathKurveUtils.clear_tags()
for i in range(len(obj.locs)):
@ -191,7 +194,7 @@ class ObjectContour:
obj.FinalDepth.Value, None)
PathKurveUtils.profile2(
curve, side, self.radius, self.vertFeed, self.horizFeed,
curve, obj.Side, self.radius, self.vertFeed, self.horizFeed,
self.vertRapid, self.horizRapid, obj.OffsetExtra.Value, roll_radius,
None, None, depthparams, extend_at_start, extend_at_end,
lead_in_line_len, lead_out_line_len)
@ -219,7 +222,7 @@ class ObjectContour:
self.vertRapid = toolLoad.VertRapid.Value
self.horizRapid = toolLoad.HorizRapid.Value
tool = PathUtils.getTool(obj, toolLoad.ToolNumber)
if tool.Diameter == 0:
if not tool or tool.Diameter == 0:
self.radius = 0.25
else:
self.radius = tool.Diameter/2