File: RoughnessForm.cpp

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (91 lines) | stat: -rw-r--r-- 3,058 bytes parent folder | download | duplicates (2)
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
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/View/Sample/RoughnessForm.cpp
//! @brief     Implements class RoughnessForm.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2024
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#include "GUI/View/Sample/RoughnessForm.h"
#include "GUI/Model/Sample/RoughnessCatalog.h"
#include "GUI/Model/Sample/RoughnessItems.h"
#include "GUI/View/Sample/HeinzFormLayout.h"
#include <QLabel>

RoughnessForm::RoughnessForm(QWidget* parent,
                             PolyPtr<RoughnessItem, RoughnessCatalog>& roughnessSelection,
                             bool& expandRoughness, SampleEditorController* ec)
    : CollapsibleGroupBox(parent, expandRoughness)
    , m_cb(new QComboBox(this))
    , m_rs(roughnessSelection)
{
    m_layout = new HeinzFormLayout(ec);
    body()->setLayout(m_layout);

    WheelEventEater::install(m_cb);
    m_cb->addItems(m_rs.menuEntries());
    m_cb->setCurrentIndex(m_rs.certainIndex());
    m_cb->setMaxVisibleItems(m_cb->count());
    m_cb->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    m_layout->addBoldRow("Type:", m_cb);

    createRoughnessWidgets();
    updateTitle();

    connect(m_cb, &QComboBox::currentIndexChanged, [this](int newIndex) {
        m_rs.setCertainIndex(newIndex);
        onRoughnessTypeChanged();
        emit gDoc->sampleChanged();
    });
}

void RoughnessForm::updateTitle()
{
    setTitle("Roughness (" + m_cb->currentText() + ")");
}

void RoughnessForm::recreateWidgets()
{
    while (m_layout->rowCount() > 1)
        m_layout->removeRow(1);

    createRoughnessWidgets();
}

void RoughnessForm::markLayerAsSubstrate(bool is_substrate)
{
    m_is_substrate = is_substrate;
    recreateWidgets();
}

void RoughnessForm::onRoughnessTypeChanged()
{
    recreateWidgets();
    updateTitle();
}

void RoughnessForm::createRoughnessWidgets()
{
    RoughnessItem* roughness = m_rs.certainItem();

    if (auto* rsi = dynamic_cast<SelfAffineFractalRoughnessItem*>(roughness)) {
        m_layout->addGroupOfValues("Parameters", rsi->roughnessProperties());
        m_layout->addSelection(roughness->transientSelection());
        if (!m_is_substrate)
            m_layout->addSelection(roughness->crossrorrModelSelection());
    } else if (auto* rsi = dynamic_cast<LinearGrowthRoughnessItem*>(roughness)) {
        if (m_is_substrate) {
            m_layout->addRow(new QLabel(
                "The growth model cannot be used for the substrate. Please select another model."));
        } else {
            m_layout->addGroupOfValues("Parameters", rsi->roughnessProperties());
            m_layout->addSelection(roughness->transientSelection());
        }
    }
}