From a84f53e2ed89655449d6a6e15dfa74bf8fc66dbf Mon Sep 17 00:00:00 2001 From: Kurt Hutten Irev-Dev Date: Thu, 19 Sep 2024 16:37:35 +1000 Subject: [PATCH] sketch on chamfer start --- src/hooks/useEngineConnectionSubscriptions.ts | 25 +++++++++++- src/lang/std/artifactGraph.ts | 38 ++++++++++++++++++- src/lang/std/sketch.ts | 5 +++ src/lib/selections.ts | 8 ++++ 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/hooks/useEngineConnectionSubscriptions.ts b/src/hooks/useEngineConnectionSubscriptions.ts index b542d93bf..908a3a0f8 100644 --- a/src/hooks/useEngineConnectionSubscriptions.ts +++ b/src/hooks/useEngineConnectionSubscriptions.ts @@ -11,6 +11,7 @@ import { getCapCodeRef, getSweepEdgeCodeRef, getSweepFromSuspectedSweepSurface, + getEdgeCuteConsumedCodeRef, getSolid2dCodeRef, getWallCodeRef, } from 'lang/std/artifactGraph' @@ -72,6 +73,17 @@ export function useEngineConnectionSubscriptions() { editorManager.setHighlightRange([ artifact?.codeRef?.range || [0, 0], ]) + } else if (artifact?.type === 'edgeCut') { + const codeRef = artifact.codeRef + const consumedCodeRef = getEdgeCuteConsumedCodeRef( + artifact, + engineCommandManager.artifactGraph + ) + editorManager.setHighlightRange( + err(consumedCodeRef) + ? [codeRef.range] + : [codeRef.range, consumedCodeRef.range] + ) } else { editorManager.setHighlightRange([[0, 0]]) } @@ -177,12 +189,21 @@ export function useEngineConnectionSubscriptions() { engineCommandManager.artifactGraph ) - if (artifact?.type !== 'cap' && artifact?.type !== 'wall') return + if ( + artifact?.type !== 'cap' && + artifact?.type !== 'wall' && + !( + artifact?.type === 'edgeCut' && artifact.subType === 'chamfer' + ) + ) + return const codeRef = artifact.type === 'cap' ? getCapCodeRef(artifact, engineCommandManager.artifactGraph) - : getWallCodeRef(artifact, engineCommandManager.artifactGraph) + : artifact.type === 'wall' + ? getWallCodeRef(artifact, engineCommandManager.artifactGraph) + : artifact.codeRef const faceInfo = await getFaceDetails(faceId) if (!faceInfo?.origin || !faceInfo?.z_axis || !faceInfo?.y_axis) diff --git a/src/lang/std/artifactGraph.ts b/src/lang/std/artifactGraph.ts index 0c2c27c10..2fae411d5 100644 --- a/src/lang/std/artifactGraph.ts +++ b/src/lang/std/artifactGraph.ts @@ -724,18 +724,52 @@ export function getSweepEdgeCodeRef( if (err(seg)) return seg return seg.codeRef } +export function getEdgeCuteConsumedCodeRef( + edge: EdgeCut, + artifactGraph: ArtifactGraph +): CommonCommandProperties | Error { + const seg = getArtifactOfTypes( + { key: edge.consumedEdgeId, types: ['segment', 'sweepEdge'] }, + artifactGraph + ) + if (err(seg)) return seg + if (seg.type === 'segment') return seg.codeRef + return getSweepEdgeCodeRef(seg, artifactGraph) +} export function getSweepFromSuspectedSweepSurface( id: ArtifactId, artifactGraph: ArtifactGraph ): SweepArtifact | Error { const artifact = getArtifactOfTypes( - { key: id, types: ['wall', 'cap'] }, + { key: id, types: ['wall', 'cap', 'edgeCut'] }, artifactGraph ) if (err(artifact)) return artifact + if (artifact.type === 'wall' || artifact.type === 'cap') { + return getArtifactOfTypes( + { key: artifact.sweepId, types: ['sweep'] }, + artifactGraph + ) + } + const segOrEdge = getArtifactOfTypes( + { key: artifact.consumedEdgeId, types: ['segment', 'sweepEdge'] }, + artifactGraph + ) + if (err(segOrEdge)) return segOrEdge + if (segOrEdge.type === 'segment') { + const path = getArtifactOfTypes( + { key: segOrEdge.pathId, types: ['path'] }, + artifactGraph + ) + if (err(path)) return path + return getArtifactOfTypes( + { key: path.sweepId, types: ['sweep'] }, + artifactGraph + ) + } return getArtifactOfTypes( - { key: artifact.sweepId, types: ['sweep'] }, + { key: segOrEdge.sweepId, types: ['sweep'] }, artifactGraph ) } diff --git a/src/lang/std/sketch.ts b/src/lang/std/sketch.ts index c212c279d..b1004f14f 100644 --- a/src/lang/std/sketch.ts +++ b/src/lang/std/sketch.ts @@ -1902,6 +1902,11 @@ export function addTagForSketchOnFace( if (expressionName === 'close') { return addTag(1)(tagInfo) } + if (expressionName === 'chamfer') { + // TODO: if there are two (or more) tags on the chamfer, it needs to pull out + // the relevant tag and put it into a separate chamfer call + return addTag(2)(tagInfo) + } if (expressionName in sketchLineHelperMap) { const { addTag } = sketchLineHelperMap[expressionName] return addTag(tagInfo) diff --git a/src/lib/selections.ts b/src/lib/selections.ts index e8fd58956..4c6291788 100644 --- a/src/lib/selections.ts +++ b/src/lib/selections.ts @@ -164,6 +164,14 @@ export async function getEventForSelectWithPoint({ }, } } + if (_artifact.type === 'edgeCut') + return { + type: 'Set selection', + data: { + selectionType: 'singleCodeCursor', + selection: { range: _artifact.codeRef.range, type: 'default' }, + }, + } return null }