added a property panel tab to the PyQt geom.app viewer that shows all properties from IfcPropertySets attached to the currently selected object

This commit is contained in:
jakob-beetz
2016-11-24 10:37:10 +01:00
committed by Thomas Krijnen
parent aec20057c7
commit 3ba2f781d8
@@ -165,6 +165,91 @@ class application(QtGui.QApplication):
self.connect(self, QtCore.SIGNAL("clicked(const QModelIndex &)"), self.clicked) self.connect(self, QtCore.SIGNAL("clicked(const QModelIndex &)"), self.clicked)
self.expandAll() self.expandAll()
class property_table(QtGui.QWidget):
instanceSelected = QtCore.pyqtSignal([object])
def __init__(self):
QtGui.QWidget.__init__(self)
self.layout= QtGui.QVBoxLayout(self)
self.setLayout(self.layout)
self.scroll = QtGui.QScrollArea(self)
self.layout.addWidget(self.scroll)
self.scroll.setWidgetResizable(True)
self.scrollContent = QtGui.QWidget(self.scroll)
self.scrollLayout = QtGui.QVBoxLayout(self.scrollContent)
self.scrollContent.setLayout(self.scrollLayout)
self.scroll.setWidget(self.scrollContent)
self.prop_dict = {}
#triggered by selection event in either component of parent
def select(self, product):
# Clear the old contents if any
while self.scrollLayout.count():
child = self.scrollLayout.takeAt(0)
if child is not None:
if child.widget() is not None:
child.widget().deleteLater()
self.scroll = QtGui.QScrollArea()
self.scroll.setWidgetResizable(True)
scrollContent = QtGui.QWidget(self.scroll)
# print ("properties for selection {}".format(self.prop_dict.get(str(product))))
prop_sets = self.prop_dict.get(str(product))
if prop_sets is not None:
for k,v in prop_sets.items():
group_box = QtGui.QGroupBox()
group_box.setTitle(k)
group_layout = QtGui.QVBoxLayout()
group_box.setLayout(group_layout)
for name, value in v.items():
prop_name = str(name)
value_str = value.wrappedValue
if isinstance(value_str,unicode):
value_str = value_str.encode('utf-8')
else:
value_str = str(value_str)
# print (value_str, type(value_str))
type_str = value.is_a()
label = QtGui.QLabel(prop_name+" : "+value_str+" : "+type_str)
group_layout.addWidget(label)
group_layout.addStretch()
self.scrollLayout.addWidget(group_box)
self.scrollLayout.addStretch()
else:
label = QtGui.QLabel("No IfcPropertySets asscociated with selected entity instance" )
self.scrollLayout.addWidget(label)
def load_file(self, f, **kwargs):
products = list(f.by_type("IfcProduct"))
for p in products:
propset_dict={}
try:
for is_def_by in p.IsDefinedBy:
if not is_def_by.is_a("IfcRelDefinesByProperties"): continue
if is_def_by.RelatingPropertyDefinition is not None:
prop_def=is_def_by.RelatingPropertyDefinition
prop_set_name = prop_def.Name
props = {}
if prop_def.is_a("IfcElementQuantity"):
for q in prop_def.Quantities:
if q.is_a("IfcPhysicalSimpleQuantity"):
props[q.Name]=q[3]
else:
for prop in prop_def.HasProperties:
if prop.is_a("IfcPropertySingleValue"):
props[prop.Name]=prop.NominalValue
propset_dict[prop_set_name]=props
except Exception, e:
print("failed to load properties: {}".format(e))
self.prop_dict[str(p)]=propset_dict
print ("property set dictionary has {} entries".format(len(propset_dict)))
class viewer(qtViewer3d): class viewer(qtViewer3d):
instanceSelected = QtCore.pyqtSignal([object]) instanceSelected = QtCore.pyqtSignal([object])
@@ -342,6 +427,7 @@ class application(QtGui.QApplication):
self.window = application.window() self.window = application.window()
self.tree = application.decomposition_treeview() self.tree = application.decomposition_treeview()
self.tree2 = application.type_treeview() self.tree2 = application.type_treeview()
self.propview = self.property_table()
self.canvas = application.viewer(self.window) self.canvas = application.viewer(self.window)
self.tabs = QtGui.QTabWidget() self.tabs = QtGui.QTabWidget()
self.window.resize(800, 600) self.window.resize(800, 600)
@@ -349,11 +435,12 @@ class application(QtGui.QApplication):
splitter.addWidget(self.tabs) splitter.addWidget(self.tabs)
self.tabs.addTab(self.tree, 'Decomposition') self.tabs.addTab(self.tree, 'Decomposition')
self.tabs.addTab(self.tree2, 'Types') self.tabs.addTab(self.tree2, 'Types')
self.tabs.addTab(self.propview, "Properties")
splitter.addWidget(self.canvas) splitter.addWidget(self.canvas)
splitter.setSizes([200,600]) splitter.setSizes([200,600])
self.window.setCentralWidget(splitter) self.window.setCentralWidget(splitter)
self.canvas.initialize() self.canvas.initialize()
self.components = [self.tree, self.tree2, self.canvas] self.components = [self.tree, self.tree2, self.canvas, self.propview]
self.files = {} self.files = {}
self.window.add_menu_item('File', '&Open', self.browse, shortcut='CTRL+O') self.window.add_menu_item('File', '&Open', self.browse, shortcut='CTRL+O')
@@ -363,6 +450,7 @@ class application(QtGui.QApplication):
self.tree.instanceSelected.connect(self.makeSelectionHandler(self.tree)) self.tree.instanceSelected.connect(self.makeSelectionHandler(self.tree))
self.tree2.instanceSelected.connect(self.makeSelectionHandler(self.tree2)) self.tree2.instanceSelected.connect(self.makeSelectionHandler(self.tree2))
self.canvas.instanceSelected.connect(self.makeSelectionHandler(self.canvas)) self.canvas.instanceSelected.connect(self.makeSelectionHandler(self.canvas))
self.propview.instanceSelected.connect(self.makeSelectionHandler(self.propview))
for t in [self.tree, self.tree2]: for t in [self.tree, self.tree2]:
t.instanceVisibilityChanged.connect(functools.partial(self.change_visibility, t)) t.instanceVisibilityChanged.connect(functools.partial(self.change_visibility, t))
t.instanceDisplayModeChanged.connect(functools.partial(self.change_displaymode, t)) t.instanceDisplayModeChanged.connect(functools.partial(self.change_displaymode, t))