Coordinate grid uses same scale as user's units (#7465)
Closes https://github.com/KittyCAD/engine/issues/3494. Thanks to @nadr0 for helping on the JS side. If users set their units, the grid will stop auto scaling, and instead will be set to 10 of whatever unit they used. If users set their units, and those units are metric, then it'll include a scale bar (see screenshot). Imperial units won't have that bar. This behaviour is configurable via settings. ## Limitations - The scale bar below the grid cannot be disabled in metric units, and cannot be enabled in imperial units <img width="1690" alt="Screenshot 2025-06-05 at 7 51 41 PM" src="https://github.com/user-attachments/assets/c597087c-f96d-4c30-95f4-b3d8ba2b5567" />
This commit is contained in:
@ -323,13 +323,15 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
|
||||
settings: &crate::ExecutorSettings,
|
||||
source_range: SourceRange,
|
||||
id_generator: &mut IdGenerator,
|
||||
grid_scale_unit: GridScaleBehavior,
|
||||
) -> 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.
|
||||
@ -760,6 +762,7 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
|
||||
async fn modify_grid(
|
||||
&self,
|
||||
hidden: bool,
|
||||
grid_scale_behavior: GridScaleBehavior,
|
||||
source_range: SourceRange,
|
||||
id_generator: &mut IdGenerator,
|
||||
) -> Result<(), KclError> {
|
||||
@ -774,6 +777,13 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
|
||||
)
|
||||
.await?;
|
||||
|
||||
self.batch_modeling_cmd(
|
||||
id_generator.next_uuid(),
|
||||
source_range,
|
||||
&grid_scale_behavior.into_modeling_cmd(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Hide/show the grid scale text.
|
||||
self.batch_modeling_cmd(
|
||||
id_generator.next_uuid(),
|
||||
@ -886,3 +896,22 @@ pub fn new_zoo_client(token: Option<String>, engine_addr: Option<String>) -> any
|
||||
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum GridScaleBehavior {
|
||||
ScaleWithZoom,
|
||||
Fixed(Option<kcmc::units::UnitLength>),
|
||||
}
|
||||
|
||||
impl GridScaleBehavior {
|
||||
fn into_modeling_cmd(self) -> ModelingCmd {
|
||||
const NUMBER_OF_GRID_COLUMNS: f32 = 10.0;
|
||||
match self {
|
||||
GridScaleBehavior::ScaleWithZoom => ModelingCmd::from(mcmd::SetGridAutoScale {}),
|
||||
GridScaleBehavior::Fixed(unit_length) => ModelingCmd::from(mcmd::SetGridScale {
|
||||
value: NUMBER_OF_GRID_COLUMNS,
|
||||
units: unit_length.unwrap_or(kcmc::units::UnitLength::Millimeters),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user