BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ParticleCoreShellForm.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/SampleDesigner/ParticleCoreShellForm.cpp
6 //! @brief Implements class ParticleCoreShellForm
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 
21 #include "GUI/Util/ActionFactory.h"
26 #include <QAction>
27 #include <QComboBox>
28 #include <memory>
29 
30 namespace {
31 
32 QComboBox* createFormFactorCombo(QWidget* parent, FormFactorItem* current)
33 {
34  ASSERT(current);
35  auto* combo = new QComboBox(parent);
37  combo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
38 
39  for (const auto type : FormFactorItemCatalog::types()) {
40  const auto ui = FormFactorItemCatalog::uiInfo(type);
41  combo->addItem(QIcon(ui.iconPath), ui.menuEntry, (uint8_t)type);
42  }
43  combo->setMaxVisibleItems(combo->count());
44  combo->setCurrentIndex(combo->findData((uint8_t)FormFactorItemCatalog::type(current)));
45 
46  return combo;
47 }
48 
49 } // namespace
50 
51 
53  SampleEditorController* ec, bool allowRemove)
54  : QGroupBox(parent)
55  , m_item(item)
56  , m_ec(ec)
57 {
58  setTitle("Sim/shell particle");
59  FormLayouter layouter(this, ec);
60  layouter.setContentsMargins(30, 6, 0, 0);
61  layouter.addVector(item->positionVector(), false);
62  layouter.addSelection(item->rotation());
63  layouter.addValue(item->abundance());
64 
65  // - core
66  {
67  auto* coreParticleGroup = new QGroupBox(this);
68  coreParticleGroup->setObjectName("Particle");
69 
70  core.layouter = std::make_unique<FormLayouter>(coreParticleGroup, ec);
71 
72  core.formfactorCombo = createFormFactorCombo(
73  coreParticleGroup,
74  item->core() != nullptr ? item->core()->formfactor_at_bottom() : nullptr);
75  connect(core.formfactorCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
77  core.layouter->addRow("Form factor:", core.formfactorCombo);
79 
80  auto* showInRealSpaceAction =
81  ActionFactory::createShowInRealSpaceAction(this, "core particle");
82  connect(showInRealSpaceAction, &QAction::triggered, this,
84  core.collapser->addAction(showInRealSpaceAction);
85 
87 
88  layouter.addRow(coreParticleGroup);
89  }
90 
91  // - shell
92  {
93  auto* shellParticleGroup = new QGroupBox(this);
94  shellParticleGroup->setObjectName("Particle");
95  shell.layouter = std::make_unique<FormLayouter>(shellParticleGroup, ec);
96  shell.formfactorCombo = createFormFactorCombo(
97  shellParticleGroup,
98  item->shell() != nullptr ? item->shell()->formfactor_at_bottom() : nullptr);
99  connect(shell.formfactorCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
101  shell.layouter->addRow("Form factor:", shell.formfactorCombo);
103 
104  auto* showInRealSpaceAction =
105  ActionFactory::createShowInRealSpaceAction(this, "shell particle");
106  connect(showInRealSpaceAction, &QAction::triggered, this,
108  shell.collapser->addAction(showInRealSpaceAction);
109 
111 
112  layouter.addRow(shellParticleGroup);
113  }
114 
115  auto* mainCollapser = GroupBoxCollapser::installIntoGroupBox(this);
116 
117  auto* showInRealSpaceAction = ActionFactory::createShowInRealSpaceAction(
118  this, "core/shell particle", [=] { ec->requestViewInRealSpace(item); });
119 
120  mainCollapser->addAction(showInRealSpaceAction);
121 
122  if (allowRemove) {
123  m_removeAction = ActionFactory::createRemoveAction(this, "core/shell particle",
124  [=] { ec->removeParticle(item); });
125  mainCollapser->addAction(m_removeAction);
126  }
127 }
128 
130 {
131  while (core.layouter->layout()->rowCount() > 1)
132  core.layouter->layout()->removeRow(1);
133 
134  const auto type = (FormFactorItemCatalog::Type)core.formfactorCombo->currentData().toUInt();
135  m_ec->setCoreFormFactor(this, type);
136 }
137 
139 {
140  while (shell.layouter->layout()->rowCount() > 1)
141  shell.layouter->layout()->removeRow(1);
142 
143  const auto type = (FormFactorItemCatalog::Type)shell.formfactorCombo->currentData().toUInt();
144  m_ec->setShellFormFactor(this, type);
145 }
146 
148 {
149  if (m_item->core())
151 }
152 
154 {
155  if (m_item->shell())
157 }
158 
160 {
161  QString groupTitle = "Core";
162 
163  if (ParticleItem* particle = m_item->core()) {
164  const QString formfactor =
165  FormFactorItemCatalog::menuEntry(particle->formfactor_at_bottom());
166  groupTitle += " (" + formfactor + ")";
167 
168  core.layouter->addGroupOfValues("Geometry",
169  particle->formfactor_at_bottom()->geometryValues());
170  core.layouter->addVector(particle->positionVector(), false);
171  core.layouter->addSelection(particle->rotation());
172  // no abundance since this is handled in CoreShell itself!
173  }
174 
175  core.collapser->setTitle(groupTitle);
176 }
177 
179 {
180  QString groupTitle = "Shell";
181 
182  if (ParticleItem* particle = m_item->shell()) {
183  const QString formfactor =
184  FormFactorItemCatalog::menuEntry(particle->formfactor_at_bottom());
185  groupTitle += " (" + formfactor + ")";
186 
187  shell.layouter->addGroupOfValues("Geometry",
188  particle->formfactor_at_bottom()->geometryValues());
189  shell.layouter->addSelection(particle->rotation());
190  // no position vector - not allowed in CoreShell
191  // no abundance since this is handled in CoreShell itself!
192  }
193 
194  shell.collapser->setTitle(groupTitle);
195 }
196 
198 {
199  if (m_removeAction)
200  m_removeAction->setVisible(b);
201 }
202 
204 {
205  return m_item;
206 }
Defines class ActionFactory.
Defines class FormFactorItemCatalog.
Defines FormFactorItems classes.
Defines classes FormLayouter.
Defines class GroupBoxCollapser.
Defines class ParticleCoreShellForm.
Defines class ParticleCoreShellItem.
Defines class ParticleItem.
Defines class SampleEditorController.
Defines class SelectionContainerForm.
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 QString menuEntry(const FormFactorItem *item)
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
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
void addAction(QAction *action)
Add a tool button to the title bar, connected to the given action.
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
void setTitle(const QString &title)
Set the title of the group box. Do not use the method groupBox->setTitle() any more once the add-on i...
DoubleDescriptor abundance() const
SelectionDescriptor< RotationItem * > rotation()
Returns selection descriptor for rotation methods.
VectorDescriptor positionVector() const
SampleEditorController * m_ec
ParticleCoreShellItem * coreShellItem() const
ParticleCoreShellItem * m_item
ParticleCoreShellForm(QWidget *parent, ParticleCoreShellItem *item, SampleEditorController *ec, bool allowRemove=true)
ParticleItem * shell() const
ParticleItem * core() const
FormFactorItem * formfactor_at_bottom() const
Class to modify a sample from the layer oriented sample editor.
void setCoreFormFactor(ParticleCoreShellForm *widget, FormFactorItemCatalog::Type type)
void requestViewInRealSpace(SampleItem item)
void setShellFormFactor(ParticleCoreShellForm *widget, FormFactorItemCatalog::Type type)
void removeParticle(ItemWithParticles *item)
static void install(QObject *obj)
std::unique_ptr< FormLayouter > layouter