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

re-implement basis selection of MesoCrystal (without SessionModel's modelType)

parent fc92ef4d
No related branches found
No related tags found
1 merge request!579Various fixes & modifications
......@@ -39,6 +39,11 @@ QVector<ItemWithParticlesCatalog::Type> ItemWithParticlesCatalog::types()
return {Type::Particle, Type::Composition, Type::CoreShell, Type::MesoCrystal};
}
QVector<ItemWithParticlesCatalog::Type> ItemWithParticlesCatalog::assemblyTypes()
{
return {Type::Composition, Type::CoreShell, Type::MesoCrystal};
}
ItemWithParticlesCatalog::UiInfo ItemWithParticlesCatalog::uiInfo(Type type)
{
auto createUiInfo = [](const QString& menuEntry, const QString& iconName,
......
......@@ -38,12 +38,12 @@ public:
//! If type is "None", a nullptr is returned.
static ItemWithParticles* create(Type type);
//! Available types of interference items.
//!
//! Contains also type "None".
//! This list is sorted as expected in the UI (e.g. in combo box)
//! Available types of items, sorted as expected in the UI (e.g. in combo box)
static QVector<Type> types();
//! Available types of assembly items, sorted as expected in the UI (e.g. in combo box)
static QVector<Type> assemblyTypes();
//! UiInfo on the given type.
static UiInfo uiInfo(Type t);
......
......@@ -43,7 +43,6 @@ public:
void setOuterShape(FormFactorItem* p);
ItemWithParticles* basisParticle() const;
template <typename T> T* createBasis();
void setBasis(ItemWithParticles* basis);
void setVectorA(const R3& vector_a);
......@@ -71,11 +70,4 @@ template <typename T> T* MesoCrystalItem::setOuterShapeType()
return p;
}
template <typename T> T* MesoCrystalItem::createBasis()
{
auto* p = new T();
setBasis(p);
return p;
}
#endif // BORNAGAIN_GUI_MODEL_SAMPLE_MESOCRYSTALITEM_H
......@@ -66,40 +66,46 @@ QComboBox* MesoCrystalForm::createBasisCombo(QWidget* parent, ItemWithParticles*
WheelEventEater::install(combo);
combo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
Q_UNUSED(current)
// #baMigration ++ implement basis combo
// const auto modelTypes = ItemCatalog::formfactorHardParticleTypes()
// + ItemCatalog::formfactorRippleTypes()
// + ItemCatalog::particleAssemblyTypes(); //
// ParticleCoreShellItem::M_TYPE,
// ParticleCompositionItem::M_TYPE,MesoCrystalItem::M_TYPE};
//
// combo->addItem("None", "");
// for (const auto& modelType : modelTypes) {
// const auto ui = ItemCatalog::instance().uiInfo(modelType);
// combo->addItem(QIcon(ui.iconPath), ui.menuEntry, modelType);
// }
//
// combo->setMaxVisibleItems(combo->count());
uint32_t currentData = 0;
for (auto type : FormFactorItemCatalog::types()) {
const auto ui = FormFactorItemCatalog::uiInfo(type);
combo->addItem(QIcon(ui.iconPath), ui.menuEntry, static_cast<uint32_t>(type));
if (auto* p = dynamic_cast<ParticleItem*>(current))
if (FormFactorItemCatalog::type(p->formfactor()) == type)
currentData = static_cast<uint32_t>(type);
}
for (auto type : ItemWithParticlesCatalog::assemblyTypes()) {
const auto ui = ItemWithParticlesCatalog::uiInfo(type);
combo->addItem(QIcon(ui.iconPath), ui.menuEntry, 1000 + static_cast<uint32_t>(type));
if (ItemWithParticlesCatalog::type(current) == type)
currentData = 1000 + static_cast<uint32_t>(type);
}
combo->setMaxVisibleItems(combo->count());
// combo->addItem("None", ""); // #baMigration ++ allow none? rm only if never can be none!
//
// if (current == nullptr)
// combo->setCurrentIndex(0);
// else if (auto* p = dynamic_cast<ParticleItem*>(current))
// combo->setCurrentIndex(combo->findData(p->formfactor()->modelType()));
// else
// combo->setCurrentIndex(combo->findData(current->modelType()));
//
const auto currentIndex = combo->findData(currentData);
ASSERT(currentIndex >= 0);
combo->setCurrentIndex(currentIndex);
return combo;
}
void MesoCrystalForm::onBasisComboChanged()
{
// #baMigration ++ implement basis combo
// while (m_layout->rowCount() > m_rowOfBasisTypeCombo + 1)
// m_layout->removeRow(m_rowOfBasisTypeCombo + 1);
//
// const QString newClassName = m_basisCombo->currentData().toString();
// m_ec->setMesoCrystalBasis(this, newClassName);
while (m_layout->rowCount() > m_rowOfBasisTypeCombo + 1)
m_layout->removeRow(m_rowOfBasisTypeCombo + 1);
const auto currentData = m_basisCombo->currentData().toUInt();
if (currentData < 1000)
m_ec->setMesoCrystalBasis(this, static_cast<FormFactorItemCatalog::Type>(currentData));
else
m_ec->setMesoCrystalBasis(this,
static_cast<ItemWithParticlesCatalog::Type>(currentData - 1000));
}
void MesoCrystalForm::createBasisWidgets()
......
......@@ -142,11 +142,8 @@ void SampleEditorController::removeLayout(LayerForm* layerItemWidget, ParticleLa
void SampleEditorController::addParticle(ParticleLayoutItem* layoutItem,
FormFactorItemCatalog::Type formFactorType)
{
auto* newParticle = new ParticleItem();
auto* newParticle = createAndInitParticle(formFactorType);
layoutItem->addParticle(newParticle);
newParticle->setMaterialModel(materialModel());
newParticle->setFormFactor(FormFactorItemCatalog::create(formFactorType));
newParticle->setMaterial(materialModel()->defaultMaterial());
emit modified();
......@@ -158,20 +155,12 @@ void SampleEditorController::addParticle(ParticleLayoutItem* layoutItem,
m_multiLayerForm->updateUnits();
}
void SampleEditorController::addParticle(ParticleLayoutItem* layoutItem,
ItemWithParticlesCatalog::Type type)
{
auto* newItem = ItemWithParticlesCatalog::create(type);
auto* newItem = createAndInitParticle(type);
layoutItem->addParticle(newItem);
if (auto* cs = dynamic_cast<ParticleCoreShellItem*>(newItem)) {
cs->createCore(materialModel());
cs->createShell(materialModel());
cs->core()->setFormFactor(new CylinderItem());
cs->shell()->setFormFactor(new CylinderItem());
}
emit modified();
// search for particle layout widget for notification
......@@ -185,19 +174,8 @@ void SampleEditorController::addParticle(ParticleLayoutItem* layoutItem,
void SampleEditorController::addParticle(ParticleCompositionItem* compositionItem,
ItemWithParticlesCatalog::Type type)
{
auto* newItem = ItemWithParticlesCatalog::create(type);
auto* newItem = createAndInitParticle(type);
compositionItem->addParticle(newItem);
if (auto* p = dynamic_cast<ItemWithMaterial*>(newItem)) {
p->setMaterialModel(materialModel());
p->setMaterial(materialModel()->defaultMaterial());
}
if (auto* cs = dynamic_cast<ParticleCoreShellItem*>(newItem)) {
cs->createCore(materialModel());
cs->createShell(materialModel());
cs->core()->setFormFactor(new CylinderItem());
cs->shell()->setFormFactor(new CylinderItem());
}
emit modified();
......@@ -212,11 +190,8 @@ void SampleEditorController::addParticle(ParticleCompositionItem* compositionIte
void SampleEditorController::addParticle(ParticleCompositionItem* compositionItem,
FormFactorItemCatalog::Type formFactorType)
{
auto* newParticle = new ParticleItem();
auto* newParticle = createAndInitParticle(formFactorType);
compositionItem->addParticle(newParticle);
newParticle->setMaterialModel(materialModel());
newParticle->setFormFactor(FormFactorItemCatalog::create(formFactorType));
newParticle->setMaterial(materialModel()->defaultMaterial());
emit modified();
......@@ -228,6 +203,42 @@ void SampleEditorController::addParticle(ParticleCompositionItem* compositionIte
m_multiLayerForm->updateUnits();
}
ItemWithParticles*
SampleEditorController::createAndInitParticle(FormFactorItemCatalog::Type formFactorType) const
{
auto* newParticle = new ParticleItem();
newParticle->setMaterialModel(materialModel());
newParticle->setFormFactor(FormFactorItemCatalog::create(formFactorType));
newParticle->setMaterial(materialModel()->defaultMaterial());
return newParticle;
}
ItemWithParticles*
SampleEditorController::createAndInitParticle(ItemWithParticlesCatalog::Type itemType) const
{
auto* newItem = ItemWithParticlesCatalog::create(itemType);
if (auto* p = dynamic_cast<ItemWithMaterial*>(newItem)) {
p->setMaterialModel(materialModel());
p->setMaterial(materialModel()->defaultMaterial());
}
if (auto* cs = dynamic_cast<ParticleCoreShellItem*>(newItem)) {
cs->createCore(materialModel());
cs->createShell(materialModel());
cs->core()->setFormFactor(new CylinderItem());
cs->shell()->setFormFactor(new CylinderItem());
}
if (auto* meso = dynamic_cast<MesoCrystalItem*>(newItem); meso && meso->basisParticle())
if (auto* p = dynamic_cast<ItemWithMaterial*>(meso->basisParticle())) {
p->setMaterialModel(materialModel());
p->setMaterial(materialModel()->defaultMaterial());
}
return newItem;
}
void SampleEditorController::setCoreFormFactor(ParticleCoreShellForm* widget,
FormFactorItemCatalog::Type type)
{
......@@ -414,7 +425,7 @@ void SampleEditorController::setMesoCrystalBasis(MesoCrystalForm* widget,
ItemWithParticlesCatalog::Type type)
{
auto* meso = widget->mesoCrystalItem();
meso->setBasis(ItemWithParticlesCatalog::create(type));
meso->setBasis(createAndInitParticle(type));
widget->createBasisWidgets();
m_multiLayerForm->updateUnits();
emit modified();
......@@ -424,10 +435,7 @@ void SampleEditorController::setMesoCrystalBasis(MesoCrystalForm* widget,
FormFactorItemCatalog::Type type)
{
auto* meso = widget->mesoCrystalItem();
auto* particle = dynamic_cast<ParticleItem*>(meso->basisParticle());
if (particle == nullptr)
particle = meso->createBasis<ParticleItem>();
particle->setFormFactor(FormFactorItemCatalog::create(type));
meso->setBasis(createAndInitParticle(type));
widget->createBasisWidgets();
m_multiLayerForm->updateUnits();
emit modified();
......
......@@ -117,6 +117,10 @@ signals:
void aboutToRemoveItem(SampleItem item);
void modified();
private:
ItemWithParticles* createAndInitParticle(FormFactorItemCatalog::Type formFactorType) const;
ItemWithParticles* createAndInitParticle(ItemWithParticlesCatalog::Type itemType) const;
private:
QUndoStack m_undoStack;
MultiLayerItem* m_multiLayerItem;
......
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