mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-08 09:24:18 +01:00
26 lines
778 B
TypeScript
26 lines
778 B
TypeScript
import React, {useContext, useState} from "react";
|
|
import {ReactApplicationContext} from "../../dom/ReactApplicationContext";
|
|
import {AssemblyProcess} from "../assemblySolver";
|
|
import {useStream} from "ui/effects";
|
|
|
|
export function StepByStepSimulation() {
|
|
|
|
const ctx = useContext(ReactApplicationContext);
|
|
|
|
const [process, setProcess] = useState<AssemblyProcess>(null);
|
|
const constraints = useStream(ctx => ctx.assemblyService.constraints$);
|
|
|
|
|
|
function stepByStepSimulation() {
|
|
if (process === null || process.isDone()) {
|
|
const newProcess = new AssemblyProcess(ctx.cadRegistry, constraints);
|
|
newProcess.begin();
|
|
setProcess(newProcess);
|
|
} else {
|
|
process.step();
|
|
}
|
|
}
|
|
|
|
return <button onClick={stepByStepSimulation}>step</button>
|
|
|
|
}
|