Horz/Vert distance constraint with modal workflow (#43)
* button style tweak * Remove duplication constraint ast transforms * giveSketchFnCallTag to return if line already had a tag * remove duplication * update tag name to referenceSegName * Update transform shape to return key details about the transform * add modal to hor vert distance workflow * fix browser env stuff from breaking tests * fmt
This commit is contained in:
@ -8,7 +8,7 @@ import {
|
||||
import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints'
|
||||
import {
|
||||
TransformInfo,
|
||||
transformAstForSketchLines,
|
||||
transformSecondarySketchLinesTagFirst,
|
||||
getTransformInfos,
|
||||
} from '../../lang/std/sketchcombos'
|
||||
|
||||
@ -73,7 +73,7 @@ export const Equal = () => {
|
||||
transformInfos &&
|
||||
ast &&
|
||||
updateAst(
|
||||
transformAstForSketchLines({
|
||||
transformSecondarySketchLinesTagFirst({
|
||||
ast,
|
||||
selectionRanges,
|
||||
transformInfos,
|
||||
@ -81,7 +81,7 @@ export const Equal = () => {
|
||||
})?.modifiedAst
|
||||
)
|
||||
}
|
||||
className={`border m-1 px-1 rounded ${
|
||||
className={`border m-1 px-1 rounded text-xs ${
|
||||
enableEqual ? 'bg-gray-50 text-gray-800' : 'bg-gray-200 text-gray-400'
|
||||
}`}
|
||||
disabled={!enableEqual}
|
||||
|
@ -8,7 +8,7 @@ import {
|
||||
import {
|
||||
TransformInfo,
|
||||
getTransformInfos,
|
||||
transformAstForHorzVert,
|
||||
transformAstSketchLines,
|
||||
} from '../../lang/std/sketchcombos'
|
||||
|
||||
export const HorzVert = ({
|
||||
@ -55,15 +55,16 @@ export const HorzVert = ({
|
||||
transformInfos &&
|
||||
ast &&
|
||||
updateAst(
|
||||
transformAstForHorzVert({
|
||||
transformAstSketchLines({
|
||||
ast,
|
||||
selectionRanges,
|
||||
transformInfos,
|
||||
programMemory,
|
||||
referenceSegName: '',
|
||||
})?.modifiedAst
|
||||
)
|
||||
}
|
||||
className={`border m-1 px-1 rounded ${
|
||||
className={`border m-1 px-1 rounded text-xs ${
|
||||
enableHorz ? 'bg-gray-50 text-gray-800' : 'bg-gray-200 text-gray-400'
|
||||
}`}
|
||||
disabled={!enableHorz}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { create } from 'react-modal-promise'
|
||||
import { toolTips, useStore } from '../../useStore'
|
||||
import { Value, VariableDeclarator } from '../../lang/abstractSyntaxTree'
|
||||
import {
|
||||
@ -8,9 +9,13 @@ import {
|
||||
import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints'
|
||||
import {
|
||||
TransformInfo,
|
||||
transformAstForSketchLines,
|
||||
transformSecondarySketchLinesTagFirst,
|
||||
getTransformInfos,
|
||||
} from '../../lang/std/sketchcombos'
|
||||
import { GetInfoModal } from '../GetInfoModal'
|
||||
import { createLiteral } from '../../lang/modifyAst'
|
||||
|
||||
const getModalInfo = create(GetInfoModal as any)
|
||||
|
||||
export const SetHorzDistance = ({
|
||||
horOrVert,
|
||||
@ -73,23 +78,41 @@ export const SetHorzDistance = ({
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={() =>
|
||||
transformInfos &&
|
||||
ast &&
|
||||
updateAst(
|
||||
transformAstForSketchLines({
|
||||
ast,
|
||||
selectionRanges,
|
||||
transformInfos,
|
||||
programMemory,
|
||||
})?.modifiedAst
|
||||
)
|
||||
}
|
||||
className={`border m-1 px-1 rounded ${
|
||||
onClick={async () => {
|
||||
if (transformInfos && ast) {
|
||||
const { modifiedAst, tagInfo, valueUsedInTransform } =
|
||||
transformSecondarySketchLinesTagFirst({
|
||||
ast: JSON.parse(JSON.stringify(ast)),
|
||||
selectionRanges,
|
||||
transformInfos,
|
||||
programMemory,
|
||||
})
|
||||
const { segName, value }: { segName: string; value: number } =
|
||||
await getModalInfo({
|
||||
segName: tagInfo?.tag,
|
||||
isSegNameEditable: !tagInfo?.isTagExisting,
|
||||
value: valueUsedInTransform,
|
||||
} as any)
|
||||
if (segName === tagInfo?.tag && value === valueUsedInTransform) {
|
||||
updateAst(modifiedAst)
|
||||
} else {
|
||||
// transform again but forcing certain values
|
||||
const { modifiedAst } = transformSecondarySketchLinesTagFirst({
|
||||
ast,
|
||||
selectionRanges,
|
||||
transformInfos,
|
||||
programMemory,
|
||||
forceSegName: segName,
|
||||
forceValueUsedInTransform: createLiteral(value),
|
||||
})
|
||||
updateAst(modifiedAst)
|
||||
}
|
||||
}
|
||||
}}
|
||||
className={`border m-1 px-1 rounded text-xs ${
|
||||
enable ? 'bg-gray-50 text-gray-800' : 'bg-gray-200 text-gray-400'
|
||||
}`}
|
||||
disabled={!enable}
|
||||
title="yo dawg"
|
||||
>
|
||||
{horOrVert}
|
||||
</button>
|
||||
|
Reference in New Issue
Block a user