diff --git a/Code/Mantid/API/inc/MantidAPI/CompositeFunction.h b/Code/Mantid/API/inc/MantidAPI/CompositeFunction.h index ea2559482464ae4a9a17d6a9ee87356a06741072..230b063cdeee04d0c36d780cde61a48293315eff 100644 --- a/Code/Mantid/API/inc/MantidAPI/CompositeFunction.h +++ b/Code/Mantid/API/inc/MantidAPI/CompositeFunction.h @@ -108,6 +108,8 @@ public: int getParameterIndex(const ParameterReference& ref)const; /// Get the containing function IFunction* getContainingFunction(const ParameterReference& ref)const; + /// Get the containing function + IFunction* getContainingFunction(const IFunction* fun); /// Apply the ties void applyTies(); diff --git a/Code/Mantid/API/inc/MantidAPI/Function.h b/Code/Mantid/API/inc/MantidAPI/Function.h index 9940c18207dd985e7b0addf85fefdb3c781858f7..ae7f353d70c8b211b0aedb8184091e71ab634556 100644 --- a/Code/Mantid/API/inc/MantidAPI/Function.h +++ b/Code/Mantid/API/inc/MantidAPI/Function.h @@ -103,6 +103,8 @@ public: virtual int getParameterIndex(const ParameterReference& ref)const; /// Get the containing function IFunction* getContainingFunction(const ParameterReference& ref)const; + /// Get the containing function + IFunction* getContainingFunction(const IFunction* fun); /// Apply the ties virtual void applyTies(); diff --git a/Code/Mantid/API/inc/MantidAPI/IFunction.h b/Code/Mantid/API/inc/MantidAPI/IFunction.h index 803d693308bca5e3b8d61c25553b00b5d07039e1..fde5dd8a7b0d4ff2102243eebe8e9b8e69fe477f 100644 --- a/Code/Mantid/API/inc/MantidAPI/IFunction.h +++ b/Code/Mantid/API/inc/MantidAPI/IFunction.h @@ -169,6 +169,8 @@ public: /// it will be the same as ParameterReference::getFunction(). In case of a CompositeFunction it returns /// a top-level function that contains the parameter. The return function itself can be a CompositeFunction virtual IFunction* getContainingFunction(const ParameterReference& ref)const = 0; + /// The same as the method above but the argument is a function + virtual IFunction* getContainingFunction(const IFunction* fun) = 0; /// Tie a parameter to other parameters (or a constant) virtual ParameterTie* tie(const std::string& parName,const std::string& expr); diff --git a/Code/Mantid/API/src/CompositeFunction.cpp b/Code/Mantid/API/src/CompositeFunction.cpp index 2af63196e677ed9b25ecc6f567f4f5a6d4d6d3d4..4ab567a20805eca5b4d77f32f6fe3530df9d8c57 100644 --- a/Code/Mantid/API/src/CompositeFunction.cpp +++ b/Code/Mantid/API/src/CompositeFunction.cpp @@ -889,5 +889,26 @@ IFunction* CompositeFunction::getContainingFunction(const ParameterReference& re return NULL; } +/** + * @param fun The searched function + * @return A function containing the argument function fun + */ +IFunction* CompositeFunction::getContainingFunction(const IFunction* fun) +{ + if (fun == this) + { + return this; + } + for(int iFun=0;iFun<nFunctions();iFun++) + { + IFunction* f = getFunction(iFun)->getContainingFunction(fun); + if (f) + { + return getFunction(iFun); + } + } + return NULL; +} + } // namespace API } // namespace Mantid diff --git a/Code/Mantid/API/src/Function.cpp b/Code/Mantid/API/src/Function.cpp index 7de5b346966fb930b2f93f8de129296d8c5efb7d..74a1c67b5b10ea5ed63bd20a17fdf19b28b117fb 100644 --- a/Code/Mantid/API/src/Function.cpp +++ b/Code/Mantid/API/src/Function.cpp @@ -502,5 +502,18 @@ IFunction* Function::getContainingFunction(const ParameterReference& ref)const return NULL; } +/** + * @param fun The function + * @return A function containing fun + */ +IFunction* Function::getContainingFunction(const IFunction* fun) +{ + if (fun == this) + { + return this; + } + return NULL; +} + } // namespace API } // namespace Mantid diff --git a/Code/Mantid/API/src/IFunction.cpp b/Code/Mantid/API/src/IFunction.cpp index 978e361a094c7de13cded3d31b31ea74a2f19af0..d2208c839d83b8d77c5a18cab339697406f07b1b 100644 --- a/Code/Mantid/API/src/IFunction.cpp +++ b/Code/Mantid/API/src/IFunction.cpp @@ -51,114 +51,121 @@ void IFunction::setWorkspace(boost::shared_ptr<const API::MatrixWorkspace> works m_xMinIndex = xMin; m_xMaxIndex = xMax; - // check if parameter are specified in instrument definition file + try + { - Geometry::ParameterMap& paramMap = m_workspace->instrumentParameters(); + // check if parameter are specified in instrument definition file - // in some tests where workspace a created on the fly a spectra to detector map - // is for convenience not created. - if ( !(m_workspace->spectraMap().nElements()) ) - return; + Geometry::ParameterMap& paramMap = m_workspace->instrumentParameters(); - Geometry::IDetector_sptr det = m_workspace->getDetector(wi); + // in some tests where workspace a created on the fly a spectra to detector map + // is for convenience not created. + if ( !(m_workspace->spectraMap().nElements()) ) + return; - // if det is a detector groupworkspace then take as the detector - // the detector returned by det->getID() - if ( boost::dynamic_pointer_cast<Geometry::DetectorGroup>(det) ) - { - API::IInstrument_sptr inst = m_workspace->getInstrument(); - det = inst->getDetector(det->getID()); - } + Geometry::IDetector_sptr det = m_workspace->getDetector(wi); - for (int i = 0; i < nParams(); i++) - { - if ( !isExplicitlySet(i) ) + // if det is a detector groupworkspace then take as the detector + // the detector returned by det->getID() + if ( boost::dynamic_pointer_cast<Geometry::DetectorGroup>(det) ) { - Geometry::Parameter_sptr param = paramMap.getRecursive(&(*det), parameterName(i), "fitting"); - if (param != Geometry::Parameter_sptr()) - { - // get FitParameter - const Geometry::FitParameter& fitParam = param->value<Geometry::FitParameter>(); + API::IInstrument_sptr inst = m_workspace->getInstrument(); + det = inst->getDetector(det->getID()); + } - // check first if this parameter is actually specified for this function - if ( name().compare(fitParam.getFunction()) == 0 ) + for (int i = 0; i < nParams(); i++) + { + if ( !isExplicitlySet(i) ) + { + Geometry::Parameter_sptr param = paramMap.getRecursive(&(*det), parameterName(i), "fitting"); + if (param != Geometry::Parameter_sptr()) { - // update value - IFunctionWithLocation* testWithLocation = dynamic_cast<IFunctionWithLocation*>(this); - if ( testWithLocation == NULL || - (fitParam.getLookUpTable().containData() == false && fitParam.getFormula().compare("") == 0) ) - { - double bob = fitParam.getValue(); - setParameter(i, fitParam.getValue()); - } - else + // get FitParameter + const Geometry::FitParameter& fitParam = param->value<Geometry::FitParameter>(); + + // check first if this parameter is actually specified for this function + if ( name().compare(fitParam.getFunction()) == 0 ) { - double centreValue = testWithLocation->centre(); - Kernel::Unit_sptr targetUnit; - if ( fitParam.getFormula().compare("") == 0 ) - targetUnit = fitParam.getLookUpTable().getXUnit(); // from table + // update value + IFunctionWithLocation* testWithLocation = dynamic_cast<IFunctionWithLocation*>(this); + if ( testWithLocation == NULL || + (fitParam.getLookUpTable().containData() == false && fitParam.getFormula().compare("") == 0) ) + { + double bob = fitParam.getValue(); + setParameter(i, fitParam.getValue()); + } else - targetUnit = Kernel::UnitFactory::Instance().create(fitParam.getFormulaUnit()); // from formula - - Kernel::Unit_sptr wsUnit = m_workspace->getAxis(0)->unit(); - - // if units are different first convert centre value into unit of look up table - if ( targetUnit->unitID().compare(wsUnit->unitID()) != 0 ) { - double factor,power; - if (wsUnit->quickConversion(*targetUnit,factor,power) ) - { - centreValue = factor * std::pow(centreValue,power); - } + double centreValue = testWithLocation->centre(); + Kernel::Unit_sptr targetUnit; + if ( fitParam.getFormula().compare("") == 0 ) + targetUnit = fitParam.getLookUpTable().getXUnit(); // from table else - { - double l1,l2,twoTheta; + targetUnit = Kernel::UnitFactory::Instance().create(fitParam.getFormulaUnit()); // from formula + + Kernel::Unit_sptr wsUnit = m_workspace->getAxis(0)->unit(); - // Get l1, l2 and theta (see also RemoveBins.calculateDetectorPosition()) - IInstrument_const_sptr instrument = m_workspace->getInstrument(); - Geometry::IObjComponent_const_sptr sample = instrument->getSample(); - l1 = instrument->getSource()->getDistance(*sample); - Geometry::IDetector_const_sptr det = m_workspace->getDetector(wi); - if ( ! det->isMonitor() ) + // if units are different first convert centre value into unit of look up table + if ( targetUnit->unitID().compare(wsUnit->unitID()) != 0 ) + { + double factor,power; + if (wsUnit->quickConversion(*targetUnit,factor,power) ) { - l2 = det->getDistance(*sample); - twoTheta = m_workspace->detectorTwoTheta(det); + centreValue = factor * std::pow(centreValue,power); } - else // If this is a monitor then make l1+l2 = source-detector distance and twoTheta=0 + else { - l2 = det->getDistance(*(instrument->getSource())); - l2 = l2 - l1; - twoTheta = 0.0; - } + double l1,l2,twoTheta; - std::vector<double> endPoint; - endPoint.push_back(centreValue); - std::vector<double> emptyVec; - wsUnit->toTOF(endPoint,emptyVec,l1,l2,twoTheta,0,0.0,0.0); - targetUnit->fromTOF(endPoint,emptyVec,l1,l2,twoTheta,0,0.0,0.0); - centreValue = endPoint[0]; - } - } // end of: lookUpUnit->unitID().compare(wsUnit->unitID()) != 0 - setParameter(i, fitParam.getValue(centreValue)); - } // end of update parameter value + // Get l1, l2 and theta (see also RemoveBins.calculateDetectorPosition()) + IInstrument_const_sptr instrument = m_workspace->getInstrument(); + Geometry::IObjComponent_const_sptr sample = instrument->getSample(); + l1 = instrument->getSource()->getDistance(*sample); + Geometry::IDetector_const_sptr det = m_workspace->getDetector(wi); + if ( ! det->isMonitor() ) + { + l2 = det->getDistance(*sample); + twoTheta = m_workspace->detectorTwoTheta(det); + } + else // If this is a monitor then make l1+l2 = source-detector distance and twoTheta=0 + { + l2 = det->getDistance(*(instrument->getSource())); + l2 = l2 - l1; + twoTheta = 0.0; + } - // add tie if specified for this parameter in instrument definition file - if ( fitParam.getTie().compare("") ) - { - std::ostringstream str; - str << fitParam.getValue(); - tie(parameterName(i), str.str()); - } + std::vector<double> endPoint; + endPoint.push_back(centreValue); + std::vector<double> emptyVec; + wsUnit->toTOF(endPoint,emptyVec,l1,l2,twoTheta,0,0.0,0.0); + targetUnit->fromTOF(endPoint,emptyVec,l1,l2,twoTheta,0,0.0,0.0); + centreValue = endPoint[0]; + } + } // end of: lookUpUnit->unitID().compare(wsUnit->unitID()) != 0 + setParameter(i, fitParam.getValue(centreValue)); + } // end of update parameter value - // add constraint if specified for this parameter in instrument definition file - if ( fitParam.getConstraint().compare("") ) - { - addConstraint(ConstraintFactory::Instance().createInitialized(this, fitParam.getConstraint())); + // add tie if specified for this parameter in instrument definition file + if ( fitParam.getTie().compare("") ) + { + std::ostringstream str; + str << fitParam.getValue(); + tie(parameterName(i), str.str()); + } + + // add constraint if specified for this parameter in instrument definition file + if ( fitParam.getConstraint().compare("") ) + { + addConstraint(ConstraintFactory::Instance().createInitialized(this, fitParam.getConstraint())); + } } } } } } + catch(...) + { + } } /** Update active parameters. Ties are applied. diff --git a/Code/Mantid/Algorithms/Algorithms.vcproj b/Code/Mantid/Algorithms/Algorithms.vcproj index 585f0e81c3c6254d6c417c74e1981f559629c2bf..4f6bc997f65f92ec079e2420743fb32f637e6811 100644 --- a/Code/Mantid/Algorithms/Algorithms.vcproj +++ b/Code/Mantid/Algorithms/Algorithms.vcproj @@ -446,6 +446,10 @@ RelativePath=".\src\ReplaceSpecialValues.cpp" > </File> + <File + RelativePath=".\src\Scale.cpp" + > + </File> <File RelativePath=".\src\SimpleIntegration.cpp" > diff --git a/Code/Mantid/CurveFitting/src/Resolution.cpp b/Code/Mantid/CurveFitting/src/Resolution.cpp index 2668ff2856f70dd7d05df86b0bdbb820111b2ece..1c17560baace3205c519aed935dab7ba7169ddd1 100644 --- a/Code/Mantid/CurveFitting/src/Resolution.cpp +++ b/Code/Mantid/CurveFitting/src/Resolution.cpp @@ -108,8 +108,8 @@ void Resolution::load(const std::string& fname) { str += ' '; std::istringstream istr(str); - double x,y,e; - istr >> x >> y >> e; + double x,y; + istr >> x >> y; if (!istr.good()) { break; @@ -126,22 +126,6 @@ void Resolution::load(const std::string& fname) m_xStart = m_xData.front(); m_xEnd = m_xData.back(); - //m_dx = (m_xEnd - m_xStart) / (size() - 1); - - //if (m_dx <= 0) - //{ - // throw std::runtime_error("Resolution: decreasing x values"); - //} - - //m_isXRegular = true; - //for (int i=1;i<size();i++) - //{ - // if ( fabs((m_xData[i]-m_xData[i-1])/m_dx - 1.) > 1e-7) - // { - // m_isXRegular = false; - // break; - // } - //} } } // namespace CurveFitting diff --git a/Code/Mantid/CurveFitting/test/ConvolutionTest.h b/Code/Mantid/CurveFitting/test/ConvolutionTest.h index 4919167d7e1b8ac888127cb25df86d173fc1fea4..1a00c96aa22aa8db59edb928b9faa168c319e202 100644 --- a/Code/Mantid/CurveFitting/test/ConvolutionTest.h +++ b/Code/Mantid/CurveFitting/test/ConvolutionTest.h @@ -317,7 +317,7 @@ public: xr[i] = x[i] - x0 - Dx/2; } - double c2 = (Dx-x0)/2; + double c2 = x0 + Dx/2; double h2 = 10.; double s2 = pi/3; ConvolutionTest_Gauss* fun = new ConvolutionTest_Gauss(); diff --git a/Code/qtiplot/QtPropertyBrowser/qtpropertybrowser.pro b/Code/qtiplot/QtPropertyBrowser/qtpropertybrowser.pro index f0cc09e5ab03025e2303c7a8e677d4659daa1c1d..9aa6706e0e106ce2055e03625989a0d214ec6a0f 100644 --- a/Code/qtiplot/QtPropertyBrowser/qtpropertybrowser.pro +++ b/Code/qtiplot/QtPropertyBrowser/qtpropertybrowser.pro @@ -12,7 +12,8 @@ SOURCES += src/qtpropertybrowser.cpp \ src/qttreepropertybrowser.cpp \ src/qtbuttonpropertybrowser.cpp \ src/qtgroupboxpropertybrowser.cpp \ - src/qtpropertybrowserutils.cpp + src/qtpropertybrowserutils.cpp \ + src/FilenameEditorFactory.cpp HEADERS += src/qtpropertybrowser.h \ src/qtpropertymanager.h \ src/qteditorfactory.h \ @@ -20,7 +21,8 @@ HEADERS += src/qtpropertybrowser.h \ src/qttreepropertybrowser.h \ src/qtbuttonpropertybrowser.h \ src/qtgroupboxpropertybrowser.h \ - src/qtpropertybrowserutils_p.h + src/qtpropertybrowserutils_p.h \ + src/FilenameEditorFactory.h RESOURCES += src/qtpropertybrowser.qrc win32 { diff --git a/Code/qtiplot/QtPropertyBrowser/src/FilenameEditorFactory.cpp b/Code/qtiplot/QtPropertyBrowser/src/FilenameEditorFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6b071b3e116fdaef98c10033d640be670730c460 --- /dev/null +++ b/Code/qtiplot/QtPropertyBrowser/src/FilenameEditorFactory.cpp @@ -0,0 +1,74 @@ +#include "FilenameEditorFactory.h" + +#include <QHBoxLayout> +#include <QLineEdit> +#include <QPushButton> +#include <QFileDialog> +#include <QLabel> +#include <QDialog> +#include <QSettings> + +#include <iostream> + +void FilenameEditorFactory::connectPropertyManager(QtStringPropertyManager *manager) +{ +} + +QWidget* FilenameEditorFactory::createEditor(QtStringPropertyManager *manager, QtProperty *property,QWidget *parent) +{ + return new FilenameEditor(property,parent); +} + +void FilenameEditorFactory::disconnectPropertyManager(QtStringPropertyManager *manager) +{ +} + +FilenameEditor::FilenameEditor(QtProperty *property, QWidget *parent):QWidget(parent),m_property(property) +{ + QHBoxLayout *layout = new QHBoxLayout; + m_lineEdit = new QLineEdit(this); + layout->addWidget(m_lineEdit); + setFocusProxy(m_lineEdit); + connect(m_lineEdit,SIGNAL(editingFinished()),this,SLOT(updateProperty())); + QtStringPropertyManager* mgr = dynamic_cast<QtStringPropertyManager*>(property->propertyManager()); + if (mgr) + { + m_lineEdit->setText(mgr->value(property)); + } + + QPushButton* button = new QPushButton("...",this); + button->setMaximumSize(20,1000000); + connect(button,SIGNAL(clicked()),this,SLOT(runDialog())); + layout->addStretch(); + layout->addWidget(button); + layout->setContentsMargins(0,0,0,0); + layout->setSpacing(0); + layout->setStretchFactor(button,0); + this->setLayout(layout); +} + +void FilenameEditor::runDialog() +{ + QSettings settings; + QString dir = settings.value("Mantid/FitBrowser/ResolutionDir").toString(); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),dir); + if (!fileName.isEmpty()) + { + m_lineEdit->setText(fileName); + updateProperty(); + } +} + +FilenameEditor::~FilenameEditor() +{ +} + +void FilenameEditor::updateProperty() +{ + QtStringPropertyManager* mgr = dynamic_cast<QtStringPropertyManager*>(m_property->propertyManager()); + if (mgr) + { + mgr->setValue(m_property,m_lineEdit->text()); + } +} + diff --git a/Code/qtiplot/QtPropertyBrowser/src/FilenameEditorFactory.h b/Code/qtiplot/QtPropertyBrowser/src/FilenameEditorFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..62e47640090d1e8ba44f0269a49f1fe2d06adea1 --- /dev/null +++ b/Code/qtiplot/QtPropertyBrowser/src/FilenameEditorFactory.h @@ -0,0 +1,34 @@ +#ifndef FILENAMEEDITORFACTORY_H +#define FILENAMEEDITORFACTORY_H + +#include "qtpropertymanager.h" + +class QLineEdit; + +class QT_QTPROPERTYBROWSER_EXPORT FilenameEditorFactory : public QtAbstractEditorFactory<QtStringPropertyManager> +{ + Q_OBJECT +public: + FilenameEditorFactory(QObject *parent = 0): QtAbstractEditorFactory<QtStringPropertyManager>(parent){} +protected: + void connectPropertyManager(QtStringPropertyManager *manager); + QWidget *createEditor(QtStringPropertyManager *manager, QtProperty *property, + QWidget *parent); + void disconnectPropertyManager(QtStringPropertyManager *manager); +}; + +class QT_QTPROPERTYBROWSER_EXPORT FilenameEditor: public QWidget +{ + Q_OBJECT +public: + FilenameEditor(QtProperty *property, QWidget *parent); + ~FilenameEditor(); +private slots: + void runDialog(); + void updateProperty(); +private: + QLineEdit* m_lineEdit; + QtProperty* m_property; +}; + +#endif diff --git a/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.cpp b/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.cpp index c991e157846b16d8db4df5546c39c66fc925f096..3d6915d4ad661893d1a6ec5d6a0b4f6e3b5abc65 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.cpp @@ -10,6 +10,8 @@ #include "MantidAPI/IConstraint.h" #include "MantidAPI/ConstraintFactory.h" +#include "FilenameEditorFactory.h" + #include "qttreepropertybrowser.h" #include "qtpropertymanager.h" #include "qteditorfactory.h" @@ -22,6 +24,8 @@ #include <QMenu> #include <QMessageBox> #include <QInputDialog> +#include <QSettings> +#include <QFileInfo> /** * Constructor @@ -46,6 +50,7 @@ m_guessOutputName(true),m_changeSlotsEnabled(true),m_peakToolOn(false),m_appWind m_enumManager = new QtEnumPropertyManager(w); m_intManager = new QtIntPropertyManager(w); m_boolManager = new QtBoolPropertyManager(w); + m_filenameManager = new QtStringPropertyManager(w); /* Create the top level group */ @@ -56,6 +61,7 @@ m_guessOutputName(true),m_changeSlotsEnabled(true),m_peakToolOn(false),m_appWind connect(m_intManager,SIGNAL(propertyChanged(QtProperty*)),this,SLOT(intChanged(QtProperty*))); connect(m_doubleManager,SIGNAL(propertyChanged(QtProperty*)),this,SLOT(doubleChanged(QtProperty*))); connect(m_stringManager,SIGNAL(propertyChanged(QtProperty*)),this,SLOT(stringChanged(QtProperty*))); + connect(m_filenameManager,SIGNAL(propertyChanged(QtProperty*)),this,SLOT(filenameChanged(QtProperty*))); /* Create function group */ @@ -93,6 +99,7 @@ m_guessOutputName(true),m_changeSlotsEnabled(true),m_peakToolOn(false),m_appWind QtSpinBoxFactory *spinBoxFactory = new QtSpinBoxFactory(w); QtDoubleSpinBoxFactory *doubleSpinBoxFactory = new QtDoubleSpinBoxFactory(w); QtLineEditFactory *lineEditFactory = new QtLineEditFactory(w); + FilenameEditorFactory* filenameEditFactory = new FilenameEditorFactory(w); m_browser = new QtTreePropertyBrowser(); m_browser->setFactoryForManager(m_enumManager, comboBoxFactory); @@ -100,6 +107,7 @@ m_guessOutputName(true),m_changeSlotsEnabled(true),m_peakToolOn(false),m_appWind m_browser->setFactoryForManager(m_intManager, spinBoxFactory); m_browser->setFactoryForManager(m_doubleManager, doubleSpinBoxFactory); m_browser->setFactoryForManager(m_stringManager, lineEditFactory); + m_browser->setFactoryForManager(m_filenameManager, filenameEditFactory); m_functionsGroup = m_browser->addProperty(functionsGroup); m_settingsGroup = m_browser->addProperty(settingsGroup); @@ -738,7 +746,7 @@ void FitPropertyBrowser::stringChanged(QtProperty* prop) } } else if (prop->propertyName() == "Tie") - { + {// ------- need to change this code for setting a tie from the property editor --------- //for(int i=0;i<m_ties.size();i++) //{ // if (prop == m_ties[i].getProperty()) @@ -781,10 +789,9 @@ void FitPropertyBrowser::stringChanged(QtProperty* prop) if (fun) { std::string attrName = prop->propertyName().toStdString(); - std::string attrValue = m_stringManager->value(prop).toStdString(); try { - fun->setAttribute(attrName,attrValue); + fun->setAttribute(attrName,m_stringManager->value(prop).toStdString()); m_compositeFunction->checkFunction(); removeFunProperties(fnItem->property(),true); addFunProperties(fun,true); @@ -797,6 +804,45 @@ void FitPropertyBrowser::stringChanged(QtProperty* prop) } } +/** Called when a filename property changed + * @param prop A pointer to the property + */ +void FitPropertyBrowser::filenameChanged(QtProperty* prop) +{ + if ( ! m_changeSlotsEnabled ) return; + + if (m_paramItems.contains(prop)) + {// Check if it is a function attribute + QtBrowserItem* attrItem = m_paramItems[prop]; + QtBrowserItem* fnItem = attrItem->parent(); + if (fnItem && m_functionItems.contains(fnItem)) + { + Mantid::API::IFunction* fun = m_functionItems[fnItem]; + if (fun) + { + std::string attrName = prop->propertyName().toStdString(); + std::string attrValue = m_filenameManager->value(prop).toStdString(); + try + { + fun->setAttribute(attrName,attrValue); + m_compositeFunction->checkFunction(); + removeFunProperties(fnItem->property(),true); + addFunProperties(fun,true); + QFileInfo finfo(QString::fromStdString(attrValue)); + QSettings settings; + settings.setValue("Mantid/FitBrowser/ResolutionDir",finfo.absolutePath()); + } + catch(std::exception& e) + { + std::cerr<<"Error "<<e.what()<<'\n'; + QMessageBox::critical(this,"Mantid - Error","Error in loading a resolution file.\n" + "The file must have two or more columns of numbers.\n" + "The first two columns are x and y-values of the resolution."); + } + } + } + } +} // Centre of the current peak double FitPropertyBrowser::centre()const { @@ -870,8 +916,8 @@ void FitPropertyBrowser::populateFunctionNames() for(size_t i=0;i<names.size();i++) { std::string fnName = names[i]; - if (fnName != "Convolution") - { + //if (fnName != "Convolution") + //{ QString qfnName = QString::fromStdString(fnName); m_registeredFunctions << qfnName; boost::shared_ptr<Mantid::API::IFunction> f = Mantid::API::FunctionFactory::Instance().create(fnName); @@ -886,7 +932,7 @@ void FitPropertyBrowser::populateFunctionNames() { m_registeredBackgrounds << qfnName; } - } + //} } } @@ -1661,17 +1707,6 @@ void FitPropertyBrowser::removeFunProperties(QtProperty* fnProp,bool doubleOnly) { QtProperty* parProp = subs[i]; if (doubleOnly && parProp->propertyManager() != m_doubleManager) continue; - //for(int t=0;t<m_ties.size();) - //{ - // if (m_ties[t].getProperty() == parProp) - // { - // m_ties.removeAt(t); - // } - // else - // { - // ++t; - // } - //} QMap<QtProperty*,std::pair<QtProperty*,QtProperty*> >::iterator cit = m_constraints.find(parProp); if (cit != m_constraints.end()) { @@ -1715,9 +1750,22 @@ void FitPropertyBrowser::addFunProperties(Mantid::API::IFunction* f,bool doubleO std::vector<std::string> attr = f->getAttributeNames(); for(size_t i=0;i<attr.size();i++) { - QtProperty* parProp = m_stringManager->addProperty(QString::fromStdString(attr[i])); - fnProp->addSubProperty(parProp); - m_stringManager->setValue(parProp,QString::fromStdString(f->getAttribute(attr[i]))); + std::string attName = attr[i]; + QtProperty* parProp = 0; + + if (attName == "FileName") + { + parProp = m_filenameManager->addProperty(QString::fromStdString(attName)); + fnProp->addSubProperty(parProp); + m_filenameManager->setValue(parProp,QString::fromStdString(f->getAttribute(attName))); + } + else + { + parProp = m_stringManager->addProperty(QString::fromStdString(attName)); + fnProp->addSubProperty(parProp); + m_stringManager->setValue(parProp,QString::fromStdString(f->getAttribute(attName))); + } + QtBrowserItem* attrItem = findItem(m_functionsGroup,parProp); if (attrItem) { diff --git a/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.h b/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.h index 1c3217205ab62dbf922480670c93af1e10ecf33c..61d0b174354b00a081ad7cc79b53f248bd64ed9f 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.h +++ b/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.h @@ -177,6 +177,7 @@ private slots: void intChanged(QtProperty* prop); void doubleChanged(QtProperty* prop); void stringChanged(QtProperty* prop); + void filenameChanged(QtProperty* prop); void workspace_added(const QString &, Mantid::API::Workspace_sptr); void workspace_removed(const QString &); void currentItemChanged(QtBrowserItem*); @@ -265,6 +266,7 @@ private: QtEnumPropertyManager *m_enumManager; QtIntPropertyManager *m_intManager; QtBoolPropertyManager *m_boolManager; + QtStringPropertyManager *m_filenameManager; /// Properties: mutable Mantid::API::IFunction* m_currentFunction; diff --git a/Code/qtiplot/qtiplot/src/Mantid/PeakPickerTool.cpp b/Code/qtiplot/qtiplot/src/Mantid/PeakPickerTool.cpp index bc3d4280ca2b37f6875559fbfcdd732115c513a1..370d7a0ecf43ed622373136b58d25103227a987e 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/PeakPickerTool.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/PeakPickerTool.cpp @@ -82,10 +82,12 @@ m_defaultPeakName("Gaussian") attach(d_graph->plotWidget()); d_graph->plotWidget()->replot(); } + connect(d_graph,SIGNAL(curveRemoved()),this,SLOT(curveRemoved())); } PeakPickerTool::~PeakPickerTool() { + disconnect(d_graph,SIGNAL(curveRemoved()),this,SLOT(curveRemoved())); QMap<Mantid::API::IFunction*,FunctionCurve*>::iterator it = m_guessCurves.begin(); for(;it!=m_guessCurves.end();it++) { @@ -866,3 +868,26 @@ bool PeakPickerTool::hasGuessPlotted(Mantid::API::IFunction* f) { return m_guessCurves.find(f) != m_guessCurves.end(); } + +void PeakPickerTool::curveRemoved() +{ + checkPlots(); +} + +void PeakPickerTool::checkPlots() +{ + QMap<Mantid::API::IFunction*,FunctionCurve*>::iterator it = m_guessCurves.begin(); + for(;it!=m_guessCurves.end();) + { + int index = d_graph->curveIndex(dynamic_cast<QwtPlotCurve*>(it.value())); + if (!fitBrowser()->theFunction()->getContainingFunction(it.key()) || index < 0) + { + std::cerr<<"deleting plot for "<<it.key()->name()<<'\n'; + it = m_guessCurves.erase(it); + } + else + { + ++it; + } + } +} diff --git a/Code/qtiplot/qtiplot/src/Mantid/PeakPickerTool.h b/Code/qtiplot/qtiplot/src/Mantid/PeakPickerTool.h index 41ca58f7ed2b4ce169d75512efe715d3ccfa760a..d4afef3d8053a4b9cca1dd12e5170016bb80c94f 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/PeakPickerTool.h +++ b/Code/qtiplot/qtiplot/src/Mantid/PeakPickerTool.h @@ -121,6 +121,8 @@ private slots: void plotAllGuess(); void removeAllGuess(); + void curveRemoved(); + private: virtual void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &) const; // Add a new peak with centre c and height h. @@ -174,6 +176,9 @@ private: // Shows if a function i is plotted bool hasGuessPlotted(Mantid::API::IFunction*); + // Checks that the plotted functions exist + void checkPlots(); + FitPropertyBrowser* fitBrowser()const; /// The parent application window MantidUI* m_mantidUI;