Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent length constraint creation on endAbsolute lines #5938

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
37 changes: 34 additions & 3 deletions src/clientSideScene/segments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from 'three'
import { mergeGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils.js'
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer'
import { PathToNode, Sketch, getTangentialArcToInfo } from 'lang/wasm'
import { Expr, PathToNode, Sketch, getTangentialArcToInfo } from 'lang/wasm'
import {
CIRCLE_CENTER_HANDLE,
CIRCLE_SEGMENT,
Expand Down Expand Up @@ -81,10 +81,12 @@ import {
} from 'machines/modelingMachine'
import { SegmentInputs } from 'lang/std/stdTypes'
import { err } from 'lib/trap'
import { sceneInfra } from 'lib/singletons'
import { Selections } from 'lib/selections'
import { engineCommandManager, sceneInfra } from 'lib/singletons'
import { Selection, Selections } from 'lib/selections'
import { calculate_circle_from_3_points } from '@rust/kcl-wasm-lib/pkg/kcl_wasm_lib'
import { commandBarActor } from 'machines/commandBarMachine'
import { getNodeFromPath } from 'lang/queryAst'
import toast from 'react-hot-toast'

const ANGLE_INDICATOR_RADIUS = 30 // in px
interface CreateSegmentArgs {
Expand Down Expand Up @@ -1701,6 +1703,35 @@ function createLengthIndicator({
console.error('Unable to dimension segment when clicking the label.')
return
}

if (engineCommandManager.kclManager !== null) {
if (
selection.graphSelections &&
selection.graphSelections[0] &&
selection.graphSelections[0].codeRef
) {
const graphSelection = selection.graphSelections[0] as Selection
const node = getNodeFromPath<Expr>(
engineCommandManager.kclManager.ast,
graphSelection.codeRef.pathToNode,
['CallExpressionKw']
)
if (!err(node)) {
const hasEndAbsolute =
node.node.type === 'CallExpressionKw' &&
node.node.arguments[0] &&
node.node.arguments[0].label.name === 'endAbsolute'
if (hasEndAbsolute) {
// Won't be able to constrain that length
toast.error(
'Unable to constrain the length of a segment with endAbsolute'
)
return
}
}
}
}

sceneInfra.modelingSend({
type: 'Set selection',
data: {
Expand Down
Loading