Move hide grid to rust (#2850)
* updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * add back in to js side; Signed-off-by: Jess Frazelle <github@jessfraz.com> * order of operations Signed-off-by: Jess Frazelle <github@jessfraz.com> * fxi Signed-off-by: Jess Frazelle <github@jessfraz.com> * typos Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -3,7 +3,7 @@ import { useStore } from '../useStore'
|
|||||||
import { engineCommandManager, kclManager } from 'lib/singletons'
|
import { engineCommandManager, kclManager } from 'lib/singletons'
|
||||||
import { deferExecution } from 'lib/utils'
|
import { deferExecution } from 'lib/utils'
|
||||||
import { Themes } from 'lib/theme'
|
import { Themes } from 'lib/theme'
|
||||||
import { makeDefaultPlanes } from 'lang/wasm'
|
import { makeDefaultPlanes, modifyGrid } from 'lang/wasm'
|
||||||
|
|
||||||
export function useSetupEngineManager(
|
export function useSetupEngineManager(
|
||||||
streamRef: React.RefObject<HTMLDivElement>,
|
streamRef: React.RefObject<HTMLDivElement>,
|
||||||
@ -66,6 +66,9 @@ export function useSetupEngineManager(
|
|||||||
makeDefaultPlanes: () => {
|
makeDefaultPlanes: () => {
|
||||||
return makeDefaultPlanes(kclManager.engineCommandManager)
|
return makeDefaultPlanes(kclManager.engineCommandManager)
|
||||||
},
|
},
|
||||||
|
modifyGrid: (hidden: boolean) => {
|
||||||
|
return modifyGrid(kclManager.engineCommandManager, hidden)
|
||||||
|
},
|
||||||
})
|
})
|
||||||
setStreamDimensions({
|
setStreamDimensions({
|
||||||
streamWidth: quadWidth,
|
streamWidth: quadWidth,
|
||||||
|
@ -1143,6 +1143,7 @@ export class EngineCommandManager extends EventTarget {
|
|||||||
this.getAst = cb
|
this.getAst = cb
|
||||||
}
|
}
|
||||||
private makeDefaultPlanes: () => Promise<DefaultPlanes> | null = () => null
|
private makeDefaultPlanes: () => Promise<DefaultPlanes> | null = () => null
|
||||||
|
private modifyGrid: (hidden: boolean) => Promise<void> | null = () => null
|
||||||
|
|
||||||
start({
|
start({
|
||||||
setMediaStream,
|
setMediaStream,
|
||||||
@ -1152,6 +1153,7 @@ export class EngineCommandManager extends EventTarget {
|
|||||||
executeCode,
|
executeCode,
|
||||||
token,
|
token,
|
||||||
makeDefaultPlanes,
|
makeDefaultPlanes,
|
||||||
|
modifyGrid,
|
||||||
settings = {
|
settings = {
|
||||||
theme: Themes.Dark,
|
theme: Themes.Dark,
|
||||||
highlightEdges: true,
|
highlightEdges: true,
|
||||||
@ -1165,6 +1167,7 @@ export class EngineCommandManager extends EventTarget {
|
|||||||
executeCode: () => void
|
executeCode: () => void
|
||||||
token?: string
|
token?: string
|
||||||
makeDefaultPlanes: () => Promise<DefaultPlanes>
|
makeDefaultPlanes: () => Promise<DefaultPlanes>
|
||||||
|
modifyGrid: (hidden: boolean) => Promise<void>
|
||||||
settings?: {
|
settings?: {
|
||||||
theme: Themes
|
theme: Themes
|
||||||
highlightEdges: boolean
|
highlightEdges: boolean
|
||||||
@ -1172,6 +1175,7 @@ export class EngineCommandManager extends EventTarget {
|
|||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
this.makeDefaultPlanes = makeDefaultPlanes
|
this.makeDefaultPlanes = makeDefaultPlanes
|
||||||
|
this.modifyGrid = modifyGrid
|
||||||
if (width === 0 || height === 0) {
|
if (width === 0 || height === 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1247,31 +1251,11 @@ export class EngineCommandManager extends EventTarget {
|
|||||||
type: 'default_camera_get_settings',
|
type: 'default_camera_get_settings',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
// We want modify the grid first because we don't want it to flash.
|
||||||
this.initPlanes().then(async () => {
|
// Ideally these would already be default hidden in engine (TODO do
|
||||||
// Hide the grid and grid scale text.
|
// that) https://github.com/KittyCAD/engine/issues/2282
|
||||||
this.sendSceneCommand({
|
this.modifyGrid(true)?.then(async () => {
|
||||||
type: 'modeling_cmd_req',
|
await this.initPlanes()
|
||||||
cmd_id: uuidv4(),
|
|
||||||
cmd: {
|
|
||||||
type: 'object_visible' as any,
|
|
||||||
// Found in engine/constants.h
|
|
||||||
object_id: 'cfa78409-653d-4c26-96f1-7c45fb784840',
|
|
||||||
hidden: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
this.sendSceneCommand({
|
|
||||||
type: 'modeling_cmd_req',
|
|
||||||
cmd_id: uuidv4(),
|
|
||||||
cmd: {
|
|
||||||
type: 'object_visible' as any,
|
|
||||||
// Found in engine/constants.h
|
|
||||||
object_id: '10782f33-f588-4668-8bcd-040502d26590',
|
|
||||||
hidden: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
this.resolveReady()
|
this.resolveReady()
|
||||||
setIsStreamReady(true)
|
setIsStreamReady(true)
|
||||||
await executeCode()
|
await executeCode()
|
||||||
|
@ -9,6 +9,7 @@ import init, {
|
|||||||
get_tangential_arc_to_info,
|
get_tangential_arc_to_info,
|
||||||
program_memory_init,
|
program_memory_init,
|
||||||
make_default_planes,
|
make_default_planes,
|
||||||
|
modify_grid,
|
||||||
coredump,
|
coredump,
|
||||||
toml_stringify,
|
toml_stringify,
|
||||||
default_app_settings,
|
default_app_settings,
|
||||||
@ -237,6 +238,20 @@ export const makeDefaultPlanes = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const modifyGrid = async (
|
||||||
|
engineCommandManager: EngineCommandManager,
|
||||||
|
hidden: boolean
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
await modify_grid(engineCommandManager, hidden)
|
||||||
|
return
|
||||||
|
} catch (e) {
|
||||||
|
// TODO: do something real with the error.
|
||||||
|
console.log('modify grid error', e)
|
||||||
|
return Promise.reject(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function lexer(str: string): Token[] | Error {
|
export function lexer(str: string): Token[] | Error {
|
||||||
return lexer_wasm(str)
|
return lexer_wasm(str)
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,9 @@ export async function executor(
|
|||||||
makeDefaultPlanes: () => {
|
makeDefaultPlanes: () => {
|
||||||
return new Promise((resolve) => resolve(defaultPlanes))
|
return new Promise((resolve) => resolve(defaultPlanes))
|
||||||
},
|
},
|
||||||
|
modifyGrid: (hidden: boolean) => {
|
||||||
|
return new Promise((resolve) => resolve())
|
||||||
|
},
|
||||||
})
|
})
|
||||||
await engineCommandManager.waitForReady
|
await engineCommandManager.waitForReady
|
||||||
engineCommandManager.startNewSession()
|
engineCommandManager.startNewSession()
|
||||||
|
@ -22,6 +22,12 @@ use crate::{
|
|||||||
executor::{DefaultPlanes, Point3d},
|
executor::{DefaultPlanes, Point3d},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
pub static ref GRID_OBJECT_ID: uuid::Uuid = uuid::Uuid::parse_str("cfa78409-653d-4c26-96f1-7c45fb784840").unwrap();
|
||||||
|
|
||||||
|
pub static ref GRID_SCALE_TEXT_OBJECT_ID: uuid::Uuid = uuid::Uuid::parse_str("10782f33-f588-4668-8bcd-040502d26590").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
|
pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
|
||||||
/// Get the batch of commands to be sent to the engine.
|
/// Get the batch of commands to be sent to the engine.
|
||||||
@ -456,6 +462,34 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
|
|||||||
source_ranges: vec![],
|
source_ranges: vec![],
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn modify_grid(&self, hidden: bool) -> Result<(), KclError> {
|
||||||
|
// Hide/show the grid.
|
||||||
|
self.batch_modeling_cmd(
|
||||||
|
uuid::Uuid::new_v4(),
|
||||||
|
Default::default(),
|
||||||
|
&ModelingCmd::ObjectVisible {
|
||||||
|
hidden,
|
||||||
|
object_id: *GRID_OBJECT_ID,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// Hide/show the grid scale text.
|
||||||
|
self.batch_modeling_cmd(
|
||||||
|
uuid::Uuid::new_v4(),
|
||||||
|
Default::default(),
|
||||||
|
&ModelingCmd::ObjectVisible {
|
||||||
|
hidden,
|
||||||
|
object_id: *GRID_SCALE_TEXT_OBJECT_ID,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
self.flush_batch(false, Default::default()).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Hash, Eq, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
#[derive(Debug, Hash, Eq, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||||
|
@ -94,6 +94,23 @@ pub async fn make_default_planes(
|
|||||||
JsValue::from_serde(&default_planes).map_err(|e| e.to_string())
|
JsValue::from_serde(&default_planes).map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wasm_bindgen wrapper for modifying the grid
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub async fn modify_grid(
|
||||||
|
engine_manager: kcl_lib::engine::conn_wasm::EngineCommandManager,
|
||||||
|
hidden: bool,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
console_error_panic_hook::set_once();
|
||||||
|
// deserialize the ast from a stringified json
|
||||||
|
|
||||||
|
let engine = kcl_lib::engine::conn_wasm::EngineConnection::new(engine_manager)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("{:?}", e))?;
|
||||||
|
engine.modify_grid(hidden).await.map_err(String::from)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// wasm_bindgen wrapper for execute
|
// wasm_bindgen wrapper for execute
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub async fn modify_ast_for_sketch_wasm(
|
pub async fn modify_ast_for_sketch_wasm(
|
||||||
|
Reference in New Issue
Block a user