Cleaned up dressup creation.

This commit is contained in:
Markus Lampert
2017-07-09 22:24:14 -07:00
committed by wmayer
parent 900e9e0dcf
commit 0e3cbe360d
3 changed files with 58 additions and 23 deletions

View File

@@ -24,8 +24,10 @@
import FreeCAD
import Part
import Path
import PathScripts
import PathScripts.PathLog as PathLog
import PathScripts.PathPreferencesPathDressup as PathPreferencesPathDressup
import PathScripts.PathUtils as PathUtils
import math
import sys
@@ -107,9 +109,8 @@ class TagSolid:
class ObjectDressup(QtCore.QObject):
changed = QtCore.Signal()
def __init__(self, obj):
obj.Proxy = self
self.obj = obj
def __init__(self, obj, base):
obj.addProperty('App::PropertyLink', 'Base','Base', QtCore.QT_TRANSLATE_NOOP('PathDressup_Tag', 'The base path to modify'))
obj.addProperty('App::PropertyLength', 'Width', 'Tag', QtCore.QT_TRANSLATE_NOOP('PathDressup_Tag', 'Width of tags.'))
obj.addProperty('App::PropertyLength', 'Height', 'Tag', QtCore.QT_TRANSLATE_NOOP('PathDressup_Tag', 'Height of tags.'))
@@ -119,16 +120,21 @@ class ObjectDressup(QtCore.QObject):
obj.addProperty('App::PropertyIntegerList', 'Disabled', 'Tag', QtCore.QT_TRANSLATE_NOOP('PathDressup_Tag', 'Ids of disabled holding tags'))
obj.addProperty('App::PropertyInteger', 'SegmentationFactor', 'Tag', QtCore.QT_TRANSLATE_NOOP('PathDressup_Tag', 'Factor determining the # segments used to approximate rounded tags.'))
obj.addProperty('App::PropertyLink', 'Debug', 'Debug', QtCore.QT_TRANSLATE_NOOP('PathDressup_Tag', 'Some elements for debugging'))
obj.Proxy = self
obj.Base = base
if PathLog.getLevel(PathLog.thisModule()) != PathLog.Level.DEBUG:
obj.setEditorMode('Debug', 2) # hide
dbg = obj.Document.addObject('App::DocumentObjectGroup', 'TagDebug')
obj.Debug = dbg
self.obj = obj
self.solids = []
super(ObjectDressup, self).__init__()
def __getstate__(self):
return None
def __setstate__(self, state):
return None
@@ -185,6 +191,7 @@ class ObjectDressup(QtCore.QObject):
self.masterSolid = TagSolid(self, minZ, self.toolRadius())
self.solids = [self.masterSolid.cloneAt(pos) for pos in self.obj.Positions]
self.changed.emit()
obj.Path = obj.Base.Path
PathLog.track()
def toolRadius(self):
@@ -195,5 +202,23 @@ class ObjectDressup(QtCore.QObject):
obj = FreeCAD.ActiveDocument.addObject('Part::Compound', "tag_%02d" % i)
obj.Shape = solid
def Create(baseObject, name = 'DressupTag'):
'''
Create(basePath, name = 'DressupTag') ... create tag dressup object for the given base path.
'''
if not baseObject.isDerivedFrom('Path::Feature'):
PathLog.error(translate('PathDressup_Tag', 'The selected object is not a path\n'))
return None
if baseObject.isDerivedFrom('Path::FeatureCompoundPython'):
PathLog.error(translate('PathDressup_Tag', 'Please select a Profile object'))
return None
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "TagDressup")
dbo = ObjectDressup(obj, baseObject)
job = PathUtils.findParentJob(baseObject)
PathUtils.addObjectToJob(obj, job)
dbo.assignDefaultValues()
return obj
PathLog.notice('Loading PathDressupTag... done\n')

View File

@@ -23,6 +23,9 @@
# ***************************************************************************
import FreeCAD
import FreeCADGui
import Path
import PathScripts
import PathScripts.PathDressupTag as PathDressupTag
import PathScripts.PathLog as PathLog
import PathScripts.PathUtils as PathUtils
@@ -77,6 +80,11 @@ class PathDressupTagViewProvider:
self.vobj = vobj
self.panel = None
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def setupColors(self):
def colorForColorValue(val):
v = [((val >> n) & 0xff) / 255. for n in [24, 16, 8, 0]]
@@ -180,6 +188,15 @@ class PathDressupTagViewProvider:
self.panel.selectTagWithId(i)
FreeCADGui.updateGui()
def Create(baseObject, name='DressupTag'):
'''
Create(basePath, name = 'DressupTag') ... create tag dressup object for the given base path.
Use this command only iff the UI is up - for batch processing see PathDressupTag.Create
'''
obj = PathDressupTag.Create(baseObject, name)
vp = PathDressupTagViewProvider(obj.ViewObject)
return obj
class CommandPathDressupTag:
def GetResources(self):
@@ -195,33 +212,17 @@ class CommandPathDressupTag:
return False
def Activated(self):
# check that the selection contains exactly what we want
selection = FreeCADGui.Selection.getSelection()
if len(selection) != 1:
PathLog.error(translate('PathDressup_Tag', 'Please select one path object\n'))
return
baseObject = selection[0]
if not baseObject.isDerivedFrom('Path::Feature'):
PathLog.error(translate('PathDressup_Tag', 'The selected object is not a path\n'))
return
if baseObject.isDerivedFrom('Path::FeatureCompoundPython'):
PathLog.error(translate('PathDressup_Tag', 'Please select a Profile object'))
return
# everything ok!
FreeCAD.ActiveDocument.openTransaction(translate('PathDressup_Tag', 'Create Tag Dress-up'))
FreeCADGui.addModule('PathScripts.PathDressupTag')
FreeCADGui.addModule('PathScripts.PathDressupTagGui')
FreeCADGui.addModule('PathScripts.PathUtils')
FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "TagDressup")')
FreeCADGui.doCommand('dbo = PathScripts.PathDressupTag.ObjectDressup(obj)')
FreeCADGui.doCommand('obj.Base = FreeCAD.ActiveDocument.' + selection[0].Name)
FreeCADGui.doCommand('PathScripts.PathDressupTagGui.PathDressupTagViewProvider(obj.ViewObject)')
FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)')
FreeCADGui.doCommand('dbo.assignDefaultValues()')
FreeCADGui.doCommand('obj.Positions = [App.Vector(-10, -10, 0), App.Vector(10, 10, 0)]')
FreeCADGui.doCommand('dbo.execute(obj)')
FreeCADGui.doCommand("PathScripts.PathDressupTagGui.Create(App.ActiveDocument.%s)" % baseObject.Name)
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()

View File

@@ -446,6 +446,15 @@ def addObjectToJob(obj, job):
job.Group = g
return job
def addObjectToJob(obj, job):
'''
addObjectToJob(obj, job) ... adds object to given job.
'''
g = job.Group
g.append(obj)
job.Group = g
return job
def addToJob(obj, jobname=None):
'''adds a path object to a job
obj = obj
@@ -456,12 +465,13 @@ def addToJob(obj, jobname=None):
if len(jobs) == 1:
job = jobs[0]
else:
PathLog.error("Job %s does not exist" % jobname)
FreeCAD.Console.PrintError("Didn't find the job")
return None
else:
jobs = GetJobs()
if len(jobs) == 0:
job = PathJob.CommandJob.Create()
elif len(jobs) == 1:
job = jobs[0]
else:
@@ -480,7 +490,6 @@ def addToJob(obj, jobname=None):
addObjectToJob(obj, job)
return job
def rapid(x=None, y=None, z=None):
""" Returns gcode string to perform a rapid move."""
retstr = "G00"