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

add missing material initializations

parent 92cc11fc
No related branches found
No related tags found
1 merge request!497Corrections and simplifications
......@@ -600,9 +600,9 @@ ParticleItem* GUIDomainSampleVisitor::CreateIParticle(SessionItem* parent,
ASSERT(coreshell);
auto* parentCoreShell = polymorphic_cast<ParticleCoreShellItem*>(parent);
if (particle == coreshell->coreParticle())
return parentCoreShell->createCore();
return parentCoreShell->createCore(m_materialModel);
if (particle == coreshell->shellParticle())
return parentCoreShell->createShell();
return parentCoreShell->createShell(m_materialModel);
ASSERT(0);
}
return m_sampleModel->insertItem<ParticleItem>(parent, -1);
......
......@@ -13,6 +13,7 @@
// ************************************************************************************************
#include "GUI/Model/Sample/ParticleCoreShellItem.h"
#include "GUI/Model/Material/MaterialModel.h"
#include "GUI/Model/Sample/ParticleItem.h"
#include "GUI/Model/Session/SessionItemUtils.h"
#include "GUI/Model/Session/SessionModel.h"
......@@ -76,9 +77,12 @@ void ParticleCoreShellItem::setCore(ParticleItem* newCore)
model()->moveItem(newCore, this, -1, T_CORE);
}
ParticleItem* ParticleCoreShellItem::createCore()
ParticleItem* ParticleCoreShellItem::createCore(MaterialModel* materials)
{
return model()->insertItem<ParticleItem>(this, -1, T_CORE);
auto* p = model()->insertItem<ParticleItem>(this, -1, T_CORE);
p->setMaterialModel(materials);
p->setMaterial(materials->defaultMaterial());
return p;
}
bool ParticleCoreShellItem::isCoreTagName(const QString& name)
......@@ -102,9 +106,12 @@ void ParticleCoreShellItem::setShell(ParticleItem* newShell)
model()->moveItem(newShell, this, -1, T_SHELL);
}
ParticleItem* ParticleCoreShellItem::createShell()
ParticleItem* ParticleCoreShellItem::createShell(MaterialModel* materials)
{
return model()->insertItem<ParticleItem>(this, -1, T_SHELL);
auto* p = model()->insertItem<ParticleItem>(this, -1, T_SHELL);
p->setMaterialModel(materials);
p->setMaterial(materials->defaultMaterial());
return p;
}
bool ParticleCoreShellItem::isShellTagName(const QString& name)
......
......@@ -20,6 +20,7 @@
class ParticleCoreShell;
class ParticleItem;
class VectorItem;
class MaterialModel;
class BA_CORE_API_ ParticleCoreShellItem : public ItemWithParticles {
private:
......@@ -35,12 +36,12 @@ public:
ParticleItem* core() const;
void setCore(ParticleItem* core);
ParticleItem* createCore();
ParticleItem* createCore(MaterialModel* materials);
static bool isCoreTagName(const QString& name);
ParticleItem* shell() const;
void setShell(ParticleItem* newShell);
ParticleItem* createShell();
ParticleItem* createShell(MaterialModel* materials);
static bool isShellTagName(const QString& name);
};
......
......@@ -138,8 +138,8 @@ void SampleEditorController::addParticle(ParticleLayoutItem* layoutItem, const Q
newItem = layoutItem->model()->insertNewItem(classname, layoutItem);
if (auto* cs = dynamic_cast<ParticleCoreShellItem*>(newItem)) {
cs->createCore();
cs->createShell();
cs->createCore(materialModel());
cs->createShell(materialModel());
}
// search for particle layout widget for notification
......@@ -160,12 +160,17 @@ void SampleEditorController::addParticle(ParticleCompositionItem* compositionIte
new_particle->setFormFactor(classname);
new_particle->setMaterial(materialModel()->defaultMaterial());
newItem = new_particle;
} else
} else {
newItem = compositionItem->model()->insertNewItem(classname, compositionItem);
if (auto* p = dynamic_cast<ItemWithMaterial*>(newItem)) {
p->setMaterialModel(materialModel());
p->setMaterial(materialModel()->defaultMaterial());
}
}
if (auto* cs = dynamic_cast<ParticleCoreShellItem*>(newItem)) {
cs->createCore();
cs->createShell();
cs->createCore(materialModel());
cs->createShell(materialModel());
}
// search for composition widget for notification
......@@ -187,7 +192,7 @@ void SampleEditorController::setCoreFormFactor(ParticleCoreShellForm* widget,
}
if (particleCoreShell->core() == nullptr)
particleCoreShell->createCore();
particleCoreShell->createCore(materialModel());
particleCoreShell->core()->setFormFactor(formFactorModelType);
widget->createCoreWidgets();
......@@ -205,7 +210,7 @@ void SampleEditorController::setShellFormFactor(ParticleCoreShellForm* widget,
}
if (particleCoreShell->shell() == nullptr)
particleCoreShell->createShell();
particleCoreShell->createShell(materialModel());
particleCoreShell->shell()->setFormFactor(formFactorModelType);
widget->createShellWidgets();
......
#include "GUI/Model/Material/MaterialModel.h"
#include "GUI/Model/Sample/ParticleCompositionItem.h"
#include "GUI/Model/Sample/ParticleCoreShellItem.h"
#include "GUI/Model/Sample/ParticleItem.h"
......@@ -51,6 +52,8 @@ TEST_F(TestParticleCoreShell, moveCoreAndShell)
TEST_F(TestParticleCoreShell, propertyAppearance)
{
SampleModel model;
MaterialModel materials;
materials.addRefractiveMaterial("Default", 1e-3, 1e-5);
// empty coreshell particle
auto* coreshell = model.insertItem<ParticleCoreShellItem>();
......@@ -63,7 +66,7 @@ TEST_F(TestParticleCoreShell, propertyAppearance)
EXPECT_EQ(pos.z(), 0.0);
// adding core, and checking that abundance is disabled
auto* core = coreshell->createCore();
auto* core = coreshell->createCore(&materials);
EXPECT_FALSE(core->abundanceItem()->isEnabled());
EXPECT_TRUE(core->positionItem()->isEnabled());
......
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