From 053aca4bba0861e2a5af3e3db9c2815766306cef Mon Sep 17 00:00:00 2001 From: Tom Beach Date: Mon, 21 Oct 2024 10:12:32 +0100 Subject: [PATCH] Add Reset Cache --- src/cpp/geometry/IfcGeometryLoader.cpp | 11 +++++++++++ src/cpp/geometry/IfcGeometryLoader.h | 17 +++++++++-------- src/cpp/web-ifc-wasm.cpp | 4 ++++ src/ts/web-ifc-api.ts | 9 +++++++++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/cpp/geometry/IfcGeometryLoader.cpp b/src/cpp/geometry/IfcGeometryLoader.cpp index 8020816e..b51ed847 100644 --- a/src/cpp/geometry/IfcGeometryLoader.cpp +++ b/src/cpp/geometry/IfcGeometryLoader.cpp @@ -20,6 +20,17 @@ namespace webifc::geometry ReadLinearScalingFactor(); } + void IfcGeometryLoader::ResetCache() { + _relVoidRel = PopulateRelVoidsRelMap(); + _relVoids = PopulateRelVoidsMap(); + _relAggregates = PopulateRelAggregatesMap(); + _relNests = PopulateRelNestsMap(); + _relElementAggregates = PopulateRelElementAggregatesMap(); + _styledItems = PopulateStyledItemMap(); + _relMaterials = PopulateRelMaterialsMap(); + _materialDefinitions = PopulateMaterialDefinitionsMap(); + } + void IfcGeometryLoader::Clear() const{ _expressIDToPlacement.clear(); std::unordered_map().swap(_expressIDToPlacement); diff --git a/src/cpp/geometry/IfcGeometryLoader.h b/src/cpp/geometry/IfcGeometryLoader.h index 52199678..eb1cea27 100644 --- a/src/cpp/geometry/IfcGeometryLoader.h +++ b/src/cpp/geometry/IfcGeometryLoader.h @@ -26,6 +26,7 @@ namespace webifc::geometry { public: IfcGeometryLoader(const webifc::parsing::IfcLoader &loader,const webifc::schema::IfcSchemaManager &schemaManager,uint16_t circleSegments); + void ResetCache(); std::array GetAxis1Placement(const uint32_t expressID) const; glm::dmat3 GetAxis2Placement2D(const uint32_t expressID) const; glm::dmat4 GetLocalPlacement(const uint32_t expressID, glm::dvec3 vector = glm::dvec3(1)) const; @@ -70,14 +71,14 @@ namespace webifc::geometry std::vector ReadCurveIndices() const; const webifc::parsing::IfcLoader &_loader; const webifc::schema::IfcSchemaManager &_schemaManager; - const std::unordered_map> _relVoidRel; - const std::unordered_map> _relVoids; - const std::unordered_map> _relNests; - const std::unordered_map> _relAggregates; - const std::unordered_map> _relElementAggregates; - const std::unordered_map>> _styledItems; - const std::unordered_map>> _relMaterials; - const std::unordered_map>> _materialDefinitions; + std::unordered_map> _relVoidRel; + std::unordered_map> _relVoids; + std::unordered_map> _relNests; + std::unordered_map> _relAggregates; + std::unordered_map> _relElementAggregates; + std::unordered_map>> _styledItems; + std::unordered_map>> _relMaterials; + std::unordered_map>> _materialDefinitions; double _linearScalingFactor = 1; double _squaredScalingFactor = 1; double _cubicScalingFactor = 1; diff --git a/src/cpp/web-ifc-wasm.cpp b/src/cpp/web-ifc-wasm.cpp index 44bd18a6..d737442a 100644 --- a/src/cpp/web-ifc-wasm.cpp +++ b/src/cpp/web-ifc-wasm.cpp @@ -721,6 +721,10 @@ std::string DecodeText(std::string text) { return webifc::parsing::p21decode(strView); } +void ResetCache(uint32_t modelID) { + if (manager.IsModelOpen(modelID)) manager.GetGeometryProcessor(modelID)->GetLoader().ResetCache(); +} + EMSCRIPTEN_BINDINGS(my_module) { emscripten::class_("IfcGeometry") diff --git a/src/ts/web-ifc-api.ts b/src/ts/web-ifc-api.ts index 5819bf19..36fce819 100644 --- a/src/ts/web-ifc-api.ts +++ b/src/ts/web-ifc-api.ts @@ -1120,4 +1120,13 @@ export class IfcAPI { return this.wasmModule.DecodeText(text); } + /** + * Resets the Cached IFC Data - useful when changing the geometry of a model + * @param modelID Model handle retrieved by OpenModel + */ + + ResetCache(modelID: number) { + return this.wasmModule.DecodeText(modelID); + } + }