Skip to content

Commit 3f09972

Browse files
committed
Start building optimized recursive spatial tree
1 parent 9a47341 commit 3f09972

File tree

7 files changed

+75
-86
lines changed

7 files changed

+75
-86
lines changed

examples/simple-angular/src/app/app.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, AfterViewInit, ViewChild, ElementRef, HostListener } from '@angular/core';
1+
import { Component, AfterContentInit, ViewChild, ElementRef, HostListener } from '@angular/core';
22
import { MatSidenav } from '@angular/material/sidenav';
33
import { IfcService } from './services/ifc.service';
44
import { SpatialTreeComponent } from './spatial-tree/spatial-tree.component';
@@ -8,7 +8,7 @@ import { SpatialTreeComponent } from './spatial-tree/spatial-tree.component';
88
templateUrl: './app.component.html',
99
styleUrls: ['./app.component.css']
1010
})
11-
export class AppComponent implements AfterViewInit {
11+
export class AppComponent implements AfterContentInit {
1212

1313
title = 'ifcjs-angular-example';
1414
ifc: IfcService;
@@ -21,7 +21,7 @@ export class AppComponent implements AfterViewInit {
2121
this.ifc = service;
2222
}
2323

24-
ngAfterViewInit() {
24+
ngAfterContentInit() {
2525
if (this.sidenav) this.sidenav.close();
2626
const container = this.getContainer();
2727
if(container) this.ifc.startIfcViewer(container);

examples/simple-angular/src/app/services/ifc.service.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { IfcViewerAPI } from 'web-ifc-viewer';
22

33
export class IfcService {
4+
currentModel = -1;
45
ifcViewer?: IfcViewerAPI;
56
container?: HTMLElement;
7+
onClickActions: ((modelID: number, id: number) => void)[];
8+
9+
constructor() {
10+
this.onClickActions = [];
11+
}
612

713
startIfcViewer(container: HTMLElement) {
814
if (!container) return this.notFoundError('container');
@@ -11,7 +17,7 @@ export class IfcService {
1117
this.setupInputs();
1218
}
1319

14-
setupIfcScene(){
20+
setupIfcScene() {
1521
if (!this.container) return;
1622
this.ifcViewer = new IfcViewerAPI({ container: this.container });
1723
this.ifcViewer.addAxes();
@@ -27,9 +33,15 @@ export class IfcService {
2733
this.container.onmousemove = this.handleMouseMove;
2834
}
2935

36+
subscribeOnClick(action: (modelID: number, id: number) => void) {
37+
this.onClickActions.push(action);
38+
}
39+
3040
private handleClick = (event: Event) => {
31-
const id = this.ifcViewer?.getModelID();
32-
// if (typeof id === 'number') this.spatialTree?.updateSpatialTree(id);
41+
const modelID = this.ifcViewer?.getModelID();
42+
if(typeof modelID != 'number') return;
43+
this.currentModel = modelID;
44+
this.onClickActions.forEach(action => action(modelID, -1));
3345
};
3446

3547
private handleDoubleClick = (event: Event) => {};
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
<mat-accordion>
2-
<mat-expansion-panel
3-
(opened)="loadChildren()"
4-
class="mat-elevation-z0 spatial-tree-node"
5-
[ngClass] = "{'root-node': rootNode && clicked}"
6-
hideToggle>
2+
<mat-expansion-panel
3+
(opened)="loadChildren()"
4+
class="mat-elevation-z0 spatial-tree-node"
5+
[ngClass]="{ 'root-node': rootNode && clicked }"
6+
hideToggle
7+
>
78
<mat-expansion-panel-header>
89
<mat-panel-title>
9-
<mat-checkbox class="example-margin" click-stop-propagation>{{ prefix }}</mat-checkbox>
10+
<mat-checkbox class="example-margin" click-stop-propagation>{{ name }}</mat-checkbox>
1011
</mat-panel-title>
11-
<mat-panel-description> {{"ID: " + ifcID}} </mat-panel-description>
12+
<mat-panel-description> {{ 'ID: ' + ifcID }} </mat-panel-description>
1213
</mat-expansion-panel-header>
1314

14-
1515
<app-spatial-tree-node
16-
*ngFor="let spatialChild of spatialChildren; index as i"
17-
[currentModel]="currentModel"
18-
[ifcID]="spatialChildren[i]"
19-
[ifc]="ifcViewer"
20-
prefix="IfcProject"
21-
>
22-
</app-spatial-tree-node>
23-
16+
*ngFor="let spatialChild of spatialChildren; index as i"
17+
[ifcID]="spatialChildren[i]"
18+
(spatialIndex)="(spatialIndex == 0 || spatialIndex) ? spatialIndex + 1 : 0"
19+
>
20+
</app-spatial-tree-node>
2421

22+
<!-- <app-spatial-tree-node
23+
*ngFor="let child of children; index as j"
24+
[ifcID]="children[j]"
25+
>
26+
</app-spatial-tree-node> -->
2527
</mat-expansion-panel>
2628
</mat-accordion>
Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Component, AfterContentInit, Input, Output, EventEmitter } from '@angular/core';
1+
import { Component, Input, AfterContentInit, EventEmitter } from '@angular/core';
2+
import { IfcService } from 'src/app/services/ifc.service';
23
import { IfcViewerAPI } from '../../../../../../viewer/dist';
34

45
@Component({
@@ -7,34 +8,37 @@ import { IfcViewerAPI } from '../../../../../../viewer/dist';
78
styleUrls: ['./spatial-tree-node.component.css']
89
})
910
export class SpatialTreeNodeComponent implements AfterContentInit {
10-
@Input('currentModel') currentModel: number;
11-
@Input('ifcID') ifcID: number;
12-
@Input('prefix') prefix: string;
13-
@Input('rootNode') rootNode: boolean;
14-
@Input('ifc') ifcViewer?: IfcViewerAPI;
15-
// @Output('onSelect') onSelect = new EventEmitter();
16-
props: object;
17-
spatialChildren: number[];
18-
clicked: boolean;
11+
@Input('ifcID') ifcID: number = -1;
12+
@Input('rootNode') rootNode: boolean = false;
13+
@Input('spatialIndex') spatialIndex?: number;
1914

20-
constructor() {
21-
this.ifcID = -1;
22-
this.currentModel = -1;
23-
this.clicked = false;
24-
this.rootNode = false;
25-
this.spatialChildren = [];
26-
this.props = {};
27-
this.prefix = '';
15+
ifc: IfcService;
16+
name: string = '';
17+
props: any = {};
18+
spatialChildren: number[] = [];
19+
children: number[] = [];
20+
clicked: boolean = false;
21+
spatialStructure: string[] = [
22+
'IfcProject',
23+
'IfcSite',
24+
'IfcBuilding',
25+
'IfcBuildingStorey',
26+
'IfcSpace'
27+
];
28+
29+
constructor(service: IfcService) {
30+
this.ifc = service;
2831
}
2932

30-
ngAfterContentInit(): void {}
33+
ngAfterContentInit() {
34+
if (this.spatialIndex) this.name = this.spatialStructure[this.spatialIndex] || 'IfcItem';
35+
}
3136

3237
loadChildren() {
3338
this.clicked = true;
34-
// this.onSelect.emit(this.ifcID);
3539
const found = { expressID: this.ifcID, hasChildren: [], hasSpatialChildren: [] };
36-
this.ifcViewer?.getAllSpatialChildren(this.currentModel, found, false, true);
37-
console.log(found);
40+
this.ifc.ifcViewer?.getAllSpatialChildren(this.ifc.currentModel, found, false, true);
3841
this.spatialChildren = found.hasSpatialChildren;
42+
this.children = found.hasChildren;
3943
}
4044
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<div class="tree-menu">
22
<app-spatial-tree-node
33
*ngFor="let project of ifcProjects; index as i"
4-
[rootNode]="true"
5-
[currentModel]="currentModel"
64
[ifcID]="ifcProjects[i]"
7-
[ifc]="ifcViewer"
8-
prefix="IfcProject"
5+
[rootNode]="true"
96
>
107
</app-spatial-tree-node>
118
</div>
Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,30 @@
1-
import { Component, AfterViewInit, Input } from '@angular/core';
1+
import { Component, Input } from '@angular/core';
22
import { IFCPROJECT } from 'web-ifc';
33
import { IfcViewerAPI } from '../../../../../viewer/dist';
4+
import { IfcService } from '../services/ifc.service';
45
// import { MatMenuTrigger } from '@angular/material/menu';
56

67
@Component({
78
selector: 'app-spatial-tree',
89
templateUrl: './spatial-tree.component.html',
910
styleUrls: ['./spatial-tree.component.css']
1011
})
11-
export class SpatialTreeComponent implements AfterViewInit {
12-
@Input('ifc') ifcViewer?: IfcViewerAPI;
13-
14-
spatialTree: any;
12+
export class SpatialTreeComponent {
13+
ifc: IfcService;
1514
currentModel: number;
1615
ifcProjects: number[];
17-
ifcSites: number[];
18-
ifcBuildings: number[];
19-
ifcStoreys: number[];
20-
ifcProducts: {[key: number]: number[]};
21-
spatialChildren: {[key: number]: number[]};
2216

23-
constructor() {
17+
constructor(service: IfcService) {
18+
this.ifc = service;
2419
this.currentModel = -1;
25-
this.spatialTree = {};
2620
this.ifcProjects = [];
27-
this.ifcSites = [];
28-
this.ifcBuildings = [];
29-
this.ifcStoreys = [];
30-
this.ifcProducts = {};
31-
this.spatialChildren = {};
21+
this.ifc.subscribeOnClick(this.updateSpatialTree);
3222
}
3323

34-
ngAfterViewInit(): void {}
35-
36-
updateSpatialTree(modelID: number) {
24+
updateSpatialTree = (modelID: number, id: number) => {
3725
if (modelID == this.currentModel) return;
3826
this.currentModel = modelID;
39-
const ifcProjectsIds = this.ifcViewer?.getAllItemsOfType(modelID, IFCPROJECT, false);
27+
const ifcProjectsIds = this.ifc.ifcViewer?.getAllItemsOfType(modelID, IFCPROJECT, false);
4028
if (ifcProjectsIds) this.ifcProjects = ifcProjectsIds;
4129
}
42-
43-
// getSpatialChildren(id: number, spatialChildren: number[]){
44-
// const found = { expressID: id, hasChildren: [], hasSpatialChildren: [] };
45-
// this.ifcViewer?.getAllSpatialChildren(this.currentModel, found, false, true);
46-
// console.log(found);
47-
// if(spatialChildren != undefined){
48-
// spatialChildren.length = 0;
49-
// spatialChildren.push(...found.hasSpatialChildren);
50-
// }
51-
// this.ifcProducts[id] = found.hasChildren;
52-
// }
5330
}

examples/simple-angular/src/app/toolbar/toolbar.component.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
1+
import { Component, Output, EventEmitter } from '@angular/core';
22
import { IfcService } from '../services/ifc.service';
33

44
@Component({
55
selector: 'app-toolbar',
66
templateUrl: './toolbar.component.html',
77
styleUrls: ['./toolbar.component.css']
88
})
9-
export class ToolbarComponent implements OnInit {
10-
clippingActive: boolean;
9+
export class ToolbarComponent {
1110
ifc: IfcService;
12-
11+
clippingActive: boolean;
1312
private fileOpener: HTMLInputElement;
1413

1514
constructor(service: IfcService) {
@@ -18,8 +17,6 @@ export class ToolbarComponent implements OnInit {
1817
this.fileOpener = this.newFileOpener();
1918
}
2019

21-
ngOnInit(): void {}
22-
2320
onOpenIfc() {
2421
this.fileOpener.click();
2522
}

0 commit comments

Comments
 (0)