2021-04-15 16:36:54 +08:00
|
|
|
|
|
|
|
|
2021-04-17 21:32:14 +08:00
|
|
|
import React, { useEffect, useRef } from 'react';
|
2021-04-15 16:36:54 +08:00
|
|
|
|
|
|
|
import { useDispatch, useSelector } from 'react-redux'
|
|
|
|
import { MdDone, MdClose } from 'react-icons/md'
|
|
|
|
import * as Icon from "./icons";
|
|
|
|
|
|
|
|
|
2021-04-17 11:54:01 +08:00
|
|
|
export const Dialog = () => {
|
|
|
|
|
|
|
|
const dialog = useSelector(state => state.ui.dialog)
|
2021-04-19 11:53:02 +08:00
|
|
|
const treeEntries = useSelector(state => state.treeEntries)
|
2021-04-15 16:36:54 +08:00
|
|
|
const dispatch = useDispatch()
|
|
|
|
|
|
|
|
const ref = useRef()
|
2021-04-17 11:54:01 +08:00
|
|
|
|
2021-04-15 16:36:54 +08:00
|
|
|
useEffect(() => {
|
2021-04-17 11:54:01 +08:00
|
|
|
if (!ref.current) return
|
2021-04-15 16:36:54 +08:00
|
|
|
ref.current.focus()
|
2021-04-17 11:54:01 +08:00
|
|
|
}, [dialog])
|
2021-04-15 16:36:54 +08:00
|
|
|
|
|
|
|
const extrude = () => {
|
2021-04-19 11:53:02 +08:00
|
|
|
const mesh = sc.extrude(dialog.target, ref.current.value)
|
|
|
|
|
|
|
|
dispatch({ type: 'rx-extrusion', mesh, sketchId: dialog.target.obj3d.name })
|
|
|
|
|
|
|
|
if (sc.activeSketch == dialog.target) {
|
|
|
|
dispatch({ type: 'finish-sketch' })
|
|
|
|
dialog.target.deactivate()
|
|
|
|
}
|
2021-04-15 16:36:54 +08:00
|
|
|
|
2021-04-17 11:54:01 +08:00
|
|
|
dispatch({ type: "clear-dialog" })
|
|
|
|
|
2021-04-19 11:53:02 +08:00
|
|
|
sc.render()
|
2021-04-17 11:54:01 +08:00
|
|
|
}
|
2021-04-15 16:36:54 +08:00
|
|
|
|
2021-04-17 21:32:14 +08:00
|
|
|
const extrudeEdit = () => {
|
2021-04-19 11:53:02 +08:00
|
|
|
|
2021-04-17 21:32:14 +08:00
|
|
|
|
|
|
|
dialog.target.userData.featureInfo[1] = ref.current.value
|
|
|
|
|
2021-04-19 11:53:02 +08:00
|
|
|
sc.refreshNode(dialog.target.name, treeEntries)
|
|
|
|
dispatch({ type: 'set-modified', status: true })
|
2021-04-17 21:32:14 +08:00
|
|
|
|
|
|
|
dispatch({ type: "clear-dialog" })
|
|
|
|
|
2021-04-19 11:53:02 +08:00
|
|
|
sc.render()
|
2021-04-17 21:32:14 +08:00
|
|
|
}
|
|
|
|
|
2021-04-15 16:36:54 +08:00
|
|
|
|
2021-04-17 11:54:01 +08:00
|
|
|
switch (dialog.action) {
|
|
|
|
case 'extrude':
|
|
|
|
return <>
|
2021-04-19 03:14:01 +08:00
|
|
|
<input className='w-16 border-t-0 border-l-0 border-r-0 border-b border-gray-50 text-gray-50 mr-2' type="number" defaultValue="1" step="0.1" ref={ref} />
|
2021-04-17 13:58:54 +08:00
|
|
|
<Icon.Flip className="btn w-auto h-full p-3.5"
|
2021-04-17 11:54:01 +08:00
|
|
|
onClick={() => ref.current.value *= -1}
|
|
|
|
/>
|
|
|
|
<MdDone
|
2021-04-17 13:58:54 +08:00
|
|
|
className="btn w-auto h-full p-3.5"
|
2021-04-17 11:54:01 +08:00
|
|
|
onClick={extrude}
|
|
|
|
/>
|
2021-04-17 13:58:54 +08:00
|
|
|
<MdClose className="btn w-auto h-full p-3.5 mr-6"
|
2021-04-19 11:53:02 +08:00
|
|
|
onClick={() => {
|
|
|
|
if (sc.activeSketch == dialog.target) { // if extrude dialog launched from sketch mode we set dialog back to the sketch dialog
|
|
|
|
dispatch({ type: 'set-dialog', action: 'sketch' })
|
|
|
|
} else {
|
|
|
|
dispatch({ type: "clear-dialog" })
|
|
|
|
}
|
|
|
|
}}
|
2021-04-17 11:54:01 +08:00
|
|
|
/>
|
|
|
|
</>
|
2021-04-17 21:32:14 +08:00
|
|
|
case 'extrude-edit':
|
|
|
|
return <>
|
2021-04-19 03:14:01 +08:00
|
|
|
<input className='w-16 border-t-0 border-l-0 border-r-0 border-b border-gray-50 text-gray-50 mr-2' type="number" defaultValue={dialog.target.userData.featureInfo[1]} step="0.1" ref={ref} />
|
2021-04-17 21:32:14 +08:00
|
|
|
<Icon.Flip className="btn w-auto h-full p-3.5"
|
|
|
|
onClick={() => ref.current.value *= -1}
|
|
|
|
/>
|
|
|
|
<MdDone
|
|
|
|
className="btn w-auto h-full p-3.5"
|
|
|
|
onClick={extrudeEdit}
|
|
|
|
/>
|
|
|
|
<MdClose className="btn w-auto h-full p-3.5 mr-6"
|
|
|
|
onClick={() => dispatch({ type: "clear-dialog" })}
|
|
|
|
/>
|
|
|
|
</>
|
2021-04-17 11:54:01 +08:00
|
|
|
case 'sketch':
|
|
|
|
return <>
|
|
|
|
<MdDone
|
2021-04-17 13:58:54 +08:00
|
|
|
className="btn w-auto h-full p-3.5"
|
2021-04-17 11:54:01 +08:00
|
|
|
onClick={() => {
|
2021-04-17 21:32:14 +08:00
|
|
|
if (sc.activeSketch.hasChanged
|
|
|
|
|| sc.activeSketch.idOnActivate != id
|
|
|
|
|| sc.activeSketch.c_idOnActivate != sc.activeSketch.c_id
|
|
|
|
) {
|
2021-04-19 11:53:02 +08:00
|
|
|
sc.refreshNode(sc.activeSketch.obj3d.name, treeEntries)
|
|
|
|
|
|
|
|
dispatch({ type: 'set-modified', status: true })
|
2021-04-17 17:09:35 +08:00
|
|
|
}
|
2021-04-17 21:32:14 +08:00
|
|
|
|
|
|
|
dispatch({ type: 'finish-sketch' })
|
|
|
|
|
2021-04-17 11:54:01 +08:00
|
|
|
sc.activeSketch.deactivate()
|
2021-04-17 17:54:41 +08:00
|
|
|
sc.render()
|
2021-04-17 13:58:54 +08:00
|
|
|
dispatch({ type: "clear-dialog" })
|
2021-04-17 11:54:01 +08:00
|
|
|
}}
|
|
|
|
/>
|
2021-04-17 13:58:54 +08:00
|
|
|
<MdClose className="btn w-auto h-full p-3.5 mr-6"
|
|
|
|
onClick={() => {
|
2021-04-17 21:32:14 +08:00
|
|
|
if (sc.activeSketch.hasChanged
|
|
|
|
|| sc.activeSketch.idOnActivate != id
|
|
|
|
|| sc.activeSketch.c_idOnActivate != sc.activeSketch.c_id
|
|
|
|
) {
|
|
|
|
dispatch({ type: "restore-sketch" })
|
2021-04-19 11:53:02 +08:00
|
|
|
// dispatch({ type: 'set-modified', status: false })
|
2021-04-17 17:09:35 +08:00
|
|
|
}
|
2021-04-19 11:53:02 +08:00
|
|
|
|
|
|
|
dispatch({ type: 'finish-sketch' })
|
2021-04-17 17:09:35 +08:00
|
|
|
|
2021-04-17 21:32:14 +08:00
|
|
|
sc.activeSketch.deactivate()
|
2021-04-17 18:25:43 +08:00
|
|
|
sc.render()
|
2021-04-17 13:58:54 +08:00
|
|
|
dispatch({ type: "clear-dialog" })
|
2021-04-17 21:32:14 +08:00
|
|
|
}}
|
2021-04-17 11:54:01 +08:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
default:
|
|
|
|
return null
|
|
|
|
}
|
2021-04-15 16:36:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-17 11:54:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
|