fix new workspace crash

This commit is contained in:
jiegeaiai 2025-01-05 21:49:36 +08:00
parent 0892fe6c6d
commit f4bdb4473d
11 changed files with 77 additions and 114 deletions

View File

@ -18,6 +18,7 @@
#include "common/RecourceHelper.h"
#include "scene/ScopedTimer.h"
#include "viewer/OsgView.h"
#include "viewer/OsgCameraManipulator.h"
const osgEarth::SpatialReference* g_srs_{ nullptr };

View File

@ -676,57 +676,57 @@
<context>
<name>ModelTreeWidget</name>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="96"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="98"/>
<source>Release Track</source>
<translation></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="113"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="115"/>
<source>Add boke Entity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="120"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="122"/>
<source>Add lsjhqt Entity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="127"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="129"/>
<source>Add nimizi Entity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="134"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="136"/>
<source>Add tkdlj Entity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="141"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="143"/>
<source>Add jiaofan Entity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="148"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="150"/>
<source>Add satellite Entity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="250"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="252"/>
<source>Track</source>
<translation></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="258"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="260"/>
<source>Add Mesh Component</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="262"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="264"/>
<source>Add Path Component</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="269"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="271"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
@ -1271,12 +1271,12 @@
<context>
<name>QtOsgViewWidget</name>
<message>
<location filename="../viewer/QtOsgViewWidget.cpp" line="105"/>
<location filename="../viewer/QtOsgViewWidget.cpp" line="110"/>
<source>notify</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../viewer/QtOsgViewWidget.cpp" line="105"/>
<location filename="../viewer/QtOsgViewWidget.cpp" line="110"/>
<source>open dyt file failed</source>
<translation type="unfinished"></translation>
</message>
@ -1724,7 +1724,7 @@
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="73"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="82"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="88"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="97"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="98"/>
<source>warning</source>
<translation></translation>
</message>
@ -1759,12 +1759,12 @@
<translation></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="97"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="98"/>
<source>create workSpace failed</source>
<translation></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="107"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="108"/>
<source>save spaceWork directory</source>
<translation></translation>
</message>

View File

@ -5,6 +5,8 @@
#include <QVariant>
#include <QMenu>
#include <osgEarth/EarthManipulator>
#include "common/RecourceHelper.h"
#include "common/SpdLogger.h"
#include "entities/EntitiesManager.h"
@ -332,14 +334,14 @@ void ModelTreeWidget::OnTrackEntity(Entity* entity) {
osgGA::CameraManipulator* gaManipulator = manipulator->GetManipulator();
CameraControlManipulator* ccm = dynamic_cast<CameraControlManipulator*>(gaManipulator);
osgEarth::Util::EarthManipulator* ccm = dynamic_cast<osgEarth::Util::EarthManipulator*>(gaManipulator);
if (nullptr != ccm) {
if (nullptr != entity) {
osg::MatrixTransform* mt = entity->GetRootComponent()->GetMatrixTransform();
ccm->setManipulatorMode(CameraControlManipulator::Tracker_ManipulatorMode);
ccm->setTrackNode(mt);
ccm->setNode(mt);
//ccm->setTetherMode(osgGA::CameraManipulator::TETHER_CENTER_AND_ROTATION);
} else {
ccm->setManipulatorMode(CameraControlManipulator::Roam_ManipulatorMode);
ccm->setNode(nullptr);
}
}
}

View File

@ -89,9 +89,10 @@ void WorkSpaceDlg::OnSure() {
return;
}
WorkSpace* workSpace = WorkSpaceManager::Get().GetOrCreate(name);
workSpace->SetDescribe(ui->etDescribe->toPlainText());
workspacePath += QString("/%1.dyt").arg(name);
WorkSpace* workSpace = WorkSpaceManager::Get().GetOrCreate(workspacePath, name);
workSpace->SetDescribe(ui->etDescribe->toPlainText());
if (!workSpace->Save(workspacePath)) {
LOG_ERROR("save workSpace failed");
QMessageBox::warning(this, tr("warning"), tr("create workSpace failed"));

View File

@ -71,6 +71,11 @@ void QtOsgViewWidget::Initialize(void) {
setMouseTracking(true);
activeScene_ = new OEScene;
activeScene_->AttachView(view_);
activeScene_->InitEventHandle(view_);
osgEarth::Util::EarthManipulator* manipulator = new osgEarth::Util::EarthManipulator;
osgEarth::Viewpoint vp("home", 107.85, 32.35, 100.0, -2.50, -90.0, 1.5e7);
@ -94,13 +99,13 @@ void QtOsgViewWidget::Uninitialize(void) {
}
void QtOsgViewWidget::LoadDefaultScene(void) {
dyt_check(nullptr != view_, "view is nullptr");
WorkSpaceManager::Get().LoadDefaultWorkspace(view_);
dyt_check(nullptr != activeScene_);
WorkSpaceManager::Get().LoadDefaultWorkspace(activeScene_);
}
void QtOsgViewWidget::OnLoadDyt(const QString& path) {
LOG_INFO("load dyt path:{}", path.toStdString());
WorkSpace* workSpace = WorkSpaceManager::Get().LoadDyt(path, view_);
WorkSpace* workSpace = WorkSpaceManager::Get().LoadDyt(path);
if (nullptr == workSpace) {
QMessageBox::warning(&MainFrame::Get(), tr("notify"), tr("open dyt file failed"), QMessageBox::Ok);
return;
@ -128,9 +133,5 @@ void QtOsgViewWidget::resizeEvent(QResizeEvent* event) {
double pixelRatio = screen()->devicePixelRatio();
const QSize& size = event->size();
view_->Resize(0, 0, size.width() * pixelRatio, size.height() * pixelRatio);
if (nullptr != workspace_) {
workspace_->ViewReize(size.width() * pixelRatio, size.height() * pixelRatio);
}
}

View File

@ -3,6 +3,8 @@
// #include <QGLWidget>
#include <QWidget>
#include "scene/OEScene.h"
class QMouseEvent;
class QWheelEvent;
@ -41,5 +43,6 @@ protected:
private:
class OsgView* view_{ nullptr };
osg::ref_ptr<OEScene> activeScene_;
class WorkSpace* workspace_{ nullptr };
};

View File

@ -18,57 +18,17 @@
Q_DECLARE_METATYPE(WorkSpace*)
WorkSpace::WorkSpace(OsgView* view, QObject* parent) noexcept
: QObject(parent)
, view_(view) {
WorkSpace::WorkSpace(QObject* parent) noexcept
: QObject(parent) {
uuid_ = QUuid::createUuid().toString();
}
WorkSpace::WorkSpace(const QString& name, QObject* parent)
WorkSpace::WorkSpace(const QString& path, QObject* parent)
: QObject(parent)
, name_(name){
, path_(path){
uuid_ = QUuid::createUuid().toString();
}
void WorkSpace::ViewReize(int width, int height) {
if (nullptr != activeScene_) {
//activeScene_->GetOceanScene()->setScreenDims(osg::Vec2s(width * 2, height * 2));
} else {
LOG_WARN("secen_:{} or ocean is nullptr", spdlog::fmt_lib::ptr(activeScene_.get()));
}
}
bool WorkSpace::CreateScene(const std::string& scene) {
LOG_INFO("create scene {}", scene);
if (nullptr == view_) {
return false;
}
if (nullptr != activeScene_) {
activeScene_->DetachView(view_);
}
name_ = name_.fromStdString(scene);
#if 0
activeScene_ = new OsgScene;
activeScene_->UseShadows(false);
activeScene_->ChangeScene(OsgScene::CLOUDY);
activeScene_->AttachView(view_);
activeScene_->InitEventHandle(view_);
#else
activeScene_ = new OEScene;
//activeScene_->UseShadows(false);
//activeScene_->ChangeScene(OsgScene::CLOUDY);
activeScene_->AttachView(view_);
activeScene_->InitEventHandle(view_);
#endif
return true;
}
void WorkSpace::AddEntity(Entity* entity) {
if (nullptr == entity) {
@ -91,24 +51,6 @@ void WorkSpace::RemoveEntity(Entity* entity) {
}
}
#if USE_OCEAN
OsgScene* WorkSpace::GetActiveScene() const {
if (!activeScene_.valid()) {
return nullptr;
}
return activeScene_.get();
}
#else
OEScene* WorkSpace::GetActiveScene() const {
if (!activeScene_.valid()) {
return nullptr;
}
return activeScene_.get();
}
#endif
bool WorkSpace::SetTimestep(Timestep* timestep) {
if (!timestep) {
return false;

View File

@ -5,6 +5,8 @@
#include "scene/OsgScene.h"
#include "scene/OEScene.h"
#include "config.h"
#include "common/SpdLogger.h"
//#include "../ui/chartPlot/DYTChart.h"
@ -14,8 +16,8 @@ class WorkSpace : public QObject {
Q_OBJECT
public:
explicit WorkSpace(class OsgView* view, QObject* parent = nullptr) noexcept;
WorkSpace(const QString& name, QObject* parent = nullptr);
explicit WorkSpace(QObject* parent = nullptr) noexcept;
WorkSpace(const QString& path, QObject* parent = nullptr);
~WorkSpace() override = default;
inline void SetName(const QString& name) {
@ -47,14 +49,15 @@ public:
return entities_;
}
void ViewReize(int width, int height);
bool CreateScene(const std::string& scene);
#if USE_OCEAN
OsgScene* GetActiveScene() const;
#else
OEScene* GetActiveScene() const;
#endif
void SetActiveScene(OEScene* scene) {
dyt_check(nullptr != scene);
scene_ = scene;
}
OEScene* GetActiveScene() const {
dyt_check(nullptr != scene_);
return scene_;
}
bool SetTimestep(class Timestep* timestep);
bool SetTimestepPath(const QString& path);
class Timestep* GetTimestep() const {
@ -96,8 +99,7 @@ private:
bool leaded_{ false };
std::vector<class Entity*> entities_;
osg::ref_ptr<OEScene> activeScene_;
class OsgView* view_{ nullptr };
OEScene* scene_{ nullptr };
class Timestep* timestep_{ nullptr };
class LampStatus* lampStatus_{ nullptr };
};

View File

@ -10,8 +10,7 @@
template<> WorkSpaceManager* Singleton<WorkSpaceManager>::instance_ = nullptr;
WorkSpaceManager::WorkSpaceManager(QObject* parent)
: QObject(parent) {
}
: QObject(parent) {}
WorkSpaceManager::~WorkSpaceManager() {
@ -21,7 +20,10 @@ void WorkSpaceManager::OnDestory() {
SaveDefaultWorkspace();
}
WorkSpace* WorkSpaceManager::LoadDefaultWorkspace(class OsgView* view) {
WorkSpace* WorkSpaceManager::LoadDefaultWorkspace(class OEScene* secen) {
dyt_check(nullptr != secen);
scene_ = secen;
const QString iniFile = GetDefaultWorkSpaceName();
if (!QFile::exists(iniFile)) {
LOG_ERROR("default workspace file not exist:{}", iniFile.toStdString());
@ -34,7 +36,7 @@ WorkSpace* WorkSpaceManager::LoadDefaultWorkspace(class OsgView* view) {
LOG_ERROR("default workspace path is empty");
return nullptr;
}
WorkSpace* workspace = LoadDyt(path, view);
WorkSpace* workspace = LoadDyt(path);
if (nullptr == workspace) {
LOG_ERROR("load default workspace failed");
return nullptr;
@ -85,8 +87,8 @@ bool WorkSpaceManager::Remove(const QString& name) {
return true;
}
WorkSpace* WorkSpaceManager::LoadDyt(const QString& dyt, class OsgView* view) {
WorkSpace* workspace = new WorkSpace(view, this);
WorkSpace* WorkSpaceManager::LoadDyt(const QString& dyt) {
WorkSpace* workspace = new WorkSpace(this);
if (!workspace->Load(dyt)) {
LOG_WARN("load workspace failed");
workspace->deleteLater();
@ -97,7 +99,7 @@ WorkSpace* WorkSpaceManager::LoadDyt(const QString& dyt, class OsgView* view) {
return workspace;
}
WorkSpace* WorkSpaceManager::GetOrCreate(const QString& path) {
WorkSpace* WorkSpaceManager::GetOrCreate(const QString& path, const QString& name) {
const auto itor = workSpaces_.find(path);
if (workSpaces_.end() != itor) {
return itor->second;
@ -105,15 +107,22 @@ WorkSpace* WorkSpaceManager::GetOrCreate(const QString& path) {
LOG_INFO("create workspace name:{}", path.toStdString());
WorkSpace* workspace = new WorkSpace(path, this);
workspace->SetName(name);
workSpaces_[path] = workspace;
return workspace;
}
void WorkSpaceManager::SetCurrent(WorkSpace* workspace) {
if (current_ == workspace) {
LOG_INFO("current == workspace");
return;
}
if (nullptr != current_) {
current_->End();
}
current_ = workspace;
workspace->SetActiveScene(scene_);
lastTime_ = clock();

View File

@ -19,13 +19,13 @@ public:
~WorkSpaceManager();
void OnDestory();
WorkSpace* LoadDefaultWorkspace(class OsgView* view);
WorkSpace* LoadDefaultWorkspace(class OEScene* secen);
void SaveDefaultWorkspace();
bool Contains(const QString& name) const;
bool Remove(const QString& name);
WorkSpace* LoadDyt(const QString& dyt, class OsgView* view);
WorkSpace* GetOrCreate(const QString& path);
WorkSpace* LoadDyt(const QString& dyt);
WorkSpace* GetOrCreate(const QString& path, const QString& name);
void SetCurrent(WorkSpace* workspace);
WorkSpace* GetCurrent() const { return current_; }
@ -72,6 +72,7 @@ private:
private:
std::unordered_map<QString, WorkSpace*> workSpaces_;
class OEScene* scene_{ nullptr };
WorkSpace* current_{ nullptr };
int64_t lastTime_{ 0 };

View File

@ -26,7 +26,8 @@ bool WorkSpaceXMLParse::ParseScene(const tinyxml2::XMLElement* element) {
if (0 == strcmp(eleName, "scene")) {
const char* name = element->Attribute("name");
return workSpace_->CreateScene(name);
workSpace_->SetName(name);
return true;
} else if (0 == strcmp(eleName, "describe")) {
const char* value = element->Attribute("describe");