PeriDyno 1.0.0
Loading...
Searching...
No Matches
QtApp.cpp
Go to the documentation of this file.
1#include <QMap>
2#include <QDebug>
3#include <QFile>
4#include "QtApp.h"
5#include "PMainWindow.h"
6#include "POpenGLWidget.h"
7#include "Log.h"
8
9#include "SceneGraphFactory.h"
11
12#include <OrbitCamera.h>
13
14namespace dyno {
15 QtApp::QtApp(int argc, char **argv)
16 {
17#ifdef CUDA_BACKEND
18 auto status = cudaSetDevice(0);
19 if (status != cudaSuccess) {
20 fprintf(stderr, "CUDA initialization failed! Do you have a CUDA-capable GPU installed?");
21 exit(0);
22 }
23 cudaFree(0);
24#endif // CUDA_BACKEND
25
26 mMainWindow = nullptr;
27
28 //To fix the displace scaling issue
29 QApplication::setAttribute(Qt::AA_Use96Dpi);
30 qputenv("QT_ENABLE_HIGHDPI_SCALING", "0");
31
32 mQApp = std::make_shared<QApplication>(argc, argv);
33
34 //Set default GUI style
35 QFile file(":/dyno/DarkStyle.qss");
36 file.open(QIODevice::ReadOnly);
37
38 QString style = file.readAll();
39 mQApp->setStyleSheet(style);
40
41 //To resolver the error "Cannot queue arguments of type of Log::Message" for multi-thread applications
42 qRegisterMetaType<Log::Message>("Log::Message");
43 }
44
46 {
47
48 }
49
50 void QtApp::initialize(int width, int height, bool usePlugin)
51 {
52 //A hack to address the slow launching problem
53
54 if (usePlugin)
55 {
56#ifdef NDEBUG
57 PluginManager::instance()->loadPluginByPath(getPluginPath() + "Release");
58#else
59 PluginManager::instance()->loadPluginByPath(getPluginPath() + "Debug");
60#endif // DEBUG
61 }
62
63 mMainWindow = std::make_shared<PMainWindow>(this);
64 mMainWindow->resize(width, height);
65 mMainWindow->show();
66 }
67
69 {
70 mQApp->exec();
71 }
72
73 void QtApp::setSceneGraph(std::shared_ptr<SceneGraph> scn)
74 {
77 }
78
79 void QtApp::setWindowTitle(const std::string& str)
80 {
81 mMainWindow->setWindowTitle(QString::fromStdString(str));
82 }
83
85 {
86 return dynamic_cast<RenderWindow*>(mMainWindow->openglWidget());
87 }
88
89}
90
virtual void setSceneGraph(std::shared_ptr< SceneGraph > scene)
Definition AppBase.h:25
static PluginManager * instance()
void loadPluginByPath(const std::string &pathName)
void setSceneGraph(std::shared_ptr< SceneGraph > scn)
Definition QtApp.cpp:73
RenderWindow * renderWindow() override
Definition QtApp.cpp:84
std::shared_ptr< PMainWindow > mMainWindow
Definition QtApp.h:33
void mainLoop() override
Definition QtApp.cpp:68
std::shared_ptr< QApplication > mQApp
Definition QtApp.h:32
QtApp(int argc=0, char **argv=NULL)
Definition QtApp.cpp:15
void initialize(int width, int height, bool usePlugin=true) override
Definition QtApp.cpp:50
void setWindowTitle(const std::string &str)
Definition QtApp.cpp:79
static SceneGraphFactory * instance()
void pushScene(std::shared_ptr< SceneGraph > scn)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25