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

add missing material initializations

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