add partdesign toolbar

This commit is contained in:
DeepSOIC 2018-06-14 01:03:17 +03:00
parent 33d5f5edf8
commit 57f3d26d68
5 changed files with 82 additions and 37 deletions

View File

@ -32,7 +32,8 @@ __Status__ = 'alpha'
__Requires__ = 'freecad 0.16.5155'
__Communication__ = 'vv.titov@gmail.com; DeepSOIC on FreeCAD forum'
import lattice2InjectedToolbars as TB
TB.registerPDToolbar()
class Lattice2Workbench (Workbench):
MenuText = 'Lattice2'
@ -85,7 +86,7 @@ class Lattice2Workbench (Workbench):
self.appendMenu('Lattice2', cmdsCompoundTools)
cmdsPDTools = ([]
+ Lattice2.PartDesignFeatures.PDPattern.exportedCommands
+ Lattice2.PartDesignFeatures.PDPatternCommand.exportedCommands
)
self.appendToolbar('Lattice2PartDesignFeatres', cmdsPDTools)
self.appendMenu('Lattice2', cmdsPDTools)

View File

@ -1 +1,2 @@
import lattice2PDPattern as PDPattern
import lattice2PDPatternCommand as PDPatternCommand

View File

@ -0,0 +1,35 @@
import FreeCAD as App
def findToolbar(name, label, workbench, create = False):
"""findToolbar(name, label, workbench, create= False): returns tuple "User parameter:BaseApp/Workbench/Global/Toolbar", "toolbar_group_name"."""
tb_root = "User parameter:BaseApp/Workbench/{workbench}/Toolbar".format(workbench= workbench)
pp = App.ParamGet(tb_root)
if pp.HasGroup(name):
return [tb_root, name]
for i in range(10):
g = 'Custom_'+str(i)
if pp.HasGroup(g) and pp.GetGroup(g).GetString('Name') == label:
return [tb_root, g]
if create:
return [tb_root, name]
return None
def findGlobalToolbar(name, label, create = False):
return findToolbar(name, label, 'Global', create)
def findPDToolbar(name, label, create = False):
return findToolbar(name, label, 'PartDesignWorkbench', create)
def registerPDToolbar():
creating_anew = not isPDRegistered()
p = App.ParamGet('/'.join(findPDToolbar('Lattice2',"Lattice2 PartDesign", create= True)))
p.SetString("Name", "Lattice2 PartDesign")
import lattice2PDPatternCommand as PDPattern
for cmd in PDPattern.exportedCommands:
p.SetString(cmd, "FreeCAD")
if creating_anew:
p.SetBool("Active", 1)
def isPDRegistered():
return findPDToolbar('Lattice2',"Lattice2 PartDesign")

View File

@ -357,38 +357,4 @@ def cmdPDPattern():
" a template body and two placements/arrays, one from selected body and one from active body."
)
class CommandLatticePDPattern:
"Command to create Lattice PartDesign Pattern feature"
def GetResources(self):
return {'Pixmap' : getIconPath("Lattice2_PDPattern.svg"),
'MenuText': "Lattice PartDesign Pattern",
'Accel': "",
'ToolTip': "Lattice PartDesign Pattern command. Replicates partdesign features at every placement in array."}
def Activated(self):
try:
if len(FreeCADGui.Selection.getSelection())==0:
infoMessage("Lattice PartDesign Pattern",
"Lattice PartDesign Pattern command. Replicates partdesign features at every placement in array.\n\n"
"Please select features to repeat, reference placement (optional), and target placement/array. \n\n"
"You can use features from another body. Then, reference placement is required. You can also select a body (a \"template body\"), then all features from that body will be replicated.\n\n"
"Please observe scope restrictions. Reference placement must be in same body the original features are in; target placement/array must be in active body. You can create Lattice Arrays "
"right in PartDesign bodies, but you can't drag them in after the fact. You can import arrays of placements from elsewhere using a Shapebinder, or Part-o-Magic Ghost.")
return
if activeBody() is None:
infoMessage("Lattice PartDesign Pattern", "No active body. Please, activate a body, first.")
cmdPDPattern()
except Exception as err:
msgError(err)
def IsActive(self):
if FreeCAD.ActiveDocument:
return True
else:
return False
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Lattice2_PDPattern', CommandLatticePDPattern())
exportedCommands = ['Lattice2_PDPattern']
# command defined in lattice2PDPatternCommand.py

View File

@ -0,0 +1,42 @@
# all imports are in command's activated(), for to speed up FC startup
import FreeCAD
if FreeCAD.GuiUp:
import FreeCADGui
class CommandLatticePDPattern:
"Command to create Lattice PartDesign Pattern feature"
def GetResources(self):
import lattice2_rc
return {'Pixmap' : ":/icons/Lattice2_PDPattern.svg",
'MenuText': "Lattice PartDesign Pattern",
'Accel': "",
'ToolTip': "Lattice PartDesign Pattern command. Replicates partdesign features at every placement in array."}
def Activated(self):
from lattice2Common import infoMessage, msgError, activeBody
from lattice2PDPattern import cmdPDPattern
try:
if len(FreeCADGui.Selection.getSelection())==0:
infoMessage("Lattice PartDesign Pattern",
"Lattice PartDesign Pattern command. Replicates partdesign features at every placement in array.\n\n"
"Please select features to repeat, reference placement (optional), and target placement/array. \n\n"
"You can use features from another body. Then, reference placement is required. You can also select a body (a \"template body\"), then all features from that body will be replicated.\n\n"
"Please observe scope restrictions. Reference placement must be in same body the original features are in; target placement/array must be in active body. You can create Lattice Arrays "
"right in PartDesign bodies, but you can't drag them in after the fact. You can import arrays of placements from elsewhere using a Shapebinder, or Part-o-Magic Ghost.")
return
if activeBody() is None:
infoMessage("Lattice PartDesign Pattern", "No active body. Please, activate a body, first.")
cmdPDPattern()
except Exception as err:
msgError(err)
def IsActive(self):
if FreeCAD.ActiveDocument:
return True
else:
return False
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Lattice2_PDPattern', CommandLatticePDPattern())
exportedCommands = ['Lattice2_PDPattern']