Merge branch 'new_osg' of http://brigecode.icu:16623/PM/DYTSrouce into new_osg
This commit is contained in:
commit
f32db7fbb4
26
src/main.cpp
26
src/main.cpp
@ -1,14 +1,6 @@
|
||||
|
||||
#include "app/Application.h"
|
||||
|
||||
#include "common/SpdLogger.h"
|
||||
#include "common/RecourceHelper.h"
|
||||
#include "common/CrashHandler.h"
|
||||
|
||||
#include "ui/MainFrame.h"
|
||||
#include "ui/MainWindow.h"
|
||||
#include "viewer/OsgWidget.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QApplication>
|
||||
#include <QGridLayout>
|
||||
@ -17,19 +9,14 @@
|
||||
#include <QLockFile>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <osgViewer/CompositeViewer>
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
#include "common/SpdLogger.h"
|
||||
#include "common/RecourceHelper.h"
|
||||
#include "common/CrashHandler.h"
|
||||
|
||||
#include <osgGA/MultiTouchTrackballManipulator>
|
||||
#include "workspace/WorkspaceManager.h"
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgEarth/MapNode>
|
||||
#include <osgEarthUtil/ExampleResources>
|
||||
#include <osgGA/StateSetManipulator>
|
||||
#include "ui/MainFrame.h"
|
||||
|
||||
#include "osgqt/GraphicsWindowQt.h"
|
||||
#include "scene/ui/CompositeWidgetManager.h"
|
||||
#include "scene/ui/QueryElevationWidget.h"
|
||||
|
||||
#ifndef LC
|
||||
#define LC "DYT"
|
||||
@ -83,9 +70,12 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
MainFrame mainWindow;
|
||||
splash.showMessage(("正在创建主窗口..."), Qt::AlignHCenter | Qt::AlignBottom, Qt:: white);
|
||||
// 先显示窗口,再在事件循环启动后最大化,避免首次显示时原生窗口放置未就绪导致尺寸异常
|
||||
mainWindow.showMaximized();
|
||||
// QTimer::singleShot(0, &mainWindow, &MainFrame::showMaximized);
|
||||
splash.finish(&mainWindow);
|
||||
|
||||
|
||||
int ret = app.exec();
|
||||
// app.Uninit();
|
||||
Sleep(200);
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgEarthUtil/EarthManipulator>
|
||||
#include <osgGA/StateSetManipulator>
|
||||
#include <osgEarth/Registry>
|
||||
|
||||
#include <osgShadow/ShadowedScene>
|
||||
#include <osgShadow/ViewDependentShadowMap>
|
||||
@ -34,53 +35,79 @@ OEScene::OEScene() {
|
||||
Init();
|
||||
}
|
||||
|
||||
OEScene::~OEScene() {
|
||||
|
||||
}
|
||||
|
||||
void OEScene::AttachView(osgViewer::View* view) {
|
||||
if (!view) return;
|
||||
if (curentView_ == view) return;
|
||||
|
||||
dyt_check(nullptr != earthRootNode_);
|
||||
skyDome_ = osgEarth::Util::SkyNode::create(earthMapNode_);
|
||||
|
||||
if (!earthMapNode_) {
|
||||
LOG_WARN("eart map node is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
dyt_check(nullptr != earthManipulator_);
|
||||
view->setCameraManipulator(earthManipulator_);
|
||||
if (skyDome_.valid()) {
|
||||
removeChild(skyDome_.get());
|
||||
skyDome_ = nullptr;
|
||||
}
|
||||
|
||||
skyDome_ = osgEarth::Util::SkyNode::create(earthMapNode_);
|
||||
skyDome_->attach(view);
|
||||
skyDome_->getSunLight()->setAmbient(osg::Vec4(0.5,0.5,0.5,1.0));
|
||||
addChild(skyDome_);
|
||||
|
||||
skyDome_->setDateTime(osgEarth::DateTime(2024, 12, 24, 3));
|
||||
|
||||
dyt_check(nullptr != earthManipulator_);
|
||||
view->setCameraManipulator(earthManipulator_);
|
||||
|
||||
view->setSceneData(this);
|
||||
curentView_ = view;
|
||||
}
|
||||
|
||||
void OEScene::DetachView(osgViewer::View* view) {
|
||||
if (!view) return;
|
||||
if (view != curentView_) return;
|
||||
|
||||
// Remove sky dome from this group if present; SkyNode has no detach in osgEarth 2.8
|
||||
if (skyDome_.valid()) {
|
||||
// Proactively disable lighting/effects to reduce interactions with the View
|
||||
skyDome_->setLighting(osg::StateAttribute::OFF);
|
||||
skyDome_->setSunVisible(false);
|
||||
skyDome_->setMoonVisible(false);
|
||||
skyDome_->setStarsVisible(false);
|
||||
skyDome_->setAtmosphereVisible(false);
|
||||
removeChild(skyDome_.get());
|
||||
skyDome_ = nullptr;
|
||||
}
|
||||
|
||||
// Clear scene data
|
||||
view->setSceneData(nullptr);
|
||||
|
||||
// Clear manipulator association
|
||||
if (earthManipulator_.valid()) {
|
||||
view->setCameraManipulator(nullptr);
|
||||
}
|
||||
|
||||
// Clear internal view pointer
|
||||
if (skyDome_.valid()) {
|
||||
removeChild(skyDome_.get());
|
||||
skyDome_ = nullptr;
|
||||
}
|
||||
|
||||
if (entityRoot_.valid()) {
|
||||
removeChild(entityRoot_);
|
||||
entityRoot_ = nullptr;
|
||||
}
|
||||
|
||||
if (earthRootNode_.valid()) {
|
||||
removeChild(earthRootNode_);
|
||||
earthRootNode_ = nullptr;
|
||||
}
|
||||
|
||||
view->setSceneData(nullptr);
|
||||
|
||||
// 清理内部视图指针
|
||||
if (curentView_ == view) {
|
||||
curentView_ = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool OEScene::AddToScene(osg::Node* node) const {
|
||||
dyt_check(nullptr != entityRoot_);
|
||||
return entityRoot_->addChild(node);
|
||||
@ -198,18 +225,19 @@ void OEScene::Init() {
|
||||
|
||||
std::string earthPath(earthFile.toLocal8Bit().constData());
|
||||
LOG_INFO("Loading earth file from: {}", earthPath);
|
||||
// earthRootNode_ = osgDB::readNodeFile("triton.earth");
|
||||
|
||||
osg::ref_ptr<osgDB::Options> myReadOptions = osgEarth::Registry::cloneOrCreateOptions();
|
||||
earthRootNode_ = osgDB::readNodeFile(earthPath);
|
||||
dyt_check(nullptr != earthRootNode_);
|
||||
addChild(earthRootNode_);
|
||||
|
||||
earthMapNode_ = osgEarth::MapNode::get(earthRootNode_);
|
||||
earthMapNode_ = osgEarth::MapNode::findMapNode(earthRootNode_);
|
||||
dyt_check(nullptr != earthMapNode_);
|
||||
addChild(earthMapNode_);
|
||||
|
||||
LOG_INFO("earth map node get success: {}", earthMapNode_.valid());
|
||||
g_srs_ = earthMapNode_->getMapSRS();
|
||||
|
||||
earthManipulator_ = new osgEarth::Util::EarthManipulator();
|
||||
earthManipulator_->getSettings()->setMinMaxPitch(-90.0, -10.0);
|
||||
|
||||
|
||||
entityRoot_ = new osg::Group;
|
||||
|
||||
@ -17,6 +17,7 @@ namespace Util {
|
||||
class OEScene : public osg::Group {
|
||||
public:
|
||||
OEScene();
|
||||
~OEScene();
|
||||
void AttachView(osgViewer::View* view);
|
||||
void DetachView(osgViewer::View* view);
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#include "scene/ui/OESceneUI.h"
|
||||
#include "scene/ui/OESceneUI.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "common/SpdLogger.h"
|
||||
@ -18,11 +18,10 @@ OESceneUI::OESceneUI(OEScene* oeScene)
|
||||
|
||||
OESceneUI::~OESceneUI(void) {
|
||||
LOG_INFO("dctor self={}", spdlog::fmt_lib::ptr(this));
|
||||
/* if (compositeWidgetManager_) {
|
||||
compositeWidgetManager_->DetachViewUI();
|
||||
delete compositeWidgetManager_;
|
||||
|
||||
compositeWidgetManager_ = nullptr;
|
||||
}*/
|
||||
queryElevationWidget_ = nullptr;
|
||||
oeScene_ = nullptr;
|
||||
}
|
||||
|
||||
void OESceneUI::InitUI(OsgViewUI* ui) {
|
||||
@ -53,12 +52,20 @@ void OESceneUI::UninitUI(OsgViewUI* ui) {
|
||||
LOG_INFO("not init");
|
||||
return;
|
||||
}
|
||||
|
||||
// 安全清理,不访问可能已销毁的资源
|
||||
if (compositeWidgetManager_) {
|
||||
// 只在ui有效时才调用DetachViewUI
|
||||
if (ui) {
|
||||
compositeWidgetManager_->DetachViewUI(ui);
|
||||
}
|
||||
compositeWidgetManager_ = nullptr;
|
||||
}
|
||||
if (queryElevationWidget_) {
|
||||
// 只在ui有效时才调用DetachViewUI
|
||||
if (ui) {
|
||||
queryElevationWidget_->DetachViewUI(ui);
|
||||
}
|
||||
queryElevationWidget_ = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -24,10 +24,9 @@ namespace Gdiplus
|
||||
|
||||
#include "FrameTitleBar.h"
|
||||
|
||||
#pragma comment (lib,"Dwmapi.lib") // Adds missing library, fixes error LNK2019: unresolved external symbol __imp__DwmExtendFrameIntoClientArea
|
||||
#pragma comment (lib,"Dwmapi.lib")
|
||||
#pragma comment (lib,"user32.lib")
|
||||
|
||||
// 无边框样式:不使用 CAPTION 与系统按钮,避免在 Win7 显示原生按钮
|
||||
constexpr unsigned long BorderlessFlag = WS_POPUP | WS_THICKFRAME | WS_SYSMENU;
|
||||
|
||||
inline bool IsCompositionEnabled() {
|
||||
@ -103,10 +102,9 @@ bool FramelessDelegateWin::nativeEvent(const QByteArray & eventType, void* messa
|
||||
return true;
|
||||
}
|
||||
NCCALCSIZE_PARAMS* ncParam = reinterpret_cast<NCCALCSIZE_PARAMS*>(msg->lParam);
|
||||
// 最大化时将客户区严格对齐到工作区,避免左右空隙
|
||||
ncParam->rgrc[0].left = rc->left();
|
||||
ncParam->rgrc[0].top = rc->top();
|
||||
ncParam->rgrc[0].right = rc->right();
|
||||
ncParam->rgrc[0].right = rc->right() + 1;
|
||||
ncParam->rgrc[0].bottom = rc->bottom();
|
||||
*result = 0;
|
||||
return true;
|
||||
@ -123,7 +121,7 @@ bool FramelessDelegateWin::nativeEvent(const QByteArray & eventType, void* messa
|
||||
} else {
|
||||
clientRect->top = before.top;
|
||||
clientRect->left = before.left;
|
||||
clientRect->right = before.right;
|
||||
clientRect->right = before.right + 1;
|
||||
clientRect->bottom = before.bottom + 1;
|
||||
}
|
||||
}
|
||||
@ -132,12 +130,8 @@ bool FramelessDelegateWin::nativeEvent(const QByteArray & eventType, void* messa
|
||||
return true;
|
||||
}
|
||||
case WM_NCPAINT: {
|
||||
if (!IsCompositionEnabled()) {
|
||||
*result = 0;
|
||||
return true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
case WM_SETFOCUS: {
|
||||
Qt::FocusReason reason;
|
||||
@ -153,28 +147,38 @@ bool FramelessDelegateWin::nativeEvent(const QByteArray & eventType, void* messa
|
||||
}
|
||||
break;
|
||||
case WM_NCACTIVATE: {
|
||||
if (!IsCompositionEnabled()) {
|
||||
*result = 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WM_NCHITTEST: {
|
||||
return OnNCTitTest(msg, result);
|
||||
}
|
||||
case WM_GETMINMAXINFO:
|
||||
{
|
||||
if (::IsZoomed(msg->hwnd)) {
|
||||
RECT frame = { 0, 0, 0, 0 };
|
||||
AdjustWindowRectEx(&frame, WS_OVERLAPPEDWINDOW, FALSE, 0);
|
||||
double dpr = mainWidget_->devicePixelRatioF();
|
||||
case WM_GETMINMAXINFO: {
|
||||
MINMAXINFO* mmi = reinterpret_cast<MINMAXINFO*>(msg->lParam);
|
||||
HMONITOR monitor = MonitorFromWindow(msg->hwnd, MONITOR_DEFAULTTONEAREST);
|
||||
MONITORINFO mi;
|
||||
::ZeroMemory(&mi, sizeof(mi));
|
||||
mi.cbSize = sizeof(mi);
|
||||
if (monitor && GetMonitorInfo(monitor, &mi)) {
|
||||
const RECT& work = mi.rcWork;
|
||||
const RECT& rcMon = mi.rcMonitor;
|
||||
const int frameX = GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
|
||||
const int frameY = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
|
||||
|
||||
// 最大化时不叠加系统边框内边距,避免左右出现可见空隙
|
||||
mmi->ptMaxPosition.x = work.left - frameX;
|
||||
mmi->ptMaxPosition.y = work.top - frameY;
|
||||
mmi->ptMaxSize.x = (work.right - work.left) + frameX * 2;
|
||||
mmi->ptMaxSize.y = (work.bottom - work.top) + frameY * 2;
|
||||
|
||||
mmi->ptMaxTrackSize.x = (rcMon.right - rcMon.left) + frameX * 2;
|
||||
mmi->ptMaxTrackSize.y = (rcMon.bottom - rcMon.top) + frameY * 2;
|
||||
}
|
||||
|
||||
if (::IsZoomed(msg->hwnd)) {
|
||||
frames_.setLeft(0);
|
||||
frames_.setTop(0);
|
||||
frames_.setRight(0);
|
||||
frames_.setBottom(0);
|
||||
|
||||
mainWidget_->setContentsMargins(margins_);
|
||||
justMaximized_ = true;
|
||||
} else {
|
||||
@ -188,14 +192,16 @@ bool FramelessDelegateWin::nativeEvent(const QByteArray & eventType, void* messa
|
||||
if (nullptr != titleBar_ && flag) {
|
||||
titleBar_->OnMaximized(justMaximized_);
|
||||
}
|
||||
return false;
|
||||
*result = 0;
|
||||
return true;
|
||||
}
|
||||
case WM_NCLBUTTONDBLCLK: {
|
||||
*result = 0;
|
||||
if (mainWidget_->maximumSize() == QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX) &&
|
||||
mainWidget_->windowFlags().testFlag(Qt::WindowMaximizeButtonHint))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
case WM_NCRBUTTONUP:
|
||||
{
|
||||
@ -211,13 +217,12 @@ bool FramelessDelegateWin::nativeEvent(const QByteArray & eventType, void* messa
|
||||
|
||||
void FramelessDelegateWin::OnShow() {
|
||||
if (isFirstShow_) {
|
||||
isFirstShow_ = false;
|
||||
|
||||
SetNativeWindowLong();
|
||||
isFirstShow_ = false;
|
||||
}
|
||||
|
||||
mainWidget_->setAttribute(Qt::WA_Resized);
|
||||
if (!isFirstShow_ && mainWidget_->isMaximized()) {
|
||||
if (!isFirstShow_ && mainWidget_->isMaximized() && wndPlaceMent_.length == sizeof(wndPlaceMent_)) {
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[=]() {
|
||||
@ -360,26 +365,24 @@ void FramelessDelegateWin::SetNativeWindowLong() {
|
||||
}
|
||||
HWND hwnd = reinterpret_cast<HWND>(mainWidget_->winId());
|
||||
unsigned long style = BorderlessFlag;
|
||||
// 避免父窗口与子窗口重叠绘制导致闪烁,启用剪裁样式
|
||||
style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
|
||||
|
||||
// 显式清理可能由 Qt 或系统设置的标题栏与系统按钮标志,确保不显示原生按钮
|
||||
style &= ~WS_CAPTION;
|
||||
style &= ~WS_MINIMIZEBOX;
|
||||
style &= ~WS_MAXIMIZEBOX;
|
||||
|
||||
if (!mainWidget_->windowFlags().testFlag(Qt::WindowMinimizeButtonHint) ||
|
||||
mainWidget_->maximumSize() != QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)) {
|
||||
style &= ~WS_MINIMIZEBOX;
|
||||
const bool canResize = (mainWidget_->maximumSize() == QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
||||
if (mainWidget_->windowFlags().testFlag(Qt::WindowMinimizeButtonHint) && canResize) {
|
||||
style |= WS_MINIMIZEBOX;
|
||||
}
|
||||
if (!mainWidget_->windowFlags().testFlag(Qt::WindowMaximizeButtonHint)) {
|
||||
style &= ~WS_MAXIMIZEBOX;
|
||||
if (mainWidget_->windowFlags().testFlag(Qt::WindowMaximizeButtonHint) && canResize) {
|
||||
style |= WS_MAXIMIZEBOX;
|
||||
}
|
||||
|
||||
::SetWindowLongPtr(hwnd, GWL_STYLE, style);
|
||||
|
||||
if (IsCompositionEnabled()) {
|
||||
ExtendFrameIntoClientArea(mainWidget_->windowHandle(), 1, 0, 0, 0);
|
||||
ExtendFrameIntoClientArea(mainWidget_->windowHandle(), 1, 1, 0, 0);
|
||||
}
|
||||
RECT rect;
|
||||
GetWindowRect(hwnd, &rect);
|
||||
@ -430,10 +433,6 @@ bool FramelessDelegateWin::OnNCTitTest(MSG* msg, qintptr* result) {
|
||||
*result = HTTOP;
|
||||
return true;
|
||||
}
|
||||
if (y > rect.top() + borderY && y < rect.top() + borderY) {
|
||||
*result = HTCAPTION;
|
||||
return true;
|
||||
}
|
||||
if (!maxSized && y >= rect.bottom() - borderY && y <= rect.bottom()) {
|
||||
*result = HTBOTTOM;
|
||||
return true;
|
||||
|
||||
@ -6,9 +6,13 @@
|
||||
|
||||
FramelessWindow::FramelessWindow(QWidget* parent)
|
||||
: QFrame(parent) {
|
||||
setWindowFlags(windowFlags() | Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
|
||||
setWindowFlags(windowFlags()
|
||||
| Qt::Window
|
||||
| Qt::FramelessWindowHint
|
||||
| Qt::WindowSystemMenuHint
|
||||
| Qt::WindowMaximizeButtonHint
|
||||
| Qt::WindowMinimizeButtonHint);
|
||||
|
||||
// 初始化平台相关的无边框委托,用于命中测试和缩放。
|
||||
delegate_ = FramelessDelegate::Create(this);
|
||||
|
||||
}
|
||||
|
||||
@ -123,8 +123,8 @@ void MainFrame::InitUI() {
|
||||
|
||||
simuRunMenu->SetMainWindow(mainWindow);
|
||||
|
||||
OsgWidget* viewWidget = mainWindow->GetViewWidget();
|
||||
connect(fileMenu, &FileManagerMenu::LoadDyt, viewWidget, &OsgWidget::OnLoadDyt);
|
||||
/*OsgWidget* viewWidget = mainWindow->GetViewWidget();
|
||||
connect(fileMenu, &FileManagerMenu::LoadDyt, viewWidget, &OsgWidget::OnLoadDyt);*/
|
||||
|
||||
//connect(system_, &SystemManagerMenu::signalShowUISetting, mainWindow, &MainWindow::slotShowUISetting);
|
||||
|
||||
|
||||
@ -18,16 +18,16 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="FrameTitleBar" name="titleFrame">
|
||||
@ -55,7 +55,7 @@
|
||||
<widget class="QWidget" name="body" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
@ -64,10 +64,10 @@
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="menuWidget">
|
||||
|
||||
@ -42,8 +42,6 @@ MainWindow::MainWindow(QWidget* parent)
|
||||
LOG_INFO("MainWindow::MainWindow - Constructor called, about to call InitUI");
|
||||
InitUI();
|
||||
LOG_INFO("MainWindow::MainWindow - Constructor completed");
|
||||
|
||||
QTimer::singleShot(1000.0, this, SLOT(slotUpdateShowMax()));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
@ -182,9 +180,7 @@ void MainWindow::InitUI() {
|
||||
}
|
||||
}
|
||||
|
||||
//ui->viewWidget->layout()->addWidget(qtOsgViewWidget_);
|
||||
qtOsgViewWidget_->LoadDefaultScene();
|
||||
|
||||
#if 0
|
||||
MatlabObject::GetInstance()->RunMatlabFile("");
|
||||
#endif // 1
|
||||
@ -206,7 +202,3 @@ void MainWindow::UninitUI() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::slotUpdateShowMax()
|
||||
{
|
||||
showMaximized();
|
||||
}
|
||||
@ -36,9 +36,6 @@ public:
|
||||
return dataPanelManager_;
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void slotUpdateShowMax();
|
||||
|
||||
private:
|
||||
void InitUI();
|
||||
void UninitUI();
|
||||
|
||||
@ -75,6 +75,7 @@ void FileManagerMenu::OpenWorkSpace() {
|
||||
}
|
||||
|
||||
LOG_INFO("open workspace: {}", fileName.toLocal8Bit().constData());
|
||||
WorkSpaceManager::Get().LoadDyt(fileName);
|
||||
emit LoadDyt(fileName);
|
||||
}
|
||||
|
||||
|
||||
@ -48,10 +48,9 @@ OsgWidget::OsgWidget(QWidget* parent, Qt::WindowFlags f)
|
||||
: QWidget(parent, f)
|
||||
{
|
||||
//setAttribute(Qt::WA_PaintOnScreen, true);
|
||||
// setAttribute(Qt::WA_StaticContents, true);
|
||||
// setAttribute(Qt::WA_NoSystemBackground, true);
|
||||
//setAttribute(Qt::WA_OpaquePaintEvent, true);
|
||||
// setAttribute(Qt::WA_DontCreateNativeAncestors, false);
|
||||
setAttribute(Qt::WA_StaticContents, true);
|
||||
setAttribute(Qt::WA_NoSystemBackground, true);
|
||||
setAttribute(Qt::WA_OpaquePaintEvent, true);
|
||||
|
||||
setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
|
||||
setMouseTracking(true);
|
||||
@ -73,16 +72,6 @@ OsgWidget::~OsgWidget() {
|
||||
if (timer_.isActive()) {
|
||||
timer_.stop();
|
||||
}
|
||||
|
||||
// First unload the workspace while scene/view are still valid,
|
||||
// so entities can detach cleanly from the scene graph
|
||||
if (nullptr != workspace_) {
|
||||
workspace_->Unlaod();
|
||||
workspace_ = nullptr;
|
||||
}
|
||||
|
||||
// Then perform the viewer teardown (detach UI, view, and scene)
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
void OsgWidget::Initialize() {
|
||||
@ -109,6 +98,11 @@ void OsgWidget::Initialize() {
|
||||
|
||||
void OsgWidget::Uninitialize() {
|
||||
LOG_INFO("OsgWidget::Uninitialize");
|
||||
|
||||
if (nullptr != activeScene_) {
|
||||
activeScene_->DetachView(view_);
|
||||
}
|
||||
|
||||
if (nullptr != viewUI_) {
|
||||
// Avoid creating UI during teardown; only remove if it exists
|
||||
if (activeScene_.valid()) {
|
||||
@ -119,8 +113,8 @@ void OsgWidget::Uninitialize() {
|
||||
}
|
||||
viewUI_ = nullptr;
|
||||
}
|
||||
|
||||
if (nullptr != activeScene_) {
|
||||
activeScene_->DetachView(view_);
|
||||
activeScene_ = nullptr;
|
||||
}
|
||||
if (nullptr != view_) {
|
||||
@ -137,29 +131,6 @@ void OsgWidget::LoadDefaultScene() {
|
||||
}
|
||||
}
|
||||
|
||||
void OsgWidget::OnLoadDyt(const QString& path) {
|
||||
LOG_INFO("load dyt path:{}", path.toStdString());
|
||||
WorkSpace* workSpace = WorkSpaceManager::Get().LoadDyt(path);
|
||||
if (nullptr == workSpace) {
|
||||
QMessageBox::warning(&MainFrame::Get(), tr("warning"),
|
||||
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();
|
||||
}
|
||||
|
||||
osgQt::GraphicsWindowQt* OsgWidget::createGraphicsWindow(int x, int y, int w, int h, const std::string& name,
|
||||
bool windowDecoration) {
|
||||
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
|
||||
@ -182,7 +153,6 @@ osgQt::GraphicsWindowQt* OsgWidget::createGraphicsWindow(int x, int y, int w, in
|
||||
QWidget* OsgWidget::addViewWidget(osgQt::GraphicsWindowQt* gw) {
|
||||
view_ = new osgViewer::View;
|
||||
addView(view_);
|
||||
ConfigureView(view_);
|
||||
|
||||
osg::Camera* camera = view_->getCamera();
|
||||
camera->setGraphicsContext( gw );
|
||||
@ -194,6 +164,9 @@ QWidget* OsgWidget::addViewWidget(osgQt::GraphicsWindowQt* gw) {
|
||||
camera->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(traits->width)/static_cast<double>(traits->height), 1.0f, 10000.0f );
|
||||
|
||||
activeScene_->AttachView(view_);
|
||||
|
||||
ConfigureView(view_);
|
||||
|
||||
return gw->getGLWidget();
|
||||
}
|
||||
|
||||
|
||||
@ -16,10 +16,8 @@ public:
|
||||
void Initialize(void);
|
||||
void Uninitialize(void);
|
||||
void LoadDefaultScene(void);
|
||||
void OnLoadDyt(const QString& path);
|
||||
|
||||
signals:
|
||||
void signalResetWorkSpace();
|
||||
void signalScaleInfo(const QString&);
|
||||
|
||||
protected:
|
||||
@ -52,7 +50,6 @@ private:
|
||||
|
||||
osg::ref_ptr<OEScene> activeScene_;
|
||||
osg::ref_ptr<class OsgViewUI> viewUI_;
|
||||
class WorkSpace* workspace_{ nullptr };
|
||||
osg::ref_ptr<osgViewer::View> view_;
|
||||
// class OsgView* view_{nullptr};
|
||||
};
|
||||
|
||||
@ -152,6 +152,7 @@ WorkSpace* WorkSpaceManager::LoadDyt(const QString& dyt) {
|
||||
}
|
||||
|
||||
workSpaces_[dyt] = workspace;
|
||||
SetCurrent(workspace);
|
||||
return workspace;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user