BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MesoCrystalForm.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/SampleDesigner/MesoCrystalForm.cpp
6 //! @brief Implements class MesoCrystalForm
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
20 #include "GUI/Util/ActionFactory.h"
23 
24 #include <QAction>
25 
27  bool allowRemove)
28  : QGroupBox(parent)
29  , m_item(item)
30  , m_ec(ec)
31 {
32  setTitle("Meso crystal");
33  setObjectName("MesoCrystal");
34  FormLayouter layouter(this, ec);
35  m_layout = layouter.layout();
36  layouter.setContentsMargins(30, 6, 0, 0);
37  layouter.addVector(item->positionVector(), false);
38  layouter.addSelection(item->rotation());
39  layouter.addValue(item->abundance());
40  layouter.addVector(item->vectorA(), false);
41  layouter.addVector(item->vectorB(), false);
42  layouter.addVector(item->vectorC(), false);
43 
44  layouter.addSelection(item->outerShape());
45 
47  connect(m_basisCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
49  m_rowOfBasisTypeCombo = layouter.addRow("Basis type", m_basisCombo);
51 
52  auto* collapser = GroupBoxCollapser::installIntoGroupBox(this);
53 
54  auto* showInRealSpaceAction = ActionFactory::createShowInRealSpaceAction(
55  this, "meso crystal", [=] { ec->requestViewInRealSpace(item); });
56  collapser->addAction(showInRealSpaceAction);
57 
58  if (allowRemove) {
60  [=] { ec->removeParticle(item); });
61  collapser->addAction(m_removeAction);
62  }
63 }
64 
65 QComboBox* MesoCrystalForm::createBasisCombo(QWidget* parent, ItemWithParticles* current)
66 {
67  auto* combo = new QComboBox(parent);
69  combo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
70 
71  uint32_t currentData = 0;
72  for (auto type : FormFactorItemCatalog::types()) {
73  const auto ui = FormFactorItemCatalog::uiInfo(type);
74  combo->addItem(QIcon(ui.iconPath), ui.menuEntry, static_cast<uint32_t>(type));
75  if (auto* p = dynamic_cast<ParticleItem*>(current))
76  if (FormFactorItemCatalog::type(p->formfactor_at_bottom()) == type)
77  currentData = static_cast<uint32_t>(type);
78  }
79  for (auto type : ItemWithParticlesCatalog::assemblyTypes()) {
80  const auto ui = ItemWithParticlesCatalog::uiInfo(type);
81  combo->addItem(QIcon(ui.iconPath), ui.menuEntry, 1000 + static_cast<uint32_t>(type));
82  if (ItemWithParticlesCatalog::type(current) == type)
83  currentData = 1000 + static_cast<uint32_t>(type);
84  }
85 
86  combo->setMaxVisibleItems(combo->count());
87 
88  const auto currentIndex = combo->findData(currentData);
89  ASSERT(currentIndex >= 0);
90  combo->setCurrentIndex(currentIndex);
91 
92  return combo;
93 }
94 
96 {
97  while (m_layout->rowCount() > m_rowOfBasisTypeCombo + 1)
98  m_layout->removeRow(m_rowOfBasisTypeCombo + 1);
99 
100  const auto currentData = m_basisCombo->currentData().toUInt();
101  if (currentData < 1000)
102  m_ec->setMesoCrystalBasis(this, static_cast<FormFactorItemCatalog::Type>(currentData));
103  else
105  static_cast<ItemWithParticlesCatalog::Type>(currentData - 1000));
106 }
107 
109 {
110  if (!m_item->basisParticle())
111  return;
112 
114  this, m_item->basisParticle(), false, m_ec, false));
115 }
116 
118 {
119  if (m_removeAction)
120  m_removeAction->setVisible(b);
121 }
122 
124 {
125  return m_item;
126 }
Defines class ActionFactory.
Defines FormFactorItems classes.
Defines classes FormLayouter.
Defines class GroupBoxCollapser.
Defines class MesoCrystalForm.
Defines class MesoCrystalItem.
Defines class ParticleItem.
Defines class VectorDescriptor.
static QAction * createShowInRealSpaceAction(QObject *parent, const QString &what, std::function< void()> slot=nullptr)
Create "show in RealSpace" action.
static QAction * createRemoveAction(QObject *parent, const QString &what, std::function< void()> slot=nullptr)
Create "remove" action.
static QVector< Type > types()
Available types of interference items.
static UiInfo uiInfo(Type t)
UiInfo on the given type.
static Type type(const FormFactorItem *item)
Returns the enum type of the given item.
Utility class to populate a QFormLayout.
Definition: FormLayouter.h:36
QFormLayout * layout()
The layout where this layouter is operating on.
int addRow(QWidget *w)
Convenience method to add a widget.
int addValue(const DoubleDescriptor &d)
Adds a row with a bold printed label and a DoubleSpinBox.
int addVector(const VectorDescriptor &d, bool vertically=true)
Adds a row with a bold printed label and the 3 values of a 3D vector.
void setContentsMargins(int left, int top, int right, int bottom)
Convenience method to set the contents margins.
int addSelection(const SelectionDescriptor< T > &d)
Add a row with a selection.
Definition: FormLayouter.h:170
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
static Type type(const ItemWithParticles *item)
Returns the enum type of the given item.
static QVector< Type > assemblyTypes()
Available types of assembly items, sorted as expected in the UI (e.g. in combo box)
static UiInfo uiInfo(Type t)
UiInfo on the given type.
DoubleDescriptor abundance() const
SelectionDescriptor< RotationItem * > rotation()
Returns selection descriptor for rotation methods.
VectorDescriptor positionVector() const
QComboBox * m_basisCombo
MesoCrystalItem * m_item
MesoCrystalItem * mesoCrystalItem() const
MesoCrystalForm(QWidget *parent, MesoCrystalItem *item, SampleEditorController *ec, bool allowRemove=true)
QComboBox * createBasisCombo(QWidget *parent, ItemWithParticles *current)
QFormLayout * m_layout
SampleEditorController * m_ec
QAction * m_removeAction
void enableStructureEditing(bool b)
VectorDescriptor vectorB() const
VectorDescriptor vectorC() const
VectorDescriptor vectorA() const
SelectionDescriptor< FormFactorItem * > outerShape() const
ItemWithParticles * basisParticle() const
Class to modify a sample from the layer oriented sample editor.
void setMesoCrystalBasis(MesoCrystalForm *widget, ItemWithParticlesCatalog::Type type)
void requestViewInRealSpace(SampleItem item)
void removeParticle(ItemWithParticles *item)
static void install(QObject *obj)
QWidget * createWidgetForItemWithParticles(QWidget *parentWidget, ItemWithParticles *itemWithParticles, bool allowAbundance, SampleEditorController *ec, bool allowRemove=true)