From ee49b9874dec2aed0beccae4e1d06d3775dc04e1 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Tue, 21 Aug 2018 19:20:12 -0700 Subject: [PATCH] Prototype objects for operations and the ability to create them through the regular proxy instantiation. --- src/Mod/Path/PathScripts/PathOp.py | 5 +- src/Mod/Path/PathScripts/PathOpGui.py | 11 +- src/Mod/Path/PathScripts/PathPocketShape.py | 15 ++- .../Path/PathScripts/PathPocketShapeGui.py | 3 +- src/Mod/Path/PathScripts/PathSetupSheet.py | 11 ++ .../PathScripts/PathSetupSheetOpPrototype.py | 104 ++++++++++++++++++ 6 files changed, 141 insertions(+), 8 deletions(-) create mode 100644 src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py diff --git a/src/Mod/Path/PathScripts/PathOp.py b/src/Mod/Path/PathScripts/PathOp.py index 23e7320db9..3bc5ca5493 100644 --- a/src/Mod/Path/PathScripts/PathOp.py +++ b/src/Mod/Path/PathScripts/PathOp.py @@ -162,8 +162,9 @@ class ObjectOp(object): self.initOperation(obj) - if self.setDefaultValues(obj): - obj.Proxy = self + if not hasattr(obj, 'DoNotSetDefaultValues') or not obj.DoNotSetDefaultValues: + if self.setDefaultValues(obj): + obj.Proxy = self def setEditorModes(self, obj, features): '''Editor modes are not preserved during document store/restore, set editor modes for all properties''' diff --git a/src/Mod/Path/PathScripts/PathOpGui.py b/src/Mod/Path/PathScripts/PathOpGui.py index 8a408713e3..de8249a41b 100644 --- a/src/Mod/Path/PathScripts/PathOpGui.py +++ b/src/Mod/Path/PathScripts/PathOpGui.py @@ -31,6 +31,7 @@ import PathScripts.PathLog as PathLog import PathScripts.PathOp as PathOp import PathScripts.PathPreferences as PathPreferences import PathScripts.PathSelection as PathSelection +import PathScripts.PathSetupSheet as PathSetupSheet import PathScripts.PathUtil as PathUtil import PathScripts.PathUtils as PathUtils import importlib @@ -996,8 +997,8 @@ def SetupOperation(name, pixmap, menuText, toolTip, - accelKey=None): - '''SetupOperation(name, objFactory, opPageClass, pixmap, menuText, toolTip, accelKey=None) + setupProperties=None): + '''SetupOperation(name, objFactory, opPageClass, pixmap, menuText, toolTip, setupProperties=None) Creates an instance of CommandPathOp with the given parameters and registers the command with FreeCAD. When activated it creates a model with proxy (by invoking objFactory), assigns a view provider to it (see ViewProvider in this module) and starts the editor specifically for this operation (driven by opPageClass). @@ -1005,10 +1006,14 @@ def SetupOperation(name, It is not expected to be called manually. ''' - res = CommandResources(name, objFactory, opPageClass, pixmap, menuText, accelKey, toolTip) + res = CommandResources(name, objFactory, opPageClass, pixmap, menuText, None, toolTip) command = CommandPathOp(res) FreeCADGui.addCommand("Path_%s" % name.replace(' ', '_'), command) + + if not setupProperties is None: + PathSetupSheet.RegisterOperation(name, objFactory, setupProperties) + return command diff --git a/src/Mod/Path/PathScripts/PathPocketShape.py b/src/Mod/Path/PathScripts/PathPocketShape.py index 321ad3eee1..879357d667 100644 --- a/src/Mod/Path/PathScripts/PathPocketShape.py +++ b/src/Mod/Path/PathScripts/PathPocketShape.py @@ -156,8 +156,19 @@ class ObjectPocket(PathPocketBase.ObjectPocket): obj.OpFinalDepth = bb.ZMin obj.OpStartDepth = bb.ZMax -def Create(name): +def SetupProperties(): + setup = [] + setup.append('CutMode') + setup.append('ExtraOffset') + setup.append('StepOver') + setup.append('ZigZagAngle') + setup.append('OffsetPattern') + setup.append('UseOutline') + return setup + +def Create(name, obj=None): '''Create(name) ... Creates and returns a Pocket operation.''' - obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name) + if obj is None: + obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name) proxy = ObjectPocket(obj) return obj diff --git a/src/Mod/Path/PathScripts/PathPocketShapeGui.py b/src/Mod/Path/PathScripts/PathPocketShapeGui.py index c49cb99625..cd0876261e 100644 --- a/src/Mod/Path/PathScripts/PathPocketShapeGui.py +++ b/src/Mod/Path/PathScripts/PathPocketShapeGui.py @@ -46,6 +46,7 @@ Command = PathOpGui.SetupOperation('Pocket Shape', TaskPanelOpPage, 'Path-Pocket', QtCore.QT_TRANSLATE_NOOP("PathPocket", "Pocket Shape"), - QtCore.QT_TRANSLATE_NOOP("PathPocket", "Creates a Path Pocket object from a face or faces")) + QtCore.QT_TRANSLATE_NOOP("PathPocket", "Creates a Path Pocket object from a face or faces"), + PathPocketShape.SetupProperties) FreeCAD.Console.PrintLog("Loading PathPocketShapeGui... done\n") diff --git a/src/Mod/Path/PathScripts/PathSetupSheet.py b/src/Mod/Path/PathScripts/PathSetupSheet.py index a1df2d88a6..7ec476313f 100644 --- a/src/Mod/Path/PathScripts/PathSetupSheet.py +++ b/src/Mod/Path/PathScripts/PathSetupSheet.py @@ -34,6 +34,8 @@ __author__ = "sliptonic (Brad Collette)" __url__ = "http://www.freecadweb.org" __doc__ = "A container for all default values and job specific configuration values." +_RegisteredOps = {} + if False: PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) PathLog.trackModule() @@ -211,3 +213,12 @@ def Create(name = 'SetupSheet'): obj = FreeCAD.ActiveDocument.addObject('App::FeaturePython', name) proxy = SetupSheet(obj) return obj + +class _RegisteredOp(object): + def __init__(self, factory, properties): + self.factory = factory + self.properties = properties + +def RegisterOperation(name, objFactory, setupProperties): + global _RegisteredOps + _RegisteredOps[name] = _RegisteredOp(objFactory, setupProperties) diff --git a/src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py b/src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py new file mode 100644 index 0000000000..b2e32f863d --- /dev/null +++ b/src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py @@ -0,0 +1,104 @@ +# -*- coding: utf-8 -*- + +# *************************************************************************** +# * * +# * Copyright (c) 2018 sliptonic * +# * * +# * 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 * +# * * +# *************************************************************************** + +import FreeCAD +import Path +import PathScripts.PathLog as PathLog + +__title__ = "Setup Sheet for a Job." +__author__ = "sliptonic (Brad Collette)" +__url__ = "http://www.freecadweb.org" +__doc__ = "Prototype objects to allow extraction of setup sheet values and editing." + + +class Property(object): + '''Base class for all prototype properties''' + def __init__(self, name, category, info): + self.name = name + self.category = category + self.info = info + self.editorMode = 0 + + def setValue(self, value): + self.value = value + def getValue(self): + return self.value + + def setEditorMode(self, mode): + self.editorMode = mode + +class PropertyEnumeration(Property): + def setValue(self, value): + if list == type(value): + self.enums = value + else: + super(self.__class__, self).setValue(value) + + def getEnumValues(self): + return self.enums + +class PropertyDistance(Property): + pass + +class PropertyPercent(Property): + pass + +class PropertyFloat(Property): + pass + +class PropertyBool(Property): + pass + +class PropertyString(Property): + pass + +class OpPrototype(object): + + PropertyType = { + 'App::PropertyEnumeration': PropertyEnumeration, + 'App::PropertyDistance': PropertyDistance, + 'App::PropertyPercent': PropertyPercent, + 'App::PropertyFloat': PropertyFloat, + 'App::PropertyBool': PropertyBool, + 'App::PropertyString': PropertyString, + 'App::PropertyLinkSubListGlobal': Property, + 'App::PropertyLink': Property, + 'App::PropertyVectorDistance': Property, + 'Part::PropertyPartShape': Property, + } + + def __init__(self): + self.properties = {} + self.DoNotSetDefaultValues = True + + def addProperty(self, typeString, name, category, info = None): + prop = self.PropertyType[typeString](name, category, info) + self.properties[name] = prop + + def setEditorMode(self, name, mode): + self.properties[name].setEditorMode(mode) + + + def setupProperties(self, setup): + return [p for p in self.properties if p.name in setup]