Fixed base object clone handling.
This commit is contained in:
@@ -43,6 +43,7 @@ SET(PathScripts_SRCS
|
||||
PathScripts/PathHelix.py
|
||||
PathScripts/PathHelixGui.py
|
||||
PathScripts/PathHop.py
|
||||
PathScripts/PathIconViewProvider.py
|
||||
PathScripts/PathInspect.py
|
||||
PathScripts/PathJob.py
|
||||
PathScripts/PathJobCmd.py
|
||||
|
||||
49
src/Mod/Path/PathScripts/PathIconViewProvider.py
Normal file
49
src/Mod/Path/PathScripts/PathIconViewProvider.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ***************************************************************************
|
||||
# * *
|
||||
# * Copyright (c) 2017 sliptonic <shopinthewoods@gmail.com> *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * This program is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with this program; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
__title__ = "Path Icon ViewProvider"
|
||||
__author__ = "sliptonic (Brad Collette)"
|
||||
__url__ = "http://www.freecadweb.org"
|
||||
__doc__ = "ViewProvider who's main and only task is to assign an icon."
|
||||
|
||||
class ViewProvider(object):
|
||||
'''Generic view provider to assign an icon.'''
|
||||
|
||||
def __init__(self, vobj, icon):
|
||||
self.icon = icon
|
||||
vobj.Proxy = self
|
||||
|
||||
def attach(self, vobj):
|
||||
self.vobj = vobj
|
||||
self.obj = vobj.Object
|
||||
|
||||
def __getstate__(self):
|
||||
return {'icon': self.icon }
|
||||
|
||||
def __setstate__(self, state):
|
||||
self.icon = state['icon']
|
||||
|
||||
def getIcon(self):
|
||||
return ":/icons/Path-{}.svg".format(self.icon)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
import ArchPanel
|
||||
import Draft
|
||||
import FreeCAD
|
||||
import PathScripts.PathIconViewProvider as PathIconViewProvider
|
||||
import PathScripts.PathLog as PathLog
|
||||
import PathScripts.PathToolController as PathToolController
|
||||
import PathScripts.PathUtil as PathUtil
|
||||
@@ -39,6 +40,7 @@ if False:
|
||||
PathLog.trackModule(PathLog.thisModule())
|
||||
else:
|
||||
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
|
||||
PathLog.trackModule(PathLog.thisModule())
|
||||
|
||||
"""Path Job object and FreeCAD command"""
|
||||
|
||||
@@ -89,7 +91,7 @@ class ObjectJob:
|
||||
obj.setEditorMode('Operations', 2) # hide
|
||||
obj.setEditorMode('Placement', 2)
|
||||
|
||||
obj.Base = base
|
||||
self.createResourceClone(obj, base, 'Base')
|
||||
obj.Proxy = self
|
||||
|
||||
self.assignTemplate(obj, template)
|
||||
@@ -107,46 +109,37 @@ class ObjectJob:
|
||||
|
||||
def isResourceClone(self, obj, propName, resourceName):
|
||||
if hasattr(obj, propName):
|
||||
prop = getattr(obj, propName)
|
||||
if hasattr(prop, 'PathResource') and resourceName == getattr(prop, 'PathResource'):
|
||||
propLink = getattr(obj, propName)
|
||||
if hasattr(propLink, 'PathResource') and resourceName == propLink.PathResource:
|
||||
return True
|
||||
return False
|
||||
|
||||
def createResourceClone(self, obj, orig, name):
|
||||
clone = Draft.clone(orig)
|
||||
clone.Label = "%s-%s" % (name, orig.Label)
|
||||
clone.addProperty('App::PropertyString', 'PathResource')
|
||||
clone.PathResource = name
|
||||
if clone.ViewObject:
|
||||
PathIconViewProvider.ViewProvider(clone.ViewObject, 'BaseGeometry')
|
||||
clone.ViewObject.Visibility = False
|
||||
setattr(obj, name, clone)
|
||||
|
||||
def fixupResourceClone(self, obj, name):
|
||||
if not self.isResourceClone(obj, name, name):
|
||||
orig = getattr(obj, name)
|
||||
if orig:
|
||||
clone = Draft.clone(orig)
|
||||
clone.Label = name
|
||||
clone.addProperty('App::PropertyString', 'PathResource')
|
||||
clone.PathResource = name
|
||||
if clone.ViewObject:
|
||||
clone.ViewObject.Visibility = False
|
||||
setattr(obj, name, clone)
|
||||
|
||||
def onBeforeChange(self, obj, prop):
|
||||
PathLog.track(obj.Label, prop)
|
||||
if prop == 'Base' and obj.Base and hasattr(obj.Base, 'PathResource'):
|
||||
PathLog.info('removing old base clone')
|
||||
obj.Base.removeProperty('PathResource')
|
||||
obj.Document.removeObject(obj.Base.Name)
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
PathLog.track(obj.Label, prop)
|
||||
if prop == "PostProcessor" and obj.PostProcessor:
|
||||
processor = PostProcessor.load(obj.PostProcessor)
|
||||
self.tooltip = processor.tooltip
|
||||
self.tooltipArgs = processor.tooltipArgs
|
||||
|
||||
if prop == 'Base':
|
||||
self.fixupResourceClone(obj, 'Base')
|
||||
if prop == 'Stock':
|
||||
self.fixupResourceClone(obj, 'Stock')
|
||||
self.createResourceClone(obj, orig, name)
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
self.fixupResourceClone(obj, 'Base')
|
||||
self.fixupResourceClone(obj, 'Stock')
|
||||
|
||||
def baseObject(self, obj):
|
||||
'''Return the base object, not its clone.'''
|
||||
if self.isResourceClone(obj, 'Base', 'Base'):
|
||||
return obj.Base.Objects[0]
|
||||
return obj.Base
|
||||
|
||||
def assignTemplate(self, obj, template):
|
||||
'''assignTemplate(obj, template) ... extract the properties from the given template file and assign to receiver.
|
||||
This will also create any TCs stored in the template.'''
|
||||
|
||||
@@ -126,7 +126,9 @@ class TaskPanel:
|
||||
self.obj.PostProcessor = currentPostProcessor
|
||||
|
||||
for o in PathJob.ObjectJob.baseCandidates():
|
||||
self.form.infoModel.addItem(o.Label, o)
|
||||
if o != self.obj.Base:
|
||||
self.form.infoModel.addItem(o.Label, o)
|
||||
self.selectComboBoxText(self.form.infoModel, self.obj.Proxy.baseObject(self.obj).Label)
|
||||
|
||||
self.postProcessorDefaultTooltip = self.form.postProcessor.toolTip()
|
||||
self.postProcessorArgsDefaultTooltip = self.form.postProcessorArguments.toolTip()
|
||||
@@ -135,16 +137,29 @@ class TaskPanel:
|
||||
self.baseOrigVisibilty = False
|
||||
if self.obj.Base and self.obj.Base.ViewObject:
|
||||
self.baseVisibility = self.obj.Base.ViewObject.Visibility
|
||||
self.obj.Base.ViewObject.Visibility = True
|
||||
self.baseOrigVisibility = self.obj.Base.Objects[0].ViewObject.Visibility
|
||||
self.obj.Base.Objects[0].ViewObject.Visibility = False
|
||||
self.baseObjectSaveVisibility(self.obj)
|
||||
|
||||
def baseObjectViewObject(self, obj):
|
||||
base = obj.Proxy.baseObject(obj)
|
||||
body = base.getParentGeoFeatureGroup()
|
||||
return body.ViewObject if body else base.ViewObject
|
||||
|
||||
def baseObjectSaveVisibility(self, obj):
|
||||
baseVO = self.baseObjectViewObject(self.obj)
|
||||
self.baseOrigVisibility = baseVO.Visibility
|
||||
baseVO.Visibility = False
|
||||
obj.Base.ViewObject.Visibility = True
|
||||
|
||||
def baseObjectRestoreVisibility(self, obj):
|
||||
baseVO = self.baseObjectViewObject(self.obj)
|
||||
baseVO.Visibility = self.baseOrigVisibility
|
||||
|
||||
def preCleanup(self):
|
||||
PathLog.track()
|
||||
FreeCADGui.Selection.removeObserver(self)
|
||||
if self.obj.Base and self.obj.Base.ViewObject:
|
||||
self.obj.Base.ViewObject.Visibility = self.baseVisibility
|
||||
self.obj.Base.Objects[0].ViewObject.Visibility = self.baseOrigVisibility
|
||||
self.baseObjectRestoreVisibility(self.obj)
|
||||
|
||||
def accept(self, resetEdit=True):
|
||||
PathLog.track()
|
||||
@@ -195,7 +210,11 @@ class TaskPanel:
|
||||
self.obj.Operations.Group = [self.form.operationsList.item(i).data(self.DataObject) for i in range(self.form.operationsList.count())]
|
||||
|
||||
selObj = self.form.infoModel.itemData(self.form.infoModel.currentIndex())
|
||||
self.obj.Base = selObj
|
||||
if self.obj.Proxy.baseObject(self.obj) != selObj:
|
||||
self.baseObjectRestoreVisibility(self.obj)
|
||||
self.obj.Document.removeObject(self.obj.Base.Name)
|
||||
self.obj.Proxy.createResourceClone(self.obj, selObj, 'Base')
|
||||
self.baseObjectSaveVisibility(self.obj)
|
||||
|
||||
self.updateTooltips()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user