-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathsurface-component.ts
68 lines (58 loc) · 1.97 KB
/
surface-component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* @file Surface Component
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @private
*/
import { ComponentRegistry } from '../globals'
import Component, { ComponentParameters } from './component'
import Stage from '../stage/stage'
import Surface from '../surface/surface'
type SurfaceRepresentationType = 'surface'|'dot'
/**
* Component wrapping a {@link Surface} object
*
* @example
* // get a surface component by loading a surface file into the stage
* stage.loadFile( "url/for/surface" ).then( function( surfaceComponent ){
* surfaceComponent.addRepresentation( "surface" );
* surfaceComponent.autoView();
* } );
*/
class SurfaceComponent extends Component {
/**
* @param {Stage} stage - stage object the component belongs to
* @param {Surface} surface - surface object to wrap
* @param {ComponentParameters} params - component parameters
*/
constructor (stage: Stage, readonly surface: Surface, params: Partial<ComponentParameters> = {}) {
super(stage, surface, Object.assign({ name: surface.name }, params))
}
/**
* Component type
* @type {String}
*/
get type () { return 'surface' }
/**
* Add a new surface representation to the component
* @param {String} type - the name of the representation, one of:
* surface, dot.
* @param {SurfaceRepresentationParameters} params - representation parameters
* @return {RepresentationComponent} the created representation wrapped into
* a representation component object
*/
addRepresentation (type: SurfaceRepresentationType, params: { [k: string]: any } = {}) {
return this._addRepresentation(type, this.surface, params)
}
getBoxUntransformed () {
return this.surface.boundingBox
}
getCenterUntransformed () {
return this.surface.center
}
dispose () {
this.surface.dispose()
super.dispose()
}
}
ComponentRegistry.add('surface', SurfaceComponent)
export default SurfaceComponent