BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MaterialItemUtils Namespace Reference

Functions

ExternalProperty colorProperty (const QColor &color)
 Constructs color property from given color. More...
 
std::unique_ptr< MaterialcreateDomainMaterial (const ExternalProperty &material_property)
 
std::unique_ptr< MaterialcreateDomainMaterial (const ExternalProperty &material_property, const MaterialItemContainer &container)
 
ExternalProperty defaultMaterialProperty ()
 
MaterialItemfindMaterial (const ExternalProperty &material_property)
 
ExternalProperty materialProperty (const SessionItem &materialItem)
 Constructs material property corresponding to given material. More...
 
QVector< SessionItem * > materialPropertyItems (SessionItem *item)
 Gather material property items from a given item. More...
 
QStringList materialRelatedModelTypes ()
 Returns list of model types which contains registered MaterialProperty. More...
 
QString materialTag (const SessionItem &item)
 Returns material tag for given item. Returns empty string, if item doesn't have materials. More...
 
ExternalProperty selectColorProperty (const ExternalProperty &previous=ExternalProperty())
 Calls color selector dialog. More...
 
ExternalProperty selectMaterialProperty (const ExternalProperty &previous=ExternalProperty())
 Calls material selector dialog. More...
 
QColor suggestMaterialColor (const QString &name)
 

Function Documentation

◆ colorProperty()

ExternalProperty MaterialItemUtils::colorProperty ( const QColor &  color)

Constructs color property from given color.

Definition at line 142 of file MaterialItemUtils.cpp.

143 {
144  ExternalProperty result;
145  result.setColor(color);
146  result.setText(QString("[%1, %2, %3] (%4)")
147  .arg(color.red())
148  .arg(color.green())
149  .arg(color.blue())
150  .arg(color.alpha()));
151  return result;
152 }
The ExternalProperty class defines custom QVariant property to carry the text, color and an identifie...
void setColor(const QColor &color)
void setText(const QString &name)

References ExternalProperty::setColor(), and ExternalProperty::setText().

Referenced by MaterialItem::MaterialItem(), MaterialModel::createMaterial(), materialProperty(), and selectColorProperty().

Here is the call graph for this function:

◆ createDomainMaterial() [1/2]

std::unique_ptr< Material > MaterialItemUtils::createDomainMaterial ( const ExternalProperty material_property)

Definition at line 74 of file MaterialItemUtils.cpp.

75 {
76  MaterialItem* materialItem = findMaterial(material_property);
77  return materialItem->createMaterial();
78 }
std::unique_ptr< Material > createMaterial() const
MaterialItem * findMaterial(const ExternalProperty &material_property)

References MaterialItem::createMaterial(), and findMaterial().

Referenced by TransformToDomain::createDomainMaterial().

Here is the call graph for this function:

◆ createDomainMaterial() [2/2]

std::unique_ptr< Material > MaterialItemUtils::createDomainMaterial ( const ExternalProperty material_property,
const MaterialItemContainer container 
)

Definition at line 81 of file MaterialItemUtils.cpp.

83 {
84  const MaterialItem* material_item = container.findMaterialById(material_property.identifier());
85  if (!material_item)
86  throw GUIHelpers::Error("MaterialUtils::createDomainMaterial() -> Error. Can't find "
87  "material with name '"
88  + material_property.text() + "'.");
89  return material_item->createMaterial();
90 }
QString identifier() const
QString text() const
const MaterialItem * findMaterialById(QString id) const

References MaterialItem::createMaterial(), MaterialItemContainer::findMaterialById(), ExternalProperty::identifier(), and ExternalProperty::text().

Here is the call graph for this function:

◆ defaultMaterialProperty()

ExternalProperty MaterialItemUtils::defaultMaterialProperty ( )

Definition at line 63 of file MaterialItemUtils.cpp.

64 {
65  if (!AppSvc::materialModel())
66  return ExternalProperty();
67 
68  auto materials = AppSvc::materialModel()->topItems();
69  return materials.isEmpty() ? ExternalProperty()
70  : MaterialItemUtils::materialProperty(*materials.front());
71 }
static MaterialModel * materialModel()
Definition: AppSvc.cpp:33
QVector< T * > topItems() const
Definition: SessionModel.h:147
ExternalProperty materialProperty(const SessionItem &materialItem)
Constructs material property corresponding to given material.

References AppSvc::materialModel(), materialProperty(), and SessionModel::topItems().

Referenced by LayerItem::LayerItem(), and ParticleItem::ParticleItem().

Here is the call graph for this function:

◆ findMaterial()

MaterialItem * MaterialItemUtils::findMaterial ( const ExternalProperty material_property)

Definition at line 92 of file MaterialItemUtils.cpp.

93 {
94  if (!AppSvc::materialModel())
95  throw GUIHelpers::Error("MaterialItemUtils::findMaterial() -> Error. "
96  "Attempt to access non-existing material model");
97 
98  auto material = AppSvc::materialModel()->materialFromIdentifier(material_property.identifier());
99 
100  if (!material)
101  throw GUIHelpers::Error("MaterialUtils::findMaterial() -> Error. Can't find "
102  "material with name '"
103  + material_property.text() + "'.");
104  return material;
105 }
MaterialItem * materialFromIdentifier(const QString &identifier)

References ExternalProperty::identifier(), MaterialModel::materialFromIdentifier(), AppSvc::materialModel(), and ExternalProperty::text().

Referenced by createDomainMaterial(), and JobModelFunctions::setupJobItemSampleData().

Here is the call graph for this function:

◆ materialProperty()

ExternalProperty MaterialItemUtils::materialProperty ( const SessionItem materialItem)

Constructs material property corresponding to given material.

Constructs material property for given material.

Definition at line 129 of file MaterialItemUtils.cpp.

130 {
131  ExternalProperty result;
132 
134  materialItem.getItemValue(MaterialItem::P_COLOR).value<ExternalProperty>();
135  result.setIdentifier(materialItem.getItemValue(MaterialItem::P_IDENTIFIER).toString());
136  result.setColor(colorProperty.color());
137  result.setText(materialItem.itemName());
138 
139  return result;
140 }
void setIdentifier(const QString &identifier)
QColor color() const
static const QString P_IDENTIFIER
Definition: MaterialItem.h:27
static const QString P_COLOR
Definition: MaterialItem.h:24
QString itemName() const
Get item name, return display name if no name is set.
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
ExternalProperty colorProperty(const QColor &color)
Constructs color property from given color.

References ExternalProperty::color(), colorProperty(), SessionItem::getItemValue(), SessionItem::itemName(), MaterialItem::P_COLOR, MaterialItem::P_IDENTIFIER, ExternalProperty::setColor(), ExternalProperty::setIdentifier(), and ExternalProperty::setText().

Referenced by GUIDomainSampleVisitor::createMaterialFromDomain(), defaultMaterialProperty(), ExternalPropertyEditor::initEditor(), MaterialPropertyController::onMaterialDataChanged(), MaterialPropertyController::onMaterialModelLoad(), and MaterialEditorDialog::selectedMaterialProperty().

Here is the call graph for this function:

◆ materialPropertyItems()

QVector< SessionItem * > MaterialItemUtils::materialPropertyItems ( SessionItem item)

Gather material property items from a given item.

Definition at line 185 of file MaterialItemUtils.cpp.

186 {
187  static const std::map<QString, QString> tag_map = get_tag_map();
188  QVector<SessionItem*> materials;
189  QList<SessionItem*> particle_holders{item};
190  while (!particle_holders.isEmpty()) {
191  auto item = particle_holders.takeFirst();
192  if (!item)
193  continue;
194 
195  const QString model_type = item->modelType();
196  auto iter = tag_map.find(model_type);
197  if (iter != tag_map.end()) {
198  particle_holders.append(QList<SessionItem*>::fromVector(item->getItems(iter->second)));
199  continue;
200  }
201 
202  if (model_type == "Particle")
203  materials.append(static_cast<ParticleItem*>(item)->materialPropertyItems());
204  else if (model_type == "ParticleCoreShell")
205  materials.append(static_cast<ParticleCoreShellItem*>(item)->materialPropertyItems());
206  else
207  throw GUIHelpers::Error(
208  "Error in MaterialItemUtils::materialProperties: cannot handle passed model type '"
209  + model_type + "'");
210  }
211  return materials;
212 }
QVector< SessionItem * > getItems(const QString &tag="") const
Returns vector of all items of given tag.
QString modelType() const
Get model type.
QVector< SessionItem * > materialPropertyItems(SessionItem *item)
Gather material property items from a given item.
std::string model_type
Definition: types.h:23

References SessionItem::getItems(), and SessionItem::modelType().

Referenced by LayerItem::materialPropertyItems().

Here is the call graph for this function:

◆ materialRelatedModelTypes()

QStringList MaterialItemUtils::materialRelatedModelTypes ( )

Returns list of model types which contains registered MaterialProperty.

Definition at line 122 of file MaterialItemUtils.cpp.

123 {
124  return {"Particle", "Layer"};
125 }

Referenced by MaterialPropertyController::relatedSampleItems().

◆ materialTag()

QString MaterialItemUtils::materialTag ( const SessionItem item)

Returns material tag for given item. Returns empty string, if item doesn't have materials.

Definition at line 109 of file MaterialItemUtils.cpp.

110 {
111  QString result;
112  if (item.modelType() == "Particle") {
113  result = ParticleItem::P_MATERIAL;
114  } else if (item.modelType() == "Layer") {
115  result = LayerItem::P_MATERIAL;
116  }
117  return result;
118 }
static const QString P_MATERIAL
Definition: LayerItem.h:24
static const QString P_MATERIAL
Definition: ParticleItem.h:27

References SessionItem::modelType(), LayerItem::P_MATERIAL, and ParticleItem::P_MATERIAL.

Referenced by TransformToDomain::createDomainMaterial(), MaterialPropertyController::onMaterialDataChanged(), MaterialPropertyController::onMaterialModelLoad(), and MaterialPropertyController::onMaterialRowsAboutToBeRemoved().

Here is the call graph for this function:

◆ selectColorProperty()

ExternalProperty MaterialItemUtils::selectColorProperty ( const ExternalProperty previous = ExternalProperty())

Calls color selector dialog.

Definition at line 165 of file MaterialItemUtils.cpp.

166 {
167  ExternalProperty result;
168 
169 #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
170  auto oldColor = previous.color();
171  auto newColor = QColorDialog::getColor(oldColor);
172  if (oldColor != newColor)
173  result = MaterialItemUtils::colorProperty(newColor);
174 #else
175  bool ok = false;
176  QRgb oldRgba = previous.color().rgba();
177  QRgb newRgba = QColorDialog::getRgba(oldRgba, &ok, nullptr);
178  if (ok && newRgba != oldRgba)
179  result = MaterialItemUtils::colorProperty(QColor::fromRgba(newRgba));
180 #endif
181 
182  return result;
183 }

References ExternalProperty::color(), and colorProperty().

Referenced by ExternalPropertyEditor::buttonClicked().

Here is the call graph for this function:

◆ selectMaterialProperty()

ExternalProperty MaterialItemUtils::selectMaterialProperty ( const ExternalProperty previous = ExternalProperty())

Calls material selector dialog.

Definition at line 154 of file MaterialItemUtils.cpp.

155 {
157  dialog.setMaterialProperty(previous);
158  if (dialog.exec() == QDialog::Accepted) {
159  return dialog.selectedMaterialProperty();
160  }
161 
162  return ExternalProperty();
163 }
static MainWindow * instance()
Returns the one and only instance of this class.
Definition: mainwindow.cpp:129
Dialog to hold MaterialEditor.

References MainWindow::instance(), AppSvc::materialModel(), MaterialEditorDialog::selectedMaterialProperty(), and MaterialEditorDialog::setMaterialProperty().

Referenced by ExternalPropertyEditor::buttonClicked(), and SampleToolBar::onMaterialEditorCall().

Here is the call graph for this function:

◆ suggestMaterialColor()

QColor MaterialItemUtils::suggestMaterialColor ( const QString &  name)

Definition at line 48 of file MaterialItemUtils.cpp.

49 {
50  if (name.contains("Vacuum")) {
51  return QColor(179, 242, 255);
52  } else if (name.contains("Substrate")) {
53  return QColor(205, 102, 0);
54  } else if (name.contains("Default")) {
55  return QColor(Qt::green);
56  } else if (name.contains("Particle")) {
57  return QColor(146, 198, 255);
58  } else {
60  }
61 }
static QColor getRandomColor()
QString const & name(EShape k)
Definition: particles.cpp:21

References DesignerHelper::getRandomColor(), and RealSpace::Particles::name().

Referenced by MaterialModel::createMaterial(), and gui2::MaterialModel::init_model().

Here is the call graph for this function: