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

#ifndef __SFACT_H__
#define __SFACT_H__

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

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

28
29
#include "tlibs2/libs/glplot.h"
#include "tlibs2/libs/math20.h"
30

31
32
#include "numerictablewidgetitem.h"

33

34
35
using t_real = double;
using t_cplx = std::complex<t_real>;
Tobias WEBER's avatar
Tobias WEBER committed
36
using t_vec = tl2::vec<t_real, std::vector>;
37
using t_vec_cplx = std::vector<t_cplx>;
Tobias WEBER's avatar
Tobias WEBER committed
38
39
using t_mat = tl2::mat<t_real, std::vector>;
using t_mat_cplx = tl2::mat<t_cplx, std::vector>;
40

Tobias WEBER's avatar
Tobias WEBER committed
41
42
43
44
45
46
using t_real_gl = tl2::t_real_gl;
using t_vec2_gl = tl2::t_vec2_gl;
using t_vec3_gl = tl2::t_vec3_gl;
using t_vec_gl = tl2::t_vec_gl;
using t_mat_gl = tl2::t_mat_gl;

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

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;
Tobias WEBER's avatar
Tobias WEBER committed
64
	QMenuBar *m_menu = nullptr;
65

66
	QDialog *m_dlgPlot = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
67
	std::shared_ptr<tl2::GlPlot> m_plot;
68
69
	std::size_t m_sphere = 0;
	QLabel *m_labelGlInfos[4] = { nullptr, nullptr, nullptr, nullptr };
70
	QLabel *m_status3D = nullptr;
71

72
73
74
	QTableWidget *m_nuclei = nullptr;
	QPlainTextEdit *m_structfacts = nullptr;
	QPlainTextEdit *m_powderlines = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
75
76
	QTableWidget *m_nuclei_FindSG = nullptr;
	QPlainTextEdit *m_sgmatches = nullptr;
77
78
79
80
81
82
83
84

	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
85
	QComboBox *m_comboSG = nullptr;
86
	std::vector<std::vector<t_mat>> m_SGops;
Tobias WEBER's avatar
Tobias WEBER committed
87

88
	QSpinBox *m_maxBZ = nullptr;
89
	QCheckBox *m_RemoveZeroes = nullptr;
90

91
92
	QMenu *m_pTabContextMenu = nullptr;			// menu in case a nucleus is selected
	QMenu *m_pTabContextMenuNoItem = nullptr;	// menu if nothing is selected
93

Tobias WEBER's avatar
Tobias WEBER committed
94
95
96
	QMenu *m_pTabContextMenu_FindSG = nullptr;			// menu in case a nucleus is selected
	QMenu *m_pTabContextMenuNoItem_FindSG = nullptr;	// menu if nothing is selected

Tobias WEBER's avatar
Tobias WEBER committed
97
98
	t_mat m_crystA = tl2::unit<t_mat>(3);
	t_mat m_crystB = tl2::unit<t_mat>(3);
Tobias WEBER's avatar
Tobias WEBER committed
99

100
protected:
Tobias WEBER's avatar
Tobias WEBER committed
101
	// for nuclei tab
Tobias WEBER's avatar
Tobias WEBER committed
102
	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
103
		t_real x=0., t_real y=0., t_real z=0., t_real scale=1., const std::string &col="#ff0000");
104
	void DelTabItem(int begin=-2, int end=-2);
105
106
107
	void MoveTabItemUp();
	void MoveTabItemDown();

108
109
110
	void Add3DItem(int row=-1);
	void Set3DStatusMsg(const std::string& msg);

111
112
113
114
115
	void TableCurCellChanged(int rowNew, int colNew, int rowOld, int colOld);
	void TableCellEntered(const QModelIndex& idx);
	void TableItemChanged(QTableWidgetItem *item);
	void ShowTableContextMenu(const QPoint& pt);

Tobias WEBER's avatar
Tobias WEBER committed
116

117
118
	void Load();
	void Save();
Tobias WEBER's avatar
Tobias WEBER committed
119
	void ImportCIF();
120
	void ImportTAZ();
Tobias WEBER's avatar
Tobias WEBER committed
121
	void ExportTAZ();
Tobias WEBER's avatar
Tobias WEBER committed
122
	void GenerateFromSG();
123

124
	std::vector<NuclPos> GetNuclei() const;
Tobias WEBER's avatar
Tobias WEBER committed
125
	void CalcB(bool bFullRecalc=true);
126
127
	void Calc();

128
129
130
	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);
131
132
	void AfterGLInitialisation();

Tobias WEBER's avatar
Tobias WEBER committed
133
134
135
136
137
138
139
140
141
142
143
144
145

	// for space group finder tab
	void AddTabItem_FindSG(int row=-1, t_real x=0., t_real y=0., t_real z=0.);
	void DelTabItem_FindSG(int begin=-2, int end=-2);
	void MoveTabItemUp_FindSG();
	void MoveTabItemDown_FindSG();

	void TableItemChanged_FindSG(QTableWidgetItem *item);
	void ShowTableContextMenu_FindSG(const QPoint& pt);

	void FindSG();


146
147
148
149
150
	virtual void closeEvent(QCloseEvent *evt) override;

private:
	int m_iCursorRow = -1;
	bool m_ignoreChanges = 1;
151
	bool m_ignoreCalc = 0;
152

153
154
	long m_curPickedObj = -1;

Tobias WEBER's avatar
Tobias WEBER committed
155
156
	int m_iCursorRow_FindSG = -1;

157
158
	static std::vector<std::string> g_default_colours;

159
160
private:
	std::vector<int> GetSelectedRows(bool sort_reversed = false) const;
Tobias WEBER's avatar
Tobias WEBER committed
161
	std::vector<int> GetSelectedRows_FindSG(bool sort_reversed = false) const;
162
163
164
165
};


#endif