//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/View/Sample/SelectionContainerForm.cpp
//! @brief     Implements class SelectionContainerForm, except for templated functions.
//!
//! @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/SelectionContainerForm.h"
#include "GUI/Model/Sample/FormFactorItems.h"
#include "GUI/Model/Sample/ProfileItems.h"
#include "GUI/Model/Sample/RotationItems.h"
#include "GUI/Model/Sample/RoughnessItems.h"
#include "GUI/View/Base/LayoutUtil.h"

ISelectionContainerForm::ISelectionContainerForm(QWidget* parent, SampleEditorController* ec)
    : QWidget(parent)
    , m_ec(ec)
{
}

void ISelectionContainerForm::clear()
{
    auto* layoutItemOfComboBox = m_grid_layout->itemAtPosition(1, 0);
    m_grid_layout->takeAt(m_grid_layout->indexOf(layoutItemOfComboBox));
    GUI::Util::Layout::clearLayout(m_grid_layout, true);
    m_grid_layout->addWidget(layoutItemOfComboBox->widget(), 1, 0);
}

void SelectionContainerForm::createContent()
{
    if (currentValues != nullptr)
        GUI::Util::Layer::addMultiPropertyToGrid(m_grid_layout, 1, currentValues(), m_ec, true);
}

DoubleProperties SelectionContainerForm::doublePropertiesOfItem(RotationItem* item)
{
    if (!item)
        return {};
    return item->rotationProperties();
}

DoubleProperties SelectionContainerForm::doublePropertiesOfItem(Profile2DItem* item)
{
    if (!item)
        return {};
    return item->profileProperties();
}

DoubleProperties SelectionContainerForm::doublePropertiesOfItem(Profile1DItem* item)
{
    if (!item)
        return {};
    return item->profileProperties();
}

DoubleProperties SelectionContainerForm::doublePropertiesOfItem(FormFactorItem* item)
{
    if (!item)
        return {};
    return item->geometryProperties();
}

DoubleProperties SelectionContainerForm::doublePropertiesOfItem(RoughnessItem* item)
{
    if (!item)
        return {};
    return item->roughnessProperties();
}
