From 9daf2d712cd6e142608a25a9c2b1bff7caaa2412 Mon Sep 17 00:00:00 2001 From: andreas Date: Mon, 11 Mar 2024 19:09:33 +0100 Subject: [PATCH] Bauteile fehlen - Number of erroneous files: xxx http://bitnami/issues/7926 --- .../geometry/StreamingGeometryGenerator.java | 132 ++++++++++++------ 1 file changed, 88 insertions(+), 44 deletions(-) diff --git a/BimServer/src/org/bimserver/geometry/StreamingGeometryGenerator.java b/BimServer/src/org/bimserver/geometry/StreamingGeometryGenerator.java index 0f7baf6165..86f6ef3057 100644 --- a/BimServer/src/org/bimserver/geometry/StreamingGeometryGenerator.java +++ b/BimServer/src/org/bimserver/geometry/StreamingGeometryGenerator.java @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -571,52 +572,10 @@ public GenerateGeometryResult generateGeometry(long uoid, final DatabaseSession Include representationsInclude2 = rInclude.createInclude(); representationsInclude2.addType(packageMetaData.getEClass("IfcShapeModel"), true); representationsInclude2.addFieldDirect("ContextOfItems"); - - Query query = new Query("Main " + eClass.getName(), packageMetaData); - query.setDoubleBuffer(true); - QueryPart queryPart = query.createQueryPart(); - int written = 0; QueryObjectProvider queryObjectProvider2 = new QueryObjectProvider(databaseSession, bimServer, query3, Collections.singleton(queryContext.getRoid()), packageMetaData); - HashMapVirtualObject next = queryObjectProvider2.next(); - - Set representationOids = new HashSet<>(); - while (next != null) { - // Not sure why the duplicate code in the next 20 lines - if (next.eClass() == eClass && !done.contains(next.getOid()) && !toSkip.contains(next.getOid())) { - AbstractHashMapVirtualObject representation = next.getDirectFeature(representationFeature); - if (representation != null) { - Set list = representation.getDirectListFeature(packageMetaData.getEReference("IfcProductRepresentation", "Representations")); - Set goForIt = goForIt(list); - if (!goForIt.isEmpty()) { - if (next.eClass() == eClass && !done.contains(next.getOid())) { - representation = next.getDirectFeature(representationFeature); - if (representation != null) { - list = representation.getDirectListFeature(packageMetaData.getEReference("IfcProductRepresentation", "Representations")); - Set goForIt2 = goForIt(list); - if (!goForIt2.isEmpty()) { - queryPart.addOid(next.getOid()); - representationOids.addAll(goForIt2); - written++; - if (written >= maxObjectsPerFile) { - processQuery(databaseSession, queryContext, generateGeometryResult, ifcSerializerPlugin, settings, renderEngineFilter, renderEnginePool, executor, eClass, query, queryPart, false, null, written, representationOids); - query = new Query("Main " + eClass.getName(), packageMetaData); - query.setDoubleBuffer(true); - queryPart = query.createQueryPart(); - written = 0; - representationOids.clear(); - } - } - } - } - } - } - } - next = queryObjectProvider2.next(); - } - if (written > 0) { - processQuery(databaseSession, queryContext, generateGeometryResult, ifcSerializerPlugin, settings, renderEngineFilter, renderEnginePool, executor, eClass, query, queryPart, false, null, written, representationOids); - } + Map> mappedProducts = mapProducts(queryObjectProvider2, done, toSkip, eClass); + processProducts(mappedProducts, eClass, maxObjectsPerFile, databaseSession, queryContext, generateGeometryResult, ifcSerializerPlugin, settings, renderEngineFilter, renderEnginePool, executor, reuseGeometry, maxObjectsPerFile); } allJobsPushed = true; @@ -922,6 +881,91 @@ private float processUnits(DatabaseSession databaseSession, QueryContext queryCo // Assume meters, we need to multiply by 1000 return 1000f; } + + private String getRepresentationKey(Set list) { + StringBuilder representationKey = new StringBuilder(128); + for (HashMapVirtualObject representationItem : list) { + representationKey.append(representationItem.get("RepresentationType")).append(";"); + } + + return representationKey.toString(); + } + + private Map> mapProducts(QueryObjectProvider queryObjectProvider, Set done, Set toSkip, EClass eClass) throws BimserverDatabaseException { + Map> mappedProducts = new HashMap<>(); + + HashMapVirtualObject next = queryObjectProvider.next(); + + while (next != null) { + if (next.eClass() != eClass || done.contains(next.getOid()) || toSkip.contains(next.getOid())) { + next = queryObjectProvider.next(); + continue; + } + + AbstractHashMapVirtualObject representation = next.getDirectFeature(representationFeature); + if (representation == null) { + next = queryObjectProvider.next(); + continue; + } + + Set list = representation.getDirectListFeature(packageMetaData.getEReference("IfcProductRepresentation", "Representations")); + String key = getRepresentationKey(list); + + List products = mappedProducts.get(key); + if(products == null) { + products = new LinkedList<>(); + mappedProducts.put(key, products); + } + + products.add(next); + + next = queryObjectProvider.next(); + } + + return mappedProducts; + } + + private void processProducts(Map> mappedProducts, EClass eClass, int maxObjectsPerFile, final DatabaseSession databaseSession, + QueryContext queryContext, GenerateGeometryResult generateGeometryResult, final StreamingSerializerPlugin ifcSerializerPlugin, + final RenderEngineSettings settings, final RenderEngineFilter renderEngineFilter, RenderEnginePool renderEnginePool, ThreadPoolExecutor executor, + boolean geometryReused, int nrObjects) throws QueryException, IOException { + for(List products : mappedProducts.values()) { + int written = 0; + + Query query = new Query("Main " + eClass.getName(), packageMetaData); + query.setDoubleBuffer(true); + QueryPart queryPart = query.createQueryPart(); + + Set representationOids = new HashSet<>(); + + for(HashMapVirtualObject product : products) { + AbstractHashMapVirtualObject representation = product.getDirectFeature(representationFeature); + Set list = representation.getDirectListFeature(packageMetaData.getEReference("IfcProductRepresentation", "Representations")); + Set goForIt = goForIt(list); + if (goForIt.isEmpty()) { + continue; + } + + queryPart.addOid(product.getOid()); + representationOids.addAll(goForIt); + written++; + if (written < maxObjectsPerFile) { + continue; + } + + processQuery(databaseSession, queryContext, generateGeometryResult, ifcSerializerPlugin, settings, renderEngineFilter, renderEnginePool, executor, eClass, query, queryPart, false, null, written, representationOids); + query = new Query("Main " + eClass.getName(), packageMetaData); + query.setDoubleBuffer(true); + queryPart = query.createQueryPart(); + written = 0; + representationOids.clear(); + } + + if (written > 0) { + processQuery(databaseSession, queryContext, generateGeometryResult, ifcSerializerPlugin, settings, renderEngineFilter, renderEnginePool, executor, eClass, query, queryPart, false, null, written, representationOids); + } + } + } private Set goForIt(Set list) { Set representationOids = new HashSet<>();