Enhance GCodePreview Component with Render Mode and Travel Visibility Options
- Added render mode selection to toggle between 'lines' and 'pipes' for GCode visualization. - Introduced travel visibility options to show or hide travel paths in the preview. - Updated rendering logic to reflect changes in user-selected options, improving the flexibility and usability of the GCodePreview component.
This commit is contained in:
parent
5f776f896f
commit
4d2ec19ff1
@ -1,6 +1,6 @@
|
|||||||
import * as GCodePreview from 'gcode-preview'
|
import * as GCodePreview from 'gcode-preview'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { Button, Card, Flex, Slider } from 'antd'
|
import { Button, Card, Flex, Select, Slider } from 'antd'
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import * as THREE from 'three'
|
import * as THREE from 'three'
|
||||||
import PlusIcon from '../../Icons/PlusIcon.jsx'
|
import PlusIcon from '../../Icons/PlusIcon.jsx'
|
||||||
@ -84,6 +84,12 @@ function GCodePreviewUI(props) {
|
|||||||
const [previewScale, setPreviewScale] = useState(1)
|
const [previewScale, setPreviewScale] = useState(1)
|
||||||
const [panMode, setPanMode] = useState(false)
|
const [panMode, setPanMode] = useState(false)
|
||||||
const [isDragging, setIsDragging] = useState(false)
|
const [isDragging, setIsDragging] = useState(false)
|
||||||
|
const [renderMode, setRenderMode] = useState('lines')
|
||||||
|
const [travelVisibility, setTravelVisibility] = useState('hide')
|
||||||
|
const renderModeRef = useRef(renderMode)
|
||||||
|
const travelVisibilityRef = useRef(travelVisibility)
|
||||||
|
renderModeRef.current = renderMode
|
||||||
|
travelVisibilityRef.current = travelVisibility
|
||||||
|
|
||||||
const resizePreview = useCallback(() => {
|
const resizePreview = useCallback(() => {
|
||||||
previewRef.current?.resize()
|
previewRef.current?.resize()
|
||||||
@ -117,6 +123,8 @@ function GCodePreviewUI(props) {
|
|||||||
initialCameraPosition: [0, 400, 450],
|
initialCameraPosition: [0, 400, 450],
|
||||||
allowDragNDrop: false
|
allowDragNDrop: false
|
||||||
})
|
})
|
||||||
|
instance.renderTubes = renderModeRef.current === 'pipes'
|
||||||
|
instance.renderTravel = travelVisibilityRef.current === 'show'
|
||||||
previewRef.current = instance
|
previewRef.current = instance
|
||||||
|
|
||||||
const { camera, controls } = instance
|
const { camera, controls } = instance
|
||||||
@ -188,6 +196,21 @@ function GCodePreviewUI(props) {
|
|||||||
applyingScaleRef.current = false
|
applyingScaleRef.current = false
|
||||||
}, [preview, previewScale])
|
}, [preview, previewScale])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!preview) return
|
||||||
|
const renderTubes = renderMode === 'pipes'
|
||||||
|
const renderTravel = travelVisibility === 'show'
|
||||||
|
if (
|
||||||
|
preview.renderTubes === renderTubes &&
|
||||||
|
preview.renderTravel === renderTravel
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
preview.renderTubes = renderTubes
|
||||||
|
preview.renderTravel = renderTravel
|
||||||
|
preview.render()
|
||||||
|
}, [preview, renderMode, travelVisibility])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!preview) return
|
if (!preview) return
|
||||||
preview.controls.mouseButtons = {
|
preview.controls.mouseButtons = {
|
||||||
@ -253,7 +276,7 @@ function GCodePreviewUI(props) {
|
|||||||
gap={'middle'}
|
gap={'middle'}
|
||||||
style={{ width: '100%', height: '100%', minHeight: 0, ...style }}
|
style={{ width: '100%', height: '100%', minHeight: 0, ...style }}
|
||||||
>
|
>
|
||||||
<Flex gap={'small'}>
|
<Flex gap={'small'} wrap='wrap' align='center'>
|
||||||
<KeyboardShortcut
|
<KeyboardShortcut
|
||||||
shortcut={'alt+p'}
|
shortcut={'alt+p'}
|
||||||
hint={'ALT P'}
|
hint={'ALT P'}
|
||||||
@ -293,6 +316,26 @@ function GCodePreviewUI(props) {
|
|||||||
setPreviewScale((prev) => clampPreviewScale(prev - 0.05))
|
setPreviewScale((prev) => clampPreviewScale(prev - 0.05))
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<Select
|
||||||
|
value={renderMode}
|
||||||
|
options={[
|
||||||
|
{ value: 'lines', label: 'Lines' },
|
||||||
|
{ value: 'pipes', label: 'Pipes' }
|
||||||
|
]}
|
||||||
|
style={{ minWidth: 77 }}
|
||||||
|
popupMatchSelectWidth={false}
|
||||||
|
onChange={setRenderMode}
|
||||||
|
/>
|
||||||
|
<Select
|
||||||
|
value={travelVisibility}
|
||||||
|
options={[
|
||||||
|
{ value: 'show', label: 'Show Travel' },
|
||||||
|
{ value: 'hide', label: 'Hide Travel' }
|
||||||
|
]}
|
||||||
|
style={{ minWidth: 118 }}
|
||||||
|
popupMatchSelectWidth={false}
|
||||||
|
onChange={setTravelVisibility}
|
||||||
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user