Skip to content

Commit e73f4a5

Browse files
committed
merge
2 parents be02d86 + 8c6232f commit e73f4a5

File tree

15 files changed

+753
-515
lines changed

15 files changed

+753
-515
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,12 @@ tests/ifcfiles/private/*.stl
6161
tests/ifcfiles/created.ifc
6262
src/cpp/_deps/
6363
yarn.lock
64+
65+
#external dependencies downloaded by Cmake
66+
src/cpp/_deps/cdt-src/
67+
src/cpp/_deps/earcut-src/
68+
src/cpp/_deps/fastfloat-src/
69+
src/cpp/_deps/glm-src/
70+
src/cpp/_deps/spdlog-src/
71+
src/cpp/_deps/tinycpptest-src/
72+
src/cpp/_deps/tinynurbs-src/

package-lock.json

Lines changed: 174 additions & 174 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cpp/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ FetchContent_Declare(spdlog GIT_REPOSITORY "https://github.com/gabime/spdlog" GI
6060
FetchContent_MakeAvailable(spdlog)
6161
FetchContent_GetProperties(spdlog)
6262

63+
Message("Downloading StdUUID")
64+
FetchContent_Declare(stduuid GIT_REPOSITORY "https://github.com/mariusbancila/stduuid" GIT_TAG "3afe7193facd5d674de709fccc44d5055e144d7a" EXCLUDE_FROM_ALL)
65+
FetchContent_MakeAvailable(stduuid)
66+
FetchContent_GetProperties(stduuid)
67+
68+
6369
Message("Downloads Finished")
6470

6571
function(PARAM_SETTER THE_EXECUTABLE)
@@ -70,6 +76,7 @@ function(PARAM_SETTER THE_EXECUTABLE)
7076
target_include_directories(${THE_EXECUTABLE} PUBLIC ${glm_SOURCE_DIR}/glm)
7177
target_include_directories(${THE_EXECUTABLE} PUBLIC ${earcut_SOURCE_DIR}/include)
7278
target_include_directories(${THE_EXECUTABLE} PUBLIC ${spdlog_SOURCE_DIR}/include)
79+
target_include_directories(${THE_EXECUTABLE} PUBLIC ${stduuid_SOURCE_DIR}/include)
7380

7481
if(NOT MSVC)
7582
target_compile_options(${THE_EXECUTABLE} PUBLIC "-Wall")

src/cpp/wasm/web-ifc-wasm.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ void SaveModel(uint32_t modelID, emscripten::val callback)
5353
manager.GetIfcLoader(modelID)->SaveFile([&](char* src, size_t srcSize)
5454
{
5555
emscripten::val retVal = callback((uint32_t)src, srcSize);
56-
}
57-
, false);
56+
}, false
57+
);
5858
}
5959

6060
int GetModelSize(uint32_t modelID) {
@@ -679,10 +679,11 @@ emscripten::val GetHeaderLine(uint32_t modelID, uint32_t headerType)
679679
return retVal;
680680
}
681681

682+
682683
emscripten::val GetLine(uint32_t modelID, uint32_t expressID)
683684
{
684-
if (!manager.IsModelOpen(modelID)) return emscripten::val::undefined();
685685
auto loader = manager.GetIfcLoader(modelID);
686+
if (!manager.IsModelOpen(modelID)) return emscripten::val::object();
686687
if (!loader->IsValidExpressID(expressID)) return emscripten::val::object();
687688
uint32_t lineType = loader->GetLineType(expressID);
688689
if (lineType==0) return emscripten::val::object();
@@ -696,6 +697,17 @@ emscripten::val GetLine(uint32_t modelID, uint32_t expressID)
696697
retVal.set(emscripten::val("type"), lineType);
697698
retVal.set(emscripten::val("arguments"), arguments);
698699
return retVal;
700+
701+
}
702+
703+
emscripten::val GetLines(uint32_t modelID, emscripten::val expressIDs)
704+
{
705+
auto result = emscripten::val::array();
706+
uint32_t size = expressIDs["length"].as<uint32_t>();
707+
708+
for (size_t x=0; x < size;x++) result.set(x,GetLine(modelID,expressIDs[x].as<uint32_t>()));
709+
710+
return result;
699711
}
700712

701713
uint32_t GetLineType(uint32_t modelID, uint32_t expressID) {
@@ -706,6 +718,12 @@ std::string GetVersion() {
706718
return std::string(WEB_IFC_VERSION_NUMBER);
707719
}
708720

721+
std::string GenerateGuid(uint32_t modelID) {
722+
if (!manager.IsModelOpen(modelID)) return "";
723+
auto loader = manager.GetIfcLoader(modelID);
724+
return loader->GenerateUUID();
725+
}
726+
709727
uint32_t GetMaxExpressID(uint32_t modelID) {
710728
return manager.IsModelOpen(modelID) ? manager.GetIfcLoader(modelID)->GetMaxExpressId() : 0;
711729
}
@@ -866,6 +884,7 @@ EMSCRIPTEN_BINDINGS(my_module) {
866884
emscripten::function("StreamAllMeshes", &StreamAllMeshes);
867885
emscripten::function("StreamAllMeshesWithTypes", &StreamAllMeshesWithTypesVal);
868886
emscripten::function("GetLine", &GetLine);
887+
emscripten::function("GetLines", &GetLines);
869888
emscripten::function("GetLineType", &GetLineType);
870889
emscripten::function("GetHeaderLine", &GetHeaderLine);
871890
emscripten::function("WriteLine", &WriteLine);
@@ -886,4 +905,5 @@ EMSCRIPTEN_BINDINGS(my_module) {
886905
emscripten::function("CloseAllModels", &CloseAllModels);
887906
emscripten::function("DecodeText", &DecodeText);
888907
emscripten::function("EncodeText", &EncodeText);
908+
emscripten::function("GenerateGuid", &GenerateGuid);
889909
}

src/cpp/web-ifc/geometry/IfcGeometryLoader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,9 @@ namespace webifc::geometry
347347
}
348348

349349

350-
if (_relNests.count(expressID) == 1)
350+
if (_relAggregates.count(expressID) == 1)
351351
{
352-
auto &relAgg = _relNests.at(expressID);
352+
auto &relAgg = _relAggregates.at(expressID);
353353
for (auto expressID : relAgg)
354354
{
355355
alignment = GetAlignment(expressID, alignment, transform * transform_t, expressID);
@@ -383,9 +383,9 @@ namespace webifc::geometry
383383
transform_t = GetLocalPlacement(localPlacement);
384384
}
385385

386-
if (_relNests.count(expressID) == 1)
386+
if (_relAggregates.count(expressID) == 1)
387387
{
388-
auto &relAgg = _relNests.at(expressID);
388+
auto &relAgg = _relAggregates.at(expressID);
389389
for (auto expressID : relAgg)
390390
{
391391
alignment.Horizontal.curves.push_back(GetAlignmentCurve(expressID, sourceExpressID));

src/cpp/web-ifc/geometry/IfcGeometryProcessor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ namespace webifc::geometry
11601160
case schema::IFCTEXTLITERALWITHEXTENT:
11611161
// TODO: save string of the text literal in IfcComposedMesh
11621162
return mesh;
1163-
default:
1163+
default:
11641164
spdlog::error("[GetMesh()] unexpected mesh type {}", expressID, lineType);
11651165
break;
11661166
}
@@ -1608,9 +1608,9 @@ namespace webifc::geometry
16081608

16091609
auto geom = _expressIDToGeometry[composedMesh.expressID];
16101610
if (geom.isPolygon)
1611-
{
1612-
return; // only triangles here
1613-
}
1611+
{
1612+
return; // only triangles here
1613+
}
16141614
if (geometry.testReverse()) geom.ReverseFaces();
16151615

16161616
auto translation = glm::dmat4(1.0);

src/cpp/web-ifc/geometry/nurbs.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,6 @@ namespace webifc::geometry{
178178
this->pth = tinynurbs::surfacePoint(*this->nurbs, 1.0, 0.0);
179179
this->ptv = tinynurbs::surfacePoint(*this->nurbs, 0.0, 1.0);
180180

181-
if (std::isnan(pth.x) || std::isnan(pth.y) ||std::isnan(pth.z) ) {
182-
spdlog::error("pth isnan: ({}/{}/{})", pth.x, pth.y, pth.z);
183-
return;
184-
}
185-
186181
// Compute distances for further use.
187182
this->dh = glm::distance(ptc, pth);
188183
this->dv = glm::distance(ptc, ptv);

src/cpp/web-ifc/parsing/IfcLoader.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
namespace webifc::parsing {
1616

1717
void p21encode(std::string_view input, std::ostringstream &output);
18-
std::string p21decode(std::string_view & str);
18+
std::string p21decode(std::string_view & str);
19+
std::string generateStringUUID();
20+
std::string expandIfcGuid(const std::string_view &guid);
21+
std::string compressIfcGuid(const std::string& guid);
1922

2023
IfcLoader::IfcLoader(uint32_t tapeSize, uint64_t memoryLimit,uint32_t lineWriterBuffer, const schema::IfcSchemaManager &schemaManager) :_lineWriterBuffer(lineWriterBuffer), _schemaManager(schemaManager)
2124
{
@@ -676,8 +679,9 @@ namespace webifc::parsing {
676679
if (t==SET_BEGIN) {
677680
StepBack();
678681
GetSetArgument();
679-
noArguments++;
680-
continue;
682+
noArguments++;
683+
continue;
684+
681685
}
682686
if (t == IfcTokenType::STRING || t == IfcTokenType::INTEGER || t == IfcTokenType::REAL || t == IfcTokenType::LABEL || t == IfcTokenType::ENUM) {
683687
uint16_t length = _tokenStream->Read<uint16_t>();
@@ -737,4 +741,13 @@ namespace webifc::parsing {
737741
return currentId;
738742
}
739743

744+
std::string IfcLoader::GetExpandedUUIDArgument() const
745+
{
746+
return expandIfcGuid(GetStringArgument());
747+
}
748+
749+
std::string IfcLoader::GenerateUUID() const {
750+
return compressIfcGuid(generateStringUUID());
751+
}
752+
740753
}

src/cpp/web-ifc/parsing/IfcLoader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace webifc::parsing
3636
void MoveToHeaderLineArgument(const uint32_t lineID, const uint32_t argumentIndex) const;
3737
std::string_view GetStringArgument() const;
3838
std::string GetDecodedStringArgument() const;
39+
std::string GetExpandedUUIDArgument() const;
3940
double GetDoubleArgument() const;
4041
long GetIntArgument() const;
4142
long GetIntArgument(const uint32_t tapeOffset) const;
@@ -62,6 +63,8 @@ namespace webifc::parsing
6263
void RemoveLine(const uint32_t expressID);
6364
void PushDouble(double input);
6465
void PushInt(int input);
66+
std::string GenerateUUID() const;
67+
6568
uint32_t GetNextExpressID(uint32_t expressId) const;
6669
template <typename T> void Push(T input)
6770
{
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include <map>
2+
#include <random>
3+
#include "uuid.h"
4+
#include "IfcLoader.h"
5+
6+
namespace webifc::parsing {
7+
8+
std::string generateStringUUID() {
9+
std::random_device rd;
10+
auto seed_data = std::array<int, 6> {};
11+
std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd));
12+
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
13+
std::ranlux48_base generator(seq);
14+
uuids::basic_uuid_random_generator<std::ranlux48_base> gen(&generator);
15+
auto id = gen();
16+
std::string final = uuids::to_string(id);
17+
return final;
18+
}
19+
20+
static constexpr const int8_t base16mask[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
21+
- 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
22+
- 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
23+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
24+
- 1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
25+
- 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
26+
- 1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
27+
- 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
28+
29+
30+
static constexpr const int8_t base64mask[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
31+
- 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
32+
- 1, -1, -1, -1, 63, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
33+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
34+
- 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
35+
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 62,
36+
- 1, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
37+
51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1 };
38+
39+
static constexpr const char base16Chars[] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
40+
41+
static constexpr std::array<char, 64> base64Chars = {
42+
'0','1','2','3','4','5','6','7','8','9',
43+
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
44+
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
45+
'_','$'
46+
};
47+
48+
std::string expandIfcGuid(const std::string_view &guid) {
49+
char temp[34];
50+
uint8_t ii = 0;
51+
52+
for (size_t i = 0; i < 22; i += 2)
53+
{
54+
uint16_t n = base64mask[(uint8_t)guid[i]] << 6;
55+
n += base64mask[(uint8_t)guid[i + 1]];
56+
uint16_t t = n / 16;
57+
temp[ii + 2] = base16Chars[n % 16];
58+
temp[ii + 1] = base16Chars[t % 16];
59+
temp[ii] = base16Chars[t / 16];
60+
ii += 3;
61+
}
62+
temp[ii] = '\0';
63+
64+
std::string result;
65+
result.resize(36);
66+
for (size_t i = 1; i < 36; ++i)
67+
{
68+
if (i == 9 || i == 13 || i == 17 || i == 21) result.push_back('-');
69+
result.push_back(temp[i]);
70+
}
71+
return result;
72+
}
73+
74+
75+
std::string compressIfcGuid(const std::string& guid)
76+
{
77+
std::string temp;
78+
temp.push_back('0');
79+
for (size_t ii = 0; ii < guid.length(); ++ii) if (guid[ii] != '-') temp.push_back(guid[ii]);
80+
81+
// compress
82+
size_t n = 0;
83+
char result[23];
84+
for (size_t i = 0, oi = 0; i < 32; i += 3)
85+
{
86+
n = base16mask[(uint8_t)temp[i]] << 8;
87+
n += base16mask[(uint8_t)temp[i + 1]] << 4;
88+
n += base16mask[(uint8_t)temp[i + 2]];
89+
result[oi + 1] = base64Chars[n % 64];
90+
result[oi] = base64Chars[n / 64];
91+
oi+=2;
92+
}
93+
result[22]='\0';
94+
return std::string(result);
95+
}
96+
}

0 commit comments

Comments
 (0)