1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Sample/LayerForm.cpp
//! @brief Implements class LayerForm.
//!
//! @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/Sample/LayerForm.h"
#include "Base/Util/Assert.h"
#include "Base/Util/Vec.h"
#include "GUI/Model/Material/MaterialItem.h"
#include "GUI/Model/Material/MaterialsSet.h"
#include "GUI/Model/Project/ProjectDocument.h"
#include "GUI/Model/Sample/LayerItem.h"
#include "GUI/Model/Sample/RoughnessItems.h"
#include "GUI/Model/Sample/SampleItem.h"
#include "GUI/View/Numeric/NumWidgetUtil.h"
#include "GUI/View/Sample/HeinzFormLayout.h"
#include "GUI/View/Sample/MaterialInplaceForm.h"
#include "GUI/View/Sample/ParticleLayoutForm.h"
#include "GUI/View/Sample/RoughnessForm.h"
#include "GUI/View/Widget/WidgetMoverButton.h"
#include <QLineEdit>
#include <QPushButton>
LayerForm::LayerForm(QWidget* parent, LayerItem* layer, SampleEditorController* ec)
: LayerContainerForm(parent, layer, ec, "layer")
{
m_layout->addBoldRow("Material:", new MaterialInplaceForm(layer, ec));
m_layout->addValue(layer->thickness());
m_thickness_row = m_layout->rowCount() - 1;
m_layout->addBoldRow("Number of slices:", GUI::Util::createIntSpinBox(
[this] { return layerItem()->numSlices(); },
[this](int v) {
layerItem()->setNumSlices(v);
emit gDoc->sampleChanged();
},
RealLimits::lowerLimited(1),
"Number of horizontal slices.\n"
"Used for Average Layer Material calculations \n"
"when corresponding simulation option is set."));
m_roughnessForm =
new RoughnessForm(this, layer->roughnessSelection(), layer->expandRoughness, m_ec);
m_layout->addRow(m_roughnessForm);
m_roughness_row = m_layout->rowCount() - 1;
// -- layouts
for (auto* layout : layer->layoutItems())
m_layout->addRow(new ParticleLayoutForm(this, layout, ec));
// -- Button for adding a new layout
auto* btn = new QPushButton("Add particle layout", this);
connect(btn, &QPushButton::clicked, [this, ec] { ec->addLayoutItem(this); });
m_layout->addStructureEditingRow(btn);
// listen to changes in materials to update the title (contains the material name). Necessary
// to reflect e.g. a name change done in the material editor.
connect(ec->materialModel(), &MaterialsSet::materialChanged, this, &LayerForm::updateTitle);
updatePositionDependentElements();
}
LayerItem* LayerForm::layerItem() const
{
return dynamic_cast<LayerItem*>(m_item);
}
void LayerForm::updateTitle()
{
QString material_text = " Material: " + layerItem()->materialName();
if (layerItem()->isAmbient())
setTitle("Ambient" + material_text);
else if (layerItem()->isSubstrate())
setTitle("Substrate" + material_text);
else {
int i = Vec::indexOfPtr(layerItem(), m_ec->sampleItem()->uniqueLayerItems());
setTitle("Layer " + QString::number(i) + material_text);
}
}
void LayerForm::updatePositionDependentElements()
{
LayerContainerForm::updatePositionDependentElements();
if (m_roughness_row == -1)
return;
updateTitle();
const auto* sample = m_ec->sampleItem();
const bool isAmbient = layerItem()->isAmbient();
const bool isSubstrate = layerItem()->isSubstrate();
const bool thicknessIsSemiInfinite =
(isAmbient || isSubstrate) && (sample->uniqueLayerItems().size() > 1);
const bool thicknessIsInfinite = isAmbient && (sample->uniqueLayerItems().size() == 1);
m_roughnessForm->setVisible(!isAmbient);
if (m_thickness_row == -1)
return;
m_roughnessForm->markLayerAsSubstrate(isSubstrate);
QWidget* w = m_layout->itemAt(m_thickness_row, QFormLayout::FieldRole)->widget();
if (thicknessIsSemiInfinite || thicknessIsInfinite) {
auto* info = qobject_cast<QLineEdit*>(w);
if (info == nullptr) {
m_layout->removeRow(m_thickness_row);
info = new QLineEdit(this);
info->setEnabled(false);
info->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_layout->insertRow(m_thickness_row, layerItem()->thickness().label(), info);
}
info->setText(thicknessIsSemiInfinite ? "Semi-infinite" : "Infinite");
} else if (!thicknessIsSemiInfinite && !thicknessIsInfinite
&& (qobject_cast<QLineEdit*>(w) != nullptr)) {
m_layout->removeRow(m_thickness_row);
m_layout->insertValue(m_thickness_row, layerItem()->thickness());
}
}
void LayerForm::onLayoutAdded(ParticleLayoutItem* t)
{
int index = Vec::indexOfPtr(t, layerItem()->layoutItems());
const int rowInLayout = m_layout->rowCount() - layerItem()->layoutItems().size() + index;
QWidget* w = new ParticleLayoutForm(this, t, m_ec);
m_layout->insertRow(rowInLayout, w);
}
void LayerForm::onAboutToRemoveLayout(ParticleLayoutItem* t)
{
int index = Vec::indexOfPtr(t, layerItem()->layoutItems());
const int rowInLayout =
m_layout->rowCount() - layerItem()->layoutItems().size() - 1 + index; // -1: btn
m_layout->removeRow(rowInLayout);
}
|