magstructfact.h 4.24 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * magnetic structure factor tool
 * @author Tobias Weber <tweber@ill.fr>
 * @date Jan-2019
 * @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 __MAG_SFACT_H__
#define __MAG_SFACT_H__

#include <QtWidgets/QDialog>
#include <QtWidgets/QTableWidget>
#include <QtWidgets/QPlainTextEdit>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QMenu>
#include <QtWidgets/QLabel>
#include <QtWidgets/QComboBox>
21
#include <QtWidgets/QCheckBox>
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <QtCore/QSettings>

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

#include "libs/_cxx20/glplot.h"
#include "libs/_cxx20/math_algos.h"

#include "../structfact/numerictablewidgetitem.h"


using t_real = double;
using t_cplx = std::complex<t_real>;
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>;


struct NuclPos
{
	std::string name;
45
46
47
48
	t_real pos[3];	// position
	t_cplx MAbs;	// scaling of Fourier components
	t_real ReM[3];	// real part of Fourier components
	t_real ImM[3];	// imag part of Fourier components
49
50
51
52
53
54
55
};


class MagStructFactDlg : public QDialog
{
public:
	MagStructFactDlg(QWidget* pParent = nullptr);
Tobias WEBER's avatar
Tobias WEBER committed
56
	virtual ~MagStructFactDlg() = default;
57
58
59
60
61

protected:
	QSettings *m_sett = nullptr;
	QMenuBar *m_menu = nullptr;

Tobias WEBER's avatar
Tobias WEBER committed
62
	// unit cell view
63
64
65
	QDialog *m_dlgPlot = nullptr;
	std::shared_ptr<GlPlot> m_plot;
	std::size_t m_sphere = 0;
66
	std::size_t m_arrow = 0;
Tobias WEBER's avatar
Tobias WEBER committed
67
68
69
70
71
72
73

	// super cell view
	QDialog *m_dlgPlotSC = nullptr;
	std::shared_ptr<GlPlot> m_plotSC;
	std::size_t m_sphereSC = 0;
	std::size_t m_arrowSC = 0;

74
75
76
77
	QLabel *m_labelGlInfos[4] = { nullptr, nullptr, nullptr, nullptr };
	QLabel *m_status3D = nullptr;

	QWidget *m_nucleipanel = nullptr;
78
	QWidget *m_propvecpanel = nullptr;
79
	QTableWidget *m_nuclei = nullptr;
80
	QTableWidget *m_propvecs = nullptr;
81
82
	QPlainTextEdit *m_structfacts = nullptr;
	QPlainTextEdit *m_powderlines = nullptr;
83
	QPlainTextEdit *m_moments = nullptr;
84
85
86
87
88
89
90
91
92
93
94
95

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

	QComboBox *m_comboSG = nullptr;
	std::vector<std::vector<t_mat>> m_SGops;

	QSpinBox *m_maxBZ = nullptr;
96
	QCheckBox *m_RemoveZeroes = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
97
	QSpinBox *m_maxSC[3] = { nullptr, nullptr, nullptr };
98
99
100
101
102

	t_mat m_crystA = m::unit<t_mat>(3);
	t_mat m_crystB = m::unit<t_mat>(3);

protected:
103
104
105
106
107
108
109
	// general table operations
	void MoveTabItemUp(QTableWidget *pTab);
	void MoveTabItemDown(QTableWidget *pTab);
	void ShowTableContextMenu(QTableWidget *pTab, QMenu *pMenu, QMenu *pMenuNoItem, const QPoint& pt);
	std::vector<int> GetSelectedRows(QTableWidget *pTab, bool sort_reversed = false) const;

	// Fourier components table
110
111
112
113
114
115
	void AddTabItem(int row=-1, const std::string& name="n/a", t_real MMag=1.,
		t_real x=0., t_real y=0., t_real z=0., 
		t_real ReMx=0., t_real ReMy=0., t_real ReMz=1.,
		t_real ImMx=0., t_real ImMy=0., t_real ImMz=0., 
		t_real scale=1., const std::string &col="#ff0000");
	void DelTabItem(int begin=-2, int end=-2);
116
117
118
119
120
121
	void TableCurCellChanged(int rowNew, int colNew, int rowOld, int colOld);
	void TableCellEntered(const QModelIndex& idx);
	void TableItemChanged(QTableWidgetItem *item);

	// propagation vectors table
	void AddPropItem(int row=-1, const std::string& name="n/a", 
Tobias WEBER's avatar
Tobias WEBER committed
122
		t_real x=0., t_real y=0., t_real z=0., bool bConjFC=0);
123
124
	void DelPropItem(int begin=-2, int end=-2);
	void PropItemChanged(QTableWidgetItem *item);
125
126

	void Add3DItem(int row=-1);
127
	void Sync3DItem(int row=-1);
128
129
130
131
132
133
134
135
136
137
138
139
140

	void Load();
	void Save();
	void ImportCIF();
	void GenerateFromSG();

	std::vector<NuclPos> GetNuclei() const;
	void CalcB(bool bFullRecalc=true);
	void Calc();

	void PlotMouseDown(bool left, bool mid, bool right);
	void PickerIntersection(const t_vec3_gl* pos, std::size_t objIdx, const t_vec3_gl* posSphere);
	void AfterGLInitialisation();
Tobias WEBER's avatar
Tobias WEBER committed
141
	void AfterGLInitialisationSC();
142
143
144
145
146

	virtual void closeEvent(QCloseEvent *evt) override;

private:
	int m_iCursorRow = -1;
Tobias WEBER's avatar
Tobias WEBER committed
147

148
	bool m_ignoreChanges = 1;
149
	bool m_ignoreCalc = 0;
150
151

	long m_curPickedObj = -1;
Tobias WEBER's avatar
Tobias WEBER committed
152
153

	std::vector<std::size_t> m_3dobjsSC;
154
155
156
157
};


#endif