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() {
Uninit();
}
QString Application::GetWorkSpacePath() {

View File

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

View File

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

View File

@ -65,6 +65,12 @@ bool OEScene::AddToScene(osg::Node* node) const {
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) {
// if (nullptr == view) {

View File

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

View File

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

View File

@ -35,7 +35,7 @@ MainWindow::MainWindow(QWidget* parent)
ui->setupUi(this);
InitUI();
}
}
MainWindow::~MainWindow() {
//OsgViewer::Get().Uninitialize();

View File

@ -50,6 +50,15 @@ OsgWidget::OsgWidget(QWidget* parent, Qt::WindowFlags f)
void OsgWidget::Initialize() {
QHBoxLayout* layout = new QHBoxLayout(this);
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));
layout->addWidget(widget);
@ -61,7 +70,7 @@ void OsgWidget::LoadDefaultScene() {
dyt_check(nullptr != activeScene_);
if (nullptr == WorkSpaceManager::Get().LoadDefaultWorkspace(activeScene_)) {
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;
connect(&WorkSpaceManager::Get(), &WorkSpaceManager::WorkSpaceChanged, [](WorkSpace* workspace) {
connect(&WorkSpaceManager::Get(), &WorkSpaceManager::WorkSpaceChanged, [this](WorkSpace* workspace) {
LOG_INFO("WorkSpaceChanged");
if (nullptr == workspace) {
return;
}
//OsgCameraManipulator* manipulator = OsgViewer::Get().GetView()->GetCameraManipulator();
//if (nullptr == manipulator) {
// LOG_WARN("manipulator is nullptr");
// return;
//}
//osgGA::CameraManipulator* gaManipulator = manipulator->GetManipulator();
//osgEarth::Util::EarthManipulator* ccm = dynamic_cast<osgEarth::Util::EarthManipulator*>(gaManipulator);
//if (nullptr == ccm) {
// LOG_WARN("ccm is nullptr");
// return;
//}
OsgCameraManipulator* manipulator = view_->GetCameraManipulator();
if (nullptr == manipulator) {
LOG_WARN("manipulator is nullptr");
return;
}
osgGA::CameraManipulator* gaManipulator = manipulator->GetManipulator();
osgEarth::Util::EarthManipulator* ccm = dynamic_cast<osgEarth::Util::EarthManipulator*>(gaManipulator);
if (nullptr == ccm) {
LOG_WARN("ccm is nullptr");
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_);
if (nullptr == WorkSpaceManager::Get().LoadDefaultWorkspace(activeScene_)) {
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) {
if (!timestep) {
return false;

View File

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

View File

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