Skip to content

Commit

Permalink
fix autoconversion in test bed viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
interim17 committed Dec 27, 2024
1 parent e0c98a7 commit 20ec0c9
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions examples/src/Viewer.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -87,6 +87,8 @@ interface ViewerState {
initialPlay: boolean;
firstFrameTime: number;
followObjectData: AgentData;
convertingFile: boolean;
conversionFileName: string;
}

const simulariumController = new SimulariumController({});
Expand Down Expand Up @@ -120,6 +122,8 @@ const initialState: ViewerState = {
initialPlay: true,
firstFrameTime: 0,
followObjectData: nullAgent(),
convertingFile: false,
conversionFileName: "",
};

class Viewer extends React.Component<InputParams, ViewerState> {
Expand Down Expand Up @@ -333,6 +337,7 @@ class Viewer extends React.Component<InputParams, ViewerState> {

public convertFile(obj: Record<string, any>, fileType: TrajectoryType) {
const fileName = uuidv4() + ".simularium";
this.setState({ convertingFile: true, conversionFileName: fileName });
simulariumController
.convertTrajectory(
this.netConnectionSettings,
Expand All @@ -343,13 +348,6 @@ class Viewer extends React.Component<InputParams, ViewerState> {
.then(() => {
this.clearPendingFile();
})
.then(() => {
simulariumController.changeFile(
{ netConnectionSettings: this.netConnectionSettings },
fileName,
true
);
})
.catch((err) => {
console.error(err);
});
Expand Down Expand Up @@ -430,8 +428,27 @@ class Viewer extends React.Component<InputParams, ViewerState> {
});
}

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({
Expand Down

0 comments on commit 20ec0c9

Please sign in to comment.