mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
Speed up geometry generation in ifcopenshell.geom.application by using iterator
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import operator
|
import operator
|
||||||
@@ -5,8 +7,6 @@ import functools
|
|||||||
|
|
||||||
import OCC.AIS
|
import OCC.AIS
|
||||||
|
|
||||||
import ifcopenshell
|
|
||||||
|
|
||||||
from collections import defaultdict, Iterable
|
from collections import defaultdict, Iterable
|
||||||
|
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
@@ -24,9 +24,11 @@ except:
|
|||||||
from OCC.Display.qtDisplay import qtViewer3d
|
from OCC.Display.qtDisplay import qtViewer3d
|
||||||
|
|
||||||
|
|
||||||
from .main import create_shape, settings
|
from .main import settings, iterator
|
||||||
from .occ_utils import display_shape
|
from .occ_utils import display_shape
|
||||||
|
|
||||||
|
from .. import open, get_supertype
|
||||||
|
|
||||||
# Depending on Python version and what not there may or may not be a QString
|
# Depending on Python version and what not there may or may not be a QString
|
||||||
try:
|
try:
|
||||||
from PyQt4.QtCore import QString
|
from PyQt4.QtCore import QString
|
||||||
@@ -144,7 +146,7 @@ class application(QtGui.QApplication):
|
|||||||
items = {}
|
items = {}
|
||||||
for t in types:
|
for t in types:
|
||||||
def add(t):
|
def add(t):
|
||||||
s = ifcopenshell.get_supertype(t)
|
s = get_supertype(t)
|
||||||
if s: add(s)
|
if s: add(s)
|
||||||
s2, t2 = map(QString, (s,t))
|
s2, t2 = map(QString, (s,t))
|
||||||
if t2 not in items:
|
if t2 not in items:
|
||||||
@@ -218,21 +220,37 @@ class application(QtGui.QApplication):
|
|||||||
terminate = [False]
|
terminate = [False]
|
||||||
self.window.window_closed.connect(lambda *args: operator.setitem(terminate, 0, True))
|
self.window.window_closed.connect(lambda *args: operator.setitem(terminate, 0, True))
|
||||||
|
|
||||||
for p in f.by_type("IfcProduct"):
|
t0 = time.time()
|
||||||
|
|
||||||
|
it = iterator(setting, f)
|
||||||
|
if not it.initialize():
|
||||||
|
return
|
||||||
|
|
||||||
|
old_progress = -1
|
||||||
|
while True:
|
||||||
if terminate[0]: break
|
if terminate[0]: break
|
||||||
if p.Representation is None: continue
|
shape = it.get()
|
||||||
shape = create_shape(setting, p)
|
product = f[shape.data.id]
|
||||||
ais = display_shape(shape, viewer_handle=v)
|
ais = display_shape(shape, viewer_handle=v)
|
||||||
ais.GetObject().SetSelectionPriority(self.counter)
|
ais.GetObject().SetSelectionPriority(self.counter)
|
||||||
self.ais_to_product[self.counter] = p
|
self.ais_to_product[self.counter] = product
|
||||||
self.product_to_ais[p] = ais
|
self.product_to_ais[product] = ais
|
||||||
self.counter += 1
|
self.counter += 1
|
||||||
QtGui.QApplication.processEvents()
|
QtGui.QApplication.processEvents()
|
||||||
if p.is_a() in {'IfcSpace', 'IfcOpeningElement'}:
|
if product.is_a() in {'IfcSpace', 'IfcOpeningElement'}:
|
||||||
v.Context.Erase(ais, True)
|
v.Context.Erase(ais, True)
|
||||||
update(0.1)
|
progress = it.progress() // 2
|
||||||
|
if progress > old_progress:
|
||||||
|
print("\r[" + "#" * progress + " " * (50 - progress) + "]", end="")
|
||||||
|
old_progress = progress
|
||||||
|
if not it.next():
|
||||||
|
break
|
||||||
|
update(0.2)
|
||||||
|
|
||||||
|
print("\rOpened file in %.2f seconds%s" % (time.time() - t0, " "*25))
|
||||||
|
|
||||||
update()
|
update()
|
||||||
|
|
||||||
def select(self, product):
|
def select(self, product):
|
||||||
ais = self.product_to_ais.get(product)
|
ais = self.product_to_ais.get(product)
|
||||||
if ais is None: return
|
if ais is None: return
|
||||||
@@ -374,7 +392,7 @@ class application(QtGui.QApplication):
|
|||||||
|
|
||||||
def load(self, fn):
|
def load(self, fn):
|
||||||
if fn in self.files: return
|
if fn in self.files: return
|
||||||
f = ifcopenshell.open(fn)
|
f = open(fn)
|
||||||
self.files[fn] = f
|
self.files[fn] = f
|
||||||
for c in self.components:
|
for c in self.components:
|
||||||
c.load_file(f, setting=self.settings)
|
c.load_file(f, setting=self.settings)
|
||||||
|
|||||||
Reference in New Issue
Block a user