Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/editor/components/build-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ export function BuildTab() {
</div>
</TooltipProvider>

{(activeTool === 'duct-segment' || activeTool === 'pipe-segment') && (
<ToolOptionsPanel kind={activeTool} />
)}

{(['duct-fitting', 'pipe-fitting'] as const)
.filter((kind) => (kind === 'duct-fitting' ? ductContext : pipeContext))
.map((kind) => (
Expand Down
2 changes: 1 addition & 1 deletion apps/editor/lib/build-palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function activateBuildTool(kind: string): void {
useViewer.getState().setSelection({ selectedIds: [], zoneId: null })
editor.setPhase('building')
editor.setCatalogCategory(null)
editor.setToolDefaults(kind, null)
if (!definition?.distributionRole) editor.setToolDefaults(kind, null)
editor.setMode('build')
editor.setTool(kind)
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/registry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ export type ToolOption = {
/** Row label. Sentence case, e.g. 'Create from'. */
label: string
choices: readonly ToolOptionChoice[]
/** Optional exact numeric entry instead of choice buttons. */
input?: { min?: number; max?: number; step?: number; unit?: string }
/** Subscribe to live value changes (Zustand-store-like); returns unsubscribe. */
subscribe: (onChange: () => void) => () => void
/** Current value token. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'bun:test'
import { emitter, type GridEvent, useScene, WallNode } from '@pascal-app/core'
import { useEditor, useInteractionScope } from '@pascal-app/editor'
import { type EditorGridEvent, useEditor, useInteractionScope } from '@pascal-app/editor'
import { useThree } from '@react-three/fiber'
import { act, create } from '@react-three/test-renderer'
import { useDistributionRunTool } from './distribution-run-tool'
Expand Down Expand Up @@ -123,3 +123,94 @@ test.each(['duct-segment', 'pipe-segment'] as const)(
}
},
)

test.each(['duct-segment', 'pipe-segment'] as const)(
'%s routes at an exact elevation and updates a vertical target without pointer movement',
async (toolName) => {
const previousEditor = useEditor.getState()
const previousScope = useInteractionScope.getState()
const previousWindow = Object.getOwnPropertyDescriptor(globalThis, 'window')
const previousAct = Object.getOwnPropertyDescriptor(globalThis, 'IS_REACT_ACT_ENVIRONMENT')
Object.defineProperty(globalThis, 'window', {
value: new EventTarget(),
configurable: true,
writable: true,
})
Object.defineProperty(globalThis, 'IS_REACT_ACT_ENVIRONMENT', {
value: true,
configurable: true,
writable: true,
})
let tool: ReturnType<typeof useDistributionRunTool> | undefined
const commits: Array<[number, number, number]> = []
let routingMode: 'horizontal' | 'vertical' = 'horizontal'
let targetElevation = 4
function Host() {
const { gl } = useThree()
gl.domElement.getBoundingClientRect = () =>
({ left: 0, top: 0, width: 100, height: 100 }) as DOMRect
tool = useDistributionRunTool({
active: true,
levelId: 'level_test',
toolName,
routingMode,
elevation: 2,
targetElevation,
getPorts: () => [],
findBody: () => null,
commit: ({ end }) => {
commits.push(end)
return { nextStart: end, nextConnection: { port: null, body: null } }
},
})
return null
}
let renderer: Awaited<ReturnType<typeof create>> | undefined
const event = (x: number): GridEvent => ({
position: [x, 0, 0],
localPosition: [x, 0, 0],
nativeEvent: {} as GridEvent['nativeEvent'],
})
try {
useEditor.setState({ snappingModeByContext: { wall: 'off', polygon: 'off', item: 'off' } })
useEditor.getState().showView('2d')
renderer = await create(<Host />)
await act(async () => {
emitter.emit('grid:click', event(1))
})
expect(tool?.start).toEqual([1, 2, 0])
await act(async () => {
emitter.emit('grid:click', event(3))
})
expect(commits).toEqual([[3, 2, 0]])
await act(async () => {
const planEvent: EditorGridEvent = {
...event(7),
screenProjection: { pointer: [120, 180], localToScreen: [1, 0, 0, 1, 0, 0] },
}
emitter.emit('grid:move', planEvent)
})
expect(tool?.cursorScreen).toEqual({ x: 120, y: 180, depth: 0 })
await act(async () => useEditor.getState().showView('3d'))
expect(tool?.cursorScreen).toBeNull()
routingMode = 'vertical'
await renderer.update(<Host />)
expect(tool?.cursor).toEqual([3, 4, 0])
targetElevation = 5
await renderer.update(<Host />)
expect(tool?.cursor).toEqual([3, 5, 0])
await act(async () => {
emitter.emit('grid:click', event(7))
})
expect(commits.at(-1)).toEqual([3, 5, 0])
} finally {
await renderer?.unmount()
useEditor.setState(previousEditor)
useInteractionScope.setState(previousScope)
if (previousWindow) Object.defineProperty(globalThis, 'window', previousWindow)
else Reflect.deleteProperty(globalThis, 'window')
if (previousAct) Object.defineProperty(globalThis, 'IS_REACT_ACT_ENVIRONMENT', previousAct)
else Reflect.deleteProperty(globalThis, 'IS_REACT_ACT_ENVIRONMENT')
}
},
)
Loading
Loading