Skip to content
Snippets Groups Projects
  • Wuttke, Joachim's avatar
    2a33f913
    Initialize item and item parameter tags in header files. · 2a33f913
    Wuttke, Joachim authored
    import edtools as et
    import re
    
    def user_edit_pair(fname_stem, th, tc):
    
        data = []
        mm = re.finditer('const QString (\w+)::([MPT]_[A-Z0-9_]+) = "(.+?)";', tc)
        for m in mm:
            data.append([m.group(1), m.group(2), m.group(3)])
        mm = re.finditer('const QString (\w+)::([MPT]_[A-Z0-9_]+)\("(.+?)"\);', tc)
        for m in mm:
            data.append([m.group(1), m.group(2), m.group(3)])
    
        for cname, typ, label in data:
            rlabel = re.sub(r'\[', r'\\[', label)
            rlabel = re.sub(r'\]', r'\\]', rlabel)
            rlabel = re.sub(r'\(', r'\\(', rlabel)
            rlabel = re.sub(r'\)', r'\\)', rlabel)
            tc = re.sub('\n+const QString '+cname+'::'+typ+' =\s+"'+rlabel+'";', '', tc)
            tc = re.sub('\n+const QString '+cname+'::'+typ+'\("'+rlabel+'"\);', '', tc)
            th = re.sub(r'class( BA_CORE_API_)? ('+cname+r'.+?)static const QString '+typ+r';(.*?\n};)',
                        r'class \2static constexpr auto '+typ+r'{"'+label+r'"};\3', th, 0, re.S)
    
        return th, tc
    
    et.ed_argfilepairs(user_edit_pair)
    2a33f913
    History
    Initialize item and item parameter tags in header files.
    Wuttke, Joachim authored
    import edtools as et
    import re
    
    def user_edit_pair(fname_stem, th, tc):
    
        data = []
        mm = re.finditer('const QString (\w+)::([MPT]_[A-Z0-9_]+) = "(.+?)";', tc)
        for m in mm:
            data.append([m.group(1), m.group(2), m.group(3)])
        mm = re.finditer('const QString (\w+)::([MPT]_[A-Z0-9_]+)\("(.+?)"\);', tc)
        for m in mm:
            data.append([m.group(1), m.group(2), m.group(3)])
    
        for cname, typ, label in data:
            rlabel = re.sub(r'\[', r'\\[', label)
            rlabel = re.sub(r'\]', r'\\]', rlabel)
            rlabel = re.sub(r'\(', r'\\(', rlabel)
            rlabel = re.sub(r'\)', r'\\)', rlabel)
            tc = re.sub('\n+const QString '+cname+'::'+typ+' =\s+"'+rlabel+'";', '', tc)
            tc = re.sub('\n+const QString '+cname+'::'+typ+'\("'+rlabel+'"\);', '', tc)
            th = re.sub(r'class( BA_CORE_API_)? ('+cname+r'.+?)static const QString '+typ+r';(.*?\n};)',
                        r'class \2static constexpr auto '+typ+r'{"'+label+r'"};\3', th, 0, re.S)
    
        return th, tc
    
    et.ed_argfilepairs(user_edit_pair)
ItemWithParticles.cpp 3.30 KiB
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/Models/ItemWithParticles.cpp
//! @brief     Implements class ItemWithParticles
//!
//! @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/Models/ItemWithParticles.h"
#include "Base/Vector/Transform3D.h"
#include "GUI/Models/RotationItems.h"
#include "GUI/Models/SessionItemUtils.h"
#include "GUI/Models/SessionModel.h"
#include "GUI/Models/TransformationItem.h"
#include "GUI/Models/VectorItem.h"

double ItemWithParticles::abundance() const
{
    return getItemValue(P_ABUNDANCE).toDouble();
}

void ItemWithParticles::setAbundance(const double abundance)
{
    setItemValue(P_ABUNDANCE, abundance);
}

SessionItem* ItemWithParticles::abundanceItem() const
{
    return getItem(P_ABUNDANCE);
}

const R3 ItemWithParticles::position() const
{
    return item<VectorItem>(P_POSITION)->getVector();
}

void ItemWithParticles::setPosition(const R3& position)
{
    item<VectorItem>(P_POSITION)->setVector(position);
}

VectorItem* ItemWithParticles::positionItem() const
{
    return item<VectorItem>(P_POSITION);
}

TransformationItem* ItemWithParticles::createTransformationItem()
{
    return model()->insertItem<TransformationItem>(this, -1, T_TRANSFORMATION);
}

void ItemWithParticles::setTransformation(RotationItem* transformation)
{
    model()->moveItem(transformation, this, -1, T_TRANSFORMATION);
}

bool ItemWithParticles::isTransformationTagName(const QString& name)
{
    return name == T_TRANSFORMATION;
}

Transform3D ItemWithParticles::rotation() const
{
    const auto item = dynamic_cast<TransformationItem*>(getItem(T_TRANSFORMATION));
    return item ? item->rotationItem()->rotation() : Transform3D();
}

ItemWithParticles::ItemWithParticles(const QString& model_type, const QString& abundance_tooltip,
                                     const QString& position_tooltip)
    : SessionGraphicsItem(model_type)
{
    addProperty(P_ABUNDANCE, 1.0)
        ->setLimits(RealLimits::limited(0.0, 1.0))
        .setDecimals(3)
        .setToolTip(abundance_tooltip);
    addProperty<VectorItem>(P_POSITION)->setToolTip(position_tooltip);

    registerTag(T_TRANSFORMATION, 0, 1, {TransformationItem::M_TYPE});

    mapper()->setOnParentChange([this](SessionItem* parent) {
        if (GUI::Session::ItemUtils::HasOwnAbundance(parent)) {
            setItemValue(P_ABUNDANCE, 1.0);
            getItem(P_ABUNDANCE)->setEnabled(false);
            if (isShellParticle()) {
                auto pos = item<VectorItem>(P_POSITION);
                pos->setVector(R3());
                pos->setEnabled(false);
            }
        } else {
            getItem(P_ABUNDANCE)->setEnabled(true);
            if (isShellParticle())
                item<VectorItem>(P_POSITION)->setEnabled(true);
        }
    });
}

void ItemWithParticles::setDefaultTagTransformation()
{
    setDefaultTag(T_TRANSFORMATION);
}

bool ItemWithParticles::isShellParticle() const
{
    return false;
}