|
1 | | -import { Component, OnInit } from '@angular/core'; |
| 1 | +import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; |
| 2 | +import { MatTableDataSource } from '@angular/material/table'; |
| 3 | +import { IfcService } from '../services/ifc.service'; |
| 4 | + |
| 5 | +interface ifcProperty { |
| 6 | + [key: string]: string; |
| 7 | +} |
| 8 | + |
| 9 | +interface ifcPropertyGroup { |
| 10 | + name: string; |
| 11 | + props: ifcProperty[]; |
| 12 | +} |
2 | 13 |
|
3 | 14 | @Component({ |
4 | 15 | selector: 'app-property-menu', |
5 | 16 | templateUrl: './property-menu.component.html', |
6 | 17 | styleUrls: ['./property-menu.component.css'] |
7 | 18 | }) |
8 | 19 | export class PropertyMenuComponent implements OnInit { |
| 20 | + dataSources: MatTableDataSource<ifcProperty>[] = []; |
| 21 | + properties: ifcPropertyGroup[] = [ |
| 22 | + { |
| 23 | + name: '01', |
| 24 | + props: [ |
| 25 | + { name: 'asdf', value: 'asdf' }, |
| 26 | + { name: 'asdf', value: 'asdf' }, |
| 27 | + { name: 'asdf', value: 'asdf' }, |
| 28 | + { name: 'asdf', value: 'asdf' } |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + name: '02', |
| 33 | + props: [ |
| 34 | + { name: 'asdf', value: 'asdf' }, |
| 35 | + { name: 'asdf', value: 'asdf' }, |
| 36 | + { name: 'asdf', value: 'asdf' }, |
| 37 | + { name: 'asdf', value: 'asdf' } |
| 38 | + ] |
| 39 | + } |
| 40 | + ]; |
9 | 41 |
|
10 | | - constructor() { } |
| 42 | + ifc: IfcService; |
11 | 43 |
|
12 | | - ngOnInit(): void { |
| 44 | + constructor(service: IfcService) { |
| 45 | + this.ifc = service; |
| 46 | + this.ifc.subscribeOnSelect(this.updateProperties); |
| 47 | + this.dataSources = this.properties.map((p) => { |
| 48 | + const source = new MatTableDataSource<ifcProperty>(); |
| 49 | + source.data = p.props; |
| 50 | + return source; |
| 51 | + }); |
13 | 52 | } |
14 | 53 |
|
| 54 | + ngOnInit(): void {} |
| 55 | + |
| 56 | + updateProperties = (modelID: number, id: number) => { |
| 57 | + if (modelID == null || id == null) return; |
| 58 | + const props = this.ifc.ifcViewer?.getProperties(modelID, id, true); |
| 59 | + this.properties.length = 0; |
| 60 | + this.dataSources = []; |
| 61 | + const allGroups = this.getPropertyGroups(props); |
| 62 | + this.properties.push(...allGroups); |
| 63 | + this.dataSources = this.properties.map((p) => { |
| 64 | + const source = new MatTableDataSource<ifcProperty>(); |
| 65 | + source.data = p.props; |
| 66 | + return source; |
| 67 | + }); |
| 68 | + }; |
| 69 | + |
| 70 | + getPropertyGroups(props: any): ifcPropertyGroup[] { |
| 71 | + const psets = props.psets.map((p: any) => { |
| 72 | + return { name: 'Property set', props: this.getProps(p) }; |
| 73 | + }); |
| 74 | + delete props.psets; |
| 75 | + const type = props.type.map((p: any) => { |
| 76 | + return { name: 'Type properties', props: this.getProps(p) }; |
| 77 | + }); |
| 78 | + delete props.type; |
| 79 | + props = { name: 'Native properties', props: this.getProps(props) }; |
| 80 | + return [props, ...psets, ...type]; |
| 81 | + } |
| 82 | + |
| 83 | + getProps(props: any) { |
| 84 | + for (let i in props) { |
| 85 | + props[i] = this.getProp(props[i]); |
| 86 | + } |
| 87 | + return Object.keys(props).map((p) => { |
| 88 | + return { name: p, value: props[p] }; |
| 89 | + }); |
| 90 | + } |
| 91 | + |
| 92 | + getProp(prop: any) { |
| 93 | + if (prop == null || prop == undefined) return 'undefined'; |
| 94 | + if (prop.value != undefined) return '' + prop.value; |
| 95 | + if (typeof prop == 'number') return '' + prop; |
| 96 | + return 'undefined'; |
| 97 | + } |
15 | 98 | } |
0 commit comments