moldyn.h 3.19 KB
Newer Older
Tobias WEBER's avatar
Tobias WEBER committed
1
/**
Tobias WEBER's avatar
Tobias WEBER committed
2
 * atom dynamics
Tobias WEBER's avatar
Tobias WEBER committed
3
4
5
6
7
 * @author Tobias Weber <tweber@ill.fr>
 * @date Dec-2019
 * @license GPLv3, see 'LICENSE' file
 */

Tobias WEBER's avatar
Tobias WEBER committed
8
9
#ifndef __MOLDYN_GUI_H__
#define __MOLDYN_GUI_H__
Tobias WEBER's avatar
Tobias WEBER committed
10

Tobias WEBER's avatar
Tobias WEBER committed
11
#include <QtWidgets/QMainWindow>
Tobias WEBER's avatar
Tobias WEBER committed
12
#include <QtWidgets/QMenu>
Tobias WEBER's avatar
Tobias WEBER committed
13
14
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QStatusBar>
Tobias WEBER's avatar
Tobias WEBER committed
15
#include <QtWidgets/QSlider>
Tobias WEBER's avatar
Tobias WEBER committed
16
#include <QtWidgets/QLabel>
Tobias WEBER's avatar
Tobias WEBER committed
17
#include <QtWidgets/QDoubleSpinBox>
Tobias WEBER's avatar
Tobias WEBER committed
18
#include <QtCore/QSettings>
Tobias WEBER's avatar
Tobias WEBER committed
19
20

#include <vector>
Tobias WEBER's avatar
Tobias WEBER committed
21
#include <tuple>
Tobias WEBER's avatar
Tobias WEBER committed
22

23
24
#include "tlibs2/libs/glplot.h"
#include "tlibs2/libs/math20.h"
Tobias WEBER's avatar
Tobias WEBER committed
25

Tobias WEBER's avatar
Tobias WEBER committed
26
27
#include "moldyn-loader.h"

Tobias WEBER's avatar
Tobias WEBER committed
28

Tobias WEBER's avatar
Tobias WEBER committed
29
using t_real = double;
Tobias WEBER's avatar
Tobias WEBER committed
30
using t_vec = tl2::vec<t_real, std::vector>;
Tobias WEBER's avatar
Tobias WEBER committed
31
using t_mat = tl2::mat<t_real, std::vector>;
Tobias WEBER's avatar
Tobias WEBER committed
32

Tobias WEBER's avatar
Tobias WEBER committed
33
34
35
36
37
38
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;

Tobias WEBER's avatar
Tobias WEBER committed
39

Tobias WEBER's avatar
Tobias WEBER committed
40
41
42
/**
 * atom indices for convex hull calculation
 */
43
struct Hull
Tobias WEBER's avatar
Tobias WEBER committed
44
45
{
	std::vector<std::tuple<std::size_t, std::size_t>> vertices;
46
	std::optional<std::size_t> plotObj;
Tobias WEBER's avatar
Tobias WEBER committed
47
48
49
};


Tobias WEBER's avatar
Tobias WEBER committed
50
class MolDynDlg : public QMainWindow
Tobias WEBER's avatar
Tobias WEBER committed
51
{
Tobias WEBER's avatar
Tobias WEBER committed
52
53
54
public:
	MolDynDlg(QWidget* pParent = nullptr);
	~MolDynDlg() = default;
Tobias WEBER's avatar
Tobias WEBER committed
55

Tobias WEBER's avatar
Tobias WEBER committed
56
protected:
Tobias WEBER's avatar
Tobias WEBER committed
57
	std::size_t Add3DAtom(const t_vec& vec, const t_vec& col, t_real scale, const std::string& typelabel, int atomindex=-1);
58
	void Change3DAtom(std::size_t obj, const t_vec* vec, const t_vec* col=nullptr, const t_real *scale=nullptr,
59
		const std::string *typelabel=nullptr, int atomindex=-1);
Tobias WEBER's avatar
Tobias WEBER committed
60

Tobias WEBER's avatar
Tobias WEBER committed
61
	void SetStatusMsg(const std::string& msg);
Tobias WEBER's avatar
Tobias WEBER committed
62
	void UpdateAtomsStatusMsg();
Tobias WEBER's avatar
Tobias WEBER committed
63

Tobias WEBER's avatar
Tobias WEBER committed
64
65
	void New();
	void Load();
Tobias WEBER's avatar
Tobias WEBER committed
66
	void SaveAs();
Tobias WEBER's avatar
Tobias WEBER committed
67

Tobias WEBER's avatar
Tobias WEBER committed
68
69
	void PlotMouseDown(bool left, bool mid, bool right);
	void PlotMouseUp(bool left, bool mid, bool right);
Tobias WEBER's avatar
Tobias WEBER committed
70
	void PlotMouseClick(bool left, bool mid, bool right);
Tobias WEBER's avatar
Tobias WEBER committed
71
72
	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
73
	void GLInitialisationFailed();
Tobias WEBER's avatar
Tobias WEBER committed
74

Tobias WEBER's avatar
Tobias WEBER committed
75
	std::tuple<bool, std::size_t, std::size_t, std::size_t> GetAtomIndexFromHandle(std::size_t handle) const;
76
	std::tuple<std::string, int> SplitDataString(const std::string&) const;
Tobias WEBER's avatar
Tobias WEBER committed
77

Tobias WEBER's avatar
Tobias WEBER committed
78
	void CalculateDistanceBetweenAtoms();
Tobias WEBER's avatar
Tobias WEBER committed
79
80
	void CalculatePositionsOfAtoms();
	void CalculateDeltaDistancesOfAtoms();
Tobias WEBER's avatar
Tobias WEBER committed
81
82
83
	void CalculateConvexHullOfAtoms();

	void CalculateConvexHulls();
Tobias WEBER's avatar
Tobias WEBER committed
84

Tobias WEBER's avatar
Tobias WEBER committed
85
86
87
88
89
	void SliderValueChanged(int val);

	void SelectAll();
	void SelectNone();

Tobias WEBER's avatar
Tobias WEBER committed
90
91
	std::vector<std::tuple<std::size_t, std::size_t>> GetSelectedAtoms();

92
93
    void DeleteSelectedAtoms();
    void OnlyKeepSelectedAtoms();
Tobias WEBER's avatar
Tobias WEBER committed
94
	void SelectAtomsOfSameType();
Tobias WEBER's avatar
Tobias WEBER committed
95
96
97
98
	void DeleteAtomUnderCursor();
	void DeleteAllAtomsOfSameType();
	void KeepAtomsOfSameType();

Tobias WEBER's avatar
Tobias WEBER committed
99
	virtual void closeEvent(QCloseEvent *evt) override;
Tobias WEBER's avatar
Tobias WEBER committed
100
	virtual void keyPressEvent(QKeyEvent *evt) override;
Tobias WEBER's avatar
Tobias WEBER committed
101

102
103
104

protected:
	MolDyn<t_real, t_vec> m_mol;
Tobias WEBER's avatar
Tobias WEBER committed
105
106
	t_mat m_crystA = tl2::unit<t_mat>(3);
	t_mat m_crystB = tl2::unit<t_mat>(3);
107
108
109

	QSettings *m_sett = nullptr;
	QMenuBar *m_menu = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
110

111
	QStatusBar *m_status = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
112
	QLabel *m_statusCurAtom = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
113
	QLabel *m_statusAtoms = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
114

Tobias WEBER's avatar
Tobias WEBER committed
115
	QSlider *m_sliderFrame = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
116
	QDoubleSpinBox *m_spinScale = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
117
	QMenu *m_atomContextMenu = nullptr;
118

Tobias WEBER's avatar
Tobias WEBER committed
119
	tl2::GlPlot *m_plot = nullptr;
120
121
122
	std::size_t m_sphere = 0;
	std::vector<std::size_t> m_sphereHandles;

123
	std::vector<Hull> m_hulls;
Tobias WEBER's avatar
Tobias WEBER committed
124

125

Tobias WEBER's avatar
Tobias WEBER committed
126
127
128
private:
	long m_curPickedObj = -1;
	bool m_ignoreChanges = 1;
Tobias WEBER's avatar
Tobias WEBER committed
129
130
131
132
};


#endif