From b9d7cd23a97af4120780960f58f0f54dbe91f596 Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Mon, 4 Nov 2024 13:02:07 +0000 Subject: [PATCH] BIM: IFC explorer Qt 6 compatibility and other fixes (#17649) * BIM: IFC - Fixes for Qt 6 due to QtGui.QFont.setWeight() PySide6 replaced: PySide6.QtGui.QFont.setWeight(int) with: PySide6.QtGui.QFont.setWeight(PySide6.QtGui.QFont.Weight) * BIM: Fix IFC explorer addEntity() and addProperties() on Qt 6 Qt 6 removed QTreeWidget.setFirstItemColumnSpanned() https://doc.qt.io/qt-5/qtreewidget-obsolete.html#setFirstItemColumnSpanned Running the Python command 'BIM_IfcExplorer' failed: Traceback (most recent call last): File "/usr/lib64/freecad/Mod/BIM/bimcommands/BimIfcExplorer.py", line 170, in Activated self.open() File "/usr/lib64/freecad/Mod/BIM/bimcommands/BimIfcExplorer.py", line 223, in open self.addEntity(eid, children, self.tree) File "/usr/lib64/freecad/Mod/BIM/bimcommands/BimIfcExplorer.py", line 455, in addEntity self.tree.setFirstItemColumnSpanned(item, True) * BIM: Fix IFC explorer exception on toggle mesh Traceback (most recent call last): File "/usr/lib64/freecad/Mod/BIM/bimcommands/BimIfcExplorer.py", line 278, in toggleMesh import importIFCHelper ModuleNotFoundError: No module named 'importIFCHelper' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib64/freecad/Mod/BIM/bimcommands/BimIfcExplorer.py", line 282, in toggleMesh import importIFC ModuleNotFoundError: No module named 'importIFC' * BIM: Fix IFC explorer layout warnings QLayout: Attempting to add QLayout "" to QDialog "IfcExplorer", which already has a layout QLayout: Attempting to add QLayout "" to QDialog "IfcExplorer", which already has a layout https://doc.qt.io/qt-6/qtwidgets-tutorials-widgets-nestedlayouts-example.html * BIM: Output an error if IFC explorer can't explore a file --------- Co-authored-by: Roy-043 --- src/Mod/BIM/bimcommands/BimIfcExplorer.py | 27 ++++++++++++++++------- src/Mod/BIM/importers/importIFClegacy.py | 1 - 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Mod/BIM/bimcommands/BimIfcExplorer.py b/src/Mod/BIM/bimcommands/BimIfcExplorer.py index 829ca4d1cb..47c5ee976c 100644 --- a/src/Mod/BIM/bimcommands/BimIfcExplorer.py +++ b/src/Mod/BIM/bimcommands/BimIfcExplorer.py @@ -60,7 +60,6 @@ class BIM_IfcExplorer: # setting up a font self.bold = QtGui.QFont() - self.bold.setWeight(75) self.bold.setBold(True) # setting up a link fint @@ -108,15 +107,16 @@ class BIM_IfcExplorer: self.dialog.resize(720, 540) toolbar = FreeCADGui.UiLoader().createWidget("Gui::ToolBar") - layout = QtGui.QVBoxLayout(self.dialog) + layout = QtGui.QVBoxLayout() layout.addWidget(toolbar) - hlayout = QtGui.QHBoxLayout(self.dialog) + hlayout = QtGui.QHBoxLayout() hlayout.addWidget(self.tree) layout.addLayout(hlayout) - vlayout = QtGui.QVBoxLayout(self.dialog) + vlayout = QtGui.QVBoxLayout() hlayout.addLayout(vlayout) vlayout.addWidget(self.attributes) vlayout.addWidget(self.properties) + self.dialog.setLayout(layout) # draw the toolbar buttons self.openAction = QtGui.QAction(translate("BIM", "Open"), None) @@ -217,6 +217,17 @@ class BIM_IfcExplorer: self.ifc = ifcopenshell.open(self.filename) root = self.getEntitiesTree() + # unable to find IfcSite + if not root: + FreeCAD.Console.PrintError( + translate( + "BIM", + "IfcSite element was not found in %s. Unable to explore.", + ) + % self.filename + "\n" + ) + return + # populate tree contents for eid, children in root.items(): self.addEntity(eid, children, self.tree) @@ -274,11 +285,11 @@ class BIM_IfcExplorer: self.mesh.ViewObject.show() else: try: - import importIFCHelper + from importers import importIFCHelper s = importIFCHelper.getScaling(self.ifc) except: - import importIFC + from importers import importIFC s = importIFC.getScaling(self.ifc) s *= 1000 # ifcopenshell outputs its meshes in metres @@ -451,7 +462,7 @@ class BIM_IfcExplorer: item.setIcon(0, QtGui.QIcon(":icons/Arch_Rebar.svg")) elif entity.is_a("IfcProduct"): item.setIcon(0, QtGui.QIcon(":icons/Arch_Component.svg")) - self.tree.setFirstItemColumnSpanned(item, True) + item.setFirstColumnSpanned(True) item.setData(0, QtCore.Qt.UserRole, eid) for childid, grandchildren in children.items(): self.addEntity(childid, grandchildren, item) @@ -558,7 +569,7 @@ class BIM_IfcExplorer: + self.tostr(rel.RelatingPropertyDefinition.Name), ) item.setFont(0, self.bold) - self.properties.setFirstItemColumnSpanned(item, True) + item.setFirstColumnSpanned(True) if hasattr(rel.RelatingPropertyDefinition, "HasProperties"): for prop in rel.RelatingPropertyDefinition.HasProperties: subitem = QtGui.QTreeWidgetItem(item) diff --git a/src/Mod/BIM/importers/importIFClegacy.py b/src/Mod/BIM/importers/importIFClegacy.py index ab4dee52cb..ebf4841376 100644 --- a/src/Mod/BIM/importers/importIFClegacy.py +++ b/src/Mod/BIM/importers/importIFClegacy.py @@ -1793,7 +1793,6 @@ def explorer(filename,schema="IFC2X3_TC1.exp"): tree.headerItem().setText(1, "") tree.headerItem().setText(2, "Item and Properties") bold = QtGui.QFont() - bold.setWeight(75) bold.setBold(True) #print(ifc.Entities)