Add Rust side artifacts for startSketchOn face or plane
This commit is contained in:
@ -313,6 +313,8 @@ export class KclManager {
|
||||
this.addDiagnostics(await lintAst({ ast: ast }))
|
||||
setSelectionFilterToDefault(execState.memory, this.engineCommandManager)
|
||||
|
||||
console.log('executeAst artifacts', execState.artifacts)
|
||||
|
||||
if (args.zoomToFit) {
|
||||
let zoomObjectId: string | undefined = ''
|
||||
if (args.zoomOnRangeAndType) {
|
||||
|
||||
@ -44,7 +44,11 @@ import { CompilationError } from 'wasm-lib/kcl/bindings/CompilationError'
|
||||
import { SourceRange as RustSourceRange } from 'wasm-lib/kcl/bindings/SourceRange'
|
||||
import { getAllCurrentSettings } from 'lib/settings/settingsUtils'
|
||||
import { KclErrorWithOutputs } from 'wasm-lib/kcl/bindings/KclErrorWithOutputs'
|
||||
import { Artifact } from 'wasm-lib/kcl/bindings/Artifact'
|
||||
import { ArtifactId } from 'wasm-lib/kcl/bindings/ArtifactId'
|
||||
|
||||
export type { Artifact } from 'wasm-lib/kcl/bindings/Artifact'
|
||||
export type { ArtifactId } from 'wasm-lib/kcl/bindings/ArtifactId'
|
||||
export type { Configuration } from 'wasm-lib/kcl/bindings/Configuration'
|
||||
export type { Program } from '../wasm-lib/kcl/bindings/Program'
|
||||
export type { Expr } from '../wasm-lib/kcl/bindings/Expr'
|
||||
@ -245,6 +249,7 @@ export const isPathToNodeNumber = (
|
||||
|
||||
export interface ExecState {
|
||||
memory: ProgramMemory
|
||||
artifacts: { [key in ArtifactId]?: Artifact }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -254,12 +259,14 @@ export interface ExecState {
|
||||
export function emptyExecState(): ExecState {
|
||||
return {
|
||||
memory: ProgramMemory.empty(),
|
||||
artifacts: {},
|
||||
}
|
||||
}
|
||||
|
||||
function execStateFromRaw(raw: RawExecState): ExecState {
|
||||
return {
|
||||
memory: ProgramMemory.fromRaw(raw.modLocal.memory),
|
||||
artifacts: raw.global.artifacts,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
47
src/wasm-lib/kcl/src/execution/artifact.rs
Normal file
47
src/wasm-lib/kcl/src/execution/artifact.rs
Normal file
@ -0,0 +1,47 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::SourceRange;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Hash, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
pub struct ArtifactId(Uuid);
|
||||
|
||||
impl ArtifactId {
|
||||
pub fn new(uuid: Uuid) -> Self {
|
||||
Self(uuid)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Uuid> for ArtifactId {
|
||||
fn from(uuid: Uuid) -> Self {
|
||||
Self::new(uuid)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Uuid> for ArtifactId {
|
||||
fn from(uuid: &Uuid) -> Self {
|
||||
Self::new(*uuid)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Artifact {
|
||||
pub id: ArtifactId,
|
||||
#[serde(flatten)]
|
||||
pub inner: ArtifactInner,
|
||||
pub source_range: SourceRange,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum ArtifactInner {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
StartSketchOnFace { face_id: Uuid },
|
||||
#[serde(rename_all = "camelCase")]
|
||||
StartSketchOnPlane { plane_id: Uuid },
|
||||
}
|
||||
@ -25,6 +25,7 @@ pub use kcl_value::{KclObjectFields, KclValue};
|
||||
use uuid::Uuid;
|
||||
|
||||
mod annotations;
|
||||
mod artifact;
|
||||
pub(crate) mod cache;
|
||||
mod cad_op;
|
||||
mod exec_ast;
|
||||
@ -47,6 +48,7 @@ use crate::{
|
||||
};
|
||||
|
||||
// Re-exports.
|
||||
pub use artifact::{Artifact, ArtifactId, ArtifactInner};
|
||||
pub use cad_op::Operation;
|
||||
|
||||
/// State for executing a program.
|
||||
@ -68,6 +70,8 @@ pub struct GlobalState {
|
||||
pub path_to_source_id: IndexMap<std::path::PathBuf, ModuleId>,
|
||||
/// Map from module ID to module info.
|
||||
pub module_infos: IndexMap<ModuleId, ModuleInfo>,
|
||||
/// Output map of UUIDs to artifacts.
|
||||
pub artifacts: IndexMap<ArtifactId, Artifact>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
@ -134,6 +138,11 @@ impl ExecState {
|
||||
self.global.id_generator.next_uuid()
|
||||
}
|
||||
|
||||
pub fn add_artifact(&mut self, artifact: Artifact) {
|
||||
let id = artifact.id;
|
||||
self.global.artifacts.insert(id, artifact);
|
||||
}
|
||||
|
||||
async fn add_module(
|
||||
&mut self,
|
||||
path: std::path::PathBuf,
|
||||
@ -171,6 +180,7 @@ impl GlobalState {
|
||||
id_generator: Default::default(),
|
||||
path_to_source_id: Default::default(),
|
||||
module_infos: Default::default(),
|
||||
artifacts: Default::default(),
|
||||
};
|
||||
|
||||
// TODO(#4434): Use the top-level file's path.
|
||||
|
||||
@ -11,6 +11,7 @@ use parse_display::{Display, FromStr};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::execution::{Artifact, ArtifactId, ArtifactInner};
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
execution::{
|
||||
@ -1075,7 +1076,17 @@ async fn inner_start_sketch_on(
|
||||
let plane = make_sketch_plane_from_orientation(plane_data, exec_state, args).await?;
|
||||
Ok(SketchSurface::Plane(plane))
|
||||
}
|
||||
SketchData::Plane(plane) => Ok(SketchSurface::Plane(plane)),
|
||||
SketchData::Plane(plane) => {
|
||||
// Create artifact used only by the UI, not the engine.
|
||||
let id = exec_state.next_uuid();
|
||||
exec_state.add_artifact(Artifact {
|
||||
id: ArtifactId::from(id),
|
||||
inner: ArtifactInner::StartSketchOnPlane { plane_id: plane.id },
|
||||
source_range: args.source_range,
|
||||
});
|
||||
|
||||
Ok(SketchSurface::Plane(plane))
|
||||
}
|
||||
SketchData::Solid(solid) => {
|
||||
let Some(tag) = tag else {
|
||||
return Err(KclError::Type(KclErrorDetails {
|
||||
@ -1084,6 +1095,15 @@ async fn inner_start_sketch_on(
|
||||
}));
|
||||
};
|
||||
let face = start_sketch_on_face(solid, tag, exec_state, args).await?;
|
||||
|
||||
// Create artifact used only by the UI, not the engine.
|
||||
let id = exec_state.next_uuid();
|
||||
exec_state.add_artifact(Artifact {
|
||||
id: ArtifactId::from(id),
|
||||
inner: ArtifactInner::StartSketchOnFace { face_id: face.id },
|
||||
source_range: args.source_range,
|
||||
});
|
||||
|
||||
Ok(SketchSurface::Face(face))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user