make other startSketchOn's work

This commit is contained in:
Kurt Hutten Irev-Dev
2025-02-12 18:19:39 +11:00
parent 4a8e582865
commit de526ae36e
3 changed files with 43 additions and 35 deletions

View File

@ -445,32 +445,6 @@ function getPlaneFromSolid2D(
if (err(path)) return path
return getPlaneFromPath(path, graph)
}
function getPlaneFromCap(
cap: CapArtifact,
graph: ArtifactGraph
): PlaneArtifact | WallArtifact | CapArtifact | Error {
const sweep = getArtifactOfTypes(
{ key: cap.sweepId, types: ['sweep'] },
graph
)
if (err(sweep)) return sweep
const path = getArtifactOfTypes({ key: sweep.pathId, types: ['path'] }, graph)
if (err(path)) return path
return getPlaneFromPath(path, graph)
}
function getPlaneFromWall(
wall: WallArtifact,
graph: ArtifactGraph
): PlaneArtifact | WallArtifact | CapArtifact | Error {
const sweep = getArtifactOfTypes(
{ key: wall.sweepId, types: ['sweep'] },
graph
)
if (err(sweep)) return sweep
const path = getArtifactOfTypes({ key: sweep.pathId, types: ['path'] }, graph)
if (err(path)) return path
return getPlaneFromPath(path, graph)
}
function getPlaneFromSweepEdge(edge: SweepEdge, graph: ArtifactGraph) {
const sweep = getArtifactOfTypes(
{ key: edge.sweepId, types: ['sweep'] },
@ -623,10 +597,15 @@ export function getArtifactFromRange(
artifactGraph: ArtifactGraph
): Artifact | null {
for (const artifact of artifactGraph.values()) {
if ('codeRef' in artifact && artifact.codeRef) {
const codeRef =
'codeRef' in artifact
? artifact.codeRef
: 'faceCodeRef' in artifact
? artifact.faceCodeRef
: null
if (codeRef) {
const match =
artifact.codeRef?.range[0] === range[0] &&
artifact.codeRef.range[1] === range[1]
codeRef?.range[0] === range[0] && codeRef.range[1] === range[1]
if (match) return artifact
}
}

View File

@ -63,13 +63,19 @@ export function isCursorInSketchCommandRange(
): string | false {
const overlappingEntries = filterArtifacts(
{
types: ['segment', 'path', 'plane'],
types: ['segment', 'path', 'plane', 'cap', 'wall'],
predicate: (artifact) => {
const codeRefRange =
'codeRef' in artifact
? artifact?.codeRef.range
: 'faceCodeRef' in artifact
? artifact?.faceCodeRef.range
: null
return selectionRanges.graphSelections.some(
(selection) =>
isArray(selection?.codeRef?.range) &&
isArray(artifact?.codeRef?.range) &&
isOverlap(selection?.codeRef?.range, artifact.codeRef.range)
isArray(codeRefRange) &&
isOverlap(selection?.codeRef?.range, codeRefRange)
)
},
},
@ -79,7 +85,10 @@ export function isCursorInSketchCommandRange(
const parentId =
firstEntry?.type === 'segment'
? firstEntry.pathId
: firstEntry?.type === 'plane' && firstEntry.pathIds.length
: (firstEntry?.type === 'plane' ||
firstEntry?.type === 'cap' ||
firstEntry?.type === 'wall') &&
firstEntry.pathIds.length
? firstEntry.pathIds[0]
: false

View File

@ -613,8 +613,14 @@ export function codeToIdSelections(
// TODO #868: loops over all artifacts will become inefficient at a large scale
const overlappingEntries = Array.from(engineCommandManager.artifactGraph)
.map(([id, artifact]) => {
if (!('codeRef' in artifact && artifact.codeRef)) return null
return isOverlap(artifact.codeRef.range, selection.range)
const codeRef =
'codeRef' in artifact
? artifact.codeRef
: 'faceCodeRef' in artifact
? artifact.faceCodeRef
: null
if (!codeRef) return null
return isOverlap(codeRef.range, selection.range)
? {
artifact,
selection,
@ -678,6 +684,20 @@ export function codeToIdSelections(
id: entry.id,
}
}
if (entry.artifact.type === 'cap') {
bestCandidate = {
artifact: entry.artifact,
selection,
id: entry.id,
}
}
if (entry.artifact.type === 'wall') {
bestCandidate = {
artifact: entry.artifact,
selection,
id: entry.id,
}
}
if (type === 'extrude-wall' && entry.artifact.type === 'segment') {
if (!entry.artifact.surfaceId) return
const wall = engineCommandManager.artifactGraph.get(