2025-01-04 04:12:51 +00:00
|
|
|
#include "viewer/QtOsgViewWidget.h"
|
|
|
|
|
|
|
|
#include <QWheelEvent>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QOpenGLContext>
|
|
|
|
#include <QOpenGLFunctions>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QResizeEvent>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QScreen>
|
|
|
|
#include <QWindow>
|
|
|
|
|
|
|
|
#include <osgEarth/EarthManipulator>
|
|
|
|
#include <osgEarth/Viewpoint>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "app/Application.h"
|
|
|
|
#include "common/SpdLogger.h"
|
|
|
|
#include "viewer/OsgView.h"
|
|
|
|
#include "viewer/OsgViewer.h"
|
|
|
|
#include "viewer/OsgCameraManipulator.h"
|
|
|
|
#include "viewer/CameraControlManipulator.h"
|
|
|
|
#include "scene/OsgScene.h"
|
|
|
|
#include "workspace/WorkSpace.h"
|
|
|
|
#include "workspace/WorkSpaceManager.h"
|
|
|
|
#include "ui/MainFrame.h"
|
|
|
|
|
|
|
|
QtOsgViewWidget::QtOsgViewWidget(QWidget* parent)
|
|
|
|
: QWidget(parent) {
|
|
|
|
LOG_INFO("actor, self={}", fmt::ptr(this));
|
|
|
|
|
|
|
|
setAttribute(Qt::WA_PaintOnScreen, false);
|
|
|
|
setAttribute(Qt::WA_StaticContents, false);
|
|
|
|
setAttribute(Qt::WA_NoSystemBackground, false);
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, false);
|
|
|
|
setAttribute(Qt::WA_DontCreateNativeAncestors, false);
|
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
2025-01-05 11:12:18 +00:00
|
|
|
//Initialize();
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QtOsgViewWidget::~QtOsgViewWidget() {
|
|
|
|
LOG_INFO("dctor, self={}", fmt::ptr(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtOsgViewWidget::keyPressEvent(QKeyEvent* event) {
|
|
|
|
assert(nullptr != view_);
|
|
|
|
view_->KeyPress(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtOsgViewWidget::keyReleaseEvent(QKeyEvent* event) {
|
|
|
|
assert(nullptr != view_);
|
|
|
|
view_->KeyRelease(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtOsgViewWidget::Initialize(void) {
|
|
|
|
if (view_) {
|
|
|
|
LOG_INFO("view is created");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WId handle= winId();
|
|
|
|
|
|
|
|
double pixelRatio = screen()->devicePixelRatio();
|
|
|
|
view_ = OsgViewer::Get().CreateView(x(), y(), width() * pixelRatio, height() * pixelRatio, reinterpret_cast<void*>(handle));
|
|
|
|
if (nullptr == view_) {
|
|
|
|
LOG_ERROR("view is nullptr");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setMouseTracking(true);
|
|
|
|
|
2025-01-05 13:49:36 +00:00
|
|
|
activeScene_ = new OEScene;
|
|
|
|
|
|
|
|
activeScene_->AttachView(view_);
|
|
|
|
activeScene_->InitEventHandle(view_);
|
|
|
|
|
2025-01-04 04:12:51 +00:00
|
|
|
|
|
|
|
osgEarth::Util::EarthManipulator* manipulator = new osgEarth::Util::EarthManipulator;
|
|
|
|
osgEarth::Viewpoint vp("home", 107.85, 32.35, 100.0, -2.50, -90.0, 1.5e7);
|
|
|
|
manipulator->setHomeViewpoint(vp, 3.0);
|
|
|
|
|
|
|
|
|
|
|
|
OsgCameraManipulator* cameraManipulator = new OsgCameraManipulator(manipulator, this);
|
|
|
|
view_->Initialize(cameraManipulator);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtOsgViewWidget::Uninitialize(void) {
|
|
|
|
/*if (nullptr != scene_) {
|
|
|
|
delete scene_;
|
|
|
|
scene_ = nullptr;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
if (nullptr != view_) {
|
|
|
|
view_->Uninitialize();
|
|
|
|
OsgViewer::Get().DestroyView(view_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-05 11:12:18 +00:00
|
|
|
void QtOsgViewWidget::LoadDefaultScene(void) {
|
2025-01-05 13:49:36 +00:00
|
|
|
dyt_check(nullptr != activeScene_);
|
|
|
|
WorkSpaceManager::Get().LoadDefaultWorkspace(activeScene_);
|
2025-01-05 11:12:18 +00:00
|
|
|
}
|
|
|
|
|
2025-01-04 04:12:51 +00:00
|
|
|
void QtOsgViewWidget::OnLoadDyt(const QString& path) {
|
|
|
|
LOG_INFO("load dyt path:{}", path.toStdString());
|
2025-01-05 13:49:36 +00:00
|
|
|
WorkSpace* workSpace = WorkSpaceManager::Get().LoadDyt(path);
|
2025-01-04 04:12:51 +00:00
|
|
|
if (nullptr == workSpace) {
|
|
|
|
QMessageBox::warning(&MainFrame::Get(), tr("notify"), tr("open dyt file failed"), QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString& name = workSpace->GetName();
|
|
|
|
const QString windowTitle = MainFrame::Get().windowTitle();
|
|
|
|
|
|
|
|
MainFrame::Get().setWindowTitle(windowTitle + "-" + name);
|
|
|
|
WorkSpaceManager::Get().SetCurrent(workSpace);
|
|
|
|
if (nullptr != workspace_ && workspace_ != workSpace) {
|
|
|
|
workspace_->Unlaod();
|
|
|
|
}
|
|
|
|
|
|
|
|
workspace_ = workSpace;
|
|
|
|
|
|
|
|
emit signalResetWorkSpace();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtOsgViewWidget::resizeEvent(QResizeEvent* event) {
|
|
|
|
if (nullptr == view_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
double pixelRatio = screen()->devicePixelRatio();
|
|
|
|
const QSize& size = event->size();
|
|
|
|
view_->Resize(0, 0, size.width() * pixelRatio, size.height() * pixelRatio);
|
|
|
|
}
|
|
|
|
|