Prototype objects for operations and the ability to create them through the regular proxy instantiation.

This commit is contained in:
Markus Lampert
2018-08-21 19:20:12 -07:00
parent 070d17e4e4
commit ee49b9874d
6 changed files with 141 additions and 8 deletions

View File

@@ -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'''

View File

@@ -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

View File

@@ -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

View File

@@ -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")

View File

@@ -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)

View File

@@ -0,0 +1,104 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2018 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 *
# * *
# ***************************************************************************
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]