structfact.h 3.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
 * 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>
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>

Tobias WEBER's avatar
Tobias WEBER committed
28
#include "libs/_cxx20/glplot.h"
29
#include "libs/_cxx20/math_algos.h"
30

31
32
#include "numerictablewidgetitem.h"

33

34
35
using t_real = double;
using t_cplx = std::complex<t_real>;
36
37
38
39
40
using t_vec = std::vector<t_real>;
using t_vec_cplx = std::vector<t_cplx>;
using t_mat = m::mat<t_real, std::vector>;
using t_mat_cplx = m::mat<t_cplx, std::vector>;

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

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
58
	QMenuBar *m_menu = nullptr;
59

60
	QDialog *m_dlgPlot = nullptr;
61
62
63
	std::shared_ptr<GlPlot> m_plot;
	std::size_t m_sphere = 0;
	QLabel *m_labelGlInfos[4] = { nullptr, nullptr, nullptr, nullptr };
64
	QLabel *m_status3D = nullptr;
65

66
67
68
69
70
71
72
73
74
75
76
77
	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
78
	QComboBox *m_comboSG = nullptr;
79
	std::vector<std::vector<t_mat>> m_SGops;
Tobias WEBER's avatar
Tobias WEBER committed
80

81
	QSpinBox *m_maxBZ = nullptr;
82
	QCheckBox *m_RemoveZeroes = nullptr;
83

84
85
	QMenu *m_pTabContextMenu = nullptr;			// menu in case a nucleus is selected
	QMenu *m_pTabContextMenuNoItem = nullptr;	// menu if nothing is selected
86

Tobias WEBER's avatar
Tobias WEBER committed
87
88
89
	t_mat m_crystA = m::unit<t_mat>(3);
	t_mat m_crystB = m::unit<t_mat>(3);

90
protected:
Tobias WEBER's avatar
Tobias WEBER committed
91
	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
92
		t_real x=0., t_real y=0., t_real z=0., t_real scale=1., const std::string &col="#ff0000");
93
	void DelTabItem(int begin=-2, int end=-2);
94
95
96
	void MoveTabItemUp();
	void MoveTabItemDown();

97
98
99
	void Add3DItem(int row=-1);
	void Set3DStatusMsg(const std::string& msg);

100
101
102
103
104
	void TableCurCellChanged(int rowNew, int colNew, int rowOld, int colOld);
	void TableCellEntered(const QModelIndex& idx);
	void TableItemChanged(QTableWidgetItem *item);
	void ShowTableContextMenu(const QPoint& pt);

105
106
	void Load();
	void Save();
Tobias WEBER's avatar
Tobias WEBER committed
107
	void ImportCIF();
Tobias WEBER's avatar
Tobias WEBER committed
108
	void ExportTAZ();
Tobias WEBER's avatar
Tobias WEBER committed
109
	void GenerateFromSG();
110

111
	std::vector<NuclPos> GetNuclei() const;
Tobias WEBER's avatar
Tobias WEBER committed
112
	void CalcB(bool bFullRecalc=true);
113
114
	void Calc();

115
116
117
	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);
118
119
	void AfterGLInitialisation();

120
121
122
123
124
	virtual void closeEvent(QCloseEvent *evt) override;

private:
	int m_iCursorRow = -1;
	bool m_ignoreChanges = 1;
125
	bool m_ignoreCalc = 0;
126

127
128
	long m_curPickedObj = -1;

129
130
131
132
133
134
private:
	std::vector<int> GetSelectedRows(bool sort_reversed = false) const;
};


#endif