Verified Commit 94e3bd64 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

a) made gui compacter; b) cleanups

parent 5d54f01e
......@@ -118,8 +118,11 @@ void PathsRenderer::Clear()
/**
* create a 3d representation of the instrument and walls
*/
void PathsRenderer::LoadInstrument(const InstrumentSpace& instrspace)
bool PathsRenderer::LoadInstrument(const InstrumentSpace& instrspace)
{
if(!m_initialised)
return false;
Clear();
// upper and lower floor plane
......@@ -172,6 +175,7 @@ void PathsRenderer::LoadInstrument(const InstrumentSpace& instrspace)
}
update();
return true;
}
......@@ -180,6 +184,9 @@ void PathsRenderer::LoadInstrument(const InstrumentSpace& instrspace)
*/
void PathsRenderer::AddWall(const Geometry& wall, bool update_scene)
{
if(!m_initialised)
return;
auto [_verts, _norms, _uvs] = wall.GetTriangles();
auto verts = tl2::convert<t_vec3_gl>(_verts);
......@@ -204,6 +211,9 @@ void PathsRenderer::AddWall(const Geometry& wall, bool update_scene)
*/
void PathsRenderer::UpdateInstrumentSpace(const InstrumentSpace& instr)
{
if(!m_initialised)
return;
// update wall matrices
for(const auto& wall : instr.GetWalls())
{
......@@ -219,6 +229,9 @@ void PathsRenderer::UpdateInstrumentSpace(const InstrumentSpace& instr)
*/
void PathsRenderer::UpdateInstrument(const Instrument& instr)
{
if(!m_initialised)
return;
// instrument axes
const auto& mono = instr.GetMonochromator();
const auto& sample = instr.GetSample();
......
......@@ -80,7 +80,7 @@ public:
virtual ~PathsRenderer();
void Clear();
void LoadInstrument(const InstrumentSpace& instr);
bool LoadInstrument(const InstrumentSpace& instr);
void AddWall(const Geometry& geo, bool update_scene=true);
// receivers for instrument (space) update signals
......
......@@ -45,6 +45,7 @@ namespace pt = boost::property_tree;
#include "tlibs2/libs/file.h"
#include "tlibs2/libs/algos.h"
#include "tlibs2/libs/helper.h"
#include "tlibs2/libs/log.h"
#if defined(__MINGW32__) || defined(__MINGW64__)
......@@ -167,7 +168,7 @@ void PathsTool::OpenFile()
{
QString dirLast = m_sett.value("cur_dir", "").toString();
QFileDialog filedlg(this, "Open File", dirLast,
QFileDialog filedlg(this, "Open Instrument File", dirLast,
"TAS-Paths Files (*.taspaths)");
filedlg.setAcceptMode(QFileDialog::AcceptOpen);
filedlg.setDefaultSuffix("taspaths");
......@@ -204,7 +205,7 @@ void PathsTool::SaveFileAs()
{
QString dirLast = m_sett.value("cur_dir", "").toString();
QFileDialog filedlg(this, "Open File", dirLast,
QFileDialog filedlg(this, "Save Instrument File", dirLast,
"TAS-Paths Files (*.taspaths)");
filedlg.setAcceptMode(QFileDialog::AcceptSave);
filedlg.setDefaultSuffix("taspaths");
......@@ -308,8 +309,12 @@ bool PathsTool::ExportPath(PathsExporterFormat fmt)
/**
* load file
*/
bool PathsTool::OpenFile(const QString &file)
bool PathsTool::OpenFile(const QString& file)
{
// no file given
if(file == "")
return false;
try
{
NewFile();
......@@ -496,6 +501,7 @@ bool PathsTool::SaveFile(const QString &file)
// set format and version
prop.put(FILE_BASENAME "ident", PROG_IDENT);
prop.put(FILE_BASENAME "doi", "https://doi.org/10.5281/zenodo.4625649");
prop.put(FILE_BASENAME "timestamp", tl2::var_to_str(tl2::epoch<t_real>()));
std::string filename = file.toStdString();
......@@ -1044,7 +1050,8 @@ PathsTool::PathsTool(QWidget* pParent) : QMainWindow{pParent}
addDockWidget(Qt::RightDockWidgetArea, m_coordProperties.get());
addDockWidget(Qt::RightDockWidgetArea, m_pathProperties.get());
addDockWidget(Qt::RightDockWidgetArea, m_camProperties.get());
//addDockWidget(Qt::NoDockWidgetArea, m_xtalInfos.get());
addDockWidget(Qt::RightDockWidgetArea, m_xtalInfos.get());
m_xtalInfos->hide();
auto* taswidget = m_tasProperties->GetWidget().get();
auto* xtalwidget = m_xtalProperties->GetWidget().get();
......
......@@ -160,6 +160,12 @@ public:
void SetInitialInstrumentFile(const std::string& file);
// load file
bool OpenFile(const QString &file);
// save file
bool SaveFile(const QString &file);
protected:
// events
......@@ -172,12 +178,6 @@ protected:
// File -> Export Path
bool ExportPath(PathsExporterFormat fmt);
// load file
bool OpenFile(const QString &file);
// save file
bool SaveFile(const QString &file);
// save a screenshot of the instrument 3d view
bool SaveScreenshot(const QString& file);
......
......@@ -57,9 +57,9 @@ TASPropertiesWidget::TASPropertiesWidget(QWidget *parent)
m_checkScatteringSense[1] = new QCheckBox(this);
m_checkScatteringSense[2] = new QCheckBox(this);
m_checkScatteringSense[0]->setText("Monochromator ccw");
m_checkScatteringSense[1]->setText("Sample ccw");
m_checkScatteringSense[2]->setText("Analyser ccw");
m_checkScatteringSense[0]->setText("Mono.");
m_checkScatteringSense[1]->setText("Sample");
m_checkScatteringSense[2]->setText("Analyser");
m_checkScatteringSense[0]->setToolTip("Move the monochromator scattering angle in the counterclockwise direction.");
m_checkScatteringSense[1]->setToolTip("Move the sample scattering angle in the counterclockwise direction.");
m_checkScatteringSense[2]->setToolTip("Move the analyser scattering angle in the counterclockwise direction.");
......@@ -151,10 +151,11 @@ TASPropertiesWidget::TASPropertiesWidget(QWidget *parent)
layoutScatter->setVerticalSpacing(2);
layoutScatter->setContentsMargins(4,4,4,4);
int x = 0;
int y = 0;
layoutScatter->addWidget(m_checkScatteringSense[0], y++, 0, 1, 2);
layoutScatter->addWidget(m_checkScatteringSense[1], y++, 0, 1, 2);
layoutScatter->addWidget(m_checkScatteringSense[2], y++, 0, 1, 2);
for(int comp=0; comp<3; ++comp)
layoutScatter->addWidget(
m_checkScatteringSense[comp], y, x++, 1, 1);
}
/*auto *groupOptions = new QGroupBox("Options", this);
......
......@@ -25,6 +25,7 @@
#include <QtCore/QDir>
#include <QtCore/QLoggingCategory>
#include <QtGui/QFileOpenEvent>
#include <QtWidgets/QApplication>
#include "PathsTool.h"
......@@ -34,7 +35,110 @@
/**
* main
* main application
*/
class PathsApp : public QApplication
{
public:
/**
* constructor getting command-line arguments
*/
explicit PathsApp(int& argc, char **argv) : QApplication{argc, argv}
{
// application settings
//QApplication::setAttribute(Qt::AA_NativeWindows, true);
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
QApplication::addLibraryPath(QDir::currentPath() + QDir::separator() + "Qt_Plugins");
setOrganizationName("tw");
setApplicationName("taspaths");
//setApplicationDisplayName(TASPATHS_TITLE);
setApplicationVersion(TASPATHS_VERSION);
// application path
g_apppath = applicationDirPath().toStdString();
addLibraryPath(applicationDirPath() + QDir::separator() + ".." +
QDir::separator() + "Libraries" + QDir::separator() + "Qt_Plugins");
#ifdef DEBUG
std::cout << "Application binary path: " << g_apppath << "." << std::endl;
#endif
}
/**
* no default constructor
*/
PathsApp() = delete;
/**
* default destructor
*/
virtual ~PathsApp() = default;
/**
* get the initial file to be loaded
*/
const QString& GetInitialFile() const
{
return m_init_file;
}
/**
* associate a main window with the application
*/
void SetMainWnd(const std::shared_ptr<PathsTool>& paths)
{
m_paths = paths;
}
protected:
/**
* receive file open events
* @see https://doc.qt.io/qt-5/qfileopenevent.html
*/
virtual bool event(QEvent *evt) override
{
if(!evt)
return false;
switch(evt->type())
{
// open a file
case QEvent::FileOpen:
{
m_init_file = static_cast<QFileOpenEvent*>(evt)->file();
// if the main window is ready, directly open it
if(m_paths)
m_paths->OpenFile(m_init_file);
break;
}
default:
{
break;
}
}
return QApplication::event(evt);
}
private:
// file requested to open
QString m_init_file{};
// main application window
std::shared_ptr<PathsTool> m_paths{};
};
/**
* main entry point
*/
int main(int argc, char** argv)
{
......@@ -71,6 +175,7 @@ int main(int argc, char** argv)
<< "function " << get_str(ctx.function) << ", "
<< "line " << ctx.line;
}
std::cerr << ": " << log.toStdString() << std::endl;
});
......@@ -81,25 +186,10 @@ int main(int argc, char** argv)
// set maximum number of threads
g_maxnum_threads = std::max<unsigned int>(1, std::thread::hardware_concurrency()/2);
// application settings
//QApplication::setAttribute(Qt::AA_NativeWindows, true);
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
QApplication::addLibraryPath(QDir::currentPath() + QDir::separator() + "Qt_Plugins");
// create application
auto app = std::make_unique<QApplication>(argc, argv);
app->setOrganizationName("tw");
app->setApplicationName("taspaths");
//app->setApplicationDisplayName(TASPATHS_TITLE);
app->setApplicationVersion(TASPATHS_VERSION);
// application path
g_apppath = app->applicationDirPath().toStdString();
app->addLibraryPath(app->applicationDirPath() + QDir::separator() + ".." +
QDir::separator() + "Libraries" + QDir::separator() + "Qt_Plugins");
std::cout << "Application binary path: " << g_apppath << "." << std::endl;
auto app = std::make_unique<PathsApp>(argc, argv);
// resource paths
// set up resource paths
fs::path apppath = g_apppath;
g_res.AddPath((apppath / "res").string());
g_res.AddPath((apppath / ".." / "res").string());
......@@ -111,6 +201,7 @@ int main(int argc, char** argv)
g_res.AddPath(fs::path("/usr/share/taspaths/res").string());
g_res.AddPath(fs::path("/usr/local/share/taspaths").string());
g_res.AddPath(fs::path("/usr/share/taspaths").string());
g_res.AddPath(fs::current_path().string());
// make type definitions known as qt meta objects
qRegisterMetaType<t_real>("t_real");
......@@ -120,9 +211,13 @@ int main(int argc, char** argv)
qRegisterMetaType<CalculationState>("CalculationState");
// create main window
auto mainwnd = std::make_unique<PathsTool>(nullptr);
auto mainwnd = std::make_shared<PathsTool>(nullptr);
// the main window is not yet ready, indirectly open a given file
if(argc > 1)
mainwnd->SetInitialInstrumentFile(argv[1]);
else if(const QString& init_file = app->GetInitialFile(); init_file!="")
mainwnd->SetInitialInstrumentFile(init_file.toStdString());
// sequence to show the window,
// see: https://doc.qt.io/qt-5/qdialog.html#code-examples
......@@ -131,6 +226,7 @@ int main(int argc, char** argv)
mainwnd->activateWindow();
// run application
app->SetMainWnd(mainwnd);
return app->exec();
}
catch(const std::exception& ex)
......
......@@ -60,7 +60,9 @@ namespace ptree = boost::property_tree;
#include "src/libs/hull.h"
#include "src/libs/voronoi.h"
#include "src/libs/graphs.h"
#include "tlibs2/libs/helper.h"
#include "tlibs2/libs/log.h"
#include "tlibs2/libs/qt/numerictablewidgetitem.h"
......@@ -1138,6 +1140,9 @@ bool HullWnd::SaveFile(const QString& file)
}
ptree::ptree prop{};
prop.put("lines2d.ident", "takin_taspaths_hull");
prop.put("lines2d.doi", "https://doi.org/10.5281/zenodo.4625649");
prop.put("lines2d.timestamp", tl2::var_to_str(tl2::epoch<t_real>()));
std::size_t vertidx = 0;
for(const Vertex* vertex : m_scene->GetVertices())
......
......@@ -53,6 +53,8 @@
#include <iostream>
#include "tlibs2/libs/helper.h"
#include "tlibs2/libs/log.h"
#include "src/libs/voronoi_lines.h"
#include "settings_variables.h"
#include "src/core/mingw_hacks.h"
......@@ -1491,6 +1493,9 @@ bool LinesWnd::SaveFile(const QString& file)
}
ptree::ptree prop{};
prop.put("lines2d.ident", "takin_taspaths_lines");
prop.put("lines2d.doi", "https://doi.org/10.5281/zenodo.4625649");
prop.put("lines2d.timestamp", tl2::var_to_str(tl2::epoch<t_real>()));
std::size_t vertidx = 0;
for(const Vertex* vertex : m_scene->GetVertexElems())
......
......@@ -49,6 +49,7 @@ namespace ptree = boost::property_tree;
#include "settings_variables.h"
#include "tlibs2/libs/helper.h"
#include "tlibs2/libs/log.h"
// ----------------------------------------------------------------------------
......@@ -760,6 +761,9 @@ bool PolyWnd::SaveFile(const QString& file)
}
ptree::ptree prop{};
prop.put("lines2d.ident", "takin_taspaths_poly");
prop.put("lines2d.doi", "https://doi.org/10.5281/zenodo.4625649");
prop.put("lines2d.timestamp", tl2::var_to_str(tl2::epoch<t_real>()));
std::size_t vertidx = 0;
for(const Vertex* vertex : m_view->GetVertexElems())
......
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