fix close crash

This commit is contained in:
brige 2025-06-19 22:05:52 +08:00
parent 8bbf971540
commit 43a30fefe3
16 changed files with 170 additions and 113 deletions

View File

@ -1,5 +1,5 @@
#include "effects/ConeWave.h"
/*
#include <osg/BlendFunc>
#include <osg/Material>
#include <osg/Texture2D>
@ -230,18 +230,18 @@ void ConeWave::CreateTexturedCone(osg::Geode* geode) {
//设置渲染顺序 仿真模型被波束遮盖 ,1000000-指的是若有1000000个Node 则此节点最后一个被渲染
// //stateset->setRenderBinDetails(120, "OSGEARTH_SCREEN_SPACE_LAYOUT_BIN");
stateset->setRenderBinDetails(10, "RenderBin");
// osg::ref_ptr<osg::BlendFunc> blendFunc = new osg::BlendFunc();
// stateset->setAttributeAndModes(blendFunc, osg::StateAttribute::ON);
// osg::ref_ptr<osg::Program> program = new osg::Program();
// program->addShader(vertexShader);
// program->addShader(fragmentShader);
//
// baseColorUniform_ = new osg::Uniform("baseColor", baseColor_);
// stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
// stateset->addUniform(baseColorUniform_);
osg::ref_ptr<osg::BlendFunc> blendFunc = new osg::BlendFunc();
stateset->setAttributeAndModes(blendFunc, osg::StateAttribute::ON);
osg::ref_ptr<osg::Program> program = new osg::Program();
program->addShader(vertexShader);
program->addShader(fragmentShader);
baseColorUniform_ = new osg::Uniform("baseColor", baseColor_);
stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
stateset->addUniform(baseColorUniform_);
// // stateset->osg::ref_ptr<osg::Program> program = new osg::Program();
program->addShader(vertexShader);
program->addShader(fragmentShader);(program, osg::StateAttribute::ON);
program->addShader(vertexShader);
program->addShader(fragmentShader);(program, osg::StateAttribute::ON);
// // stateset->setAttributeAndModes(new osg::Depth(osg::Depth::LESS, 0.0, 1.0, false));
//
// levelCountUniform_ = new osg::Uniform("num", float(levelCount_));
@ -250,7 +250,7 @@ program->addShader(fragmentShader);(program, osg::StateAttribute::ON);
// stateset->addUniform(levelCountUniform_);
// stateset->addUniform(levelHeightUniform_.get());
}
*/
/*
#include <osg/Geode>
#include <osg/Geometry>
@ -528,3 +528,4 @@ void ConeWave::changeWaveBeamConeAppearance( osg::Vec4 color, osg::Vec4 lineColo
}
*/

View File

@ -1,5 +1,5 @@
#pragma once
/*
#include <osg/Matrix>
#include <osg/Array>
#include <osg/Geometry>
@ -62,7 +62,7 @@ private:
float radius_{ 10.0f };
};
*/
/*
#pragma once
#include <osg/Node>
@ -82,7 +82,7 @@ public:
void createWaveBeamCone(osg::MatrixTransform* node,double angle, double length, osg::Vec4 color, osg::Vec4 lineColor, double lineWidth);
void changeWaveBeamConeTarget(/*osg::MatrixTransform* mt,*/ double latitude, double longitude, double height, bool ifDynamic);
void changeWaveBeamConeTarget(/*osg::MatrixTransform* mt, * / double latitude, double longitude, double height, bool ifDynamic);
void changeWaveBeamConeAppearance(osg::Vec4 color, osg::Vec4 lineColor, double lineWidth);
@ -93,4 +93,4 @@ private:
osg::ref_ptr<osg::MatrixTransform> _waveBeamCone;
};
*/

View File

@ -13,8 +13,8 @@
ConeWaveComponent::ConeWaveComponent(SceneComponent* parent)
: SceneComponent(parent) {
// coneWave_ = new ConeWave();
// coneWave_->InitGeode();
coneWave_ = new ConeWave();
coneWave_->InitGeode();
colorMap_[1] = osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
colorMap_[2] = osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
@ -84,48 +84,46 @@ void ConeWaveComponent::Update(double dt) {
}
void ConeWaveComponent::SetHeight(float height) {
// coneWave_->SetHeight(height);
// if (nullptr != mt_) {
// mt_->setMatrix(osg::Matrix::translate(osg::Vec3(0.0f, 0.0f, -coneWave_->GetHeght() * 0.75f)));
// }
coneWave_->SetHeight(height);
if (nullptr != mt_) {
mt_->setMatrix(osg::Matrix::translate(osg::Vec3(0.0f, 0.0f, -coneWave_->GetHeght() * 0.75f)));
}
}
float ConeWaveComponent::GetHeight() const {
return 0;// coneWave_->GetHeght();
return coneWave_->GetHeght();
}
void ConeWaveComponent::SetRadius(float radius) {
// coneWave_->SetRadius(radius);
coneWave_->SetRadius(radius);
}
float ConeWaveComponent::GetRadius() const {
return 0;// return coneWave_->GetRadius();
return coneWave_->GetRadius();
}
void ConeWaveComponent::SetLevelCount(int count) {
// coneWave_->SetLevelCount(count);
coneWave_->SetLevelCount(count);
}
float ConeWaveComponent::GetLevelCount() const {
return 0; // return coneWave_->GetLevelCount();
return coneWave_->GetLevelCount();
}
void ConeWaveComponent::SetLevelHeight(float height) {
// coneWave_->SetLevelHeight(height);
coneWave_->SetLevelHeight(height);
}
float ConeWaveComponent::GetLevelHeight() const {
// return coneWave_->GetLevelHeihgt();
return 0.0f;
return coneWave_->GetLevelHeihgt();
}
void ConeWaveComponent::SetBaseColor(const osg::Vec4& color) {
// coneWave_->SetBaseColor(color);
coneWave_->SetBaseColor(color);
}
const osg::Vec4 ConeWaveComponent::GetBaseColor() const {
// return coneWave_->GetBaseColor();
return osg::Vec4();
return coneWave_->GetBaseColor();
}
void ConeWaveComponent::SetColor1(const osg::Vec4& color) {
@ -172,7 +170,7 @@ void ConeWaveComponent::AddToRender() {
void ConeWaveComponent::Initialize() {
mt_ = new osg::MatrixTransform;
mt_->addChild(coneWave_);
// mt_->setMatrix(osg::Matrix::translate(osg::Vec3(0.0f, 0.0f, -coneWave_->GetHeght() * 0.75f)));
mt_->setMatrix(osg::Matrix::translate(osg::Vec3(0.0f, 0.0f, -coneWave_->GetHeght() * 0.75f)));
}
void ConeWaveComponent::UpdateEvent() {
@ -200,24 +198,24 @@ void ConeWaveComponent::UpdateEvent() {
}
osg::Vec4& color = colorMap_[currentStatus_];
// coneWave_->SetBaseColor(color);
coneWave_->SetBaseColor(color);
coneWave_->setNodeMask(0xff);
//Timestep* timeStep = workspace->GetTimestep();
//if (nullptr == timeStep) {
// LOG_WARN("timeStep is nullptr");
// return;
//}
Timestep* timeStep = workspace->GetTimestep();
if (nullptr == timeStep) {
LOG_WARN("timeStep is nullptr");
return;
}
//double dt = timeStep->GetCurrent();
//int value = timeAction_->GetValue(dt);
//if (-1 == value) {
// return;
//}
//
double dt = timeStep->GetCurrent();
int value = timeAction_->GetValue(dt);
if (-1 == value) {
return;
}
//coneWave_->setNodeMask(value == 0 ? 0x0 : 0xff);
coneWave_->setNodeMask(value == 0 ? 0x0 : 0xff);
}

View File

@ -78,23 +78,7 @@ CompositeWidgetManager::CompositeWidgetManager(void)
_canvasFX->getBackground()->setColor(0, 0, 0, 0);
}
CompositeWidgetManager::~CompositeWidgetManager(void)
{
delete _canvasN;
delete _canvasO;
delete _canvasBackGround;
delete _canvasFX;
delete _bgLayer1;
delete _bgLayer2;
delete _bgLayer3;
delete _bgLayer4;
delete _bgShadow;
delete _widgetCenter;
delete _widgetN;
delete _widgetFX;
CompositeWidgetManager::~CompositeWidgetManager(void) {
}
void CompositeWidgetManager::ResetCanvasPosition(double x, double y)
@ -164,6 +148,13 @@ void CompositeWidgetManager::AttachViewUI(osgWidget::WindowManager* ui) {
ui->addChild(_canvasBackGround);
}
void CompositeWidgetManager::DetachViewUI(OsgViewUI* ui) {
ui->removeChild(_canvasO);
ui->removeChild(_canvasN);
ui->removeChild(_canvasFX);
ui->removeChild(_canvasBackGround);
}
//void CompositeWidgetManager::slotHeading(double angle)
//{
// SetHeading(angle);

View File

@ -32,6 +32,7 @@ public:
void AttachViewUI(class OsgViewUI* ui);
void AttachViewUI(osgWidget::WindowManager* ui);
void DetachViewUI(class OsgViewUI* ui);
//
//
@ -44,23 +45,22 @@ public slots:
void slotHeading(double angle);
private:
osgWidget::Canvas* _canvasN;
osgWidget::Canvas* _canvasO;
osgWidget::Canvas* _canvasBackGround;
osgWidget::Canvas* _canvasFX;
osg::ref_ptr<osgWidget::Canvas> _canvasN;
osg::ref_ptr<osgWidget::Canvas> _canvasO;
osg::ref_ptr<osgWidget::Canvas> _canvasBackGround;
osg::ref_ptr<osgWidget::Canvas> _canvasFX;
CompositeWidget* _bgLayer1;
osgWidget::Widget* _bgLayer2;
osgWidget::Widget* _bgLayer3;
osgWidget::Widget* _bgLayer4;
osgWidget::Widget* _bgShadow;
osg::ref_ptr<CompositeWidget> _bgLayer1;
osg::ref_ptr<osgWidget::Widget> _bgLayer2;
osg::ref_ptr<osgWidget::Widget> _bgLayer3;
osg::ref_ptr<osgWidget::Widget> _bgLayer4;
osg::ref_ptr<osgWidget::Widget> _bgShadow;
CompositeWidget* _widgetCenter;
osg::ref_ptr<CompositeWidget> _widgetCenter;
osg::ref_ptr<CompositeWidget> _widgetN;
CompositeWidget* _widgetN;
osgWidget::Widget* _widgetFX;
osgWidget::Widget* _widgetFXBackground;
osg::ref_ptr<osgWidget::Widget> _widgetFX;
osg::ref_ptr<osgWidget::Widget> _widgetFXBackground;
osg::Vec2 _mouseDirection;

View File

@ -18,6 +18,11 @@ OESceneUI::OESceneUI(OEScene* oeScene)
OESceneUI::~OESceneUI(void) {
LOG_INFO("dctor self={}", spdlog::fmt_lib::ptr(this));
/* if (compositeWidgetManager_) {
compositeWidgetManager_->DetachViewUI();
delete compositeWidgetManager_;
compositeWidgetManager_ = nullptr;
}*/
}
void OESceneUI::InitUI(OsgViewUI* ui) {
@ -42,6 +47,25 @@ void OESceneUI::InitUI(OsgViewUI* ui) {
LOG_INFO("exit");
}
void OESceneUI::UninitUI(OsgViewUI* ui) {
LOG_INFO("enter");
if (!isInit_) {
LOG_INFO("not init");
return;
}
if (compositeWidgetManager_) {
compositeWidgetManager_->DetachViewUI(ui);
compositeWidgetManager_ = nullptr;
}
if (queryElevationWidget_) {
queryElevationWidget_->DetachViewUI(ui);
queryElevationWidget_ = nullptr;
}
isInit_ = false;
LOG_INFO("exit");
}
void OESceneUI::OnResize(double width, double height) {
dyt_check(compositeWidgetManager_);
//dyt_check(zoomManager_);

View File

@ -16,6 +16,7 @@ public:
~OESceneUI(void) override;
void InitUI(OsgViewUI* ui) override;
void UninitUI(OsgViewUI* ui) override;
void OnResize(double width, double height) override;
private:

View File

@ -43,7 +43,17 @@ void QueryElevationWidget::AttachViewUI(OsgViewUI* ui) {
ui->addChild(this);
dyt_check(nullptr != oeScene_);
osgEarth::MapNode* mapNode = oeScene_->GetMapNode();
ui->getView()->addEventHandler(new QueryElevationEventHandler(mapNode, this));
eventHandler_ = new QueryElevationEventHandler(mapNode, this);
ui->getView()->addEventHandler(eventHandler_);
}
void QueryElevationWidget::DetachViewUI(OsgViewUI* ui) {
dyt_check(nullptr != ui);
ui->removeChild(this);
if (nullptr != eventHandler_) {
ui->getView()->removeEventHandler(eventHandler_);
eventHandler_ = nullptr;
}
}

View File

@ -24,6 +24,7 @@ public:
~QueryElevationWidget() override;
void AttachViewUI(class OsgViewUI* ui);
void DetachViewUI(class OsgViewUI* ui);
void OnUpdateGeoPoint(double x, double y, double z);
void ResetCanvasPosition(double width, double height);
@ -34,6 +35,7 @@ private:
private:
class OEScene* oeScene_;
osg::ref_ptr<osgWidget::Label> label_;
osg::ref_ptr<QueryElevationEventHandler> eventHandler_;
};

View File

@ -503,132 +503,132 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="65"/>
<location filename="../ui/MainWindow.cpp" line="66"/>
<source>model elements</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="71"/>
<location filename="../ui/MainWindow.cpp" line="72"/>
<source>attribte</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="108"/>
<location filename="../ui/MainWindow.cpp" line="109"/>
<source>Wave Curve</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="114"/>
<location filename="../ui/MainWindow.cpp" line="115"/>
<source>Speed Curve</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="123"/>
<location filename="../ui/MainWindow.cpp" line="124"/>
<source>3D Curve</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="135"/>
<location filename="../ui/MainWindow.cpp" line="136"/>
<source>Target number</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="135"/>
<location filename="../ui/MainWindow.cpp" line="136"/>
<source>Signal-to-noise ratio</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="136"/>
<location filename="../ui/MainWindow.cpp" line="137"/>
<source>Azimuth line of sight</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="136"/>
<location filename="../ui/MainWindow.cpp" line="137"/>
<source>Pitch gaze angle</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="137"/>
<location filename="../ui/MainWindow.cpp" line="138"/>
<source>azimuth</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="137"/>
<location filename="../ui/MainWindow.cpp" line="138"/>
<source>Pitch angle</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="138"/>
<location filename="../ui/MainWindow.cpp" line="139"/>
<source>attribute</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="138"/>
<location filename="../ui/MainWindow.cpp" line="139"/>
<source>Doppler</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="139"/>
<location filename="../ui/MainWindow.cpp" line="140"/>
<source>course</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="139"/>
<location filename="../ui/MainWindow.cpp" line="140"/>
<source>Speed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="140"/>
<location filename="../ui/MainWindow.cpp" line="141"/>
<source>longitude</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="140"/>
<location filename="../ui/MainWindow.cpp" line="141"/>
<source>latitude</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="141"/>
<location filename="../ui/MainWindow.cpp" line="142"/>
<source>distance</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="141"/>
<location filename="../ui/MainWindow.cpp" line="142"/>
<source>velocity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="142"/>
<location filename="../ui/MainWindow.cpp" line="143"/>
<source>Radial dimensions</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="142"/>
<location filename="../ui/MainWindow.cpp" line="143"/>
<source>Target RCS</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="148"/>
<location filename="../ui/MainWindow.cpp" line="149"/>
<source>Report Table</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="157"/>
<location filename="../ui/MainWindow.cpp" line="158"/>
<source>Signal Indicator Lamp</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="164"/>
<location filename="../ui/MainWindow.cpp" line="165"/>
<source>ParamSetting</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="169"/>
<location filename="../ui/MainWindow.cpp" line="170"/>
<source>Matlab File</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="174"/>
<location filename="../ui/MainWindow.cpp" line="175"/>
<source>name: 5year 0412</source>
<translation type="unfinished"></translation>
</message>
@ -694,12 +694,12 @@
<context>
<name>OsgWidget</name>
<message>
<location filename="../viewer/OsgWidget.cpp" line="93"/>
<location filename="../viewer/OsgWidget.cpp" line="110"/>
<source>warning</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../viewer/OsgWidget.cpp" line="94"/>
<location filename="../viewer/OsgWidget.cpp" line="111"/>
<source>open dyt file failed</source>
<translation type="unfinished"></translation>
</message>
@ -858,17 +858,17 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../scene/ui/QueryElevationWidget.cpp" line="65"/>
<location filename="../scene/ui/QueryElevationWidget.cpp" line="75"/>
<source>longitude:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../scene/ui/QueryElevationWidget.cpp" line="66"/>
<location filename="../scene/ui/QueryElevationWidget.cpp" line="76"/>
<source>latitude:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../scene/ui/QueryElevationWidget.cpp" line="67"/>
<location filename="../scene/ui/QueryElevationWidget.cpp" line="77"/>
<source>altitude:</source>
<translation type="unfinished"></translation>
</message>

View File

@ -39,6 +39,7 @@ MainWindow::MainWindow(QWidget* parent)
MainWindow::~MainWindow() {
//OsgViewer::Get().Uninitialize();
UninitUI();
delete ui;
}
@ -187,6 +188,14 @@ void MainWindow::InitUI() {
#endif // 1
}
void MainWindow::UninitUI() {
if (qtOsgViewWidget_) {
qtOsgViewWidget_->Uninitialize();
delete qtOsgViewWidget_;
qtOsgViewWidget_ = nullptr;
}
}
void MainWindow::InitDockLayout() {
while (tabWidget_->count() > 0) {
tabWidget_->removeTab(0);

View File

@ -42,6 +42,7 @@ public slots:
private:
void InitUI();
void UninitUI();
void InitDockLayout();
void AddDockArea(const QString& strArea);

View File

@ -58,6 +58,7 @@ void OsgViewUI::AddUI(OsgViewUI::ViewUI* viewUI) {
}
void OsgViewUI::RemoveUI(OsgViewUI::ViewUI* viewUI) {
viewUI->UninitUI(this);
for (auto it = viewUIs_.begin(); it != viewUIs_.end(); ++it) {
if (*it == viewUI) {
viewUIs_.erase(it);

View File

@ -11,6 +11,7 @@ public:
public:
virtual ~ViewUI() = default;
virtual void InitUI(OsgViewUI* ui ) = 0;
virtual void UninitUI(OsgViewUI* ui) = 0;
virtual void OnResize(double width, double height) = 0;
};

View File

@ -59,9 +59,10 @@ OsgWidget::~OsgWidget() {
}
}
void OsgWidget::Initialize() {
void OsgWidget::Initialize() {
LOG_INFO("OsgWidget::Initialize");
QHBoxLayout* layout = new QHBoxLayout(this);
activeScene_ = new OEScene();
activeScene_ = new OEScene;
connect(&WorkSpaceManager::Get(), &WorkSpaceManager::WorkSpaceChanged, [this](WorkSpace* workspace) {
if (nullptr == workspace) {
LOG_WARN("workspace is nullptr");
@ -78,6 +79,22 @@ void OsgWidget::Initialize() {
viewUI_->AddUI(activeScene_->GetOrCreateSceneUI());
}
void OsgWidget::Uninitialize() {
LOG_INFO("OsgWidget::Uninitialize");
if (nullptr != viewUI_) {
viewUI_->RemoveUI(activeScene_->GetOrCreateSceneUI());
viewUI_ = nullptr;
}
if (nullptr != activeScene_) {
activeScene_->DetachView(view_);
activeScene_ = nullptr;
}
if (nullptr != view_) {
removeView(view_);
view_ = nullptr;
}
}
void OsgWidget::LoadDefaultScene() {
dyt_check(nullptr != activeScene_);
if (nullptr == WorkSpaceManager::Get().LoadDefaultWorkspace(activeScene_)) {

View File

@ -13,6 +13,7 @@ public:
~OsgWidget() override;
void Initialize(void);
void Uninitialize(void);
void LoadDefaultScene(void);
void OnLoadDyt(const QString& path);