From bec3ba71cd4bed025745de98f25aeccbfdbac609 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Wed, 2 Apr 2025 15:10:57 -0700 Subject: [PATCH] More circular deps fixed (#6121) * 23 Signed-off-by: Jess Frazelle * 22 Signed-off-by: Jess Frazelle * 21 Signed-off-by: Jess Frazelle * fix known Signed-off-by: Jess Frazelle * fixes Signed-off-by: Jess Frazelle * cleanup Signed-off-by: Jess Frazelle * cleanup Signed-off-by: Jess Frazelle * 20 Signed-off-by: Jess Frazelle * 11 Signed-off-by: Jess Frazelle * 11 Signed-off-by: Jess Frazelle * fixes Signed-off-by: Jess Frazelle --------- Signed-off-by: Jess Frazelle --- known-circular.txt | 14 +- package.json | 1 + scripts/diff-circular-deps.sh | 4 +- src/clientSideScene/CameraControls.ts | 2 +- src/clientSideScene/ClientSideSceneComp.tsx | 146 +----------------- src/clientSideScene/confirmModal.tsx | 72 +++++++++ src/clientSideScene/deleteSegment.ts | 75 +++++++++ src/clientSideScene/sceneEntities.ts | 2 +- src/clientSideScene/sceneInfra.ts | 60 ++----- src/clientSideScene/sceneUtils.ts | 52 +++++++ src/clientSideScene/segments.ts | 2 +- src/components/LowerRightControls.tsx | 2 +- src/components/Settings/AllSettingsFields.tsx | 2 +- src/components/ToastTextToCad.tsx | 2 +- src/components/ToastUpdate.tsx | 2 +- src/editor/manager.ts | 19 ++- .../modelingCommandConfig.ts | 2 +- src/lib/coredump.ts | 2 +- src/lib/createMachineCommand.ts | 2 +- src/lib/selections.ts | 2 +- src/lib/singletons.ts | 2 +- src/lib/textToCad.ts | 16 -- src/lib/textToCadTelemetry.ts | 19 +++ src/lib/toolbar.ts | 2 +- src/machines/modelingMachine.ts | 4 +- src/routes/Settings.tsx | 29 ---- src/routes/SignIn.tsx | 2 +- src/routes/utils.ts | 29 ++++ 28 files changed, 309 insertions(+), 259 deletions(-) create mode 100644 src/clientSideScene/confirmModal.tsx create mode 100644 src/clientSideScene/deleteSegment.ts create mode 100644 src/lib/textToCadTelemetry.ts create mode 100644 src/routes/utils.ts diff --git a/known-circular.txt b/known-circular.txt index d8fd5c2df..b221565c9 100644 --- a/known-circular.txt +++ b/known-circular.txt @@ -1 +1,13 @@ -$ dpdm --no-warning --no-tree -T --skip-dynamic-imports=circular src/index.tsx• Circular Dependencies 01) src/lang/std/sketch.ts -> src/lang/modifyAst.ts -> src/lang/modifyAst/addEdgeTreatment.ts 02) src/lang/std/sketch.ts -> src/lang/modifyAst.ts 03) src/lang/std/sketch.ts -> src/lang/modifyAst.ts -> src/lang/std/sketchcombos.ts 04) src/clientSideScene/CameraControls.ts -> src/clientSideScene/sceneInfra.ts 05) src/lib/singletons.ts -> src/editor/manager.ts -> src/lib/selections.ts 06) src/lib/singletons.ts -> src/editor/manager.ts 07) src/lib/singletons.ts -> src/lang/KclSingleton.ts 08) src/lib/singletons.ts -> src/lang/codeManager.ts 09) src/lib/singletons.ts -> src/clientSideScene/sceneEntities.ts -> src/clientSideScene/segments.ts -> src/components/Toolbar/angleLengthInfo.ts 10) src/lib/singletons.ts -> src/clientSideScene/sceneEntities.ts -> src/clientSideScene/segments.ts -> src/machines/commandBarMachine.ts -> src/lib/commandBarConfigs/authCommandConfig.ts -> src/machines/appMachine.ts -> src/machines/settingsMachine.ts -> src/lib/commandBarConfigs/settingsCommandConfig.ts -> src/lib/createMachineCommand.ts -> src/routes/Settings.tsx -> src/components/Settings/AllSettingsFields.tsx -> src/components/LspProvider.tsx -> src/editor/plugins/lsp/copilot/index.ts 11) src/lib/singletons.ts -> src/clientSideScene/sceneEntities.ts -> src/clientSideScene/segments.ts -> src/machines/commandBarMachine.ts -> src/lib/commandBarConfigs/authCommandConfig.ts -> src/machines/appMachine.ts -> src/machines/settingsMachine.ts -> src/lib/commandBarConfigs/settingsCommandConfig.ts -> src/lib/createMachineCommand.ts -> src/routes/Settings.tsx -> src/components/Settings/AllSettingsFields.tsx -> src/components/LspProvider.tsx -> src/editor/plugins/lsp/kcl/language.ts -> src/editor/plugins/lsp/kcl/index.ts 12) src/lib/singletons.ts -> src/clientSideScene/sceneEntities.ts -> src/clientSideScene/segments.ts -> src/machines/commandBarMachine.ts -> src/lib/commandBarConfigs/authCommandConfig.ts -> src/machines/appMachine.ts -> src/machines/settingsMachine.ts -> src/lib/commandBarConfigs/settingsCommandConfig.ts -> src/lib/createMachineCommand.ts -> src/routes/Settings.tsx -> src/components/Settings/AllSettingsFields.tsx -> src/components/LspProvider.tsx 13) src/machines/appMachine.ts -> src/machines/settingsMachine.ts -> src/lib/commandBarConfigs/settingsCommandConfig.ts -> src/lib/createMachineCommand.ts -> src/routes/Settings.tsx -> src/components/Settings/AllSettingsFields.tsx -> src/components/LspProvider.tsx 14) src/machines/appMachine.ts -> src/machines/settingsMachine.ts -> src/lib/commandBarConfigs/settingsCommandConfig.ts -> src/lib/createMachineCommand.ts -> src/routes/Settings.tsx -> src/components/Settings/AllSettingsFields.tsx -> src/components/Settings/SettingsFieldInput.tsx 15) src/machines/appMachine.ts -> src/machines/settingsMachine.ts -> src/lib/commandBarConfigs/settingsCommandConfig.ts -> src/lib/createMachineCommand.ts -> src/routes/Settings.tsx -> src/components/Settings/AllSettingsFields.tsx 16) src/routes/Settings.tsx -> src/components/Settings/AllSettingsFields.tsx 17) src/machines/appMachine.ts -> src/machines/settingsMachine.ts -> src/lib/commandBarConfigs/settingsCommandConfig.ts -> src/lib/createMachineCommand.ts -> src/routes/Settings.tsx -> src/components/Settings/SettingsSearchBar.tsx 18) src/machines/appMachine.ts -> src/machines/settingsMachine.ts -> src/lib/commandBarConfigs/settingsCommandConfig.ts -> src/lib/createMachineCommand.ts -> src/routes/Settings.tsx -> src/components/Settings/SettingsSectionsList.tsx 19) src/lib/singletons.ts -> src/clientSideScene/sceneEntities.ts -> src/clientSideScene/segments.ts -> src/machines/commandBarMachine.ts -> src/lib/commandBarConfigs/authCommandConfig.ts -> src/machines/appMachine.ts -> src/machines/settingsMachine.ts 20) src/machines/commandBarMachine.ts -> src/lib/commandBarConfigs/authCommandConfig.ts -> src/machines/appMachine.ts -> src/machines/settingsMachine.ts 21) src/hooks/useModelingContext.ts -> src/components/ModelingMachineProvider.tsx -> src/components/Toolbar/Intersect.tsx -> src/components/SetHorVertDistanceModal.tsx -> src/lib/useCalculateKclExpression.ts 22) src/components/ToastTextToCad.tsx -> src/lib/textToCad.ts 23) src/hooks/useModelingContext.ts -> src/components/ModelingMachineProvider.tsx -> src/machines/modelingMachine.ts -> src/clientSideScene/ClientSideSceneComp.tsx 24) src/routes/Onboarding/index.tsx -> src/routes/Onboarding/Camera.tsx -> src/routes/Onboarding/utils.tsx \ No newline at end of file +$ dpdm --no-warning --no-tree -T --skip-dynamic-imports=circular src/index.tsx +• Circular Dependencies + 01) src/lang/std/sketch.ts -> src/lang/modifyAst.ts -> src/lang/modifyAst/addEdgeTreatment.ts + 02) src/lang/std/sketch.ts -> src/lang/modifyAst.ts + 03) src/lang/std/sketch.ts -> src/lang/modifyAst.ts -> src/lang/std/sketchcombos.ts + 04) src/lib/singletons.ts -> src/editor/manager.ts -> src/lib/selections.ts + 05) src/lib/singletons.ts -> src/lang/KclSingleton.ts + 06) src/lib/singletons.ts -> src/lang/codeManager.ts + 07) src/lib/singletons.ts -> src/clientSideScene/sceneEntities.ts -> src/clientSideScene/segments.ts -> src/components/Toolbar/angleLengthInfo.ts + 08) src/lib/singletons.ts -> src/clientSideScene/sceneEntities.ts -> src/clientSideScene/segments.ts -> src/machines/commandBarMachine.ts -> src/lib/commandBarConfigs/authCommandConfig.ts -> src/machines/appMachine.ts -> src/machines/settingsMachine.ts + 09) src/machines/commandBarMachine.ts -> src/lib/commandBarConfigs/authCommandConfig.ts -> src/machines/appMachine.ts -> src/machines/settingsMachine.ts + 10) src/hooks/useModelingContext.ts -> src/components/ModelingMachineProvider.tsx -> src/components/Toolbar/Intersect.tsx -> src/components/SetHorVertDistanceModal.tsx -> src/lib/useCalculateKclExpression.ts + 11) src/routes/Onboarding/index.tsx -> src/routes/Onboarding/Camera.tsx -> src/routes/Onboarding/utils.tsx diff --git a/package.json b/package.json index cfe7682e3..984494660 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,7 @@ "lint-fix": "eslint --fix --ext .ts --ext .tsx src e2e packages/codemirror-lsp-client/src rust/kcl-language-server/client/src", "lint": "eslint --max-warnings 0 --ext .ts --ext .tsx src e2e packages/codemirror-lsp-client/src rust/kcl-language-server/client/src", "circular-deps": "dpdm --no-warning --no-tree -T --skip-dynamic-imports=circular src/index.tsx", + "circular-deps:overwrite": "yarn circular-deps | sed '$d' | grep -v '^yarn run' > known-circular.txt", "circular-deps:diff": "./scripts/diff-circular-deps.sh", "files:set-version": "echo \"$(jq --arg v \"$VERSION\" '.version=$v' package.json --indent 2)\" > package.json", "files:set-notes": "./scripts/set-files-notes.sh", diff --git a/scripts/diff-circular-deps.sh b/scripts/diff-circular-deps.sh index 808f8c783..71ba2cdcb 100755 --- a/scripts/diff-circular-deps.sh +++ b/scripts/diff-circular-deps.sh @@ -1,5 +1,5 @@ #!/bin/bash set -euo pipefail -yarn circular-deps | sed '$d' | grep -v '^yarn run' | tr -d '\n' > /tmp/circular-deps.txt -diff -w /tmp/circular-deps.txt ./known-circular.txt +yarn circular-deps | sed '$d' | grep -v '^yarn run' > /tmp/circular-deps.txt +diff --ignore-blank-lines -w /tmp/circular-deps.txt ./known-circular.txt diff --git a/src/clientSideScene/CameraControls.ts b/src/clientSideScene/CameraControls.ts index a25d3bf99..8272b0179 100644 --- a/src/clientSideScene/CameraControls.ts +++ b/src/clientSideScene/CameraControls.ts @@ -20,7 +20,7 @@ import { INTERSECTION_PLANE_LAYER, SKETCH_LAYER, ZOOM_MAGIC_NUMBER, -} from '@src/clientSideScene/sceneInfra' +} from '@src/clientSideScene/sceneUtils' import type { EngineCommand } from '@src/lang/std/artifactGraph' import type { EngineCommandManager, diff --git a/src/clientSideScene/ClientSideSceneComp.tsx b/src/clientSideScene/ClientSideSceneComp.tsx index 106734c5c..58a36be52 100644 --- a/src/clientSideScene/ClientSideSceneComp.tsx +++ b/src/clientSideScene/ClientSideSceneComp.tsx @@ -1,8 +1,6 @@ -import { Dialog, Popover, Transition } from '@headlessui/react' -import { Fragment, useEffect, useMemo, useRef, useState } from 'react' +import { Popover } from '@headlessui/react' +import { useEffect, useMemo, useRef, useState } from 'react' import toast from 'react-hot-toast' -import type { InstanceProps } from 'react-modal-promise' -import { create } from 'react-modal-promise' import type { Node } from '@rust/kcl-lib/bindings/Node' @@ -15,16 +13,11 @@ import { import { ARROWHEAD, DEBUG_SHOW_BOTH_SCENES, -} from '@src/clientSideScene/sceneInfra' -import { ActionButton } from '@src/components/ActionButton' +} from '@src/clientSideScene/sceneUtils' import type { CustomIconName } from '@src/components/CustomIcon' import { CustomIcon } from '@src/components/CustomIcon' import { useModelingContext } from '@src/hooks/useModelingContext' -import { executeAstMock } from '@src/lang/langHelpers' -import { - deleteSegmentFromPipeExpression, - removeSingleConstraintInfo, -} from '@src/lang/modifyAst' +import { removeSingleConstraintInfo } from '@src/lang/modifyAst' import { findUsesOfTagInPipe, getNodeFromPath } from '@src/lang/queryAst' import { getConstraintInfo, getConstraintInfoKw } from '@src/lang/std/sketch' import type { ConstrainInfo } from '@src/lang/std/stdTypes' @@ -34,7 +27,6 @@ import type { CallExpressionKw, Expr, PathToNode, - Program, } from '@src/lang/wasm' import { defaultSourceRange, parse, recast, resultIsOk } from '@src/lang/wasm' import { cameraMouseDragGuards } from '@src/lib/cameraControls' @@ -43,7 +35,6 @@ import { editorManager, engineCommandManager, kclManager, - rustContext, sceneEntitiesManager, sceneInfra, } from '@src/lib/singletons' @@ -51,10 +42,7 @@ import { err, reportRejection, trap } from '@src/lib/trap' import { throttle, toSync } from '@src/lib/utils' import type { useSettings } from '@src/machines/appMachine' import { commandBarActor } from '@src/machines/commandBarMachine' -import type { - SegmentOverlay, - SketchDetails, -} from '@src/machines/modelingMachine' +import type { SegmentOverlay } from '@src/machines/modelingMachine' function useShouldHideScene(): { hideClient: boolean; hideServer: boolean } { const [isCamMoving, setIsCamMoving] = useState(false) @@ -343,130 +331,6 @@ const Overlay = ({ ) } -type ConfirmModalProps = InstanceProps & { text: string } - -export const ConfirmModal = ({ - isOpen, - onResolve, - onReject, - text, -}: ConfirmModalProps) => { - return ( - - onResolve(false)} - > - -
- - -
-
- - -
{text}
-
- onResolve(true)} - > - Continue and unconstrain - - onReject(false)} - > - Cancel - -
-
-
-
-
-
-
- ) -} - -export const confirmModal = create( - ConfirmModal -) - -export async function deleteSegment({ - pathToNode, - sketchDetails, -}: { - pathToNode: PathToNode - sketchDetails: SketchDetails | null -}) { - let modifiedAst: Node | Error = kclManager.ast - const dependentRanges = findUsesOfTagInPipe(modifiedAst, pathToNode) - - const shouldContinueSegDelete = dependentRanges.length - ? await confirmModal({ - text: `At least ${dependentRanges.length} segment rely on the segment you're deleting.\nDo you want to continue and unconstrain these segments?`, - isOpen: true, - }) - : true - - if (!shouldContinueSegDelete) return - - modifiedAst = deleteSegmentFromPipeExpression( - dependentRanges, - modifiedAst, - kclManager.variables, - codeManager.code, - pathToNode - ) - if (err(modifiedAst)) return Promise.reject(modifiedAst) - - const newCode = recast(modifiedAst) - const pResult = parse(newCode) - if (err(pResult) || !resultIsOk(pResult)) return Promise.reject(pResult) - modifiedAst = pResult.program - - const testExecute = await executeAstMock({ - ast: modifiedAst, - usePrevMemory: false, - rustContext: rustContext, - }) - if (testExecute.errors.length) { - toast.error('Segment tag used outside of current Sketch. Could not delete.') - return - } - - if (!sketchDetails) return - await sceneEntitiesManager.updateAstAndRejigSketch( - pathToNode, - sketchDetails.sketchNodePaths, - sketchDetails.planeNodePath, - modifiedAst, - sketchDetails.zAxis, - sketchDetails.yAxis, - sketchDetails.origin - ) - - // Now 'Set sketchDetails' is called with the modified pathToNode -} - const SegmentMenu = ({ verticalPosition, pathToNode, diff --git a/src/clientSideScene/confirmModal.tsx b/src/clientSideScene/confirmModal.tsx new file mode 100644 index 000000000..778a9aa3f --- /dev/null +++ b/src/clientSideScene/confirmModal.tsx @@ -0,0 +1,72 @@ +import { Fragment } from 'react' +import { create, type InstanceProps } from 'react-modal-promise' + +import { Dialog, Transition } from '@headlessui/react' +import { ActionButton } from '@src/components/ActionButton' + +type ConfirmModalProps = InstanceProps & { text: string } + +export const ConfirmModal = ({ + isOpen, + onResolve, + onReject, + text, +}: ConfirmModalProps) => { + return ( + + onResolve(false)} + > + +
+ + +
+
+ + +
{text}
+
+ onResolve(true)} + > + Continue and unconstrain + + onReject(false)} + > + Cancel + +
+
+
+
+
+
+
+ ) +} + +export const confirmModal = create( + ConfirmModal +) diff --git a/src/clientSideScene/deleteSegment.ts b/src/clientSideScene/deleteSegment.ts new file mode 100644 index 000000000..4246d53ce --- /dev/null +++ b/src/clientSideScene/deleteSegment.ts @@ -0,0 +1,75 @@ +import toast from 'react-hot-toast' + +import type { Node } from '@rust/kcl-lib/bindings/Node' + +import { confirmModal } from '@src/clientSideScene/confirmModal' +import { executeAstMock } from '@src/lang/langHelpers' +import { deleteSegmentFromPipeExpression } from '@src/lang/modifyAst' +import { findUsesOfTagInPipe } from '@src/lang/queryAst' +import type { PathToNode, Program } from '@src/lang/wasm' +import { parse, recast, resultIsOk } from '@src/lang/wasm' +import { + codeManager, + kclManager, + rustContext, + sceneEntitiesManager, +} from '@src/lib/singletons' +import { err } from '@src/lib/trap' +import type { SketchDetails } from '@src/machines/modelingMachine' + +export async function deleteSegment({ + pathToNode, + sketchDetails, +}: { + pathToNode: PathToNode + sketchDetails: SketchDetails | null +}) { + let modifiedAst: Node | Error = kclManager.ast + const dependentRanges = findUsesOfTagInPipe(modifiedAst, pathToNode) + + const shouldContinueSegDelete = dependentRanges.length + ? await confirmModal({ + text: `At least ${dependentRanges.length} segment rely on the segment you're deleting.\nDo you want to continue and unconstrain these segments?`, + isOpen: true, + }) + : true + + if (!shouldContinueSegDelete) return + + modifiedAst = deleteSegmentFromPipeExpression( + dependentRanges, + modifiedAst, + kclManager.variables, + codeManager.code, + pathToNode + ) + if (err(modifiedAst)) return Promise.reject(modifiedAst) + + const newCode = recast(modifiedAst) + const pResult = parse(newCode) + if (err(pResult) || !resultIsOk(pResult)) return Promise.reject(pResult) + modifiedAst = pResult.program + + const testExecute = await executeAstMock({ + ast: modifiedAst, + usePrevMemory: false, + rustContext: rustContext, + }) + if (testExecute.errors.length) { + toast.error('Segment tag used outside of current Sketch. Could not delete.') + return + } + + if (!sketchDetails) return + await sceneEntitiesManager.updateAstAndRejigSketch( + pathToNode, + sketchDetails.sketchNodePaths, + sketchDetails.planeNodePath, + modifiedAst, + sketchDetails.zAxis, + sketchDetails.yAxis, + sketchDetails.origin + ) + + // Now 'Set sketchDetails' is called with the modified pathToNode +} diff --git a/src/clientSideScene/sceneEntities.ts b/src/clientSideScene/sceneEntities.ts index 697bfc773..8dffef924 100644 --- a/src/clientSideScene/sceneEntities.ts +++ b/src/clientSideScene/sceneEntities.ts @@ -86,7 +86,7 @@ import { X_AXIS, Y_AXIS, getSceneScale, -} from '@src/clientSideScene/sceneInfra' +} from '@src/clientSideScene/sceneUtils' import type { SegmentUtils } from '@src/clientSideScene/segments' import { createProfileStartHandle, diff --git a/src/clientSideScene/sceneInfra.ts b/src/clientSideScene/sceneInfra.ts index b889c1fbb..67f306061 100644 --- a/src/clientSideScene/sceneInfra.ts +++ b/src/clientSideScene/sceneInfra.ts @@ -14,7 +14,6 @@ import { GridHelper, LineBasicMaterial, OrthographicCamera, - PerspectiveCamera, Raycaster, Scene, TextureLoader, @@ -26,6 +25,16 @@ import { CSS2DRenderer } from 'three/examples/jsm/renderers/CSS2DRenderer' import { CameraControls } from '@src/clientSideScene/CameraControls' import { orthoScale, perspScale } from '@src/clientSideScene/helpers' +import { + AXIS_GROUP, + DEBUG_SHOW_INTERSECTION_PLANE, + INTERSECTION_PLANE_LAYER, + RAYCASTABLE_PLANE, + SKETCH_LAYER, + X_AXIS, + Y_AXIS, + getSceneScale, +} from '@src/clientSideScene/sceneUtils' import type { useModelingContext } from '@src/hooks/useModelingContext' import type { EngineCommandManager } from '@src/lang/std/engineConnection' import type { Coords2d } from '@src/lang/std/sketch' @@ -41,37 +50,6 @@ import type { type SendType = ReturnType['send'] -// 63.5 is definitely a bit of a magic number, play with it until it looked right -// if it were 64, that would feel like it's something in the engine where a random -// power of 2 is used, but it's the 0.5 seems to make things look much more correct -export const ZOOM_MAGIC_NUMBER = 63.5 - -export const INTERSECTION_PLANE_LAYER = 1 -export const SKETCH_LAYER = 2 - -// redundant types so that it can be changed temporarily but CI will catch the wrong type -export const DEBUG_SHOW_INTERSECTION_PLANE = false -export const DEBUG_SHOW_BOTH_SCENES = false - -export const RAYCASTABLE_PLANE = 'raycastable-plane' - -export const X_AXIS = 'xAxis' -export const Y_AXIS = 'yAxis' -/** If a segment angle is less than this many degrees off a meanginful angle it'll snap to it */ -export const ANGLE_SNAP_THRESHOLD_DEGREES = 3 -/** the THREEjs representation of the group surrounding a "snapped" point that is not yet placed */ -export const DRAFT_POINT_GROUP = 'draft-point-group' -/** the THREEjs representation of a "snapped" point that is not yet placed */ -export const DRAFT_POINT = 'draft-point' -export const AXIS_GROUP = 'axisGroup' -export const SKETCH_GROUP_SEGMENTS = 'sketch-group-segments' -export const ARROWHEAD = 'arrowhead' -export const SEGMENT_LENGTH_LABEL = 'segment-length-label' -export const SEGMENT_LENGTH_LABEL_TEXT = 'segment-length-label-text' -export const SEGMENT_LENGTH_LABEL_OFFSET_PX = 30 -export const CIRCLE_3_POINT_DRAFT_POINT = 'circle-3-point-draft-point' -export const CIRCLE_3_POINT_DRAFT_CIRCLE = 'circle-3-point-draft-circle' - export interface OnMouseEnterLeaveArgs { selected: Object3D dragSelected?: Object3D @@ -689,24 +667,6 @@ export class SceneInfra { } } -export function getSceneScale( - camera: PerspectiveCamera | OrthographicCamera, - target: Vector3 -): number { - const distance = - camera instanceof PerspectiveCamera - ? camera.position.distanceTo(target) - : 63.7942123 / camera.zoom - - if (distance <= 20) return 0.1 - else if (distance > 20 && distance <= 200) return 1 - else if (distance > 200 && distance <= 2000) return 10 - else if (distance > 2000 && distance <= 20000) return 100 - else if (distance > 20000) return 1000 - - return 1 -} - function baseUnitTomm(baseUnit: BaseUnit) { switch (baseUnit) { case 'mm': diff --git a/src/clientSideScene/sceneUtils.ts b/src/clientSideScene/sceneUtils.ts index e69de29bb..d688e3bcc 100644 --- a/src/clientSideScene/sceneUtils.ts +++ b/src/clientSideScene/sceneUtils.ts @@ -0,0 +1,52 @@ +// 63.5 is definitely a bit of a magic number, play with it until it looked right +// if it were 64, that would feel like it's something in the engine where a random + +import type { OrthographicCamera, Vector3 } from 'three' +import { PerspectiveCamera } from 'three' + +// power of 2 is used, but it's the 0.5 seems to make things look much more correct +export const ZOOM_MAGIC_NUMBER = 63.5 + +export const INTERSECTION_PLANE_LAYER = 1 +export const SKETCH_LAYER = 2 + +// redundant types so that it can be changed temporarily but CI will catch the wrong type +export const DEBUG_SHOW_INTERSECTION_PLANE = false +export const DEBUG_SHOW_BOTH_SCENES = false + +export const RAYCASTABLE_PLANE = 'raycastable-plane' + +export const X_AXIS = 'xAxis' +export const Y_AXIS = 'yAxis' +/** If a segment angle is less than this many degrees off a meanginful angle it'll snap to it */ +export const ANGLE_SNAP_THRESHOLD_DEGREES = 3 +/** the THREEjs representation of the group surrounding a "snapped" point that is not yet placed */ +export const DRAFT_POINT_GROUP = 'draft-point-group' +/** the THREEjs representation of a "snapped" point that is not yet placed */ +export const DRAFT_POINT = 'draft-point' +export const AXIS_GROUP = 'axisGroup' +export const SKETCH_GROUP_SEGMENTS = 'sketch-group-segments' +export const ARROWHEAD = 'arrowhead' +export const SEGMENT_LENGTH_LABEL = 'segment-length-label' +export const SEGMENT_LENGTH_LABEL_TEXT = 'segment-length-label-text' +export const SEGMENT_LENGTH_LABEL_OFFSET_PX = 30 +export const CIRCLE_3_POINT_DRAFT_POINT = 'circle-3-point-draft-point' +export const CIRCLE_3_POINT_DRAFT_CIRCLE = 'circle-3-point-draft-circle' + +export function getSceneScale( + camera: PerspectiveCamera | OrthographicCamera, + target: Vector3 +): number { + const distance = + camera instanceof PerspectiveCamera + ? camera.position.distanceTo(target) + : 63.7942123 / camera.zoom + + if (distance <= 20) return 0.1 + else if (distance > 20 && distance <= 200) return 1 + else if (distance > 200 && distance <= 2000) return 10 + else if (distance > 2000 && distance <= 20000) return 100 + else if (distance > 20000) return 1000 + + return 1 +} diff --git a/src/clientSideScene/segments.ts b/src/clientSideScene/segments.ts index f23fa0841..9a393ed21 100644 --- a/src/clientSideScene/segments.ts +++ b/src/clientSideScene/segments.ts @@ -71,7 +71,7 @@ import { SEGMENT_LENGTH_LABEL, SEGMENT_LENGTH_LABEL_OFFSET_PX, SEGMENT_LENGTH_LABEL_TEXT, -} from '@src/clientSideScene/sceneInfra' +} from '@src/clientSideScene/sceneUtils' import { angleLengthInfo } from '@src/components/Toolbar/angleLengthInfo' import type { Coords2d } from '@src/lang/std/sketch' import type { SegmentInputs } from '@src/lang/std/stdTypes' diff --git a/src/components/LowerRightControls.tsx b/src/components/LowerRightControls.tsx index 5666422aa..aa1df45c8 100644 --- a/src/components/LowerRightControls.tsx +++ b/src/components/LowerRightControls.tsx @@ -13,7 +13,7 @@ import type { CoreDumpManager } from '@src/lib/coredump' import openWindow, { openExternalBrowserIfDesktop } from '@src/lib/openWindow' import { PATHS } from '@src/lib/paths' import { reportRejection } from '@src/lib/trap' -import { APP_VERSION, getReleaseUrl } from '@src/routes/Settings' +import { APP_VERSION, getReleaseUrl } from '@src/routes/utils' export function LowerRightControls({ children, diff --git a/src/components/Settings/AllSettingsFields.tsx b/src/components/Settings/AllSettingsFields.tsx index 167f0440c..02c33f974 100644 --- a/src/components/Settings/AllSettingsFields.tsx +++ b/src/components/Settings/AllSettingsFields.tsx @@ -30,7 +30,7 @@ import { import { reportRejection } from '@src/lib/trap' import { toSync } from '@src/lib/utils' import { settingsActor, useSettings } from '@src/machines/appMachine' -import { APP_VERSION, IS_NIGHTLY, getReleaseUrl } from '@src/routes/Settings' +import { APP_VERSION, IS_NIGHTLY, getReleaseUrl } from '@src/routes/utils' interface AllSettingsFieldsProps { searchParamTab: SettingsLevel diff --git a/src/components/ToastTextToCad.tsx b/src/components/ToastTextToCad.tsx index 56875a123..c039acef3 100644 --- a/src/components/ToastTextToCad.tsx +++ b/src/components/ToastTextToCad.tsx @@ -30,7 +30,7 @@ import { isDesktop } from '@src/lib/isDesktop' import { openExternalBrowserIfDesktop } from '@src/lib/openWindow' import { PATHS } from '@src/lib/paths' import { codeManager, kclManager } from '@src/lib/singletons' -import { sendTelemetry } from '@src/lib/textToCad' +import { sendTelemetry } from '@src/lib/textToCadTelemetry' import type { Themes } from '@src/lib/theme' import { reportRejection } from '@src/lib/trap' import { commandBarActor } from '@src/machines/commandBarMachine' diff --git a/src/components/ToastUpdate.tsx b/src/components/ToastUpdate.tsx index 208ade576..f46e0b865 100644 --- a/src/components/ToastUpdate.tsx +++ b/src/components/ToastUpdate.tsx @@ -5,7 +5,7 @@ import toast from 'react-hot-toast' import { ActionButton } from '@src/components/ActionButton' import { SafeRenderer } from '@src/lib/markdown' import { openExternalBrowserIfDesktop } from '@src/lib/openWindow' -import { getReleaseUrl } from '@src/routes/Settings' +import { getReleaseUrl } from '@src/routes/utils' export function ToastUpdate({ version, diff --git a/src/editor/manager.ts b/src/editor/manager.ts index b6492bf53..0991b4e53 100644 --- a/src/editor/manager.ts +++ b/src/editor/manager.ts @@ -11,10 +11,11 @@ import { addLineHighlight, addLineHighlightEvent, } from '@src/editor/highlightextension' +import type { KclManager } from '@src/lang/KclSingleton' +import type { EngineCommandManager } from '@src/lang/std/engineConnection' import { markOnce } from '@src/lib/performance' import type { Selection, Selections } from '@src/lib/selections' import { processCodeMirrorRanges } from '@src/lib/selections' -import { engineCommandManager, kclManager } from '@src/lib/singletons' import { kclEditorActor } from '@src/machines/kclEditorMachine' import type { ModelingMachineEvent, @@ -44,6 +45,8 @@ export const setDiagnosticsEvent = setDiagnosticsAnnotation.of(true) export default class EditorManager { private _copilotEnabled: boolean = true + private engineCommandManager: EngineCommandManager + private kclManager: KclManager private _isAllTextSelected: boolean = false private _isShiftDown: boolean = false @@ -64,6 +67,14 @@ export default class EditorManager { public _editorView: EditorView | null = null + constructor( + engineCommandManager: EngineCommandManager, + kclManager: KclManager + ) { + this.engineCommandManager = engineCommandManager + this.kclManager = kclManager + } + setCopilotEnabled(enabled: boolean) { this._copilotEnabled = enabled } @@ -379,8 +390,8 @@ export default class EditorManager { codeMirrorRanges: viewUpdate.state.selection.ranges, selectionRanges: this._selectionRanges, isShiftDown: this._isShiftDown, - ast: kclManager.ast, - artifactGraph: kclManager.artifactGraph, + ast: this.kclManager.ast, + artifactGraph: this.kclManager.artifactGraph, }) if (!eventInfo) { @@ -407,7 +418,7 @@ export default class EditorManager { this._modelingSend(eventInfo.modelingEvent) eventInfo.engineEvents.forEach((event) => { // eslint-disable-next-line @typescript-eslint/no-floating-promises - engineCommandManager.sendSceneCommand(event) + this.engineCommandManager.sendSceneCommand(event) }) } } diff --git a/src/lib/commandBarConfigs/modelingCommandConfig.ts b/src/lib/commandBarConfigs/modelingCommandConfig.ts index 00f115981..c586d061d 100644 --- a/src/lib/commandBarConfigs/modelingCommandConfig.ts +++ b/src/lib/commandBarConfigs/modelingCommandConfig.ts @@ -28,7 +28,7 @@ import type { Selections } from '@src/lib/selections' import { codeManager, kclManager } from '@src/lib/singletons' import { err } from '@src/lib/trap' import type { SketchTool, modelingMachine } from '@src/machines/modelingMachine' -import { IS_NIGHTLY_OR_DEBUG } from '@src/routes/Settings' +import { IS_NIGHTLY_OR_DEBUG } from '@src/routes/utils' type OutputFormat = Models['OutputFormat3d_type'] type OutputTypeKey = OutputFormat['type'] diff --git a/src/lib/coredump.ts b/src/lib/coredump.ts index 384aa53b4..fa528c4ff 100644 --- a/src/lib/coredump.ts +++ b/src/lib/coredump.ts @@ -12,7 +12,7 @@ import type { import { isDesktop } from '@src/lib/isDesktop' import type RustContext from '@src/lib/rustContext' import screenshot from '@src/lib/screenshot' -import { APP_VERSION } from '@src/routes/Settings' +import { APP_VERSION } from '@src/routes/utils' /* eslint-disable suggest-no-throw/suggest-no-throw -- * All the throws in CoreDumpManager are intentional and should be caught and handled properly diff --git a/src/lib/createMachineCommand.ts b/src/lib/createMachineCommand.ts index 501ffd5ab..4a8504940 100644 --- a/src/lib/createMachineCommand.ts +++ b/src/lib/createMachineCommand.ts @@ -16,7 +16,7 @@ import type { StateMachineCommandSetSchema, } from '@src/lib/commandTypes' import { isDesktop } from '@src/lib/isDesktop' -import { IS_NIGHTLY_OR_DEBUG } from '@src/routes/Settings' +import { IS_NIGHTLY_OR_DEBUG } from '@src/routes/utils' interface CreateMachineCommandProps< T extends AnyStateMachine, diff --git a/src/lib/selections.ts b/src/lib/selections.ts index ff548d54c..a0196234d 100644 --- a/src/lib/selections.ts +++ b/src/lib/selections.ts @@ -10,7 +10,7 @@ import { SEGMENT_BODIES_PLUS_PROFILE_START, getParentGroup, } from '@src/clientSideScene/sceneConstants' -import { AXIS_GROUP, X_AXIS } from '@src/clientSideScene/sceneInfra' +import { AXIS_GROUP, X_AXIS } from '@src/clientSideScene/sceneUtils' import { getNodeFromPath, isSingleCursorInPipe } from '@src/lang/queryAst' import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' import type { Artifact, ArtifactId, CodeRef } from '@src/lang/std/artifactGraph' diff --git a/src/lib/singletons.ts b/src/lib/singletons.ts index 99cf2bece..6b4de6ae6 100644 --- a/src/lib/singletons.ts +++ b/src/lib/singletons.ts @@ -34,7 +34,7 @@ kclManager.sceneInfraBaseUnitMultiplierSetter = (unit: BaseUnit) => { } // This needs to be after sceneInfra and engineCommandManager are is created. -export const editorManager = new EditorManager() +export const editorManager = new EditorManager(engineCommandManager, kclManager) export const rustContext = new RustContext(engineCommandManager) diff --git a/src/lib/textToCad.ts b/src/lib/textToCad.ts index d4b3db734..29e9e307b 100644 --- a/src/lib/textToCad.ts +++ b/src/lib/textToCad.ts @@ -251,19 +251,3 @@ export async function submitAndAwaitTextToKcl({ ) return textToCadOutputCreated } - -export async function sendTelemetry( - id: string, - feedback: Models['MlFeedback_type'], - token?: string -): Promise { - const url = - VITE_KC_API_BASE_URL + '/user/text-to-cad/' + id + '?feedback=' + feedback - await crossPlatformFetch( - url, - { - method: 'POST', - }, - token - ) -} diff --git a/src/lib/textToCadTelemetry.ts b/src/lib/textToCadTelemetry.ts new file mode 100644 index 000000000..a5c336522 --- /dev/null +++ b/src/lib/textToCadTelemetry.ts @@ -0,0 +1,19 @@ +import type { Models } from '@kittycad/lib/dist/types/src' +import { VITE_KC_API_BASE_URL } from '@src/env' +import crossPlatformFetch from '@src/lib/crossPlatformFetch' + +export async function sendTelemetry( + id: string, + feedback: Models['MlFeedback_type'], + token?: string +): Promise { + const url = + VITE_KC_API_BASE_URL + '/user/text-to-cad/' + id + '?feedback=' + feedback + await crossPlatformFetch( + url, + { + method: 'POST', + }, + token + ) +} diff --git a/src/lib/toolbar.ts b/src/lib/toolbar.ts index edc60cd2c..3a89c8d08 100644 --- a/src/lib/toolbar.ts +++ b/src/lib/toolbar.ts @@ -9,7 +9,7 @@ import { isEditingExistingSketch, pipeHasCircle, } from '@src/machines/modelingMachine' -import { IS_NIGHTLY_OR_DEBUG } from '@src/routes/Settings' +import { IS_NIGHTLY_OR_DEBUG } from '@src/routes/utils' export type ToolbarModeName = 'modeling' | 'sketching' diff --git a/src/machines/modelingMachine.ts b/src/machines/modelingMachine.ts index bc9ac3bc9..a1823be4f 100644 --- a/src/machines/modelingMachine.ts +++ b/src/machines/modelingMachine.ts @@ -4,13 +4,13 @@ import { assign, fromPromise, setup } from 'xstate' import type { Node } from '@rust/kcl-lib/bindings/Node' -import { deleteSegment } from '@src/clientSideScene/ClientSideSceneComp' +import { deleteSegment } from '@src/clientSideScene/deleteSegment' import { orthoScale, quaternionFromUpNForward, } from '@src/clientSideScene/helpers' import { DRAFT_DASHED_LINE } from '@src/clientSideScene/sceneConstants' -import { DRAFT_POINT } from '@src/clientSideScene/sceneInfra' +import { DRAFT_POINT } from '@src/clientSideScene/sceneUtils' import { createProfileStartHandle } from '@src/clientSideScene/segments' import type { MachineManager } from '@src/components/MachineManagerProvider' import type { ModelingMachineContext } from '@src/components/ModelingMachineProvider' diff --git a/src/routes/Settings.tsx b/src/routes/Settings.tsx index 287f8340f..c19962f36 100644 --- a/src/routes/Settings.tsx +++ b/src/routes/Settings.tsx @@ -1,11 +1,8 @@ import { Dialog, Transition } from '@headlessui/react' -import { NODE_ENV } from '@src/env' import { Fragment, useEffect, useRef } from 'react' import { useHotkeys } from 'react-hotkeys-hook' import { useLocation, useNavigate, useSearchParams } from 'react-router-dom' -import { IS_PLAYWRIGHT_KEY } from '@e2e/playwright/storageStates' - import { CustomIcon } from '@src/components/CustomIcon' import { AllKeybindingsFields } from '@src/components/Settings/AllKeybindingsFields' import { AllSettingsFields } from '@src/components/Settings/AllSettingsFields' @@ -14,35 +11,9 @@ import { SettingsSearchBar } from '@src/components/Settings/SettingsSearchBar' import { SettingsSectionsList } from '@src/components/Settings/SettingsSectionsList' import { SettingsTabs } from '@src/components/Settings/SettingsTabs' import { useDotDotSlash } from '@src/hooks/useDotDotSlash' -import { isDesktop } from '@src/lib/isDesktop' import { PATHS } from '@src/lib/paths' import type { SettingsLevel } from '@src/lib/settings/settingsTypes' -const isTestEnv = window?.localStorage.getItem(IS_PLAYWRIGHT_KEY) === 'true' - -export const APP_VERSION = - isTestEnv && NODE_ENV === 'development' - ? '11.22.33' - : isDesktop() - ? // @ts-ignore - window.electron.packageJson.version - : 'main' - -export const PACKAGE_NAME = isDesktop() - ? window.electron.packageJson.name - : 'zoo-modeling-app' - -export const IS_NIGHTLY = PACKAGE_NAME.indexOf('-nightly') > -1 - -export const IS_NIGHTLY_OR_DEBUG = - IS_NIGHTLY || APP_VERSION === '0.0.0' || APP_VERSION === '11.22.33' - -export function getReleaseUrl(version: string = APP_VERSION) { - return `https://github.com/KittyCAD/modeling-app/releases/tag/${ - IS_NIGHTLY ? 'nightly-' : '' - }v${version}` -} - export const Settings = () => { const navigate = useNavigate() const [searchParams, setSearchParams] = useSearchParams() diff --git a/src/routes/SignIn.tsx b/src/routes/SignIn.tsx index 68f9e5047..1cd641287 100644 --- a/src/routes/SignIn.tsx +++ b/src/routes/SignIn.tsx @@ -15,7 +15,7 @@ import { Themes, getSystemTheme } from '@src/lib/theme' import { reportRejection } from '@src/lib/trap' import { toSync } from '@src/lib/utils' import { authActor, useSettings } from '@src/machines/appMachine' -import { APP_VERSION } from '@src/routes/Settings' +import { APP_VERSION } from '@src/routes/utils' const subtleBorder = 'border border-solid border-chalkboard-30 dark:border-chalkboard-80' diff --git a/src/routes/utils.ts b/src/routes/utils.ts new file mode 100644 index 000000000..5cadccea1 --- /dev/null +++ b/src/routes/utils.ts @@ -0,0 +1,29 @@ +import { NODE_ENV } from '@src/env' +import { isDesktop } from '@src/lib/isDesktop' + +import { IS_PLAYWRIGHT_KEY } from '@e2e/playwright/storageStates' + +const isTestEnv = window?.localStorage.getItem(IS_PLAYWRIGHT_KEY) === 'true' + +export const APP_VERSION = + isTestEnv && NODE_ENV === 'development' + ? '11.22.33' + : isDesktop() + ? // @ts-ignore + window.electron.packageJson.version + : 'main' + +export const PACKAGE_NAME = isDesktop() + ? window.electron.packageJson.name + : 'zoo-modeling-app' + +export const IS_NIGHTLY = PACKAGE_NAME.indexOf('-nightly') > -1 + +export const IS_NIGHTLY_OR_DEBUG = + IS_NIGHTLY || APP_VERSION === '0.0.0' || APP_VERSION === '11.22.33' + +export function getReleaseUrl(version: string = APP_VERSION) { + return `https://github.com/KittyCAD/modeling-app/releases/tag/${ + IS_NIGHTLY ? 'nightly-' : '' + }v${version}` +}