moldyn.h 4.1 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
 * @author Tobias Weber <tweber@ill.fr>
 * @date Dec-2019
 * @license GPLv3, see 'LICENSE' file
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *
 * ----------------------------------------------------------------------------
 * mag-core (part of the Takin software suite)
 * Copyright (C) 2018-2021  Tobias WEBER (Institut Laue-Langevin (ILL),
 *                          Grenoble, France).
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * ----------------------------------------------------------------------------
Tobias WEBER's avatar
Tobias WEBER committed
24
25
 */

Tobias WEBER's avatar
Tobias WEBER committed
26
27
#ifndef __MOLDYN_GUI_H__
#define __MOLDYN_GUI_H__
Tobias WEBER's avatar
Tobias WEBER committed
28

Tobias WEBER's avatar
Tobias WEBER committed
29
#include <QtWidgets/QMainWindow>
Tobias WEBER's avatar
Tobias WEBER committed
30
#include <QtWidgets/QMenu>
Tobias WEBER's avatar
Tobias WEBER committed
31
32
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QStatusBar>
Tobias WEBER's avatar
Tobias WEBER committed
33
#include <QtWidgets/QSlider>
Tobias WEBER's avatar
Tobias WEBER committed
34
#include <QtWidgets/QLabel>
Tobias WEBER's avatar
Tobias WEBER committed
35
#include <QtWidgets/QDoubleSpinBox>
Tobias WEBER's avatar
Tobias WEBER committed
36
#include <QtCore/QSettings>
Tobias WEBER's avatar
Tobias WEBER committed
37
38

#include <vector>
Tobias WEBER's avatar
Tobias WEBER committed
39
#include <tuple>
Tobias WEBER's avatar
Tobias WEBER committed
40

Tobias WEBER's avatar
Tobias WEBER committed
41
#include "tlibs2/libs/qt/glplot.h"
42
#include "tlibs2/libs/math20.h"
Tobias WEBER's avatar
Tobias WEBER committed
43

Tobias WEBER's avatar
Tobias WEBER committed
44
45
#include "moldyn-loader.h"

Tobias WEBER's avatar
Tobias WEBER committed
46

Tobias WEBER's avatar
Tobias WEBER committed
47
using t_real = double;
Tobias WEBER's avatar
Tobias WEBER committed
48
using t_vec = tl2::vec<t_real, std::vector>;
Tobias WEBER's avatar
Tobias WEBER committed
49
using t_mat = tl2::mat<t_real, std::vector>;
Tobias WEBER's avatar
Tobias WEBER committed
50

Tobias WEBER's avatar
Tobias WEBER committed
51
52
53
54
55
56
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
57

Tobias WEBER's avatar
Tobias WEBER committed
58
59
60
/**
 * atom indices for convex hull calculation
 */
61
struct Hull
Tobias WEBER's avatar
Tobias WEBER committed
62
63
{
	std::vector<std::tuple<std::size_t, std::size_t>> vertices;
64
	std::optional<std::size_t> plotObj;
Tobias WEBER's avatar
Tobias WEBER committed
65
66
67
};


Tobias WEBER's avatar
Tobias WEBER committed
68
class MolDynDlg : public QMainWindow
Tobias WEBER's avatar
Tobias WEBER committed
69
{
Tobias WEBER's avatar
Tobias WEBER committed
70
71
72
public:
	MolDynDlg(QWidget* pParent = nullptr);
	~MolDynDlg() = default;
Tobias WEBER's avatar
Tobias WEBER committed
73

Tobias WEBER's avatar
Tobias WEBER committed
74
protected:
Tobias WEBER's avatar
Tobias WEBER committed
75
	std::size_t Add3DAtom(const t_vec& vec, const t_vec& col, t_real scale, const std::string& typelabel, int atomindex=-1);
76
	void Change3DAtom(std::size_t obj, const t_vec* vec, const t_vec* col=nullptr, const t_real *scale=nullptr,
77
		const std::string *typelabel=nullptr, int atomindex=-1);
Tobias WEBER's avatar
Tobias WEBER committed
78

Tobias WEBER's avatar
Tobias WEBER committed
79
	void SetStatusMsg(const std::string& msg);
Tobias WEBER's avatar
Tobias WEBER committed
80
	void UpdateAtomsStatusMsg();
Tobias WEBER's avatar
Tobias WEBER committed
81

Tobias WEBER's avatar
Tobias WEBER committed
82
83
	void New();
	void Load();
Tobias WEBER's avatar
Tobias WEBER committed
84
	void SaveAs();
Tobias WEBER's avatar
Tobias WEBER committed
85

Tobias WEBER's avatar
Tobias WEBER committed
86
87
	void PlotMouseDown(bool left, bool mid, bool right);
	void PlotMouseUp(bool left, bool mid, bool right);
Tobias WEBER's avatar
Tobias WEBER committed
88
	void PlotMouseClick(bool left, bool mid, bool right);
Tobias WEBER's avatar
Tobias WEBER committed
89
90
	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
91
	void GLInitialisationFailed();
Tobias WEBER's avatar
Tobias WEBER committed
92

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

Tobias WEBER's avatar
Tobias WEBER committed
96
	void CalculateDistanceBetweenAtoms();
Tobias WEBER's avatar
Tobias WEBER committed
97
98
	void CalculatePositionsOfAtoms();
	void CalculateDeltaDistancesOfAtoms();
Tobias WEBER's avatar
Tobias WEBER committed
99
100
101
	void CalculateConvexHullOfAtoms();

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

Tobias WEBER's avatar
Tobias WEBER committed
103
104
105
106
107
	void SliderValueChanged(int val);

	void SelectAll();
	void SelectNone();

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

110
111
    void DeleteSelectedAtoms();
    void OnlyKeepSelectedAtoms();
Tobias WEBER's avatar
Tobias WEBER committed
112
	void SelectAtomsOfSameType();
Tobias WEBER's avatar
Tobias WEBER committed
113
114
115
116
	void DeleteAtomUnderCursor();
	void DeleteAllAtomsOfSameType();
	void KeepAtomsOfSameType();

Tobias WEBER's avatar
Tobias WEBER committed
117
	virtual void closeEvent(QCloseEvent *evt) override;
Tobias WEBER's avatar
Tobias WEBER committed
118
	virtual void keyPressEvent(QKeyEvent *evt) override;
Tobias WEBER's avatar
Tobias WEBER committed
119

120
121
122

protected:
	MolDyn<t_real, t_vec> m_mol;
Tobias WEBER's avatar
Tobias WEBER committed
123
124
	t_mat m_crystA = tl2::unit<t_mat>(3);
	t_mat m_crystB = tl2::unit<t_mat>(3);
125
126
127

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

129
	QStatusBar *m_status = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
130
	QLabel *m_statusCurAtom = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
131
	QLabel *m_statusAtoms = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
132

Tobias WEBER's avatar
Tobias WEBER committed
133
	QSlider *m_sliderFrame = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
134
	QDoubleSpinBox *m_spinScale = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
135
	QMenu *m_atomContextMenu = nullptr;
136

Tobias WEBER's avatar
Tobias WEBER committed
137
	tl2::GlPlot *m_plot = nullptr;
138
139
140
	std::size_t m_sphere = 0;
	std::vector<std::size_t> m_sphereHandles;

141
	std::vector<Hull> m_hulls;
Tobias WEBER's avatar
Tobias WEBER committed
142

143

Tobias WEBER's avatar
Tobias WEBER committed
144
145
146
private:
	long m_curPickedObj = -1;
	bool m_ignoreChanges = 1;
Tobias WEBER's avatar
Tobias WEBER committed
147
148
149
150
};


#endif