-
Matthias Puchner authored
...which held the position of an item in the GraphicsScene of the net oriented sample editor
Matthias Puchner authored...which held the position of an item in the GraphicsScene of the net oriented sample editor
ItemWithMaterial.cpp 2.83 KiB
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Sample/ItemWithMaterial.cpp
//! @brief Implements class ItemWithMaterial
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/Model/Sample/ItemWithMaterial.h"
#include "GUI/Model/Job/JobItem.h"
#include "GUI/Model/Job/JobModelFunctions.h"
#include "GUI/Model/Material/MaterialItem.h"
#include "GUI/Model/Material/MaterialItemContainer.h"
#include "GUI/Model/Material/MaterialItemUtils.h"
#include "Sample/Material/Material.h"
void ItemWithMaterial::setMaterial(const MaterialItem* materialItem)
{
setItemValue(P_MATERIAL, materialItem->identifier());
}
void ItemWithMaterial::setMaterial(const QString& materialIdentifier)
{
setItemValue(P_MATERIAL, materialIdentifier);
}
bool ItemWithMaterial::isMaterialPropertyName(const QString& name)
{
return name == P_MATERIAL;
}
void ItemWithMaterial::setMaterialUndefined()
{
setItemValue(P_MATERIAL, QString());
}
QColor ItemWithMaterial::materialColor() const
{
const auto* const parentJob = GUI::Model::JobFunctions::findJobItem(this);
if (parentJob)
return parentJob->materialContainerItem()->findMaterialById(materialIdentifier())->color();
return GUI::MaterialUtil::findMaterial(materialIdentifier())->color();
}
QString ItemWithMaterial::materialName() const
{
const auto* const parentJob = GUI::Model::JobFunctions::findJobItem(this);
if (parentJob)
return parentJob->materialContainerItem()
->findMaterialById(materialIdentifier())
->itemName();
return GUI::MaterialUtil::findMaterial(materialIdentifier())->itemName();
}
QString ItemWithMaterial::materialIdentifier() const
{
return getItemValue(P_MATERIAL).toString();
}
ItemWithMaterial::ItemWithMaterial(const QString& model_type) : SessionItem(model_type)
{
addProperty(P_MATERIAL, GUI::MaterialUtil::defaultMaterialIdentifier())
->setToolTip("Material this item is made of")
.setEditorType(SessionItem::EDITOR_TYPE_MATERIAL);
}
std::unique_ptr<Material> ItemWithMaterial::domainMaterial() const
{
const auto* parent_job = GUI::Model::JobFunctions::findJobItem(this);
const MaterialItemContainer* container =
parent_job ? parent_job->materialContainerItem() : nullptr;
return container ? GUI::MaterialUtil::createDomainMaterial(materialIdentifier(), *container)
: GUI::MaterialUtil::createDomainMaterial(materialIdentifier());
}