Lengths and angles should be set with |abs| values (#93)
* Lengths and angles should be set with |abs| values * clean up
This commit is contained in:
@ -1,7 +1,11 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { create } from 'react-modal-promise'
|
||||
import { toolTips, useStore } from '../../useStore'
|
||||
import { Value, VariableDeclarator } from '../../lang/abstractSyntaxTree'
|
||||
import {
|
||||
BinaryPart,
|
||||
Value,
|
||||
VariableDeclarator,
|
||||
} from '../../lang/abstractSyntaxTree'
|
||||
import {
|
||||
getNodePathFromSourceRange,
|
||||
getNodeFromPath,
|
||||
@ -17,6 +21,7 @@ import {
|
||||
createIdentifier,
|
||||
createVariableDeclaration,
|
||||
} from '../../lang/modifyAst'
|
||||
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
||||
|
||||
const getModalInfo = create(GetInfoModal as any)
|
||||
|
||||
@ -95,12 +100,14 @@ export const Intersect = () => {
|
||||
valueNode,
|
||||
variableName,
|
||||
newVariableInsertIndex,
|
||||
sign,
|
||||
}: {
|
||||
segName: string
|
||||
value: number
|
||||
valueNode: Value
|
||||
variableName?: string
|
||||
newVariableInsertIndex: number
|
||||
sign: number
|
||||
} = await getModalInfo({
|
||||
segName: tagInfo?.tag,
|
||||
isSegNameEditable: !tagInfo?.isTagExisting,
|
||||
@ -111,6 +118,11 @@ export const Intersect = () => {
|
||||
updateAst(modifiedAst)
|
||||
} else {
|
||||
// transform again but forcing certain values
|
||||
const finalValue = removeDoubleNegatives(
|
||||
valueNode as BinaryPart,
|
||||
sign,
|
||||
variableName
|
||||
)
|
||||
const { modifiedAst: _modifiedAst } =
|
||||
transformSecondarySketchLinesTagFirst({
|
||||
ast,
|
||||
@ -118,9 +130,7 @@ export const Intersect = () => {
|
||||
transformInfos,
|
||||
programMemory,
|
||||
forceSegName: segName,
|
||||
forceValueUsedInTransform: variableName
|
||||
? createIdentifier(variableName)
|
||||
: valueNode,
|
||||
forceValueUsedInTransform: finalValue,
|
||||
})
|
||||
if (variableName) {
|
||||
const newBody = [..._modifiedAst.body]
|
||||
|
@ -5,7 +5,6 @@ import { Value } from '../../lang/abstractSyntaxTree'
|
||||
import {
|
||||
getNodePathFromSourceRange,
|
||||
getNodeFromPath,
|
||||
findAllPreviousVariables,
|
||||
} from '../../lang/queryAst'
|
||||
import {
|
||||
TransformInfo,
|
||||
@ -13,10 +12,8 @@ import {
|
||||
transformAstSketchLines,
|
||||
} from '../../lang/std/sketchcombos'
|
||||
import { SetAngleLengthModal } from '../SetAngleLengthModal'
|
||||
import {
|
||||
createIdentifier,
|
||||
createVariableDeclaration,
|
||||
} from '../../lang/modifyAst'
|
||||
import { createVariableDeclaration } from '../../lang/modifyAst'
|
||||
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
||||
|
||||
const getModalInfo = create(SetAngleLengthModal as any)
|
||||
|
||||
@ -71,11 +68,16 @@ export const SetAngleLength = ({
|
||||
referenceSegName: '',
|
||||
})
|
||||
try {
|
||||
const { valueNode, variableName, newVariableInsertIndex } =
|
||||
const { valueNode, variableName, newVariableInsertIndex, sign } =
|
||||
await getModalInfo({
|
||||
value: valueUsedInTransform,
|
||||
valueName: angleOrLength === 'setAngle' ? 'angle' : 'length',
|
||||
} as any)
|
||||
const finalValue = removeDoubleNegatives(
|
||||
valueNode,
|
||||
sign,
|
||||
variableName
|
||||
)
|
||||
|
||||
const { modifiedAst: _modifiedAst } = transformAstSketchLines({
|
||||
ast: JSON.parse(JSON.stringify(ast)),
|
||||
@ -83,9 +85,7 @@ export const SetAngleLength = ({
|
||||
transformInfos,
|
||||
programMemory,
|
||||
referenceSegName: '',
|
||||
forceValueUsedInTransform: variableName
|
||||
? createIdentifier(variableName)
|
||||
: valueNode,
|
||||
forceValueUsedInTransform: finalValue,
|
||||
})
|
||||
if (variableName) {
|
||||
const newBody = [..._modifiedAst.body]
|
||||
|
@ -1,7 +1,11 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { create } from 'react-modal-promise'
|
||||
import { toolTips, useStore } from '../../useStore'
|
||||
import { Value, VariableDeclarator } from '../../lang/abstractSyntaxTree'
|
||||
import {
|
||||
BinaryPart,
|
||||
Value,
|
||||
VariableDeclarator,
|
||||
} from '../../lang/abstractSyntaxTree'
|
||||
import {
|
||||
getNodePathFromSourceRange,
|
||||
getNodeFromPath,
|
||||
@ -17,6 +21,7 @@ import {
|
||||
createIdentifier,
|
||||
createVariableDeclaration,
|
||||
} from '../../lang/modifyAst'
|
||||
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
||||
|
||||
const getModalInfo = create(GetInfoModal as any)
|
||||
|
||||
@ -99,12 +104,14 @@ export const SetHorzDistance = ({
|
||||
valueNode,
|
||||
variableName,
|
||||
newVariableInsertIndex,
|
||||
sign,
|
||||
}: {
|
||||
segName: string
|
||||
value: number
|
||||
valueNode: Value
|
||||
variableName?: string
|
||||
newVariableInsertIndex: number
|
||||
sign: number
|
||||
} = await getModalInfo({
|
||||
segName: tagInfo?.tag,
|
||||
isSegNameEditable: !tagInfo?.isTagExisting,
|
||||
@ -115,6 +122,12 @@ export const SetHorzDistance = ({
|
||||
if (segName === tagInfo?.tag && value === valueUsedInTransform) {
|
||||
updateAst(modifiedAst)
|
||||
} else {
|
||||
const finalValue = removeDoubleNegatives(
|
||||
valueNode as BinaryPart,
|
||||
sign,
|
||||
variableName
|
||||
)
|
||||
console.log(finalValue)
|
||||
// transform again but forcing certain values
|
||||
const { modifiedAst: _modifiedAst } =
|
||||
transformSecondarySketchLinesTagFirst({
|
||||
@ -123,9 +136,7 @@ export const SetHorzDistance = ({
|
||||
transformInfos,
|
||||
programMemory,
|
||||
forceSegName: segName,
|
||||
forceValueUsedInTransform: variableName
|
||||
? createIdentifier(variableName)
|
||||
: valueNode,
|
||||
forceValueUsedInTransform: finalValue,
|
||||
})
|
||||
if (variableName) {
|
||||
const newBody = [..._modifiedAst.body]
|
||||
|
Reference in New Issue
Block a user