From 0b591d518934412714935c7d9e40742daf433d37 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Thu, 14 Jun 2018 01:29:38 +0300 Subject: [PATCH] active body awareness disable some commands when in body --- CompoundFilter2.py | 4 ++-- FuseCompound2.py | 2 +- lattice2BoundBox.py | 2 +- lattice2Downgrade.py | 2 +- lattice2MakeCompound.py | 2 +- lattice2Mirror.py | 3 +++ lattice2PopulateChildren.py | 6 +++++- lattice2PopulateCopies.py | 7 +++++++ lattice2SeriesGroup.py | 3 ++- lattice2ShapeString.py | 3 ++- lattice2Slice.py | 2 +- lattice2SubLink.py | 2 +- 12 files changed, 27 insertions(+), 11 deletions(-) diff --git a/CompoundFilter2.py b/CompoundFilter2.py index 0d1dd13..90d3798 100644 --- a/CompoundFilter2.py +++ b/CompoundFilter2.py @@ -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 diff --git a/FuseCompound2.py b/FuseCompound2.py index 27fd06d..9ecb905 100644 --- a/FuseCompound2.py +++ b/FuseCompound2.py @@ -127,7 +127,7 @@ class _CommandFuseCompound: def IsActive(self): if FreeCAD.ActiveDocument: - return True + return activeBody() is None else: return False diff --git a/lattice2BoundBox.py b/lattice2BoundBox.py index eb74d5d..5d6300b 100644 --- a/lattice2BoundBox.py +++ b/lattice2BoundBox.py @@ -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()) diff --git a/lattice2Downgrade.py b/lattice2Downgrade.py index bc2cbaf..c339602 100644 --- a/lattice2Downgrade.py +++ b/lattice2Downgrade.py @@ -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()) diff --git a/lattice2MakeCompound.py b/lattice2MakeCompound.py index dedabc3..38fc69c 100644 --- a/lattice2MakeCompound.py +++ b/lattice2MakeCompound.py @@ -63,7 +63,7 @@ class _CommandLatticeMakeCompound: def IsActive(self): if FreeCAD.ActiveDocument: - return True + return activeBody() is None else: return False diff --git a/lattice2Mirror.py b/lattice2Mirror.py index c95f313..d325536 100644 --- a/lattice2Mirror.py +++ b/lattice2Mirror.py @@ -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") diff --git a/lattice2PopulateChildren.py b/lattice2PopulateChildren.py index 9602793..d65712c 100644 --- a/lattice2PopulateChildren.py +++ b/lattice2PopulateChildren.py @@ -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:] diff --git a/lattice2PopulateCopies.py b/lattice2PopulateCopies.py index bb9555f..738f010 100644 --- a/lattice2PopulateCopies.py +++ b/lattice2PopulateCopies.py @@ -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:] diff --git a/lattice2SeriesGroup.py b/lattice2SeriesGroup.py index 4163cb1..88e41f2 100644 --- a/lattice2SeriesGroup.py +++ b/lattice2SeriesGroup.py @@ -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()) diff --git a/lattice2ShapeString.py b/lattice2ShapeString.py index 7e08fdb..e8af7c2 100644 --- a/lattice2ShapeString.py +++ b/lattice2ShapeString.py @@ -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) diff --git a/lattice2Slice.py b/lattice2Slice.py index 3d5a594..ca645f0 100644 --- a/lattice2Slice.py +++ b/lattice2Slice.py @@ -167,7 +167,7 @@ class CommandLatticeSlice: msgError(err) def IsActive(self): if FreeCAD.ActiveDocument: - return True + return activeBody() is None else: return False diff --git a/lattice2SubLink.py b/lattice2SubLink.py index c3d876d..23f1b33 100644 --- a/lattice2SubLink.py +++ b/lattice2SubLink.py @@ -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())