Skip to content

Commit

Permalink
Refactored remove paramters from cftree method
Browse files Browse the repository at this point in the history
Refs #12669
  • Loading branch information
Elliot Oram authored and Elliot Oram committed Jul 27, 2015
1 parent 2529340 commit b404c93
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@ private slots:
boost::shared_ptr<Mantid::API::CompositeFunction>
createFunction(bool tieCentres = false);
double getInstrumentResolution(std::string workspaceName);
QtProperty *createLorentzian(const QString &);
QtProperty *createDiffSphere(const QString &);
QtProperty *createDiffRotDiscreteCircle(const QString &);
QtProperty *createElasticDiffSphere(const QString &);
QtProperty *createElasticDiffRotDiscreteCircle(const QString &);
QtProperty *createInelasticDiffSphere(const QString &);
QtProperty *createInelasticDiffRotDiscreteCircle(const QString &);
QtProperty *createStretchedExpFT(const QString &);
QtProperty *createLorentzian(const QString &);
void createTemperatureCorrection(Mantid::API::CompositeFunction_sptr product);
void populateFunction(Mantid::API::IFunction_sptr func,
Mantid::API::IFunction_sptr comp, QtProperty *group,
Expand All @@ -81,6 +74,8 @@ private slots:
Mantid::API::IAlgorithm_sptr m_fitAlg;


void removeTreeParams();

};
} // namespace IDA
} // namespace CustomInterfaces
Expand Down
166 changes: 38 additions & 128 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ConvFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,6 @@ void ConvFit::setup() {
m_properties["DeltaFunction"]->addSubProperty(m_properties["UseDeltaFunc"]);
m_cfTree->addProperty(m_properties["DeltaFunction"]);

// Fit functions
m_properties["Lorentzian1"] = createLorentzian("Lorentzian 1");
m_properties["Lorentzian2"] = createLorentzian("Lorentzian 2");
m_properties["DiffSphere"] = createDiffSphere("Diffusion Sphere");
m_properties["DiffRotDiscreteCircle"] =
createDiffRotDiscreteCircle("Diffusion Circle");
m_properties["ElasticDiffSphere"] =
createElasticDiffSphere("Elastic Diffusion Sphere");
m_properties["ElasticDiffRotDiscreteCircle"] =
createElasticDiffRotDiscreteCircle("Elastic Diffusion Circle");
m_properties["InelasticDiffSphere"] =
createInelasticDiffSphere("Inelastic Diffusion Sphere");
m_properties["InelasticDiffRotDiscreteCircle"] =
createInelasticDiffRotDiscreteCircle("Inelastic Diffusion Circle");
m_properties["StretchedExpFT"] =
createStretchedExpFT("Strecthced Exponential Fit");

m_uiForm.leTempCorrection->setValidator(new QDoubleValidator(m_parentWidget));

// Connections
Expand Down Expand Up @@ -195,11 +178,6 @@ void ConvFit::setup() {
SLOT(showTieCheckbox(QString)));
showTieCheckbox(m_uiForm.cbFitType->currentText());

// Fitting function
/*m_properties["FitFunction"] = m_grpManager->addProperty("Fitting
Parameters");
m_cfTree->addProperty(m_properties["FitFunction"]);*/

// Update fit parameters in browser when function is selected
connect(m_uiForm.cbFitType, SIGNAL(currentIndexChanged(QString)), this,
SLOT(fitFunctionSelected(const QString &)));
Expand All @@ -209,8 +187,8 @@ void ConvFit::setup() {
/**
* Converts data into a python script which prodcues the output workspace
*/
// void ConvFit::run() {
/*if (m_cfInputWS == NULL) {
void ConvFit::run() {
if (m_cfInputWS == NULL) {
g_log.error("No workspace loaded");
return;
}
Expand Down Expand Up @@ -288,16 +266,18 @@ QString pyOutput = runPythonCode(pyInput);
// Set the result workspace for Python script export
m_pythonExportWsName = pyOutput.toStdString();

updatePlot();*/
//}
updatePlot();
}



/**
* Runs algorithm.
*
* @param plot Enable/disable plotting
* @param save Enable/disable saving
*/
void ConvFit::run() {
/*void ConvFit::run() {
if (m_batchAlgoRunner->queueLength() > 0)
return;
Expand All @@ -307,7 +287,7 @@ void ConvFit::run() {
functionName = "Lorentzian";
}
if (functionName.compare("Two Lorentzian") == 0) {
// Implement two peak lorentxian behaviour
// Implement two peak lorentzian behaviour
}
QString functionString = "name=" + functionName;
Expand Down Expand Up @@ -340,18 +320,19 @@ void ConvFit::run() {
m_fitAlg->setProperty("CreateOutput", true);
m_fitAlg->setProperty("Output", outputName.toStdString());
// Debugging
// Debugging -----------TO BE REMOVED
std::string fs = functionString.toStdString();
std::string smple = sample.toStdString();
double sx = m_dblManager->value(m_properties["StartX"]);
double ex = m_dblManager->value(m_properties["EndX"]);
std::string on = outputName.toStdString();
std::string funcString = functionString.toStdString();
m_batchAlgoRunner->addAlgorithm(m_fitAlg);
m_batchAlgoRunner->executeBatchAsync();
updatePlot();
}
}*/

/**
* Validates the user's inputs in the ConvFit tab.
Expand Down Expand Up @@ -822,89 +803,6 @@ QtProperty *ConvFit::createLorentzian(const QString &name) {
return lorentzGroup;
}

/**
* Creates a DiffSphere
* @param name The name of the DiffSphere
* @return The QTProperty that represents the DiffSphere
*/
QtProperty *ConvFit::createDiffSphere(const QString &name) {
QtProperty *diffSphereGroup = m_grpManager->addProperty(name);

m_properties[name + ".Intensity"] = m_dblManager->addProperty("Intensity");
m_properties[name + ".Radius"] = m_dblManager->addProperty("Radius");
m_properties[name + ".Diffusion"] = m_dblManager->addProperty("Diffusion");
m_properties[name + ".Shift"] = m_dblManager->addProperty("Shift");

m_dblManager->setDecimals(m_properties[name + ".Intensity"], NUM_DECIMALS);
m_dblManager->setDecimals(m_properties[name + ".Radius"], NUM_DECIMALS);
m_dblManager->setDecimals(m_properties[name + ".Diffusion"], NUM_DECIMALS);
m_dblManager->setDecimals(m_properties[name + ".Shift"], NUM_DECIMALS);

diffSphereGroup->addSubProperty(m_properties[name + ".Intensity"]);
diffSphereGroup->addSubProperty(m_properties[name + ".Radius"]);
diffSphereGroup->addSubProperty(m_properties[name + ".Diffusion"]);
diffSphereGroup->addSubProperty(m_properties[name + ".Shift"]);

return diffSphereGroup;
}

/**
* Creates a DiffRotDiscreteCircle
* @param name The name of the DiffRotDiscreteCircle
* @return The QTProperty that represents the DiffRotDiscreteCircle
*/
QtProperty *ConvFit::createDiffRotDiscreteCircle(const QString &name) {
QtProperty *diffRotDiscreteCircleGroup = m_grpManager->addProperty(name);

m_properties[name + ".N"] = m_dblManager->addProperty("N");
m_dblManager->setValue(m_properties[name + ".N"], 3.0);

m_properties[name + ".Intensity"] = m_dblManager->addProperty("Intensity");
m_properties[name + ".Radius"] = m_dblManager->addProperty("Radius");
m_properties[name + ".Decay"] = m_dblManager->addProperty("Decay");
m_properties[name + ".Shift"] = m_dblManager->addProperty("Shift");

m_dblManager->setDecimals(m_properties[name + ".N"], 0);
m_dblManager->setDecimals(m_properties[name + ".Intensity"], NUM_DECIMALS);
m_dblManager->setDecimals(m_properties[name + ".Radius"], NUM_DECIMALS);
m_dblManager->setDecimals(m_properties[name + ".Decay"], NUM_DECIMALS);
m_dblManager->setDecimals(m_properties[name + ".Shift"], NUM_DECIMALS);

diffRotDiscreteCircleGroup->addSubProperty(m_properties[name + ".N"]);
diffRotDiscreteCircleGroup->addSubProperty(m_properties[name + ".Intensity"]);
diffRotDiscreteCircleGroup->addSubProperty(m_properties[name + ".Radius"]);
diffRotDiscreteCircleGroup->addSubProperty(m_properties[name + ".Decay"]);
diffRotDiscreteCircleGroup->addSubProperty(m_properties[name + ".Shift"]);

return diffRotDiscreteCircleGroup;
}

QtProperty *ConvFit::createElasticDiffSphere(const QString &name) {
QtProperty *elasticDiffSphereGroup = m_grpManager->addProperty(name);
return elasticDiffSphereGroup;
}

QtProperty *ConvFit::createElasticDiffRotDiscreteCircle(const QString &name) {
QtProperty *elasticDiffRotDiscreteCircleGroup =
m_grpManager->addProperty(name);
return elasticDiffRotDiscreteCircleGroup;
}

QtProperty *ConvFit::createInelasticDiffSphere(const QString &name) {
QtProperty *elasticDiffSphereGroup = m_grpManager->addProperty(name);
return elasticDiffSphereGroup;
}

QtProperty *ConvFit::createInelasticDiffRotDiscreteCircle(const QString &name) {
QtProperty *inelasticDiffSphereGroup = m_grpManager->addProperty(name);
return inelasticDiffSphereGroup;
}

QtProperty *ConvFit::createStretchedExpFT(const QString &name) {
QtProperty *stretchedExpFTGroup = m_grpManager->addProperty(name);
return stretchedExpFTGroup;
}

/**
* Populates the properties of a function with given values
* @param func The function currently being added to the composite
Expand Down Expand Up @@ -1522,6 +1420,9 @@ void ConvFit::fixItem() {
item->parent()->property()->removeSubProperty(prop);
}

/**
*
*/
void ConvFit::unFixItem() {
QtBrowserItem *item = m_cfTree->currentItem();

Expand All @@ -1539,10 +1440,12 @@ void ConvFit::unFixItem() {
delete prop;
}


void ConvFit::showTieCheckbox(QString fitType) {
m_uiForm.ckTieCentres->setVisible(fitType == "Two Lorentzians");
}


/**
* Gets a list of parameters for a given fit function.
*
Expand Down Expand Up @@ -1577,24 +1480,13 @@ QStringList ConvFit::getFunctionParameters(QString functionName) {
return parameters;
}


/**
* Handles a new fit function being selected.
*
* @param functionName Name of new fit function
*/
void ConvFit::fitFunctionSelected(const QString &functionName) {
// remove old parameter elements
for (auto it = m_properties.begin(); it != m_properties.end();) {
if (it.key().startsWith("parameter_")) {
delete it.value();
it = m_properties.erase(it);
} else {
++it;
}
}

m_cfTree->removeProperty(m_properties["FitFunction1"]);
m_cfTree->removeProperty(m_properties["FitFunction2"]);
removeTreeParams();

// Add new parameter elements
QStringList parameters = getFunctionParameters(functionName);
Expand All @@ -1608,32 +1500,50 @@ void ConvFit::fitFunctionSelected(const QString &functionName) {
m_cfTree->addProperty(m_properties["FitFunction1"]);
}

//No fit function parameters required for Zero
if (parameters[0].compare("Zero") != 0) {
if (functionName.compare("Two Lorentzians") == 0) {
int count = 0;
for (auto it = parameters.begin(); it != parameters.end(); ++it) {
QString name = "parameter_" + *it;
m_properties[name] = m_dblManager->addProperty(*it);
m_dblManager->setValue(m_properties[name], 0.0);
m_dblManager->setDecimals(m_properties[name], NUM_DECIMALS);
if (count < 3) {
m_properties["FitFunction1"]->addSubProperty(m_properties[name]);
} else {
m_properties["FitFunction2"]->addSubProperty(m_properties[name]);
}
count++;
}

} else {
for (auto it = parameters.begin(); it != parameters.end(); ++it) {
QString name = "parameter_" + *it;
m_properties[name] = m_dblManager->addProperty(*it);
m_dblManager->setValue(m_properties[name], 0.0);
m_properties["FitFunction1"]->addSubProperty(m_properties[name]);
m_dblManager->setDecimals(m_properties[name], NUM_DECIMALS);
m_properties["FitFunction1"]->addSubProperty(m_properties[name]);
}
}
}
}

/**
* Removes fit function related parameters from the cfTree
*/
void ConvFit::removeTreeParams() {
for (auto it = m_properties.begin(); it != m_properties.end();) {
if (it.key().startsWith("parameter_")) {
delete it.value();
it = m_properties.erase(it);
} else {
++it;
}
}
m_cfTree->removeProperty(m_properties["FitFunction1"]);
m_cfTree->removeProperty(m_properties["FitFunction2"]);
}

} // namespace IDA
} // namespace CustomInterfaces
} // namespace MantidQt

0 comments on commit b404c93

Please sign in to comment.