Skip to content
Snippets Groups Projects
Commit fdc10136 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Refactoring in GUIObjectBuilder for later processing of SimulationDistributionParameters.

parent 10ede64f
No related branches found
No related tags found
No related merge requests found
......@@ -46,51 +46,26 @@ bool GUIExamplesFactory::isValidExampleName(const QString &name)
return m_name_to_registry.contains(name);
}
//! Populate sample model with
ParameterizedItem *GUIExamplesFactory::createSampleItems(const QString &name, SampleModel *sampleModel)
{
if(sampleModel->getModelTag() != SessionXML::SampleModelTag ) {
throw GUIHelpers::Error("GUIExamplesFactory::createSampleItems() -> Error. Not a SampleModelTag");
}
QString exampleName = m_name_to_registry[name];
SimulationRegistry registry;
boost::scoped_ptr<Simulation> simulation(registry.createItem(exampleName.toLatin1().data()));
boost::scoped_ptr<Simulation> simulation(registry.createSimulation(exampleName.toStdString()));
Q_ASSERT(simulation.get());
boost::scoped_ptr<ISample> sample(simulation->getSampleBuilder()->buildSample());
Q_ASSERT(sample.get());
sample->setName(name.toUtf8().constData());
//sample->printSampleTree();
GUIObjectBuilder guiBuilder;
return guiBuilder.populateSampleModel(sampleModel, sample.get());
//return guiBuilder.getTopItem();
return guiBuilder.populateSampleModel(sampleModel, *simulation, name);
}
ParameterizedItem *GUIExamplesFactory::createInstrumentItems(const QString &name, InstrumentModel *instrumentModel)
{
if(instrumentModel->getModelTag() != SessionXML::InstrumentModelTag ) {
throw GUIHelpers::Error("GUIExamplesFactory::createInstrumentItems() -> Error. Not an InstrumentModelTag");
}
QString exampleName = m_name_to_registry[name];
qDebug() << " ";
qDebug() << " ";
qDebug() << " GUIExamplesFactory::createInstrumentItems()" << name << exampleName;
SimulationRegistry registry;
boost::scoped_ptr<Simulation> simulation(registry.createItem(exampleName.toLatin1().data()));
boost::scoped_ptr<Simulation> simulation(registry.createSimulation(exampleName.toStdString()));
Q_ASSERT(simulation.get());
boost::scoped_ptr<Instrument> instrument(new Instrument(simulation.get()->getInstrument()));
QString instrumentName = name + "_instrument";
instrument->setName(instrumentName.toUtf8().constData());
//simulation->setName(name.toUtf8().constData());
GUIObjectBuilder guiBuilder;
return guiBuilder.populateInstrumentModel(instrumentModel, instrument.get());
return guiBuilder.populateInstrumentModel(instrumentModel, *simulation, instrumentName);
}
......@@ -51,35 +51,61 @@ GUIObjectBuilder::GUIObjectBuilder()
{
}
ParameterizedItem *GUIObjectBuilder::populateSampleModel(
SampleModel *sampleModel, ISample *sample)
ParameterizedItem *GUIObjectBuilder::populateSampleModel(SampleModel *sampleModel,
const Simulation &simulation, const QString &sampleName)
{
boost::scoped_ptr<ISample> sample;
if(simulation.getSampleBuilder()) {
sample.reset(simulation.getSampleBuilder()->buildSample());
} else if(simulation.getSample()) {
sample.reset(simulation.getSample()->clone());
} else {
throw GUIHelpers::Error("GUIObjectBuilder::populateSampleModel() -> No valid sample");
}
return populateSampleModel(sampleModel, *sample, sampleName);
}
ParameterizedItem *GUIObjectBuilder::populateSampleModel(SampleModel *sampleModel, const ISample &sample, const QString &sampleName)
{
Q_ASSERT(sampleModel);
Q_ASSERT(sample);
m_levelToParentItem.clear();
m_topSampleName = sample->getName().c_str();
m_topSampleName = sampleName;
if(m_topSampleName.isEmpty()) m_topSampleName = sample.getName().c_str();
m_sampleModel = sampleModel;
qDebug() << "GUIObjectBuilder::populateModel()" << m_topSampleName;
VisitSampleTree(sample, *this);
ParameterizedItem *result = m_levelToParentItem[0];
//sample->accept(this);
VisitSampleTree(*sample, *this);
return m_levelToParentItem[0];
result->setItemName(m_topSampleName);
return result;
}
ParameterizedItem *GUIObjectBuilder::populateInstrumentModel(
InstrumentModel *instrumentModel, Instrument *instrument)
ParameterizedItem *GUIObjectBuilder::populateInstrumentModel(InstrumentModel *instrumentModel,
const Simulation &simulation, const QString &instrumentName)
{
Q_UNUSED(instrumentModel);
Q_UNUSED(instrument);
return populateInstrumentModel(instrumentModel, simulation.getInstrument(), instrumentName);
}
ParameterizedItem *GUIObjectBuilder::populateInstrumentModel(InstrumentModel *instrumentModel, const Instrument &instrument, const QString &instrumentName)
{
Q_ASSERT(instrumentModel);
ParameterizedItem *instrumentItem =
instrumentModel->insertNewItem(Constants::InstrumentType);
instrumentItem->setItemName(instrument->getName().c_str());
Beam beam = instrument->getBeam();
if(instrumentName.isEmpty()) {
instrumentItem->setItemName(instrument.getName().c_str());
} else {
instrumentItem->setItemName(instrumentName);
}
Beam beam = instrument.getBeam();
BeamItem *beamItem = dynamic_cast<BeamItem *>(instrumentModel->insertNewItem(
Constants::BeamType,
instrumentModel->indexOfItem(instrumentItem)));
......@@ -90,7 +116,7 @@ ParameterizedItem *GUIObjectBuilder::populateInstrumentModel(
beamItem->setInclinationAngle(Units::rad2deg(-1.0*beam.getAlpha()));
beamItem->setAzimuthalAngle(Units::rad2deg(-1.0*beam.getPhi()));
Detector detector = instrument->getDetector();
Detector detector = instrument.getDetector();
ParameterizedItem *detectorItem = instrumentModel->insertNewItem(
Constants::DetectorType, instrumentModel->indexOfItem(instrumentItem));
ParameterizedItem *detectorSubItem =
......
......@@ -34,9 +34,20 @@ public:
virtual ~GUIObjectBuilder(){}
ParameterizedItem *populateSampleModel(SampleModel *sampleModel,
ISample *sample);
const Simulation &simulation,
const QString &sampleName=QString());
ParameterizedItem *populateSampleModel(SampleModel *sampleModel,
const ISample &sample,
const QString &sampleName=QString());
ParameterizedItem *populateInstrumentModel(InstrumentModel *instrumentModel,
const Simulation &simulation,
const QString &instrumentName=QString());
ParameterizedItem *populateInstrumentModel(InstrumentModel *instrumentModel,
Instrument *instrument);
const Instrument &instrument,
const QString &instrumentName=QString());
using ISampleVisitor::visit;
......
......@@ -307,7 +307,7 @@ void MainWindow::testGUIObjectBuilder()
boost::scoped_ptr<ISample> sample(factory.createSample("isgisaxs01"));
GUIObjectBuilder guiBuilder;
guiBuilder.populateSampleModel(m_sampleModel, sample.get());
guiBuilder.populateSampleModel(m_sampleModel, *sample);
}
void MainWindow::onAboutApplication()
......
......@@ -81,19 +81,15 @@ void GUIFunctionalTest::createDomainSimulation()
boost::scoped_ptr<MaterialEditor> materialEditor(new MaterialEditor(materialModel.get()));
// populating GUI models from domain
boost::scoped_ptr<ISample> reference_sample(m_reference_simulation->getSample()->clone());
boost::scoped_ptr<Instrument> reference_instrument(new Instrument(m_reference_simulation->getInstrument()));
GUIObjectBuilder guiBuilder;
guiBuilder.populateSampleModel(sampleModel.get(), reference_sample.get());
guiBuilder.populateInstrumentModel(instrumentModel.get(), reference_instrument.get());
guiBuilder.populateSampleModel(sampleModel.get(), *m_reference_simulation);
guiBuilder.populateInstrumentModel(instrumentModel.get(), *m_reference_simulation);
// building sample back
QModelIndex sampleIndex = sampleModel->index(0, 0, QModelIndex());
ParameterizedItem *sampleItem = sampleModel->itemForIndex(sampleIndex);
DomainObjectBuilder builder;
MultiLayer *new_sample = builder.buildMultiLayer(*sampleItem);
new_sample->printSampleTree();
// building multilayer back
QModelIndex instrumentIndex = instrumentModel->index(0, 0, QModelIndex());
......
......@@ -44,7 +44,7 @@ def RunSimulation():
wavelength_distr = DistributionLogNormal(1.0*angstrom, 0.1)
alpha_distr = DistributionGaussian(-0.2*degree, 0.1*degree)
phi_distr = DistributionGaussian(0.0*degree, 0.1*degree)
simulation.addParameterDistribution("*/Beam/wavelength", wavelength_distr, 4)
simulation.addParameterDistribution("*/Beam/wavelength", wavelength_distr, 5)
simulation.addParameterDistribution("*/Beam/alpha", alpha_distr, 5)
simulation.addParameterDistribution("*/Beam/phi", phi_distr, 5)
simulation.setSample(multi_layer)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment