Skip to content
Snippets Groups Projects
Commit 9add0e44 authored by Matthias Puchner's avatar Matthias Puchner
Browse files

move example infos to example factory (in the future the info will be used at...

move example infos to example factory (in the future the info will be used at different locations, not only the sample toolbox)
parent cfad9ee2
No related branches found
No related tags found
1 merge request!397Centralize item infos
......@@ -17,23 +17,48 @@
#include "GUI/Models/GUIDomainSampleVisitor.h"
#include "Sample/Multilayer/MultiLayer.h"
#include "Sample/StandardSamples/ExemplarySamples.h"
#include <QMap>
#include <functional>
#include <map>
#include <memory>
using std::tuple;
namespace {
const std::map<QString, std::function<MultiLayer*()>> builders{
{"CylindersAndPrismsBuilder", ExemplarySamples::createCylindersAndPrisms},
{"RadialParaCrystalBuilder", ExemplarySamples::createRadialParaCrystal},
{"HexParaCrystalBuilder", ExemplarySamples::createHexParaCrystal},
{"CoreShellParticleBuilder", ExemplarySamples::createCoreShellParticle},
{"MultiLayerWithRoughnessBuilder", ExemplarySamples::createMultiLayerWithRoughness},
{"SquareLattice2DBuilder", ExemplarySamples::createSquareLattice2D},
{"RotatedPyramidsBuilder", ExemplarySamples::createRotatedPyramids},
{"ParticleCompositionBuilder", ExemplarySamples::createParticleComposition},
{"MesoCrystalBuilder", ExemplarySamples::createMesoCrystal},
};
const QMap<QString, tuple<QString, QString, std::function<MultiLayer*()>>> builders{
{"CylindersAndPrismsBuilder",
{"Cylinder and prisms", "Mixture of cylinders and prisms without interference",
ExemplarySamples::createCylindersAndPrisms}},
{"RadialParaCrystalBuilder",
{"Interference 1D paracrystal", "Interference 1D radial paracrystal",
ExemplarySamples::createRadialParaCrystal}},
{"HexParaCrystalBuilder",
{"Interference 2D paracrystal", "Interference 2D paracrystal",
ExemplarySamples::createHexParaCrystal}},
{"CoreShellParticleBuilder",
{"Core shell particles", "Core shell particles", ExemplarySamples::createCoreShellParticle}},
{"MultiLayerWithRoughnessBuilder",
{"Multilayer with correlated roughness", "Multilayer with correlated roughness",
ExemplarySamples::createMultiLayerWithRoughness}},
{"SquareLattice2DBuilder",
{"Interference 2D square lattice", "Interference 2D lattice",
ExemplarySamples::createSquareLattice2D}},
{"RotatedPyramidsBuilder",
{"Rotated pyramids", "Rotated pyramids on top of substrate",
ExemplarySamples::createRotatedPyramids}},
{"ParticleCompositionBuilder",
{"Hexagonal lattice with basis",
"Hexagonal lattice with basis to represent two layers of spheres",
ExemplarySamples::createParticleComposition}},
{"MesoCrystalBuilder", {"Mesocrystal", "", ExemplarySamples::createMesoCrystal}}};
} // namespace
......@@ -47,7 +72,19 @@ SessionItem* GUIExamplesFactory::createSampleItems(const QString& name, SampleMo
MaterialModel* materialModel)
{
ASSERT(isValidExampleName(name));
MultiLayer* sample = builders.at(name)();
MultiLayer* sample = std::get<2>(builders[name])();
return GUIDomainSampleVisitor().populateSampleModel(sampleModel, materialModel, *sample, name);
}
QStringList GUIExamplesFactory::exampleNames()
{
return builders.keys();
}
std::tuple<QString, QString> GUIExamplesFactory::exampleInfo(const QString& name)
{
ASSERT(isValidExampleName(name));
auto [title, description, builder] = builders[name];
return {title, description};
}
......@@ -28,6 +28,12 @@ public:
static SessionItem* createSampleItems(const QString& name, SampleModel* sampleModel,
MaterialModel* materialModel);
//! The internal example name, e.g. for creation with createSampleItems.
static QStringList exampleNames();
//! Returns human readable name and description
static std::tuple<QString, QString> exampleInfo(const QString& name);
};
#endif // BORNAGAIN_GUI_MODELS_GUIEXAMPLESFACTORY_H
......@@ -13,6 +13,7 @@
// ************************************************************************************************
#include "GUI/Views/SampleDesigner/SampleToolBox.h"
#include "GUI/Models/GUIExamplesFactory.h"
#include "GUI/Views/SampleDesigner/DesignerMimeData.h"
#include "GUI/Views/SampleDesigner/SampleToolBoxTreeWidget.h"
#include <QApplication>
......@@ -200,21 +201,9 @@ void SampleToolBox::fill()
// ------------------------------------------------------------------------------------------
group("Demo samples");
entry("Cylinder and prisms", "sample_layers2.png", "CylindersAndPrismsBuilder",
"Mixture of cylinders and prisms without interference");
entry("Interference 1D paracrystal", "sample_layers2.png", "RadialParaCrystalBuilder",
"Interference 1D radial paracrystal");
entry("Interference 2D paracrystal", "sample_layers2.png", "HexParaCrystalBuilder",
"Interference 2D paracrystal");
entry("Core shell particles", "sample_layers2.png", "CoreShellParticleBuilder",
"Core shell particles");
entry("Multilayer with correlated roughness", "sample_layers2.png",
"MultiLayerWithRoughnessBuilder", "Multilayer with correlated roughness");
entry("Interference 2D square lattice", "sample_layers2.png", "SquareLattice2DBuilder",
"Interference 2D lattice");
entry("Rotated pyramids", "sample_layers2.png", "RotatedPyramidsBuilder",
"Rotated pyramids on top of substrate");
entry("Hexagonal lattice with basis", "sample_layers2.png", "ParticleCompositionBuilder",
"Hexagonal lattice with basis to represent two layers of spheres");
entry("Mesocrystal", "sample_layers2.png", "MesoCrystalBuilder", "");
for (auto exampleName : GUIExamplesFactory::exampleNames()) {
auto [title, description] = GUIExamplesFactory::exampleInfo(exampleName);
m_view->addEntry(title, QIcon(":/SampleDesignerToolbox/images/sample_layers2.png"),
exampleName, description);
}
}
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