Skip to content

Commit

Permalink
Merge pull request #90 from aglowacki/master
Browse files Browse the repository at this point in the history
Added periodic table for picking elements
  • Loading branch information
aglowacki authored Aug 23, 2024
2 parents 88d73da + 55149bd commit 5a98316
Show file tree
Hide file tree
Showing 8 changed files with 434 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/mvc/FitElementsTableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ bool FitElementsTableModel::setData(const QModelIndex &index,
{
bool ok = false;
double dval = value.toDouble(&ok);
QVariant new_value = value;
if (false == ok)
{
QMessageBox::warning(nullptr, "Could not convert to double", "Could not convert your value to a double.");
Expand All @@ -566,8 +567,7 @@ bool FitElementsTableModel::setData(const QModelIndex &index,
}
else if (dval < -10)
{
QMessageBox::warning(nullptr, "Value too small", "Value is too small and will create NaN/Inf. Use range -10 : 20 .");
return false;
new_value = QVariant(-11);
}
}
else
Expand All @@ -579,11 +579,10 @@ bool FitElementsTableModel::setData(const QModelIndex &index,
}
else if (dval < 1.0e-10)
{
QMessageBox::warning(nullptr, "Value too small", "Value is too small and will create NaN/Inf. Use range 1.0e-10 : 1.0e20 .");
return false;
new_value = QVariant(0);
}
}
node->itemData[1] = value;
node->itemData[1] = new_value;
}
}
else
Expand Down
33 changes: 30 additions & 3 deletions src/mvc/FitSpectraWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ FitSpectraWidget::FitSpectraWidget(QWidget* parent) : QWidget(parent)

FitSpectraWidget::~FitSpectraWidget()
{
if(_periodic_table_widget != nullptr)
{
delete _periodic_table_widget;
}

if (_fitting_dialog != nullptr)
{
delete _fitting_dialog;
Expand Down Expand Up @@ -137,6 +142,8 @@ void FitSpectraWidget::createLayout()
ComboBoxDelegate *cbDelegate = new ComboBoxDelegate(bound_types);
NumericPrecDelegate* npDelegate = new NumericPrecDelegate();

_periodic_table_widget = new PeriodicTableWidget();
connect(_periodic_table_widget, &PeriodicTableWidget::onSelect, this, &FitSpectraWidget::update_selected_element_to_add);

_fit_params_table = new QTableView();
_fit_params_table->setModel(_fit_params_table_model);
Expand Down Expand Up @@ -194,10 +201,16 @@ void FitSpectraWidget::createLayout()
_btn_del_element = new QPushButton("Delete Element");
connect(_btn_del_element, &QPushButton::released, this, &FitSpectraWidget::del_element);

_btn_periodic_table = new QPushButton();
_btn_periodic_table->setIcon(QIcon(":/images/grid.png"));
_btn_periodic_table->setFixedSize(32,32);
connect(_btn_periodic_table, &QPushButton::released, this, &FitSpectraWidget::display_periodic_table);

QGridLayout* add_element_grid_layout = new QGridLayout();
add_element_grid_layout->setAlignment(Qt::AlignTop);
add_element_grid_layout->addWidget(new QLabel("Element"), 0, 0);
add_element_grid_layout->addWidget(_cb_add_elements, 0, 1);
add_element_grid_layout->addWidget(_btn_periodic_table, 0, 2);
add_element_grid_layout->addWidget(new QLabel("Shell"), 1, 0);
add_element_grid_layout->addWidget(_cb_add_shell, 1, 1);
//add_element_grid_layout->addWidget(new QLabel("Detector Element"), 2, 0);
Expand All @@ -208,7 +221,7 @@ void FitSpectraWidget::createLayout()
add_element_grid_layout->addWidget(_btn_del_element, 3, 1);

QLayout* elements_layout;
if(Preferences::inst()->getValue(STR_PREF_SPRECTRA_CONTROLS_HORIZONTAL_OPTION).toBool())
if(Preferences::inst()->getValue(STR_PREF_SPRECTRA_CONTROLS_HORIZONTAL_OPTION).toInt() == 1)
{
elements_layout = new QVBoxLayout();
}
Expand Down Expand Up @@ -253,7 +266,7 @@ void FitSpectraWidget::createLayout()

QLayout * orient_layout;
//QSplitter* splitter = new QSplitter();
if(Preferences::inst()->getValue(STR_PREF_SPRECTRA_CONTROLS_HORIZONTAL_OPTION).toBool())
if(Preferences::inst()->getValue(STR_PREF_SPRECTRA_CONTROLS_HORIZONTAL_OPTION).toInt() == 1)
{
orient_layout = new QHBoxLayout();
//splitter->setOrientation(Qt::Horizontal);
Expand Down Expand Up @@ -331,6 +344,13 @@ void FitSpectraWidget::displayROIs(bool val)

//---------------------------------------------------------------------------

void FitSpectraWidget::update_selected_element_to_add(QString val)
{
_cb_add_elements->setCurrentText(val);
}

//---------------------------------------------------------------------------

void FitSpectraWidget::setParamOverride(data_struct::Params_Override<double>* po)
{
_param_override = po;
Expand Down Expand Up @@ -737,9 +757,15 @@ void FitSpectraWidget::clearROISpectra()

//---------------------------------------------------------------------------

void FitSpectraWidget::add_element()
void FitSpectraWidget::display_periodic_table()
{
_periodic_table_widget->show();
}

//---------------------------------------------------------------------------

void FitSpectraWidget::add_element()
{
if(_elements_to_fit == nullptr)
{
_elements_to_fit = new data_struct::Fit_Element_Map_Dict<double>();
Expand Down Expand Up @@ -1340,6 +1366,7 @@ void FitSpectraWidget::optimizer_preset_changed(int val)
_fit_params_table_model->setOptimizerPreset(fitting::models::Fit_Params_Preset::BATCH_FIT_NO_TAILS_E_QUAD);
break;
default:
break;
}
_fit_params_table->resizeColumnToContents(0);
}
Expand Down
9 changes: 9 additions & 0 deletions src/mvc/FitSpectraWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "data_struct/fit_element_map.h"
#include "data_struct/params_override.h"
#include "mvc/SpectraWidgetSettingsDialog.h"
#include "mvc/PeriodicTableWidget.h"

//---------------------------------------------------------------------------

Expand Down Expand Up @@ -182,6 +183,10 @@ private slots:

void on_export_fit_paramters();

void display_periodic_table();

void update_selected_element_to_add(QString);

private:

//std::mutex _mutex;
Expand Down Expand Up @@ -255,6 +260,10 @@ private slots:
std::unordered_map<std::string, ArrayDr> _labeled_spectras;

QDir _dataset_dir;

QPushButton* _btn_periodic_table;

PeriodicTableWidget* _periodic_table_widget;
};


Expand Down
217 changes: 217 additions & 0 deletions src/mvc/PeriodicTableWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
/*-----------------------------------------------------------------------------
* Copyright (c) 2024, UChicago Argonne, LLC
* See LICENSE file.
*---------------------------------------------------------------------------*/

#include <mvc/PeriodicTableWidget.h>
#include <QLabel>

//---------------------------------------------------------------------------

PeriodicTableWidget::PeriodicTableWidget(QWidget *parent) : QWidget(parent)
{
_layout = new QGridLayout();
_layout->setHorizontalSpacing(0);


_layout->addWidget(_gen_el_btn("H"), 0,0);
_layout->addWidget(_gen_el_btn("He"), 0,17);

_layout->addWidget(_gen_el_btn("Li"), 1,0);
_layout->addWidget(_gen_el_btn("Be"), 1,1);
_layout->addWidget(_gen_el_btn("B"), 1,12);
_layout->addWidget(_gen_el_btn("C"), 1,13);
_layout->addWidget(_gen_el_btn("N"), 1,14);
_layout->addWidget(_gen_el_btn("O"), 1,15);
_layout->addWidget(_gen_el_btn("F"), 1,16);
_layout->addWidget(_gen_el_btn("Ne"), 1,17);

_layout->addWidget(_gen_el_btn("Na"), 2,0);
_layout->addWidget(_gen_el_btn("Mg"), 2,1);
_layout->addWidget(_gen_el_btn("Al"), 2,12);
_layout->addWidget(_gen_el_btn("Si"), 2,13);
_layout->addWidget(_gen_el_btn("P"), 2,14);
_layout->addWidget(_gen_el_btn("S"), 2,15);
_layout->addWidget(_gen_el_btn("Cl"), 2,16);
_layout->addWidget(_gen_el_btn("Ar"), 2,17);

_layout->addWidget(_gen_el_btn("K"), 3,0);
_layout->addWidget(_gen_el_btn("Ca"), 3,1);
_layout->addWidget(_gen_el_btn("Sc"), 3,2);
_layout->addWidget(_gen_el_btn("Ti"), 3,3);
_layout->addWidget(_gen_el_btn("V"), 3,4);
_layout->addWidget(_gen_el_btn("Cr"), 3,5);
_layout->addWidget(_gen_el_btn("Mn"), 3,6);
_layout->addWidget(_gen_el_btn("Fe"), 3,7);
_layout->addWidget(_gen_el_btn("Co"), 3,8);
_layout->addWidget(_gen_el_btn("Ni"), 3,9);
_layout->addWidget(_gen_el_btn("Cu"), 3,10);
_layout->addWidget(_gen_el_btn("Zn"), 3,11);
_layout->addWidget(_gen_el_btn("Ga"), 3,12);
_layout->addWidget(_gen_el_btn("Ge"), 3,13);
_layout->addWidget(_gen_el_btn("As"), 3,14);
_layout->addWidget(_gen_el_btn("Se"), 3,15);
_layout->addWidget(_gen_el_btn("Br"), 3,16);
_layout->addWidget(_gen_el_btn("Kr"), 3,17);

_layout->addWidget(_gen_el_btn("Rb"), 4,0);
_layout->addWidget(_gen_el_btn("Sr"), 4,1);
_layout->addWidget(_gen_el_btn("Y"), 4,2);
_layout->addWidget(_gen_el_btn("Zr"), 4,3);
_layout->addWidget(_gen_el_btn("Nb"), 4,4);
_layout->addWidget(_gen_el_btn("Mo"), 4,5);
_layout->addWidget(_gen_el_btn("Tc"), 4,6);
_layout->addWidget(_gen_el_btn("Ru"), 4,7);
_layout->addWidget(_gen_el_btn("Rh"), 4,8);
_layout->addWidget(_gen_el_btn("Pd"), 4,9);
_layout->addWidget(_gen_el_btn("Ag"), 4,10);
_layout->addWidget(_gen_el_btn("Cd"), 4,11);
_layout->addWidget(_gen_el_btn("In"), 4,12);
_layout->addWidget(_gen_el_btn("Sn"), 4,13);
_layout->addWidget(_gen_el_btn("Sb"), 4,14);
_layout->addWidget(_gen_el_btn("Te"), 4,15);
_layout->addWidget(_gen_el_btn("I"), 4,16);
_layout->addWidget(_gen_el_btn("Xe"), 4,17);

_layout->addWidget(_gen_el_btn("Cs"), 5,0);
_layout->addWidget(_gen_el_btn("Ba"), 5,1);
_layout->addWidget(_gen_el_btn("La"), 5,2);
_layout->addWidget(_gen_el_btn("Hf"), 5,3);
_layout->addWidget(_gen_el_btn("Ta"), 5,4);
_layout->addWidget(_gen_el_btn("W"), 5,5);
_layout->addWidget(_gen_el_btn("Re"), 5,6);
_layout->addWidget(_gen_el_btn("Os"), 5,7);
_layout->addWidget(_gen_el_btn("Ir"), 5,8);
_layout->addWidget(_gen_el_btn("Pt"), 5,9);
_layout->addWidget(_gen_el_btn("Au"), 5,10);
_layout->addWidget(_gen_el_btn("Hg"), 5,11);
_layout->addWidget(_gen_el_btn("Tl"), 5,12);
_layout->addWidget(_gen_el_btn("Pb"), 5,13);
_layout->addWidget(_gen_el_btn("Bi"), 5,14);
_layout->addWidget(_gen_el_btn("Po"), 5,15);
_layout->addWidget(_gen_el_btn("At"), 5,16);
_layout->addWidget(_gen_el_btn("Rn"), 5,17);

_layout->addWidget(_gen_el_btn("Fr"), 6,0);
_layout->addWidget(_gen_el_btn("Ra"), 6,1);
_layout->addWidget(_gen_el_btn("Ac"), 6,2);
_layout->addWidget(_gen_el_btn("Rf"), 6,3);
_layout->addWidget(_gen_el_btn("Db"), 6,4);
_layout->addWidget(_gen_el_btn("Sg"), 6,5);
_layout->addWidget(_gen_el_btn("Bh"), 6,6);
_layout->addWidget(_gen_el_btn("Hs"), 6,7);
_layout->addWidget(_gen_el_btn("Mt"), 6,8);
_layout->addWidget(_gen_el_btn("Ds"), 6,9);
_layout->addWidget(_gen_el_btn("Rg"), 6,10);
_layout->addWidget(_gen_el_btn("Cn"), 6,11);
_layout->addWidget(_gen_el_btn("Nh"), 6,12);
_layout->addWidget(_gen_el_btn("Fl"), 6,13);
_layout->addWidget(_gen_el_btn("Mc"), 6,14);
_layout->addWidget(_gen_el_btn("Lv"), 6,15);
_layout->addWidget(_gen_el_btn("Ts"), 6,16);
_layout->addWidget(_gen_el_btn("Og"), 6,17);

_layout->addWidget(new QLabel(" "), 7,3);

_layout->addWidget(_gen_el_btn("Ce"), 8,3);
_layout->addWidget(_gen_el_btn("Pr"), 8,4);
_layout->addWidget(_gen_el_btn("Nd"), 8,5);
_layout->addWidget(_gen_el_btn("Pm"), 8,6);
_layout->addWidget(_gen_el_btn("Sm"), 8,7);
_layout->addWidget(_gen_el_btn("Eu"), 8,8);
_layout->addWidget(_gen_el_btn("Gd"), 8,9);
_layout->addWidget(_gen_el_btn("Tb"), 8,10);
_layout->addWidget(_gen_el_btn("Dy"), 8,11);
_layout->addWidget(_gen_el_btn("Ho"), 8,12);
_layout->addWidget(_gen_el_btn("Er"), 8,13);
_layout->addWidget(_gen_el_btn("Tm"), 8,14);
_layout->addWidget(_gen_el_btn("Yb"), 8,15);
_layout->addWidget(_gen_el_btn("Lu"), 8,16);

_layout->addWidget(_gen_el_btn("Th"), 9,3);
_layout->addWidget(_gen_el_btn("Pa"), 9,4);
_layout->addWidget(_gen_el_btn("U"), 9,5);
_layout->addWidget(_gen_el_btn("Np"), 9,6);
_layout->addWidget(_gen_el_btn("Pu"), 9,7);
_layout->addWidget(_gen_el_btn("Am"), 9,8);
_layout->addWidget(_gen_el_btn("Cm"), 9,9);
_layout->addWidget(_gen_el_btn("Bk"), 9,10);
_layout->addWidget(_gen_el_btn("Cf"), 9,11);
_layout->addWidget(_gen_el_btn("Es"), 9,12);
_layout->addWidget(_gen_el_btn("Fm"), 9,13);
_layout->addWidget(_gen_el_btn("Md"), 9,14);
_layout->addWidget(_gen_el_btn("No"), 9,15);
_layout->addWidget(_gen_el_btn("Lr"), 9,16);

this->setLayout(_layout);
}

//---------------------------------------------------------------------------

PeriodicTableWidget::~PeriodicTableWidget()
{

}

//---------------------------------------------------------------------------

void PeriodicTableWidget::button_pressed()
{
QPushButton* btn = qobject_cast<QPushButton*>(sender());
emit onSelect(btn->text());
this->hide();
}

//---------------------------------------------------------------------------

QPushButton* PeriodicTableWidget::_gen_el_btn(QString symbol)
{
enum Element_Class ec = Element_Class_Map.at(symbol);
QPushButton *btn;
btn = new QPushButton();
btn->setText(symbol);
btn->setFixedWidth(36);
switch(ec)
{
case Element_Class::Hydrogen:
btn->setStyleSheet("QPushButton {background-color: #8ab4f8; color: white;}");
break;
case Element_Class::Alkaline_Metal:
btn->setStyleSheet("QPushButton {background-color: #244d57; color: white;}");
break;
case Element_Class::Alkaline_Earth_Metal:
btn->setStyleSheet("QPushButton {background-color: #622e39; color: white;}");
break;
case Element_Class::Transition_metals:
btn->setStyleSheet("QPushButton {background-color: #433c65; color: white;}");
break;
case Element_Class::Post_Transition_Metals:
btn->setStyleSheet("QPushButton {background-color: #2f4d47; color: white;}");
break;
case Element_Class::Metalloids:
btn->setStyleSheet("QPushButton {background-color: #523e1b; color: white;}");
break;
case Element_Class::Reactive_nonmetals:
btn->setStyleSheet("QPushButton {background-color: #2a4165; color: white;}");
break;
case Element_Class::Noble_gases:
btn->setStyleSheet("QPushButton {background-color: #623842; color: white;}");
break;
case Element_Class::Lanthanides:
btn->setStyleSheet("QPushButton {background-color: #004a77; color: white;}");
break;
case Element_Class::Actinides:
btn->setStyleSheet("QPushButton {background-color: #613b28; color: white;}");
break;
case Element_Class::Unknown_properties:
default:
btn->setStyleSheet("QPushButton {background-color: #46474c; color: white;}");
break;
}

connect(btn, &QPushButton::released, this, &PeriodicTableWidget::button_pressed);
return btn;
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
Loading

0 comments on commit 5a98316

Please sign in to comment.