more updates for kcl-samples (#5696)

* screenshots and step

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* automations

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add manifest generation

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* small refactor

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* update readme

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* write the readme

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes for comments

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* derive-docs tests updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* update all the generated artifact commands, since we dont need to clear scene at the start of run so we dont need to recreate all the planes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2025-03-07 18:45:33 -08:00
committed by GitHub
parent be69039d40
commit bc3a0e3896
318 changed files with 393583 additions and 29897 deletions

View File

@ -625,8 +625,6 @@ impl ExecutorContext {
let mut exec_state = old_state;
exec_state.reset(&self.settings);
exec_state.add_root_module_contents(&program);
// We don't do this in mock mode since there is no engine connection
// anyways and from the TS side we override memory and don't want to clear it.
self.send_clear_scene(&mut exec_state, Default::default())
@ -636,7 +634,6 @@ impl ExecutorContext {
(exec_state, false)
} else {
old_state.mut_stack().restore_env(result_env);
old_state.add_root_module_contents(&program);
(old_state, true)
};
@ -644,7 +641,6 @@ impl ExecutorContext {
(program, exec_state, preserve_mem)
} else {
let mut exec_state = ExecState::new(&self.settings);
exec_state.add_root_module_contents(&program);
self.send_clear_scene(&mut exec_state, Default::default())
.await
.map_err(KclErrorWithOutputs::no_outputs)?;
@ -683,28 +679,7 @@ impl ExecutorContext {
&self,
program: &crate::Program,
exec_state: &mut ExecState,
) -> Result<(EnvironmentRef, Option<ModelingSessionData>), KclError> {
self.run_with_ui_outputs(program, exec_state)
.await
.map_err(|e| e.into())
}
/// Perform the execution of a program.
///
/// You can optionally pass in some initialization memory for partial
/// execution.
///
/// The error includes additional outputs used for the feature tree and
/// artifact graph.
pub async fn run_with_ui_outputs(
&self,
program: &crate::Program,
exec_state: &mut ExecState,
) -> Result<(EnvironmentRef, Option<ModelingSessionData>), KclErrorWithOutputs> {
exec_state.add_root_module_contents(program);
self.send_clear_scene(exec_state, Default::default())
.await
.map_err(KclErrorWithOutputs::no_outputs)?;
self.inner_run(program, exec_state, false).await
}
@ -716,6 +691,8 @@ impl ExecutorContext {
exec_state: &mut ExecState,
preserve_mem: bool,
) -> Result<(EnvironmentRef, Option<ModelingSessionData>), KclErrorWithOutputs> {
exec_state.add_root_module_contents(program);
let _stats = crate::log::LogPerfStats::new("Interpretation");
// Re-apply the settings, in case the cache was busted.
@ -882,6 +859,73 @@ impl ExecutorContext {
Ok(contents)
}
/// Export the current scene as a CAD file.
pub async fn export(
&self,
format: kittycad_modeling_cmds::format::OutputFormat3d,
) -> Result<Vec<kittycad_modeling_cmds::websocket::RawFile>, KclError> {
let resp = self
.engine
.send_modeling_cmd(
uuid::Uuid::new_v4(),
crate::SourceRange::default(),
&kittycad_modeling_cmds::ModelingCmd::Export(kittycad_modeling_cmds::Export {
entity_ids: vec![],
format,
}),
)
.await?;
let kittycad_modeling_cmds::websocket::OkWebSocketResponseData::Export { files } = resp else {
return Err(KclError::Internal(crate::errors::KclErrorDetails {
message: format!("Expected Export response, got {resp:?}",),
source_ranges: vec![SourceRange::default()],
}));
};
Ok(files)
}
/// Export the current scene as a STEP file.
pub async fn export_step(
&self,
deterministic_time: bool,
) -> Result<Vec<kittycad_modeling_cmds::websocket::RawFile>, KclError> {
let mut files = self
.export(kittycad_modeling_cmds::format::OutputFormat3d::Step(
kittycad_modeling_cmds::format::step::export::Options {
coords: *kittycad_modeling_cmds::coord::KITTYCAD,
created: None,
},
))
.await?;
if deterministic_time {
for kittycad_modeling_cmds::websocket::RawFile { contents, .. } in &mut files {
use std::fmt::Write;
let utf8 = std::str::from_utf8(contents).unwrap();
let mut postprocessed = String::new();
for line in utf8.lines() {
if line.starts_with("FILE_NAME") {
let name = "test.step";
let time = "2021-01-01T00:00:00Z";
let author = "Test";
let org = "Zoo";
let version = "zoo.dev beta";
let system = "zoo.dev";
let authorization = "Test";
writeln!(&mut postprocessed, "FILE_NAME('{name}', '{time}', ('{author}'), ('{org}'), '{version}', '{system}', '{authorization}');").unwrap();
} else {
writeln!(&mut postprocessed, "{line}").unwrap();
}
}
*contents = postprocessed.into_bytes();
}
}
Ok(files)
}
pub async fn close(&self) {
self.engine.close().await;
}

View File

@ -10,8 +10,10 @@ use uuid::Uuid;
use crate::{
errors::{KclError, KclErrorDetails, Severity},
execution::{
annotations, kcl_value, memory::ProgramMemory, memory::Stack, Artifact, ArtifactCommand, ArtifactGraph,
ArtifactId, EnvironmentRef, ExecOutcome, ExecutorSettings, KclValue, Operation, UnitAngle, UnitLen,
annotations, kcl_value,
memory::{ProgramMemory, Stack},
Artifact, ArtifactCommand, ArtifactGraph, ArtifactId, EnvironmentRef, ExecOutcome, ExecutorSettings, KclValue,
Operation, UnitAngle, UnitLen,
},
modules::{ModuleId, ModuleInfo, ModuleLoader, ModulePath, ModuleRepr, ModuleSource},
parsing::ast::types::Annotation,