DYTSrouce/src/workspace/WorkSpace.h

200 lines
5.3 KiB
C
Raw Normal View History

2025-01-04 04:12:51 +00:00
#pragma once
#include <map>
2025-10-13 00:20:53 +00:00
#include <memory>
2025-10-12 14:55:13 +00:00
#include <cstdint>
2025-01-04 04:12:51 +00:00
#include <QObject>
2025-01-05 18:18:16 +00:00
#include <osgEarth/Viewpoint>
2025-01-04 04:12:51 +00:00
#include "scene/OsgScene.h"
#include "scene/OEScene.h"
2025-01-05 13:49:36 +00:00
#include "config.h"
#include "common/SpdLogger.h"
2025-10-12 14:14:16 +00:00
#include "workspace/FileEntry.h"
2025-10-20 18:17:40 +00:00
#include "workspace/ChartData.h"
2025-01-04 04:12:51 +00:00
//#include "../ui/chartPlot/DYTChart.h"
class WorkSpaceItem;
2025-10-13 00:20:53 +00:00
class CommandManager;
2025-01-04 04:12:51 +00:00
class WorkSpace : public QObject {
Q_OBJECT
public:
2025-01-05 13:49:36 +00:00
explicit WorkSpace(QObject* parent = nullptr) noexcept;
WorkSpace(const QString& path, QObject* parent = nullptr);
2025-01-04 04:12:51 +00:00
~WorkSpace() override = default;
inline void SetName(const QString& name) {
name_ = name;
}
inline const QString& GetName() const {
return name_;
}
2025-01-05 11:12:18 +00:00
inline const QString& GetPath() const {
return path_;
}
2025-01-05 15:12:58 +00:00
const QString GetDir() const;
2025-01-04 04:12:51 +00:00
inline void SetUUid(const QString& uuid) {
uuid_ = uuid;
}
inline const QString& GetUUid() const {
return uuid_;
}
// static WorkSpace* Create(const QString& name);
inline void SetDescribe(const QString& describe) {
describe_ = describe;
}
inline const QString& GetDescribe() const {
return describe_;
}
2025-10-11 00:32:25 +00:00
void SetCommondFilePath(const QString& path);
2025-10-14 16:41:12 +00:00
const QString GetCommondFilePath() const {
return commondPath_;
}
2025-10-11 00:32:25 +00:00
2025-10-13 00:20:53 +00:00
// Execute command xml according to trigger
enum class CommandWhen { OnCreate, OnLoad };
void ExecuteCommands(CommandWhen when);
2025-07-05 04:07:30 +00:00
void SetSimMatlab(const QString& path);
const QString GetSimMatlab() const;
2025-01-07 15:45:23 +00:00
inline void SetMatlabParam(const QString& path) {
matlabParamPath_ = path;
}
inline const QString GetMatlabParam() const {
return matlabParamPath_;
}
2025-07-05 04:07:30 +00:00
void SetWavePath(const QString& path);
const QString GetWavePath() const;
2025-01-07 15:45:23 +00:00
2025-07-05 04:07:30 +00:00
void SetReportPath(const QString& path) ;
const QString GetReportPath() const;
2025-01-07 15:45:23 +00:00
2025-07-05 04:07:30 +00:00
void SetRDPath(const QString& path);
const QString GetRDPath() const;
2025-01-07 15:45:23 +00:00
2025-10-12 14:14:16 +00:00
// Files list API (per-type, max 9 per type)
enum class FileEntryResult { Ok, LimitExceeded, Duplicate, CopyFailed };
FileEntryResult CreateFileEntry(FileEntryType type);
std::vector<FileEntry> GetFileEntries(FileEntryType type) const;
// Manage grouped file entries
bool SetFileEntryCount(FileEntryType type, int count);
bool SetFileEntryPath(FileEntryType type, int index, const QString& path);
QString GetFileEntryAbsPath(FileEntryType type, int index) const;
2025-10-20 18:17:40 +00:00
// Chart data management
void SetFileTypeData(const QList<FileTypeData>& fileTypes);
const QList<FileTypeData>& GetFileTypeData() const;
void AddChartData(FileEntryType type, const std::shared_ptr<BaseChartData>& chart);
QList<std::shared_ptr<BaseChartData>> GetChartData(FileEntryType type) const;
2025-01-05 18:18:16 +00:00
inline void SetHomeViewpoint(const osgEarth::Viewpoint& viewpoint) {
homeViewpoint_ = viewpoint;
2025-06-17 18:05:47 +00:00
homeViewpoint_.setHeading(0.0); // Ensure heading is set to 0.0
2025-01-05 18:18:16 +00:00
}
inline const osgEarth::Viewpoint& GetHomeViewpoint() const {
return homeViewpoint_;
}
2025-01-04 04:12:51 +00:00
const std::vector<class Entity*>& GetEntities() const {
return entities_;
}
std::vector<class Entity*>& GetEntities() {
return entities_;
}
2025-04-21 00:20:00 +00:00
void SetActiveScene(OEScene* scene);
2025-01-04 04:12:51 +00:00
2025-01-05 13:49:36 +00:00
OEScene* GetActiveScene() const {
dyt_check(nullptr != scene_);
return scene_;
}
2025-01-04 04:12:51 +00:00
bool SetTimestep(class Timestep* timestep);
bool SetTimestepPath(const QString& path);
class Timestep* GetTimestep() const {
return timestep_;
}
bool SetLampStatus(class LampStatus* timestep);
bool SetLampPath(const QString& path);
class LampStatus* GetLampStatus() const {
return lampStatus_;
}
void AddEntity(class Entity* entity);
void RemoveEntity(class Entity* entity);
2025-06-17 18:05:47 +00:00
bool TrackEntity(class Entity* entity);
void UntrackEntity();
2025-06-18 15:33:06 +00:00
class Entity* GetTrackEntity() const {
return trackedEntity_;
}
2025-01-04 04:12:51 +00:00
bool Save(const QString& path);
bool Save();
bool Load(const QString& dyt);
void Unlaod();
void Begin();
void OnFrame(double dt);
void End();
2025-01-05 11:12:18 +00:00
void OnLoaded();
2025-01-04 04:12:51 +00:00
Q_SIGNALS:
2025-10-12 14:14:16 +00:00
void EntityAdded(class Entity* entity);
void EntityRemoved(class Entity* entity);
void TimestepChanged(class Timestep* timestep);
void LampStatusChanged(class LampStatus* lampStatus);
// Emitted when grouped file entries change (count or path or creation)
void FilesChanged(FileEntryType type);
2025-01-04 04:12:51 +00:00
2025-07-05 04:07:30 +00:00
protected:
const QString& GetSimMatlabName() const {
return simMatlabPath_;
}
2025-01-04 04:12:51 +00:00
private:
QString name_;
QString uuid_;
QString describe_;
QString path_;
2025-10-11 00:32:25 +00:00
QString commondPath_;
2025-01-07 15:45:23 +00:00
QString simMatlabPath_;
QString waveFile_;
QString reportFile_;
QString rdFile_;
QString matlabParamPath_;
2025-01-05 18:18:16 +00:00
osgEarth::Viewpoint homeViewpoint_;
2025-01-04 04:12:51 +00:00
2025-01-05 03:33:33 +00:00
bool leaded_{ false };
2025-10-12 14:55:13 +00:00
std::vector<class Entity*> entities_;
OEScene* scene_{ nullptr };
class Timestep* timestep_{ nullptr };
class LampStatus* lampStatus_{ nullptr };
class Entity* trackedEntity_{ nullptr };
2025-10-12 14:14:16 +00:00
// Stored as file entries under workspace dir, keyed by type
std::map<FileEntryType, std::vector<FileEntry>> files_;
2025-10-20 18:17:40 +00:00
// Chart data storage
QList<FileTypeData> fileTypeData_;
2025-10-12 14:55:13 +00:00
// Monotonic sequence for file entries changes, used to trigger UI refresh
std::uint64_t filesSeq_{ 0 };
2025-10-13 00:20:53 +00:00
// Executor for command XML actions
std::unique_ptr<CommandManager> cmdMgr_;
2025-10-12 14:55:13 +00:00
public:
std::uint64_t GetFilesSeq() const { return filesSeq_; }
2025-07-05 04:07:30 +00:00
friend class WorkSpaceXMLWrite;
2025-10-14 16:41:12 +00:00
friend class WorkSpaceXMLParse;
2025-01-04 04:12:51 +00:00
};