Grid scale proportional to user's units

The grid lines should be 1 unit apart, where the unit is whatever the
user's defaultUnitLength setting is, e.g. 1mm or 1cm or 1in apart.
This commit is contained in:
Adam Chalmers
2025-05-29 16:40:52 -05:00
parent 13c4de77c3
commit 9419381068
5 changed files with 39 additions and 9 deletions

4
rust/Cargo.lock generated
View File

@ -2082,9 +2082,9 @@ dependencies = [
[[package]]
name = "kittycad-modeling-cmds"
version = "0.2.121"
version = "0.2.122"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94ba95c22493d79ec8a1faab963d8903f6de0e373efedf2bc3bb76a0ddbab036"
checksum = "643f41fa4bc9c98104d6f0da937024dbb5fce37ffe63c0635b348db74bd78c4f"
dependencies = [
"anyhow",
"chrono",

View File

@ -36,7 +36,7 @@ dashmap = { version = "6.1.0" }
http = "1"
indexmap = "2.9.0"
kittycad = { version = "0.3.37", default-features = false, features = ["js", "requests"] }
kittycad-modeling-cmds = { version = "0.2.120", features = ["ts-rs", "websocket"] }
kittycad-modeling-cmds = { version = "0.2.122", features = ["ts-rs", "websocket"] }
lazy_static = "1.5.0"
miette = "7.5.0"
pyo3 = { version = "0.24.1" }

View File

@ -369,13 +369,15 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
settings: &crate::ExecutorSettings,
source_range: SourceRange,
id_generator: &mut IdGenerator,
grid_scale_unit: Option<kcmc::units::UnitLength>,
) -> Result<(), crate::errors::KclError> {
// Set the edge visibility.
self.set_edge_visibility(settings.highlight_edges, source_range, id_generator)
.await?;
// Send the command to show the grid.
self.modify_grid(!settings.show_grid, source_range, id_generator)
self.modify_grid(!settings.show_grid, grid_scale_unit, source_range, id_generator)
.await?;
// We do not have commands for changing ssao on the fly.
@ -829,6 +831,7 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
async fn modify_grid(
&self,
hidden: bool,
base_unit: Option<kcmc::units::UnitLength>,
source_range: SourceRange,
id_generator: &mut IdGenerator,
) -> Result<(), KclError> {
@ -843,6 +846,17 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
)
.await?;
let grid_scale = if let Some(units) = base_unit {
// The grid is 10x10, so setting the value to 10 means that
// users whose unit is cm will see each cell as 1cm by 1cm,
// which is useful for sketching.
ModelingCmd::from(mcmd::SetGridScale { value: 10.0, units })
} else {
ModelingCmd::from(mcmd::SetGridAutoScale {})
};
self.batch_modeling_cmd(id_generator.next_uuid(), source_range, &grid_scale)
.await?;
// Hide/show the grid scale text.
self.batch_modeling_cmd(
id_generator.next_uuid(),

View File

@ -593,6 +593,12 @@ impl ExecutorContext {
pub async fn run_with_caching(&self, program: crate::Program) -> Result<ExecOutcome, KclErrorWithOutputs> {
assert!(!self.is_mock());
let grid_scale = program
.meta_settings()
.ok()
.flatten()
.map(|s| s.default_length_units)
.map(kcmc::units::UnitLength::from);
let (program, mut exec_state, preserve_mem, cached_body_items, imports_info) = if let Some(OldAstState {
ast: old_ast,
@ -623,7 +629,7 @@ impl ExecutorContext {
if reapply_settings
&& self
.engine
.reapply_settings(&self.settings, Default::default(), old_state.id_generator())
.reapply_settings(&self.settings, Default::default(), old_state.id_generator(), grid_scale)
.await
.is_err()
{
@ -647,7 +653,7 @@ impl ExecutorContext {
if reapply_settings
&& self
.engine
.reapply_settings(&self.settings, Default::default(), old_state.id_generator())
.reapply_settings(&self.settings, Default::default(), old_state.id_generator(), grid_scale)
.await
.is_err()
{
@ -697,7 +703,7 @@ impl ExecutorContext {
CacheResult::NoAction(true) => {
if self
.engine
.reapply_settings(&self.settings, Default::default(), old_state.id_generator())
.reapply_settings(&self.settings, Default::default(), old_state.id_generator(), grid_scale)
.await
.is_ok()
{
@ -1089,8 +1095,19 @@ impl ExecutorContext {
let _stats = crate::log::LogPerfStats::new("Interpretation");
// Re-apply the settings, in case the cache was busted.
let grid_scale = program
.meta_settings()
.ok()
.flatten()
.map(|s| s.default_length_units)
.map(kcmc::units::UnitLength::from);
self.engine
.reapply_settings(&self.settings, Default::default(), exec_state.id_generator())
.reapply_settings(
&self.settings,
Default::default(),
exec_state.id_generator(),
grid_scale,
)
.await
.map_err(KclErrorWithOutputs::no_outputs)?;

View File

@ -256,7 +256,6 @@ impl EngineConnection {
let entity_ids = generate_repl_uuids(*num_repetitions as usize);
this_response = OkModelingCmdResponse::EntityCircularPattern(kcmc::output::EntityCircularPattern {
entity_ids: entity_ids.clone(),
entity_face_edge_ids: vec![],
});