410 lines
12 KiB
C++
410 lines
12 KiB
C++
#pragma once
|
||
|
||
#include <QString>
|
||
#include <QColor>
|
||
#include "xml/tinyxml2.h"
|
||
|
||
enum class FileEntryType {
|
||
Curve,
|
||
Surface,
|
||
Table,
|
||
Light,
|
||
Polar,
|
||
Image
|
||
};
|
||
|
||
enum class ChartType {
|
||
Wave,
|
||
Report
|
||
};
|
||
|
||
inline const char* ChartTypeToString(ChartType t) {
|
||
switch (t) {
|
||
case ChartType::Wave: return "Wave";
|
||
case ChartType::Report: return "Report";
|
||
}
|
||
return "Wave";
|
||
}
|
||
|
||
inline bool ChartTypeFromString(const char* s, ChartType& out) {
|
||
if (!s) return false;
|
||
if (0 == strcmp(s, "Wave")) { out = ChartType::Wave; return true; }
|
||
if (0 == strcmp(s, "Report")) { out = ChartType::Report; return true; }
|
||
return false;
|
||
}
|
||
|
||
inline const char* FileEntryTypeToString(FileEntryType t) {
|
||
switch (t) {
|
||
case FileEntryType::Curve: return "curve";
|
||
case FileEntryType::Surface: return "surface";
|
||
case FileEntryType::Table: return "table";
|
||
case FileEntryType::Light: return "light";
|
||
case FileEntryType::Polar: return "polar";
|
||
case FileEntryType::Image: return "image";
|
||
}
|
||
return "unknown";
|
||
}
|
||
|
||
inline bool FileEntryTypeFromString(const char* s, FileEntryType& out) {
|
||
if (!s) return false;
|
||
if (0 == strcmp(s, "curve")) { out = FileEntryType::Curve; return true; }
|
||
if (0 == strcmp(s, "surface")) { out = FileEntryType::Surface; return true; }
|
||
if (0 == strcmp(s, "table")) { out = FileEntryType::Table; return true; }
|
||
if (0 == strcmp(s, "light")) { out = FileEntryType::Light; return true; }
|
||
if (0 == strcmp(s, "polar")) { out = FileEntryType::Polar; return true; }
|
||
if (0 == strcmp(s, "image")) { out = FileEntryType::Image; return true; }
|
||
return false;
|
||
}
|
||
|
||
class FileEntryCurve;
|
||
class FileEntryLight;
|
||
class FileEntrySurface;
|
||
class FileEntryTable;
|
||
class FileEntryPolar;
|
||
class FileEntryImage;
|
||
|
||
class FileEntry {
|
||
public:
|
||
virtual ~FileEntry() = default;
|
||
|
||
FileEntryType GetType() const { return type_; }
|
||
void SetType(FileEntryType type) { type_ = type; }
|
||
|
||
void SetPath(const QString& path);
|
||
QString GetPath() const { return path_; }
|
||
|
||
void SetFileNanme(const QString& fileNmae) { fileName_ = fileNmae; }
|
||
const QString& GetFileName() const { return fileName_; }
|
||
|
||
void SetName(const QString& name) { name_ = name; }
|
||
QString GetName() const { return name_; }
|
||
|
||
virtual FileEntryCurve* AsCurve() { return nullptr; }
|
||
virtual FileEntryLight* AsLight() { return nullptr; }
|
||
virtual FileEntrySurface* AsSurface() { return nullptr; }
|
||
virtual FileEntryTable* AsTable() { return nullptr; }
|
||
virtual FileEntryPolar* AsPolar() { return nullptr; }
|
||
virtual FileEntryImage* AsImage() { return nullptr; }
|
||
|
||
virtual bool ParseFiles(const tinyxml2::XMLElement* element) { return false; }
|
||
virtual bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) { return false; }
|
||
|
||
protected:
|
||
FileEntryType type_;
|
||
QString path_;
|
||
QString fileName_;
|
||
QString name_;
|
||
};
|
||
|
||
QString QColorToString(const QColor& color);
|
||
QColor StringToQColor(const QString& colorStr);
|
||
|
||
// Factory functions for creating FileEntry objects
|
||
std::shared_ptr<FileEntry> CreateFileEntry(FileEntryType type, const QString& filePath);
|
||
std::shared_ptr<FileEntryCurve> CreateFileEntryCurve(const QString& filePath);
|
||
std::shared_ptr<FileEntry> CreateFileEntrySurface(const QString& filePath);
|
||
std::shared_ptr<FileEntryTable> CreateFileEntryTable(const QString& filePath);
|
||
std::shared_ptr<FileEntryLight> CreateFileEntryLight(const QString& filePath);
|
||
std::shared_ptr<FileEntryPolar> CreateFileEntryPolar(const QString& filePath);
|
||
std::shared_ptr<FileEntryImage> CreateFileEntryImage(const QString& filePath);
|
||
|
||
// Factory functions for creating empty FileEntry objects (for XML parsing)
|
||
std::shared_ptr<FileEntry> CreateEmptyFileEntry(FileEntryType type);
|
||
std::shared_ptr<FileEntryCurve> CreateEmptyFileEntryCurve();
|
||
std::shared_ptr<FileEntry> CreateEmptyFileEntrySurface();
|
||
std::shared_ptr<FileEntryTable> CreateEmptyFileEntryTable();
|
||
std::shared_ptr<FileEntryLight> CreateEmptyFileEntryLight();
|
||
std::shared_ptr<FileEntryPolar> CreateEmptyFileEntryPolar();
|
||
std::shared_ptr<FileEntryImage> CreateEmptyFileEntryImage();
|
||
|
||
|
||
class FileEntryCurve : public FileEntry {
|
||
public:
|
||
struct ChartProperties {
|
||
ChartType chartType; // 新增:Chart类型
|
||
int xCount;
|
||
int yCount; // 对应XML的yCount
|
||
QString xTitle;
|
||
QString yTitle;
|
||
double xMin;
|
||
double xMax;
|
||
double yMin;
|
||
double yMax;
|
||
double timeParam; // 对应XML的t
|
||
};
|
||
|
||
struct CurveProperty {
|
||
QString name;
|
||
QColor color;
|
||
|
||
// Wave类型使用start/stop,Report类型使用x/y
|
||
union {
|
||
struct {
|
||
int start;
|
||
int stop;
|
||
} wave;
|
||
struct {
|
||
double x;
|
||
double y;
|
||
} report;
|
||
} data;
|
||
};
|
||
|
||
using CurveProperties = QList<CurveProperty>;
|
||
|
||
public:
|
||
FileEntryCurve() {
|
||
type_ = FileEntryType::Curve;
|
||
chartProperties_.chartType = ChartType::Wave; // 默认为Wave类型
|
||
}
|
||
|
||
void SetChartProperties(const ChartProperties& props) { chartProperties_ = props; }
|
||
const ChartProperties& GetChartProperties() const { return chartProperties_; }
|
||
|
||
void SetChartType(ChartType type) { chartProperties_.chartType = type; }
|
||
ChartType GetChartType() const { return chartProperties_.chartType; }
|
||
|
||
void AddCurveProperty(const CurveProperty& prop) { curveProperties_.append(prop); }
|
||
void RemoveCurveProperty(int index) { curveProperties_.removeAt(index); }
|
||
const CurveProperties& GetCurveProperties() const { return curveProperties_; }
|
||
|
||
FileEntryCurve* AsCurve() override { return this; }
|
||
|
||
// XML处理方法
|
||
bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) override;
|
||
bool ParseFiles(const tinyxml2::XMLElement* element) override;
|
||
|
||
private:
|
||
ChartProperties chartProperties_;
|
||
CurveProperties curveProperties_;
|
||
};
|
||
|
||
class FileEntrySurface : public FileEntry {
|
||
public:
|
||
struct ChartProperties {
|
||
int xCount;
|
||
int yCount; // Added missing yCount
|
||
int zCount; // Added missing zCount
|
||
QString xTitle;
|
||
QString yTitle;
|
||
QString zTitle;
|
||
double xMin;
|
||
double xMax;
|
||
double yMin;
|
||
double yMax;
|
||
double zMin;
|
||
double zMax;
|
||
double timeParam;
|
||
};
|
||
|
||
struct SurfaceProperty {
|
||
QString name;
|
||
QColor color;
|
||
int start;
|
||
int stop;
|
||
QString x;
|
||
QString y;
|
||
QString z;
|
||
};
|
||
|
||
using SurfaceProperties = QList<SurfaceProperty>;
|
||
|
||
public:
|
||
FileEntrySurface() { type_ = FileEntryType::Surface; }
|
||
|
||
// Chart properties management
|
||
void SetChartProperties(const ChartProperties& properties);
|
||
const ChartProperties& GetChartProperties() const;
|
||
|
||
// Surface properties management
|
||
void AddSurfaceProperty(const SurfaceProperty& surface);
|
||
void RemoveSurfaceProperty(int index);
|
||
void SetSurfaceProperty(int index, const SurfaceProperty& surface);
|
||
const SurfaceProperties& GetSurfaceProperties() const;
|
||
|
||
// Type conversion
|
||
FileEntrySurface* AsSurface() override;
|
||
|
||
// XML处理方法
|
||
bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) override;
|
||
bool ParseFiles(const tinyxml2::XMLElement* element) override;
|
||
|
||
private:
|
||
ChartProperties chartProperties_;
|
||
SurfaceProperties surfaceProperties_;
|
||
};
|
||
|
||
class FileEntryTable : public FileEntry {
|
||
public:
|
||
struct ChartProperties {
|
||
QString headerString;
|
||
double timeParam;
|
||
};
|
||
|
||
struct TableProperty {
|
||
QString name;
|
||
QColor color;
|
||
QList<int> datas;
|
||
};
|
||
|
||
using TableProperties = QList<TableProperty>;
|
||
|
||
public:
|
||
FileEntryTable() { type_ = FileEntryType::Table; }
|
||
|
||
// Chart properties management
|
||
void SetChartProperties(const ChartProperties& properties);
|
||
const ChartProperties& GetChartProperties() const;
|
||
|
||
// Table properties management
|
||
void AddTableProperty(const TableProperty& table);
|
||
void RemoveTableProperty(int index);
|
||
void SetTableProperty(int index, const TableProperty& table);
|
||
const TableProperties& GetTableProperties() const;
|
||
|
||
// Type conversion
|
||
FileEntryTable* AsTable() override;
|
||
|
||
// XML处理方法
|
||
bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) override;
|
||
bool ParseFiles(const tinyxml2::XMLElement* element) override;
|
||
|
||
private:
|
||
ChartProperties chartProperties_;
|
||
TableProperties tableProperties_;
|
||
};
|
||
|
||
class FileEntryLight : public FileEntry {
|
||
public:
|
||
struct ColorProperties {
|
||
QColor openColor;
|
||
QColor closeColor;
|
||
double timeParam;
|
||
};
|
||
|
||
struct LightRowProperty {
|
||
QStringList name;
|
||
QList<int> data;
|
||
};
|
||
|
||
using LightRowProperties = QList<LightRowProperty>;
|
||
|
||
public:
|
||
FileEntryLight() { type_ = FileEntryType::Light; }
|
||
|
||
void SetColorProperties(const ColorProperties& props) { colorProperties_ = props; }
|
||
const ColorProperties& GetColorProperties() const { return colorProperties_; }
|
||
|
||
void AddLightProperty(const LightRowProperty& prop) { lightProperties_.append(prop); }
|
||
void RemoveLightProperty(int index) { lightProperties_.removeAt(index); }
|
||
const LightRowProperties& GetLightProperties() const { return lightProperties_; }
|
||
|
||
FileEntryLight* AsLight() override { return this; }
|
||
|
||
bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) override;
|
||
bool ParseFiles(const tinyxml2::XMLElement* element) override;
|
||
|
||
private:
|
||
ColorProperties colorProperties_;
|
||
LightRowProperties lightProperties_;
|
||
};
|
||
|
||
class FileEntryPolar : public FileEntry {
|
||
public:
|
||
struct ChartProperties {
|
||
int AngularCount;
|
||
int RadialCount;
|
||
QString AngularTitle;
|
||
QString RadialTitle;
|
||
double AngularMin;
|
||
double AngularMax;
|
||
double RadialMin;
|
||
double RadialMax;
|
||
QString AngularUnit;
|
||
QString RadialUnit;
|
||
double timeParam; // 对应XML的t
|
||
};
|
||
|
||
struct LineProperty {
|
||
QString name;
|
||
QColor color;
|
||
int Angular;
|
||
int Radial;
|
||
};
|
||
|
||
using LineProperties = QList<LineProperty>;
|
||
|
||
public:
|
||
FileEntryPolar() { type_ = FileEntryType::Polar; }
|
||
|
||
// Chart properties management
|
||
void SetChartProperties(const ChartProperties& properties);
|
||
const ChartProperties& GetChartProperties() const;
|
||
|
||
// Line properties management
|
||
void AddLineProperty(const LineProperty& line);
|
||
void RemoveLineProperty(int index);
|
||
void SetLineProperty(int index, const LineProperty& line);
|
||
const LineProperties& GetLineProperties() const;
|
||
|
||
// Type conversion
|
||
FileEntryPolar* AsPolar() override;
|
||
|
||
// XML处理方法
|
||
bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) override;
|
||
bool ParseFiles(const tinyxml2::XMLElement* element) override;
|
||
|
||
private:
|
||
ChartProperties chartProperties_;
|
||
LineProperties lineProperties_;
|
||
};
|
||
|
||
class FileEntryImage : public FileEntry {
|
||
public:
|
||
struct ChartProperties {
|
||
int AngularCount;
|
||
int RadialCount;
|
||
QString AngularTitle;
|
||
QString RadialTitle;
|
||
double AngularMin;
|
||
double AngularMax;
|
||
double RadialMin;
|
||
double RadialMax;
|
||
QString AngularUnit;
|
||
QString RadialUnit;
|
||
double timeParam; // 对应XML的t
|
||
};
|
||
|
||
struct ImageProperty {
|
||
QString name;
|
||
QColor color;
|
||
int Angular;
|
||
int Radial;
|
||
};
|
||
|
||
using ImageProperties = QList<ImageProperty>;
|
||
|
||
public:
|
||
FileEntryImage() { type_ = FileEntryType::Image; }
|
||
|
||
// Chart properties management
|
||
void SetChartProperties(const ChartProperties& properties);
|
||
const ChartProperties& GetChartProperties() const;
|
||
|
||
// Line properties management
|
||
void AddImageProperty(const ImageProperty& image);
|
||
void RemoveImageProperty(int index);
|
||
void SetImageProperty(int index, const ImageProperty& image);
|
||
const ImageProperties& GetImageProperties() const;
|
||
|
||
// Type conversion
|
||
FileEntryImage* AsImage() override;
|
||
|
||
//// XML处理方法
|
||
//bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) override;
|
||
//bool ParseFiles(const tinyxml2::XMLElement* element) override;
|
||
|
||
private:
|
||
ChartProperties chartProperties_;
|
||
ImageProperties imageProperties_;
|
||
}; |