BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ApplicationModels.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/ApplicationModels.cpp
6 //! @brief Defines class holding all application models
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
37 #include <QtCore/QXmlStreamWriter>
38 
40  : QObject(parent)
41  , m_documentModel(nullptr)
42  , m_materialModel(nullptr)
43  , m_instrumentModel(nullptr)
44  , m_sampleModel(nullptr)
45  , m_realDataModel(nullptr)
46  , m_jobModel(nullptr)
47  , m_materialPropertyController(new MaterialPropertyController(this))
48 {
49  //! creates and initializes models, order is important
50  m_documentModel = new DocumentModel(this);
51  m_materialModel = new MaterialModel(this);
52  m_sampleModel = new SampleModel(this);
54  m_realDataModel = new RealDataModel(this);
55  m_jobModel = new JobModel(this);
56 
58 
65 
66  resetModels();
67 
69 }
70 
72 
74 {
75  return m_documentModel;
76 }
77 
79 {
80  return m_materialModel;
81 }
82 
84 {
85  return m_instrumentModel;
86 }
87 
89 {
90  return m_sampleModel;
91 }
92 
94 {
95  return m_realDataModel;
96 }
97 
99 {
100  return m_jobModel;
101 }
102 
103 //! reset all models to initial state
105 {
108 
110  m_materialModel->addRefractiveMaterial("Default", 1e-3, 1e-5);
111  m_materialModel->addRefractiveMaterial("Vacuum", 0.0, 0.0);
112  m_materialModel->addRefractiveMaterial("Particle", 6e-4, 2e-8);
113  m_materialModel->addRefractiveMaterial("Substrate", 6e-6, 2e-8);
114 
115  m_sampleModel->clear();
116 
118 
119  m_jobModel->clear();
120 
122  auto instrument = m_instrumentModel->insertItem<GISASInstrumentItem>();
123  instrument->setItemName("GISAS");
124 }
125 
126 //! Writes all model in file one by one
127 
128 void ApplicationModels::writeTo(QXmlStreamWriter* writer)
129 {
130  for (auto model : modelList())
131  model->writeTo(writer);
132 }
133 
134 void ApplicationModels::readFrom(QXmlStreamReader* reader, MessageService* messageService)
135 {
136  try {
137 
138  for (auto model : modelList()) {
139  if (model->getModelTag() == reader->name()) {
140  model->readFrom(reader, messageService);
141  break;
142  }
143  }
144  } catch (DeserializationException& ex) {
145  resetModels();
146  reader->raiseError(ex.text());
147  }
148 
150 }
151 
152 //! Returns the list of all GUI models
153 
154 QList<SessionModel*> ApplicationModels::modelList()
155 {
156  QList<SessionModel*> result;
157  result.append(m_documentModel);
158  result.append(m_materialModel);
159  result.append(m_instrumentModel);
160  result.append(m_sampleModel);
161  result.append(m_realDataModel);
162  result.append(m_jobModel);
163  return result;
164 }
165 
166 QVector<SessionItem*> ApplicationModels::nonXMLItems() const
167 {
169  return QVector<SessionItem*>() << m_realDataModel->nonXMLItems() << m_jobModel->nonXMLItems()
171 }
172 
174 {
175  if (model) {
176  connect(model, &SessionModel::dataChanged, this, &ApplicationModels::modelChanged,
177  Qt::UniqueConnection);
178  connect(model, &SessionModel::rowsRemoved, this, &ApplicationModels::modelChanged,
179  Qt::UniqueConnection);
180  connect(model, &SessionModel::rowsInserted, this, &ApplicationModels::modelChanged,
181  Qt::UniqueConnection);
182  }
183 }
Defines class holding all application models.
#define ASSERT(condition)
Definition: Assert.h:31
Defines class DeserializationException.
Defines class DocumentModel.
Defines GUIObjectBuilder namespace.
Defines ImportDataUtils namespace.
Defines InstrumentItems classes.
Defines class InstrumentModel.
Defines class IntensityDataIOFactory.
Defines class IntensityDataItem.
Defines class JobItem.
Defines class JobModel.
Defines class MaterialModel.
Defines MaterialPropertyController class.
Defines MessageService class.
Defines class MultiLayer.
Defines class OffSpecularSimulation.
Defines class RealDataItem.
Defines class RealDataModel.
Defines class SampleBuilderFactory.
Defines class SampleModel.
Defines class SimulationOptionsItem.
Defines namespace and functions for standard simulations.
SampleModel * sampleModel()
MaterialPropertyController * m_materialPropertyController
RealDataModel * realDataModel()
SampleModel * m_sampleModel
MaterialModel * materialModel()
QList< SessionModel * > modelList()
Returns the list of all GUI models.
void connectModel(SessionModel *model)
QVector< SessionItem * > nonXMLItems() const
Returns all non-XML items.
MaterialModel * m_materialModel
void readFrom(class QXmlStreamReader *reader, MessageService *messageService)
RealDataModel * m_realDataModel
void writeTo(class QXmlStreamWriter *writer)
Writes all model in file one by one.
ApplicationModels(QObject *parent=nullptr)
DocumentModel * m_documentModel
DocumentModel * documentModel()
InstrumentModel * instrumentModel()
void resetModels()
reset all models to initial state
InstrumentModel * m_instrumentModel
The DocumentModel class is a model with GUI settings related to the opened project.
Definition: DocumentModel.h:25
QVector< SessionItem * > nonXMLItems() const override
void clear() override
Definition: JobModel.cpp:127
QVector< SessionItem * > nonXMLItems() const override
Definition: JobModel.cpp:135
MaterialItem * addRefractiveMaterial(const QString &name, double delta, double beta)
Listens MaterialModel for changes in MaterialItems and then updates MaterialProperties in all related...
void setModels(MaterialModel *materialModel, SampleModel *sampleModel)
void onMaterialModelLoad()
Special case when original MaterialModel was fully rebuild from MaterialEditor.
The service to collect messages from different senders.
The RealDataModel class is a model to store all imported RealDataItem's.
Definition: RealDataModel.h:26
void setInstrumentModel(InstrumentModel *instrumentModel)
virtual QVector< SessionItem * > nonXMLItems() const override
Main model to hold sample items.
Definition: SampleModel.h:24
void setItemName(const QString &name)
Set item name, add property if necessary.
virtual void clear()
T * insertItem(SessionItem *parent=nullptr, int row=-1, QString tag="")
Definition: SessionModel.h:125
The SimulationOptionsItem class holds simulation status (run policy, number of threads,...