@@ -6,9 +6,9 @@ import { useQuery, useMutation } from '@apollo/client'
6
6
import File from './graphql/File.graphql'
7
7
import UpdateFile from './graphql/UpdateFile.graphql'
8
8
import GcodeDocs from './GcodeDocs/GcodeDocs.json'
9
- import { GCodeViewer } from 'react-gcode-viewer '
9
+ import GCodePreviewUI from '../../../components/GCodePreviewUI '
10
10
11
- import { Card , Collapse , Col , Row , Button , Typography , Divider , Input } from 'antd'
11
+ import { Card , Collapse , Col , Row , Button , Typography , Divider , Input , Slider } from 'antd'
12
12
import { PageHeader } from '@ant-design/pro-layout'
13
13
import { FileOutlined } from '@ant-design/icons'
14
14
@@ -26,7 +26,11 @@ export default function FileEditor () {
26
26
const fileID = match . params . id
27
27
28
28
const editorRef = useRef ( null )
29
+ const gcodePreviewRef = useRef ( null )
30
+
29
31
const [ lineContent , setLineContent ] = useState ( )
32
+ const [ selectedLayer , setSelectedLayer ] = useState ( )
33
+ const [ layerCount , setLayerCount ] = useState ( )
30
34
const [ filename , setFilename ] = useState ( null )
31
35
32
36
const [ openedCollapse , setOpenedCollapse ] = useState ( [ ] )
@@ -74,8 +78,13 @@ export default function FileEditor () {
74
78
monaco . editor . defineTheme ( 'Tomorrow' , Tomorrow )
75
79
}
76
80
81
+ function handleEditorChange ( value ) {
82
+ // gcodePreviewRef.current?.replaceGCode(value)
83
+ }
84
+
77
85
function handleEditorMount ( editor ) {
78
86
editorRef . current = editor
87
+
79
88
editor . onDidChangeCursorPosition ( ( position ) => {
80
89
const model = editor . getModel ( )
81
90
const content = model . getValueInRange ( {
@@ -100,6 +109,7 @@ export default function FileEditor () {
100
109
}
101
110
}
102
111
)
112
+ gcodePreviewRef . current ?. replaceGCode ( editorRef . current . getValue ( ) )
103
113
}
104
114
105
115
const onSearch = ( event ) => {
@@ -269,22 +279,29 @@ export default function FileEditor () {
269
279
{
270
280
key : '1' ,
271
281
label : 'Preview' ,
272
- children : < GCodeViewer
273
- orbitControls
274
- showAxes
275
- quality = { 0.2 }
276
- floorProps = { {
277
- gridWidth : 300 ,
278
- gridLength : 300
279
- } }
280
- style = { {
281
- top : 0 ,
282
- left : 0 ,
283
- width : '100%' ,
284
- height : '25%'
285
- } }
286
- url = { file . downloadUrl }
287
- />
282
+ children :
283
+ < Row >
284
+ < Col span = { 4 } >
285
+ < Slider
286
+ vertical
287
+ value = { selectedLayer }
288
+ max = { layerCount }
289
+ min = { 1 }
290
+ onChange = { setSelectedLayer }
291
+ marks = { { 1 : '1' , [ layerCount ] : layerCount } }
292
+ />
293
+ </ Col >
294
+ < Col span = { 20 } >
295
+ < GCodePreviewUI
296
+ ref = { gcodePreviewRef }
297
+ startLayer = { 1 }
298
+ endLayer = { selectedLayer + 1 }
299
+ lineWidth = { 20 }
300
+ renderTubes = { true }
301
+ gcode = { file . fileContent }
302
+ />
303
+ </ Col >
304
+ </ Row >
288
305
} ,
289
306
{
290
307
key : '2' ,
@@ -330,6 +347,7 @@ export default function FileEditor () {
330
347
defaultValue = { file . fileContent }
331
348
onMount = { handleEditorMount }
332
349
beforeMount = { handleEditorWillMount }
350
+ onChange = { handleEditorChange }
333
351
/>
334
352
</ Card >
335
353
</ Col >
0 commit comments