Newer
Older
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/SampleDesigner/ParticleLayoutForm.cpp
//! @brief Implements class ParticleLayoutForm
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/View/SampleDesigner/ParticleLayoutForm.h"
#include "GUI/Model/Sample/ItemWithParticles.h"
#include "GUI/Model/Sample/ParticleLayoutItem.h"
#include "GUI/View/SampleDesigner/ActionFactory.h"
#include "GUI/View/SampleDesigner/InterferenceForm.h"
#include "GUI/View/SampleDesigner/LayerEditorUtils.h"
#include "GUI/View/SampleDesigner/LayerForm.h"
#include "GUI/View/SampleDesigner/SampleEditorController.h"
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <QAction>
#include <QPushButton>
ParticleLayoutForm::ParticleLayoutForm(LayerForm* parent, ParticleLayoutItem* layoutItem,
SampleEditorController* ec)
: QGroupBox(parent), m_layoutItem(layoutItem), m_ec(ec)
{
setTitle(m_layoutItem->itemName());
FormLayouter layouter(this, ec);
layouter.setContentsMargins(30, 6, 0, 0);
layouter.addValue(m_layoutItem->totalDensity());
layouter.addValue(m_layoutItem->weight());
layouter.addRow(new InterferenceForm(this, layoutItem, ec));
for (auto particle : m_layoutItem->particles())
layouter.addRow(LayerEditorUtils::createWidgetForItemWithParticles(this, particle, ec));
auto* btn = LayerEditorUtils::createAddParticleButton(
this, [=](const QString& cls) { ec->addParticle(layoutItem, cls); });
m_structureEditingWidgets << btn;
layouter.addStructureEditingRow(btn);
m_removeAction = ActionFactory::createRemoveAction(
this, "particle layout", [=] { ec->removeLayout(parent, layoutItem); });
auto* collapser = GroupBoxCollapser::installIntoGroupBox(this);
collapser->addAction(m_removeAction);
m_layout = layouter.layout();
}
void ParticleLayoutForm::enableStructureEditing(bool b)
{
m_removeAction->setVisible(b);
for (auto w : m_structureEditingWidgets)
w->setVisible(b);
}
ParticleLayoutItem* ParticleLayoutForm::layoutItem() const
{
return m_layoutItem;
}
void ParticleLayoutForm::onParticleAdded(SessionItem* new_item)
{
if (auto p = dynamic_cast<ItemWithParticles*>(new_item)) {
int index = m_layoutItem->particles().indexOf(p);
const int rowInLayout =
m_layout->rowCount() - 1 - (m_layoutItem->particles().size() - 1) + index; // -1: btn
m_layout->insertRow(rowInLayout,
LayerEditorUtils::createWidgetForItemWithParticles(this, p, m_ec));
}
}
void ParticleLayoutForm::onAboutToRemoveParticle(ItemWithParticles* item)
{
int index = m_layoutItem->particles().indexOf(item);
const int rowInLayout =
m_layout->rowCount() - m_layoutItem->particles().size() - 1 + index; // -1: btn
m_layout->removeRow(rowInLayout);
}