Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
beachtom committed Nov 12, 2024
1 parent 6633d74 commit 2c76b8b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 70 deletions.
78 changes: 28 additions & 50 deletions src/cpp/parsing/IfcLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace webifc::parsing {
IfcLoader::IfcLoader(uint32_t tapeSize, uint32_t memoryLimit,uint32_t lineWriterBuffer, const schema::IfcSchemaManager &schemaManager) :_lineWriterBuffer(lineWriterBuffer), _schemaManager(schemaManager)
{
_tokenStream = new IfcTokenStream(tapeSize,memoryLimit/tapeSize);
_maxExpressId=0;
}

const std::vector<uint32_t> IfcLoader::GetExpressIDsWithType(const uint32_t type) const
Expand Down Expand Up @@ -218,7 +219,6 @@ namespace webifc::parsing {

void IfcLoader::ParseLines()
{
uint32_t maxExpressId = 0;
uint32_t currentIfcType = 0;
uint32_t currentExpressID = 0;
uint32_t currentTapeOffset = 0;
Expand All @@ -241,8 +241,8 @@ namespace webifc::parsing {
else if (currentExpressID != 0)
{
_ifcTypeToExpressID[currentIfcType].push_back(currentExpressID);
maxExpressId = std::max(maxExpressId, currentExpressID);
_lines[currentExpressID-1]=l;
_maxExpressId = std::max(_maxExpressId, currentExpressID);
_lines[currentExpressID]=l;
currentExpressID = 0;
}
currentIfcType = 0;
Expand Down Expand Up @@ -284,39 +284,37 @@ namespace webifc::parsing {

uint32_t IfcLoader::GetMaxExpressId() const
{
return _lines.size();
return _maxExpressId;
}

bool IfcLoader::IsValidExpressID(const uint32_t expressID) const
{
if (expressID == 0 || expressID > _lines.size() || !_lines.contains(expressID-1)) return false;
if (expressID == 0 || expressID > _maxExpressId || !_lines.contains(expressID)) return false;
else return true;
}

uint32_t IfcLoader::GetLineType(const uint32_t expressID) const
{
if (expressID == 0 || expressID > _lines.size()) {
if (expressID == 0 || expressID > _maxExpressId || !_lines.contains(expressID)) {
spdlog::error("[GetLineType()] Attempt to Access Invalid ExpressID {}", expressID);
return 0;
}
return _lines.at(expressID-1)->ifcType;
return _lines.at(expressID)->ifcType;
}

IfcLoader::~IfcLoader()
{
delete _tokenStream;
for (size_t i=0; i < _lines.size();i++) {
if (!_lines.contains(i)) continue;
delete _lines[i];
}
for (const auto & [key, value] : _lines) delete value;
for (size_t i=0; i < _headerLines.size();i++) delete _headerLines[i];
_lines.clear();
_headerLines.clear();
}

void IfcLoader::MoveToLineArgument(const uint32_t expressID, const uint32_t argumentIndex) const
{
_tokenStream->MoveTo(_lines.at(expressID-1)->tapeOffset);
if (!_lines.contains(expressID)) return;
_tokenStream->MoveTo(_lines.at(expressID)->tapeOffset);
ArgumentOffset(argumentIndex);
}

Expand Down Expand Up @@ -385,15 +383,13 @@ namespace webifc::parsing {
uint32_t IfcLoader::GetCurrentLineExpressID() const
{
if (_lines.size()==0) return 0;
uint32_t pos = _tokenStream->GetReadOffset();
uint32_t prevLine = 0;
for (size_t i=0; i < _lines.size();i++)
{
if (!_lines.contains(i)) continue;
if (_lines.at(i)->tapeOffset > pos) break;
prevLine = i;
uint32_t pos = _tokenStream->GetReadOffset();
for (const auto & [key, value] : _lines) {
if (value->tapeOffset > pos) break;
prevLine = key;
}
return prevLine+1;
return prevLine;
}

uint32_t IfcLoader::GetRefArgument() const
Expand All @@ -420,28 +416,24 @@ namespace webifc::parsing {

void IfcLoader::RemoveLine(const uint32_t expressID)
{
_lines[expressID-1]->ifcType = 0;
}

void IfcLoader::ExtendLineStorage(uint32_t lineStorageSize)
{
_lines.reserve(_lines.size()+lineStorageSize);
_lines.erase(expressID);
}

void IfcLoader::UpdateLineTape(const uint32_t expressID, const uint32_t type, const uint32_t start)
{
if (expressID > _lines.size())
if (!_lines.contains(expressID))
{
// create line object
IfcLine * line = new IfcLine();
// fill line data
line->ifcType = type;
line->tapeOffset = start;
//place in vector
_lines[expressID-1]=line;
_lines[expressID]=line;
_ifcTypeToExpressID[type].push_back(expressID);
if (expressID > _maxExpressId) _maxExpressId=expressID;

} else _lines[expressID-1]->tapeOffset = start;
} else _lines[expressID]->tapeOffset = start;
}

void IfcLoader::AddHeaderLineTape(const uint32_t type, const uint32_t start)
Expand Down Expand Up @@ -653,8 +645,10 @@ namespace webifc::parsing {

void IfcLoader::MoveToArgumentOffset(const uint32_t expressID, const uint32_t argumentIndex) const
{
_tokenStream->MoveTo(_lines.at(expressID-1)->tapeOffset);
ArgumentOffset(argumentIndex);
if (_lines.contains(expressID)) {
_tokenStream->MoveTo(_lines.at(expressID)->tapeOffset);
ArgumentOffset(argumentIndex);
}
}

void IfcLoader::StepBack() const {
Expand All @@ -680,30 +674,14 @@ namespace webifc::parsing {

std::vector<uint32_t> IfcLoader::GetAllLines() const {
std::vector<uint32_t> expressIDs;
auto numLines = GetMaxExpressId();
for (uint32_t i = 1; i <= numLines; i++)
{
if (!IsValidExpressID(i)) continue;
expressIDs.push_back(i);
}
std::transform( _lines.begin(), _lines.end(), std::back_inserter( expressIDs ), [](auto &kv){ return kv.first;} );
return expressIDs;
}

uint32_t IfcLoader::GetNextExpressID(uint32_t expressId) const {
uint32_t currentId = expressId;
bool cont = true;
uint32_t maxId = GetMaxExpressId();

while(cont)
{
if(currentId > maxId)
{
cont = false;
continue;
}
currentId++;
cont = !(IsValidExpressID(currentId));
}
uint32_t currentId = expressId+1;
while(!_lines.contains(currentId)) currentId++;
return currentId;
}

}
2 changes: 1 addition & 1 deletion src/cpp/parsing/IfcLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ namespace webifc::parsing
void RemoveLine(const uint32_t expressID);
void PushDouble(double input);
void PushInt(int input);
void ExtendLineStorage(uint32_t lineStorageSize);
uint32_t GetNextExpressID(uint32_t expressId) const;
template <typename T> void Push(T input)
{
Expand All @@ -74,6 +73,7 @@ namespace webifc::parsing
uint32_t ifcType;
uint32_t tapeOffset;
};
uint32_t _maxExpressId;
const uint32_t _lineWriterBuffer;
const schema::IfcSchemaManager &_schemaManager;
IfcTokenStream * _tokenStream;
Expand Down
5 changes: 0 additions & 5 deletions src/cpp/web-ifc-wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,6 @@ bool ValidateExpressID(uint32_t modelID, uint32_t expressId) {
return manager.IsModelOpen(modelID) ? manager.GetIfcLoader(modelID)->IsValidExpressID(expressId) : false;
}

void ExtendLineStorage(uint32_t modelID, uint32_t lineStorageSize) {
if (manager.IsModelOpen(modelID)) manager.GetIfcLoader(modelID)->ExtendLineStorage(lineStorageSize);
}

uint32_t GetNextExpressID(uint32_t modelID, uint32_t expressId) {
return manager.IsModelOpen(modelID) ? manager.GetIfcLoader(modelID)->GetNextExpressID(expressId) : 0;
}
Expand Down Expand Up @@ -824,7 +820,6 @@ EMSCRIPTEN_BINDINGS(my_module) {

emscripten::register_vector<double>("DoubleVector");

emscripten::function("ExtendLineStorage", &ExtendLineStorage);
emscripten::function("LoadAllGeometry", &LoadAllGeometry);
emscripten::function("GetAllCrossSections", &GetAllCrossSections);
emscripten::function("GetAllAlignments", &GetAllAlignments);
Expand Down
2 changes: 0 additions & 2 deletions src/ts/web-ifc-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,6 @@ export class IfcAPI {
* @param lineObject array of line object to write
*/
WriteLines<Type extends IfcLineObject>(modelID: number, lineObjects: Array<Type>) {
this.wasmModule.ExtendLineStorage(modelID,lineObjects.length);
for (let lineObject of lineObjects) this.WriteLine(modelID,lineObject);
}

Expand Down Expand Up @@ -676,7 +675,6 @@ export class IfcAPI {

/** @ignore */
WriteRawLinesData(modelID: number, data: Array<RawLineData>) {
this.wasmModule.ExtendLineStorage(modelID,data.length);
for (let rawLine of data) this.wasmModule.WriteLine(modelID, rawLine.ID, rawLine.type, rawLine.arguments);
}

Expand Down
18 changes: 6 additions & 12 deletions tests/functional/WebIfcApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,28 +426,22 @@ describe('WebIfcApi known failures', () => {

describe('some use cases', () => {
test("can write a new property value and read it back in", async () => {
async function getFirstStorey(api:any, mId:any) {
const storeyIds = await api.GetLineIDsWithType(mId, WebIFC.IFCBUILDINGSTOREY);
expect(storeyIds.size()).toBe(2);
const storeyId = storeyIds.get(0);
const storey = await api.properties.getItemProperties(mId, storeyId);
return [storey, storeyId];
}
let [storey, storeyId] = await getFirstStorey(ifcApi, modelID);

let storey = await ifcApi.properties.getItemProperties(modelID, 138);
const newStoreyName = 'Nivel 1 - Editado'
storey.LongName.value = newStoreyName;
ifcApi.WriteLine(modelID, storey);
storey = await ifcApi.properties.getItemProperties(modelID, storeyId);
storey = await ifcApi.properties.getItemProperties(modelID, 138);
expect(storey.LongName.value).toBe(newStoreyName);

const writtenData = await ifcApi.SaveModel(modelID);
let modelId = ifcApi.OpenModel(writtenData);
[storey, storeyId] = await getFirstStorey(ifcApi, modelId);
storey = await ifcApi.properties.getItemProperties(modelId, 138);
expect(storey.LongName.value).toBe(newStoreyName);
});

})
})


describe('creating ifc', () => {
test('can create new ifc model', () => {
let createdID = ifcApi.CreateModel({schema: WebIFC.Schemas.IFC2X3});
Expand Down

0 comments on commit 2c76b8b

Please sign in to comment.