Support for converting existing jobs to multi base model on loading.

This commit is contained in:
Markus Lampert
2018-09-03 21:08:10 -07:00
committed by wmayer
parent 7925da828e
commit bc871e2b8e
4 changed files with 32 additions and 21 deletions

View File

@@ -99,7 +99,6 @@ class ObjectJob:
obj.addProperty("App::PropertyString", "Description", "Path", QtCore.QT_TRANSLATE_NOOP("PathJob","An optional description for this job"))
obj.addProperty("App::PropertyDistance", "GeometryTolerance", "Geometry", QtCore.QT_TRANSLATE_NOOP("PathJob", "For computing Paths; smaller increases accuracy, but slows down computation"))
obj.addProperty("App::PropertyLink", "Model", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "The base objects for all operations"))
obj.addProperty("App::PropertyLink", "Stock", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "Solid object to be used as stock."))
obj.addProperty("App::PropertyLink", "Operations", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "Compound path of all operations in the order they are processed."))
obj.addProperty("App::PropertyLinkList", "ToolController", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "Collection of tool controllers available for this job."))
@@ -126,12 +125,7 @@ class ObjectJob:
obj.setEditorMode('Placement', 2)
self.setupSetupSheet(obj)
model = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "Model")
if model.ViewObject:
model.ViewObject.Visibility = False
model.addObjects([createModelResourceClone(obj, base) for base in models])
obj.Model = model
self.setupBaseModel(obj, models)
obj.Proxy = self
@@ -153,8 +147,25 @@ class ObjectJob:
PathIconViewProvider.Attach(obj.SetupSheet.ViewObject, 'SetupSheet')
self.setupSheet = obj.SetupSheet.Proxy
def setupBaseModel(self, obj, models=None):
PathLog.track(obj.Label, models)
if not hasattr(obj, 'Model'):
obj.addProperty("App::PropertyLink", "Model", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "The base objects for all operations"))
model = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "Model")
if model.ViewObject:
model.ViewObject.Visibility = False
if models:
model.addObjects([createModelResourceClone(obj, base) for base in models])
obj.Model = model
if hasattr(obj, 'Base'):
PathLog.info("Converting Job.Base to new Job.Model for {}".format(obj.Label))
obj.Model.addObject(obj.Base)
obj.Base = None
obj.removeProperty('Base')
def removeBase(self, obj, base, removeFromModel):
if isResourceClone(obj, base, 'Model'):
if isResourceClone(obj, base, None):
PathUtil.clearExpressionEngine(base)
if removeFromModel:
obj.Model.removeObject(base)
@@ -206,13 +217,6 @@ class ObjectJob:
obj.SetupSheet = None
return True
def fixupResourceClone(self, obj, name, icon):
#if not isResourceClone(obj, name) and not isArchPanelSheet(obj):
# orig = getattr(obj, name)
# if orig:
# setattr(obj, name, createResourceClone(obj, orig, name, icon))
pass
def fixupOperations(self, obj):
if obj.Operations.ViewObject:
try:
@@ -230,7 +234,7 @@ class ObjectJob:
def onDocumentRestored(self, obj):
self.fixupResourceClone(obj, 'Base', 'BaseGeometry')
self.setupBaseModel(obj)
self.fixupOperations(obj)
self.setupSetupSheet(obj)
obj.setEditorMode('Operations', 2) # hide
@@ -244,7 +248,7 @@ class ObjectJob:
def baseObject(self, obj, base):
'''Return the base object, not its clone.'''
if isResourceClone(obj, base, 'Model'):
if isResourceClone(obj, base, 'Model') or isResourceClone(obj, base, 'Base'):
return base.Objects[0]
return base

View File

@@ -38,7 +38,7 @@ from PySide import QtCore, QtGui
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
if True:
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
@@ -71,6 +71,8 @@ class JobCreate:
else:
selected = []
PathLog.track('selected', selected)
expandSolids = False
expandTwoDs = False
expandJobs = False
@@ -78,6 +80,7 @@ class JobCreate:
for base in sorted(PathJob.ObjectJob.baseCandidates(), key=lambda o: o.Label):
PathLog.track(base.Label)
if not base in xxx and not PathJob.isResourceClone(job, base, None) and not hasattr(base, 'StockType'):
PathLog.track('base', base.Label)
item = QtGui.QTreeWidgetItem([base.Label])
item.setData(0, self.DataObject, base)
sel = base.Label in selected

View File

@@ -168,7 +168,11 @@ class ViewProvider:
def claimChildren(self):
children = self.obj.ToolController
children.append(self.obj.Operations)
children.append(self.obj.Model)
if hasattr(self.obj, 'Model'):
# unfortunately this function is called before the object has been fully loaded
# which means we could be dealing with an old job which doesn't have the new Model
# yet.
children.append(self.obj.Model)
if self.obj.Stock:
children.append(self.obj.Stock)
if hasattr(self.obj, 'SetupSheet'):
@@ -1037,6 +1041,7 @@ class TaskPanel:
for base in retired:
self.vproxy.forgetBaseVisibility(obj, base)
self.obj.Proxy.removeBase(obj, base, True)
# do not access any of the retired objects after this point, they don't exist anymore
# then add all rookie base models
baseOrigNames = [proxy.baseObject(obj, base).Name for base in obj.Model.Group]
@@ -1048,7 +1053,6 @@ class TaskPanel:
# refresh the view
if retired or rookies:
PathLog.track([o.Label for o in retired], [o.Label for o in rookies])
self.setFields()
else:
PathLog.track('no changes to model')

View File

@@ -125,7 +125,7 @@ class StockFromBase(Stock):
return None
def execute(self, obj):
bb = shapeBoundBox(obj.Base.Group) if obj.Base else None
bb = shapeBoundBox(obj.Base.Group) if obj.Base and hasattr(obj.Base, 'Group') else None
PathLog.track(obj.Label, bb)
# Sometimes, when the Base changes it's temporarily not assigned when