Commit 44b7c110 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

continued with moldyn gui

parent b15ad7ec
......@@ -52,6 +52,7 @@ tools/cif2xml/build/**
tools/magstructfact/build/**
tools/magsgbrowser/build/**
tools/pol/build/**
tools/moldyn/build/**
*.pyc
.DS_Store
*.csv
......
......@@ -37,6 +37,17 @@ class MolFrame
m_config.push_back(config);
}
std::size_t GetNumAtoms() const
{
return m_config.size();
}
const std::vector<t_vec>& GetCoords(std::size_t atomidx) const
{
return m_config[atomidx];
}
private:
// atoms -> coordinates
std::vector<std::vector<t_vec>> m_config;
......@@ -105,6 +116,10 @@ class MolDyn
return 0;
}
// clear old data
Clear();
std::string strSys;
std::getline(ifstr, strSys);
tl2::trim(strSys);
......@@ -231,6 +246,31 @@ class MolDyn
}
void Clear()
{
m_vecAtoms.clear();
m_vecAtomNums.clear();
m_frames.clear();
}
std::size_t GetFrameCount() const
{
return m_frames.size();
}
const MolFrame<t_real, t_vec>& GetFrame(std::size_t frame) const
{
return m_frames[frame];
}
const std::string& GetAtomName(std::size_t idx) const
{
return m_vecAtoms[idx];
}
private:
t_vec m_baseA;
t_vec m_baseB;
......
......@@ -8,8 +8,6 @@
#include "moldyn.h"
#include <QtWidgets/QApplication>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox>
......@@ -45,19 +43,19 @@ MolDynDlg::MolDynDlg(QWidget* pParent) : QMainWindow{pParent},
auto acNew = new QAction("New", menuFile);
auto acLoad = new QAction("Load...", menuFile);
auto acSave = new QAction("Save...", menuFile);
//auto acSave = new QAction("Save...", menuFile);
auto acExit = new QAction("Exit", menuFile);
menuFile->addAction(acNew);
menuFile->addSeparator();
menuFile->addAction(acLoad);
menuFile->addAction(acSave);
//menuFile->addAction(acSave);
menuFile->addSeparator();
menuFile->addAction(acExit);
connect(acNew, &QAction::triggered, this, &MolDynDlg::New);
connect(acLoad, &QAction::triggered, this, &MolDynDlg::Load);
connect(acSave, &QAction::triggered, this, &MolDynDlg::Save);
//connect(acSave, &QAction::triggered, this, &MolDynDlg::Save);
connect(acExit, &QAction::triggered, this, &QDialog::close);
m_menu->addMenu(menuFile);
......@@ -70,6 +68,7 @@ MolDynDlg::MolDynDlg(QWidget* pParent) : QMainWindow{pParent},
m_plot = new GlPlot(this);
m_plot->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Expanding});
m_plot->GetImpl()->EnablePicker(1);
m_plot->GetImpl()->SetLight(0, m::create<t_vec3_gl>({ 5, 5, 5 }));
m_plot->GetImpl()->SetLight(1, m::create<t_vec3_gl>({ -5, -5, -5 }));
m_plot->GetImpl()->SetCoordMax(1.);
......@@ -100,27 +99,15 @@ MolDynDlg::MolDynDlg(QWidget* pParent) : QMainWindow{pParent},
/**
* add 3d object
*/
void MolDynDlg::Add3DItem(int row)
void MolDynDlg::Add3DItem(const t_vec& vec, const t_vec& col, t_real scale, const std::string& label)
{
if(!m_plot) return;
// add all items
if(row < 0)
{
//for(int row=0; row<m_nuclei->rowCount(); ++row)
// Add3DItem(row);
return;
}
qreal r=1, g=1, b=1;
QColor col;
col.getRgbF(&r, &g, &b);
//auto obj = m_plot->GetImpl()->AddLinkedObject(m_sphere, 0,0,0, r,g,b,1);
//auto obj = m_plot->GetImpl()->AddSphere(0.05, 0,0,0, r,g,b,1);
//m_plot->GetImpl()->SetObjectMatrix(obj, m::hom_translation<t_mat_gl>(posx, posy, posz)*m::hom_scaling<t_mat_gl>(scale,scale,scale));
//m_plot->GetImpl()->SetObjectLabel(obj, itemName->text().toStdString());
//m_plot->update();
auto obj = m_plot->GetImpl()->AddLinkedObject(m_sphere, 0,0,0, col[0],col[1],col[2],1);
//auto obj = m_plot->GetImpl()->AddSphere(0.05, 0,0,0, col[0],col[1],col[2],1);
m_plot->GetImpl()->SetObjectMatrix(obj, m::hom_translation<t_mat_gl>(vec[0], vec[1], vec[2])*m::hom_scaling<t_mat_gl>(scale,scale,scale));
m_plot->GetImpl()->SetObjectLabel(obj, label);
m_plot->update();
}
// ----------------------------------------------------------------------------
......@@ -130,11 +117,56 @@ void MolDynDlg::Add3DItem(int row)
// ----------------------------------------------------------------------------
void MolDynDlg::New()
{
m_mol.Clear();
}
void MolDynDlg::Load()
{
m_ignoreCalc = 1;
try
{
QString dirLast = m_sett->value("dir", "").toString();
QString filename = QFileDialog::getOpenFileName(this, "Load File", dirLast, "Molecular Dynamics File (*)");
if(filename=="" || !QFile::exists(filename))
return;
m_sett->setValue("dir", QFileInfo(filename).path());
if(!m_mol.LoadFile(filename.toStdString(), 100))
{
QMessageBox::critical(this, "Molecular Dynamics", "Error loading file.");
}
std::vector<t_vec> cols =
{
m::create<t_vec>({1, 0, 0}),
m::create<t_vec>({0, 0, 1}),
m::create<t_vec>({0, 0.5, 0}),
m::create<t_vec>({0, 0.5, 0.5}),
m::create<t_vec>({0.5, 0.5, 0}),
m::create<t_vec>({0, 0, 0}),
};
if(m_mol.GetFrameCount())
{
const auto& frame = m_mol.GetFrame(0);
for(std::size_t atomidx=0; atomidx<frame.GetNumAtoms(); ++atomidx)
{
const auto& coords = frame.GetCoords(atomidx);
for(const t_vec& vec : coords)
Add3DItem(vec, cols[atomidx % cols.size()], 0.5, m_mol.GetAtomName(atomidx));
}
}
}
catch(const std::exception& ex)
{
QMessageBox::critical(this, "Molecular Dynamics", ex.what());
}
m_ignoreCalc = 0;
}
......@@ -159,10 +191,12 @@ void MolDynDlg::PickerIntersection(const t_vec3_gl* pos, std::size_t objIdx, con
if(m_curPickedObj > 0)
{
// TODO
std::cout << m_curPickedObj << std::endl;
}
else
{
Set3DStatusMsg("");
SetStatusMsg("");
}
}
......@@ -171,7 +205,7 @@ void MolDynDlg::PickerIntersection(const t_vec3_gl* pos, std::size_t objIdx, con
/**
* set status label text in 3d dialog
*/
void MolDynDlg::Set3DStatusMsg(const std::string& msg)
void MolDynDlg::SetStatusMsg(const std::string& msg)
{
if(!m_status) return;
......@@ -210,9 +244,6 @@ void MolDynDlg::AfterGLInitialisation()
m_sphere = m_plot->GetImpl()->AddSphere(0.05, 0.,0.,0., 1.,1.,1.,1.);
m_plot->GetImpl()->SetObjectVisible(m_sphere, false);
// add all 3d objects
Add3DItem(-1);
// GL device info
auto [strGlVer, strGlShaderVer, strGlVendor, strGlRenderer]
= m_plot->GetImpl()->GetGlDescr();
......
......@@ -9,19 +9,18 @@
#define __MOLDYN_GUI_H__
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QDialog>
#include <QtWidgets/QMenu>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QMenu>
#include <QtWidgets/QLabel>
#include <QtCore/QSettings>
#include <vector>
#include <sstream>
#include "libs/_cxx20/glplot.h"
#include "libs/_cxx20/math_algos.h"
#include "moldyn-loader.h"
using t_real = double;
using t_vec = std::vector<t_real>;
......@@ -35,6 +34,8 @@ public:
~MolDynDlg() = default;
protected:
MolDyn<t_real, t_vec> m_mol;
QSettings *m_sett = nullptr;
QMenuBar *m_menu = nullptr;
QStatusBar *m_status = nullptr;
......@@ -44,8 +45,8 @@ protected:
protected:
void Add3DItem(int row=-1);
void Set3DStatusMsg(const std::string& msg);
void Add3DItem(const t_vec& vec, const t_vec& col, t_real scale, const std::string& label);
void SetStatusMsg(const std::string& msg);
void New();
void Load();
......@@ -61,6 +62,7 @@ protected:
private:
long m_curPickedObj = -1;
bool m_ignoreChanges = 1;
bool m_ignoreCalc = 1;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment