-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmainwindow.cpp
132 lines (107 loc) · 5.82 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***************************************************************************
mainwindow.cpp
--------------------------------------
Date : 01-04-2019
Copyright : (C) 2018 by Vincent Cloarec
email : vcloarec at gmail dot com / projetreos at gmail dot com
***************************************************************************
* *
* 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 "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDesktopWidget>
#include <3d/qgs3dmapcanvasdockwidget.h>
#include <qgs3dmapsettings.h>
#include <qgsflatterraingenerator.h>
#include <qgs3drendererregistry.h>
#include <qgsvectorlayer3drenderer.h>
#include <qgsrulebased3drenderer.h>
#include <qgsmeshlayer3drenderer.h>
MainWindow::MainWindow( QWidget *parent ) :
QMainWindow( parent ),
ui( new Ui::MainWindow ),
actionTinEditor( new QAction( QPixmap( "://toolbar/MeshTinEditor.png" ), tr( "Edit TIN" ), this ) ),
actionMap3D( new QAction( tr( "Open Map 3D" ), this ) )
{
ui->setupUi( this );
setDockNestingEnabled( true );
mMap = new ReosMap( this );
centralWidget()->setLayout( new QVBoxLayout );
centralWidget()->layout()->addWidget( mMap->getMapCanvas() );
statusBar()->addPermanentWidget( mMap->getCursorPosition() );
mGisManager = new ReosGisManager( mMap );
QDockWidget *dockSIG = new QDockWidget( tr( "GIS panel" ) );
dockSIG->setWidget( mGisManager->getWidget() );
statusBar()->addPermanentWidget( mGisManager->createCRSDisplay( this ) );
dockSIG->setObjectName( QStringLiteral( "Dock GIS" ) );
addDockWidget( Qt::LeftDockWidgetArea, dockSIG );
ReosMessageBox *messageBox = new ReosMessageBox;
QDockWidget *dockMessage = new QDockWidget( tr( "Message box" ) );
dockMessage->setWidget( messageBox );
addDockWidget( Qt::LeftDockWidgetArea, dockMessage );
QgsProviderRegistry::instance()->registerProvider( new ReosMeshPoviderMetadata() );
QMenu *fileMenu = new QMenu( tr( "Files" ) );
menuBar()->addMenu( fileMenu );
ui->mainToolBar->addAction( actionTinEditor );
actionTinEditor->setCheckable( true );
ui->mainToolBar->addAction( actionMap3D );
tinEditor = new ReosTinEditorUi( mGisManager, this );
QMenu *tinMenu = new QMenu( tr( "Triangulated Irregular Network DEM" ) );
tinMenu->addActions( tinEditor->getActions() );
menuBar()->addMenu( tinMenu );
connect( actionTinEditor, &QAction::triggered, this, &MainWindow::showTinEditor );
connect( actionMap3D, &QAction::triggered, this, &MainWindow::openMap3D );
connect( tinEditor, &ReosModule::widgetVisibility, actionTinEditor, &QAction::setChecked );
connect( tinEditor, &ReosModule::activeUndoStack, this, &MainWindow::activeUndoStack );
mUndoGroup = new QUndoGroup( this );
ui->mainToolBar->addAction( mUndoGroup->createUndoAction( this ) );
ui->mainToolBar->addAction( mUndoGroup->createRedoAction( this ) );
//Active Tin editor
tinEditor->showWidget();
actionTinEditor->setChecked( true );
QgsApplication::instance()->renderer3DRegistry()->addRenderer( new QgsVectorLayer3DRendererMetadata );
QgsApplication::instance()->renderer3DRegistry()->addRenderer( new QgsRuleBased3DRendererMetadata );
QgsApplication::instance()->renderer3DRegistry()->addRenderer( new QgsMeshLayer3DRendererMetadata );
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::openMap3D()
{
Qgs3DMapCanvasDockWidget *dock3D = new Qgs3DMapCanvasDockWidget( this );
dock3D->setAllowedAreas( Qt::AllDockWidgetAreas );
addDockWidget( Qt::RightDockWidgetArea, dock3D );
dock3D->setFloating( false );
dock3D->setMainCanvas( mMap->getMapCanvas() );
Qgs3DMapSettings *map3dSettings = new Qgs3DMapSettings;
map3dSettings->setCrs( mMap->getMapCanvas()->mapSettings().destinationCrs() );
map3dSettings->setOrigin( QgsVector3D( mMap->getMapCanvas()->fullExtent().center().x(), mMap->getMapCanvas()->fullExtent().center().y(), 0 ) );
map3dSettings->setSelectionColor( mMap->getMapCanvas()->selectionColor() );
map3dSettings->setBackgroundColor( mMap->getMapCanvas()->canvasColor() );
map3dSettings->setLayers( mMap->getMapCanvas()->layers() );
map3dSettings->setTransformContext( QgsProject::instance()->transformContext() );
map3dSettings->setPathResolver( QgsProject::instance()->pathResolver() );
map3dSettings->setMapThemeCollection( QgsProject::instance()->mapThemeCollection() );
connect( QgsProject::instance(), &QgsProject::transformContextChanged, mMap, [map3dSettings]
{
map3dSettings->setTransformContext( QgsProject::instance()->transformContext() );
} );
QgsFlatTerrainGenerator *flatTerrain = new QgsFlatTerrainGenerator;
flatTerrain->setCrs( mMap->getMapCanvas()->mapSettings().destinationCrs() );
flatTerrain->setExtent( mMap->getMapCanvas()->fullExtent() );
map3dSettings->setTerrainGenerator( flatTerrain );
QgsPointLightSettings defaultPointLight;
defaultPointLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
defaultPointLight.setConstantAttenuation( 0 );
map3dSettings->setPointLights( QList<QgsPointLightSettings>() << defaultPointLight );
map3dSettings->setOutputDpi( QgsApplication::desktop()->logicalDpiX() );
dock3D->setMapSettings( map3dSettings );
connect( mGisManager, &ReosGisManager::projectHasToBeClosed, dock3D, &Qgs3DMapCanvasDockWidget::close );
connect( mGisManager, &ReosGisManager::projectHasToBeClosed, dock3D, &Qgs3DMapCanvasDockWidget::deleteLater );
}