Add id to all artifact types
This commit is contained in:
@ -3,6 +3,8 @@ import { Models } from '@kittycad/lib'
|
|||||||
import { getNodePathFromSourceRange } from 'lang/queryAst'
|
import { getNodePathFromSourceRange } from 'lang/queryAst'
|
||||||
import { err } from 'lib/trap'
|
import { err } from 'lib/trap'
|
||||||
|
|
||||||
|
export type ArtifactId = string
|
||||||
|
|
||||||
interface CommonCommandProperties {
|
interface CommonCommandProperties {
|
||||||
range: SourceRange
|
range: SourceRange
|
||||||
pathToNode: PathToNode
|
pathToNode: PathToNode
|
||||||
@ -10,17 +12,20 @@ interface CommonCommandProperties {
|
|||||||
|
|
||||||
export interface PlaneArtifact {
|
export interface PlaneArtifact {
|
||||||
type: 'plane'
|
type: 'plane'
|
||||||
|
id: ArtifactId
|
||||||
pathIds: Array<string>
|
pathIds: Array<string>
|
||||||
codeRef: CommonCommandProperties
|
codeRef: CommonCommandProperties
|
||||||
}
|
}
|
||||||
export interface PlaneArtifactRich {
|
export interface PlaneArtifactRich {
|
||||||
type: 'plane'
|
type: 'plane'
|
||||||
|
id: ArtifactId
|
||||||
paths: Array<PathArtifact>
|
paths: Array<PathArtifact>
|
||||||
codeRef: CommonCommandProperties
|
codeRef: CommonCommandProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PathArtifact {
|
export interface PathArtifact {
|
||||||
type: 'path'
|
type: 'path'
|
||||||
|
id: ArtifactId
|
||||||
planeId: string
|
planeId: string
|
||||||
segIds: Array<string>
|
segIds: Array<string>
|
||||||
extrusionId: string
|
extrusionId: string
|
||||||
@ -30,10 +35,12 @@ export interface PathArtifact {
|
|||||||
|
|
||||||
interface solid2D {
|
interface solid2D {
|
||||||
type: 'solid2D'
|
type: 'solid2D'
|
||||||
|
id: ArtifactId
|
||||||
pathId: string
|
pathId: string
|
||||||
}
|
}
|
||||||
export interface PathArtifactRich {
|
export interface PathArtifactRich {
|
||||||
type: 'path'
|
type: 'path'
|
||||||
|
id: ArtifactId
|
||||||
plane: PlaneArtifact | WallArtifact
|
plane: PlaneArtifact | WallArtifact
|
||||||
segments: Array<SegmentArtifact>
|
segments: Array<SegmentArtifact>
|
||||||
extrusion: ExtrusionArtifact
|
extrusion: ExtrusionArtifact
|
||||||
@ -42,6 +49,7 @@ export interface PathArtifactRich {
|
|||||||
|
|
||||||
interface SegmentArtifact {
|
interface SegmentArtifact {
|
||||||
type: 'segment'
|
type: 'segment'
|
||||||
|
id: ArtifactId
|
||||||
pathId: string
|
pathId: string
|
||||||
surfaceId: string
|
surfaceId: string
|
||||||
edgeIds: Array<string>
|
edgeIds: Array<string>
|
||||||
@ -50,6 +58,7 @@ interface SegmentArtifact {
|
|||||||
}
|
}
|
||||||
interface SegmentArtifactRich {
|
interface SegmentArtifactRich {
|
||||||
type: 'segment'
|
type: 'segment'
|
||||||
|
id: ArtifactId
|
||||||
path: PathArtifact
|
path: PathArtifact
|
||||||
surf: WallArtifact
|
surf: WallArtifact
|
||||||
edges: Array<ExtrudeEdge>
|
edges: Array<ExtrudeEdge>
|
||||||
@ -59,6 +68,7 @@ interface SegmentArtifactRich {
|
|||||||
|
|
||||||
interface ExtrusionArtifact {
|
interface ExtrusionArtifact {
|
||||||
type: 'extrusion'
|
type: 'extrusion'
|
||||||
|
id: ArtifactId
|
||||||
pathId: string
|
pathId: string
|
||||||
surfaceIds: Array<string>
|
surfaceIds: Array<string>
|
||||||
edgeIds: Array<string>
|
edgeIds: Array<string>
|
||||||
@ -66,6 +76,7 @@ interface ExtrusionArtifact {
|
|||||||
}
|
}
|
||||||
interface ExtrusionArtifactRich {
|
interface ExtrusionArtifactRich {
|
||||||
type: 'extrusion'
|
type: 'extrusion'
|
||||||
|
id: ArtifactId
|
||||||
path: PathArtifact
|
path: PathArtifact
|
||||||
surfaces: Array<WallArtifact | CapArtifact>
|
surfaces: Array<WallArtifact | CapArtifact>
|
||||||
edges: Array<ExtrudeEdge>
|
edges: Array<ExtrudeEdge>
|
||||||
@ -74,6 +85,7 @@ interface ExtrusionArtifactRich {
|
|||||||
|
|
||||||
interface WallArtifact {
|
interface WallArtifact {
|
||||||
type: 'wall'
|
type: 'wall'
|
||||||
|
id: ArtifactId
|
||||||
segId: string
|
segId: string
|
||||||
edgeCutEdgeIds: Array<string>
|
edgeCutEdgeIds: Array<string>
|
||||||
extrusionId: string
|
extrusionId: string
|
||||||
@ -81,6 +93,7 @@ interface WallArtifact {
|
|||||||
}
|
}
|
||||||
interface CapArtifact {
|
interface CapArtifact {
|
||||||
type: 'cap'
|
type: 'cap'
|
||||||
|
id: ArtifactId
|
||||||
subType: 'start' | 'end'
|
subType: 'start' | 'end'
|
||||||
edgeCutEdgeIds: Array<string>
|
edgeCutEdgeIds: Array<string>
|
||||||
extrusionId: string
|
extrusionId: string
|
||||||
@ -89,6 +102,7 @@ interface CapArtifact {
|
|||||||
|
|
||||||
interface ExtrudeEdge {
|
interface ExtrudeEdge {
|
||||||
type: 'extrudeEdge'
|
type: 'extrudeEdge'
|
||||||
|
id: ArtifactId
|
||||||
segId: string
|
segId: string
|
||||||
extrusionId: string
|
extrusionId: string
|
||||||
edgeId: string
|
edgeId: string
|
||||||
@ -97,6 +111,7 @@ interface ExtrudeEdge {
|
|||||||
/** A edgeCut is a more generic term for both fillet or chamfer */
|
/** A edgeCut is a more generic term for both fillet or chamfer */
|
||||||
interface EdgeCut {
|
interface EdgeCut {
|
||||||
type: 'edgeCut'
|
type: 'edgeCut'
|
||||||
|
id: ArtifactId
|
||||||
subType: 'fillet' | 'chamfer'
|
subType: 'fillet' | 'chamfer'
|
||||||
consumedEdgeId: string
|
consumedEdgeId: string
|
||||||
edgeIds: Array<string>
|
edgeIds: Array<string>
|
||||||
@ -106,6 +121,7 @@ interface EdgeCut {
|
|||||||
|
|
||||||
interface EdgeCutEdge {
|
interface EdgeCutEdge {
|
||||||
type: 'edgeCutEdge'
|
type: 'edgeCutEdge'
|
||||||
|
id: ArtifactId
|
||||||
edgeCutId: string
|
edgeCutId: string
|
||||||
surfaceId: string
|
surfaceId: string
|
||||||
}
|
}
|
||||||
@ -122,8 +138,6 @@ export type Artifact =
|
|||||||
| EdgeCutEdge
|
| EdgeCutEdge
|
||||||
| solid2D
|
| solid2D
|
||||||
|
|
||||||
export type ArtifactId = string
|
|
||||||
|
|
||||||
export type ArtifactGraph = Map<ArtifactId, Artifact>
|
export type ArtifactGraph = Map<ArtifactId, Artifact>
|
||||||
|
|
||||||
export type EngineCommand = Models['WebSocketRequest_type']
|
export type EngineCommand = Models['WebSocketRequest_type']
|
||||||
@ -255,6 +269,7 @@ export function getArtifactsToUpdate({
|
|||||||
id: currentPlaneId,
|
id: currentPlaneId,
|
||||||
artifact: {
|
artifact: {
|
||||||
type: 'wall',
|
type: 'wall',
|
||||||
|
id: currentPlaneId,
|
||||||
segId: existingPlane.segId,
|
segId: existingPlane.segId,
|
||||||
edgeCutEdgeIds: existingPlane.edgeCutEdgeIds,
|
edgeCutEdgeIds: existingPlane.edgeCutEdgeIds,
|
||||||
extrusionId: existingPlane.extrusionId,
|
extrusionId: existingPlane.extrusionId,
|
||||||
@ -264,7 +279,10 @@ export function getArtifactsToUpdate({
|
|||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
return [
|
return [
|
||||||
{ id: currentPlaneId, artifact: { type: 'plane', pathIds, codeRef } },
|
{
|
||||||
|
id: currentPlaneId,
|
||||||
|
artifact: { type: 'plane', id: currentPlaneId, pathIds, codeRef },
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
} else if (cmd.type === 'start_path') {
|
} else if (cmd.type === 'start_path') {
|
||||||
@ -272,6 +290,7 @@ export function getArtifactsToUpdate({
|
|||||||
id,
|
id,
|
||||||
artifact: {
|
artifact: {
|
||||||
type: 'path',
|
type: 'path',
|
||||||
|
id,
|
||||||
segIds: [],
|
segIds: [],
|
||||||
planeId: currentPlaneId,
|
planeId: currentPlaneId,
|
||||||
extrusionId: '',
|
extrusionId: '',
|
||||||
@ -284,7 +303,7 @@ export function getArtifactsToUpdate({
|
|||||||
if (plane?.type === 'plane') {
|
if (plane?.type === 'plane') {
|
||||||
returnArr.push({
|
returnArr.push({
|
||||||
id: currentPlaneId,
|
id: currentPlaneId,
|
||||||
artifact: { type: 'plane', pathIds: [id], codeRef },
|
artifact: { type: 'plane', id: currentPlaneId, pathIds: [id], codeRef },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (plane?.type === 'wall') {
|
if (plane?.type === 'wall') {
|
||||||
@ -292,6 +311,7 @@ export function getArtifactsToUpdate({
|
|||||||
id: currentPlaneId,
|
id: currentPlaneId,
|
||||||
artifact: {
|
artifact: {
|
||||||
type: 'wall',
|
type: 'wall',
|
||||||
|
id: currentPlaneId,
|
||||||
segId: plane.segId,
|
segId: plane.segId,
|
||||||
edgeCutEdgeIds: plane.edgeCutEdgeIds,
|
edgeCutEdgeIds: plane.edgeCutEdgeIds,
|
||||||
extrusionId: plane.extrusionId,
|
extrusionId: plane.extrusionId,
|
||||||
@ -306,6 +326,7 @@ export function getArtifactsToUpdate({
|
|||||||
id,
|
id,
|
||||||
artifact: {
|
artifact: {
|
||||||
type: 'segment',
|
type: 'segment',
|
||||||
|
id,
|
||||||
pathId,
|
pathId,
|
||||||
surfaceId: '',
|
surfaceId: '',
|
||||||
edgeIds: [],
|
edgeIds: [],
|
||||||
@ -315,21 +336,22 @@ export function getArtifactsToUpdate({
|
|||||||
const path = getArtifact(pathId)
|
const path = getArtifact(pathId)
|
||||||
if (path?.type === 'path')
|
if (path?.type === 'path')
|
||||||
returnArr.push({
|
returnArr.push({
|
||||||
id: pathId,
|
id: path.id,
|
||||||
artifact: { ...path, segIds: [id] },
|
artifact: { ...path, segIds: [id] },
|
||||||
})
|
})
|
||||||
if (
|
if (
|
||||||
response?.type === 'modeling' &&
|
response?.type === 'modeling' &&
|
||||||
response.data.modeling_response.type === 'close_path'
|
response.data.modeling_response.type === 'close_path'
|
||||||
) {
|
) {
|
||||||
|
const id = response.data.modeling_response.data.face_id
|
||||||
returnArr.push({
|
returnArr.push({
|
||||||
id: response.data.modeling_response.data.face_id,
|
id,
|
||||||
artifact: { type: 'solid2D', pathId },
|
artifact: { type: 'solid2D', id, pathId },
|
||||||
})
|
})
|
||||||
const path = getArtifact(pathId)
|
const path = getArtifact(pathId)
|
||||||
if (path?.type === 'path')
|
if (path?.type === 'path')
|
||||||
returnArr.push({
|
returnArr.push({
|
||||||
id: pathId,
|
id: path.id,
|
||||||
artifact: {
|
artifact: {
|
||||||
...path,
|
...path,
|
||||||
solid2dId: response.data.modeling_response.data.face_id,
|
solid2dId: response.data.modeling_response.data.face_id,
|
||||||
@ -342,6 +364,7 @@ export function getArtifactsToUpdate({
|
|||||||
id,
|
id,
|
||||||
artifact: {
|
artifact: {
|
||||||
type: 'extrusion',
|
type: 'extrusion',
|
||||||
|
id,
|
||||||
pathId: cmd.target,
|
pathId: cmd.target,
|
||||||
surfaceIds: [],
|
surfaceIds: [],
|
||||||
edgeIds: [],
|
edgeIds: [],
|
||||||
@ -351,7 +374,7 @@ export function getArtifactsToUpdate({
|
|||||||
const path = getArtifact(cmd.target)
|
const path = getArtifact(cmd.target)
|
||||||
if (path?.type === 'path')
|
if (path?.type === 'path')
|
||||||
returnArr.push({
|
returnArr.push({
|
||||||
id: cmd.target,
|
id: path.id,
|
||||||
artifact: { ...path, extrusionId: id },
|
artifact: { ...path, extrusionId: id },
|
||||||
})
|
})
|
||||||
return returnArr
|
return returnArr
|
||||||
@ -373,6 +396,7 @@ export function getArtifactsToUpdate({
|
|||||||
id: face_id,
|
id: face_id,
|
||||||
artifact: {
|
artifact: {
|
||||||
type: 'wall',
|
type: 'wall',
|
||||||
|
id: face_id,
|
||||||
segId: curve_id,
|
segId: curve_id,
|
||||||
edgeCutEdgeIds: [],
|
edgeCutEdgeIds: [],
|
||||||
extrusionId: path.extrusionId,
|
extrusionId: path.extrusionId,
|
||||||
@ -380,7 +404,7 @@ export function getArtifactsToUpdate({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
returnArr.push({
|
returnArr.push({
|
||||||
id: curve_id,
|
id: seg.id,
|
||||||
artifact: { ...seg, surfaceId: face_id },
|
artifact: { ...seg, surfaceId: face_id },
|
||||||
})
|
})
|
||||||
const extrusion = getArtifact(path.extrusionId)
|
const extrusion = getArtifact(path.extrusionId)
|
||||||
@ -405,6 +429,7 @@ export function getArtifactsToUpdate({
|
|||||||
id: face_id,
|
id: face_id,
|
||||||
artifact: {
|
artifact: {
|
||||||
type: 'cap',
|
type: 'cap',
|
||||||
|
id: face_id,
|
||||||
subType: cap === 'bottom' ? 'start' : 'end',
|
subType: cap === 'bottom' ? 'start' : 'end',
|
||||||
edgeCutEdgeIds: [],
|
edgeCutEdgeIds: [],
|
||||||
extrusionId: path.extrusionId,
|
extrusionId: path.extrusionId,
|
||||||
@ -414,7 +439,7 @@ export function getArtifactsToUpdate({
|
|||||||
const extrusion = getArtifact(path.extrusionId)
|
const extrusion = getArtifact(path.extrusionId)
|
||||||
if (extrusion?.type !== 'extrusion') return
|
if (extrusion?.type !== 'extrusion') return
|
||||||
returnArr.push({
|
returnArr.push({
|
||||||
id: path.extrusionId,
|
id: extrusion.id,
|
||||||
artifact: {
|
artifact: {
|
||||||
...extrusion,
|
...extrusion,
|
||||||
surfaceIds: [face_id],
|
surfaceIds: [face_id],
|
||||||
@ -429,6 +454,7 @@ export function getArtifactsToUpdate({
|
|||||||
id,
|
id,
|
||||||
artifact: {
|
artifact: {
|
||||||
type: 'edgeCut',
|
type: 'edgeCut',
|
||||||
|
id,
|
||||||
subType: cmd.cut_type,
|
subType: cmd.cut_type,
|
||||||
consumedEdgeId: cmd.edge_id,
|
consumedEdgeId: cmd.edge_id,
|
||||||
edgeIds: [],
|
edgeIds: [],
|
||||||
@ -439,7 +465,7 @@ export function getArtifactsToUpdate({
|
|||||||
const consumedEdge = getArtifact(cmd.edge_id)
|
const consumedEdge = getArtifact(cmd.edge_id)
|
||||||
if (consumedEdge?.type === 'segment') {
|
if (consumedEdge?.type === 'segment') {
|
||||||
returnArr.push({
|
returnArr.push({
|
||||||
id: cmd.edge_id,
|
id: consumedEdge.id,
|
||||||
artifact: { ...consumedEdge, edgeCutId: id },
|
artifact: { ...consumedEdge, edgeCutId: id },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -519,6 +545,7 @@ export function expandPlane(
|
|||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
type: 'plane',
|
type: 'plane',
|
||||||
|
id: plane.id,
|
||||||
paths: Array.from(paths.values()),
|
paths: Array.from(paths.values()),
|
||||||
codeRef: plane.codeRef,
|
codeRef: plane.codeRef,
|
||||||
}
|
}
|
||||||
@ -547,6 +574,7 @@ export function expandPath(
|
|||||||
if (err(plane)) return plane
|
if (err(plane)) return plane
|
||||||
return {
|
return {
|
||||||
type: 'path',
|
type: 'path',
|
||||||
|
id: path.id,
|
||||||
segments: Array.from(segs.values()),
|
segments: Array.from(segs.values()),
|
||||||
extrusion,
|
extrusion,
|
||||||
plane,
|
plane,
|
||||||
@ -573,6 +601,7 @@ export function expandExtrusion(
|
|||||||
if (err(path)) return path
|
if (err(path)) return path
|
||||||
return {
|
return {
|
||||||
type: 'extrusion',
|
type: 'extrusion',
|
||||||
|
id: extrusion.id,
|
||||||
surfaces: Array.from(surfs.values()),
|
surfaces: Array.from(surfs.values()),
|
||||||
edges: Array.from(edges.values()),
|
edges: Array.from(edges.values()),
|
||||||
path,
|
path,
|
||||||
@ -608,6 +637,7 @@ export function expandSegment(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'segment',
|
type: 'segment',
|
||||||
|
id: segment.id,
|
||||||
path,
|
path,
|
||||||
surf,
|
surf,
|
||||||
edges: Array.from(edges.values()),
|
edges: Array.from(edges.values()),
|
||||||
|
|||||||
Reference in New Issue
Block a user