"git@jugit.fz-juelich.de:mlz/bornagain.git" did not exist on "fee3f7ca9cda53faf8a8fcaffd668a89420c06fe"
Newer
Older
// ************************************************************************************************
// BornAgain: simulate and fit reflection and scattering
//! @file GUI/Model/Job/ParameterTreeUtils.cpp
//! @brief Implements ParameterTreeUtils namespace
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
// ************************************************************************************************
#include "GUI/Model/Job/ParameterTreeUtils.h"
#include "GUI/Model/Fit/ParameterTreeItems.h"
#include "GUI/Model/Group/GroupItem.h"
#include "GUI/Model/Instrument/InstrumentItems.h"
#include "GUI/Model/Job/JobItem.h"
#include "GUI/Model/Material/MaterialItemContainer.h"
#include "GUI/Model/Sample/MultiLayerItem.h"
#include "GUI/Model/Session/ModelPath.h"
Pospelov, Gennady
committed
#include <QStack>
#include <boost/polymorphic_cast.hpp>
using boost::polymorphic_downcast;
Pospelov, Gennady
committed
void handleItem(ParameterContainerItem* container, SessionItem* tree, const SessionItem* source,
bool recreateBackupValues)
tree->setDisplayName(source->itemName());
else if (tree->hasModelType<ParameterItem>()) {
double sourceValue = source->value().toDouble();
tree->setValue(QVariant(sourceValue));
QString path = GUI::Model::Path::getPathFromIndex(source->index());
int firstSlash = path.indexOf('/');
path = path.mid(firstSlash + 1);
auto* parItem = polymorphic_downcast<ParameterItem*>(tree);
if (recreateBackupValues)
container->setBackupValue(parItem->link(), sourceValue);
for (SessionItem* child : source->children()) {
if (child->hasModelType<PropertyItem>()) {
auto* branch = tree->model()->insertItem<ParameterItem>(tree);
handleItem(container, branch, child, recreateBackupValues);
} else if (child->hasModelType<GroupItem>()) {
SessionItem* currentItem = dynamic_cast<GroupItem*>(child)->currentItem();
if (currentItem && currentItem->numberOfChildren() > 0) {
auto* branch = tree->model()->insertItem<ParameterLabelItem>(tree);
handleItem(container, branch, currentItem, recreateBackupValues);
auto* branch = tree->model()->insertItem<ParameterLabelItem>(tree);
handleItem(container, branch, child, recreateBackupValues);
Pospelov, Gennady
committed
//! Populates ParameterContainer with ParameterItem's corresponding to all properties found
//! in a source item.
void populateParameterContainer(ParameterContainerItem* container, const SessionItem* source,
bool recreateBackupValues)
auto* sourceLabel = container->model()->insertItem<ParameterLabelItem>(container);
handleItem(container, sourceLabel, source, recreateBackupValues);
} // namespace
void GUI::Model::ParameterTreeUtils::createParameterTree(JobItem* jobItem,
bool recreateBackupValues)
auto* container = jobItem->parameterContainerItem();
if (!container)
container = jobItem->createParameterContainerItem();
populateParameterContainer(container, jobItem->materialContainerItem(), recreateBackupValues);
populateParameterContainer(container, jobItem->sampleItem(), recreateBackupValues);
populateParameterContainer(container, jobItem->instrumentItem(), recreateBackupValues);