mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-20 20:22:09 +00:00
Optimise the optimisation recipe. See #944.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
from collections import deque
|
||||
import ifcopenshell.util.element
|
||||
|
||||
class Patcher:
|
||||
def __init__(self, src, file, logger, args=None):
|
||||
self.src = src
|
||||
@@ -6,15 +9,27 @@ class Patcher:
|
||||
self.args = args
|
||||
|
||||
def patch(self):
|
||||
import ifcopenshell.util.element
|
||||
deleted = []
|
||||
hashes = {}
|
||||
for element in self.file:
|
||||
if element.is_a('IfcRoot'):
|
||||
continue
|
||||
h = hash(tuple(element))
|
||||
if h in hashes:
|
||||
for inverse in f.get_inverse(element):
|
||||
for inverse in self.file.get_inverse(element):
|
||||
ifcopenshell.util.element.replace_attribute(inverse, element, hashes[h])
|
||||
self.file.remove(element)
|
||||
deleted.append(element.id())
|
||||
else:
|
||||
hashes[h] = element
|
||||
deleted.sort()
|
||||
deleted_q = deque(deleted)
|
||||
new = ''
|
||||
for line in self.file.wrapped_data.to_string().split('\n'):
|
||||
try:
|
||||
if int(line.split('=')[0][1:]) != deleted_q[0]:
|
||||
new += (line + '\n')
|
||||
else:
|
||||
deleted_q.popleft()
|
||||
except:
|
||||
new += (line + '\n')
|
||||
self.file = new
|
||||
|
||||
Reference in New Issue
Block a user