Skip to content

Commit

Permalink
Merge branch 'main' into franknoirot/adhoc/hide-fillet-cmd-bar
Browse files Browse the repository at this point in the history
  • Loading branch information
franknoirot authored Nov 22, 2024
2 parents 4ba672d + 2529066 commit 69e9d50
Show file tree
Hide file tree
Showing 104 changed files with 38,200 additions and 161,319 deletions.
19 changes: 9 additions & 10 deletions src/clientSideScene/sceneEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ export class SceneEntities {
activeSegments: { [key: string]: Group } = {}
intersectionPlane: Mesh | null = null
axisGroup: Group | null = null
draftPointGroups: Group[] = []
currentSketchQuaternion: Quaternion | null = null
constructor(engineCommandManager: EngineCommandManager) {
this.engineCommandManager = engineCommandManager
this.scene = sceneInfra?.scene
sceneInfra?.camControls.subscribeToCamChange(this.onCamChange)
window.addEventListener('resize', this.onWindowResize)
this.createIntersectionPlane()
}

onWindowResize = () => {
Expand Down Expand Up @@ -224,7 +226,6 @@ export class SceneEntities {

createIntersectionPlane() {
if (sceneInfra.scene.getObjectByName(RAYCASTABLE_PLANE)) {
// this.removeIntersectionPlane()
console.warn('createIntersectionPlane called when it already exists')
return
}
Expand Down Expand Up @@ -316,10 +317,6 @@ export class SceneEntities {
sketchPosition && this.axisGroup.position.set(...sketchPosition)
this.scene.add(this.axisGroup)
}
removeIntersectionPlane() {
const intersectionPlane = this.scene.getObjectByName(RAYCASTABLE_PLANE)
if (intersectionPlane) this.scene.remove(intersectionPlane)
}
getDraftPoint() {
return this.scene.getObjectByName(DRAFT_POINT)
}
Expand All @@ -337,6 +334,7 @@ export class SceneEntities {
draftPoint.layers.set(SKETCH_LAYER)
group.add(draftPoint)
}

removeDraftPoint() {
const draftPoint = this.getDraftPoint()
if (draftPoint) draftPoint.removeFromParent()
Expand All @@ -352,8 +350,9 @@ export class SceneEntities {
// TODO: Consolidate shared logic between this and setupSketch
// Which should just fire when the sketch mode is entered,
// instead of in these two separate XState states.
this.createIntersectionPlane()

const draftPointGroup = new Group()
this.draftPointGroups.push(draftPointGroup)
draftPointGroup.name = DRAFT_POINT_GROUP
sketchDetails.origin &&
draftPointGroup.position.set(...sketchDetails.origin)
Expand Down Expand Up @@ -456,7 +455,6 @@ export class SceneEntities {

await kclManager.updateAst(modifiedAst, false)

this.removeIntersectionPlane()
this.scene.remove(draftPointGroup)

// Now perform the caller-specified action
Expand Down Expand Up @@ -487,8 +485,6 @@ export class SceneEntities {
sketch: Sketch
variableDeclarationName: string
}> {
this.createIntersectionPlane()

const prepared = this.prepareTruncatedMemoryAndAst(
sketchPathToNode || [],
maybeModdedAst
Expand Down Expand Up @@ -1841,7 +1837,10 @@ export class SceneEntities {
reject: () => void,
{ removeAxis = true }: { removeAxis?: boolean }
) {
if (this.intersectionPlane) this.scene.remove(this.intersectionPlane)
// Remove all draft groups
this.draftPointGroups.forEach((draftPointGroup) => {
this.scene.remove(draftPointGroup)
})
if (this.axisGroup && removeAxis) this.scene.remove(this.axisGroup)
const sketchSegments = this.scene.children.find(
({ userData }) => userData?.type === SKETCH_GROUP_SEGMENTS
Expand Down
1 change: 1 addition & 0 deletions src/clientSideScene/sceneInfra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ export class SceneInfra {
this.currentMouseVector,
this.camControls.camera
)

// Get the intersection of the ray with the default planes
const planeIntersects = this.planeRaycaster.intersectObjects(
this.scene.children,
Expand Down
16 changes: 1 addition & 15 deletions src/machines/modelingMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,14 +748,6 @@ export const modelingMachine = setup({
})
})().catch(reportRejection)
},
'conditionally equip line tool': ({ event: { type } }) => {
if (type === 'xstate.done.actor.animate-to-face') {
sceneInfra.modelingSend({
type: 'change tool',
data: { tool: 'line' },
})
}
},
'setup client side sketch segments': ({
context: { sketchDetails, selectionRanges },
}) => {
Expand Down Expand Up @@ -860,7 +852,6 @@ export const modelingMachine = setup({

'listen for circle origin': ({ context: { sketchDetails } }) => {
if (!sketchDetails) return
sceneEntitiesManager.createIntersectionPlane()
const quaternion = quaternionFromUpNForward(
new Vector3(...sketchDetails.yAxis),
new Vector3(...sketchDetails.zAxis)
Expand Down Expand Up @@ -966,7 +957,6 @@ export const modelingMachine = setup({
},
'setup noPoints onClick listener': ({ context: { sketchDetails } }) => {
if (!sketchDetails) return

sceneEntitiesManager.setupNoPointsListener({
sketchDetails,
afterClick: () => sceneInfra.modelingSend({ type: 'Add start point' }),
Expand Down Expand Up @@ -2176,11 +2166,7 @@ export const modelingMachine = setup({
'enable copilot',
],

entry: [
'add axis n grid',
'conditionally equip line tool',
'clientToEngine cam sync direction',
],
entry: ['add axis n grid', 'clientToEngine cam sync direction'],
},

'Sketch no face': {
Expand Down
13 changes: 10 additions & 3 deletions src/wasm-lib/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ redo-kcl-stdlib-docs:
TWENTY_TWENTY=overwrite {{cnr}} -p kcl-lib kcl_test_example
EXPECTORATE=overwrite {{cnr}} -p kcl-lib docs::gen_std_tests::test_generate_stdlib


# Copy a test KCL file from executor tests into a new simulation test.
copy-exec-test-into-sim-test test_name:
mkdir -p kcl/tests/{{test_name}}
cp tests/executor/inputs/{{test_name}}.kcl kcl/tests/{{test_name}}/input.kcl
zoo kcl fmt -w kcl/tests/{{test_name}}/input.kcl
just new-sim-test {{test_name}}

# Create a new KCL deterministic simulation test case.
new-sim-test test_name render_to_png="true":
# Add the various tests for this new test case.
cat kcl/tests/simtest.tmpl | sed "s/TEST_NAME_HERE/{{test_name}}/" | sed "s/RENDER_TO_PNG/{{render_to_png}}/" >> kcl/src/simulation_tests.rs
# Run all the tests for the first time, in the right order.
{{cita}} -p kcl-lib -- tests::{{test_name}}::tokenize
{{cita}} -p kcl-lib -- tests::{{test_name}}::parse
{{cita}} -p kcl-lib -- tests::{{test_name}}::unparse
{{cita}} -p kcl-lib -- simulation_tests::{{test_name}}::parse
{{cita}} -p kcl-lib -- simulation_tests::{{test_name}}::unparse
TWENTY_TWENTY=overwrite {{cita}} -p kcl-lib -- tests::{{test_name}}::kcl_test_execute

4 changes: 3 additions & 1 deletion src/wasm-lib/kcl/src/ast/modify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ pub async fn modify_ast_for_sketch(
let recasted = program.ast.recast(&FormatOptions::default(), 0);

// Re-parse the ast so we get the correct source ranges.
*program = crate::parser::parse_str(&recasted, module_id)?.into();
*program = crate::parser::parse_str(&recasted, module_id)
.parse_errs_as_err()?
.into();

Ok(recasted)
}
Expand Down
30 changes: 0 additions & 30 deletions src/wasm-lib/kcl/src/ast/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3491,36 +3491,6 @@ const cylinder = startSketchOn('-XZ')
assert_eq!(l.raw, "false");
}

#[tokio::test(flavor = "multi_thread")]
async fn test_parse_tag_named_std_lib() {
let some_program_string = r#"startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([5, 5], %, $xLine)
"#;
let result = crate::parser::top_level_parse(some_program_string);

assert!(result.is_err());
assert_eq!(
result.unwrap_err().to_string(),
r#"syntax: KclErrorDetails { source_ranges: [SourceRange([76, 82, 0])], message: "Cannot assign a tag to a reserved keyword: xLine" }"#
);
}

#[tokio::test(flavor = "multi_thread")]
async fn test_parse_empty_tag() {
let some_program_string = r#"startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([5, 5], %, $)
"#;
let result = crate::parser::top_level_parse(some_program_string);

assert!(result.is_err());
assert_eq!(
result.unwrap_err().to_string(),
r#"syntax: KclErrorDetails { source_ranges: [SourceRange([57, 59, 0])], message: "Unexpected token: |>" }"#
);
}

#[tokio::test(flavor = "multi_thread")]
async fn test_parse_digest() {
let prog1_string = r#"startSketchOn('XY')
Expand Down
7 changes: 7 additions & 0 deletions src/wasm-lib/kcl/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ pub struct KclErrorDetails {
}

impl KclError {
pub fn internal(message: String) -> KclError {
KclError::Internal(KclErrorDetails {
source_ranges: Default::default(),
message,
})
}

/// Get the error message.
pub fn get_message(&self) -> String {
format!("{}: {}", self.error_type(), self.message())
Expand Down
3 changes: 2 additions & 1 deletion src/wasm-lib/kcl/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,8 @@ impl ExecutorContext {
}
let module_id = exec_state.add_module(resolved_path.clone());
let source = self.fs.read_to_string(&resolved_path, source_range).await?;
let program = crate::parser::parse_str(&source, module_id)?;
// TODO handle parsing errors properly
let program = crate::parser::parse_str(&source, module_id).parse_errs_as_err()?;
let (module_memory, module_exports) = {
exec_state.import_stack.push(resolved_path.clone());
let original_execution = self.engine.replace_execution_kind(ExecutionKind::Isolated);
Expand Down
3 changes: 2 additions & 1 deletion src/wasm-lib/kcl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ impl Program {
pub fn parse(input: &str) -> Result<Program, KclError> {
let module_id = ModuleId::default();
let tokens = token::lexer(input, module_id)?;
let ast = parser::parse_tokens(tokens)?;
// TODO handle parsing errors properly
let ast = parser::parse_tokens(tokens).parse_errs_as_err()?;

Ok(Program { ast })
}
Expand Down
7 changes: 4 additions & 3 deletions src/wasm-lib/kcl/src/lsp/kcl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ impl crate::lsp::backend::Backend for Backend {

// Lets update the ast.
let result = crate::parser::parse_tokens(tokens.clone());
let mut ast = match result {
// TODO handle parse errors properly
let mut ast = match result.parse_errs_as_err() {
Ok(ast) => ast,
Err(err) => {
self.add_to_diagnostics(&params, &[err], true).await;
Expand Down Expand Up @@ -1301,7 +1302,7 @@ impl LanguageServer for Backend {
// I don't know if we need to do this again since it should be updated in the context.
// But I figure better safe than sorry since this will write back out to the file.
let module_id = ModuleId::default();
let Ok(ast) = crate::parser::parse_str(current_code, module_id) else {
let Ok(ast) = crate::parser::parse_str(current_code, module_id).parse_errs_as_err() else {
return Ok(None);
};
// Now recast it.
Expand Down Expand Up @@ -1335,7 +1336,7 @@ impl LanguageServer for Backend {
// I don't know if we need to do this again since it should be updated in the context.
// But I figure better safe than sorry since this will write back out to the file.
let module_id = ModuleId::default();
let Ok(mut ast) = crate::parser::parse_str(current_code, module_id) else {
let Ok(mut ast) = crate::parser::parse_str(current_code, module_id).parse_errs_as_err() else {
return Ok(None);
};

Expand Down
Loading

0 comments on commit 69e9d50

Please sign in to comment.