Skip to content
Snippets Groups Projects
Commit d0c18c9f authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Init method for DistributionItems to pass cached value and precision.

parent dceccf0a
No related branches found
No related tags found
No related merge requests found
......@@ -60,10 +60,9 @@ BeamWavelengthItem::BeamWavelengthItem(ParameterizedItem *parent)
: ParameterizedItem(Constants::BeamWavelengthType, parent)
{
setItemName(Constants::BeamWavelengthType);
registerGroupProperty(P_DISTRIBUTION, Constants::DistributionExtendedGroup);
setGroupProperty(P_DISTRIBUTION, Constants::DistributionGateType);
registerProperty(P_CACHED_VALUE, 0.1, PropertyAttribute(PropertyAttribute::HIDDEN, AttLimits::lowerLimited(1e-4), 4));
registerGroupProperty(P_DISTRIBUTION, Constants::DistributionExtendedGroup);
setGroupProperty(P_DISTRIBUTION, Constants::DistributionNoneType);
}
//void BeamWavelengthItem::onPropertyChange(const QString &name)
......@@ -90,31 +89,23 @@ BeamWavelengthItem::BeamWavelengthItem(ParameterizedItem *parent)
// ParameterizedItem::onPropertyChange(name);
//}
//! updates DistributionItem with cached_value
void BeamWavelengthItem::onSubItemChanged(const QString &propertyName)
{
qDebug() << " ";
qDebug() << " ";
qDebug() << " ";
qDebug() << " ";
qDebug() << "BeamWavelengthItem::onSubItemChanged(const QString &propertyName)" << propertyName;
if(propertyName == P_DISTRIBUTION) {
ParameterizedItem *distribution = getSubItems()[P_DISTRIBUTION];
DistributionItem *distribution = dynamic_cast<DistributionItem *>(getSubItems()[P_DISTRIBUTION]);
Q_ASSERT(distribution);
if(distribution->modelType() == Constants::DistributionNoneType) {
double cached_value = getRegisteredProperty(P_CACHED_VALUE).toDouble();
distribution->setRegisteredProperty(DistributionNoneItem::P_VALUE, cached_value);
distribution->setPropertyAttribute(DistributionNoneItem::P_VALUE, PropertyAttribute(AttLimits::lowerLimited(1e-4), 4));
}
double cached_value = getRegisteredProperty(P_CACHED_VALUE).toDouble();
PropertyAttribute cached_attribute = getPropertyAttribute(P_CACHED_VALUE);
cached_attribute.setAppearance(PropertyAttribute::VISIBLE);
distribution->init_parameters(cached_value, cached_attribute);
}
ParameterizedItem::onSubItemChanged(propertyName);
}
void BeamWavelengthItem::onSubItemPropertyChanged(const QString &property_group, const QString &property_name)
{
qDebug() << "OOO";
qDebug() << "OOO";
qDebug() << "OOO";
qDebug() << "OOO";
qDebug() << "BeamWavelengthItem::onSubItemPropertyChanged(const QString &property_group, const QString &property_name)" << property_group << property_name;
if(property_group == P_DISTRIBUTION && property_name == DistributionNoneItem::P_VALUE) {
double value_to_cache = getSubItems()[P_DISTRIBUTION]->getRegisteredProperty(DistributionNoneItem::P_VALUE).toDouble();
......
......@@ -45,6 +45,12 @@ IDistribution1D *DistributionNoneItem::createDistribution() const
return 0;
}
void DistributionNoneItem::init_parameters(double value, PropertyAttribute attribute)
{
setRegisteredProperty(DistributionNoneItem::P_VALUE, value);
setPropertyAttribute(DistributionNoneItem::P_VALUE, attribute);
}
/* ------------------------------------------------ */
const QString DistributionGateItem::P_MIN = "Minimum";
......@@ -66,6 +72,14 @@ IDistribution1D *DistributionGateItem::createDistribution() const
return new DistributionGate(min, max);
}
void DistributionGateItem::init_parameters(double value, PropertyAttribute attribute)
{
setRegisteredProperty(P_MIN, value - 0.1*value);
setPropertyAttribute(P_MIN, attribute);
setRegisteredProperty(P_MAX, value + 0.1*value);
setPropertyAttribute(P_MAX, attribute);
}
/* ------------------------------------------------ */
const QString DistributionLorentzItem::P_MEAN = "Mean";
......@@ -87,6 +101,14 @@ IDistribution1D *DistributionLorentzItem::createDistribution() const
return new DistributionLorentz(mean, hwhm);
}
void DistributionLorentzItem::init_parameters(double value, PropertyAttribute attribute)
{
setRegisteredProperty(P_MEAN, value);
setPropertyAttribute(P_MEAN, attribute);
setRegisteredProperty(P_HWHM, 0.1*value);
setPropertyAttribute(P_HWHM, attribute);
}
/* ------------------------------------------------ */
const QString DistributionGaussianItem::P_MEAN = "Mean";
......@@ -108,6 +130,14 @@ IDistribution1D *DistributionGaussianItem::createDistribution() const
return new DistributionGaussian(mean, std_dev);
}
void DistributionGaussianItem::init_parameters(double value, PropertyAttribute attribute)
{
setRegisteredProperty(P_MEAN, value);
setPropertyAttribute(P_MEAN, attribute);
setRegisteredProperty(P_STD_DEV, 0.1*value);
setPropertyAttribute(P_STD_DEV, attribute);
}
/* ------------------------------------------------ */
const QString DistributionLogNormalItem::P_MEDIAN = "Median";
......@@ -129,6 +159,14 @@ IDistribution1D *DistributionLogNormalItem::createDistribution() const
return new DistributionLogNormal(median, scale_par);
}
void DistributionLogNormalItem::init_parameters(double value, PropertyAttribute attribute)
{
setRegisteredProperty(P_MEDIAN, value);
setPropertyAttribute(P_MEDIAN, attribute);
setRegisteredProperty(P_SCALE_PAR, 0.1*value);
setPropertyAttribute(P_SCALE_PAR, attribute);
}
/* ------------------------------------------------ */
const QString DistributionCosineItem::P_MEAN = "Mean";
......@@ -149,3 +187,11 @@ IDistribution1D *DistributionCosineItem::createDistribution() const
double sigma = getRegisteredProperty(P_SIGMA).toDouble();
return new DistributionCosine(mean, sigma);
}
void DistributionCosineItem::init_parameters(double value, PropertyAttribute attribute)
{
setRegisteredProperty(P_MEAN, value);
setPropertyAttribute(P_MEAN, attribute);
setRegisteredProperty(P_SIGMA, 0.1*value);
setPropertyAttribute(P_SIGMA, attribute);
}
......@@ -19,6 +19,7 @@
#include "ParameterizedItem.h"
#include "Distributions.h"
class BA_CORE_API_ DistributionItem : public ParameterizedItem
{
Q_OBJECT
......@@ -28,6 +29,8 @@ public:
virtual ~DistributionItem() {}
virtual IDistribution1D *createDistribution() const=0;
virtual void init_parameters(double, PropertyAttribute){}
protected:
void register_number_of_samples();
};
......@@ -39,6 +42,7 @@ public:
static const QString P_VALUE;
explicit DistributionNoneItem(ParameterizedItem *parent=0);
virtual IDistribution1D *createDistribution() const;
virtual void init_parameters(double value, PropertyAttribute attribute);
};
......@@ -51,6 +55,7 @@ public:
explicit DistributionGateItem(ParameterizedItem *parent=0);
virtual IDistribution1D *createDistribution() const;
virtual void init_parameters(double value, PropertyAttribute attribute);
};
......@@ -63,6 +68,7 @@ public:
explicit DistributionLorentzItem(ParameterizedItem *parent=0);
virtual IDistribution1D *createDistribution() const;
virtual void init_parameters(double value, PropertyAttribute attribute);
};
......@@ -75,6 +81,7 @@ public:
explicit DistributionGaussianItem(ParameterizedItem *parent=0);
virtual IDistribution1D *createDistribution() const;
virtual void init_parameters(double value, PropertyAttribute attribute);
};
......@@ -87,6 +94,7 @@ public:
explicit DistributionLogNormalItem(ParameterizedItem *parent=0);
virtual IDistribution1D *createDistribution() const;
virtual void init_parameters(double value, PropertyAttribute attribute);
};
......@@ -99,6 +107,7 @@ public:
explicit DistributionCosineItem(ParameterizedItem *parent=0);
virtual IDistribution1D *createDistribution() const;
virtual void init_parameters(double value, PropertyAttribute attribute);
};
#endif // DISTRIBUTIONITEM_H
......
......@@ -229,7 +229,7 @@ void ParameterizedItem::setRegisteredProperty(const QString &name, const QVarian
QVariant ParameterizedItem::getRegisteredProperty(const QString &name) const
{
if( !m_registered_properties.contains(name))
throw GUIHelpers::Error("ParameterizedItem::getRegisteredProperty() -> Error. Unknown property "+name);
throw GUIHelpers::Error("ParameterizedItem::getRegisteredProperty() -> Error. Unknown property "+name+" model="+modelType());
return property(name.toUtf8().constData());
}
......
......@@ -70,7 +70,6 @@ inline void TestParameterizedItem::test_registerProperty()
QCOMPARE(arguments.size(), 1);
QCOMPARE(arguments.at(0).toString(), property_name);
QVERIFY_THROW(item.getRegisteredProperty(property_name), GUIHelpers::Error);
}
inline void TestParameterizedItem::test_SelectableGroupProperty()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment