modiyf workspace creat and save, set timestep bug

This commit is contained in:
jiegeaiai 2025-01-22 02:42:57 +08:00
parent ca5df0f018
commit 74f4d658d1
17 changed files with 111 additions and 73 deletions

View File

@ -103,7 +103,7 @@ INCLUDE_DIRECTORIES(
if(MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /Od") #/Od
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi") #/Od
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
foreach(var
@ -185,7 +185,7 @@ endif()
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ProjectDIR}/bin)
TARGET_LINK_LIBRARIES(${PROJECT_NAME})
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE")
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE")
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD

View File

@ -10,10 +10,12 @@
#include <osg/Shader>
#include <osg/Program>
#include <osg/Uniform>
#include <osg/Depth>
#include <osgEarth/Registry>
ConeWave::ConeWave() {
osgEarth::Registry::shaderGenerator().run(this);
}
@ -27,6 +29,10 @@ void ConeWave::Render(double dt) {
void ConeWave::InitGeode() {
CreateTexturedCone(this);
//getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
//getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
//getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
//setCullingActive(false);
}
void ConeWave::Destory() {
@ -76,7 +82,15 @@ void ConeWave::CreateTexturedCone(osg::Geode* geode) {
tesselate->setCreateBottom(false);
tesselate->setCreateBackFace(false);
coneDrawable_ = new osg::ShapeDrawable(cone_, tesselate);
addDrawable(coneDrawable_);
geode->addDrawable(coneDrawable_);
//coneDrawable_->setColor(baseColor_);
//osg::StateSet* ss = coneDrawable_->getOrCreateStateSet();
////stateset->setRenderBinDetails(120, "OSGEARTH_SCREEN_SPACE_LAYOUT_BIN");
//ss->setRenderBinDetails(120, "RenderBin");
//osg::ref_ptr<osg::BlendFunc> bf = new osg::BlendFunc();
//ss->setAttributeAndModes(bf, osg::StateAttribute::ON);
//ss->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
//return;
static const char* vertSource = {
"varying vec3 pos;\n"
@ -128,6 +142,7 @@ void ConeWave::CreateTexturedCone(osg::Geode* geode) {
stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
stateset->addUniform(baseColorUniform_);
stateset->setAttributeAndModes(program, osg::StateAttribute::ON);
stateset->setAttributeAndModes(new osg::Depth(osg::Depth::LESS, 0.0, 1.0, false));
levelCountUniform_ = new osg::Uniform("num", float(levelCount_));
levelHeightUniform_ = new osg::Uniform("height", levelHeight_);

View File

@ -67,7 +67,7 @@ void PathComponent::Begin() {
int num = std::min(steps.size(), transforms.size());
for (int index = 0; index < num; ++index) {
const Transform& transform = transforms[index];
osg::AnimationPath::ControlPoint controlPoint(transform.GetLocation() + osg::Vec3(index * 10, 0, 0),
osg::AnimationPath::ControlPoint controlPoint(transform.GetLocation() /*+ osg::Vec3(index * 10, 0, 0)*/,
OsgUtils::HPRToQuat(transform.GetRotation() + osg::Vec3(0, 0, -90.0)), transform.GetScale());
animationPath_->insert(steps[index], controlPoint);
}

View File

@ -63,13 +63,11 @@ void OEScene::AttachView(OsgView* view) {
view->GetView()->setSceneData(root_);
earthRootNode_ = osgDB::readNodeFile("triton.earth");
if (!earthRootNode_) {
LOG_ERROR("read earth node(triton.earth) failed");
return;
}
dyt_check(nullptr != earthRootNode_);
logarithmicDepthBuffer_ = std::make_unique<osgEarth::Util::LogarithmicDepthBuffer>();
earthMapNode_ = osgEarth::MapNode::get(earthRootNode_);
dyt_check(nullptr != earthMapNode_);
LOG_INFO("earth map node get success: {}", earthMapNode_.valid());
g_srs_ = earthMapNode_->getMapSRS();

Binary file not shown.

View File

@ -369,25 +369,28 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/Menu/FileManagerMenu.cpp" line="44"/>
<location filename="../ui/Menu/FileManagerMenu.cpp" line="60"/>
<location filename="../ui/Menu/FileManagerMenu.cpp" line="45"/>
<source>Dyt (*.dyt)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/Menu/FileManagerMenu.cpp" line="47"/>
<location filename="../ui/Menu/FileManagerMenu.cpp" line="48"/>
<source>open dyt file</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/Menu/FileManagerMenu.cpp" line="48"/>
<location filename="../ui/Menu/FileManagerMenu.cpp" line="64"/>
<location filename="../ui/Menu/FileManagerMenu.cpp" line="49"/>
<source>Dyt (*.dyt);;All files (*.*)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/Menu/FileManagerMenu.cpp" line="63"/>
<source>save dyt file</source>
<location filename="../ui/Menu/FileManagerMenu.cpp" line="65"/>
<source>warning</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/Menu/FileManagerMenu.cpp" line="65"/>
<source>workspace is nullptr</source>
<translation type="unfinished"></translation>
</message>
</context>
@ -1297,7 +1300,7 @@
<message>
<location filename="../ui/PropertyBrowser/qtpropertymanager.cpp" line="8683"/>
<source>Path</source>
<translation type="unfinished"></translation>
<translation type="unfinished"></translation>
</message>
</context>
<context>
@ -1516,12 +1519,12 @@
<message>
<location filename="../ui/PropertyBrowser/qttreepropertybrowser.cpp" line="454"/>
<source>Property</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../ui/PropertyBrowser/qttreepropertybrowser.cpp" line="455"/>
<source>Value</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
</context>
<context>
@ -1764,53 +1767,51 @@
<translation></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="52"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="58"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="68"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="75"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="84"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="90"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="100"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="57"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="63"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="73"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="80"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="89"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="95"/>
<source>warning</source>
<translation></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="52"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="57"/>
<source>name or save path is empty, please check it</source>
<translation></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="58"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="63"/>
<source>save current workspace?</source>
<translation></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="68"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="73"/>
<source>current path is contains current folder, do you want to overwrite it?</source>
<translation></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="75"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="80"/>
<source>removeRecursively failed</source>
<translation></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="84"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="89"/>
<source>mkpath failed</source>
<translation></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="90"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="95"/>
<source>name is exits</source>
<translation></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="100"/>
<source>create workSpace failed</source>
<translation></translation>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="111"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="110"/>
<source>save spaceWork directory</source>
<translation></translation>
</message>

View File

@ -12,6 +12,7 @@
#include "common/SpdLogger.h"
#include "workspace/WorkSpace.h"
#include "workspace/WorkSpaceManager.h"
#include "utils/FileUtils.h"
#include "ui_FileManagerMenu.h"
@ -57,23 +58,31 @@ void FileManagerMenu::OpenWorkSpace() {
void FileManagerMenu::SaveWorkSpace() {
LOG_INFO("click SaveWorkSpace");
QString selfilter = tr("Dyt (*.dyt)");
const QString workspacePath = Application::GetWorkSpacePath();
QString dytFile = QFileDialog::getSaveFileName(&MainFrame::Get(), tr("save dyt file"), workspacePath,
tr("Dyt (*.dyt);;All files (*.*)"),
&selfilter);
LOG_INFO("user select file: {}", dytFile.toStdString());
if (dytFile.isEmpty()) {
return;
}
WorkSpace* workspace = WorkSpaceManager::Get().GetCurrent();
if (nullptr == workspace) {
LOG_WARN("workspace is nullptr");
QMessageBox::warning(&MainFrame::Get(), tr("warning"), tr("workspace is nullptr"));
return;
}
const QString name = workspace->GetName();
QString dytFile = workspace->GetPath();
LOG_INFO("save {} dyt file: {}", name.toLocal8Bit().constData(),
dytFile.toLocal8Bit().constData());
/* if (!FileUtils::IsExist(dytFile)) {
QString selfilter = tr("Dyt (*.dyt)");
const QString workspacePath = Application::GetWorkSpacePath();
dytFile = QFileDialog::getSaveFileName(&MainFrame::Get(), tr("save dyt file"), workspacePath,
tr("Dyt (*.dyt);;All files (*.*)"),
&selfilter);
LOG_INFO("user select file: {}", dytFile.toLocal8Bit().constData());
if (dytFile.isEmpty()) {
return;
}
}*/
bool success = workspace->Save(dytFile);
LOG_INFO("save dyt: {}", success);
}

View File

@ -751,12 +751,12 @@ void QFilePathEdit::onFileSelect() {
return;
}
}
if (!FileUtils::CopyFileToPath(filePath, filePath, true)) {
if (!FileUtils::CopyFileToPath(filePath, savePath, true)) {
LOG_ERROR("Failed to copy file to workspace");
QMessageBox::critical(nullptr, "Error", "Failed to copy file to workspace");
return;
}
LOG_INFO("PathComponent::SetPath: {}", workPath.toStdString().c_str());
LOG_INFO("SetPath: {}", savePath.toLocal8Bit().constData());
m_initialvalue = m_fileName;
m_stringEdit->setText(m_fileName);
}

View File

@ -26,8 +26,8 @@ WorkSpaceDlg::WorkSpaceDlg(QWidget* parent)
SetTitle(tr("new workspace"));
const QString path = qApp->applicationDirPath() + "/workspace";
ui->lePath->setText(path);
path_ = qApp->applicationDirPath() + "/workspace";
ui->lePath->setText(path_);
//setFixedHeight(500);
}
@ -39,15 +39,20 @@ void WorkSpaceDlg::InitConnect() {
connect(ui->pbSure, &QPushButton::clicked, this, &WorkSpaceDlg::OnSure);
connect(ui->pbCancel, &QPushButton::clicked, this, &WorkSpaceDlg::reject);
connect(ui->tbPath, &QPushButton::clicked, this, &WorkSpaceDlg::OnSelectSavePath);
connect(ui->leName, &QLineEdit::textChanged, [this](const QString& txt) {
QString path = QString("%1/%2").arg(path_).arg(txt);
ui->lePath->setText(path);
}
);
//connect(ui->pbCancel, &QPushButton::clicked, this, &WorkSpaceDlg::reject);
}
void WorkSpaceDlg::OnSure() {
const QString name = ui->leName->text();
const QString savePath = ui->lePath->text();
LOG_INFO("name:{}, save path:{}", name.toStdString(), savePath.toStdString());
if (name.isEmpty() || savePath.isEmpty()) {
LOG_INFO("name:{}, save path:{}", name.toLocal8Bit().constData(), path_.toLocal8Bit().constData());
if (name.isEmpty() || path_.isEmpty()) {
LOG_WARN("name or save path is empty");
QMessageBox::warning(this, tr("warning"), tr("name or save path is empty, please check it"));
return;
@ -61,7 +66,7 @@ void WorkSpaceDlg::OnSure() {
current->Unlaod();
}
QString workspacePath = QString("%1/%2").arg(savePath).arg(name);
QString workspacePath = QString("%1/%2").arg(path_).arg(name);
QDir dir(workspacePath);
if (dir.exists()) {
LOG_WARN("current path is contains current folder, {}", workspacePath.toStdString());
@ -95,12 +100,6 @@ void WorkSpaceDlg::OnSure() {
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"));
return;
}
WorkSpaceManager::Get().SetCurrent(workSpace);
accept();
}
@ -113,9 +112,9 @@ void WorkSpaceDlg::OnSelectSavePath() {
LOG_WARN("save path is empty");
return;
}
ui->lePath->setText(savePath);
LOG_INFO("save path: {}", savePath.toStdString());
path_ = savePath;
ui->lePath->setText(QString("%1/%2").arg(path_).arg(ui->leName->text()));
LOG_INFO("save path: {}", path_.toLocal8Bit().constData());
}
void WorkSpaceDlg::InitFrame() {

View File

@ -23,4 +23,5 @@ protected:
private:
Ui::WorkSpaceDlg* ui;
QString path_;
};

View File

@ -22,6 +22,7 @@ TransformPath::~TransformPath() {
}
TransformPath* TransformPath::LoadFromFile(const QString& path, QObject* parent) {
LOG_INFO("Loading transform path from file: {}", path.toLocal8Bit().constData());
QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -42,7 +43,7 @@ TransformPath* TransformPath::LoadFromFile(const QString& path, QObject* parent)
bool ok;
double value = line.toDouble(&ok);
if (ok) {
transform.GetLocation()[i] = value * 1.5;
transform.GetLocation()[i] = value;
} else {
LOG_WARN("Failed to convert line to double: {}", line.toStdString());
return {};

View File

@ -16,13 +16,13 @@ Timestep::Timestep(const std::vector<double>& steps, const QString& path, WorkSp
maxTime_ = *steps_.rbegin();
}
Timestep* Timestep::Load(const QString& path, WorkSpace* parent) {
const QString filePath = QString("%1/%2").arg(RecourceHelper::Get().GetBasePath()).arg(path);
Timestep* Timestep::Load(const QString& path, WorkSpace* workSpace) {
const QString filePath = QString("%1/%2").arg(workSpace->GetDir()).arg(path);
LOG_INFO("Load timestep: {}", filePath.toStdString());
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
LOG_WARN("Cannot open file for reading: {}", file.errorString().toStdString());
LOG_WARN("Cannot open file for reading: {}", file.errorString().toLocal8Bit().constData());
return nullptr;
}
@ -42,7 +42,7 @@ Timestep* Timestep::Load(const QString& path, WorkSpace* parent) {
file.close();
Timestep* timestep = new Timestep(numbers, path, parent);
Timestep* timestep = new Timestep(numbers, path, workSpace);
return timestep;
}

View File

@ -20,7 +20,7 @@ public:
explicit Timestep(const std::vector<double>& steps, const QString& path, WorkSpace* parent = nullptr) noexcept;
~Timestep() override = default;
static Timestep* Load(const QString& path, WorkSpace* parent = nullptr);
static Timestep* Load(const QString& path, WorkSpace* workSpace = nullptr);
const std::vector<double>& GetSteps() const {
return steps_;

View File

@ -105,6 +105,19 @@ bool WorkSpaceManager::Remove(const QString& name) {
return true;
}
bool WorkSpaceManager::Remove(WorkSpace* workspace) {
if (nullptr == workspace) {
LOG_ERROR("workspace is nullptr");
return true;
}
auto itor = workSpaces_.find(workspace->GetPath());
if (workSpaces_.end() == itor) {
return true;
}
workSpaces_.erase(itor);
}
WorkSpace* WorkSpaceManager::LoadDyt(const QString& dyt) {
dyt_check(nullptr != scene_);
LOG_INFO("load workspace name:{}", dyt.toLocal8Bit().constData());
@ -126,7 +139,7 @@ WorkSpace* WorkSpaceManager::GetOrCreate(const QString& path, const QString& nam
return itor->second;
}
LOG_INFO("create workspace name:{}", path.toStdString());
LOG_INFO("create workspace name:{}", path.toLocal8Bit().constData());
WorkSpace* workspace = new WorkSpace(path, this);
workspace->SetName(name);
workSpaces_[path] = workspace;

View File

@ -26,6 +26,7 @@ public:
bool Remove(const QString& name);
WorkSpace* LoadDyt(const QString& dyt);
WorkSpace* GetOrCreate(const QString& path, const QString& name);
bool Remove(WorkSpace* workspace);
void SetCurrent(WorkSpace* workspace);
WorkSpace* GetCurrent() const { return current_; }

View File

@ -178,7 +178,7 @@ bool WorkSpaceXMLParse::ParseReport(const tinyxml2::XMLElement* element)
}
bool WorkSpaceXMLParse::Load(const QString& dyt) {
std::string path = dyt.toStdString();
std::string path = dyt.toLocal8Bit().constData();
LOG_INFO("load path:{}", path);
tinyxml2::XMLDocument xmlDocument;
tinyxml2::XMLError error = xmlDocument.LoadFile(path.c_str());

View File

@ -16,7 +16,7 @@ WorkSpaceXMLWrite::WorkSpaceXMLWrite(WorkSpace* workspace, QObject* parent) noex
, workSpace_(workspace) {}
bool WorkSpaceXMLWrite::Save(const QString& path) {
LOG_INFO("save path: {}", path.toStdString());
LOG_INFO("save path: {}", path.toLocal8Bit().constData());
if (nullptr == workSpace_) {
LOG_WARN("worksapce is nullptr");
return false;
@ -41,7 +41,7 @@ bool WorkSpaceXMLWrite::Save(const QString& path) {
entity->UnSerialize(entitiesXml);
}
tinyxml2::XMLError xmlError = doc.SaveFile(path.toStdString().c_str(), false);
tinyxml2::XMLError xmlError = doc.SaveFile(path.toLocal8Bit().constData(), false);
if (tinyxml2::XML_SUCCESS != xmlError) {
LOG_WARN("worksapce is nullptr");
return false;