From 20ec0c97b1e85c7d20d1b796d525833d0b2b8b5a Mon Sep 17 00:00:00 2001 From: Joe Heffernan Date: Thu, 26 Dec 2024 18:39:06 -0800 Subject: [PATCH] fix autoconversion in test bed viewer --- examples/src/Viewer.tsx | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/examples/src/Viewer.tsx b/examples/src/Viewer.tsx index a5cc83dd..c54e7772 100644 --- a/examples/src/Viewer.tsx +++ b/examples/src/Viewer.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { isEqual, findIndex, reduce } from "lodash"; +import { map, isEqual, findIndex, reduce } from "lodash"; import { v4 as uuidv4 } from "uuid"; import { InputParams } from "tweakpane"; @@ -87,6 +87,8 @@ interface ViewerState { initialPlay: boolean; firstFrameTime: number; followObjectData: AgentData; + convertingFile: boolean; + conversionFileName: string; } const simulariumController = new SimulariumController({}); @@ -120,6 +122,8 @@ const initialState: ViewerState = { initialPlay: true, firstFrameTime: 0, followObjectData: nullAgent(), + convertingFile: false, + conversionFileName: "", }; class Viewer extends React.Component { @@ -333,6 +337,7 @@ class Viewer extends React.Component { public convertFile(obj: Record, fileType: TrajectoryType) { const fileName = uuidv4() + ".simularium"; + this.setState({ convertingFile: true, conversionFileName: fileName }); simulariumController .convertTrajectory( this.netConnectionSettings, @@ -343,13 +348,6 @@ class Viewer extends React.Component { .then(() => { this.clearPendingFile(); }) - .then(() => { - simulariumController.changeFile( - { netConnectionSettings: this.netConnectionSettings }, - fileName, - true - ); - }) .catch((err) => { console.error(err); }); @@ -430,8 +428,27 @@ class Viewer extends React.Component { }); } + public receiveConvertedFile(data: TrajectoryFileInfo): void { + simulariumController + .changeFile( + { netConnectionSettings: this.netConnectionSettings }, + this.state.conversionFileName, + true + ) + .then(() => { + simulariumController.gotoTime(0); + }) + .then(() => this.setState({ convertingFile: false })) + .catch((e) => { + console.warn(e); + }); + } + public handleTrajectoryInfo(data: TrajectoryFileInfo): void { console.log("Trajectory info arrived", data); + if (this.state.convertingFile === true) { + this.receiveConvertedFile(data); + } // NOTE: Currently incorrectly assumes initial time of 0 const totalDuration = (data.totalSteps - 1) * data.timeStepSize; this.setState({