From 3202174903d9fa7b21f2a83b16b3811d6c68b970 Mon Sep 17 00:00:00 2001 From: Manuel Date: Wed, 18 Nov 2020 22:10:28 +0100 Subject: [PATCH] Attempt for compatibility with PythonOCC 7.4.1 Used import statement from occ_utils.py added an If-Statement to the GetObject()-call. Calling SetSelectionPriority directly on ais, as proposed by aothms (https://github.com/IfcOpenShell/IfcOpenShell/issues/1098) did not work. Could load some ifc-models but needs further testing. --- .../ifcopenshell/geom/app.py | 60 +++++++++++-------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/geom/app.py b/src/ifcopenshell-python/ifcopenshell/geom/app.py index 8eedc41ec8..43d5762584 100644 --- a/src/ifcopenshell-python/ifcopenshell/geom/app.py +++ b/src/ifcopenshell-python/ifcopenshell/geom/app.py @@ -9,7 +9,14 @@ import operator import functools import multiprocessing -import OCC.AIS +try: + from OCC.Core import AIS + + USE_OCCT_HANDLE = False +except ImportError: + from OCC import AIS + + USE_OCCT_HANDLE = True from collections import defaultdict, OrderedDict @@ -426,30 +433,30 @@ class application(QtWidgets.QApplication): instanceSelected = QtCore.pyqtSignal([object]) - @staticmethod - def ais_to_key(ais_handle): - def yield_shapes(): - ais = ais_handle.GetObject() - if hasattr(ais, "Shape"): - yield ais.Shape() - return - shp = OCC.AIS.Handle_AIS_Shape.DownCast(ais_handle) - if not shp.IsNull(): - yield shp.Shape() - return - mult = ais_handle - if mult.IsNull(): - shp = OCC.AIS.Handle_AIS_Shape.DownCast(ais_handle) - if not shp.IsNull(): - yield shp - else: - li = mult.GetObject().ConnectedTo() - for i in range(li.Length()): - shp = OCC.AIS.Handle_AIS_Shape.DownCast(li.Value(i + 1)) - if not shp.IsNull(): - yield shp +# @staticmethod +# def ais_to_key(ais_handle): +# def yield_shapes(): +# ais = ais_handle.GetObject() +# if hasattr(ais, "Shape"): +# yield ais.Shape() +# return +# shp = OCC.AIS.Handle_AIS_Shape.DownCast(ais_handle) +# if not shp.IsNull(): +# yield shp.Shape() +# return +# mult = ais_handle +# if mult.IsNull(): +# shp = OCC.AIS.Handle_AIS_Shape.DownCast(ais_handle) +# if not shp.IsNull(): +# yield shp +# else: +# li = mult.GetObject().ConnectedTo() +# for i in range(li.Length()): +# shp = OCC.AIS.Handle_AIS_Shape.DownCast(li.Value(i + 1)) +# if not shp.IsNull(): +# yield shp - return tuple(shp.HashCode(1 << 24) for shp in yield_shapes()) +# return tuple(shp.HashCode(1 << 24) for shp in yield_shapes()) def __init__(self, widget): qtViewer3d.__init__(self, widget) @@ -479,8 +486,9 @@ class application(QtWidgets.QApplication): for shape in shapes: ais = display_shape(shape, viewer_handle=v) product = f[shape.data.id] - - ais.GetObject().SetSelectionPriority(self.counter) + + if USE_OCCT_HANDLE: + ais.GetObject().SetSelectionPriority(self.counter) self.ais_to_product[self.counter] = product self.product_to_ais[product] = ais self.counter += 1