Skip to content

Commit

Permalink
plugins: continued with help text interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tweber-ill committed Oct 9, 2023
1 parent deeabef commit a5e558a
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 29 deletions.
52 changes: 44 additions & 8 deletions core/tools/monteconvo/ConvoDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,15 @@ ConvoDlg::ConvoDlg(QWidget* pParent, QSettings* pSett)
auto vecSqwNames = get_sqw_names();
for(const auto& tupSqw : vecSqwNames)
{
QString strIdent = std::get<0>(tupSqw).c_str();
QString strName = std::get<1>(tupSqw).c_str();
const std::string& strIdent = std::get<0>(tupSqw);
const std::string& strName = std::get<1>(tupSqw);
const std::string& strHelp = std::get<2>(tupSqw);

comboSqw->addItem(strName, strIdent);
// add module item to combo box
comboSqw->addItem(strName.c_str(), strIdent.c_str());

// add module help text
m_help_texts.insert(std::make_pair(strIdent, strHelp));
}
// --------------------------------------------------------------------

Expand Down Expand Up @@ -369,6 +374,7 @@ ConvoDlg::ConvoDlg(QWidget* pParent, QSettings* pSett)
connect(btnBrowseAutosave, &QAbstractButton::clicked, this, &ConvoDlg::browseAutosaveFile);
connect(btnFav, &QAbstractButton::clicked, this, &ConvoDlg::ShowFavourites);
connect(btnSqwParams, &QAbstractButton::clicked, this, &ConvoDlg::showSqwParamDlg);
connect(btnSqwHelp, &QAbstractButton::clicked, this, &ConvoDlg::showSqwHelpDlg);
connect(btnSaveResults, &QAbstractButton::clicked,
[this]()
{
Expand Down Expand Up @@ -415,7 +421,7 @@ ConvoDlg::ConvoDlg(QWidget* pParent, QSettings* pSett)
&& find_resource_dirs("Frameworks/Python.framework", false).size()==0)
{
QMessageBox::information(this, "Python Module",
"The <i>Python</i> S(q,w) plugin module requires having the "
"The <i>Python</i> S(Q,E) plugin module requires having the "
"<a href=\"https://www.python.org/downloads/mac-osx/\">Python framework</a> installed.<br><br>"
"Please also install the <i>numpy</i> and <i>scipy</i> packages using the following command:<br><br>"
"<code>/Library/Frameworks/Python.framework/Versions/Current/bin/pip3 install numpy scipy</code>");
Expand Down Expand Up @@ -462,6 +468,7 @@ void ConvoDlg::createSqwModel(const QString& qstrFile)
emit SqwLoaded(std::vector<SqwBase::t_var>{}, nullptr);
}

// identifier of the currently selected module
std::string strSqwIdent = comboSqw->itemData(comboSqw->currentIndex()).toString().toStdString();
if(strSqwIdent == "")
return;
Expand All @@ -472,15 +479,15 @@ void ConvoDlg::createSqwModel(const QString& qstrFile)

if(strSqwFile == "")
{
tl::log_warn("No S(q,w) config file given.");
tl::log_warn("No S(Q,E) config file given.");
//return;
}

m_pSqw.reset();
m_pSqw = construct_sqw(strSqwIdent, strSqwFile);
if(!m_pSqw)
{
QMessageBox::critical(this, "Error", "Unknown S(q,w) model selected.");
QMessageBox::critical(this, "Error", "Unknown S(Q,E) model selected.");
return;
}

Expand All @@ -490,8 +497,8 @@ void ConvoDlg::createSqwModel(const QString& qstrFile)
}
else
{
//QMessageBox::critical(this, "Error", "Could not create S(q,w).");
tl::log_err("Could not create S(q,w).");
//QMessageBox::critical(this, "Error", "Could not create S(Q,E).");
tl::log_err("Could not create S(Q,E).");
return;
}
}
Expand Down Expand Up @@ -788,6 +795,35 @@ void ConvoDlg::showSqwParamDlg()
}


void ConvoDlg::showSqwHelpDlg()
{
// identifier of the currently selected S(Q,E) module
std::string strSqwIdent = comboSqw->itemData(comboSqw->currentIndex()).toString().toStdString();
if(strSqwIdent == "")
return;

// S(Q,E) module name
QString strSqwLongName = comboSqw->itemText(comboSqw->currentIndex());

auto iter = m_help_texts.find(strSqwIdent);
if(iter == m_help_texts.end())
{
QMessageBox::warning(this, strSqwLongName, "No help text was found.");
return;
}

// no help text
if(iter->second == "")
{
QMessageBox::warning(this, strSqwLongName, "No help text was defined.");
return;
}

// display help
QMessageBox::information(this, strSqwLongName, iter->second.c_str());
}


#include "libs/version.h"

void ConvoDlg::ShowAboutDlg()
Expand Down
8 changes: 7 additions & 1 deletion core/tools/monteconvo/ConvoDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <thread>
#include <atomic>
#include <memory>
#include <map>
#include <unordered_map>

#include "ui/ui_monteconvo.h"

Expand Down Expand Up @@ -82,7 +84,10 @@ class ConvoDlg : public QDialog, Ui::ConvoDlg
static const std::string s_strTitle;
std::string m_strLastFile;

t_real_reso m_chi2;
t_real_reso m_chi2 = 0.;

// maps module identifiers to the corresponding module help texts
std::unordered_map<std::string, std::string> m_help_texts;


protected:
Expand Down Expand Up @@ -136,6 +141,7 @@ class ConvoDlg : public QDialog, Ui::ConvoDlg

protected slots:
void showSqwParamDlg();
void showSqwHelpDlg();

void browseCrysFiles();
void browseResoFiles();
Expand Down
2 changes: 1 addition & 1 deletion core/tools/monteconvo/ConvoDlg_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ void ConvoDlg::browseSqwFiles()
if(m_pSett)
strDirLast = m_pSett->value("monteconvo/last_dir_sqw", "~").toString();
QString strFile = QFileDialog::getOpenFileName(this,
"Open S(q,w) File", strDirLast, "All S(q,w) files (*.dat *.DAT *.py *.PY *.jl *.JL *.XML *.xml *.MAGDYN *.magdyn)",
"Open S(q,E) File", strDirLast, "All S(q,E) files (*.dat *.DAT *.py *.PY *.jl *.JL *.XML *.xml *.MAGDYN *.magdyn);;All files (*.* *)",
nullptr, fileopt);
if(strFile == "")
return;
Expand Down
16 changes: 8 additions & 8 deletions core/tools/monteconvo/ConvoDlg_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void ConvoDlg::StartSim1D(bool bForceDeferred, unsigned int seed)

if(m_pSqw == nullptr || !m_pSqw->IsOk())
{
//QMessageBox::critical(this, "Error", "No valid S(q,w) model loaded.");
//QMessageBox::critical(this, "Error", "No valid S(Q,E) model loaded.");
fktEnableButtons();
return;
}
Expand Down Expand Up @@ -283,7 +283,7 @@ void ConvoDlg::StartSim1D(bool bForceDeferred, unsigned int seed)
t_real dhklE_mean[4] = {0., 0., 0., 0.};

if(iNumNeutrons == 0)
{ // if no neutrons are given, just plot the unconvoluted S(q,w)
{ // if no neutrons are given, just plot the unconvoluted S(Q,E)
// TODO: add an option to let the user choose if S(Q,E) is
// really the dynamical structure factor, or its absolute square
dS += (*m_pSqw)(dCurH, dCurK, dCurL, dCurE);
Expand Down Expand Up @@ -365,7 +365,7 @@ void ConvoDlg::StartSim1D(bool bForceDeferred, unsigned int seed)
if(tl::is_nan_or_inf(dS))
{
dS = t_real(0);
tl::log_warn("S(q,w) is invalid.");
tl::log_warn("S(Q,E) is invalid.");
}

ostrOut << std::left << std::setw(g_iPrec*2) << vecH[iStep] << " "
Expand Down Expand Up @@ -471,7 +471,7 @@ void ConvoDlg::StartSim1D(bool bForceDeferred, unsigned int seed)
ublas::vector<t_real> vecScanHKLE = tl::make_vec({ pt.h, pt.k, pt.l, E });


// find point on S(q,w) curve closest to scan point
// find point on S(Q,E) curve closest to scan point
std::size_t iMinIdx = 0;
t_real dMinDist = std::numeric_limits<t_real>::max();
for(std::size_t iStep=0; iStep<iNumSteps; ++iStep)
Expand Down Expand Up @@ -718,7 +718,7 @@ void ConvoDlg::Start2D()

if(m_pSqw == nullptr || !m_pSqw->IsOk())
{
//QMessageBox::critical(this, "Error", "No valid S(q,w) model loaded.");
//QMessageBox::critical(this, "Error", "No valid S(Q,E) model loaded.");
fktEnableButtons();
return;
}
Expand Down Expand Up @@ -796,7 +796,7 @@ void ConvoDlg::Start2D()
t_real dhklE_mean[4] = {0., 0., 0., 0.};

if(iNumNeutrons == 0)
{ // if no neutrons are given, just plot the unconvoluted S(q,w)
{ // if no neutrons are given, just plot the unconvoluted S(Q,E)
// TODO: add an option to let the user choose if S(Q,E) is
// really the dynamical structure factor, or its absolute square
dS += (*m_pSqw)(dCurH, dCurK, dCurL, dCurE);
Expand Down Expand Up @@ -872,7 +872,7 @@ void ConvoDlg::Start2D()
if(tl::is_nan_or_inf(dS))
{
dS = t_real(0);
tl::log_warn("S(q,w) is invalid.");
tl::log_warn("S(Q,E) is invalid.");
}

ostrOut << std::left << std::setw(g_iPrec*2) << vecH[iStep] << " "
Expand Down Expand Up @@ -1028,7 +1028,7 @@ void ConvoDlg::StartDisp()

if(m_pSqw == nullptr || !m_pSqw->IsOk())
{
//QMessageBox::critical(this, "Error", "No valid S(q,w) model loaded.");
//QMessageBox::critical(this, "Error", "No valid S(Q,E) model loaded.");
fktEnableButtons();
return;
}
Expand Down
8 changes: 6 additions & 2 deletions core/tools/monteconvo/sqwfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ static t_mapSqwExt g_mapSqwExt;

/**
* gets the short and long names of the installed plugin modules
* as well as the help texts
*/
std::vector<std::tuple<std::string, std::string>> get_sqw_names()
std::vector<std::tuple<std::string, std::string, std::string>> get_sqw_names()
{
using t_tup = std::tuple<std::string, std::string>;
using t_tup = std::tuple<std::string, std::string, std::string>;
std::vector<t_tup> vec;
vec.reserve(g_mapSqw.size());

Expand All @@ -162,6 +163,7 @@ std::vector<std::tuple<std::string, std::string>> get_sqw_names()
t_tup tup;
std::get<0>(tup) = val.first;
std::get<1>(tup) = std::get<1>(val.second);
std::get<2>(tup) = std::get<2>(val.second);

vec.emplace_back(std::move(tup));
}
Expand All @@ -171,6 +173,7 @@ std::vector<std::tuple<std::string, std::string>> get_sqw_names()
t_tup tup;
std::get<0>(tup) = val.first;
std::get<1>(tup) = std::get<2>(val.second);
std::get<2>(tup) = std::get<3>(val.second);

vec.emplace_back(std::move(tup));
}
Expand All @@ -180,6 +183,7 @@ std::vector<std::tuple<std::string, std::string>> get_sqw_names()
t_tup tup;
std::get<0>(tup) = val.first;
std::get<1>(tup) = std::get<0>(val.second);
std::get<2>(tup) = std::get<2>(val.second);

vec.emplace_back(std::move(tup));
}
Expand Down
4 changes: 2 additions & 2 deletions core/tools/monteconvo/sqwfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
extern std::shared_ptr<SqwBase> construct_sqw(const std::string& strName,
const std::string& strConfigFile);

// [identifier, long name]
extern std::vector<std::tuple<std::string, std::string>> get_sqw_names();
// [identifier, long name, help text]
extern std::vector<std::tuple<std::string, std::string, std::string>> get_sqw_names();


extern void unload_sqw_plugins();
Expand Down
31 changes: 24 additions & 7 deletions core/ui/monteconvo.ui
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>Monte-Carlo steps for sample convolution (only for Eckold-Sobolev algorithm)</string>
<string>Monte-Carlo steps for sample convolution (only for Eckold-Sobolev algorithm).</string>
</property>
<property name="minimum">
<number>1</number>
Expand Down Expand Up @@ -361,7 +361,7 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>Monte-Carlo steps for overall convolution</string>
<string>Monte-Carlo steps for overall convolution.</string>
</property>
<property name="suffix">
<string/>
Expand Down Expand Up @@ -514,7 +514,7 @@
<item row="1" column="1">
<widget class="QLineEdit" name="editSqw"/>
</item>
<item row="1" column="2">
<item row="1" column="3">
<widget class="QToolButton" name="btnBrowseSqw">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
Expand All @@ -523,14 +523,30 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>Browse for S(q,w) files.</string>
<string>Browse for S(Q,E) configuration files.</string>
</property>
<property name="text">
<string>Browse...</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="btnSqwHelp">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Show the S(Q,E) module's help.</string>
</property>
<property name="text">
<string>?</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QToolButton" name="btnSqwParams">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Minimum">
Expand All @@ -539,7 +555,7 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>S(q,w) model parameters.</string>
<string>Set S(Q,E) model parameters.</string>
</property>
<property name="text">
<string>Parameters...</string>
Expand Down Expand Up @@ -615,7 +631,7 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>Browse for crystal files</string>
<string>Browse for crystal files.</string>
</property>
<property name="text">
<string>...</string>
Expand Down Expand Up @@ -654,7 +670,7 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>Browse for resolution files</string>
<string>Browse for resolution files.</string>
</property>
<property name="text">
<string>...</string>
Expand Down Expand Up @@ -1926,6 +1942,7 @@
<tabstop>comboFocAna</tabstop>
<tabstop>comboAxis2</tabstop>
<tabstop>comboSqw</tabstop>
<tabstop>btnSqwHelp</tabstop>
<tabstop>btnSqwParams</tabstop>
<tabstop>editSqw</tabstop>
<tabstop>btnBrowseSqw</tabstop>
Expand Down

0 comments on commit a5e558a

Please sign in to comment.