diff --git a/GUI/coregui/Models/SampleModel.cpp b/GUI/coregui/Models/SampleModel.cpp index 5ef128aad32e7ecbaffa2a1b6681222bd34334a4..c41644c8d19479ce5bce43c8771d3cff65fbc8c0 100644 --- a/GUI/coregui/Models/SampleModel.cpp +++ b/GUI/coregui/Models/SampleModel.cpp @@ -16,9 +16,13 @@ #include "SampleModel.h" #include "LayerItem.h" +#include "ParticleItem.h" #include "MultiLayerItem.h" #include "MaterialProperty.h" #include "MaterialSvc.h" +#include "MaterialUtils.h" +#include <QDebug> + SampleModel::SampleModel(QObject *parent) : SessionModel(SessionXML::SampleModelTag, parent) @@ -55,17 +59,17 @@ void SampleModel::exploreForMaterials(const QModelIndex &parentIndex) for (int i_row = 0; i_row < rowCount(parentIndex); ++i_row) { QModelIndex itemIndex = index(i_row, 0, parentIndex); if (SessionItem *item = itemForIndex(itemIndex)) { - if (item->modelType() == Constants::LayerType - || item->modelType() == Constants::ParticleType) { - MaterialProperty material_property = - item->getItemValue(LayerItem::P_MATERIAL).value<MaterialProperty>(); - if(!MaterialSvc::getMaterial(material_property)) { - item->setItemValue(LayerItem::P_MATERIAL, MaterialProperty().getVariant()); - } else { - // we pretend here that MaterialProperty changed to update IView colors - item->getItem(LayerItem::P_MATERIAL)->emitDataChanged(); - } + + QString materialTag = MaterialUtils::materialTag(*item); + + if(materialTag.size()) { + // TODO take care of the case, when material doesn't exist anymore and + // we should delete identifier on Layer, Particle side. + + // we pretend here that MaterialProperty changed to update IView colors + item->getItem(materialTag)->emitDataChanged(); } + } exploreForMaterials(itemIndex); } diff --git a/GUI/coregui/Models/TransformToDomain.cpp b/GUI/coregui/Models/TransformToDomain.cpp index e9413d72f7268f2c0e2718b3c5da9fdda56bccf3..00448718c21a6677fc5cc33b4e4edb8fc366e11b 100644 --- a/GUI/coregui/Models/TransformToDomain.cpp +++ b/GUI/coregui/Models/TransformToDomain.cpp @@ -64,7 +64,8 @@ std::unique_ptr<IMaterial> TransformToDomain::createDomainMaterial(const Session } if (!material_property.isDefined()) throw GUIHelpers::Error( - "TransformToDomain::createDomainMaterial() -> Error. Unknown item to create material"); + "TransformToDomain::createDomainMaterial() -> Error. Can't create material " + "for item '"+item.displayName()+"'."); return MaterialUtils::createDomainMaterial(material_property); } diff --git a/GUI/coregui/Views/MaterialEditor/MaterialUtils.cpp b/GUI/coregui/Views/MaterialEditor/MaterialUtils.cpp index c7505ea2f7a7e153bebd476103b3a12257a8ca34..5f6d702ae9d692a89149e08567b54b592a1e85dd 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialUtils.cpp +++ b/GUI/coregui/Views/MaterialEditor/MaterialUtils.cpp @@ -24,6 +24,8 @@ #include "MaterialModel.h" #include "MaterialSvc.h" #include "RefractiveIndexItem.h" +#include "ParticleItem.h" +#include "LayerItem.h" #include <QDebug> @@ -73,3 +75,16 @@ MaterialUtils::createDomainMaterial(const MaterialProperty &material_property) return materialItem->createMaterial(); } + +//! Returns material tag for given item. Returns empty string, if item doesn't have materials. + +QString MaterialUtils::materialTag(const SessionItem &item) +{ + QString result; + if (item.modelType() == Constants::ParticleType) { + result = ParticleItem::P_MATERIAL; + } else if (item.modelType() == Constants::LayerType) { + result = LayerItem::P_MATERIAL; + } + return result; +} diff --git a/GUI/coregui/Views/MaterialEditor/MaterialUtils.h b/GUI/coregui/Views/MaterialEditor/MaterialUtils.h index 0e13b36bd902f43df45bc5dd5df233cc962f148d..9c6ed4a207afcdcc383487cdaba8f8909a7186fd 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialUtils.h +++ b/GUI/coregui/Views/MaterialEditor/MaterialUtils.h @@ -34,6 +34,8 @@ BA_CORE_API_ MaterialProperty getDefaultMaterialProperty(); BA_CORE_API_ ColorProperty suggestMaterialColorProperty(const QString &name); BA_CORE_API_ std::unique_ptr<IMaterial> createDomainMaterial( const MaterialProperty &material_property); + +BA_CORE_API_ QString materialTag(const SessionItem &item); }