From a9e4056597c1a56153daa3b95a44cda1815f2879 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Wed, 22 May 2024 14:51:01 +0200 Subject: [PATCH] BIM: improved IsActive behaviour - fixes #14061 --- src/Mod/BIM/bimcommands/BimArchUtils.py | 45 +++++++++++++------- src/Mod/BIM/bimcommands/BimAxis.py | 12 ++++-- src/Mod/BIM/bimcommands/BimBox.py | 6 +-- src/Mod/BIM/bimcommands/BimBuildingPart.py | 6 ++- src/Mod/BIM/bimcommands/BimClassification.py | 6 +-- src/Mod/BIM/bimcommands/BimConvert.py | 6 +-- src/Mod/BIM/bimcommands/BimCurtainwall.py | 3 +- src/Mod/BIM/bimcommands/BimCutPlane.py | 3 +- src/Mod/BIM/bimcommands/BimDiff.py | 6 +-- src/Mod/BIM/bimcommands/BimEquipment.py | 3 +- src/Mod/BIM/bimcommands/BimFence.py | 3 +- src/Mod/BIM/bimcommands/BimFrame.py | 3 +- src/Mod/BIM/bimcommands/BimGlue.py | 6 +-- src/Mod/BIM/bimcommands/BimIfcElements.py | 9 +--- src/Mod/BIM/bimcommands/BimIfcProperties.py | 9 +--- src/Mod/BIM/bimcommands/BimIfcQuantities.py | 9 +--- src/Mod/BIM/bimcommands/BimImagePlane.py | 6 +-- src/Mod/BIM/bimcommands/BimMaterial.py | 17 +++----- src/Mod/BIM/bimcommands/BimPanel.py | 15 ++++--- src/Mod/BIM/bimcommands/BimPipe.py | 9 ++-- src/Mod/BIM/bimcommands/BimProfile.py | 3 +- src/Mod/BIM/bimcommands/BimProject.py | 3 +- src/Mod/BIM/bimcommands/BimRebar.py | 3 +- src/Mod/BIM/bimcommands/BimReextrude.py | 6 +-- src/Mod/BIM/bimcommands/BimReference.py | 3 +- src/Mod/BIM/bimcommands/BimRoof.py | 3 +- src/Mod/BIM/bimcommands/BimSchedule.py | 6 +-- src/Mod/BIM/bimcommands/BimSectionPlane.py | 3 +- src/Mod/BIM/bimcommands/BimSite.py | 3 +- src/Mod/BIM/bimcommands/BimSketch.py | 6 +-- src/Mod/BIM/bimcommands/BimSlab.py | 3 +- src/Mod/BIM/bimcommands/BimSpace.py | 3 +- src/Mod/BIM/bimcommands/BimStairs.py | 3 +- src/Mod/BIM/bimcommands/BimTDPage.py | 6 +-- src/Mod/BIM/bimcommands/BimTDView.py | 6 +-- src/Mod/BIM/bimcommands/BimTrash.py | 7 +-- src/Mod/BIM/bimcommands/BimTruss.py | 3 +- src/Mod/BIM/bimcommands/BimUnclone.py | 6 +-- src/Mod/BIM/bimcommands/BimWPCommands.py | 6 +-- src/Mod/BIM/bimcommands/BimWall.py | 3 +- src/Mod/BIM/bimcommands/BimWindow.py | 3 +- 41 files changed, 134 insertions(+), 136 deletions(-) diff --git a/src/Mod/BIM/bimcommands/BimArchUtils.py b/src/Mod/BIM/bimcommands/BimArchUtils.py index 3f7cdbdb62..c50a173c1c 100644 --- a/src/Mod/BIM/bimcommands/BimArchUtils.py +++ b/src/Mod/BIM/bimcommands/BimArchUtils.py @@ -43,7 +43,8 @@ class Arch_Add: 'ToolTip': QT_TRANSLATE_NOOP("Arch_Add","Adds the selected components to the active object")} def IsActive(self): - return len(FreeCADGui.Selection.getSelection()) > 1 + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v and len(FreeCADGui.Selection.getSelection()) > 1 def Activated(self): import Draft @@ -78,7 +79,8 @@ class Arch_Remove: 'ToolTip': QT_TRANSLATE_NOOP("Arch_Remove","Remove the selected components from their parents, or create a hole in a component")} def IsActive(self): - return bool(FreeCADGui.Selection.getSelection()) + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v and bool(FreeCADGui.Selection.getSelection()) def Activated(self): import Draft @@ -115,7 +117,8 @@ class Arch_SplitMesh: 'ToolTip': QT_TRANSLATE_NOOP("Arch_SplitMesh","Splits selected meshes into independent components")} def IsActive(self): - return bool(FreeCADGui.Selection.getSelection()) + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v and bool(FreeCADGui.Selection.getSelection()) def Activated(self): import Arch @@ -142,7 +145,8 @@ class Arch_MeshToShape: 'ToolTip': QT_TRANSLATE_NOOP("Arch_MeshToShape","Turns selected meshes into Part Shape objects")} def IsActive(self): - return bool(FreeCADGui.Selection.getSelection()) + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v and bool(FreeCADGui.Selection.getSelection()) def Activated(self): import Arch @@ -179,7 +183,8 @@ class Arch_SelectNonSolidMeshes: 'ToolTip': QT_TRANSLATE_NOOP("Arch_SelectNonSolidMeshes","Selects all non-manifold meshes from the document or from the selected groups")} def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): msel = [] @@ -208,7 +213,8 @@ class Arch_RemoveShape: 'ToolTip': QT_TRANSLATE_NOOP("Arch_RemoveShape","Removes cubic shapes from Arch components")} def IsActive(self): - return bool(FreeCADGui.Selection.getSelection()) + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v and bool(FreeCADGui.Selection.getSelection()) def Activated(self): import Arch @@ -225,7 +231,8 @@ class Arch_CloseHoles: 'ToolTip': QT_TRANSLATE_NOOP("Arch_CloseHoles","Closes holes in open shapes, turning them solids")} def IsActive(self): - return bool(FreeCADGui.Selection.getSelection()) + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v and bool(FreeCADGui.Selection.getSelection()) def Activated(self): import Arch @@ -243,7 +250,8 @@ class Arch_Check: 'ToolTip': QT_TRANSLATE_NOOP("Arch_Check","Checks the selected objects for problems")} def IsActive(self): - return bool(FreeCADGui.Selection.getSelection()) + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v and bool(FreeCADGui.Selection.getSelection()) def Activated(self): import Arch @@ -266,7 +274,8 @@ class Arch_Survey: 'ToolTip': QT_TRANSLATE_NOOP("Arch_Survey","Starts survey")} def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): FreeCADGui.addModule("Arch") @@ -282,7 +291,8 @@ class Arch_ToggleIfcBrepFlag: 'ToolTip': QT_TRANSLATE_NOOP("Arch_ToggleIfcBrepFlag","Force an object to be exported as Brep or not")} def IsActive(self): - return bool(FreeCADGui.Selection.getSelection()) + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v and bool(FreeCADGui.Selection.getSelection()) def Activated(self): import Arch @@ -300,7 +310,8 @@ class Arch_Component: 'ToolTip': QT_TRANSLATE_NOOP("Arch_Component","Creates an undefined architectural component")} def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): sel = FreeCADGui.Selection.getSelection() @@ -326,7 +337,8 @@ class Arch_CloneComponent: 'ToolTip': QT_TRANSLATE_NOOP("Arch_CloneComponent","Clones an object as an undefined architectural component")} def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): sel = FreeCADGui.Selection.getSelection() @@ -352,7 +364,8 @@ class Arch_IfcSpreadsheet: 'ToolTip': QT_TRANSLATE_NOOP("Arch_IfcSpreadsheet","Creates a spreadsheet to store IFC properties of an object.")} def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): sel = FreeCADGui.Selection.getSelection() @@ -378,7 +391,8 @@ class Arch_ToggleSubs: 'ToolTip' : QT_TRANSLATE_NOOP("Arch_ToggleSubs","Shows or hides the subcomponents of this object")} def IsActive(self): - return bool(FreeCADGui.Selection.getSelection()) + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v and bool(FreeCADGui.Selection.getSelection()) def Activated(self): import Draft @@ -421,7 +435,8 @@ class Arch_MergeWalls: toolbars. """ - return bool(FreeCADGui.Selection.getSelection()) + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v and bool(FreeCADGui.Selection.getSelection()) def Activated(self): """Executed when Arch MergeWalls is called. diff --git a/src/Mod/BIM/bimcommands/BimAxis.py b/src/Mod/BIM/bimcommands/BimAxis.py index 007da55178..debbcf3682 100644 --- a/src/Mod/BIM/bimcommands/BimAxis.py +++ b/src/Mod/BIM/bimcommands/BimAxis.py @@ -53,7 +53,8 @@ class Arch_Axis: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v @@ -88,7 +89,8 @@ class Arch_AxisSystem: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v class Arch_Grid: @@ -112,7 +114,8 @@ class Arch_Grid: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v class Arch_AxisTools: @@ -128,7 +131,8 @@ class Arch_AxisTools: } def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v diff --git a/src/Mod/BIM/bimcommands/BimBox.py b/src/Mod/BIM/bimcommands/BimBox.py index 38b8b3878f..86be3d1ba6 100644 --- a/src/Mod/BIM/bimcommands/BimBox.py +++ b/src/Mod/BIM/bimcommands/BimBox.py @@ -41,10 +41,8 @@ class BIM_Box: } def IsActive(self): - if FreeCAD.ActiveDocument: - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): import draftguitools.gui_trackers as DraftTrackers diff --git a/src/Mod/BIM/bimcommands/BimBuildingPart.py b/src/Mod/BIM/bimcommands/BimBuildingPart.py index ee1bf68658..3e12b6fdb1 100644 --- a/src/Mod/BIM/bimcommands/BimBuildingPart.py +++ b/src/Mod/BIM/bimcommands/BimBuildingPart.py @@ -47,7 +47,8 @@ class Arch_Level: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): @@ -75,7 +76,8 @@ class Arch_Building: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): diff --git a/src/Mod/BIM/bimcommands/BimClassification.py b/src/Mod/BIM/bimcommands/BimClassification.py index 035099883e..3ddebc50c5 100644 --- a/src/Mod/BIM/bimcommands/BimClassification.py +++ b/src/Mod/BIM/bimcommands/BimClassification.py @@ -46,10 +46,8 @@ class BIM_Classification: } def IsActive(self): - if FreeCAD.ActiveDocument: - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): import Draft diff --git a/src/Mod/BIM/bimcommands/BimConvert.py b/src/Mod/BIM/bimcommands/BimConvert.py index f04ca79804..86732c11cf 100644 --- a/src/Mod/BIM/bimcommands/BimConvert.py +++ b/src/Mod/BIM/bimcommands/BimConvert.py @@ -43,10 +43,8 @@ class BIM_Convert: } def IsActive(self): - if FreeCAD.ActiveDocument: - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): sel = FreeCADGui.Selection.getSelection() diff --git a/src/Mod/BIM/bimcommands/BimCurtainwall.py b/src/Mod/BIM/bimcommands/BimCurtainwall.py index 7d90138724..7dd821d0e1 100644 --- a/src/Mod/BIM/bimcommands/BimCurtainwall.py +++ b/src/Mod/BIM/bimcommands/BimCurtainwall.py @@ -46,7 +46,8 @@ class Arch_CurtainWall: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): diff --git a/src/Mod/BIM/bimcommands/BimCutPlane.py b/src/Mod/BIM/bimcommands/BimCutPlane.py index da650364f6..87eac714dc 100644 --- a/src/Mod/BIM/bimcommands/BimCutPlane.py +++ b/src/Mod/BIM/bimcommands/BimCutPlane.py @@ -43,7 +43,8 @@ class Arch_CutPlane: "ToolTip": QT_TRANSLATE_NOOP("Arch_CutPlane", "Cut an object with a plane")} def IsActive(self): - return len(FreeCADGui.Selection.getSelection()) > 1 + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v and len(FreeCADGui.Selection.getSelection()) > 1 def Activated(self): import ArchCutPlane diff --git a/src/Mod/BIM/bimcommands/BimDiff.py b/src/Mod/BIM/bimcommands/BimDiff.py index 20f8851479..41aa74b31d 100644 --- a/src/Mod/BIM/bimcommands/BimDiff.py +++ b/src/Mod/BIM/bimcommands/BimDiff.py @@ -40,10 +40,8 @@ class BIM_Diff: } def IsActive(self): - if FreeCAD.ActiveDocument: - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): # you need two documents open, containing BIM objects with same IDs diff --git a/src/Mod/BIM/bimcommands/BimEquipment.py b/src/Mod/BIM/bimcommands/BimEquipment.py index 85335bd7d7..8625b287a1 100644 --- a/src/Mod/BIM/bimcommands/BimEquipment.py +++ b/src/Mod/BIM/bimcommands/BimEquipment.py @@ -46,7 +46,8 @@ class Arch_Equipment: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): diff --git a/src/Mod/BIM/bimcommands/BimFence.py b/src/Mod/BIM/bimcommands/BimFence.py index 238ecf12ad..f603fc9e9c 100644 --- a/src/Mod/BIM/bimcommands/BimFence.py +++ b/src/Mod/BIM/bimcommands/BimFence.py @@ -41,7 +41,8 @@ class Arch_Fence: 'ToolTip': QT_TRANSLATE_NOOP("Arch_Fence", "Creates a fence object from a selected section, post and path")} def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): if len(FreeCADGui.Selection.getSelection()) != 3: diff --git a/src/Mod/BIM/bimcommands/BimFrame.py b/src/Mod/BIM/bimcommands/BimFrame.py index 4cf0c0fbf2..da946eb765 100644 --- a/src/Mod/BIM/bimcommands/BimFrame.py +++ b/src/Mod/BIM/bimcommands/BimFrame.py @@ -45,7 +45,8 @@ class Arch_Frame: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): diff --git a/src/Mod/BIM/bimcommands/BimGlue.py b/src/Mod/BIM/bimcommands/BimGlue.py index e82481976e..81f2534978 100644 --- a/src/Mod/BIM/bimcommands/BimGlue.py +++ b/src/Mod/BIM/bimcommands/BimGlue.py @@ -43,10 +43,8 @@ class BIM_Glue: } def IsActive(self): - if FreeCADGui.Selection.getSelection(): - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): import Part diff --git a/src/Mod/BIM/bimcommands/BimIfcElements.py b/src/Mod/BIM/bimcommands/BimIfcElements.py index 769818c309..123afb057b 100644 --- a/src/Mod/BIM/bimcommands/BimIfcElements.py +++ b/src/Mod/BIM/bimcommands/BimIfcElements.py @@ -45,13 +45,8 @@ class BIM_IfcElements: } def IsActive(self): - if FreeCAD.ActiveDocument: - # disable for pre-v0.18 - if float(FreeCAD.Version()[0] + "." + FreeCAD.Version()[1]) < 0.18: - return False - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): import Draft diff --git a/src/Mod/BIM/bimcommands/BimIfcProperties.py b/src/Mod/BIM/bimcommands/BimIfcProperties.py index 7d841b857b..01f8f98765 100644 --- a/src/Mod/BIM/bimcommands/BimIfcProperties.py +++ b/src/Mod/BIM/bimcommands/BimIfcProperties.py @@ -49,13 +49,8 @@ class BIM_IfcProperties: } def IsActive(self): - if FreeCAD.ActiveDocument: - # disable for pre-v0.18 - if float(FreeCAD.Version()[0] + "." + FreeCAD.Version()[1]) < 0.18: - return False - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): from PySide import QtCore, QtGui diff --git a/src/Mod/BIM/bimcommands/BimIfcQuantities.py b/src/Mod/BIM/bimcommands/BimIfcQuantities.py index 406c620f2c..65c3a60308 100644 --- a/src/Mod/BIM/bimcommands/BimIfcQuantities.py +++ b/src/Mod/BIM/bimcommands/BimIfcQuantities.py @@ -66,13 +66,8 @@ class BIM_IfcQuantities: } def IsActive(self): - if FreeCAD.ActiveDocument: - # disable for pre-v0.18 - if float(FreeCAD.Version()[0] + "." + FreeCAD.Version()[1]) < 0.18: - return False - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): from PySide import QtCore, QtGui diff --git a/src/Mod/BIM/bimcommands/BimImagePlane.py b/src/Mod/BIM/bimcommands/BimImagePlane.py index 040079e142..7859db5e9c 100644 --- a/src/Mod/BIM/bimcommands/BimImagePlane.py +++ b/src/Mod/BIM/bimcommands/BimImagePlane.py @@ -42,10 +42,8 @@ class BIM_ImagePlane: } def IsActive(self): - if FreeCAD.ActiveDocument: - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): import FreeCADGui diff --git a/src/Mod/BIM/bimcommands/BimMaterial.py b/src/Mod/BIM/bimcommands/BimMaterial.py index 5ac24b049c..cabf38bfa9 100644 --- a/src/Mod/BIM/bimcommands/BimMaterial.py +++ b/src/Mod/BIM/bimcommands/BimMaterial.py @@ -574,11 +574,8 @@ class Arch_Material: FreeCAD.ActiveDocument.recompute() def IsActive(self): - - if FreeCAD.ActiveDocument: - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v class Arch_MultiMaterial: @@ -609,11 +606,8 @@ class Arch_MultiMaterial: FreeCAD.ActiveDocument.recompute() def IsActive(self): - - if FreeCAD.ActiveDocument: - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v class Arch_MaterialToolsCommand: @@ -625,7 +619,8 @@ class Arch_MaterialToolsCommand: 'ToolTip': QT_TRANSLATE_NOOP("Arch_MaterialTools",'Material tools') } def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v FreeCADGui.addCommand("BIM_Material", BIM_Material()) diff --git a/src/Mod/BIM/bimcommands/BimPanel.py b/src/Mod/BIM/bimcommands/BimPanel.py index c703aa887a..4c50c63ae0 100644 --- a/src/Mod/BIM/bimcommands/BimPanel.py +++ b/src/Mod/BIM/bimcommands/BimPanel.py @@ -45,7 +45,8 @@ class Arch_Panel: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): @@ -236,7 +237,8 @@ class Arch_PanelCut: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): @@ -264,7 +266,8 @@ class Arch_PanelSheet: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): @@ -299,7 +302,8 @@ class Arch_Nest: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): @@ -468,7 +472,8 @@ class Arch_PanelGroup: } def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v FreeCADGui.addCommand('Arch_Panel',Arch_Panel()) diff --git a/src/Mod/BIM/bimcommands/BimPipe.py b/src/Mod/BIM/bimcommands/BimPipe.py index 86fa9b0cbf..08485cf752 100644 --- a/src/Mod/BIM/bimcommands/BimPipe.py +++ b/src/Mod/BIM/bimcommands/BimPipe.py @@ -45,7 +45,8 @@ class Arch_Pipe: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): @@ -83,7 +84,8 @@ class Arch_PipeConnector: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): @@ -117,7 +119,8 @@ class Arch_PipeGroupCommand: 'ToolTip': QT_TRANSLATE_NOOP("Arch_PipeTools",'Pipe tools') } def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v FreeCADGui.addCommand('Arch_Pipe',Arch_Pipe()) diff --git a/src/Mod/BIM/bimcommands/BimProfile.py b/src/Mod/BIM/bimcommands/BimProfile.py index 27cf3bc011..b0ccb8e360 100644 --- a/src/Mod/BIM/bimcommands/BimProfile.py +++ b/src/Mod/BIM/bimcommands/BimProfile.py @@ -45,7 +45,8 @@ class Arch_Profile: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): diff --git a/src/Mod/BIM/bimcommands/BimProject.py b/src/Mod/BIM/bimcommands/BimProject.py index f6482b67a5..b12c2cb214 100644 --- a/src/Mod/BIM/bimcommands/BimProject.py +++ b/src/Mod/BIM/bimcommands/BimProject.py @@ -42,7 +42,8 @@ class BIM_Project: } def IsActive(self): - return not hasattr(FreeCAD.ActiveDocument, "IfcFilePath") + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v and not hasattr(FreeCAD.ActiveDocument, "IfcFilePath") def Activated(self): from nativeifc import ifc_tools diff --git a/src/Mod/BIM/bimcommands/BimRebar.py b/src/Mod/BIM/bimcommands/BimRebar.py index c751c549bb..7ded89f404 100644 --- a/src/Mod/BIM/bimcommands/BimRebar.py +++ b/src/Mod/BIM/bimcommands/BimRebar.py @@ -45,7 +45,8 @@ class Arch_Rebar: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): diff --git a/src/Mod/BIM/bimcommands/BimReextrude.py b/src/Mod/BIM/bimcommands/BimReextrude.py index bbe293838f..b21f06a51a 100644 --- a/src/Mod/BIM/bimcommands/BimReextrude.py +++ b/src/Mod/BIM/bimcommands/BimReextrude.py @@ -43,10 +43,8 @@ class BIM_Reextrude: } def IsActive(self): - if FreeCADGui.Selection.getSelection(): - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): import Draft diff --git a/src/Mod/BIM/bimcommands/BimReference.py b/src/Mod/BIM/bimcommands/BimReference.py index 3939ba2c00..0a00ab5478 100644 --- a/src/Mod/BIM/bimcommands/BimReference.py +++ b/src/Mod/BIM/bimcommands/BimReference.py @@ -45,7 +45,8 @@ class Arch_Reference: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): diff --git a/src/Mod/BIM/bimcommands/BimRoof.py b/src/Mod/BIM/bimcommands/BimRoof.py index f1fceb5617..97e097be76 100644 --- a/src/Mod/BIM/bimcommands/BimRoof.py +++ b/src/Mod/BIM/bimcommands/BimRoof.py @@ -42,7 +42,8 @@ class Arch_Roof: "ToolTip" : QT_TRANSLATE_NOOP("Arch_Roof", "Creates a roof object from the selected wire.")} def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): import ArchComponent diff --git a/src/Mod/BIM/bimcommands/BimSchedule.py b/src/Mod/BIM/bimcommands/BimSchedule.py index 5c5313e74c..8018925232 100644 --- a/src/Mod/BIM/bimcommands/BimSchedule.py +++ b/src/Mod/BIM/bimcommands/BimSchedule.py @@ -49,10 +49,8 @@ class Arch_Schedule: self.taskd = ArchSchedule.ArchScheduleTaskPanel() def IsActive(self): - if FreeCAD.ActiveDocument: - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v FreeCADGui.addCommand('Arch_Schedule',Arch_Schedule()) diff --git a/src/Mod/BIM/bimcommands/BimSectionPlane.py b/src/Mod/BIM/bimcommands/BimSectionPlane.py index 8c2f2bab77..409b4379f8 100644 --- a/src/Mod/BIM/bimcommands/BimSectionPlane.py +++ b/src/Mod/BIM/bimcommands/BimSectionPlane.py @@ -45,7 +45,8 @@ class Arch_SectionPlane: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): diff --git a/src/Mod/BIM/bimcommands/BimSite.py b/src/Mod/BIM/bimcommands/BimSite.py index 263b6d1383..0fb487e83a 100644 --- a/src/Mod/BIM/bimcommands/BimSite.py +++ b/src/Mod/BIM/bimcommands/BimSite.py @@ -47,7 +47,8 @@ class Arch_Site: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): diff --git a/src/Mod/BIM/bimcommands/BimSketch.py b/src/Mod/BIM/bimcommands/BimSketch.py index 81444bdf56..355d1c4732 100644 --- a/src/Mod/BIM/bimcommands/BimSketch.py +++ b/src/Mod/BIM/bimcommands/BimSketch.py @@ -44,10 +44,8 @@ class BIM_Sketch: } def IsActive(self): - if FreeCAD.ActiveDocument: - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): from draftutils import params diff --git a/src/Mod/BIM/bimcommands/BimSlab.py b/src/Mod/BIM/bimcommands/BimSlab.py index 5d51bd3756..8a23ea471c 100644 --- a/src/Mod/BIM/bimcommands/BimSlab.py +++ b/src/Mod/BIM/bimcommands/BimSlab.py @@ -48,7 +48,8 @@ class BIM_Slab: } def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): import DraftTools diff --git a/src/Mod/BIM/bimcommands/BimSpace.py b/src/Mod/BIM/bimcommands/BimSpace.py index 0097206825..6fc25ffd7e 100644 --- a/src/Mod/BIM/bimcommands/BimSpace.py +++ b/src/Mod/BIM/bimcommands/BimSpace.py @@ -45,7 +45,8 @@ class Arch_Space: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): diff --git a/src/Mod/BIM/bimcommands/BimStairs.py b/src/Mod/BIM/bimcommands/BimStairs.py index 00e21f737e..a983ddbdc1 100644 --- a/src/Mod/BIM/bimcommands/BimStairs.py +++ b/src/Mod/BIM/bimcommands/BimStairs.py @@ -45,7 +45,8 @@ class Arch_Stairs: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): diff --git a/src/Mod/BIM/bimcommands/BimTDPage.py b/src/Mod/BIM/bimcommands/BimTDPage.py index 62d864282d..4e3d6f44d1 100644 --- a/src/Mod/BIM/bimcommands/BimTDPage.py +++ b/src/Mod/BIM/bimcommands/BimTDPage.py @@ -43,10 +43,8 @@ class BIM_TDPage: } def IsActive(self): - if FreeCAD.ActiveDocument: - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): from PySide import QtCore, QtGui diff --git a/src/Mod/BIM/bimcommands/BimTDView.py b/src/Mod/BIM/bimcommands/BimTDView.py index 17f491ad48..393e76bcce 100644 --- a/src/Mod/BIM/bimcommands/BimTDView.py +++ b/src/Mod/BIM/bimcommands/BimTDView.py @@ -43,10 +43,8 @@ class BIM_TDView: } def IsActive(self): - if FreeCAD.ActiveDocument: - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): import Draft diff --git a/src/Mod/BIM/bimcommands/BimTrash.py b/src/Mod/BIM/bimcommands/BimTrash.py index 4352b22ec6..dcc41318c7 100644 --- a/src/Mod/BIM/bimcommands/BimTrash.py +++ b/src/Mod/BIM/bimcommands/BimTrash.py @@ -66,11 +66,8 @@ class BIM_Trash: obj.ViewObject.hide() def IsActive(self): - if FreeCADGui.Selection.getSelection(): - return True - else: - return False - + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v FreeCADGui.addCommand("BIM_Trash", BIM_Trash()) diff --git a/src/Mod/BIM/bimcommands/BimTruss.py b/src/Mod/BIM/bimcommands/BimTruss.py index 2e6392ed6b..09d91e4c2f 100644 --- a/src/Mod/BIM/bimcommands/BimTruss.py +++ b/src/Mod/BIM/bimcommands/BimTruss.py @@ -45,7 +45,8 @@ class Arch_Truss: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): diff --git a/src/Mod/BIM/bimcommands/BimUnclone.py b/src/Mod/BIM/bimcommands/BimUnclone.py index 403863637e..d7a8e6242b 100644 --- a/src/Mod/BIM/bimcommands/BimUnclone.py +++ b/src/Mod/BIM/bimcommands/BimUnclone.py @@ -43,10 +43,8 @@ class BIM_Unclone: } def IsActive(self): - if FreeCADGui.Selection.getSelection(): - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): import Draft diff --git a/src/Mod/BIM/bimcommands/BimWPCommands.py b/src/Mod/BIM/bimcommands/BimWPCommands.py index ec993c252d..c998caf050 100644 --- a/src/Mod/BIM/bimcommands/BimWPCommands.py +++ b/src/Mod/BIM/bimcommands/BimWPCommands.py @@ -92,10 +92,8 @@ class BIM_WPView: } def IsActive(self): - if FreeCAD.ActiveDocument: - return True - else: - return False + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): done = False diff --git a/src/Mod/BIM/bimcommands/BimWall.py b/src/Mod/BIM/bimcommands/BimWall.py index eff94586d1..c3dc4bad7a 100644 --- a/src/Mod/BIM/bimcommands/BimWall.py +++ b/src/Mod/BIM/bimcommands/BimWall.py @@ -55,7 +55,8 @@ class Arch_Wall: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self): """Executed when Arch Wall is called. diff --git a/src/Mod/BIM/bimcommands/BimWindow.py b/src/Mod/BIM/bimcommands/BimWindow.py index d492b0aa29..a9ec5020a3 100644 --- a/src/Mod/BIM/bimcommands/BimWindow.py +++ b/src/Mod/BIM/bimcommands/BimWindow.py @@ -50,7 +50,8 @@ class Arch_Window: def IsActive(self): - return not FreeCAD.ActiveDocument is None + v = hasattr(FreeCADGui.getMainWindow().getActiveWindow(), "getSceneGraph") + return v def Activated(self):