Verified Commit ee0f4f31 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

bz tool: continued with gui

parent 8563f3c7
......@@ -45,7 +45,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
endif()
find_package(Boost REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Svg)
find_package(Qhull)
if(Qhull_FOUND)
......@@ -86,5 +86,5 @@ endif()
target_link_libraries(takin_bz
${Boost_LIBRARIES}
${Qhull_LIBRARIES}
Qt5::Core Qt5::Gui Qt5::Widgets
Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Svg
)
......@@ -226,8 +226,10 @@ BZDlg::BZDlg(QWidget* pParent) : QDialog{pParent},
connect(m_BZOrder,
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, [this]() { this->CalcBZCut(); });
connect(m_bzview, &BZCutView::SignalMouseCoordinates,
this, &BZDlg::BZCutMouseMoved);
tabs->addTab(cutspanel, "Cut");
tabs->addTab(cutspanel, "BZ Cut");
}
......@@ -319,11 +321,17 @@ BZDlg::BZDlg(QWidget* pParent) : QDialog{pParent},
}
// status bar
m_status = new QLabel(this);
m_status->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
m_status->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
// main grid
auto pmainGrid = new QGridLayout(this);
pmainGrid->setSpacing(4);
pmainGrid->setContentsMargins(4,4,4,4);
pmainGrid->addWidget(tabs, 0,0, 1,1);
auto main_grid = new QGridLayout(this);
main_grid->setSpacing(4);
main_grid->setContentsMargins(4,4,4,4);
main_grid->addWidget(tabs, 0,0, 1,1);
main_grid->addWidget(m_status, 1,0, 1,1);
// menu bar
......@@ -341,6 +349,7 @@ BZDlg::BZDlg(QWidget* pParent) : QDialog{pParent},
auto acImportCIF = new QAction("Import CIF...", menuFile);
auto acExit = new QAction("Quit", menuFile);
auto ac3DView = new QAction("3D View...", menuFile);
auto acCutSVG = new QAction("Save Cut to SVG...", menuFile);
acNew->setShortcut(QKeySequence::New);
acLoad->setShortcut(QKeySequence::Open);
......@@ -358,30 +367,19 @@ BZDlg::BZDlg(QWidget* pParent) : QDialog{pParent},
menuFile->addSeparator();
menuFile->addAction(acExit);
menuView->addAction(ac3DView);
menuView->addAction(acCutSVG);
connect(acNew, &QAction::triggered, this, [this]()
{
// clear old table
DelTabItem(-1);
// set some defaults
m_comboSG->setCurrentIndex(0);
m_editA->setText("5");
m_editB->setText("5");
m_editC->setText("5");
m_editAlpha->setText("90");
m_editBeta->setText("90");
m_editGamma->setText("90");
});
connect(acNew, &QAction::triggered, this, &BZDlg::NewFile);
connect(acLoad, &QAction::triggered, this, &BZDlg::Load);
connect(acSave, &QAction::triggered, this, &BZDlg::Save);
connect(acImportCIF, &QAction::triggered, this, &BZDlg::ImportCIF);
connect(acExit, &QAction::triggered, this, &QDialog::close);
connect(ac3DView, &QAction::triggered, this, &BZDlg::ShowBZPlot);
connect(acCutSVG, &QAction::triggered, this, &BZDlg::SaveCutSVG);
m_menu->addMenu(menuFile);
m_menu->addMenu(menuView);
pmainGrid->setMenuBar(m_menu);
main_grid->setMenuBar(m_menu);
}
......
......@@ -69,6 +69,7 @@ public:
protected:
QSettings *m_sett = nullptr;
QMenuBar *m_menu = nullptr;
QLabel *m_status = nullptr;
// plotter
QDialog *m_dlgPlot = nullptr;
......@@ -114,6 +115,8 @@ protected:
t_mat m_crystA = tl2::unit<t_mat>(3);
t_mat m_crystB = tl2::unit<t_mat>(3);
t_mat m_cut_plane = tl2::unit<t_mat>(3);
t_mat m_cut_plane_inv = tl2::unit<t_mat>(3);
std::vector<std::vector<t_mat>> m_SGops;
......@@ -130,24 +133,29 @@ protected:
void TableItemChanged(QTableWidgetItem *item);
void ShowTableContextMenu(const QPoint& pt);
void NewFile();
void Load();
void Save();
void ImportCIF();
void GetSymOpsFromSG();
void SaveCutSVG();
std::vector<t_mat> GetSymOps(bool only_centring = false) const;
void CalcB(bool full_recalc = true);
void CalcBZ(bool full_recalc = true);
void CalcBZCut();
void ClearPlot();
// 3d bz cut plot
void BZCutMouseMoved(t_real x, t_real y);
// 3d bz plot
void ShowBZPlot();
void ClearBZPlot();
void PlotAddVoronoiVertex(const t_vec& pos);
void PlotAddBraggPeak(const t_vec& pos);
void PlotAddTriangles(const std::vector<t_vec>& vecs);
void PlotSetPlane(const t_vec& norm, t_real d);
void Set3DStatusMsg(const std::string& msg);
void ShowBZPlot();
void PlotShowCoordCross(bool show);
void PlotShowLabels(bool show);
void PlotShowPlane(bool show);
......
......@@ -85,7 +85,7 @@ void BZDlg::CalcB(bool full_recalc)
}
m_crystA = crystA * t_real(2)*tl2::pi<t_real>;
m_crystB = crystB;
m_crystB = std::move(crystB);
if(m_plot)
{
......@@ -149,7 +149,7 @@ void BZDlg::CalcBZ(bool full_recalc)
geo::calc_delaunay(3, Qs_invA, false, false, idx000);
voronoi = tl2::remove_duplicates(voronoi, g_eps);
ClearPlot();
ClearBZPlot();
m_bz_polys.clear();
#ifdef DEBUG
......@@ -252,7 +252,8 @@ void BZDlg::CalcBZCut()
vec1 /= tl2::norm<t_vec>(vec1);
vec2 /= tl2::norm<t_vec>(vec2);
t_mat matPlane = tl2::create<t_mat, t_vec>({ vec1, vec2, norm }, true);
m_cut_plane = tl2::create<t_mat, t_vec>({ vec1, vec2, norm }, false);
m_cut_plane_inv = tl2::trans<t_mat>(m_cut_plane);
std::vector<std::pair<t_vec, t_vec>> cut_lines, cut_lines000;
......@@ -288,8 +289,8 @@ void BZDlg::CalcBZCut()
if(vecs.size() >= 2)
{
t_vec pt1 = matPlane * vecs[0];
t_vec pt2 = matPlane * vecs[1];
t_vec pt1 = m_cut_plane_inv * vecs[0];
t_vec pt2 = m_cut_plane_inv * vecs[1];
tl2::set_eps_0(pt1, g_eps);
tl2::set_eps_0(pt2, g_eps);
......@@ -319,3 +320,25 @@ void BZDlg::CalcBZCut()
PlotSetPlane(norm, d);
UpdateBZDescription();
}
/**
* calculate reciprocal coordinates of the cursor position
*/
void BZDlg::BZCutMouseMoved(t_real x, t_real y)
{
t_real d = m_cutD->value();
t_vec QinvA = m_cut_plane * tl2::create<t_vec>({ x, y, d });
t_mat B_inv = m_crystA / (t_real(2)*tl2::pi<t_real>);
t_vec Qrlu = B_inv * QinvA;
tl2::set_eps_0(QinvA, g_eps);
tl2::set_eps_0(Qrlu, g_eps);
std::ostringstream ostr;
ostr.precision(g_prec_gui);
ostr << "Q = (" << QinvA[0] << ", " << QinvA[1] << ", " << QinvA[2] << ") Å⁻¹";
ostr << " = (" << Qrlu[0] << ", " << Qrlu[1] << ", " << Qrlu[2] << ") rlu.";
m_status->setText(ostr.str().c_str());
}
......@@ -29,6 +29,7 @@
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox>
#include <QtSvg/QSvgGenerator>
#include <iostream>
#include <fstream>
......@@ -43,6 +44,37 @@ namespace pt = boost::property_tree;
using namespace tl2_ops;
void BZDlg::NewFile()
{
m_ignoreCalc = 1;
// clear old table
DelTabItem(-1);
// set some defaults
m_comboSG->setCurrentIndex(0);
m_editA->setText("5");
m_editB->setText("5");
m_editC->setText("5");
m_editAlpha->setText("90");
m_editBeta->setText("90");
m_editGamma->setText("90");
m_cutX->setValue(1);
m_cutY->setValue(0);
m_cutZ->setValue(0);
m_cutNX->setValue(0);
m_cutNY->setValue(0);
m_cutNZ->setValue(1);
m_cutD->setValue(0);
m_BZOrder->setValue(4);
m_maxBZ->setValue(4);
m_ignoreCalc = 0;
CalcB(true);
}
void BZDlg::Load()
{
m_ignoreCalc = 1;
......@@ -109,6 +141,38 @@ void BZDlg::Load()
{
m_maxBZ->setValue(*opt);
}
if(auto opt = node.get_optional<int>("bz.cut.order"); opt)
{
m_BZOrder->setValue(*opt);
}
if(auto opt = node.get_optional<t_real>("bz.cut.x"); opt)
{
m_cutX->setValue(*opt);
}
if(auto opt = node.get_optional<t_real>("bz.cut.y"); opt)
{
m_cutY->setValue(*opt);
}
if(auto opt = node.get_optional<t_real>("bz.cut.z"); opt)
{
m_cutZ->setValue(*opt);
}
if(auto opt = node.get_optional<t_real>("bz.cut.nx"); opt)
{
m_cutNX->setValue(*opt);
}
if(auto opt = node.get_optional<t_real>("bz.cut.ny"); opt)
{
m_cutNY->setValue(*opt);
}
if(auto opt = node.get_optional<t_real>("bz.cut.nz"); opt)
{
m_cutNZ->setValue(*opt);
}
if(auto opt = node.get_optional<t_real>("bz.cut.d"); opt)
{
m_cutD->setValue(*opt);
}
if(auto opt = node.get_optional<int>("bz.sg_idx"); opt)
{
m_comboSG->setCurrentIndex(*opt);
......@@ -136,8 +200,7 @@ void BZDlg::Load()
m_ignoreCalc = 0;
CalcB(false);
CalcBZ();
CalcB(true);
}
......@@ -172,6 +235,14 @@ void BZDlg::Save()
node.put<t_real>("bz.xtal.beta", beta);
node.put<t_real>("bz.xtal.gamma", gamma);
node.put<int>("bz.order", m_maxBZ->value());
node.put<int>("bz.cut.order", m_BZOrder->value());
node.put<t_real>("bz.cut.x", m_cutX->value());
node.put<t_real>("bz.cut.y", m_cutY->value());
node.put<t_real>("bz.cut.z", m_cutZ->value());
node.put<t_real>("bz.cut.nx", m_cutNX->value());
node.put<t_real>("bz.cut.ny", m_cutNY->value());
node.put<t_real>("bz.cut.nz", m_cutNZ->value());
node.put<t_real>("bz.cut.d", m_cutD->value());
node.put<int>("bz.sg_idx", m_comboSG->currentIndex());
// symop list
......@@ -262,6 +333,28 @@ void BZDlg::ImportCIF()
m_ignoreCalc = 0;
CalcB(false);
CalcBZ();
CalcB(true);
}
void BZDlg::SaveCutSVG()
{
QString dirLast = m_sett->value("dir", "").toString();
QString filename = QFileDialog::getSaveFileName(
this, "Save SVG File", dirLast, "SVG Files (*.svg *.SVG)");
if(filename=="")
return;
m_sett->setValue("dir", QFileInfo(filename).path());
QSvgGenerator svg;
svg.setSize(QSize{800, 800});
svg.setViewBox(QRect{0, 0, 800, 800});
svg.setFileName(filename);
svg.setTitle("Brillouin Zone Cut");
svg.setDescription("Created with Takin (https://doi.org/10.5281/zenodo.4117437).");
QPainter painter;
painter.begin(&svg);
m_bzscene->render(&painter);
painter.end();
}
......@@ -105,7 +105,8 @@ void BZDlg::AddTabItem(int row, const t_mat& op)
if(bclone)
{
for(int thecol=0; thecol<NUM_COLS; ++thecol)
m_symops->setItem(row, thecol, m_symops->item(m_iCursorRow, thecol)->clone());
m_symops->setItem(row, thecol,
m_symops->item(m_iCursorRow, thecol)->clone());
}
else
{
......@@ -119,7 +120,7 @@ void BZDlg::AddTabItem(int row, const t_mat& op)
m_symops->setSortingEnabled(/*sorting*/ true);
m_ignoreChanges = 0;
CalcBZ();
CalcBZ(true);
}
......@@ -136,20 +137,16 @@ void BZDlg::DelTabItem(int begin, int end)
else if(begin == -2) // clear selected
{
for(int row : GetSelectedRows(true))
{
m_symops->removeRow(row);
}
}
else if(begin >= 0 && end >= 0) // clear given range
{
for(int row=end-1; row>=begin; --row)
{
m_symops->removeRow(row);
}
}
m_ignoreChanges = 0;
CalcBZ();
CalcBZ(true);
}
......@@ -283,7 +280,7 @@ void BZDlg::TableItemChanged(QTableWidgetItem *item)
}
if(!m_ignoreChanges)
CalcBZ();
CalcBZ(true);
}
......@@ -341,8 +338,7 @@ void BZDlg::GetSymOpsFromSG()
m_ignoreCalc = 0;
CalcB(false);
CalcBZ();
CalcB(true);
}
......
......@@ -265,7 +265,7 @@ void BZDlg::PlotSetPlane(const t_vec& _norm, t_real d)
}
void BZDlg::ClearPlot()
void BZDlg::ClearBZPlot()
{
if(!m_plot) return;
......
......@@ -49,6 +49,7 @@ using t_mat_gl = tl2::t_mat_gl;
constexpr t_real g_eps = 1e-6;
constexpr int g_prec = 6;
constexpr int g_prec_gui = 4;
#endif
......@@ -47,6 +47,7 @@ void BZCutScene::AddCut(const std::vector<std::pair<t_vec, t_vec>>& lines)
QPen pen;
pen.setCosmetic(true);
pen.setColor(qApp->palette().color(QPalette::WindowText));
pen.setWidthF(2.);
addLine(QLineF(
line.first[0]*m_scale, line.first[1]*m_scale,
......@@ -60,12 +61,14 @@ void BZCutScene::AddCut(const std::vector<std::pair<t_vec, t_vec>>& lines)
// --------------------------------------------------------------------------------
BZCutView::BZCutView(BZCutScene* scene)
: QGraphicsView(scene, static_cast<QWidget*>(scene->parent()))
: QGraphicsView(scene, static_cast<QWidget*>(scene->parent())),
m_scene(scene)
{
setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
setDragMode(QGraphicsView::ScrollHandDrag);
setInteractive(true);
setMouseTracking(true);
scale(1., -1.);
}
......@@ -74,6 +77,16 @@ BZCutView::~BZCutView()
}
void BZCutView::mouseMoveEvent(QMouseEvent *evt)
{
QPointF pos = mapToScene(evt->pos());
t_real scale = m_scene->GetScale();
emit SignalMouseCoordinates(pos.x()/scale, pos.y()/scale);
QGraphicsView::mouseMoveEvent(evt);
}
void BZCutView::wheelEvent(QWheelEvent *evt)
{
t_real sc = std::pow(2., evt->angleDelta().y()/8.*0.01);
......
......@@ -31,6 +31,7 @@
#include <QtWidgets/QGraphicsScene>
#include <QtWidgets/QGraphicsView>
#include <QtWidgets/QGraphicsItem>
#include <QtGui/QMouseEvent>
#include <QtGui/QWheelEvent>
#include "globals.h"
......@@ -43,6 +44,7 @@ public:
virtual ~BZCutScene();
void AddCut(const std::vector<std::pair<t_vec, t_vec>>& lines);
t_real GetScale() const { return m_scale; }
protected:
......@@ -51,14 +53,23 @@ protected:
class BZCutView : public QGraphicsView
{
{ Q_OBJECT
public:
BZCutView(BZCutScene* scene);
virtual ~BZCutView();
protected:
virtual void mouseMoveEvent(QMouseEvent *evt) override;
virtual void wheelEvent(QWheelEvent *evt) override;
signals:
void SignalMouseCoordinates(t_real x, t_real y);
protected:
BZCutScene* m_scene = nullptr;
};
......
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