modify workspace

This commit is contained in:
brige 2025-04-21 08:20:00 +08:00
parent 8a15b09464
commit 4acbf05ae0
12 changed files with 58 additions and 41 deletions

View File

@ -16,7 +16,6 @@ Application::Application(int& argc, char** argv, int /*= ApplicationFlags*/)
} }
Application::~Application() { Application::~Application() {
Uninit();
} }
QString Application::GetWorkSpacePath() { QString Application::GetWorkSpacePath() {

View File

@ -10,8 +10,7 @@ public:
~Application() override; ~Application() override;
static QString GetWorkSpacePath(); static QString GetWorkSpacePath();
void Uninit();
protected: protected:
void Init(); void Init();
void Uninit();
}; };

View File

@ -385,6 +385,7 @@ int main(int argc, char* argv[]) {
mainWindow.showMaximized(); mainWindow.showMaximized();
// //
int ret = app.exec(); int ret = app.exec();
app.Uninit();
return ret; return ret;
//osg::ArgumentParser arguments(&argc, argv); //osg::ArgumentParser arguments(&argc, argv);

View File

@ -65,6 +65,12 @@ bool OEScene::AddToScene(osg::Node* node) const {
return entityRoot_->addChild(node); return entityRoot_->addChild(node);
} }
void OEScene::SetHomeViewpoint(const osgEarth::Viewpoint& viewpoint, double duration_s) {
dyt_check(nullptr != earthManipulator_);
earthManipulator_->setViewpoint(viewpoint, duration_s);
earthManipulator_->setHomeViewpoint(viewpoint, duration_s);
}
// //
// void OEScene::InitEventHandle(osgViewer::View* view) { // void OEScene::InitEventHandle(osgViewer::View* view) {
// if (nullptr == view) { // if (nullptr == view) {

View File

@ -2,6 +2,7 @@
#include <osgEarth/MapNode> #include <osgEarth/MapNode>
#include <osgEarthUtil/Sky> #include <osgEarthUtil/Sky>
#include <osgEarth/Viewpoint>
#include "common/SpdLogger.h" #include "common/SpdLogger.h"
#include "config.h" #include "config.h"
@ -21,6 +22,7 @@ public:
void DetachView(osgViewer::View* view); void DetachView(osgViewer::View* view);
bool AddToScene(osg::Node* node) const; bool AddToScene(osg::Node* node) const;
void SetHomeViewpoint(const osgEarth::Viewpoint& viewpoint, double duration_s);
osgEarth::MapNode* GetMapNode(void) const { osgEarth::MapNode* GetMapNode(void) const {
dyt_check(earthMapNode_.valid()); dyt_check(earthMapNode_.valid());

View File

@ -694,18 +694,12 @@
<context> <context>
<name>OsgWidget</name> <name>OsgWidget</name>
<message> <message>
<location filename="../viewer/OsgWidget.cpp" line="64"/> <location filename="../viewer/OsgWidget.cpp" line="81"/>
<location filename="../viewer/OsgWidget.cpp" line="72"/>
<source>warning</source> <source>warning</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../viewer/OsgWidget.cpp" line="64"/> <location filename="../viewer/OsgWidget.cpp" line="82"/>
<source>default workspace failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../viewer/OsgWidget.cpp" line="73"/>
<source>open dyt file failed</source> <source>open dyt file failed</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -1253,18 +1247,12 @@
<context> <context>
<name>QtOsgViewWidget</name> <name>QtOsgViewWidget</name>
<message> <message>
<location filename="../viewer/QtOsgViewWidget.cpp" line="129"/> <location filename="../viewer/QtOsgViewWidget.cpp" line="136"/>
<location filename="../viewer/QtOsgViewWidget.cpp" line="137"/>
<source>warning</source> <source>warning</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../viewer/QtOsgViewWidget.cpp" line="129"/> <location filename="../viewer/QtOsgViewWidget.cpp" line="136"/>
<source>default workspace failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../viewer/QtOsgViewWidget.cpp" line="137"/>
<source>open dyt file failed</source> <source>open dyt file failed</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -50,6 +50,15 @@ OsgWidget::OsgWidget(QWidget* parent, Qt::WindowFlags f)
void OsgWidget::Initialize() { void OsgWidget::Initialize() {
QHBoxLayout* layout = new QHBoxLayout(this); 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");
return;
}
activeScene_->SetHomeViewpoint(workspace->GetHomeViewpoint(), 3.0);
}
);
QWidget* widget = addViewWidget( createGraphicsWindow(0,0,100,100)); QWidget* widget = addViewWidget( createGraphicsWindow(0,0,100,100));
layout->addWidget(widget); layout->addWidget(widget);
@ -61,7 +70,7 @@ void OsgWidget::LoadDefaultScene() {
dyt_check(nullptr != activeScene_); dyt_check(nullptr != activeScene_);
if (nullptr == WorkSpaceManager::Get().LoadDefaultWorkspace(activeScene_)) { if (nullptr == WorkSpaceManager::Get().LoadDefaultWorkspace(activeScene_)) {
LOG_ERROR("load default workspace failed"); LOG_ERROR("load default workspace failed");
QMessageBox::warning(this, tr("warning"), tr("default workspace failed")); //QMessageBox::warning(this, tr("warning"), tr("default workspace failed"));
} }
} }

View File

@ -80,24 +80,24 @@ void QtOsgViewWidget::Initialize(void) {
osgEarth::Util::EarthManipulator* manipulator = new osgEarth::Util::EarthManipulator; osgEarth::Util::EarthManipulator* manipulator = new osgEarth::Util::EarthManipulator;
connect(&WorkSpaceManager::Get(), &WorkSpaceManager::WorkSpaceChanged, [](WorkSpace* workspace) { connect(&WorkSpaceManager::Get(), &WorkSpaceManager::WorkSpaceChanged, [this](WorkSpace* workspace) {
LOG_INFO("WorkSpaceChanged"); LOG_INFO("WorkSpaceChanged");
if (nullptr == workspace) { if (nullptr == workspace) {
return; return;
} }
//OsgCameraManipulator* manipulator = OsgViewer::Get().GetView()->GetCameraManipulator(); OsgCameraManipulator* manipulator = view_->GetCameraManipulator();
//if (nullptr == manipulator) { if (nullptr == manipulator) {
// LOG_WARN("manipulator is nullptr"); LOG_WARN("manipulator is nullptr");
// return; return;
//} }
//osgGA::CameraManipulator* gaManipulator = manipulator->GetManipulator(); osgGA::CameraManipulator* gaManipulator = manipulator->GetManipulator();
//osgEarth::Util::EarthManipulator* ccm = dynamic_cast<osgEarth::Util::EarthManipulator*>(gaManipulator); osgEarth::Util::EarthManipulator* ccm = dynamic_cast<osgEarth::Util::EarthManipulator*>(gaManipulator);
//if (nullptr == ccm) { if (nullptr == ccm) {
// LOG_WARN("ccm is nullptr"); LOG_WARN("ccm is nullptr");
// return; return;
//} }
//ccm->setViewpoint(workspace->GetHomeViewpoint(), 3.0); ccm->setViewpoint(workspace->GetHomeViewpoint(), 3.0);
} }
); );
@ -126,7 +126,6 @@ void QtOsgViewWidget::LoadDefaultScene(void) {
dyt_check(nullptr != activeScene_); dyt_check(nullptr != activeScene_);
if (nullptr == WorkSpaceManager::Get().LoadDefaultWorkspace(activeScene_)) { if (nullptr == WorkSpaceManager::Get().LoadDefaultWorkspace(activeScene_)) {
LOG_ERROR("load default workspace failed"); LOG_ERROR("load default workspace failed");
QMessageBox::warning(this, tr("warning"), tr("default workspace failed"));
} }
} }

View File

@ -59,6 +59,18 @@ void WorkSpace::RemoveEntity(Entity* entity) {
} }
} }
void WorkSpace::SetActiveScene(OEScene* scene) {
dyt_check(nullptr != scene);
scene_ = scene;
osgEarth::Viewpoint vp;
vp.name() = "home";
vp.focalPoint()->set(scene->GetSrs(), -121.488, 46.2054, 0, osgEarth::AltitudeMode::ALTMODE_ABSOLUTE);
vp.pitch() = -50.0;
vp.range() = 100000;
homeViewpoint_ = vp;
}
bool WorkSpace::SetTimestep(Timestep* timestep) { bool WorkSpace::SetTimestep(Timestep* timestep) {
if (!timestep) { if (!timestep) {
return false; return false;

View File

@ -95,10 +95,7 @@ public:
return entities_; return entities_;
} }
void SetActiveScene(OEScene* scene) { void SetActiveScene(OEScene* scene);
dyt_check(nullptr != scene);
scene_ = scene;
}
OEScene* GetActiveScene() const { OEScene* GetActiveScene() const {
dyt_check(nullptr != scene_); dyt_check(nullptr != scene_);

View File

@ -3,6 +3,7 @@
#include<time.h> #include<time.h>
#include <QSettings> #include <QSettings>
#include <QFileInfo> #include <QFileInfo>
#include <QDir>
#include "app/Application.h" #include "app/Application.h"
#include "workspace/WorkSpace.h" #include "workspace/WorkSpace.h"
@ -64,9 +65,13 @@ WorkSpace* WorkSpaceManager::LoadDefaultWorkspace(class OEScene* secen) {
void WorkSpaceManager::SaveDefaultWorkspace() { void WorkSpaceManager::SaveDefaultWorkspace() {
const QString iniFile = GetDefaultWorkSpaceName(); const QString iniFile = GetDefaultWorkSpaceName();
if (!QFile::exists(iniFile)) { if (!QFile::exists(iniFile)) {
QFileInfo fileInfo(iniFile);
QDir dir;
if (!dir.mkdir(fileInfo.absolutePath())) {
LOG_ERROR("default workspace file not exist:{}", iniFile.toStdString()); LOG_ERROR("default workspace file not exist:{}", iniFile.toStdString());
return; return;
} }
}
WorkSpace* current = GetCurrent(); WorkSpace* current = GetCurrent();
if (nullptr == current) { if (nullptr == current) {