diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 808683c..a212a6b 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -859,7 +859,9 @@ void MainWindow::on_actionImport_parameters_triggered() { nlohmann::json j = fileio::OpenSettingsJson(fileName.toStdString()); SimulationManager m = JSONUtils::JsonToManager(j); + auto structure = Manager->simulationCell()->crystalStructure(); *Manager = m; + Manager->setStructure(structure); updateGuiFromManager(); } @@ -1016,6 +1018,8 @@ void MainWindow::on_actionImport_default_triggered(bool preserve_ui) { if(config_location.endsWith("/")) config_location.chop(1); + auto structure = Manager->simulationCell()->crystalStructure(); + try { nlohmann::json j = fileio::OpenSettingsJson(config_location.toStdString() + "/microscopes/" + param_name + ".json"); *Manager = JSONUtils::JsonToManager(j); @@ -1025,6 +1029,8 @@ void MainWindow::on_actionImport_default_triggered(bool preserve_ui) { Manager = std::make_shared(); } + Manager->setStructure(structure); + if (!preserve_ui) updateGuiFromManager(); } diff --git a/src/simulation/simulationmanager.cpp b/src/simulation/simulationmanager.cpp index 43766bf..4eee839 100644 --- a/src/simulation/simulationmanager.cpp +++ b/src/simulation/simulationmanager.cpp @@ -90,6 +90,27 @@ SimulationManager &SimulationManager::operator=(const SimulationManager &sm) { return *this; } +void SimulationManager::setStructure(std::shared_ptr struc_ptr) { + // lock this in case we need multiple devices to load this structure + std::unique_lock lock(structure_mutex); + + simulation_cell->setCrystalStructure(struc_ptr); + + if (simulation_cell->crystalStructure() && !maintain_area) { + auto x_lims = simulation_cell->crystalStructure()->limitsX(); + auto y_lims = simulation_cell->crystalStructure()->limitsY(); + + simulationArea()->setRawLimitsX(x_lims[0], x_lims[1]); + simulationArea()->setRawLimitsY(y_lims[0], y_lims[1]); + + stemArea()->setRawLimitsX(x_lims[0], x_lims[1]); + stemArea()->setRawLimitsY(y_lims[0], y_lims[1]); + + cbedPosition()->setXPos((x_lims[0] + x_lims[1]) / 2); + cbedPosition()->setYPos((y_lims[0] + y_lims[1]) / 2); + } +} + void SimulationManager::setStructure(std::string filePath, CIF::SuperCellInfo info, bool fix_cif) { // lock this in case we need multiple devices to load this structure diff --git a/src/simulation/simulationmanager.h b/src/simulation/simulationmanager.h index 2b5cf4e..1e47159 100644 --- a/src/simulation/simulationmanager.h +++ b/src/simulation/simulationmanager.h @@ -55,6 +55,7 @@ class SimulationManager std::shared_ptr incoherenceEffects() {return incoherence_effects;} // structure setters + void setStructure(std::shared_ptr struc_ptr); void setStructure(std::string fPath, CIF::SuperCellInfo info = CIF::SuperCellInfo(), bool fix_cif=false); void setStructure(CIF::CIFReader cif, CIF::SuperCellInfo info); diff --git a/src/simulation/structure/simulationcell.cpp b/src/simulation/structure/simulationcell.cpp index 5dfe514..5c7691d 100644 --- a/src/simulation/structure/simulationcell.cpp +++ b/src/simulation/structure/simulationcell.cpp @@ -93,3 +93,10 @@ void SimulationCell::setCrystalStructure(std::string &file_path, CIF::SuperCellI void SimulationCell::setCrystalStructure(CIF::CIFReader cif, CIF::SuperCellInfo info) { crystal_structure.reset(new CrystalStructure(cif, info)); } + +void SimulationCell::setCrystalStructure(std::shared_ptr structure_ptr) { + if (structure_ptr) + crystal_structure = std::make_shared(*structure_ptr); + else + crystal_structure = std::shared_ptr(); +} diff --git a/src/simulation/structure/simulationcell.h b/src/simulation/structure/simulationcell.h index 5e86e4c..5fa6579 100644 --- a/src/simulation/structure/simulationcell.h +++ b/src/simulation/structure/simulationcell.h @@ -46,6 +46,7 @@ class SimulationCell { unsigned int sliceCount(); unsigned int preSliceCount(); + void setCrystalStructure(std::shared_ptr structure_ptr); void setCrystalStructure(std::string &file_path, CIF::SuperCellInfo info = CIF::SuperCellInfo(), bool fix_cif=false); void setCrystalStructure(CIF::CIFReader cif, CIF::SuperCellInfo info); std::shared_ptr crystalStructure() {return crystal_structure;}