artifact map clean up (PART 2.1) (#3130)

* variable renaming

* fix fillet
This commit is contained in:
Kurt Hutten
2024-07-26 14:19:14 +10:00
committed by GitHub
parent e708b6ee6b
commit 0d4b7adf99
4 changed files with 23 additions and 38 deletions

View File

@ -1566,16 +1566,16 @@ export class SceneEntities {
// If we clicked on an extrude wall, we climb up the parent Id // If we clicked on an extrude wall, we climb up the parent Id
// to get the sketch profile's face ID. If we clicked on an endcap, // to get the sketch profile's face ID. If we clicked on an endcap,
// we already have it. // we already have it.
const targetId = const pathId =
artifact?.type === 'extrudeWall' || artifact?.type === 'extrudeCap' artifact?.type === 'extrudeWall' || artifact?.type === 'extrudeCap'
? artifact.segmentId ? artifact.pathId
: '' : ''
// tsc cannot infer that target can have extrusions // tsc cannot infer that target can have extrusions
// from the commandType (why?) so we need to cast it // from the commandType (why?) so we need to cast it
const target = this.engineCommandManager.artifactMap?.[targetId || ''] const path = this.engineCommandManager.artifactMap?.[pathId || '']
const extrusionId = const extrusionId =
target?.type === 'startPath' ? target.extrusions[0] : '' path?.type === 'startPath' ? path.extrusionIds[0] : ''
// TODO: We get the first extrusion command ID, // TODO: We get the first extrusion command ID,
// which is fine while backend systems only support one extrusion. // which is fine while backend systems only support one extrusion.
@ -1609,10 +1609,7 @@ export class SceneEntities {
) as [number, number, number], ) as [number, number, number],
sketchPathToNode, sketchPathToNode,
extrudePathToNode, extrudePathToNode,
cap: cap: artifact.type === 'extrudeCap' ? artifact.cap : 'none',
artifact.type === 'extrudeCap'
? artifact.additionalData.info
: 'none',
faceId: _entity_id, faceId: _entity_id,
}, },
}) })

View File

@ -9,12 +9,12 @@ interface CommonCommandProperties {
interface ExtrudeArtifact extends CommonCommandProperties { interface ExtrudeArtifact extends CommonCommandProperties {
type: 'extrude' type: 'extrude'
target: string pathId: string
} }
export interface StartPathArtifact extends CommonCommandProperties { export interface StartPathArtifact extends CommonCommandProperties {
type: 'startPath' type: 'startPath'
extrusions: string[] extrusionIds: string[]
} }
export interface SegmentArtifact extends CommonCommandProperties { export interface SegmentArtifact extends CommonCommandProperties {
@ -25,15 +25,12 @@ export interface SegmentArtifact extends CommonCommandProperties {
interface ExtrudeCapArtifact extends CommonCommandProperties { interface ExtrudeCapArtifact extends CommonCommandProperties {
type: 'extrudeCap' type: 'extrudeCap'
additionalData: { cap: 'start' | 'end'
type: 'cap' pathId: string
info: 'start' | 'end'
}
segmentId: string
} }
interface ExtrudeWallArtifact extends CommonCommandProperties { interface ExtrudeWallArtifact extends CommonCommandProperties {
type: 'extrudeWall' type: 'extrudeWall'
segmentId: string pathId: string
} }
interface PatternInstance extends CommonCommandProperties { interface PatternInstance extends CommonCommandProperties {
@ -154,7 +151,7 @@ function handleIndividualResponse({
type: 'extrude', type: 'extrude',
range, range,
pathToNode, pathToNode,
target: command2.target, pathId: command2.target,
}, },
}) })
@ -167,8 +164,8 @@ function handleIndividualResponse({
type: 'startPath', type: 'startPath',
range: targetArtifact.range, range: targetArtifact.range,
pathToNode: targetArtifact.pathToNode, pathToNode: targetArtifact.pathToNode,
extrusions: targetArtifact?.extrusions extrusionIds: targetArtifact?.extrusionIds
? [...targetArtifact?.extrusions, id] ? [...targetArtifact?.extrusionIds, id]
: [id], : [id],
}, },
}) })
@ -204,7 +201,7 @@ function handleIndividualResponse({
type: 'startPath', type: 'startPath',
range, range,
pathToNode, pathToNode,
extrusions: [], extrusionIds: [],
}, },
}) })
} }
@ -247,15 +244,11 @@ function handleIndividualResponse({
artifacts.push({ artifacts.push({
commandId: face.face_id, commandId: face.face_id,
artifact: { artifact: {
// ...parent,
type: 'extrudeCap', type: 'extrudeCap',
additionalData: { cap: face.cap === 'bottom' ? 'start' : 'end',
type: 'cap',
info: face.cap === 'bottom' ? 'start' : 'end',
},
range: parent.range, range: parent.range,
pathToNode: parent.pathToNode, pathToNode: parent.pathToNode,
segmentId: pathId:
edgeArtifact?.type === 'segment' ? edgeArtifact.pathId : '', edgeArtifact?.type === 'segment' ? edgeArtifact.pathId : '',
}, },
}) })
@ -265,11 +258,10 @@ function handleIndividualResponse({
artifacts.push({ artifacts.push({
commandId: face.face_id, commandId: face.face_id,
artifact: { artifact: {
...curveArtifact,
type: 'extrudeWall', type: 'extrudeWall',
range: curveArtifact.range, range: curveArtifact.range,
pathToNode: curveArtifact.pathToNode, pathToNode: curveArtifact.pathToNode,
segmentId: curveArtifact.pathId, pathId: curveArtifact.pathId,
}, },
}) })
} }

View File

@ -115,10 +115,7 @@ export async function getEventForSelectWithPoint(
selectionType: 'singleCodeCursor', selectionType: 'singleCodeCursor',
selection: { selection: {
range: sourceRange, range: sourceRange,
type: type: _artifact?.cap === 'end' ? 'end-cap' : 'start-cap',
_artifact?.additionalData.info === 'end'
? 'end-cap'
: 'start-cap',
}, },
}, },
} }
@ -525,7 +522,7 @@ function codeToIdSelections(
if ( if (
type === 'start-cap' && type === 'start-cap' &&
entry.artifact.type === 'extrudeCap' && entry.artifact.type === 'extrudeCap' &&
entry?.artifact?.additionalData?.info === 'start' entry?.artifact?.cap === 'start'
) { ) {
bestCandidate = entry bestCandidate = entry
return return
@ -533,7 +530,7 @@ function codeToIdSelections(
if ( if (
type === 'end-cap' && type === 'end-cap' &&
entry.artifact.type === 'extrudeCap' && entry.artifact.type === 'extrudeCap' &&
entry?.artifact?.additionalData?.info === 'end' entry?.artifact?.cap === 'end'
) { ) {
bestCandidate = entry bestCandidate = entry
return return

View File

@ -1143,11 +1143,10 @@ export const modelingMachine = createMachine(
if (sketchGroup?.type !== 'SketchGroup') return if (sketchGroup?.type !== 'SketchGroup') return
const idArtifact = engineCommandManager.artifactMap[sketchGroup.id] const idArtifact = engineCommandManager.artifactMap[sketchGroup.id]
if (idArtifact.type !== 'startPath') return if (idArtifact.type !== 'startPath') return
const extrusionArtifactId = (idArtifact as any)?.extrusions?.[0] const extrusionArtifactId = idArtifact?.extrusionIds?.[0]
if (typeof extrusionArtifactId !== 'string') return if (typeof extrusionArtifactId !== 'string') return
const extrusionArtifact = (engineCommandManager.artifactMap as any)[ const extrusionArtifact =
extrusionArtifactId engineCommandManager.artifactMap[extrusionArtifactId]
]
if (!extrusionArtifact) return if (!extrusionArtifact) return
const pathToExtrudeNode = getNodePathFromSourceRange( const pathToExtrudeNode = getNodePathFromSourceRange(
ast, ast,