Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IFC charset decoding #72

Merged
merged 3 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 18 additions & 4 deletions docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144104,6 +144104,8 @@ function getType(elt, viewer) {
}
function prettyType(elt, viewer) {
switch (getType(elt, viewer)) {
case "IFCANNOTATION":
return "Note";
case "IFCBEAM":
return "Beam";
case "IFCBUILDING":
Expand Down Expand Up @@ -144158,17 +144160,29 @@ function getName(elt) {
function reifyName(element, viewer) {
if (element.LongName) {
if (element.LongName.value) {
return element.LongName.value.trim();
return decodeIFCString(element.LongName.value.trim());
}
} else if (element.Name) {
if (element.Name.value) {
return element.Name.value.trim();
return decodeIFCString(element.Name.value.trim());
}
}
return prettyType(element, viewer) + "";
}
function getDescription(element) {
return getValueOrUndefined(element, "Description");
const val = getValueOrUndefined(element, "Description");
return val ? decodeIFCString(val) : val;
}
function decodeIFCString(ifcString) {
const ifcUnicodeRegEx = /\\X2\\(.*?)\\X0\\/uig;
let resultString = ifcString;
let match = ifcUnicodeRegEx.exec(ifcString);
while (match) {
const unicodeChar = String.fromCharCode(parseInt(match[1], 16));
resultString = resultString.replace(match[0], unicodeChar);
match = ifcUnicodeRegEx.exec(ifcString);
}
return resultString;
}

// src/Containers/SearchIndex.js
Expand Down Expand Up @@ -151863,7 +151877,7 @@ var MenuItem_default = MenuItem;

// package.json
var name = "builders";
var version = "0.1.0-r210";
var version = "0.1.0-r212";
var main = "src/index.jsx";
var homepage = "https://buildrs.github.io/";
var scripts = {
Expand Down
4 changes: 2 additions & 2 deletions docs/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "builders",
"version": "0.1.0-r210",
"version": "0.1.0-r212",
"main": "src/index.jsx",
"homepage": "https://buildrs.github.io/",
"scripts": {
"clean": "rm -rf docs ; cp -r public docs",
"new-version": "node --experimental-json-modules src/utils/version.mjs > package.json.new && mv package.json.new package.json",
"copy-web-asm": "cp node_modules/web-ifc/web-ifc.wasm public/static/js",
"build": "yarn copy-web-asm && yarn clean && yarn new-version && node config/build.js",
"serve": "node config/serve.js",
"serve": "yarn copy-web-asm && node config/serve.js",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
},
"dependencies": {
Expand Down
29 changes: 23 additions & 6 deletions src/utils/Ifc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function getType(elt, viewer) {

function prettyType(elt, viewer) {
switch (getType(elt, viewer)) {
case 'IFCANNOTATION': return 'Note';
case 'IFCBEAM': return 'Beam';
case 'IFCBUILDING': return 'Building';
case 'IFCBUILDINGSTOREY': return 'Storey';
Expand Down Expand Up @@ -48,26 +49,42 @@ function getName(elt) {
function reifyName(element, viewer) {
if (element.LongName) {
if (element.LongName.value) {
return element.LongName.value.trim();
return decodeIFCString(element.LongName.value.trim());
}
} else if (element.Name) {
if (element.Name.value) {
return element.Name.value.trim();
return decodeIFCString(element.Name.value.trim());
}
}
return prettyType(element, viewer) + '';
}


function getDescription(element) {
return getValueOrUndefined(element, 'Description');
const val = getValueOrUndefined(element, 'Description');
return val ? decodeIFCString(val) : val;
}


// https://github.com/tomvandig/web-ifc/issues/58#issuecomment-870344068
function decodeIFCString (ifcString) {
const ifcUnicodeRegEx = /\\X2\\(.*?)\\X0\\/uig;
let resultString = ifcString;
let match = ifcUnicodeRegEx.exec (ifcString);
while (match) {
const unicodeChar = String.fromCharCode (parseInt (match[1], 16));
resultString = resultString.replace (match[0], unicodeChar);
match = ifcUnicodeRegEx.exec (ifcString);
}
return resultString;
}


export {
decodeIFCString,
getDescription,
getName,
getType,
prettyType,
getName,
reifyName,
getDescription
reifyName
}
17 changes: 17 additions & 0 deletions src/utils/Ifc.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Testing from '@pablo-mayrgundter/testing.js/testing.js';
import {
decodeIFCString,
} from './Ifc.js';


const tests = new Testing();


tests.add('Test decode ifc string', () => {
const someAscii = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
tests.assertEquals(someAscii, decodeIFCString(someAscii));
tests.assertEquals('Küche', decodeIFCString('K\\X2\\00FC\\X0\\che'));
});


tests.run();