Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
0d83f76c
Commit
0d83f76c
authored
Oct 18, 2019
by
Anthony Lim
Browse files
refs #26544 moved the fit function generation to model for ALFView
parent
a3f41ae8
Changes
8
Hide whitespace changes
Inline
Side-by-side
qt/scientific_interfaces/Direct/ALFView.cpp
View file @
0d83f76c
...
...
@@ -31,8 +31,7 @@ Mantid::Kernel::Logger g_log("ALFView");
ALFView
::
ALFView
(
QWidget
*
parent
)
:
UserSubWindow
(
parent
),
m_view
(
nullptr
),
m_presenter
(
nullptr
),
m_analysisPane
(
nullptr
),
m_extractSingleTubeObserver
(
nullptr
),
m_averageTubeObserver
(
nullptr
)
{
m_analysisPane
(
nullptr
)
{
m_model
=
new
ALFView_model
();
m_view
=
new
ALFView_view
(
m_model
->
getInstrument
(),
this
);
auto
analysisView
=
new
PlotFitAnalysisPaneView
(
-
15.0
,
15.0
,
m_view
);
...
...
@@ -42,77 +41,8 @@ ALFView::ALFView(QWidget *parent)
m_presenter
=
new
ALFView_presenter
(
m_view
,
m_model
,
m_analysisPane
);
}
void
ALFView
::
initLayout
()
{
this
->
setCentralWidget
(
m_view
);
}
void
ALFView
::
initLayout
()
{
this
->
setCentralWidget
(
m_view
);
m_extractSingleTubeObserver
=
new
VoidObserver
();
m_averageTubeObserver
=
new
VoidObserver
();
auto
setUp
=
initInstrument
();
m_presenter
->
initLayout
(
&
setUp
);
}
typedef
std
::
pair
<
std
::
string
,
std
::
vector
<
std
::
function
<
bool
(
std
::
map
<
std
::
string
,
bool
>
)
>>>
instrumentSetUp
;
typedef
std
::
vector
<
std
::
tuple
<
std
::
string
,
Observer
*>>
instrumentObserverOptions
;
/**
* This creates the custom instrument widget
* @return <instrumentSetUp,
instrumentObserverOptions> : a pair of the
*/
std
::
pair
<
instrumentSetUp
,
instrumentObserverOptions
>
ALFView
::
initInstrument
()
{
instrumentSetUp
setUpContextConditions
;
// set up the slots for the custom context menu
std
::
vector
<
std
::
tuple
<
std
::
string
,
Observer
*>>
customInstrumentOptions
;
std
::
vector
<
std
::
function
<
bool
(
std
::
map
<
std
::
string
,
bool
>
)
>>
binders
;
// set up custom context menu conditions
std
::
function
<
bool
(
std
::
map
<
std
::
string
,
bool
>
)
>
extractConditionBinder
=
std
::
bind
(
&
ALFView_model
::
extractTubeConditon
,
m_model
,
std
::
placeholders
::
_1
);
std
::
function
<
bool
(
std
::
map
<
std
::
string
,
bool
>
)
>
averageTubeConditonBinder
=
std
::
bind
(
&
ALFView_model
::
averageTubeConditon
,
m_model
,
std
::
placeholders
::
_1
);
binders
.
push_back
(
extractConditionBinder
);
binders
.
push_back
(
averageTubeConditonBinder
);
setUpContextConditions
=
std
::
make_pair
(
m_model
->
dataFileName
(),
binders
);
// set up single tube extract
std
::
function
<
void
()
>
extractSingleTubeBinder
=
std
::
bind
(
&
ALFView
::
extractSingleTube
,
this
);
// binder for slot
m_extractSingleTubeObserver
->
setSlot
(
extractSingleTubeBinder
);
// add slot to observer
std
::
tuple
<
std
::
string
,
Observer
*>
tmp
=
std
::
make_tuple
(
"singleTube"
,
m_extractSingleTubeObserver
);
// store observer for later
customInstrumentOptions
.
push_back
(
tmp
);
// set up average tube
std
::
function
<
void
()
>
averageTubeBinder
=
std
::
bind
(
&
ALFView
::
averageTube
,
this
);
m_averageTubeObserver
->
setSlot
(
averageTubeBinder
);
tmp
=
std
::
make_tuple
(
"averageTube"
,
m_averageTubeObserver
);
customInstrumentOptions
.
push_back
(
tmp
);
return
std
::
make_pair
(
setUpContextConditions
,
customInstrumentOptions
);
}
void
ALFView
::
extractSingleTube
()
{
m_model
->
extractSingleTube
();
m_analysisPane
->
addSpectrum
(
m_model
->
WSName
());
}
void
ALFView
::
averageTube
()
{
m_model
->
averageTube
();
m_analysisPane
->
addSpectrum
(
m_model
->
WSName
());
}
}
// namespace CustomInterfaces
}
// namespace MantidQt
qt/scientific_interfaces/Direct/ALFView.h
View file @
0d83f76c
...
...
@@ -29,9 +29,6 @@ public:
ALFView
(
QWidget
*
parent
=
nullptr
);
~
ALFView
()
{
delete
m_presenter
;
delete
m_model
;
delete
m_extractSingleTubeObserver
;
delete
m_averageTubeObserver
;
};
static
std
::
string
name
()
{
return
"ALF View"
;
}
static
QString
categoryInfo
()
{
return
"Direct"
;
}
...
...
@@ -40,23 +37,11 @@ protected:
void
initLayout
()
override
;
private:
typedef
std
::
pair
<
std
::
string
,
std
::
vector
<
std
::
function
<
bool
(
std
::
map
<
std
::
string
,
bool
>
)
>>>
instrumentSetUp
;
typedef
std
::
vector
<
std
::
tuple
<
std
::
string
,
Observer
*>>
instrumentObserverOptions
;
std
::
pair
<
instrumentSetUp
,
instrumentObserverOptions
>
initInstrument
();
void
extractSingleTube
();
void
averageTube
();
ALFView_view
*
m_view
;
ALFView_model
*
m_model
;
ALFView_presenter
*
m_presenter
;
PlotFitAnalysisPanePresenter
*
m_analysisPane
;
VoidObserver
*
m_extractSingleTubeObserver
;
VoidObserver
*
m_averageTubeObserver
;
};
}
// namespace CustomInterfaces
...
...
qt/scientific_interfaces/Direct/ALFView_model.cpp
View file @
0d83f76c
...
...
@@ -27,8 +27,7 @@ using namespace Mantid::API;
namespace
MantidQt
{
namespace
CustomInterfaces
{
ALFView_model
::
ALFView_model
()
:
m_numberOfTubesInAverage
(
0
)
{
ALFView_model
::
ALFView_model
()
:
m_numberOfTubesInAverage
(
0
),
m_currentRun
(
0
)
{
setTmpName
(
"ALF_tmp"
);
setInstrumentName
(
"ALF"
);
setWSName
(
"ALFData"
);
...
...
@@ -196,7 +195,21 @@ void ALFView_model::extractSingleTube() {
m_numberOfTubesInAverage
=
1
;
}
CompositeFunction_sptr
ALFView_model
::
getDefaultFunction
()
{
CompositeFunction_sptr
composite
=
boost
::
dynamic_pointer_cast
<
Mantid
::
API
::
CompositeFunction
>
(
Mantid
::
API
::
FunctionFactory
::
Instance
().
createFunction
(
"CompositeFunction"
));
auto
func
=
Mantid
::
API
::
FunctionFactory
::
Instance
().
createInitialized
(
"name = FlatBackground"
);
composite
->
addFunction
(
func
);
func
=
Mantid
::
API
::
FunctionFactory
::
Instance
().
createInitialized
(
"name = Gaussian, Height = 3., Sigma= 1.0"
);
composite
->
addFunction
(
func
);
return
composite
;
}
}
// namespace CustomInterfaces
}
// namespace MantidQt
qt/scientific_interfaces/Direct/ALFView_model.h
View file @
0d83f76c
...
...
@@ -8,6 +8,8 @@
#define MANTIDQT_CUSTOMINTERFACES_ALFVIEWMODEL_H_
#include
"BaseInstrumentModel.h"
#include
"MantidAPI/FunctionFactory.h"
#include
"MantidAPI/CompositeFunction.h"
#include
<map>
#include
<string>
...
...
@@ -32,6 +34,8 @@ public:
bool
averageTubeConditon
(
std
::
map
<
std
::
string
,
bool
>
tabBools
);
void
extractSingleTube
();
std
::
string
WSName
();
Mantid
::
API
::
CompositeFunction_sptr
getDefaultFunction
();
private:
int
m_numberOfTubesInAverage
;
int
m_currentRun
;
...
...
qt/scientific_interfaces/Direct/ALFView_presenter.cpp
View file @
0d83f76c
...
...
@@ -6,10 +6,10 @@
// SPDX - License - Identifier: GPL - 3.0 +
#include
"ALFView_presenter.h"
#include
"ALFView_view.h"
#include
"ALFView_model.h"
#include
"MantidAPI/CompositeFunction.h"
#include
"MantidAPI/FileFinder.h"
#include
"MantidAPI/FunctionFactory.h"
#include
<functional>
#include
<tuple>
...
...
@@ -17,31 +17,88 @@
namespace
MantidQt
{
namespace
CustomInterfaces
{
ALFView_presenter
::
ALFView_presenter
(
ALFView_view
*
view
,
BaseInstrumentModel
*
model
,
ALFView_presenter
::
ALFView_presenter
(
ALFView_view
*
view
,
ALFView_model
*
model
,
PlotFitAnalysisPanePresenter
*
analysisPane
)
:
BaseInstrumentPresenter
(
view
,
model
,
analysisPane
->
getView
()),
m_view
(
view
),
m_model
(
model
),
m_analysisPane
(
analysisPane
)
{
:
BaseInstrumentPresenter
(
view
,
model
,
analysisPane
->
getView
()),
m_view
(
view
),
m_model
(
model
),
m_analysisPane
(
analysisPane
),
m_extractSingleTubeObserver
(
nullptr
),
m_averageTubeObserver
(
nullptr
)
{
m_extractSingleTubeObserver
=
new
VoidObserver
();
m_averageTubeObserver
=
new
VoidObserver
();
auto
setUp
=
initInstrument
();
initLayout
(
&
setUp
);
}
void
ALFView_presenter
::
setUpInstrumentAnalysisSplitter
()
{
auto
composite
=
boost
::
dynamic_pointer_cast
<
Mantid
::
API
::
CompositeFunction
>
(
Mantid
::
API
::
FunctionFactory
::
Instance
().
createFunction
(
"CompositeFunction"
));
auto
func
=
Mantid
::
API
::
FunctionFactory
::
Instance
().
createInitialized
(
"name = FlatBackground"
);
composite
->
addFunction
(
func
);
func
=
Mantid
::
API
::
FunctionFactory
::
Instance
().
createInitialized
(
"name = Gaussian, Height = 3000, Sigma= 1.0"
);
composite
->
addFunction
(
func
);
CompositeFunction_sptr
composite
=
m_model
->
getDefaultFunction
();
m_analysisPane
->
addFunction
(
composite
);
m_view
->
setupAnalysisPane
(
m_analysisPane
->
getView
());
}
// want to pass the presenter not the view...
void
ALFView_presenter
::
loadSideEffects
()
{
m_analysisPane
->
clearCurrentWS
();
}
typedef
std
::
pair
<
std
::
string
,
std
::
vector
<
std
::
function
<
bool
(
std
::
map
<
std
::
string
,
bool
>
)
>>>
instrumentSetUp
;
typedef
std
::
vector
<
std
::
tuple
<
std
::
string
,
Observer
*>>
instrumentObserverOptions
;
/**
* This creates the custom instrument widget
* @return <instrumentSetUp,
instrumentObserverOptions> : a pair of the
*/
std
::
pair
<
instrumentSetUp
,
instrumentObserverOptions
>
ALFView_presenter
::
initInstrument
()
{
instrumentSetUp
setUpContextConditions
;
// set up the slots for the custom context menu
std
::
vector
<
std
::
tuple
<
std
::
string
,
Observer
*>>
customInstrumentOptions
;
std
::
vector
<
std
::
function
<
bool
(
std
::
map
<
std
::
string
,
bool
>
)
>>
binders
;
// set up custom context menu conditions
std
::
function
<
bool
(
std
::
map
<
std
::
string
,
bool
>
)
>
extractConditionBinder
=
std
::
bind
(
&
ALFView_model
::
extractTubeConditon
,
m_model
,
std
::
placeholders
::
_1
);
std
::
function
<
bool
(
std
::
map
<
std
::
string
,
bool
>
)
>
averageTubeConditonBinder
=
std
::
bind
(
&
ALFView_model
::
averageTubeConditon
,
m_model
,
std
::
placeholders
::
_1
);
binders
.
push_back
(
extractConditionBinder
);
binders
.
push_back
(
averageTubeConditonBinder
);
setUpContextConditions
=
std
::
make_pair
(
m_model
->
dataFileName
(),
binders
);
// set up single tube extract
std
::
function
<
void
()
>
extractSingleTubeBinder
=
std
::
bind
(
&
ALFView_presenter
::
extractSingleTube
,
this
);
// binder for slot
m_extractSingleTubeObserver
->
setSlot
(
extractSingleTubeBinder
);
// add slot to observer
std
::
tuple
<
std
::
string
,
Observer
*>
tmp
=
std
::
make_tuple
(
"singleTube"
,
m_extractSingleTubeObserver
);
// store observer for later
customInstrumentOptions
.
push_back
(
tmp
);
// set up average tube
std
::
function
<
void
()
>
averageTubeBinder
=
std
::
bind
(
&
ALFView_presenter
::
averageTube
,
this
);
m_averageTubeObserver
->
setSlot
(
averageTubeBinder
);
tmp
=
std
::
make_tuple
(
"averageTube"
,
m_averageTubeObserver
);
customInstrumentOptions
.
push_back
(
tmp
);
return
std
::
make_pair
(
setUpContextConditions
,
customInstrumentOptions
);
}
void
ALFView_presenter
::
extractSingleTube
()
{
m_model
->
extractSingleTube
();
m_analysisPane
->
addSpectrum
(
m_model
->
WSName
());
}
void
ALFView_presenter
::
averageTube
()
{
m_model
->
averageTube
();
m_analysisPane
->
addSpectrum
(
m_model
->
WSName
());
}
}
// namespace CustomInterfaces
}
// namespace MantidQt
\ No newline at end of file
qt/scientific_interfaces/Direct/ALFView_presenter.h
View file @
0d83f76c
...
...
@@ -7,12 +7,11 @@
#ifndef MANTIDQT_CUSTOMINTERFACES_ALFVIEWPRESENTER_H_
#define MANTIDQT_CUSTOMINTERFACES_ALFVIEWPRESENTER_H_
#include
"BaseInstrumentModel.h"
#include
"BaseInstrumentPresenter.h"
#include
"BaseInstrumentView.h"
#include
"PlotFitAnalysisPanePresenter.h"
#include
"ALFView_view.h"
#include
"ALFView_model.h"
#include
"DllConfig.h"
#include
"MantidQtWidgets/Common/ObserverPattern.h"
#include
"MantidQtWidgets/Common/UserSubWindow.h"
...
...
@@ -26,19 +25,37 @@ class MANTIDQT_DIRECT_DLL ALFView_presenter : public BaseInstrumentPresenter {
Q_OBJECT
public:
ALFView_presenter
(
ALFView_view
*
view
,
BaseInstrumentM
odel
*
model
,
ALFView_presenter
(
ALFView_view
*
view
,
ALFView_m
odel
*
model
,
PlotFitAnalysisPanePresenter
*
analysisPane
);
~
ALFView_presenter
(){};
~
ALFView_presenter
()
{
delete
m_extractSingleTubeObserver
;
delete
m_averageTubeObserver
;
delete
m_analysisPane
;
delete
m_model
;};
protected:
void
loadSideEffects
()
override
;
private:
void
setUpInstrumentAnalysisSplitter
()
override
;
typedef
std
::
pair
<
std
::
string
,
std
::
vector
<
std
::
function
<
bool
(
std
::
map
<
std
::
string
,
bool
>
)
>>>
instrumentSetUp
;
typedef
std
::
vector
<
std
::
tuple
<
std
::
string
,
Observer
*>>
instrumentObserverOptions
;
std
::
pair
<
instrumentSetUp
,
instrumentObserverOptions
>
initInstrument
();
void
extractSingleTube
();
void
averageTube
();
ALFView_view
*
m_view
;
BaseInstrumentM
odel
*
m_model
;
ALFView_m
odel
*
m_model
;
PlotFitAnalysisPanePresenter
*
m_analysisPane
;
VoidObserver
*
m_extractSingleTubeObserver
;
VoidObserver
*
m_averageTubeObserver
;
};
}
// namespace CustomInterfaces
}
// namespace MantidQt
...
...
qt/scientific_interfaces/Direct/PlotFitAnalysisPanePresenter.cpp
View file @
0d83f76c
...
...
@@ -30,15 +30,13 @@ PlotFitAnalysisPanePresenter::PlotFitAnalysisPanePresenter(
void
PlotFitAnalysisPanePresenter
::
doFit
()
{
auto
func
=
m_view
->
getFunction
();
auto
d
=
func
->
nParams
();
if
(
m_currentName
!=
""
&&
func
->
nParams
()
!=
0
)
{
try
{
func
=
m_model
->
doFit
(
m_currentName
,
m_view
->
getRange
(),
func
);
m_view
->
updateFunction
(
func
);
}
catch
(
std
::
exception
&
error
)
{
}
catch
(
...
)
{
m_view
->
fitWarning
(
"Fit failed"
);
}
m_view
->
addFitSpectrum
(
m_currentName
+
"_fits_Workspace"
);
}
else
{
...
...
qt/scientific_interfaces/Direct/PlotFitAnalysisPanePresenter.h
View file @
0d83f76c
...
...
@@ -22,7 +22,10 @@ class PlotFitAnalysisPanePresenter : public QObject {
public:
PlotFitAnalysisPanePresenter
(
PlotFitAnalysisPaneView
*
m_view
,
PlotFitAnalysisPaneModel
*
m_model
);
~
PlotFitAnalysisPanePresenter
(){};
~
PlotFitAnalysisPanePresenter
()
{
delete
m_model
;
delete
m_fitObserver
;
};
PlotFitAnalysisPaneView
*
getView
()
{
return
m_view
;
};
std
::
string
getCurrentWS
(){
return
m_currentName
;};
void
clearCurrentWS
()
{
m_currentName
=
""
;
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment