Skip to content
Permalink
Browse files

Created export settings class

  • Loading branch information
NEDJIMAbelgacem committed Jul 3, 2020
1 parent 14881ce commit 8a80bac7ea5cc09081b2813616aaa46bfcbb5705
@@ -111,6 +111,8 @@ SET(QGIS_3D_HDRS
chunks/qgschunkqueuejob_p.h
mesh/qgsmeshterraingenerator.h
qgs3dsceneexporter.h
qgs3dmapexportsettings.cpp

)

SET(QGIS_3D_PRIVATE_HDRS
@@ -0,0 +1,22 @@
/***************************************************************************
qgs3dmapexportsettings.cpp
--------------------------------------
Date : July 2020
Copyright : (C) 2020 by Belgacem Nedjima
Email : gb underscore nedjima at esi dot dz
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgs3dmapexportsettings.h"

Qgs3DMapExportSettings::Qgs3DMapExportSettings(QObject* parent)
: QObject(parent)
{

}
@@ -0,0 +1,45 @@
/***************************************************************************
qgs3dmapexportsettings.h
--------------------------------------
Date : July 2020
Copyright : (C) 2020 by Belgacem Nedjima
Email : gb underscore nedjima at esi dot dz
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGS3DMAPEXPORTSETTINGS_H
#define QGS3DMAPEXPORTSETTINGS_H

#include "qgis_3d.h"

#include <QString>
#include <QObject>

class _3D_EXPORT Qgs3DMapExportSettings : public QObject
{
Q_OBJECT
public:
Qgs3DMapExportSettings(QObject* parent = nullptr);
QString sceneName() const { return mSceneName; }
QString sceneFolderPath() const { return mSceneFolderPath; }
int levelOfDetails() const { return mLevelOfDetails; }
bool smoothEdges() const { return mSmoothEdges; }

void setSceneName( const QString& sceneName ) { mSceneName = sceneName; }
void setSceneFolderPath( const QString& sceneFolderPath ) { mSceneFolderPath = sceneFolderPath; }
void setLevelOfDetails( int levelOfDetails ) { mLevelOfDetails = levelOfDetails; }
void setSmoothEdges( bool smoothEdges ) { mSmoothEdges = smoothEdges; }
private:
QString mSceneName;
QString mSceneFolderPath;
int mLevelOfDetails;
bool mSmoothEdges;
};

#endif // QGS3DMAPEXPORTSETTINGS_H
@@ -59,6 +59,7 @@
#include "qgslinematerial_p.h"
#include "qgs3dsceneexporter.h"
#include "qgsabstract3drenderer.h"
#include "qgs3dmapexportsettings.h"

Qgs3DMapScene::Qgs3DMapScene( const Qgs3DMapSettings &map, QgsAbstract3DEngine *engine )
: mMap( map )
@@ -766,21 +767,22 @@ void Qgs3DMapScene::updateSceneState()
setSceneState( Ready );
}

void Qgs3DMapScene::exportScene( const QString &sceneName, const QString &sceneDir, int levelOfDetails, bool smoothEdges )
void Qgs3DMapScene::exportScene( const Qgs3DMapExportSettings &exportSettings )
{
Qgs3DSceneExporter exporter;

exporter.setLevelOfDetails( levelOfDetails );
exporter.setSmoothEdges( smoothEdges );
exporter.setLevelOfDetails( exportSettings.levelOfDetails() );
exporter.setSmoothEdges( exportSettings.smoothEdges() );

for ( QgsMapLayer *layer : mLayerEntities.keys() )
{
exporter.parseEntity( mLayerEntities[layer] );
}
exporter.parseEntity( mTerrain );

QString filePath = sceneDir;
// TODO: make the scene .obj file created using a function in Qgs3DMapExportSettings
QString filePath = exportSettings.sceneFolderPath();
if ( !filePath.endsWith( '/' ) ) filePath.push_back( '/' );
filePath += sceneName + ".obj";
filePath += exportSettings.sceneName() + ".obj";
exporter.saveToFile( filePath );
}
@@ -48,6 +48,7 @@ class Qgs3DMapScenePickHandler;
class Qgs3DMapSettings;
class QgsTerrainEntity;
class QgsChunkedEntity;
class Qgs3DMapExportSettings;

#define SIP_NO_FILE

@@ -102,7 +103,7 @@ class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
*/
float worldSpaceError( float epsilon, float distance );

void exportScene( const QString &sceneName, const QString &sceneDir, int levelOfDetails = 1, bool smoothEdges = false );
void exportScene( const Qgs3DMapExportSettings &exportSettings );
signals:
//! Emitted when the current terrain entity is replaced by a new one
void terrainEntityChanged();
@@ -47,7 +47,7 @@
#include "qgs3dsceneexporter.h"
#include "qgsabstract3drenderer.h"
#include "qgsmap3dexportwidget.h"

#include "qgs3dmapexportsettings.h"

Qgs3DMapCanvasDockWidget::Qgs3DMapCanvasDockWidget( QWidget *parent )
: QgsDockWidget( parent )
@@ -306,7 +306,9 @@ void Qgs3DMapCanvasDockWidget::exportScene()
dlg.setMinimumSize( 380, 460 );
// QgsGui::instance()->enableAutoGeometryRestore( &dlg );

QgsMap3DExportWidget *w = new QgsMap3DExportWidget( mCanvas->scene(), &dlg );
Qgs3DMapExportSettings *exportSettings = new Qgs3DMapExportSettings( &dlg );
QgsMap3DExportWidget *w = new QgsMap3DExportWidget( mCanvas->scene(), exportSettings, &dlg );

QDialogButtonBox *buttons = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dlg );

connect( buttons, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
@@ -18,14 +18,17 @@

#include <QPushButton>
#include <QFileDialog>
#include <QtGlobal>

#include "qgs3dmapscene.h"
#include "qgssettings.h"
#include "qgs3dmapexportsettings.h"

QgsMap3DExportWidget::QgsMap3DExportWidget( Qgs3DMapScene *scene, QWidget *parent ) :
QgsMap3DExportWidget::QgsMap3DExportWidget( Qgs3DMapScene *scene, Qgs3DMapExportSettings *exportSettings, QWidget *parent ) :
QWidget( parent ),
ui( new Ui::Map3DExportWidget ),
mScene( scene )
mScene( scene ),
mExportSettings( exportSettings )
{
ui->setupUi( this );

@@ -39,20 +42,32 @@ QgsMap3DExportWidget::QgsMap3DExportWidget( Qgs3DMapScene *scene, QWidget *paren
QString outputDir = QFileDialog::getExistingDirectory( this, QString( "Export scane" ), initialPath );
ui->folderPathLineEdit->setText( outputDir );
} );

connect( ui->sceneNameLineEdit, &QLineEdit::textChanged, [ = ]( const QString & ) { settingsChanged(); } );
connect( ui->folderPathLineEdit, &QLineEdit::textChanged, [ = ]( const QString & ) { settingsChanged(); } );
connect( ui->smoothEdgesCheckBox, &QCheckBox::stateChanged, [ = ]( int ) { settingsChanged(); } );
connect( ui->levelOfDetailsSpinBox, QOverload<int>::of( &QSpinBox::valueChanged ), [ = ]( int ) { settingsChanged(); } );

// sets the export settings to whatever is on the scene
settingsChanged();
}

QgsMap3DExportWidget::~QgsMap3DExportWidget()
{
delete ui;
}

void QgsMap3DExportWidget::settingsChanged()
{
mExportSettings->setSceneName( ui->sceneNameLineEdit->text() );
mExportSettings->setSceneFolderPath( ui->folderPathLineEdit->text() );
mExportSettings->setLevelOfDetails( ui->levelOfDetailsSpinBox->value() );
mExportSettings->setSmoothEdges( ui->smoothEdgesCheckBox->isChecked() );
}

void QgsMap3DExportWidget::exportScene()
{
QString sceneName = ui->sceneNameLineEdit->text();
QString sceneFolder = ui->folderPathLineEdit->text();
int levelOfDetails = ui->levelOfDetailsSpinBox->value();
bool smoothEdges = ui->smoothEdgesCheckBox->isChecked();
mScene->exportScene( sceneName, sceneFolder, levelOfDetails, smoothEdges );
mScene->exportScene( *mExportSettings );
QgsSettings settings;
settings.setValue( QStringLiteral( "UI/last3DSceneExportDir" ), sceneFolder );
settings.setValue( QStringLiteral( "UI/last3DSceneExportDir" ), mExportSettings->sceneFolderPath() );
}
@@ -24,20 +24,24 @@ namespace Ui
}

class Qgs3DMapScene;
class Qgs3DMapExportSettings;

class QgsMap3DExportWidget : public QWidget
{
Q_OBJECT

public:
explicit QgsMap3DExportWidget( Qgs3DMapScene *scene, QWidget *parent = nullptr );
explicit QgsMap3DExportWidget( Qgs3DMapScene *scene, Qgs3DMapExportSettings *exportSettings, QWidget *parent = nullptr );
~QgsMap3DExportWidget();

void exportScene();
private slots:
void settingsChanged();
private:
Ui::Map3DExportWidget *ui;
private:
Qgs3DMapScene *mScene = nullptr;
Qgs3DMapExportSettings *mExportSettings = nullptr;
};

#endif // QGSMAP3DEXPORTWIDGET_H

0 comments on commit 8a80bac

Please sign in to comment.
You can’t perform that action at this time.