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

MERGE ME #66

Merged
merged 2 commits into from
Dec 3, 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
1 change: 1 addition & 0 deletions config/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import esbuild from 'esbuild';
import svgrPlugin from 'esbuild-plugin-svgr';
import * as common from './common.js';

esbuild
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<html><head><meta http-equiv="refresh" content="0; URL=/Share/"></head><body></body></html>
<html><head><meta http-equiv="refresh" content="0; URL=/"></head><body></body></html>
1 change: 0 additions & 1 deletion docs/CNAME

This file was deleted.

2,133 changes: 1,694 additions & 439 deletions docs/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "builders",
"version": "0.1.0-r162",
"version": "0.1.0-r172",
"main": "src/index.jsx",
"homepage": "https://buildrs.github.io/",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion public/404.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<html><head><meta http-equiv="refresh" content="0; URL=/Share/"></head><body></body></html>
<html><head><meta http-equiv="refresh" content="0; URL=/"></head><body></body></html>
9 changes: 5 additions & 4 deletions src/Components/ItemProperties.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ const prettyProps = (viewer, element, key, props, serial) => {
const ItemProperties = ({ viewer, element }) => {
const props = element; //viewer.getProperties(0, element.expressID);
let serial = 0;
console.log('element', element);
return (
<table
style={{
Expand All @@ -131,9 +130,11 @@ const ItemProperties = ({ viewer, element }) => {
marginTop: 40,
}}
>
{Object.keys(props).map((key) =>
prettyProps(viewer, element, key, props, serial++)
)}
<tbody>
{Object.keys(props).map((key) =>
prettyProps(viewer, element, key, props, serial++)
)}
</tbody>
</table>
);
};
Expand Down
2 changes: 0 additions & 2 deletions src/Components/LoginMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ const LoginMenu = () => {
open={open}
onClose={handleClose}
>
{/*<MenuItem onClick={handleClose}>Profile</MenuItem>*/}
<MenuItem onClick={handleClose}>Version: {PkgJson.version}</MenuItem>
<Link to='/Share/about'>About</Link>
</Menu>
</div>
);
Expand Down
9 changes: 4 additions & 5 deletions src/Components/NavPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const useStyles = makeStyles((theme) => ({
},
}));


const NavPanel = ({
viewer,
element,
Expand All @@ -46,12 +47,10 @@ const NavPanel = ({
}

React.useEffect(() => {
let eltPath = location.pathname.split(/nav\//);
if (eltPath.length == 1) {
if (location.pathname.length <= 0) {
return;
}
eltPath = eltPath[1];
const parts = eltPath.split(/\//);
const parts = location.pathname.split(/\//);
if (parts.length > 0) {
const targetId = parseInt(parts[parts.length - 1]);
if (isFinite(targetId)) {
Expand Down Expand Up @@ -95,7 +94,7 @@ const NavPanel = ({
<NavTree
viewer={viewer}
element={element}
pathPrefix={'/Share/nav'}
pathPrefix={''}
onElementSelect={onElementSelect}
setExpandedElements={setExpandedElements}
/>
Expand Down
1 change: 0 additions & 1 deletion src/Components/NavTree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ const NavTree = ({
computeElementPath(element, (elt) => elt.expressID.toString())
}
style={{
color: 'black',
textDecoration: 'none',
fontFamily: 'helvetica',
fontWeight: 600,
Expand Down
70 changes: 34 additions & 36 deletions src/Containers/CadView.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { useParams } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import { IfcViewerAPI } from 'web-ifc-viewer';
import { makeStyles } from '@mui/styles';
import SearchIndex from './SearchIndex.js';
Expand All @@ -11,7 +10,7 @@ import SearchBar from '../Components/SearchBar';
import ToolBar from '../Components/ToolBar';
import gtag from '../utils/gtag.js';
import SnackBarMessage from '../Components/SnackbarMessage';
import { setupParentLinks } from '../utils/TreeUtils';
import { computeElementPath, setupLookupAndParentLinks } from '../utils/TreeUtils';
import { Color } from 'three';

const debug = 0;
Expand Down Expand Up @@ -175,7 +174,7 @@ const CadView = () => {

const onModelLoad = (rootElt, viewer) => {
setRootElement(rootElt);
setupParentLinks(rootElt);
setupLookupAndParentLinks(rootElt, elementsById);
if (debug >= 2) {
console.log(
`CadView#fileOpen: json: '${JSON.stringify(rootElt, null, ' ')}'`
Expand All @@ -190,7 +189,7 @@ const CadView = () => {
}
}
setDefaultExpandedElements(expanded);
setShowNavPanel(false);
setShowNavPanel(true);
searchIndex.clearIndex();
const index = new SearchIndex(rootElt, viewer);
index.indexElement(rootElt);
Expand All @@ -201,13 +200,14 @@ const CadView = () => {
setSearchIndex(index);
setShowSearchBar(true);
};
const navigate = useNavigate();

// Similar to componentDidMount and componentDidUpdate:
useEffect(() => {
const container = document.getElementById('viewer-container');
const viewer = new IfcViewerAPI({
container,
backgroundColor: new Color('#808080'),
backgroundColor: new Color('#e0e0e0'),
});
setViewer(viewer);
if (debug) {
Expand Down Expand Up @@ -243,41 +243,39 @@ const CadView = () => {
window.ondblclick = async () => {
const item = await viewer.IFC.pickIfcItem(true);
if (item.modelID === undefined || item.id === undefined) return;
const path = computeElementPath(elementsById[item.id], elt => elt.expressID);
navigate(path);
setSelectedElement(item);
};

// Expanded version of viewer.loadIfcUrl('/index.ifc'). Using
// this to get access to progress and error.
if (true) {
const parts = window.location.pathname.split(/[-\w\d]+.ifc/);
//console.log('Parts: ', parts);
//const filePath = './' + window.location.hash.substring(1);
//if (true) return;
const filePath = './haus.ifc';
if (debug) {
console.log('CadView#useEffect: load from server and hash: ', filePath);
}
viewer.IFC.loader.load(
filePath,
(model) => {
if (debug) {
console.log('CadView#useEffect$onLoad, model: ', model, viewer);
}
viewer.IFC.addIfcModel(model);
const rootEltPromise = model.ifcManager.getSpatialStructure(0, true);
rootEltPromise.then((rootElt) => {
onModelLoad(rootElt, viewer);
});
},
(progressEvent) => {
if (debug) {
console.log('CadView#useEffect$onProgress', progressEvent);
}
},
(error) => {
console.error('CadView#useEffect$onError', error);
}
);
const parts = window.location.pathname.split(/[-\w\d]+.ifc/);
const filePath = './haus.ifc';
if (debug) {
console.log('CadView#useEffect: load from server and hash: ', filePath);
}
viewer.IFC.loader.load(
filePath,
(model) => {
if (debug) {
console.log('CadView#useEffect$onLoad, model: ', model, viewer);
}
viewer.IFC.addIfcModel(model);
const rootEltPromise = model.ifcManager.getSpatialStructure(0, true);
rootEltPromise.then((rootElt) => {
onModelLoad(rootElt, viewer);
});
},
(progressEvent) => {
if (debug) {
console.log('CadView#useEffect$onProgress', progressEvent);
}
},
(error) => {
console.error('CadView#useEffect$onError', error);
}
);
}, []);

const loadIfc = async (file) => {
Expand Down
4 changes: 2 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import AccountCircle from '@mui/icons-material/AccountCircle';


function Routed() {
const nav = useNavigate();
const navigate = useNavigate();

React.useEffect(() => {
const referrer = document.referrer;
if (referrer) {
const path = new URL(document.referrer).pathname;
if (path.length > 1) {
nav(path);
navigate(path);
}
}
}, []);
Expand Down
30 changes: 23 additions & 7 deletions src/utils/TreeUtils.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
/**
* Visits an element tree and sets parent links for each element.
*/
function setupParentLinks(elt) {
function visitTree(elt, observeCb) {
if (elt && elt.children) {
for (const child of elt.children) {
child.parent = elt;
setupParentLinks(child);
observeCb(child, elt);
visitTree(child, observeCb);
}
}
}


/**
* Visits an element tree and sets parent links for each element.
*/
function setupLookupAndParentLinks(rootElt, elementsById) {
if (elementsById === undefined || elementsById == null) {
throw new Error('Illegal argument: elementsById undefined');
}
visitTree(rootElt, (elt, parent) => {
elementsById[parent.expressID] = parent;
elementsById[elt.expressID] = elt;
elt.parent = parent;
});
}


function computeElementPath(elt, getNameCb) {
if (getNameCb === undefined || getNameCb == null) {
throw new Error('Illegal argument: getNameCb undefined');
}
return (elt.parent ? computeElementPath(elt.parent, getNameCb) : '' ) + '/' + getNameCb(elt);
}


export {
computeElementPath,
setupParentLinks
setupLookupAndParentLinks,
visitTree
}
18 changes: 13 additions & 5 deletions src/utils/TreeUtils.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Testing from '@pablo-mayrgundter/testing.js/testing.js';
import {
computeElementPath,
setupParentLinks
} from './TreeUtils';
setupLookupAndParentLinks
} from './TreeUtils.js';


const tests = new Testing();
Expand All @@ -11,26 +11,33 @@ const tests = new Testing();
function makeTestTree() {
return {
name: 'a',
expressID: 0,
children: [{
name: 'b',
expressID: 1,
children: [{
name: 'c',
expressID: 2,
children: []
}]
}]
};
}


tests.add('Test setupParentLinks', () => {
tests.add('Test setupLookupAndParentLinks', () => {
const tree = makeTestTree();
setupParentLinks(tree);
const eltsById = {};
setupLookupAndParentLinks(tree, eltsById);
const a = tree;
const b = tree.children[0];
const c = tree.children[0].children[0];
tests.assertEquals(b, c.parent);
tests.assertEquals(a, b.parent);
tests.assertEquals(undefined, a.parent);
tests.assertEquals(a, eltsById[0]);
tests.assertEquals(b, eltsById[1]);
tests.assertEquals(c, eltsById[2]);
})

tests.add('Test computeElementPath', () => {
Expand All @@ -42,7 +49,8 @@ tests.add('Test computeElementPath', () => {
tests.assertEquals('/a', computeElementPath(a, getNameCb));
tests.assertEquals('/b', computeElementPath(b, getNameCb));
tests.assertEquals('/c', computeElementPath(c, getNameCb));
setupParentLinks(tree);
const eltsById = {};
setupLookupAndParentLinks(tree, eltsById);
tests.assertEquals('/a', computeElementPath(a, getNameCb));
tests.assertEquals('/a/b', computeElementPath(b, getNameCb));
tests.assertEquals('/a/b/c', computeElementPath(c, getNameCb));
Expand Down