active body awareness

disable some commands when in body
This commit is contained in:
DeepSOIC 2018-06-14 01:29:38 +03:00
parent 57f3d26d68
commit 0b591d5189
12 changed files with 27 additions and 11 deletions

View File

@ -255,7 +255,7 @@ class _CommandCompoundFilter:
def IsActive(self):
if App.ActiveDocument:
return True
return activeBody() is None
else:
return False
@ -326,7 +326,7 @@ class _CommandExplode:
def IsActive(self):
if App.ActiveDocument:
return True
return activeBody() is None
else:
return False

View File

@ -127,7 +127,7 @@ class _CommandFuseCompound:
def IsActive(self):
if FreeCAD.ActiveDocument:
return True
return activeBody() is None
else:
return False

View File

@ -395,7 +395,7 @@ class _CommandBoundBoxGroup:
'ToolTip': 'Bounding Box: make a box that precisely fits a shape.'}
def IsActive(self): # optional
return True
return activeBody() is None
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Lattice2_BoundBoxGroupCommand',_CommandBoundBoxGroup())

View File

@ -238,7 +238,7 @@ class GroupCommandLatticeDowngrade:
return { 'MenuText': 'Parametric Downgrade', 'ToolTip': 'Parametric Downgrade: downgrade and pack results into a compound.'}
def IsActive(self): # optional
return True
return activeBody() is None
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Lattice2_Downgrade_GroupCommand',GroupCommandLatticeDowngrade())

View File

@ -63,7 +63,7 @@ class _CommandLatticeMakeCompound:
def IsActive(self):
if FreeCAD.ActiveDocument:
return True
return activeBody() is None
else:
return False

View File

@ -235,6 +235,9 @@ class ViewProviderLatticeMirror(LBF.ViewProviderLatticeFeature):
# -------------------------- Gui command --------------------------------------------------
def CreateLatticeMirror(name, extra_code = ''):
sel = FreeCADGui.Selection.getSelectionEx()
if not LBF.isObjectLattice(sel[0].Object) and activeBody():
raise SelectionError("PartDesign Mode", "You can only mirror placements while in body. Please deactivate the body to mirror shapes. PartDesign Feature mirroring is not supported yet.")
FreeCAD.ActiveDocument.openTransaction("Create LatticeMirror")
FreeCADGui.addModule("lattice2Mirror")
FreeCADGui.addModule("lattice2Executer")

View File

@ -34,7 +34,7 @@ from lattice2Common import *
import lattice2BaseFeature
import lattice2CompoundExplorer as LCE
import lattice2Executer
from lattice2PopulateCopies import DereferenceArray
from lattice2PopulateCopies import DereferenceArray, throwBody
import lattice2ShapeCopy as ShapeCopy
# -------------------------- document object --------------------------------------------------
@ -197,6 +197,8 @@ def CreateLatticePopulateChildren(name, label, shapeObj, latticeObjFrom, lattice
def cmdPopulate_shapes_nonFromTo(refmode):
sel = FreeCADGui.Selection.getSelectionEx()
(lattices, shapes) = lattice2BaseFeature.splitSelection(sel)
if activeBody() and len(shapes)>0:
throwBody()
if len(shapes) > 0 and len(lattices) == 1:
FreeCAD.ActiveDocument.openTransaction("Populate with Children")
lattice = lattices[0]
@ -224,6 +226,8 @@ def cmdPopulate_shapes_nonFromTo(refmode):
def cmdPopulate_shapes_FromTo():
sel = FreeCADGui.Selection.getSelectionEx()
(lattices, shapes) = lattice2BaseFeature.splitSelection(sel)
if activeBody() and len(shapes)>0:
throwBody()
if len(shapes) == 0 and len(sel) >= 3:
shapes = sel[:-2]
lattices = sel[-2:]

View File

@ -216,10 +216,15 @@ def CreateLatticePopulateCopies(name, label, shapeObj, latticeObjFrom, latticeOb
#finalize
FreeCADGui.doCommand("Gui.Selection.addSelection(f)")
FreeCADGui.doCommand("f = None")
def throwBody():
raise SelectionError("PartDesign mode", "You can't use population tools on shapes in partdesign body. Use Lattice PartDesign Pattern instead. Or deactivate active body to use populate tools on shapes.")
def cmdPopulate_shapes_nonFromTo(refmode):
sel = FreeCADGui.Selection.getSelectionEx()
(lattices, shapes) = lattice2BaseFeature.splitSelection(sel)
if activeBody() and len(shapes)>0:
throwBody()
if len(shapes) > 0 and len(lattices) == 1:
FreeCAD.ActiveDocument.openTransaction("Populate with copies")
lattice = lattices[0]
@ -247,6 +252,8 @@ def cmdPopulate_shapes_nonFromTo(refmode):
def cmdPopulate_shapes_FromTo():
sel = FreeCADGui.Selection.getSelectionEx()
(lattices, shapes) = lattice2BaseFeature.splitSelection(sel)
if activeBody() and len(shapes)>0:
throwBody()
if len(shapes) == 0 and len(sel) >= 3:
shapes = sel[:-2]
lattices = sel[-2:]

View File

@ -28,6 +28,7 @@ __doc__ = "Group command for Lattice Series features"
import lattice2ParaSeries as ParaSeries
import lattice2TopoSeries as TopoSeries
from lattice2Common import activeBody
import FreeCAD as App
if App.GuiUp:
@ -45,7 +46,7 @@ class CommandSeriesGroup:
'ToolTip': 'Series features (group): features that collect permutations of an object by changing dependent objects.'}
def IsActive(self): # optional
return App.ActiveDocument is not None
return App.ActiveDocument is not None and activeBody() is None
if App.GuiUp:
FreeCADGui.addCommand('Lattice2_Series_GroupCommand',CommandSeriesGroup())

View File

@ -72,7 +72,8 @@ def findFont(font_file_name):
def makeLatticeShapeString(name):
'''makeBoundBox(name): makes a BoundBox object.'''
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
typ = 'Part::Part2DObjectPython' if activeBody() else 'Part::FeaturePython'
obj = FreeCAD.ActiveDocument.addObject(typ, name)
LatticeShapeString(obj)
if FreeCAD.GuiUp:
ViewProviderLatticeShapeString(obj.ViewObject)

View File

@ -167,7 +167,7 @@ class CommandLatticeSlice:
msgError(err)
def IsActive(self):
if FreeCAD.ActiveDocument:
return True
return activeBody() is None
else:
return False

View File

@ -330,7 +330,7 @@ class CommandSublinkGroup:
'ToolTip': 'Sublink (group): extract elements from shapes.'}
def IsActive(self): # optional
return App.ActiveDocument is not None
return App.ActiveDocument is not None and activeBody() is None
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Lattice2_Sublink_GroupCommand',CommandSublinkGroup())