BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
quicksimcontroller.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/quicksimeditor/quicksimcontroller.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
20 #include "gui2/model/jobitem.h"
21 #include "gui2/model/jobmodel.h"
23 #include "gui2/model/sampleitems.h"
24 #include "gui2/model/samplemodel.h"
31 
32 namespace {
33 const int profile_points_count = 1000;
34 }
35 
36 namespace gui2 {
37 
39  : QObject(parent)
40  , m_jobManager(new JobManager(this))
41  , m_isRealTimeMode(Constants::live_simulation_default_on)
42 {
43 }
44 
46 
48 {
49  m_models = models;
50 
51  auto on_model_change = [this]() { onMultiLayerChange(); };
52  m_materialChangedController = std::make_unique<ModelView::ModelHasChangedController>(
53  m_models->materialModel(), on_model_change);
54  m_sampleChangedController = std::make_unique<ModelView::ModelHasChangedController>(
55  m_models->sampleModel(), on_model_change);
56  m_instrumentChangedController = std::make_unique<ModelView::ModelHasChangedController>(
57  m_models->instrumentModel(), on_model_change);
58 
60 
63 }
64 
65 //! Requests interruption of running simulaitons.
66 
68 {
70 }
71 
73 {
74  m_isRealTimeMode = status;
75 }
76 
77 //! Processes multilayer on request. Doesn't work in real time mode.
78 
80 {
81  process_multilayer(/*submit_simulation*/ true);
82 }
83 
84 //! Processes multilayer on any model change. Works only in realtime mode.
85 
87 {
88  process_multilayer(/*submit_simulation*/ m_isRealTimeMode);
89 }
90 
91 //! Takes simulation results from JobManager and write into the model.
92 
94 {
96 }
97 
98 //! Constructs multislice, calculates profile and submits specular simulation.
99 
100 void QuickSimController::process_multilayer(bool submit_simulation)
101 {
102  auto multilayer = m_models->sampleModel()->topItem<MultiLayerItem>();
103  auto slices = Utils::CreateMultiSlice(*multilayer);
104  update_sld_profile(slices);
105  if (submit_simulation)
107 }
108 
109 //! Calculates sld profile from slice and immediately update data items.
110 
112 {
113  auto data = SpecularToySimulation::sld_profile(multislice, profile_points_count);
114  jobModel()->updateSLDProfile(data);
115 }
116 
117 //! Submit data to JobManager for consequent specular simulation in a separate thread.
118 
120 {
121  auto instrument = instrumentModel()->topItem<SpecularInstrumentItem>();
122  auto beam = instrument->beamItem();
123  m_jobManager->requestSimulation(multislice, beam->qScanValues(), beam->intensity());
124 }
125 
126 //! Connect signals going from JobManager. Connections are made queued since signals are emitted
127 //! from non-GUI thread and we want to deal with widgets.
128 
130 {
131 
132  // Simulation progress is propagated from JobManager to this controller for further forwarding.
134  Qt::QueuedConnection);
135 
136  // Notification about completed simulation from jobManager to this controller.
138  &QuickSimController::onSimulationCompleted, Qt::QueuedConnection);
139 }
140 
142 {
143  return m_models->jobModel();
144 }
145 
147 {
148  return m_models->instrumentModel();
149 }
150 
151 } // namespace gui2
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
T * topItem() const
Returns top item of the given type.
Definition: sessionmodel.h:126
virtual void setViewportToContent(double left, double top, double right, double bottom)
Sets range of x,y window to show all data.
Main class to holds all models of GUI session.
MaterialModel * materialModel()
InstrumentModel * instrumentModel()
Model to store specular instruments settings.
Handles all thread activity for running job simulation in the background.
Definition: jobmanager.h:27
SimulationResult simulationResult()
Returns vector representing results of a simulation.
Definition: jobmanager.cpp:36
void simulationCompleted()
void requestSimulation(const multislice_t &multislice, const std::vector< double > &qvalues, double intensity)
Performs simulation request.
Definition: jobmanager.cpp:45
void onInterruptRequest()
Processes interrupt request by setting corresponding flag.
Definition: jobmanager.cpp:59
void progressChanged(int value)
The model to store results of (possibly) multiple reflectometry simulation, and all viewports,...
Definition: jobmodel.h:36
void updateSpecularData(const SimulationResult &data)
Updates specular data in JobItem from simulation results.
Definition: jobmodel.cpp:71
void updateSLDProfile(const SLDProfile &data)
Updates SLD profile data.
Definition: jobmodel.cpp:83
ModelView::GraphViewportItem * sldViewport() const
Definition: jobmodel.cpp:49
Multi layer capable of holding layers and other multi-layers.
Definition: sampleitems.h:51
std::unique_ptr< ModelView::ModelHasChangedController > m_sampleChangedController
void onRealTimeRequest(bool status)
void update_sld_profile(const multislice_t &multilayer)
Calculates sld profile from slice and immediately update data items.
void onRunSimulationRequest()
Processes multilayer on request. Doesn't work in real time mode.
void process_multilayer(bool submit_simulation=false)
Constructs multislice, calculates profile and submits specular simulation.
InstrumentModel * instrumentModel() const
std::unique_ptr< ModelView::ModelHasChangedController > m_instrumentChangedController
void onMultiLayerChange()
Processes multilayer on any model change. Works only in realtime mode.
ApplicationModels * m_models
std::unique_ptr< ModelView::ModelHasChangedController > m_materialChangedController
Run simulation on every parameter change.
void submit_specular_simulation(const multislice_t &multislice)
Submit data to JobManager for consequent specular simulation in a separate thread.
QuickSimController(QObject *parent=nullptr)
void setup_jobmanager_connections()
Connect signals going from JobManager.
void onSimulationCompleted()
Takes simulation results from JobManager and write into the model.
void onInterruptRequest()
Requests interruption of running simulaitons.
void setModels(ApplicationModels *models)
void progressChanged(int value)
Represents specular instrument.
SpecularBeamItem * beamItem() const
static SLDProfile sld_profile(const multislice_t &multislice, int n_points)
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
const bool live_simulation_default_on
Initial state of some widgets.
Definition: app_constants.h:29
DAREFLCORE_EXPORT multislice_t CreateMultiSlice(const MultiLayerItem &multilayer)
Creates multi-slice presentation of internal multilayer structure.
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20
std::vector< SliceData > multislice_t
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?