Compare commits
4 Commits
kurt-test-
...
v0.22.0
Author | SHA1 | Date | |
---|---|---|---|
8eee3e1c58 | |||
b02529cae0 | |||
cf03021366 | |||
f52d2d55f1 |
@ -1,7 +1,7 @@
|
|||||||
import { test, expect, Page } from '@playwright/test'
|
import { test, expect, Page } from '@playwright/test'
|
||||||
import { makeTemplate, getUtils, doExport } from './test-utils'
|
import { makeTemplate, getUtils, doExport } from './test-utils'
|
||||||
import waitOn from 'wait-on'
|
import waitOn from 'wait-on'
|
||||||
import { roundOff, uuidv4 } from 'lib/utils'
|
import { XOR, roundOff, uuidv4 } from 'lib/utils'
|
||||||
import { SaveSettingsPayload } from 'lib/settings/settingsTypes'
|
import { SaveSettingsPayload } from 'lib/settings/settingsTypes'
|
||||||
import { secrets } from './secrets'
|
import { secrets } from './secrets'
|
||||||
import {
|
import {
|
||||||
@ -2440,6 +2440,245 @@ test('Extrude from command bar selects extrude line after', async ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
test.describe('Testing constraints', () => {
|
test.describe('Testing constraints', () => {
|
||||||
|
test(`Test remove constraints`, async ({ page }) => {
|
||||||
|
await page.addInitScript(async () => {
|
||||||
|
localStorage.setItem(
|
||||||
|
'persistCode',
|
||||||
|
`const yo = 79
|
||||||
|
const part001 = startSketchOn('XZ')
|
||||||
|
|> startProfileAt([-7.54, -26.74], %)
|
||||||
|
|> line([74.36, 130.4], %, 'seg01')
|
||||||
|
|> line([78.92, -120.11], %)
|
||||||
|
|> angledLine([segAng('seg01', %), yo], %)
|
||||||
|
|> line([41.19, 28.97 + 5], %)
|
||||||
|
const part002 = startSketchOn('XZ')
|
||||||
|
|> startProfileAt([299.05, 231.45], %)
|
||||||
|
|> xLine(-425.34, %, 'seg-what')
|
||||||
|
|> yLine(-264.06, %)
|
||||||
|
|> xLine(segLen('seg-what', %), %)
|
||||||
|
|> lineTo([profileStartX(%), profileStartY(%)], %)`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
const u = await getUtils(page)
|
||||||
|
await page.setViewportSize({ width: 1200, height: 500 })
|
||||||
|
await page.goto('/')
|
||||||
|
await u.waitForAuthSkipAppStart()
|
||||||
|
|
||||||
|
await page.getByText("line([74.36, 130.4], %, 'seg01')").click()
|
||||||
|
await page.getByRole('button', { name: 'Edit Sketch' }).click()
|
||||||
|
|
||||||
|
const line3 = await u.getSegmentBodyCoords(`[data-overlay-index="${2}"]`)
|
||||||
|
|
||||||
|
// await page.mouse.click(line1.x, line1.y)
|
||||||
|
// await page.keyboard.down('Shift')
|
||||||
|
await page.mouse.click(line3.x, line3.y)
|
||||||
|
await page.waitForTimeout(100) // this wait is needed for webkit - not sure why
|
||||||
|
// await page.keyboard.up('Shift')
|
||||||
|
await page
|
||||||
|
.getByRole('button', {
|
||||||
|
name: 'Constrain',
|
||||||
|
})
|
||||||
|
.click()
|
||||||
|
await page
|
||||||
|
.getByRole('button', { name: 'remove constraints', exact: true })
|
||||||
|
.click()
|
||||||
|
|
||||||
|
const activeLinesContent = await page.locator('.cm-activeLine').all()
|
||||||
|
await expect(activeLinesContent).toHaveLength(1)
|
||||||
|
await expect(activeLinesContent[0]).toHaveText('|> line([39.13, 68.63], %)')
|
||||||
|
|
||||||
|
// checking the count of the overlays is a good proxy check that the client sketch scene is in a good state
|
||||||
|
await expect(page.getByTestId('segment-overlay')).toHaveCount(4)
|
||||||
|
})
|
||||||
|
test.describe('Test perpendicular distance constraint', () => {
|
||||||
|
const cases = [
|
||||||
|
{
|
||||||
|
testName: 'Add variable',
|
||||||
|
offset: '-offset001',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: 'No variable',
|
||||||
|
offset: '-128.05',
|
||||||
|
},
|
||||||
|
] as const
|
||||||
|
for (const { testName, offset } of cases) {
|
||||||
|
test(`${testName}`, async ({ page }) => {
|
||||||
|
await page.addInitScript(async () => {
|
||||||
|
localStorage.setItem(
|
||||||
|
'persistCode',
|
||||||
|
`const yo = 5
|
||||||
|
const part001 = startSketchOn('XZ')
|
||||||
|
|> startProfileAt([-7.54, -26.74], %)
|
||||||
|
|> line([74.36, 130.4], %, 'seg01')
|
||||||
|
|> line([78.92, -120.11], %)
|
||||||
|
|> angledLine([segAng('seg01', %), 78.33], %)
|
||||||
|
|> line([41.19, 28.97], %)
|
||||||
|
const part002 = startSketchOn('XZ')
|
||||||
|
|> startProfileAt([299.05, 231.45], %)
|
||||||
|
|> xLine(-425.34, %, 'seg-what')
|
||||||
|
|> yLine(-264.06, %)
|
||||||
|
|> xLine(segLen('seg-what', %), %)
|
||||||
|
|> lineTo([profileStartX(%), profileStartY(%)], %)`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
const u = await getUtils(page)
|
||||||
|
await page.setViewportSize({ width: 1200, height: 500 })
|
||||||
|
await page.goto('/')
|
||||||
|
await u.waitForAuthSkipAppStart()
|
||||||
|
|
||||||
|
await page.getByText("line([74.36, 130.4], %, 'seg01')").click()
|
||||||
|
await page.getByRole('button', { name: 'Edit Sketch' }).click()
|
||||||
|
|
||||||
|
const [line1, line3] = await Promise.all([
|
||||||
|
u.getSegmentBodyCoords(`[data-overlay-index="${0}"]`),
|
||||||
|
u.getSegmentBodyCoords(`[data-overlay-index="${2}"]`),
|
||||||
|
])
|
||||||
|
|
||||||
|
await page.mouse.click(line1.x, line1.y)
|
||||||
|
await page.keyboard.down('Shift')
|
||||||
|
await page.mouse.click(line3.x, line3.y)
|
||||||
|
await page.waitForTimeout(100) // this wait is needed for webkit - not sure why
|
||||||
|
await page.keyboard.up('Shift')
|
||||||
|
await page
|
||||||
|
.getByRole('button', {
|
||||||
|
name: 'Constrain',
|
||||||
|
})
|
||||||
|
.click()
|
||||||
|
await page
|
||||||
|
.getByRole('button', { name: 'perpendicular distance', exact: true })
|
||||||
|
.click()
|
||||||
|
|
||||||
|
const createNewVariableCheckbox = page.getByTestId(
|
||||||
|
'create-new-variable-checkbox'
|
||||||
|
)
|
||||||
|
const isChecked = await createNewVariableCheckbox.isChecked()
|
||||||
|
const addVariable = testName === 'Add variable'
|
||||||
|
XOR(isChecked, addVariable) && // XOR because no need to click the checkbox if the state is already correct
|
||||||
|
(await createNewVariableCheckbox.click())
|
||||||
|
|
||||||
|
await page
|
||||||
|
.getByRole('button', { name: 'Add constraining value' })
|
||||||
|
.click()
|
||||||
|
|
||||||
|
const activeLinesContent = await page.locator('.cm-activeLine').all()
|
||||||
|
await expect(activeLinesContent[0]).toHaveText(
|
||||||
|
`|> line([74.36, 130.4], %, 'seg01')`
|
||||||
|
)
|
||||||
|
await expect(activeLinesContent[1]).toHaveText(`}, %)`)
|
||||||
|
await expect(page.locator('.cm-content')).toContainText(`angle: -57,`)
|
||||||
|
await expect(page.locator('.cm-content')).toContainText(
|
||||||
|
`offset: ${offset},`
|
||||||
|
)
|
||||||
|
|
||||||
|
// checking the count of the overlays is a good proxy check that the client sketch scene is in a good state
|
||||||
|
await expect(page.getByTestId('segment-overlay')).toHaveCount(4)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test.describe('Test distance between constraint', () => {
|
||||||
|
const cases = [
|
||||||
|
{
|
||||||
|
testName: 'Add variable',
|
||||||
|
constraint: 'horizontal distance',
|
||||||
|
value: "segEndX('seg01', %) + xDis001, 61.34",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: 'No variable',
|
||||||
|
constraint: 'horizontal distance',
|
||||||
|
value: "segEndX('seg01', %) + 88.08, 61.34",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: 'Add variable',
|
||||||
|
constraint: 'vertical distance',
|
||||||
|
value: "154.9, segEndY('seg01', %) - yDis001",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: 'No variable',
|
||||||
|
constraint: 'vertical distance',
|
||||||
|
value: "154.9, segEndY('seg01', %) - 42.32",
|
||||||
|
},
|
||||||
|
] as const
|
||||||
|
for (const { testName, value, constraint } of cases) {
|
||||||
|
test(`${constraint} - ${testName}`, async ({ page }) => {
|
||||||
|
await page.addInitScript(async () => {
|
||||||
|
localStorage.setItem(
|
||||||
|
'persistCode',
|
||||||
|
`const yo = 5
|
||||||
|
const part001 = startSketchOn('XZ')
|
||||||
|
|> startProfileAt([-7.54, -26.74], %)
|
||||||
|
|> line([74.36, 130.4], %)
|
||||||
|
|> line([78.92, -120.11], %)
|
||||||
|
|> line([9.16, 77.79], %)
|
||||||
|
|> line([41.19, 28.97], %)
|
||||||
|
const part002 = startSketchOn('XZ')
|
||||||
|
|> startProfileAt([299.05, 231.45], %)
|
||||||
|
|> xLine(-425.34, %, 'seg-what')
|
||||||
|
|> yLine(-264.06, %)
|
||||||
|
|> xLine(segLen('seg-what', %), %)
|
||||||
|
|> lineTo([profileStartX(%), profileStartY(%)], %)`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
const u = await getUtils(page)
|
||||||
|
await page.setViewportSize({ width: 1200, height: 500 })
|
||||||
|
await page.goto('/')
|
||||||
|
await u.waitForAuthSkipAppStart()
|
||||||
|
|
||||||
|
await page.getByText('line([74.36, 130.4], %)').click()
|
||||||
|
await page.getByRole('button', { name: 'Edit Sketch' }).click()
|
||||||
|
|
||||||
|
const [line1, line3] = await Promise.all([
|
||||||
|
u.getSegmentBodyCoords(`[data-overlay-index="${0}"]`),
|
||||||
|
u.getSegmentBodyCoords(`[data-overlay-index="${2}"]`),
|
||||||
|
])
|
||||||
|
|
||||||
|
await page.mouse.click(line1.x, line1.y)
|
||||||
|
await page.keyboard.down('Shift')
|
||||||
|
await page.mouse.click(line3.x, line3.y)
|
||||||
|
await page.waitForTimeout(100) // this wait is needed for webkit - not sure why
|
||||||
|
await page.keyboard.up('Shift')
|
||||||
|
await page
|
||||||
|
.getByRole('button', {
|
||||||
|
name: 'Constrain',
|
||||||
|
})
|
||||||
|
.click()
|
||||||
|
await page
|
||||||
|
.getByRole('button', { name: constraint, exact: true })
|
||||||
|
.click()
|
||||||
|
|
||||||
|
const createNewVariableCheckbox = page.getByTestId(
|
||||||
|
'create-new-variable-checkbox'
|
||||||
|
)
|
||||||
|
const isChecked = await createNewVariableCheckbox.isChecked()
|
||||||
|
const addVariable = testName === 'Add variable'
|
||||||
|
XOR(isChecked, addVariable) && // XOR because no need to click the checkbox if the state is already correct
|
||||||
|
(await createNewVariableCheckbox.click())
|
||||||
|
|
||||||
|
await page
|
||||||
|
.getByRole('button', { name: 'Add constraining value' })
|
||||||
|
.click()
|
||||||
|
|
||||||
|
// checking activeLines assures the cursors are where they should be
|
||||||
|
const codeAfter = [
|
||||||
|
`|> line([74.36, 130.4], %, 'seg01')`,
|
||||||
|
`|> lineTo([${value}], %)`,
|
||||||
|
]
|
||||||
|
|
||||||
|
const activeLinesContent = await page.locator('.cm-activeLine').all()
|
||||||
|
await Promise.all(
|
||||||
|
activeLinesContent.map(async (line, i) => {
|
||||||
|
await expect(page.locator('.cm-content')).toContainText(
|
||||||
|
codeAfter[i]
|
||||||
|
)
|
||||||
|
// if the code is an active line then the cursor should be on that line
|
||||||
|
await expect(line).toHaveText(codeAfter[i])
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
// checking the count of the overlays is a good proxy check that the client sketch scene is in a good state
|
||||||
|
await expect(page.getByTestId('segment-overlay')).toHaveCount(4)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
test.describe('Test ABS distance constraint', () => {
|
test.describe('Test ABS distance constraint', () => {
|
||||||
const cases = [
|
const cases = [
|
||||||
{
|
{
|
||||||
@ -2521,7 +2760,7 @@ const part002 = startSketchOn('XZ')
|
|||||||
'create-new-variable-checkbox'
|
'create-new-variable-checkbox'
|
||||||
)
|
)
|
||||||
const isChecked = await createNewVariableCheckbox.isChecked()
|
const isChecked = await createNewVariableCheckbox.isChecked()
|
||||||
;((isChecked && !addVariable) || (!isChecked && addVariable)) &&
|
XOR(isChecked, addVariable) && // XOR because no need to click the checkbox if the state is already correct
|
||||||
(await createNewVariableCheckbox.click())
|
(await createNewVariableCheckbox.click())
|
||||||
|
|
||||||
await page
|
await page
|
||||||
@ -2627,7 +2866,7 @@ const part002 = startSketchOn('XZ')
|
|||||||
'create-new-variable-checkbox'
|
'create-new-variable-checkbox'
|
||||||
)
|
)
|
||||||
const isChecked = await createNewVariableCheckbox.isChecked()
|
const isChecked = await createNewVariableCheckbox.isChecked()
|
||||||
;((isChecked && !addVariable) || (!isChecked && addVariable)) &&
|
XOR(isChecked, addVariable) && // XOR because no need to click the checkbox if the state is already correct
|
||||||
(await createNewVariableCheckbox.click())
|
(await createNewVariableCheckbox.click())
|
||||||
|
|
||||||
await page
|
await page
|
||||||
@ -2657,37 +2896,51 @@ const part002 = startSketchOn('XZ')
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
test.describe('Test Angle constraint single selection', () => {
|
test.describe('Test Angle/Length constraint single selection', () => {
|
||||||
const cases = [
|
const cases = [
|
||||||
{
|
{
|
||||||
testName: 'Add variable',
|
testName: 'Angle - Add variable',
|
||||||
addVariable: true,
|
addVariable: true,
|
||||||
value: 'angle001',
|
constraint: 'angle',
|
||||||
|
value: 'angle001, 78.33',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: 'No variable',
|
testName: 'Angle - No variable',
|
||||||
addVariable: false,
|
addVariable: false,
|
||||||
value: '83',
|
constraint: 'angle',
|
||||||
|
value: '83, 78.33',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: 'Length - Add variable',
|
||||||
|
addVariable: true,
|
||||||
|
constraint: 'length',
|
||||||
|
value: '83, length001',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: 'Length - No variable',
|
||||||
|
addVariable: false,
|
||||||
|
constraint: 'length',
|
||||||
|
value: '83, 78.33',
|
||||||
},
|
},
|
||||||
] as const
|
] as const
|
||||||
for (const { testName, addVariable, value } of cases) {
|
for (const { testName, addVariable, value, constraint } of cases) {
|
||||||
test(`${testName}`, async ({ page }) => {
|
test(`${testName}`, async ({ page }) => {
|
||||||
await page.addInitScript(async () => {
|
await page.addInitScript(async () => {
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
'persistCode',
|
'persistCode',
|
||||||
`const yo = 5
|
`const yo = 5
|
||||||
const part001 = startSketchOn('XZ')
|
const part001 = startSketchOn('XZ')
|
||||||
|> startProfileAt([-7.54, -26.74], %)
|
|> startProfileAt([-7.54, -26.74], %)
|
||||||
|> line([74.36, 130.4], %)
|
|> line([74.36, 130.4], %)
|
||||||
|> line([78.92, -120.11], %)
|
|> line([78.92, -120.11], %)
|
||||||
|> line([9.16, 77.79], %)
|
|> line([9.16, 77.79], %)
|
||||||
|> line([41.19, 28.97], %)
|
|> line([41.19, 28.97], %)
|
||||||
const part002 = startSketchOn('XZ')
|
const part002 = startSketchOn('XZ')
|
||||||
|> startProfileAt([299.05, 231.45], %)
|
|> startProfileAt([299.05, 231.45], %)
|
||||||
|> xLine(-425.34, %, 'seg-what')
|
|> xLine(-425.34, %, 'seg-what')
|
||||||
|> yLine(-264.06, %)
|
|> yLine(-264.06, %)
|
||||||
|> xLine(segLen('seg-what', %), %)
|
|> xLine(segLen('seg-what', %), %)
|
||||||
|> lineTo([profileStartX(%), profileStartY(%)], %)`
|
|> lineTo([profileStartX(%), profileStartY(%)], %)`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
const u = await getUtils(page)
|
const u = await getUtils(page)
|
||||||
@ -2708,7 +2961,7 @@ const part002 = startSketchOn('XZ')
|
|||||||
name: 'Constrain',
|
name: 'Constrain',
|
||||||
})
|
})
|
||||||
.click()
|
.click()
|
||||||
await page.getByTestId('angle').click()
|
await page.getByTestId(constraint).click()
|
||||||
|
|
||||||
if (!addVariable) {
|
if (!addVariable) {
|
||||||
await page.getByTestId('create-new-variable-checkbox').click()
|
await page.getByTestId('create-new-variable-checkbox').click()
|
||||||
@ -2717,7 +2970,7 @@ const part002 = startSketchOn('XZ')
|
|||||||
.getByRole('button', { name: 'Add constraining value' })
|
.getByRole('button', { name: 'Add constraining value' })
|
||||||
.click()
|
.click()
|
||||||
|
|
||||||
const changedCode = `|> angledLine([${value}, 78.33], %)`
|
const changedCode = `|> angledLine([${value}], %)`
|
||||||
await expect(page.locator('.cm-content')).toContainText(changedCode)
|
await expect(page.locator('.cm-content')).toContainText(changedCode)
|
||||||
// checking active assures the cursor is where it should be
|
// checking active assures the cursor is where it should be
|
||||||
await expect(page.locator('.cm-activeLine')).toHaveText(changedCode)
|
await expect(page.locator('.cm-activeLine')).toHaveText(changedCode)
|
||||||
@ -2748,7 +3001,7 @@ const part002 = startSketchOn('XZ')
|
|||||||
] as const
|
] as const
|
||||||
for (const { codeAfter, constraintName } of cases) {
|
for (const { codeAfter, constraintName } of cases) {
|
||||||
test(`${constraintName}`, async ({ page }) => {
|
test(`${constraintName}`, async ({ page }) => {
|
||||||
await page.addInitScript(async () => {
|
await page.addInitScript(async (customCode) => {
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
'persistCode',
|
'persistCode',
|
||||||
`const yo = 5
|
`const yo = 5
|
||||||
@ -2774,15 +3027,21 @@ const part002 = startSketchOn('XZ')
|
|||||||
await page.getByText('line([74.36, 130.4], %)').click()
|
await page.getByText('line([74.36, 130.4], %)').click()
|
||||||
await page.getByRole('button', { name: 'Edit Sketch' }).click()
|
await page.getByRole('button', { name: 'Edit Sketch' }).click()
|
||||||
|
|
||||||
const line1 = await u.getBoundingBox(`[data-overlay-index="${0}"]`)
|
const line1 = await u.getSegmentBodyCoords(
|
||||||
const line3 = await u.getBoundingBox(`[data-overlay-index="${2}"]`)
|
`[data-overlay-index="${0}"]`
|
||||||
const line4 = await u.getBoundingBox(`[data-overlay-index="${3}"]`)
|
)
|
||||||
|
const line3 = await u.getSegmentBodyCoords(
|
||||||
|
`[data-overlay-index="${2}"]`
|
||||||
|
)
|
||||||
|
const line4 = await u.getSegmentBodyCoords(
|
||||||
|
`[data-overlay-index="${3}"]`
|
||||||
|
)
|
||||||
|
|
||||||
// select two segments by holding down shift
|
// select two segments by holding down shift
|
||||||
await page.mouse.click(line1.x - 20, line1.y + 20)
|
await page.mouse.click(line1.x, line1.y)
|
||||||
await page.keyboard.down('Shift')
|
await page.keyboard.down('Shift')
|
||||||
await page.mouse.click(line3.x - 3, line3.y + 20)
|
await page.mouse.click(line3.x, line3.y)
|
||||||
await page.mouse.click(line4.x - 15, line4.y + 15)
|
await page.mouse.click(line4.x, line4.y)
|
||||||
await page.keyboard.up('Shift')
|
await page.keyboard.up('Shift')
|
||||||
const constraintMenuButton = page.getByRole('button', {
|
const constraintMenuButton = page.getByRole('button', {
|
||||||
name: 'Constrain',
|
name: 'Constrain',
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "untitled-app",
|
"name": "untitled-app",
|
||||||
"version": "0.21.9",
|
"version": "0.22.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@codemirror/autocomplete": "^6.16.0",
|
"@codemirror/autocomplete": "^6.16.0",
|
||||||
|
@ -74,5 +74,5 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"productName": "Zoo Modeling App",
|
"productName": "Zoo Modeling App",
|
||||||
"version": "0.21.9"
|
"version": "0.22.0"
|
||||||
}
|
}
|
||||||
|
@ -508,13 +508,26 @@ export const ModelingMachineProvider = ({
|
|||||||
},
|
},
|
||||||
'Get horizontal info': async ({
|
'Get horizontal info': async ({
|
||||||
selectionRanges,
|
selectionRanges,
|
||||||
|
sketchDetails,
|
||||||
}): Promise<SetSelections> => {
|
}): Promise<SetSelections> => {
|
||||||
const { modifiedAst, pathToNodeMap } =
|
const { modifiedAst, pathToNodeMap } =
|
||||||
await applyConstraintHorzVertDistance({
|
await applyConstraintHorzVertDistance({
|
||||||
constraint: 'setHorzDistance',
|
constraint: 'setHorzDistance',
|
||||||
selectionRanges,
|
selectionRanges,
|
||||||
})
|
})
|
||||||
await kclManager.updateAst(modifiedAst, true)
|
const _modifiedAst = parse(recast(modifiedAst))
|
||||||
|
if (!sketchDetails) throw new Error('No sketch details')
|
||||||
|
const updatedPathToNode = updatePathToNodeFromMap(
|
||||||
|
sketchDetails.sketchPathToNode,
|
||||||
|
pathToNodeMap
|
||||||
|
)
|
||||||
|
await sceneEntitiesManager.updateAstAndRejigSketch(
|
||||||
|
updatedPathToNode,
|
||||||
|
_modifiedAst,
|
||||||
|
sketchDetails.zAxis,
|
||||||
|
sketchDetails.yAxis,
|
||||||
|
sketchDetails.origin
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
selectionType: 'completeSelection',
|
selectionType: 'completeSelection',
|
||||||
selection: pathMapToSelections(
|
selection: pathMapToSelections(
|
||||||
@ -522,17 +535,31 @@ export const ModelingMachineProvider = ({
|
|||||||
selectionRanges,
|
selectionRanges,
|
||||||
pathToNodeMap
|
pathToNodeMap
|
||||||
),
|
),
|
||||||
|
updatedPathToNode,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'Get vertical info': async ({
|
'Get vertical info': async ({
|
||||||
selectionRanges,
|
selectionRanges,
|
||||||
|
sketchDetails,
|
||||||
}): Promise<SetSelections> => {
|
}): Promise<SetSelections> => {
|
||||||
const { modifiedAst, pathToNodeMap } =
|
const { modifiedAst, pathToNodeMap } =
|
||||||
await applyConstraintHorzVertDistance({
|
await applyConstraintHorzVertDistance({
|
||||||
constraint: 'setVertDistance',
|
constraint: 'setVertDistance',
|
||||||
selectionRanges,
|
selectionRanges,
|
||||||
})
|
})
|
||||||
await kclManager.updateAst(modifiedAst, true)
|
const _modifiedAst = parse(recast(modifiedAst))
|
||||||
|
if (!sketchDetails) throw new Error('No sketch details')
|
||||||
|
const updatedPathToNode = updatePathToNodeFromMap(
|
||||||
|
sketchDetails.sketchPathToNode,
|
||||||
|
pathToNodeMap
|
||||||
|
)
|
||||||
|
await sceneEntitiesManager.updateAstAndRejigSketch(
|
||||||
|
updatedPathToNode,
|
||||||
|
_modifiedAst,
|
||||||
|
sketchDetails.zAxis,
|
||||||
|
sketchDetails.yAxis,
|
||||||
|
sketchDetails.origin
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
selectionType: 'completeSelection',
|
selectionType: 'completeSelection',
|
||||||
selection: pathMapToSelections(
|
selection: pathMapToSelections(
|
||||||
@ -540,6 +567,7 @@ export const ModelingMachineProvider = ({
|
|||||||
selectionRanges,
|
selectionRanges,
|
||||||
pathToNodeMap
|
pathToNodeMap
|
||||||
),
|
),
|
||||||
|
updatedPathToNode,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'Get angle info': async ({
|
'Get angle info': async ({
|
||||||
@ -581,10 +609,23 @@ export const ModelingMachineProvider = ({
|
|||||||
},
|
},
|
||||||
'Get length info': async ({
|
'Get length info': async ({
|
||||||
selectionRanges,
|
selectionRanges,
|
||||||
|
sketchDetails,
|
||||||
}): Promise<SetSelections> => {
|
}): Promise<SetSelections> => {
|
||||||
const { modifiedAst, pathToNodeMap } =
|
const { modifiedAst, pathToNodeMap } =
|
||||||
await applyConstraintAngleLength({ selectionRanges })
|
await applyConstraintAngleLength({ selectionRanges })
|
||||||
await kclManager.updateAst(modifiedAst, true)
|
const _modifiedAst = parse(recast(modifiedAst))
|
||||||
|
if (!sketchDetails) throw new Error('No sketch details')
|
||||||
|
const updatedPathToNode = updatePathToNodeFromMap(
|
||||||
|
sketchDetails.sketchPathToNode,
|
||||||
|
pathToNodeMap
|
||||||
|
)
|
||||||
|
await sceneEntitiesManager.updateAstAndRejigSketch(
|
||||||
|
updatedPathToNode,
|
||||||
|
_modifiedAst,
|
||||||
|
sketchDetails.zAxis,
|
||||||
|
sketchDetails.yAxis,
|
||||||
|
sketchDetails.origin
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
selectionType: 'completeSelection',
|
selectionType: 'completeSelection',
|
||||||
selection: pathMapToSelections(
|
selection: pathMapToSelections(
|
||||||
@ -592,17 +633,31 @@ export const ModelingMachineProvider = ({
|
|||||||
selectionRanges,
|
selectionRanges,
|
||||||
pathToNodeMap
|
pathToNodeMap
|
||||||
),
|
),
|
||||||
|
updatedPathToNode,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'Get perpendicular distance info': async ({
|
'Get perpendicular distance info': async ({
|
||||||
selectionRanges,
|
selectionRanges,
|
||||||
|
sketchDetails,
|
||||||
}): Promise<SetSelections> => {
|
}): Promise<SetSelections> => {
|
||||||
const { modifiedAst, pathToNodeMap } = await applyConstraintIntersect(
|
const { modifiedAst, pathToNodeMap } = await applyConstraintIntersect(
|
||||||
{
|
{
|
||||||
selectionRanges,
|
selectionRanges,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
await kclManager.updateAst(modifiedAst, true)
|
const _modifiedAst = parse(recast(modifiedAst))
|
||||||
|
if (!sketchDetails) throw new Error('No sketch details')
|
||||||
|
const updatedPathToNode = updatePathToNodeFromMap(
|
||||||
|
sketchDetails.sketchPathToNode,
|
||||||
|
pathToNodeMap
|
||||||
|
)
|
||||||
|
await sceneEntitiesManager.updateAstAndRejigSketch(
|
||||||
|
updatedPathToNode,
|
||||||
|
_modifiedAst,
|
||||||
|
sketchDetails.zAxis,
|
||||||
|
sketchDetails.yAxis,
|
||||||
|
sketchDetails.origin
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
selectionType: 'completeSelection',
|
selectionType: 'completeSelection',
|
||||||
selection: pathMapToSelections(
|
selection: pathMapToSelections(
|
||||||
@ -610,6 +665,7 @@ export const ModelingMachineProvider = ({
|
|||||||
selectionRanges,
|
selectionRanges,
|
||||||
pathToNodeMap
|
pathToNodeMap
|
||||||
),
|
),
|
||||||
|
updatedPathToNode,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'Get ABS X info': async ({
|
'Get ABS X info': async ({
|
||||||
|
@ -140,7 +140,11 @@ export async function applyConstraintIntersect({
|
|||||||
value: valueUsedInTransform,
|
value: valueUsedInTransform,
|
||||||
initialVariableName: 'offset',
|
initialVariableName: 'offset',
|
||||||
})
|
})
|
||||||
if (segName === tagInfo?.tag && Number(value) === valueUsedInTransform) {
|
if (
|
||||||
|
!variableName &&
|
||||||
|
segName === tagInfo?.tag &&
|
||||||
|
Number(value) === valueUsedInTransform
|
||||||
|
) {
|
||||||
return {
|
return {
|
||||||
modifiedAst,
|
modifiedAst,
|
||||||
pathToNodeMap,
|
pathToNodeMap,
|
||||||
@ -169,6 +173,10 @@ export async function applyConstraintIntersect({
|
|||||||
createVariableDeclaration(variableName, valueNode)
|
createVariableDeclaration(variableName, valueNode)
|
||||||
)
|
)
|
||||||
_modifiedAst.body = newBody
|
_modifiedAst.body = newBody
|
||||||
|
Object.values(_pathToNodeMap).forEach((pathToNode) => {
|
||||||
|
const index = pathToNode.findIndex((a) => a[0] === 'body') + 1
|
||||||
|
pathToNode[index][0] = Number(pathToNode[index][0]) + 1
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
modifiedAst: _modifiedAst,
|
modifiedAst: _modifiedAst,
|
||||||
|
@ -106,7 +106,11 @@ export async function applyConstraintHorzVertDistance({
|
|||||||
value: valueUsedInTransform,
|
value: valueUsedInTransform,
|
||||||
initialVariableName: constraint === 'setHorzDistance' ? 'xDis' : 'yDis',
|
initialVariableName: constraint === 'setHorzDistance' ? 'xDis' : 'yDis',
|
||||||
} as any)
|
} as any)
|
||||||
if (segName === tagInfo?.tag && Number(value) === valueUsedInTransform) {
|
if (
|
||||||
|
!variableName &&
|
||||||
|
segName === tagInfo?.tag &&
|
||||||
|
Number(value) === valueUsedInTransform
|
||||||
|
) {
|
||||||
return {
|
return {
|
||||||
modifiedAst,
|
modifiedAst,
|
||||||
pathToNodeMap,
|
pathToNodeMap,
|
||||||
@ -133,6 +137,10 @@ export async function applyConstraintHorzVertDistance({
|
|||||||
createVariableDeclaration(variableName, valueNode)
|
createVariableDeclaration(variableName, valueNode)
|
||||||
)
|
)
|
||||||
_modifiedAst.body = newBody
|
_modifiedAst.body = newBody
|
||||||
|
Object.values(pathToNodeMap).forEach((pathToNode) => {
|
||||||
|
const index = pathToNode.findIndex((a) => a[0] === 'body') + 1
|
||||||
|
pathToNode[index][0] = Number(pathToNode[index][0]) + 1
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
modifiedAst: _modifiedAst,
|
modifiedAst: _modifiedAst,
|
||||||
|
@ -127,3 +127,7 @@ export function isReducedMotion(): boolean {
|
|||||||
window.matchMedia('(prefers-reduced-motion)').matches
|
window.matchMedia('(prefers-reduced-motion)').matches
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function XOR(bool1: boolean, bool2: boolean): boolean {
|
||||||
|
return (bool1 || bool2) && !(bool1 && bool2)
|
||||||
|
}
|
||||||
|
@ -360,10 +360,8 @@ export const modelingMachine = createMachine(
|
|||||||
},
|
},
|
||||||
|
|
||||||
'Constrain remove constraints': {
|
'Constrain remove constraints': {
|
||||||
target: 'SketchIdle',
|
|
||||||
internal: true,
|
|
||||||
cond: 'Can constrain remove constraints',
|
cond: 'Can constrain remove constraints',
|
||||||
actions: ['Constrain remove constraints'],
|
target: 'Await constrain remove constraints',
|
||||||
},
|
},
|
||||||
|
|
||||||
'Re-execute': {
|
'Re-execute': {
|
||||||
@ -586,6 +584,16 @@ export const modelingMachine = createMachine(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'Await constrain remove constraints': {
|
||||||
|
invoke: {
|
||||||
|
src: 'do-constrain-remove-constraint',
|
||||||
|
id: 'do-constrain-remove-constraint',
|
||||||
|
onDone: {
|
||||||
|
target: 'SketchIdle',
|
||||||
|
actions: 'Set selection',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
'Await constrain horizontally': {
|
'Await constrain horizontally': {
|
||||||
invoke: {
|
invoke: {
|
||||||
src: 'do-constrain-horizontally',
|
src: 'do-constrain-horizontally',
|
||||||
@ -848,21 +856,6 @@ export const modelingMachine = createMachine(
|
|||||||
'set new sketch metadata': assign((_, { data }) => ({
|
'set new sketch metadata': assign((_, { data }) => ({
|
||||||
sketchDetails: data,
|
sketchDetails: data,
|
||||||
})),
|
})),
|
||||||
// TODO implement source ranges for all of these constraints
|
|
||||||
// need to make the async like the modal constraints
|
|
||||||
'Constrain remove constraints': ({ selectionRanges, sketchDetails }) => {
|
|
||||||
const { modifiedAst } = applyRemoveConstrainingValues({
|
|
||||||
selectionRanges,
|
|
||||||
})
|
|
||||||
if (!sketchDetails) return
|
|
||||||
sceneEntitiesManager.updateAstAndRejigSketch(
|
|
||||||
sketchDetails?.sketchPathToNode || [],
|
|
||||||
modifiedAst,
|
|
||||||
sketchDetails.zAxis,
|
|
||||||
sketchDetails.yAxis,
|
|
||||||
sketchDetails.origin
|
|
||||||
)
|
|
||||||
},
|
|
||||||
'AST extrude': async (_, event) => {
|
'AST extrude': async (_, event) => {
|
||||||
if (!event.data) return
|
if (!event.data) return
|
||||||
const { selection, distance } = event.data
|
const { selection, distance } = event.data
|
||||||
@ -1109,6 +1102,38 @@ export const modelingMachine = createMachine(
|
|||||||
},
|
},
|
||||||
// end actions
|
// end actions
|
||||||
services: {
|
services: {
|
||||||
|
'do-constrain-remove-constraint': async ({
|
||||||
|
selectionRanges,
|
||||||
|
sketchDetails,
|
||||||
|
}) => {
|
||||||
|
const { modifiedAst, pathToNodeMap } = applyRemoveConstrainingValues({
|
||||||
|
selectionRanges,
|
||||||
|
})
|
||||||
|
if (!sketchDetails) return
|
||||||
|
sceneEntitiesManager.updateAstAndRejigSketch(
|
||||||
|
sketchDetails?.sketchPathToNode || [],
|
||||||
|
modifiedAst,
|
||||||
|
sketchDetails.zAxis,
|
||||||
|
sketchDetails.yAxis,
|
||||||
|
sketchDetails.origin
|
||||||
|
)
|
||||||
|
if (!sketchDetails) return
|
||||||
|
await sceneEntitiesManager.updateAstAndRejigSketch(
|
||||||
|
sketchDetails.sketchPathToNode,
|
||||||
|
modifiedAst,
|
||||||
|
sketchDetails.zAxis,
|
||||||
|
sketchDetails.yAxis,
|
||||||
|
sketchDetails.origin
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
selectionType: 'completeSelection',
|
||||||
|
selection: updateSelections(
|
||||||
|
pathToNodeMap,
|
||||||
|
selectionRanges,
|
||||||
|
parse(recast(modifiedAst))
|
||||||
|
),
|
||||||
|
}
|
||||||
|
},
|
||||||
'do-constrain-horizontally': async ({
|
'do-constrain-horizontally': async ({
|
||||||
selectionRanges,
|
selectionRanges,
|
||||||
sketchDetails,
|
sketchDetails,
|
||||||
|
Reference in New Issue
Block a user