Circle function and UI tool (#3860)

* circle

* fix another example

* fix bad comment

* toPoint fix

* cargo fmt

* resolve most of the tests

* fix last test

* missed circle in bracket

* remove console error

* fmt

* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest)

* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)

* trigger ci

* remove three dot menu for circle

* make sure circle can be extruded

* fix up after merge

* add extrude test for circle

* clean up

* typo

* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)

* Revert "A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)"

This reverts commit 03f8eeb542.

* update docs again

* cmd bar test serialisation improvements

* tiny clean up

* fix after: Replace kittycad crate with kittycad-modeling-cmds

* fmt

* rename fix

* Update src/lib/toolbar.ts

Co-authored-by: Frank Noirot <frank@zoo.dev>

* add another error to list

* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest)

* image updates

* Revert "A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest)"

This reverts commit 505bb20bea.

* update markdown

* skip un reproducable windows test failure

* rust review

* leave issue todo comment

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@zoo.dev>
This commit is contained in:
Kurt Hutten
2024-09-23 22:42:51 +10:00
committed by GitHub
parent 7848d63177
commit f1b0e40388
122 changed files with 22670 additions and 512 deletions

View File

@ -33,11 +33,15 @@ function CommandBarBasicInput({
return (
<form id="arg-form" onSubmit={handleSubmit}>
<label className="flex items-center mx-4 my-4">
<label
data-testid="cmd-bar-arg-name"
className="flex items-center mx-4 my-4"
>
<span className="capitalize px-2 py-1 rounded-l bg-chalkboard-100 dark:bg-chalkboard-80 text-chalkboard-10 border-b border-b-chalkboard-100 dark:border-b-chalkboard-80">
{arg.name}
</span>
<input
data-testid="cmd-bar-arg-value"
id="arg-form"
name={arg.inputType}
ref={inputRef}

View File

@ -74,7 +74,9 @@ function CommandBarHeader({ children }: React.PropsWithChildren<{}>) {
selectedCommand.icon && (
<CustomIcon name={selectedCommand.icon} className="w-5 h-5" />
)}
{selectedCommand.displayName || selectedCommand.name}
<span data-testid="command-name">
{selectedCommand.displayName || selectedCommand.name}
</span>
</p>
{Object.entries(selectedCommand?.args || {})
.filter(([_, argConfig]) =>
@ -92,6 +94,10 @@ function CommandBarHeader({ children }: React.PropsWithChildren<{}>) {
return (
<button
data-testid="cmd-bar-input-tab"
data-is-current-arg={
argName === currentArgument?.name ? 'true' : 'false'
}
disabled={!isReviewing && currentArgument?.name === argName}
onClick={() => {
commandBarSend({
@ -110,29 +116,34 @@ function CommandBarHeader({ children }: React.PropsWithChildren<{}>) {
>
<span
data-testid={`arg-name-${argName.toLowerCase()}`}
data-test-name="arg-name"
className="capitalize"
>
{argName}
</span>
<span className="sr-only">:&nbsp;</span>
{argValue ? (
arg.inputType === 'selection' ? (
getSelectionTypeDisplayText(argValue as Selections)
) : arg.inputType === 'kcl' ? (
roundOff(
Number((argValue as KclCommandValue).valueCalculated),
4
)
) : typeof argValue === 'object' ? (
arg.valueSummary ? (
arg.valueSummary(argValue)
<span data-testid="header-arg-value">
{argValue ? (
arg.inputType === 'selection' ? (
getSelectionTypeDisplayText(argValue as Selections)
) : arg.inputType === 'kcl' ? (
roundOff(
Number(
(argValue as KclCommandValue).valueCalculated
),
4
)
) : typeof argValue === 'object' ? (
arg.valueSummary ? (
arg.valueSummary(argValue)
) : (
JSON.stringify(argValue)
)
) : (
JSON.stringify(argValue)
<em>{argValue}</em>
)
) : (
<em>{argValue}</em>
)
) : null}
) : null}
</span>
{showShortcuts && (
<small className="absolute -top-[1px] right-full translate-x-1/2 px-0.5 rounded-sm bg-chalkboard-80 text-chalkboard-10 dark:bg-primary dark:text-chalkboard-100">
<span className="sr-only">Hotkey: </span>

View File

@ -139,10 +139,17 @@ function CommandBarKclInput({
return (
<form id="arg-form" onSubmit={handleSubmit} data-can-submit={canSubmit}>
<label className="flex gap-4 items-center mx-4 my-4 border-solid border-b border-chalkboard-50">
<span className="capitalize text-chalkboard-80 dark:text-chalkboard-20">
<span
data-testid="cmd-bar-arg-name"
className="capitalize text-chalkboard-80 dark:text-chalkboard-20"
>
{arg.name}
</span>
<div ref={editorRef} className={styles.editor} />
<div
data-testid="cmd-bar-arg-value"
ref={editorRef}
className={styles.editor}
/>
<CustomIcon
name="equal"
className="w-5 h-5 text-chalkboard-70 dark:text-chalkboard-40"

View File

@ -36,10 +36,14 @@ function CommandBarTextareaInput({
return (
<form id="arg-form" onSubmit={handleSubmit} ref={formRef}>
<label className="flex items-start rounded mx-4 my-4 border border-chalkboard-100 dark:border-chalkboard-80">
<span className="capitalize px-2 py-1 rounded-br bg-chalkboard-100 dark:bg-chalkboard-80 text-chalkboard-10 border-b border-b-chalkboard-100 dark:border-b-chalkboard-80">
<span
data-testid="cmd-bar-arg-name"
className="capitalize px-2 py-1 rounded-br bg-chalkboard-100 dark:bg-chalkboard-80 text-chalkboard-10 border-b border-b-chalkboard-100 dark:border-b-chalkboard-80"
>
{arg.name}
</span>
<textarea
data-testid="cmd-bar-arg-value"
id="arg-form"
name={arg.inputType}
ref={inputRef}

View File

@ -41,7 +41,7 @@ import {
canSweepSelection,
handleSelectionBatch,
isSelectionLastLine,
isRangeInbetweenCharacters,
isRangeBetweenCharacters,
isSketchPipe,
updateSelections,
} from 'lib/selections'
@ -50,8 +50,7 @@ import { applyConstraintAbsDistance } from './Toolbar/SetAbsDistance'
import useStateMachineCommands from 'hooks/useStateMachineCommands'
import { modelingMachineCommandConfig } from 'lib/commandBarConfigs/modelingCommandConfig'
import {
STRAIGHT_SEGMENT,
TANGENTIAL_ARC_TO_SEGMENT,
SEGMENT_BODIES,
getParentGroup,
getSketchOrientationDetails,
} from 'clientSideScene/sceneEntities'
@ -168,10 +167,7 @@ export const ModelingMachineProvider = ({
if (event.type !== 'Set mouse state') return {}
const nextSegmentHoverMap = () => {
if (event.data.type === 'isHovering') {
const parent = getParentGroup(event.data.on, [
STRAIGHT_SEGMENT,
TANGENTIAL_ARC_TO_SEGMENT,
])
const parent = getParentGroup(event.data.on, SEGMENT_BODIES)
const pathToNode = parent?.userData?.pathToNode
const pathToNodeString = JSON.stringify(pathToNode)
if (!parent || !pathToNode) return context.segmentHoverMap
@ -187,10 +183,10 @@ export const ModelingMachineProvider = ({
event.data.type === 'idle' &&
context.mouseState.type === 'isHovering'
) {
const mouseOnParent = getParentGroup(context.mouseState.on, [
STRAIGHT_SEGMENT,
TANGENTIAL_ARC_TO_SEGMENT,
])
const mouseOnParent = getParentGroup(
context.mouseState.on,
SEGMENT_BODIES
)
if (!mouseOnParent || !mouseOnParent?.userData?.pathToNode)
return context.segmentHoverMap
const pathToNodeString = JSON.stringify(
@ -204,8 +200,8 @@ export const ModelingMachineProvider = ({
pathToNodeString,
},
})
// overlay timeout
}, 800) as unknown as number
// overlay timeout is 1s
}, 1000) as unknown as number
return {
...context.segmentHoverMap,
[pathToNodeString]: timeoutId,
@ -495,43 +491,21 @@ export const ModelingMachineProvider = ({
},
},
guards: {
'has valid extrude selection': ({ context: { selectionRanges } }) => {
'has valid sweep selection': ({ context: { selectionRanges } }) => {
// A user can begin extruding if they either have 1+ faces selected or nothing selected
// TODO: I believe this guard only allows for extruding a single face at a time
const isPipe = isSketchPipe(selectionRanges)
if (
const hasNoSelection =
selectionRanges.codeBasedSelections.length === 0 ||
isRangeInbetweenCharacters(selectionRanges) ||
isRangeBetweenCharacters(selectionRanges) ||
isSelectionLastLine(selectionRanges, codeManager.code)
) {
if (hasNoSelection) {
// they have no selection, we should enable the button
// so they can select the face through the cmdbar
// BUT only if there's extrudable geometry
if (doesSceneHaveSweepableSketch(kclManager.ast)) return true
return false
return doesSceneHaveSweepableSketch(kclManager.ast)
}
if (!isPipe) return false
return canSweepSelection(selectionRanges)
},
'has valid revolve selection': ({ context: { selectionRanges } }) => {
// A user can begin extruding if they either have 1+ faces selected or nothing selected
// TODO: I believe this guard only allows for extruding a single face at a time
const isPipe = isSketchPipe(selectionRanges)
if (
selectionRanges.codeBasedSelections.length === 0 ||
isRangeInbetweenCharacters(selectionRanges) ||
isSelectionLastLine(selectionRanges, codeManager.code)
) {
// they have no selection, we should enable the button
// so they can select the face through the cmdbar
// BUT only if there's extrudable geometry
if (doesSceneHaveSweepableSketch(kclManager.ast)) return true
return false
}
if (!isPipe) return false
if (!isSketchPipe(selectionRanges)) return false
return canSweepSelection(selectionRanges)
},