jsketcher/web/app/cad/assembly/ui/StepByStepSimulation.tsx
2020-07-13 17:02:58 -07:00

29 lines
861 B
TypeScript

import React, {useContext, useState} from "react";
import {AppContext} from "../../dom/components/AppContext";
import {AssemblyProcess} from "../assemblySolver";
import {useStream} from "ui/effects";
import {MShell} from "../../model/mshell";
import CSys from "math/csys";
import {Matrix3} from "math/l3space";
export function StepByStepSimulation() {
const ctx = useContext(AppContext);
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>
}