Fixed Arch.Panel support.

This commit is contained in:
Markus Lampert
2017-09-22 20:50:59 -07:00
parent 749fe3631a
commit b035e658e7
2 changed files with 21 additions and 10 deletions

View File

@@ -61,15 +61,22 @@ class JobTemplate:
Stock = 'Stock'
Version = 'Version'
def isResourceClone(obj, propName, resourceName):
def isArchPanelSheet(obj):
return hasattr(obj, 'Proxy') and isinstance(obj.Proxy, ArchPanel.PanelSheet)
def isResourceClone(obj, propName, resourceName=None):
'''isResourceClone(obj, propName, resourceName) ... Return True if the given property of obj is a clone of type resourceName.'''
if hasattr(obj, propName):
propLink = getattr(obj, propName)
if hasattr(propLink, 'PathResource') and resourceName == propLink.PathResource:
if hasattr(propLink, 'PathResource') and ((resourceName and resourceName == propLink.PathResource) or (resourceName is None and propName == propLink.PathResource)):
return True
return False
def createResourceClone(obj, orig, name, icon):
if isArchPanelSheet(orig):
# can't clone panel sheets - they have to be panel sheets
return orig
clone = Draft.clone(orig)
clone.Label = "%s-%s" % (name, orig.Label)
clone.addProperty('App::PropertyString', 'PathResource')
@@ -143,7 +150,8 @@ class ObjectJob:
# base doesn't depend on anything inside job
if obj.Base:
PathLog.debug('taking down base')
doc.removeObject(obj.Base.Name)
if isResourceClone(obj, 'Base'):
doc.removeObject(obj.Base.Name)
obj.Base = None
# Tool controllers don't depend on anything
PathLog.debug('taking down tool controller')
@@ -152,7 +160,7 @@ class ObjectJob:
obj.ToolController = []
def fixupResourceClone(self, obj, name, icon):
if not isResourceClone(obj, name, name):
if not isResourceClone(obj, name, name) and not isArchPanelSheet(obj):
orig = getattr(obj, name)
if orig:
setattr(obj, name, createResourceClone(obj, orig, name, icon))
@@ -266,7 +274,7 @@ class ObjectJob:
@classmethod
def isBaseCandidate(cls, obj):
'''Answer true if the given object can be used as a Base for a job.'''
return PathUtil.isValidBaseObject(obj) or (hasattr(obj, 'Proxy') and isinstance(obj.Proxy, ArchPanel.PanelSheet))
return PathUtil.isValidBaseObject(obj) or isArchPanelSheet(obj)
def Create(name, base, templateFile = None):
'''Create(name, base, templateFile=None) ... creates a new job and all it's resources.

View File

@@ -166,7 +166,8 @@ class ViewProvider:
PathLog.track(obj.Label, prop)
# make sure the resource view providers are setup properly
if prop == 'Base' and self.obj.Base and self.obj.Base.ViewObject and self.obj.Base.ViewObject.Proxy:
self.obj.Base.ViewObject.Proxy.onEdit(_OpenCloseResourceEditor)
if not PathJob.isArchPanelSheet(self.obj.Base):
self.obj.Base.ViewObject.Proxy.onEdit(_OpenCloseResourceEditor)
if prop == 'Stock' and self.obj.Stock and self.obj.Stock.ViewObject and self.obj.Stock.ViewObject.Proxy:
self.obj.Stock.ViewObject.Proxy.onEdit(_OpenCloseResourceEditor)
@@ -379,8 +380,7 @@ class StockFromExistingEdit(StockEdit):
def candidates(self, obj):
solids = [o for o in obj.Document.Objects if PathUtil.isSolid(o)]
if obj.Base in solids:
# always a resource clone
if obj.Base in solids and PathJob.isResourceClone(obj, 'Base'):
solids.remove(obj.Base)
if obj.Stock in solids:
# regardless, what stock is/was, it's not a valid choice
@@ -430,8 +430,10 @@ class TaskPanel:
self.obj.PostProcessor = postProcessors
self.obj.PostProcessor = currentPostProcessor
base = self.obj.Base if PathJob.isResourceClone(self.obj, 'Base') else None
stock = self.obj.Stock
for o in PathJob.ObjectJob.baseCandidates():
if o != self.obj.Base:
if o != base and o != stock:
self.form.jobModel.addItem(o.Label, o)
self.selectComboBoxText(self.form.jobModel, self.obj.Proxy.baseObject(self.obj).Label)
@@ -532,7 +534,8 @@ class TaskPanel:
selObj = self.form.jobModel.itemData(self.form.jobModel.currentIndex())
if self.obj.Proxy.baseObject(self.obj) != selObj:
self.baseObjectRestoreVisibility(self.obj)
self.obj.Document.removeObject(self.obj.Base.Name)
if PathJob.isResourceClone(self.obj, 'Base'):
self.obj.Document.removeObject(self.obj.Base.Name)
self.obj.Base = PathJob.createResourceClone(self.obj, selObj, 'Base', 'Base')
self.baseObjectSaveVisibility(self.obj)