Commit 9acaa763 authored by legoc's avatar legoc
Browse files

Get the existing trajectories data at init of the trajectory controller

parent a79bc02d
......@@ -714,16 +714,16 @@ class TrajectoriesData {
class TrajectoriesDataData {
constructor() {
this._trajectoriesData = {};
this._data = {};
this._currentId = 0;
}
get currentId() { return this._currentId; }
get trajectoriesData() { return this._trajectoriesData; }
get data() { return this._data; }
get currentTrajectoryData() {
get currentData() {
if (this._currentId !== 0) {
return this._trajectoriesData[this._currentId];
return this._data[this._currentId];
}
return null;
}
......@@ -731,7 +731,7 @@ class TrajectoriesDataData {
update(trajectoriesDataModel) {
this._currentId = trajectoriesDataModel.id;
this._trajectoriesData[this._currentId] = trajectoriesDataModel.data;
this._data = trajectoriesDataModel.data;
return true;
}
......
......@@ -38,6 +38,7 @@ class TrajectoryController extends Controller {
PubSub.subscribe('update-3D-local', () => { this.update3DLocal(); });
PubSub.subscribe('update-3D-scattering', () => { this.update3DLocal(); });
PubSub.subscribe('update-trajectory-data', () => { this.updateTrajectoryData(); });
PubSub.subscribe('update-current-trajectory-data', () => { this.updateCurrentTrajectoryData(); });
}
init() {
......@@ -49,6 +50,8 @@ class TrajectoryController extends Controller {
this._trajectoryPanel.addTrajectory(traj, trajectory.isVisible(id), false);
this._trajectory3D.createTrajectory(traj);
}
this.updateTrajectoryData();
}
/**
......@@ -276,6 +279,10 @@ class TrajectoryController extends Controller {
this._trajectory3D.updateData();
}
updateCurrentTrajectoryData() {
this._trajectory3D.updateCurrentData();
}
/**
* Inits the scan spy configuration.
*/
......
......@@ -17,6 +17,8 @@ function synchronize(data) {
state.scattering.update(data.scattering);
let updateTrajectories = state.trajectory.update(data.trajectory);
state.trajectoryData.update(data.trajectoryData);
state.matrix.update(data.matrix);
state.config.configurations = {};
......@@ -31,6 +33,7 @@ function synchronize(data) {
PubSub.publish('change-expdata', 0);
PubSub.publish('change-trajectory', 0);
PubSub.publish('update-trajectory-data', 0);
PubSub.publish('change-atoms-conf', 0);
PubSub.publish('update-atom-controller', 0);
......@@ -101,7 +104,7 @@ function synchronizeSpy(data) {
PubSub.publish('change-trajectory', 0);
}
PubSub.publish('update-trajectory-data', 0);
PubSub.publish('update-current-trajectory-data', 0);
if (updateAtoms) {
PubSub.publish('change-atoms-conf', 0);
......
......@@ -603,9 +603,29 @@ class TrajectoryView3D extends View3D {
}
/**
* Update the data of the current trajectory.
* Update the data of the all the trajectories.
*/
updateData() {
// Add the trajectories.
for (let id in trajectoryData.data) {
let lines = this._trajectoryLines[id];
if (lines !== undefined && lines !== null) {
// If the energy line exists, then it "carries" the data.
if (lines.energy !== null) {
lines.energy.setData(trajectoryData.data[id]);
lines.energy.updateDataGroup();
}
}
}
}
/**
* Update the data of the current trajectory.
*/
updateCurrentData() {
if (trajectoryData.currentId == 0) {
return;
......@@ -616,7 +636,7 @@ class TrajectoryView3D extends View3D {
// If the energy line exists, then it "carries" the data.
if (lines.energy !== null) {
lines.energy.setData(trajectoryData.currentTrajectoryData);
lines.energy.setData(trajectoryData.currentData);
lines.energy.updateDataGroup();
}
}
......
......@@ -434,6 +434,7 @@ receiver.on('init', (msg, data) => {
expdata: expDataModel.toObject(),
scattering: scatteringModel.toObject(),
trajectory: trajectoryModel.toObject(),
trajectoryData: trajectoryDataModel.toObject(), // We pass all the trajectories.
atoms: atomsModel.toObject(),
matrix: {
uMatrix: vEXP.uMatrix.toArray(),
......@@ -593,7 +594,7 @@ PubSub.subscribe('syncSpy', (message, clearTrajectories) => {
// Set the XBU path.
trajectoryModel.xbuPath = vEXP.xbuPath;
// Set the scan data.
// Set the scan data. Notice the last point may be missing if the measurement time is very short.
trajectoryDataModel.setDataToCurrentTrajectory(vEXP.dataScan);
// Update the trajectories.
......
......@@ -36,7 +36,12 @@ class TrajectoryDataModel extends Model {
setDataToCurrentTrajectory(value) {
if (this._currentId !== 0) {
this._trajectoriesData[this._currentId] = value;
// Test the length of passed data to avoid clearing the current data.
// It can happen when the current id is not yet changed.
if (value.length > 0) {
this._trajectoriesData[this._currentId] = value;
}
}
}
......@@ -57,28 +62,33 @@ class TrajectoryDataModel extends Model {
return null;
}
/**
* Save the model data into a config object (the saver object).
*/
save(saver) {
saver.trajectoryData = {};
}
/**
* Cast this instance into a basic JS object.
* Only passes the current data.
*/
currentToObject() {
let data = {};
data[this._currentId] = this.getCurrentTrajectoryData();
return {
id: this._currentId,
data: this.getCurrentTrajectoryData()
data
}
}
/**
* Save the model data into a config object (the saver object).
*/
save(saver) {
saver.trajectoryData = {};
}
/**
* Cast this instance into a basic JS object.
*/
toObject() {
return {
id: this._currentId,
data: this._trajectoriesData
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment