Skip to content

Commit

Permalink
Fixed error loading config with structure loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
JJPPeters committed Jun 5, 2020
1 parent 62b9bc7 commit 0d21809
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -1025,6 +1029,8 @@ void MainWindow::on_actionImport_default_triggered(bool preserve_ui) {
Manager = std::make_shared<SimulationManager>();
}

Manager->setStructure(structure);

if (!preserve_ui)
updateGuiFromManager();
}
Expand Down
21 changes: 21 additions & 0 deletions src/simulation/simulationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ SimulationManager &SimulationManager::operator=(const SimulationManager &sm) {
return *this;
}

void SimulationManager::setStructure(std::shared_ptr<CrystalStructure> struc_ptr) {
// lock this in case we need multiple devices to load this structure
std::unique_lock<std::mutex> 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
Expand Down
1 change: 1 addition & 0 deletions src/simulation/simulationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SimulationManager
std::shared_ptr<IncoherentEffects> incoherenceEffects() {return incoherence_effects;}

// structure setters
void setStructure(std::shared_ptr<CrystalStructure> struc_ptr);
void setStructure(std::string fPath, CIF::SuperCellInfo info = CIF::SuperCellInfo(), bool fix_cif=false);
void setStructure(CIF::CIFReader cif, CIF::SuperCellInfo info);

Expand Down
7 changes: 7 additions & 0 deletions src/simulation/structure/simulationcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CrystalStructure> structure_ptr) {
if (structure_ptr)
crystal_structure = std::make_shared<CrystalStructure>(*structure_ptr);
else
crystal_structure = std::shared_ptr<CrystalStructure>();
}
1 change: 1 addition & 0 deletions src/simulation/structure/simulationcell.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SimulationCell {
unsigned int sliceCount();
unsigned int preSliceCount();

void setCrystalStructure(std::shared_ptr<CrystalStructure> 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> crystalStructure() {return crystal_structure;}
Expand Down

0 comments on commit 0d21809

Please sign in to comment.