Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3D] Debug tools in sandbox #59576

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/3d/qgs3ddebugwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class Qgs3DMapCanvas;

#include <ui_3ddebugwidget.h>
#include "qgs3dmapsettings.h"
#include "qgis_app.h"

class Qgs3DDebugWidget : public QWidget, Ui::Q3DDebugWidget
class APP_EXPORT Qgs3DDebugWidget : public QWidget, Ui::Q3DDebugWidget
{
Q_OBJECT
public:
Expand Down
3 changes: 2 additions & 1 deletion src/app/3d/qgs3dmapconfigwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <QWidget>

#include <ui_map3dconfigwidget.h>
#include "qgis_app.h"

class QCheckBox;
class Qgs3DMapSettings;
Expand All @@ -29,7 +30,7 @@ class QgsShadowRenderingSettingsWidget;
class Qgs3DMapCanvas;
class QgsSkyboxSettings;

class Qgs3DMapConfigWidget : public QWidget, private Ui::Map3DConfigWidget
class APP_EXPORT Qgs3DMapConfigWidget : public QWidget, private Ui::Map3DConfigWidget
{
Q_OBJECT
public:
Expand Down
142 changes: 134 additions & 8 deletions tests/src/3d/sandbox/qgis_3d_sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,34 @@

#include <QApplication>

#include "qgsapplication.h"
#include "qgs3d.h"
#include "qgs3ddebugwidget.h"
#include "qgs3dmapcanvas.h"
#include "qgs3dmapconfigwidget.h"
#include "qgs3dmapscene.h"
#include "qgs3dmapsettings.h"
#include "qgs3dutils.h"
#include "qgsapplication.h"
#include "qgsflatterraingenerator.h"
#include "qgsgui.h"
#include "qgshelp.h"
#include "qgslayertree.h"
#include "qgsmapcanvas.h"
#include "qgsmapsettings.h"
#include "qgsmessagebaritem.h"
#include "qgspointcloudlayer.h"
#include "qgspointcloudlayer3drenderer.h"
#include "qgspointlightsettings.h"
#include "qgsproject.h"
#include "qgsflatterraingenerator.h"
#include "qgs3dmapscene.h"
#include "qgs3dmapsettings.h"
#include "qgs3dmapcanvas.h"
#include "qgsprojectelevationproperties.h"
#include "qgsprojectviewsettings.h"
#include "qgspointlightsettings.h"
#include "qgsterrainprovider.h"
#include "qgstiledscenelayer.h"
#include "qgstiledscenelayer3drenderer.h"

#include <QHBoxLayout>
#include <QScreen>
#include <qgisapp.h>

void initCanvas3D( Qgs3DMapCanvas *canvas )
{
Expand Down Expand Up @@ -106,6 +115,69 @@ void initCanvas3D( Qgs3DMapCanvas *canvas )
qDebug() << "pending jobs:" << canvas->scene()->totalPendingJobsCount();
}

QPointer<QDialog> createConfigDialog( Qgs3DMapCanvas *canvas )
{
const QPointer configDialog = new QDialog;
configDialog->setWindowTitle( QStringLiteral( "3D Configuration" ) );
configDialog->setObjectName( QStringLiteral( "3DConfigurationDialog" ) );
configDialog->setMinimumSize( 600, 460 );
QgsGui::enableAutoGeometryRestore( configDialog );

Qgs3DMapSettings *map = canvas->mapSettings();
Qgs3DMapConfigWidget *w = new Qgs3DMapConfigWidget( map, new QgsMapCanvas, canvas, configDialog );
QDialogButtonBox *buttons = new QDialogButtonBox( QDialogButtonBox::Apply | QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, configDialog );

auto applyConfig = [ = ]
{
const QgsVector3D oldOrigin = map->origin();
const QgsCoordinateReferenceSystem oldCrs = map->crs();
const QgsCameraPose oldCameraPose = canvas->cameraController()->cameraPose();
const QgsVector3D oldLookingAt = oldCameraPose.centerPoint();

// update map
w->apply();

const QgsVector3D p = Qgs3DUtils::transformWorldCoordinates(
oldLookingAt,
oldOrigin, oldCrs,
map->origin(), map->crs(), QgsProject::instance()->transformContext() );

if ( p != oldLookingAt )
{
// apply() call has moved origin of the world so let's move camera so we look still at the same place
QgsCameraPose newCameraPose = oldCameraPose;
newCameraPose.setCenterPoint( p );
canvas->cameraController()->setCameraPose( newCameraPose );
}
};

QObject::connect( buttons, &QDialogButtonBox::rejected, configDialog, &QDialog::reject );
QObject::connect( buttons, &QDialogButtonBox::clicked, configDialog, [ = ]( const QAbstractButton * button )
{
if ( button == buttons->button( QDialogButtonBox::Apply ) || button == buttons->button( QDialogButtonBox::Ok ) )
applyConfig();
if ( button == buttons->button( QDialogButtonBox::Ok ) )
configDialog->accept();
} );
QObject::connect( buttons, &QDialogButtonBox::helpRequested, w, []() { QgsHelp::openHelp( QStringLiteral( "map_views/3d_map_view.html#scene-configuration" ) ); } );

QObject::connect( w, &Qgs3DMapConfigWidget::isValidChanged, configDialog, [ = ]( const bool valid )
{
buttons->button( QDialogButtonBox::Apply )->setEnabled( valid );
buttons->button( QDialogButtonBox::Ok )->setEnabled( valid );
} );

QgsMessageBar *messageBar = new QgsMessageBar;
QgsMessageBarItem *warningWidget = QgsMessageBar::createMessage( QString(), "Some settings are unavailable in sandbox" );
messageBar->pushWidget( warningWidget, Qgis::MessageLevel::Warning, 0 );

QVBoxLayout *layout = new QVBoxLayout( configDialog );
layout->addWidget( messageBar );
layout->addWidget( w, 1 );
layout->addWidget( buttons );
return configDialog;
}

int main( int argc, char *argv[] )
{
QgsApplication myApp( argc, argv, true, QString(), QStringLiteral( "desktop" ) );
Expand Down Expand Up @@ -151,8 +223,62 @@ int main( int argc, char *argv[] )

Qgs3DMapCanvas *canvas = new Qgs3DMapCanvas;
initCanvas3D( canvas );
canvas->resize( 800, 600 );
canvas->show();

// set up the UI
QWidget *windowWidget = new QWidget;
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->setContentsMargins( 0, 0, 0, 0 );
vLayout->setSpacing( 0 );

QToolBar *toolBar = new QToolBar( windowWidget );
toolBar->setIconSize( QgisApp::instance()->iconSize( true ) );
toolBar->addAction( QIcon( QgsApplication::iconPath( "mActionZoomFullExtent.svg" ) ), QStringLiteral( "Reset camera to default position" ), windowWidget, [canvas]
{
canvas->resetView();
} );
QAction *toggleDebugPanel = toolBar->addAction(
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/general.svg" ) ),
QStringLiteral( "Toggle on-screen Debug panel" ) );
toggleDebugPanel->setCheckable( true );
QAction *configureAction = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "mActionOptions.svg" ) ),
QStringLiteral( "Configure…" ), windowWidget );
QPointer<QDialog> configDialog = createConfigDialog( canvas );
QObject::connect( configureAction, &QAction::triggered, windowWidget, [configDialog]
{
configDialog->setVisible( true );
} );
toolBar->addAction( configureAction );
vLayout->addWidget( toolBar );

QWidget *container = QWidget::createWindowContainer( canvas );
container->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
Qgs3DDebugWidget *debugWidget = new Qgs3DDebugWidget( canvas );
debugWidget->setMapSettings( canvas->mapSettings() );
debugWidget->setVisible( false );
QObject::connect( canvas->mapSettings(), &Qgs3DMapSettings::showDebugPanelChanged, windowWidget, [ = ]( const bool enabled )
{
debugWidget->setVisible( enabled );
} );

// Connect the camera to the debug widget.
QObject::connect( canvas->cameraController(), &QgsCameraController::cameraChanged, debugWidget, &Qgs3DDebugWidget::updateFromCamera );
QObject::connect( canvas->cameraController()->camera(), &Qt3DRender::QCamera::nearPlaneChanged, debugWidget, &Qgs3DDebugWidget::updateFromCamera );
QObject::connect( canvas->cameraController()->camera(), &Qt3DRender::QCamera::farPlaneChanged, debugWidget, &Qgs3DDebugWidget::updateFromCamera );
QObject::connect( toggleDebugPanel, &QAction::toggled, windowWidget, [ = ]( const bool enabled )
{
debugWidget->setVisible( enabled );
} );

QHBoxLayout *hLayout = new QHBoxLayout;
vLayout->addLayout( hLayout );
hLayout->setContentsMargins( 0, 0, 0, 0 );
hLayout->addWidget( container );
hLayout->addWidget( debugWidget );


windowWidget->resize( 800, debugWidget->height() );
windowWidget->setLayout( vLayout );
windowWidget->show();

return myApp.exec();
}
Loading