From b382938e9facfed61befb644d8d8b7b185d3babe Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 7 Mar 2024 11:14:04 +0100 Subject: [PATCH] Introduced double-click to expand and load shape --- ifc_viewproviders.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/ifc_viewproviders.py b/ifc_viewproviders.py index aac95de..547712c 100644 --- a/ifc_viewproviders.py +++ b/ifc_viewproviders.py @@ -158,6 +158,7 @@ def expandChildren(self, obj=None): """Creates children of this object""" import ifc_tools # lazy import + from PySide import QtCore, QtGui if not obj: obj = self.Object @@ -168,6 +169,19 @@ def expandChildren(self, obj=None): obj, ifcfile, recursive=False, assemblies=True, expand=False ) obj.Document.recompute() + + # expand the item in the tree view + mw = FreeCADGui.getMainWindow() + tree = mw.findChild(QtGui.QDockWidget,"Model") + model = tree.findChild(QtGui.QWidget,"Model") + splitter = model.findChild(QtGui.QSplitter) + tree = splitter.children()[1].children()[0] + it = tree.findItems(obj.Label, QtCore.Qt.MatchRecursive, 0) + if it: + it[0].setExpanded(True) + for i in range(it[0].childCount()): + it[0].child(i).setExpanded(True) + return nc def collapseChildren(self): @@ -317,6 +331,35 @@ def createGroup(self): ifc_tools.aggregate(group, self.Object) self.Object.Document.recompute() + def doubleClicked(self, vobj): + """Expands everything that needs to be expanded""" + + import ifc_geometry # lazy import + import ifc_tools # lazy import + import ifc_psets # lazy import + import ifc_materials # lazy import + import ifc_layers # lazy import + + # generic data loading + ifc_geometry.add_geom_properties(vobj.Object) + ifc_psets.show_psets(vobj.Object) + ifc_materials.show_material(vobj.Object) + ifc_layers.add_layers(vobj.Object) + + # expand children + if self.hasChildren(vobj.Object): + self.expandChildren() + return True + + # load shape + element = ifc_tools.get_ifc_element(vobj.Object) + if ifc_tools.has_representation(element): + if vobj.Object.ShapeMode != "Shape": + vobj.Object.ShapeMode = "Shape" + vobj.Object.Document.recompute() + return True + return None + class ifc_vp_document(ifc_vp_object): """View provider for the IFC document object"""