Skip to content

Commit

Permalink
Merge pull request #1080 from ThatOpen/CachceReset
Browse files Browse the repository at this point in the history
Add Reset Cache
  • Loading branch information
beachtom authored Oct 21, 2024
2 parents 0b947cc + 053aca4 commit 5928204
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/cpp/geometry/IfcGeometryLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t, glm::dmat4>().swap(_expressIDToPlacement);
Expand Down
17 changes: 9 additions & 8 deletions src/cpp/geometry/IfcGeometryLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<glm::dvec3,2> 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;
Expand Down Expand Up @@ -70,14 +71,14 @@ namespace webifc::geometry
std::vector<IfcSegmentIndexSelect> ReadCurveIndices() const;
const webifc::parsing::IfcLoader &_loader;
const webifc::schema::IfcSchemaManager &_schemaManager;
const std::unordered_map<uint32_t, std::vector<uint32_t>> _relVoidRel;
const std::unordered_map<uint32_t, std::vector<uint32_t>> _relVoids;
const std::unordered_map<uint32_t, std::vector<uint32_t>> _relNests;
const std::unordered_map<uint32_t, std::vector<uint32_t>> _relAggregates;
const std::unordered_map<uint32_t, std::vector<uint32_t>> _relElementAggregates;
const std::unordered_map<uint32_t, std::vector<std::pair<uint32_t, uint32_t>>> _styledItems;
const std::unordered_map<uint32_t, std::vector<std::pair<uint32_t, uint32_t>>> _relMaterials;
const std::unordered_map<uint32_t, std::vector<std::pair<uint32_t, uint32_t>>> _materialDefinitions;
std::unordered_map<uint32_t, std::vector<uint32_t>> _relVoidRel;
std::unordered_map<uint32_t, std::vector<uint32_t>> _relVoids;
std::unordered_map<uint32_t, std::vector<uint32_t>> _relNests;
std::unordered_map<uint32_t, std::vector<uint32_t>> _relAggregates;
std::unordered_map<uint32_t, std::vector<uint32_t>> _relElementAggregates;
std::unordered_map<uint32_t, std::vector<std::pair<uint32_t, uint32_t>>> _styledItems;
std::unordered_map<uint32_t, std::vector<std::pair<uint32_t, uint32_t>>> _relMaterials;
std::unordered_map<uint32_t, std::vector<std::pair<uint32_t, uint32_t>>> _materialDefinitions;
double _linearScalingFactor = 1;
double _squaredScalingFactor = 1;
double _cubicScalingFactor = 1;
Expand Down
4 changes: 4 additions & 0 deletions src/cpp/web-ifc-wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_<webifc::geometry::IfcGeometry>("IfcGeometry")
Expand Down
9 changes: 9 additions & 0 deletions src/ts/web-ifc-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 5928204

Please sign in to comment.