ArrayFromShape: make dropdown toolbar button

+ extend the list in single placement dropdown
This commit is contained in:
DeepSOIC 2016-01-31 02:53:25 +03:00
parent f6c63427a6
commit a07ffc7ba5
2 changed files with 91 additions and 15 deletions

View File

@ -184,7 +184,7 @@ class ViewProviderArrayFromShape(lattice2BaseFeature.ViewProviderLatticeFeature)
# -------------------------- Gui command -------------------------------------------------- # -------------------------- Gui command --------------------------------------------------
def CreateLatticeArrayFromShape(TranslateMode = 'child', OrientMode = 'child', WholeObject = False): def CreateLatticeArrayFromShape(TranslateMode = 'child', OrientMode = 'child', WholeObject = False, TranslateElementIndex = None, OrientElementIndex = None):
sel = FreeCADGui.Selection.getSelectionEx() sel = FreeCADGui.Selection.getSelectionEx()
if len(sel) != 1: if len(sel) != 1:
raise SelectionError(message= "Please select just one object, not "+str(len(sel)) +".", title= "Bad selection") raise SelectionError(message= "Please select just one object, not "+str(len(sel)) +".", title= "Bad selection")
@ -200,6 +200,12 @@ def CreateLatticeArrayFromShape(TranslateMode = 'child', OrientMode = 'child', W
FreeCADGui.doCommand("f.Label = 'Placement "+of_or_from+" ' + f.ShapeLink.Label") FreeCADGui.doCommand("f.Label = 'Placement "+of_or_from+" ' + f.ShapeLink.Label")
else: else:
FreeCADGui.doCommand("f.Label = 'Array from ' + f.ShapeLink.Label") FreeCADGui.doCommand("f.Label = 'Array from ' + f.ShapeLink.Label")
if TranslateElementIndex:
FreeCADGui.doCommand("f.TranslateElementIndex = "+repr(TranslateElementIndex))
if OrientElementIndex:
FreeCADGui.doCommand("f.OrientElementIndex = "+repr(OrientElementIndex))
FreeCADGui.doCommand("f.TranslateMode = "+repr(TranslateMode))
FreeCADGui.doCommand("f.OrientMode = "+repr(OrientMode))
FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+ FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+
" child.ViewObject.hide()") " child.ViewObject.hide()")
@ -209,14 +215,21 @@ def CreateLatticeArrayFromShape(TranslateMode = 'child', OrientMode = 'child', W
deselect(sel) deselect(sel)
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()
class _CommandLatticeArrayFromShape: class _CommandLatticeArrayFromShape:
"Command to create LatticeArrayFromShape feature" "Command to create LatticeArrayFromShape feature"
def __init__(self, menu_text, tooltip, Label, TranslateMode, OrientMode):
self.menu_text = menu_text
self.tooltip = tooltip
self.Label = Label
self.TranslateMode = TranslateMode
self.OrientMode = OrientMode
def GetResources(self): def GetResources(self):
return {'Pixmap' : getIconPath("Lattice2_ArrayFromShape.svg"), return {'Pixmap' : getIconPath("Lattice2_ArrayFromShape.svg"),
'MenuText': QtCore.QT_TRANSLATE_NOOP("Lattice2_ArrayFromShape","Array from compound"), 'MenuText': "Array from shape: "+self.menu_text,
'Accel': "", 'Accel': "",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Lattice2_ArrayFromShape","Lattice ArrayFromShape: make placements array from shapes in a compound.")} 'ToolTip': self.tooltip}
def Activated(self): def Activated(self):
try: try:
@ -225,7 +238,7 @@ class _CommandLatticeArrayFromShape:
"Array From Shape command. Creates an array of placements from shapes in a compound.\n\n" "Array From Shape command. Creates an array of placements from shapes in a compound.\n\n"
"Select the object that is a compound, first, then invoke this tool.") "Select the object that is a compound, first, then invoke this tool.")
return return
CreateLatticeArrayFromShape(TranslateMode= 'child.CenterOfMass', OrientMode= 'child') CreateLatticeArrayFromShape(self.TranslateMode, self.OrientMode, WholeObject= False)
except Exception as err: except Exception as err:
msgError(err) msgError(err)
@ -235,24 +248,69 @@ class _CommandLatticeArrayFromShape:
else: else:
return False return False
FreeCADGui.addCommand('Lattice2_ArrayFromShape', _CommandLatticeArrayFromShape()) list_of_commands = []
cmdName = 'Lattice2_ArrayFromShape_Internal'
FreeCADGui.addCommand(cmdName, _CommandLatticeArrayFromShape("internal placements", "Read out placements of children inside the compound", "Array from %1", 'child', 'child'))
list_of_commands.append(cmdName)
cmdName = 'Lattice2_ArrayFromShape_CenterBB'
FreeCADGui.addCommand(cmdName, _CommandLatticeArrayFromShape("center of bounding box", "Align placement's origin to center of shape's bounding box", "Array from %1", 'child.CenterOfBoundBox', 'parent'))
list_of_commands.append(cmdName)
cmdName = 'Lattice2_ArrayFromShape_CenterMass'
FreeCADGui.addCommand(cmdName, _CommandLatticeArrayFromShape("center of mass", "Align placement's origin to shape's center of mass", "Array from %1", 'child.CenterOfMass', 'parent'))
list_of_commands.append(cmdName)
cmdName = 'Lattice2_ArrayFromShape_Inertial'
FreeCADGui.addCommand(cmdName, _CommandLatticeArrayFromShape("inertial axis system", "Make placements from inertial axes of children", "Array from %1", 'child.CenterOfMass', 'child.InertiaAxes'))
list_of_commands.append(cmdName)
class GroupCommandArrayFromShape:
def __init__(self, list_of_commands):
self.list_of_commands = list_of_commands
def GetCommands(self):
return tuple(self.list_of_commands) # a tuple of command names that you want to group
def GetDefaultCommand(self): # return the index of the tuple of the default command. This method is optional and when not implemented '0' is used
return 0
def GetResources(self):
return { 'MenuText': 'Array from shape:', 'ToolTip': 'Array from shape: make array of placements from children of a compound'}
def IsActive(self): # optional
return True
FreeCADGui.addCommand('Lattice2_ArrayFromShapeGroup', GroupCommandArrayFromShape(list_of_commands))
class _CommandLatticePlacementFromShape: class _CommandLatticePlacementFromShape:
"Command to create LatticeArrayFromShape feature linking to placement of one shape" "Command to create LatticePlacementFromShape feature"
def __init__(self, menu_text, tooltip, Label, TranslateMode, OrientMode):
self.menu_text = menu_text
self.tooltip = tooltip
self.Label = Label
self.TranslateMode = TranslateMode
self.OrientMode = OrientMode
def GetResources(self): def GetResources(self):
return {'Pixmap' : getIconPath("Lattice2_PlacementFromShape.svg"), return {'Pixmap' : getIconPath("Lattice2_PlacementFromShape.svg"),
'MenuText': QtCore.QT_TRANSLATE_NOOP("Lattice2_ArrayFromShape","Single Placement: linked to shape"), 'MenuText': "Placement of shape: "+self.menu_text,
'Accel': "", 'Accel': "",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Lattice2_ArrayFromShape","Lattice PlacementFromShape: make Placement linked to placement of selected object.")} 'ToolTip': self.tooltip}
def Activated(self): def Activated(self):
try: try:
if len(FreeCADGui.Selection.getSelection())==0: if len(FreeCADGui.Selection.getSelection())==0:
infoMessage("Single Placement: linked to shape", infoMessage("PlacementFromShape command",
"Single Placement: linked to shape command. Creates a placement linked to a placement of an object.\n\n" "Placement From Shape command. Creates a placements from shape.\n\n"
"Select the object first, then invoke this tool.") "Select the object first, then invoke this tool.")
return return
CreateLatticeArrayFromShape(TranslateMode= 'child', OrientMode= 'child', WholeObject= True) CreateLatticeArrayFromShape(self.TranslateMode, self.OrientMode, WholeObject= True)
except Exception as err: except Exception as err:
msgError(err) msgError(err)
@ -262,9 +320,27 @@ class _CommandLatticePlacementFromShape:
else: else:
return False return False
FreeCADGui.addCommand('Lattice2_PlacementFromShape', _CommandLatticePlacementFromShape()) list_of_commands = []
exportedCommands = ['Lattice2_ArrayFromShape'] #Lattice2_PlacementFromShape will be included in lattice2Placement set of commands. I know, it's ugly.... cmdName = 'Lattice2_PlacementFromShape_Internal'
FreeCADGui.addCommand(cmdName, _CommandLatticePlacementFromShape("copy object.Placement", "Create a placement linked to Placement property of selected object", "Placement of %1", 'child', 'child'))
list_of_commands.append(cmdName)
cmdName = 'Lattice2_PlacementFromShape_CenterBB'
FreeCADGui.addCommand(cmdName, _CommandLatticePlacementFromShape("center of bounding box", "Align placement's origin to center of shape's bounding box", "Placement of %1", 'child.CenterOfBoundBox', '(none)'))
list_of_commands.append(cmdName)
cmdName = 'Lattice2_PlacementFromShape_CenterMass'
FreeCADGui.addCommand(cmdName, _CommandLatticePlacementFromShape("center of mass", "Align placement's origin to shape's center of mass", "Placement of %1", 'child.CenterOfMass', 'parent'))
list_of_commands.append(cmdName)
cmdName = 'Lattice2_PlacementFromShape_Inertial'
FreeCADGui.addCommand(cmdName, _CommandLatticePlacementFromShape("inertial axis system", "Make placement on inertial axes of shape", "Placement of %1", 'child.CenterOfMass', 'child.InertiaAxes'))
list_of_commands.append(cmdName)
exportedCommands = ['Lattice2_ArrayFromShapeGroup'] #Lattice2_PlacementFromShape will be included in lattice2Placement set of commands. I know, it's ugly....
exportedCommands_forSinglePlacement = list(list_of_commands)
# -------------------------- /Gui command -------------------------------------------------- # -------------------------- /Gui command --------------------------------------------------

View File

@ -318,7 +318,7 @@ _listOfSubCommands.append(cmdName)
import lattice2ArrayFromShape import lattice2ArrayFromShape
_listOfSubCommands.append('Lattice2_PlacementFromShape') _listOfSubCommands.extend(lattice2ArrayFromShape.exportedCommands_forSinglePlacement)
class GroupCommandPlacement: class GroupCommandPlacement:
def GetCommands(self): def GetCommands(self):