structfact.h 3.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
 * structure factor tool
 * @author Tobias Weber <tweber@ill.fr>
 * @date Dec-2018
 * @license GPLv3, see 'LICENSE' file
 * @desc The present version was forked on 28-Dec-2018 from the privately developed "misc" project (https://github.com/t-weber/misc).
 */

#ifndef __SFACT_H__
#define __SFACT_H__

#include <QtWidgets/QDialog>
#include <QtWidgets/QTableWidget>
#include <QtWidgets/QPlainTextEdit>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QMenu>
18
#include <QtWidgets/QLabel>
Tobias WEBER's avatar
Tobias WEBER committed
19
#include <QtWidgets/QComboBox>
20
21
22
23
24
25
#include <QtCore/QSettings>

#include <vector>
#include <sstream>
#include <complex>

26
27
28
#include "../glplot/glplot.h"


29
30
31
32
33
34
35
36
37
38
39
using t_real = double;
using t_cplx = std::complex<t_real>;


template<class T = t_real>
class NumericTableWidgetItem : public QTableWidgetItem
{
public:
	NumericTableWidgetItem(T&& val)
		: QTableWidgetItem(std::to_string(std::forward<T>(val)).c_str())
	{}
Tobias WEBER's avatar
Tobias WEBER committed
40
41
42
	NumericTableWidgetItem(const T& val)
		: QTableWidgetItem(std::to_string(val).c_str())
	{}
43

44
45
46
	NumericTableWidgetItem(const QString& val) : QTableWidgetItem(val)
	{}

47
48
49
50
51
52
53
54
	virtual bool operator<(const QTableWidgetItem& item) const override
	{
		T val1{}, val2{};
		std::istringstream{text().toStdString()} >> val1;
		std::istringstream{item.text().toStdString()} >> val2;

		return val1 < val2;
	}
55
56
57

	virtual QTableWidgetItem* clone() const override
	{
Tobias WEBER's avatar
Tobias WEBER committed
58
59
60
		auto item = new NumericTableWidgetItem<T>(this->text());
		item->setData(Qt::UserRole, this->data(Qt::UserRole));
		return item;
61
	};
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
};


struct NuclPos
{
	std::string name;
	t_cplx b;
	t_real pos[3];
};


class StructFactDlg : public QDialog
{
public:
	StructFactDlg(QWidget* pParent = nullptr);
	~StructFactDlg() = default;

protected:
	QSettings *m_sett = nullptr;

82
	QDialog *m_dlgPlot = nullptr;
83
84
85
	std::shared_ptr<GlPlot> m_plot;
	std::size_t m_sphere = 0;
	QLabel *m_labelGlInfos[4] = { nullptr, nullptr, nullptr, nullptr };
86
	QLabel *m_status3D = nullptr;
87

88
89
90
91
92
93
94
95
96
97
98
99
	QWidget *m_nucleipanel = nullptr;
	QTableWidget *m_nuclei = nullptr;
	QPlainTextEdit *m_structfacts = nullptr;
	QPlainTextEdit *m_powderlines = nullptr;

	QLineEdit *m_editA = nullptr;
	QLineEdit *m_editB = nullptr;
	QLineEdit *m_editC = nullptr;
	QLineEdit *m_editAlpha = nullptr;
	QLineEdit *m_editBeta = nullptr;
	QLineEdit *m_editGamma = nullptr;

Tobias WEBER's avatar
Tobias WEBER committed
100
101
	QComboBox *m_comboSG = nullptr;

102
103
	QSpinBox *m_maxBZ = nullptr;

104
105
	QMenu *m_pTabContextMenu = nullptr;			// menu in case a nucleus is selected
	QMenu *m_pTabContextMenuNoItem = nullptr;	// menu if nothing is selected
106
107

protected:
Tobias WEBER's avatar
Tobias WEBER committed
108
	void AddTabItem(int row=-1, const std::string& name="n/a", t_real bRe=0., t_real bIm=0.,
Tobias WEBER's avatar
Tobias WEBER committed
109
		t_real x=0., t_real y=0., t_real z=0., t_real scale=1., const std::string &col="#ff0000");
Tobias WEBER's avatar
Tobias WEBER committed
110
	void DelTabItem(bool clearAll=false);
111
112
113
	void MoveTabItemUp();
	void MoveTabItemDown();

114
115
116
	void Add3DItem(int row=-1);
	void Set3DStatusMsg(const std::string& msg);

117
118
119
120
121
	void TableCurCellChanged(int rowNew, int colNew, int rowOld, int colOld);
	void TableCellEntered(const QModelIndex& idx);
	void TableItemChanged(QTableWidgetItem *item);
	void ShowTableContextMenu(const QPoint& pt);

122
123
	void Load();
	void Save();
Tobias WEBER's avatar
Tobias WEBER committed
124
	void ImportCIF();
Tobias WEBER's avatar
Tobias WEBER committed
125
	void GenerateFromSG();
126

127
128
129
	std::vector<NuclPos> GetNuclei() const;
	void Calc();

130
131
132
	void PlotMouseDown(bool left, bool mid, bool right);
	void PlotMouseUp(bool left, bool mid, bool right);
	void PickerIntersection(const t_vec3_gl* pos, std::size_t objIdx, const t_vec3_gl* posSphere);
133
134
	void AfterGLInitialisation();

135
136
137
138
139
140
	virtual void closeEvent(QCloseEvent *evt) override;

private:
	int m_iCursorRow = -1;
	bool m_ignoreChanges = 1;

141
142
	long m_curPickedObj = -1;

143
144
145
146
147
148
private:
	std::vector<int> GetSelectedRows(bool sort_reversed = false) const;
};


#endif