-
Notifications
You must be signed in to change notification settings - Fork 178
/
Viewer.js
executable file
·162 lines (128 loc) · 4.1 KB
/
Viewer.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
////////////////////////////////////////////////////////////////
// Copyright (c) Autodesk, Inc. All rights reserved
// Written by Philippe Leefsma 2016 - ADN/Developer Technical Services
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
///////////////////////////////////////////////////////////
import PropTypes from 'prop-types'
import ReactDOM from 'react-dom'
import React from 'react'
import './Viewer.scss'
class Viewer extends React.Component {
/////////////////////////////////////////////////////////
//
//
/////////////////////////////////////////////////////////
static propTypes = {
panels: PropTypes.array
}
/////////////////////////////////////////////////////////
//
//
/////////////////////////////////////////////////////////
static defaultProps = {
panels: [],
style: {}
}
/////////////////////////////////////////////////////////
//
//
/////////////////////////////////////////////////////////
constructor () {
super()
this.height = 0
this.width = 0
}
/////////////////////////////////////////////////////////
// Component has been mounted so this container div is now created
// in the DOM and viewer can be instantiated
//
/////////////////////////////////////////////////////////
componentDidMount () {
this.viewer = new Autodesk.Viewing.Private.GuiViewer3D(
this.viewerContainer)
this.panelsContainer = document.createElement('div')
this.viewer.container.appendChild(
this.panelsContainer)
if (this.props.onViewerCreated) {
this.props.onViewerCreated(this.viewer)
}
}
/////////////////////////////////////////////////////////
//
//
/////////////////////////////////////////////////////////
componentWillReceiveProps (props) {
//const panels = props.panels.map((panel) => {
//
// return panel.render()
//})
//
//this.panelsContainer = ReactDOM.render(
// <div className="viewer-panels-container">
// { panels }
// </div>, this.panelsContainer)
}
/////////////////////////////////////////////////////////
//
//
/////////////////////////////////////////////////////////
componentDidUpdate () {
if (this.viewer && this.viewer.impl) {
if (this.viewerContainer.offsetHeight !== this.height ||
this.viewerContainer.offsetWidth !== this.width) {
this.height = this.viewerContainer.offsetHeight
this.width = this.viewerContainer.offsetWidth
this.viewer.resize()
}
}
this.props.panels.map((panel) => {
panel.emit('update')
})
}
/////////////////////////////////////////////////////////
// Component will unmount so we can destroy the viewer to avoid
// memory leaks
//
/////////////////////////////////////////////////////////
componentWillUnmount () {
if (this.viewer) {
if(this.viewer.impl.selector) {
this.viewer.finish()
this.viewer = null
}
}
}
/////////////////////////////////////////////////////////
// Render component, resize the viewer if exists
//
/////////////////////////////////////////////////////////
render() {
const panels = this.props.panels.map((panel) => {
return panel.render()
})
return (
<div className="viewer-app-container">
<div ref={(div) => this.viewerContainer = div}
className="viewer-container"
style={this.props.style}
/>
<div className="viewer-panels-container">
{ panels }
</div>
</div>
)
}
}
export default Viewer