2025-01-08 20:02:30 -05:00
|
|
|
import {
|
2025-01-17 14:34:36 -05:00
|
|
|
Artifact,
|
|
|
|
ArtifactGraph,
|
|
|
|
ArtifactId,
|
2025-01-08 20:02:30 -05:00
|
|
|
PathToNode,
|
|
|
|
Program,
|
|
|
|
SourceRange,
|
2025-01-17 14:34:36 -05:00
|
|
|
PathArtifact,
|
|
|
|
PlaneArtifact,
|
|
|
|
WallArtifact,
|
|
|
|
SegmentArtifact,
|
|
|
|
Solid2dArtifact as Solid2D,
|
|
|
|
SweepArtifact,
|
|
|
|
SweepEdge,
|
|
|
|
CapArtifact,
|
|
|
|
EdgeCut,
|
2025-01-08 20:02:30 -05:00
|
|
|
} from 'lang/wasm'
|
2024-08-03 18:08:51 +10:00
|
|
|
import { Models } from '@kittycad/lib'
|
2025-01-27 14:24:28 +01:00
|
|
|
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
|
2024-08-03 18:08:51 +10:00
|
|
|
import { err } from 'lib/trap'
|
Add edit flows for extrude and offset plane operations (#5045)
* Start implementing a "prepareToEdit" callback for extrude
* Start of generic edit flow for operations
* Actually invoking command bar send generically on double-click
* Refactor: break out non-React hook helper to calculate Kcl expression value
* Add unit tests, fmt
* Integrate helper to get calculated KclExpression
* Clean up unused imports, simplify use of `programMemoryFromVariables`
* Implement basic extrude editing
* Refactor: move DefaultPlanesStr to its own lib file
* Add support for editing offset planes
* Add Edit right-click menu option
* Turn off edit flow for sketch for now
* Add e2e tests for sketch and offset plane editing, fix bug found with offset plane editing
* Add failing e2e extrude edit test
* Remove action version of extrude AST mod
* Fix behavior when adding a constant while editing operation, fixing e2e test
* Patch in changes from 61b02b570394f11afbd04d0d126d87305165c73c
* Remove shell's prepareToEdit
* Add other Surface types to `artifactIsPlaneWithPaths`
* refactor: rename `item` to `operation`
* Allow `prepareToEdit` to fail with a toast, signal sketch-on-offset is unimplemented
* Rework sketch e2e test to test several working and failing cases
* Fix tsc errors related to making `codeRef` optional
* Make basic error messages more friendly
* fmt
* Reset modifyAst.ts to main
* Fix broken artifactGraph unit test
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* Remove unused import
* Look at this (photo)Graph *in the voice of Nickelback*
* Make the offset plane insert at the end, not one before
* Fix bug caught by e2e test failure with "Command needs review" logic
* Update src/machines/modelingMachine.ts
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Remove console logs per @pierremtb
* Update src/components/CommandBar/CommandBarHeader.tsx
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
* Use better programMemory init thanks @jtran
* Fix tsc post merge of #5068
* Fix logic for `artifactIsPlaneWithPaths` post-merge
* Need to disable the sketch-on-face case now that artifactGraph is in Rust. Will active in a future PR (cc @jtran)
* Re-run CI after snapshots
* Update FeatureTreePane to not use `useCommandsContext`, missed during merge
* Fix merge issue, import location change on edited file
* fix click test step, which I believe is waiting for context scripts to load
* Convert toolbarFixture.exeIndicator to getter
We need to convert all these selectors on fixtures to getters, because
they can go stale if called on the fixture constructor.
* Missed a dumb little thing in toolbarFixture.ts
* Fix goof with merge
* fmt
* Another dumb missed thing during merge
I gotta get used to the LazyGit merge tool I'm not good at it yet
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* Conver sceneFixture's exeIndicator to a getter
Locators on fixtures will be frozen from the time of the fixture's
initialization, I'm increasingly convinced
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* Post-kwargs E2E test cleanup
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
2025-02-05 19:33:40 -05:00
|
|
|
import { codeManager } from 'lib/singletons'
|
2024-08-03 18:08:51 +10:00
|
|
|
|
2025-01-17 14:34:36 -05:00
|
|
|
export type { Artifact, ArtifactId, SegmentArtifact } from 'lang/wasm'
|
2024-09-04 11:49:13 -04:00
|
|
|
|
2024-11-21 15:04:30 +11:00
|
|
|
interface BaseArtifact {
|
|
|
|
id: ArtifactId
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CodeRef {
|
2024-08-03 18:08:51 +10:00
|
|
|
range: SourceRange
|
|
|
|
pathToNode: PathToNode
|
|
|
|
}
|
|
|
|
|
2024-11-21 15:04:30 +11:00
|
|
|
export interface PlaneArtifactRich extends BaseArtifact {
|
2024-08-03 18:08:51 +10:00
|
|
|
type: 'plane'
|
|
|
|
paths: Array<PathArtifact>
|
2024-11-21 15:04:30 +11:00
|
|
|
codeRef: CodeRef
|
2024-08-03 18:08:51 +10:00
|
|
|
}
|
|
|
|
|
2024-11-21 15:04:30 +11:00
|
|
|
export interface PathArtifactRich extends BaseArtifact {
|
2024-08-03 18:08:51 +10:00
|
|
|
type: 'path'
|
2024-11-05 21:32:05 -08:00
|
|
|
/** A path must always lie on a plane */
|
2024-12-16 10:34:11 -05:00
|
|
|
plane: PlaneArtifact | WallArtifact
|
2024-11-05 21:32:05 -08:00
|
|
|
/** A path must always contain 0 or more segments */
|
2024-08-03 18:08:51 +10:00
|
|
|
segments: Array<SegmentArtifact>
|
2024-11-05 21:32:05 -08:00
|
|
|
/** A path may not result in a sweep artifact */
|
2025-01-17 14:34:36 -05:00
|
|
|
sweep: SweepArtifact | null
|
2024-11-21 15:04:30 +11:00
|
|
|
codeRef: CodeRef
|
2024-08-03 18:08:51 +10:00
|
|
|
}
|
|
|
|
|
2024-11-21 15:04:30 +11:00
|
|
|
interface SegmentArtifactRich extends BaseArtifact {
|
2024-08-03 18:08:51 +10:00
|
|
|
type: 'segment'
|
|
|
|
path: PathArtifact
|
2025-01-13 15:02:55 -05:00
|
|
|
surf?: WallArtifact
|
2024-12-16 10:34:11 -05:00
|
|
|
edges: Array<SweepEdge>
|
2024-08-03 18:08:51 +10:00
|
|
|
edgeCut?: EdgeCut
|
2024-11-21 15:04:30 +11:00
|
|
|
codeRef: CodeRef
|
2024-08-03 18:08:51 +10:00
|
|
|
}
|
|
|
|
|
2024-11-21 15:04:30 +11:00
|
|
|
interface SweepArtifactRich extends BaseArtifact {
|
2024-09-17 13:22:53 -05:00
|
|
|
type: 'sweep'
|
2025-01-11 08:20:49 -05:00
|
|
|
subType: 'extrusion' | 'revolve' | 'loft' | 'sweep'
|
2024-08-03 18:08:51 +10:00
|
|
|
path: PathArtifact
|
|
|
|
surfaces: Array<WallArtifact | CapArtifact>
|
2024-12-16 10:34:11 -05:00
|
|
|
edges: Array<SweepEdge>
|
2024-11-21 15:04:30 +11:00
|
|
|
codeRef: CodeRef
|
2024-08-03 18:08:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
export type EngineCommand = Models['WebSocketRequest_type']
|
|
|
|
|
|
|
|
type OkWebSocketResponseData = Models['OkWebSocketResponseData_type']
|
|
|
|
|
|
|
|
export interface ResponseMap {
|
|
|
|
[commandId: string]: OkWebSocketResponseData
|
|
|
|
}
|
|
|
|
|
|
|
|
/** filter map items of a specific type */
|
|
|
|
export function filterArtifacts<T extends Artifact['type'][]>(
|
|
|
|
{
|
|
|
|
types,
|
|
|
|
predicate,
|
|
|
|
}: {
|
|
|
|
types: T
|
|
|
|
predicate?: (value: Extract<Artifact, { type: T[number] }>) => boolean
|
|
|
|
},
|
|
|
|
map: ArtifactGraph
|
|
|
|
) {
|
|
|
|
return new Map(
|
|
|
|
Array.from(map).filter(
|
|
|
|
([_, value]) =>
|
|
|
|
types.includes(value.type) &&
|
|
|
|
(!predicate ||
|
|
|
|
predicate(value as Extract<Artifact, { type: T[number] }>))
|
|
|
|
)
|
2024-09-04 11:49:13 -04:00
|
|
|
) as Map<ArtifactId, Extract<Artifact, { type: T[number] }>>
|
2024-08-03 18:08:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getArtifactsOfTypes<T extends Artifact['type'][]>(
|
|
|
|
{
|
|
|
|
keys,
|
|
|
|
types,
|
|
|
|
predicate,
|
|
|
|
}: {
|
|
|
|
keys: string[]
|
|
|
|
types: T
|
|
|
|
predicate?: (value: Extract<Artifact, { type: T[number] }>) => boolean
|
|
|
|
},
|
|
|
|
map: ArtifactGraph
|
2024-09-04 11:49:13 -04:00
|
|
|
): Map<ArtifactId, Extract<Artifact, { type: T[number] }>> {
|
2024-08-03 18:08:51 +10:00
|
|
|
return new Map(
|
|
|
|
[...map].filter(
|
|
|
|
([key, value]) =>
|
|
|
|
keys.includes(key) &&
|
|
|
|
types.includes(value.type) &&
|
|
|
|
(!predicate ||
|
|
|
|
predicate(value as Extract<Artifact, { type: T[number] }>))
|
|
|
|
)
|
2024-09-04 11:49:13 -04:00
|
|
|
) as Map<ArtifactId, Extract<Artifact, { type: T[number] }>>
|
2024-08-03 18:08:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getArtifactOfTypes<T extends Artifact['type'][]>(
|
|
|
|
{
|
|
|
|
key,
|
|
|
|
types,
|
|
|
|
}: {
|
2024-09-04 11:49:13 -04:00
|
|
|
key: ArtifactId
|
2024-08-03 18:08:51 +10:00
|
|
|
types: T
|
|
|
|
},
|
|
|
|
map: ArtifactGraph
|
|
|
|
): Extract<Artifact, { type: T[number] }> | Error {
|
|
|
|
const artifact = map.get(key)
|
|
|
|
if (!artifact) return new Error(`No artifact found with key ${key}`)
|
|
|
|
if (!types.includes(artifact?.type))
|
|
|
|
return new Error(`Expected ${types} but got ${artifact?.type}`)
|
|
|
|
return artifact as Extract<Artifact, { type: T[number] }>
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expandPlane(
|
|
|
|
plane: PlaneArtifact,
|
|
|
|
artifactGraph: ArtifactGraph
|
|
|
|
): PlaneArtifactRich {
|
|
|
|
const paths = getArtifactsOfTypes(
|
|
|
|
{ keys: plane.pathIds, types: ['path'] },
|
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
return {
|
|
|
|
type: 'plane',
|
2024-11-21 15:04:30 +11:00
|
|
|
id: plane.id,
|
2024-08-03 18:08:51 +10:00
|
|
|
paths: Array.from(paths.values()),
|
|
|
|
codeRef: plane.codeRef,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expandPath(
|
|
|
|
path: PathArtifact,
|
|
|
|
artifactGraph: ArtifactGraph
|
|
|
|
): PathArtifactRich | Error {
|
|
|
|
const segs = getArtifactsOfTypes(
|
|
|
|
{ keys: path.segIds, types: ['segment'] },
|
|
|
|
artifactGraph
|
|
|
|
)
|
2024-11-05 21:32:05 -08:00
|
|
|
const sweep = path.sweepId
|
|
|
|
? getArtifactOfTypes(
|
|
|
|
{
|
|
|
|
key: path.sweepId,
|
|
|
|
types: ['sweep'],
|
|
|
|
},
|
|
|
|
artifactGraph
|
|
|
|
)
|
2025-01-17 14:34:36 -05:00
|
|
|
: null
|
2024-08-03 18:08:51 +10:00
|
|
|
const plane = getArtifactOfTypes(
|
|
|
|
{ key: path.planeId, types: ['plane', 'wall'] },
|
|
|
|
artifactGraph
|
|
|
|
)
|
2024-09-17 13:22:53 -05:00
|
|
|
if (err(sweep)) return sweep
|
2024-08-03 18:08:51 +10:00
|
|
|
if (err(plane)) return plane
|
|
|
|
return {
|
|
|
|
type: 'path',
|
2024-11-21 15:04:30 +11:00
|
|
|
id: path.id,
|
2024-08-03 18:08:51 +10:00
|
|
|
segments: Array.from(segs.values()),
|
2024-09-17 13:22:53 -05:00
|
|
|
sweep,
|
2024-08-03 18:08:51 +10:00
|
|
|
plane,
|
|
|
|
codeRef: path.codeRef,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-17 13:22:53 -05:00
|
|
|
export function expandSweep(
|
|
|
|
sweep: SweepArtifact,
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph: ArtifactGraph
|
2024-09-17 13:22:53 -05:00
|
|
|
): SweepArtifactRich | Error {
|
2024-08-03 18:08:51 +10:00
|
|
|
const surfs = getArtifactsOfTypes(
|
2024-09-17 13:22:53 -05:00
|
|
|
{ keys: sweep.surfaceIds, types: ['wall', 'cap'] },
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
const edges = getArtifactsOfTypes(
|
2024-09-17 13:22:53 -05:00
|
|
|
{ keys: sweep.edgeIds, types: ['sweepEdge'] },
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
const path = getArtifactOfTypes(
|
2024-09-17 13:22:53 -05:00
|
|
|
{ key: sweep.pathId, types: ['path'] },
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
if (err(path)) return path
|
|
|
|
return {
|
2024-09-17 13:22:53 -05:00
|
|
|
type: 'sweep',
|
2024-11-12 15:49:49 -05:00
|
|
|
subType: sweep.subType,
|
2024-11-21 15:04:30 +11:00
|
|
|
id: sweep.id,
|
2024-08-03 18:08:51 +10:00
|
|
|
surfaces: Array.from(surfs.values()),
|
|
|
|
edges: Array.from(edges.values()),
|
|
|
|
path,
|
2024-09-17 13:22:53 -05:00
|
|
|
codeRef: sweep.codeRef,
|
2024-08-03 18:08:51 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expandSegment(
|
|
|
|
segment: SegmentArtifact,
|
|
|
|
artifactGraph: ArtifactGraph
|
|
|
|
): SegmentArtifactRich | Error {
|
|
|
|
const path = getArtifactOfTypes(
|
|
|
|
{ key: segment.pathId, types: ['path'] },
|
|
|
|
artifactGraph
|
|
|
|
)
|
2025-01-13 15:02:55 -05:00
|
|
|
const surf = segment.surfaceId
|
|
|
|
? getArtifactOfTypes(
|
|
|
|
{ key: segment.surfaceId, types: ['wall'] },
|
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
: undefined
|
2024-08-03 18:08:51 +10:00
|
|
|
const edges = getArtifactsOfTypes(
|
2024-09-17 13:22:53 -05:00
|
|
|
{ keys: segment.edgeIds, types: ['sweepEdge'] },
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
const edgeCut = segment.edgeCutId
|
|
|
|
? getArtifactOfTypes(
|
|
|
|
{ key: segment.edgeCutId, types: ['edgeCut'] },
|
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
: undefined
|
|
|
|
if (err(path)) return path
|
|
|
|
if (err(surf)) return surf
|
|
|
|
if (err(edgeCut)) return edgeCut
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'segment',
|
2024-11-21 15:04:30 +11:00
|
|
|
id: segment.id,
|
2024-08-03 18:08:51 +10:00
|
|
|
path,
|
|
|
|
surf,
|
|
|
|
edges: Array.from(edges.values()),
|
|
|
|
edgeCut: edgeCut,
|
|
|
|
codeRef: segment.codeRef,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getCapCodeRef(
|
|
|
|
cap: CapArtifact,
|
|
|
|
artifactGraph: ArtifactGraph
|
2024-11-21 15:04:30 +11:00
|
|
|
): CodeRef | Error {
|
2024-09-17 13:22:53 -05:00
|
|
|
const sweep = getArtifactOfTypes(
|
|
|
|
{ key: cap.sweepId, types: ['sweep'] },
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph
|
|
|
|
)
|
2024-09-17 13:22:53 -05:00
|
|
|
if (err(sweep)) return sweep
|
2024-08-03 18:08:51 +10:00
|
|
|
const path = getArtifactOfTypes(
|
2024-09-17 13:22:53 -05:00
|
|
|
{ key: sweep.pathId, types: ['path'] },
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
if (err(path)) return path
|
|
|
|
return path.codeRef
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSolid2dCodeRef(
|
2025-01-17 14:34:36 -05:00
|
|
|
solid2d: Solid2D,
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph: ArtifactGraph
|
2024-11-21 15:04:30 +11:00
|
|
|
): CodeRef | Error {
|
2024-08-03 18:08:51 +10:00
|
|
|
const path = getArtifactOfTypes(
|
2025-01-17 14:34:36 -05:00
|
|
|
{ key: solid2d.pathId, types: ['path'] },
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
if (err(path)) return path
|
|
|
|
return path.codeRef
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getWallCodeRef(
|
|
|
|
wall: WallArtifact,
|
|
|
|
artifactGraph: ArtifactGraph
|
2024-11-21 15:04:30 +11:00
|
|
|
): CodeRef | Error {
|
2024-08-03 18:08:51 +10:00
|
|
|
const seg = getArtifactOfTypes(
|
|
|
|
{ key: wall.segId, types: ['segment'] },
|
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
if (err(seg)) return seg
|
|
|
|
return seg.codeRef
|
|
|
|
}
|
|
|
|
|
2024-09-17 13:22:53 -05:00
|
|
|
export function getSweepEdgeCodeRef(
|
2024-12-16 10:34:11 -05:00
|
|
|
edge: SweepEdge,
|
2024-08-30 19:46:48 +10:00
|
|
|
artifactGraph: ArtifactGraph
|
2024-11-21 15:04:30 +11:00
|
|
|
): CodeRef | Error {
|
2024-08-30 19:46:48 +10:00
|
|
|
const seg = getArtifactOfTypes(
|
|
|
|
{ key: edge.segId, types: ['segment'] },
|
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
if (err(seg)) return seg
|
|
|
|
return seg.codeRef
|
|
|
|
}
|
2024-11-21 15:04:30 +11:00
|
|
|
export function getEdgeCutConsumedCodeRef(
|
2024-09-26 18:25:05 +10:00
|
|
|
edge: EdgeCut,
|
|
|
|
artifactGraph: ArtifactGraph
|
2024-11-21 15:04:30 +11:00
|
|
|
): CodeRef | Error {
|
2024-09-26 18:25:05 +10:00
|
|
|
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)
|
|
|
|
}
|
2024-08-30 19:46:48 +10:00
|
|
|
|
2024-09-17 13:22:53 -05:00
|
|
|
export function getSweepFromSuspectedSweepSurface(
|
2024-09-04 11:49:13 -04:00
|
|
|
id: ArtifactId,
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph: ArtifactGraph
|
2024-09-17 13:22:53 -05:00
|
|
|
): SweepArtifact | Error {
|
2024-08-03 18:08:51 +10:00
|
|
|
const artifact = getArtifactOfTypes(
|
2024-09-26 18:25:05 +10:00
|
|
|
{ key: id, types: ['wall', 'cap', 'edgeCut'] },
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
if (err(artifact)) return artifact
|
2024-09-26 18:25:05 +10:00
|
|
|
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
|
2025-01-13 15:02:55 -05:00
|
|
|
if (!path.sweepId) return new Error('Path does not have a sweepId')
|
2024-09-26 18:25:05 +10:00
|
|
|
return getArtifactOfTypes(
|
|
|
|
{ key: path.sweepId, types: ['sweep'] },
|
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
}
|
2024-08-03 18:08:51 +10:00
|
|
|
return getArtifactOfTypes(
|
2024-09-26 18:25:05 +10:00
|
|
|
{ key: segOrEdge.sweepId, types: ['sweep'] },
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-09-17 13:22:53 -05:00
|
|
|
export function getSweepFromSuspectedPath(
|
2024-09-04 11:49:13 -04:00
|
|
|
id: ArtifactId,
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph: ArtifactGraph
|
2024-09-17 13:22:53 -05:00
|
|
|
): SweepArtifact | Error {
|
2024-08-03 18:08:51 +10:00
|
|
|
const path = getArtifactOfTypes({ key: id, types: ['path'] }, artifactGraph)
|
|
|
|
if (err(path)) return path
|
2025-01-13 15:02:55 -05:00
|
|
|
if (!path.sweepId) return new Error('Path does not have a sweepId')
|
2024-08-03 18:08:51 +10:00
|
|
|
return getArtifactOfTypes(
|
2024-09-17 13:22:53 -05:00
|
|
|
{ key: path.sweepId, types: ['sweep'] },
|
2024-08-03 18:08:51 +10:00
|
|
|
artifactGraph
|
|
|
|
)
|
|
|
|
}
|
2024-11-21 15:04:30 +11:00
|
|
|
|
|
|
|
export function getCodeRefsByArtifactId(
|
|
|
|
id: string,
|
|
|
|
artifactGraph: ArtifactGraph
|
|
|
|
): Array<CodeRef> | null {
|
|
|
|
const artifact = artifactGraph.get(id)
|
2025-01-17 14:34:36 -05:00
|
|
|
if (artifact?.type === 'solid2d') {
|
2024-11-21 15:04:30 +11:00
|
|
|
const codeRef = getSolid2dCodeRef(artifact, artifactGraph)
|
|
|
|
if (err(codeRef)) return null
|
|
|
|
return [codeRef]
|
|
|
|
} else if (artifact?.type === 'cap') {
|
|
|
|
const codeRef = getCapCodeRef(artifact, artifactGraph)
|
|
|
|
if (err(codeRef)) return null
|
|
|
|
return [codeRef]
|
|
|
|
} else if (artifact?.type === 'wall') {
|
|
|
|
const extrusion = getSweepFromSuspectedSweepSurface(id, artifactGraph)
|
|
|
|
const codeRef = getWallCodeRef(artifact, artifactGraph)
|
|
|
|
if (err(codeRef)) return null
|
|
|
|
return err(extrusion) ? [codeRef] : [codeRef, extrusion.codeRef]
|
|
|
|
} else if (artifact?.type === 'sweepEdge') {
|
|
|
|
const codeRef = getSweepEdgeCodeRef(artifact, artifactGraph)
|
|
|
|
if (err(codeRef)) return null
|
|
|
|
return [codeRef]
|
|
|
|
} else if (artifact?.type === 'segment') {
|
|
|
|
return [artifact.codeRef]
|
|
|
|
} else if (artifact?.type === 'edgeCut') {
|
|
|
|
const codeRef = artifact.codeRef
|
|
|
|
const consumedCodeRef = getEdgeCutConsumedCodeRef(artifact, artifactGraph)
|
|
|
|
if (err(consumedCodeRef)) return [codeRef]
|
|
|
|
return [codeRef, consumedCodeRef]
|
|
|
|
} else if (artifact && 'codeRef' in artifact) {
|
|
|
|
return [artifact.codeRef]
|
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function codeRefFromRange(range: SourceRange, ast: Program): CodeRef {
|
|
|
|
return {
|
|
|
|
range,
|
|
|
|
pathToNode: getNodePathFromSourceRange(ast, range),
|
|
|
|
}
|
|
|
|
}
|
2024-12-17 15:12:18 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an artifact from a code source range
|
|
|
|
*/
|
|
|
|
export function getArtifactFromRange(
|
|
|
|
range: SourceRange,
|
|
|
|
artifactGraph: ArtifactGraph
|
|
|
|
): Artifact | null {
|
|
|
|
for (const artifact of artifactGraph.values()) {
|
|
|
|
if ('codeRef' in artifact) {
|
|
|
|
const match =
|
2024-12-20 16:19:59 -05:00
|
|
|
artifact.codeRef?.range[0] === range[0] &&
|
2024-12-17 15:12:18 -05:00
|
|
|
artifact.codeRef.range[1] === range[1]
|
|
|
|
if (match) return artifact
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|