2014-08-28 08:29:12 +00:00
|
|
|
#include "MainModelerWindow.h"
|
|
|
|
|
2015-08-12 15:02:27 +00:00
|
|
|
#include "Logs.h"
|
2014-08-28 08:29:12 +00:00
|
|
|
#include "OpenGLView.h"
|
|
|
|
#include "Scenery.h"
|
|
|
|
#include "OpenGLRenderer.h"
|
2014-08-28 13:09:47 +00:00
|
|
|
#include "AtmosphereModeler.h"
|
|
|
|
#include "WaterModeler.h"
|
2014-09-18 15:38:37 +00:00
|
|
|
#include "ModelerCameras.h"
|
2014-09-09 15:56:52 +00:00
|
|
|
#include "RenderPreviewProvider.h"
|
|
|
|
#include "RenderProcess.h"
|
|
|
|
#include "RenderConfig.h"
|
2015-08-17 20:55:30 +00:00
|
|
|
#include "DiffManager.h"
|
2014-09-09 15:56:52 +00:00
|
|
|
|
|
|
|
#include <QQmlEngine>
|
2015-07-22 16:05:24 +00:00
|
|
|
#include <QGuiApplication>
|
2014-08-28 08:29:12 +00:00
|
|
|
|
|
|
|
MainModelerWindow::MainModelerWindow()
|
|
|
|
{
|
2015-08-18 20:29:18 +00:00
|
|
|
scenery = new Scenery();
|
|
|
|
scenery->autoPreset();
|
2015-08-12 15:02:27 +00:00
|
|
|
|
2015-08-18 20:29:18 +00:00
|
|
|
renderer = new OpenGLRenderer(scenery);
|
2014-08-28 08:29:12 +00:00
|
|
|
|
2014-09-09 15:56:52 +00:00
|
|
|
render_preview_provider = new RenderPreviewProvider();
|
|
|
|
|
2014-08-28 08:29:12 +00:00
|
|
|
qmlRegisterType<OpenGLView>("Paysages", 1, 0, "OpenGLView");
|
2014-09-09 15:56:52 +00:00
|
|
|
engine()->addImageProvider("renderpreviewprovider", render_preview_provider);
|
2014-08-28 08:29:12 +00:00
|
|
|
|
2014-09-09 15:56:52 +00:00
|
|
|
setMinimumSize(QSize(1000, 800));
|
2014-08-28 08:29:12 +00:00
|
|
|
setTitle(QObject::tr("Paysages 3D"));
|
|
|
|
setResizeMode(QQuickView::SizeRootObjectToView);
|
|
|
|
setSource(QUrl("qrc:///main.qml"));
|
2014-08-28 13:09:47 +00:00
|
|
|
|
2014-09-18 15:38:37 +00:00
|
|
|
cameras = new ModelerCameras(this);
|
2014-08-28 13:09:47 +00:00
|
|
|
atmosphere = new AtmosphereModeler(this);
|
|
|
|
water = new WaterModeler(this);
|
2015-07-22 22:28:27 +00:00
|
|
|
|
|
|
|
render_process = new RenderProcess(this, render_preview_provider);
|
2014-08-28 08:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MainModelerWindow::~MainModelerWindow()
|
|
|
|
{
|
2014-08-28 13:09:47 +00:00
|
|
|
delete atmosphere;
|
|
|
|
delete water;
|
2014-09-18 15:38:37 +00:00
|
|
|
delete cameras;
|
2014-08-28 13:09:47 +00:00
|
|
|
|
2014-09-09 15:56:52 +00:00
|
|
|
delete render_preview_provider;
|
|
|
|
delete render_process;
|
|
|
|
|
2014-08-28 08:29:12 +00:00
|
|
|
delete renderer;
|
2015-08-18 20:47:18 +00:00
|
|
|
delete scenery;
|
2014-08-28 08:29:12 +00:00
|
|
|
}
|
2014-08-28 13:09:47 +00:00
|
|
|
|
|
|
|
QObject *MainModelerWindow::findQmlObject(const QString &objectName)
|
|
|
|
{
|
|
|
|
return rootObject()->findChild<QObject *>(objectName);
|
|
|
|
}
|
2014-09-09 15:56:52 +00:00
|
|
|
|
2015-07-22 22:28:27 +00:00
|
|
|
void MainModelerWindow::setQmlProperty(const QString &objectName, const QString &propertyName, const QVariant &value)
|
|
|
|
{
|
|
|
|
QObject *item = findQmlObject(objectName);
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
item->setProperty(propertyName.toLocal8Bit(), value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 16:22:16 +00:00
|
|
|
QString MainModelerWindow::getState() const
|
|
|
|
{
|
|
|
|
return rootObject()->property("state").toString();
|
|
|
|
}
|
|
|
|
|
2015-07-22 22:28:27 +00:00
|
|
|
void MainModelerWindow::setState(const QString &stateName)
|
|
|
|
{
|
|
|
|
rootObject()->setProperty("state", stateName);
|
|
|
|
}
|
|
|
|
|
2014-09-09 15:56:52 +00:00
|
|
|
void MainModelerWindow::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
2015-08-18 16:22:16 +00:00
|
|
|
if (getState() == "Render Dialog")
|
2014-09-09 15:56:52 +00:00
|
|
|
{
|
2015-08-18 16:22:16 +00:00
|
|
|
if (event->key() == Qt::Key_Escape)
|
2015-07-22 17:23:22 +00:00
|
|
|
{
|
2015-08-18 16:22:16 +00:00
|
|
|
render_process->stopRender();
|
2014-09-09 15:56:52 +00:00
|
|
|
|
2015-08-18 16:22:16 +00:00
|
|
|
setState("Init");
|
2015-07-22 16:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-18 16:22:16 +00:00
|
|
|
else
|
2015-08-17 20:55:30 +00:00
|
|
|
{
|
2015-08-18 16:22:16 +00:00
|
|
|
if (event->key() == Qt::Key_F5)
|
2015-08-17 20:55:30 +00:00
|
|
|
{
|
2015-08-18 16:22:16 +00:00
|
|
|
// Start render in a thread
|
|
|
|
if (event->modifiers() & Qt::ControlModifier)
|
2015-08-17 20:55:30 +00:00
|
|
|
{
|
2015-08-18 16:22:16 +00:00
|
|
|
render_process->startFinalRender();
|
2015-08-17 20:55:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-18 16:22:16 +00:00
|
|
|
render_process->startQuickRender();
|
2015-08-17 20:55:30 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-18 16:22:16 +00:00
|
|
|
else if (event->key() == Qt::Key_F6)
|
|
|
|
{
|
|
|
|
render_process->showPreviousRender();
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_Q)
|
|
|
|
{
|
|
|
|
if (event->modifiers() & Qt::ControlModifier)
|
|
|
|
{
|
|
|
|
QGuiApplication::instance()->exit();
|
|
|
|
}
|
|
|
|
}
|
2015-08-19 18:06:47 +00:00
|
|
|
else if (event->key() == Qt::Key_N)
|
|
|
|
{
|
|
|
|
if (event->modifiers() & Qt::ControlModifier)
|
|
|
|
{
|
|
|
|
getScenery()->autoPreset();
|
|
|
|
renderer->reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_S)
|
|
|
|
{
|
|
|
|
if (event->modifiers() & Qt::ControlModifier)
|
|
|
|
{
|
|
|
|
getScenery()->saveGlobal("saved.p3d");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_L or event->key() == Qt::Key_O)
|
|
|
|
{
|
|
|
|
if (event->modifiers() & Qt::ControlModifier)
|
|
|
|
{
|
|
|
|
getScenery()->loadGlobal("saved.p3d");
|
|
|
|
renderer->reset();
|
|
|
|
}
|
|
|
|
}
|
2015-08-18 16:22:16 +00:00
|
|
|
else if (event->key() == Qt::Key_Z)
|
2015-08-17 20:55:30 +00:00
|
|
|
{
|
2015-08-18 16:22:16 +00:00
|
|
|
if (event->modifiers() & Qt::ControlModifier)
|
|
|
|
{
|
|
|
|
if (event->modifiers() & Qt::ShiftModifier)
|
|
|
|
{
|
2015-08-18 18:31:11 +00:00
|
|
|
getScenery()->getDiffManager()->redo();
|
2015-08-18 16:22:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-18 18:31:11 +00:00
|
|
|
getScenery()->getDiffManager()->undo();
|
2015-08-18 16:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_Y)
|
|
|
|
{
|
|
|
|
if (event->modifiers() & Qt::ControlModifier)
|
|
|
|
{
|
2015-08-18 18:31:11 +00:00
|
|
|
getScenery()->getDiffManager()->undo();
|
2015-08-18 16:22:16 +00:00
|
|
|
}
|
2015-08-17 20:55:30 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-09 15:56:52 +00:00
|
|
|
}
|