Skip to content

Commit

Permalink
Merge pull request #480 from IFCjs/fixes
Browse files Browse the repository at this point in the history
Write Line Fixes
  • Loading branch information
beachtom authored Sep 8, 2023
2 parents 5e79acf + fe24808 commit 62fed77
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/wasm/parsing/IfcLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ namespace webifc::parsing {
{
_lines[expressID-1]->ifcType = 0;
}

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

void IfcLoader::UpdateLineTape(const uint32_t expressID, const uint32_t type, const uint32_t start)
{
Expand Down
1 change: 1 addition & 0 deletions src/wasm/parsing/IfcLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace webifc::parsing
void RemoveLine(const uint32_t expressID);
void PushDouble(double input);
void PushInt(int input);
void ExtendLineStorage(uint32_t lineStorageSize);
template <typename T> void Push(T input)
{
_tokenStream->Push(input);
Expand Down
14 changes: 8 additions & 6 deletions src/wasm/parsing/IfcTokenChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ namespace webifc::parsing
IfcTokenStream::IfcTokenChunk::IfcTokenChunk(const size_t chunkSize, const size_t startRef, const size_t fileStartRef, IfcFileStream *fileStream) : _startRef(startRef), _fileStartRef(fileStartRef), _chunkSize(chunkSize), _fileStream(fileStream)
{
_chunkData = nullptr;
_loaded=true;
_currentSize = 0;
if (_fileStream!=nullptr) Load();
else _loaded=true;
}

bool IfcTokenStream::IfcTokenChunk::Clear()
Expand All @@ -37,6 +38,11 @@ namespace webifc::parsing
{
return _loaded;
}

size_t IfcTokenStream::IfcTokenChunk::GetMaxSize()
{
return _chunkSize;
}

std::string_view IfcTokenStream::IfcTokenChunk::ReadString(const size_t ptr,const size_t size)
{
Expand All @@ -46,11 +52,8 @@ namespace webifc::parsing

void IfcTokenStream::IfcTokenChunk::Push(void *v, const size_t size)
{
if (_chunkData == nullptr) _chunkData = new uint8_t[_chunkSize];
_currentSize+=size;
if (_chunkData == nullptr)
{
_chunkData = new uint8_t[_chunkSize];
}
if (_currentSize > _chunkSize) {
uint8_t * tmp = _chunkData;
_chunkData = new uint8_t[_currentSize];
Expand Down Expand Up @@ -203,6 +206,5 @@ namespace webifc::parsing
else if (c == ';') Push<uint8_t>(IfcTokenType::LINE_END);
_fileStream->Forward();
}
_chunkSize=_currentSize;
}
}
16 changes: 10 additions & 6 deletions src/wasm/parsing/IfcTokenStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace webifc::parsing
IfcTokenStream::IfcTokenStream(const size_t chunkSize, const size_t maxChunks)
: _chunkSize(chunkSize), _maxChunks(maxChunks)
{
_cChunk=NULL;
_fileStream=NULL;
_cChunk=nullptr;
_fileStream=nullptr;
}

void IfcTokenStream::SetTokenSource(const std::function<uint32_t(char *, size_t, size_t)> &requestData)
Expand Down Expand Up @@ -47,9 +47,13 @@ namespace webifc::parsing
}
auto length = _cChunk->Read<uint16_t>(_readPtr);
Forward(2);
auto str = _cChunk->ReadString(_readPtr,length);
Forward(length);
return str;
if (length > 0)
{
auto str = _cChunk->ReadString(_readPtr,length);
Forward(length);
return str;
}
return "";
}

void IfcTokenStream::Forward(const size_t size)
Expand Down Expand Up @@ -99,7 +103,7 @@ namespace webifc::parsing
_chunks.emplace_back(_chunkSize,0,0,_fileStream);
_activeChunks++;
}
if ( _chunks.back().TokenSize() + size > _chunkSize)
if ( _chunks.back().TokenSize() + size > _chunks.back().GetMaxSize())
{
checkMemory();
_chunks.emplace_back(_chunkSize,_chunks.back().GetTokenRef() + _chunks.back().TokenSize(),0,_fileStream);
Expand Down
1 change: 1 addition & 0 deletions src/wasm/parsing/IfcTokenStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ namespace webifc::parsing
size_t TokenSize();
size_t GetTokenRef();
void Push(void *v, const size_t size);
size_t GetMaxSize();
std::string_view ReadString(const size_t ptr,const size_t size);
template <typename T> T Read(const size_t ptr)
{
Expand Down
11 changes: 11 additions & 0 deletions src/wasm/web-ifc-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,16 @@ bool ValidateExpressID(uint32_t modelID, uint32_t expressId)
return loader->IsValidExpressID(expressId);
}

void ExtendLineStorage(uint32_t modelID, uint32_t lineStorageSize)
{
auto loader = models[modelID].GetLoader();
if (!loader)
{
return;
}
loader->ExtendLineStorage(lineStorageSize);
}

uint32_t GetNextExpressID(uint32_t modelID, uint32_t expressId)
{
auto loader = models[modelID].GetLoader();
Expand Down Expand Up @@ -1114,6 +1124,7 @@ EMSCRIPTEN_BINDINGS(my_module) {

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

emscripten::function("ExtendLineStorage", &ExtendLineStorage);
emscripten::function("LoadAllGeometry", &LoadAllGeometry);
emscripten::function("GetAllCrossSections2D", &GetAllCrossSections2D);
emscripten::function("GetAllCrossSections3D", &GetAllCrossSections3D);
Expand Down
12 changes: 11 additions & 1 deletion src/web-ifc-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,17 @@ export class IfcAPI {
}

/**
* Writes a line to the model, can be used to write new lines or to update existing lines
* Writes a line to the model, can be used to write new lines or to update existing lines
* @param modelID Model handle retrieved by OpenModel
* @param lineObject 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);
}

/**
* Writes a set of line to the model, can be used to write new lines or to update existing lines
* @param modelID Model handle retrieved by OpenModel
* @param lineObject line object to write
*/
Expand Down

0 comments on commit 62fed77

Please sign in to comment.