|
|
|
|
|
#include "nmDataRegion.h"
|
|
|
|
|
|
#include "nmDataRegionMark.h"
|
|
|
|
|
|
|
|
|
|
|
|
nmDataRegion::nmDataRegion(){
|
|
|
|
|
|
m_regionMarkData = nullptr;
|
|
|
|
|
|
m_regionFlowModel = nmDataAttribute("Region flow model", "Leaky","", UNIT_TYPE_DIMENSIONLESS, QStringList() << "Leaky" << "Composite limit", QStringList());
|
|
|
|
|
|
m_regionLeakage = nmDataAttribute("Region leakage", 1.0,"", UNIT_TYPE_DIMENSIONLESS, QStringList(), QStringList());
|
|
|
|
|
|
|
|
|
|
|
|
// 图元可见性,默认为true
|
|
|
|
|
|
m_bPlotVisible = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nmDataRegion::nmDataRegion(const nmDataRegion& other){
|
|
|
|
|
|
*this = other; // 使用赋值运算符实现
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nmDataRegion& nmDataRegion::operator=(const nmDataRegion& other) {
|
|
|
|
|
|
if (this != &other) {
|
|
|
|
|
|
// 拷贝基本类型和Qt对象(自动深拷贝)
|
|
|
|
|
|
m_sRegionName = other.m_sRegionName;
|
|
|
|
|
|
m_vecPts = other.m_vecPts;
|
|
|
|
|
|
m_regionFlowModel = other.m_regionFlowModel;
|
|
|
|
|
|
m_regionLeakage = other.m_regionLeakage;
|
|
|
|
|
|
|
|
|
|
|
|
// 处理指针成员 - 这里采用浅拷贝策略
|
|
|
|
|
|
// 因为nmDataRegionMark的生命周期由外部管理
|
|
|
|
|
|
m_regionMarkData = other.m_regionMarkData;
|
|
|
|
|
|
|
|
|
|
|
|
m_bPlotVisible = other.m_bPlotVisible;
|
|
|
|
|
|
}
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nmDataRegion::~nmDataRegion(){
|
|
|
|
|
|
if (m_regionMarkData != nullptr) {
|
|
|
|
|
|
m_regionMarkData = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 序列化 nmDataRegion 为 RapidJSON Value
|
|
|
|
|
|
rapidjson::Value nmDataRegion::ToJsonValue(rapidjson::Document::AllocatorType& allocator) const
|
|
|
|
|
|
{
|
|
|
|
|
|
// 创建一个 RapidJSON 对象类型的值
|
|
|
|
|
|
rapidjson::Value regionObject(rapidjson::kObjectType);
|
|
|
|
|
|
|
|
|
|
|
|
// 序列化名称
|
|
|
|
|
|
// 将 QString 转换为 UTF-8 编码的 C 字符串,并添加到 JSON 中
|
|
|
|
|
|
regionObject.AddMember("RegionName", rapidjson::Value(m_sRegionName.toStdString().c_str(), allocator).Move(), allocator);
|
|
|
|
|
|
|
|
|
|
|
|
// 序列化点 (m_vecPts)
|
|
|
|
|
|
rapidjson::Value pointsArray(rapidjson::kArrayType); // 创建一个 RapidJSON 数组类型的值
|
|
|
|
|
|
foreach (const QPointF& point , m_vecPts) {
|
|
|
|
|
|
rapidjson::Value pointObject(rapidjson::kObjectType); // 创建一个点对象
|
|
|
|
|
|
pointObject.AddMember("x", point.x(), allocator); // 添加x坐标
|
|
|
|
|
|
pointObject.AddMember("y", point.y(), allocator); // 添加y坐标
|
|
|
|
|
|
pointsArray.PushBack(pointObject, allocator); // 将点对象推入数组
|
|
|
|
|
|
}
|
|
|
|
|
|
regionObject.AddMember("RegionPoints", pointsArray, allocator); // 将点数组添加到JSON对象
|
|
|
|
|
|
|
|
|
|
|
|
// 序列化 nmDataAttribute 类型的成员
|
|
|
|
|
|
// 调用 nmDataAttribute 自身的 ToJsonValue 方法进行递归序列化
|
|
|
|
|
|
regionObject.AddMember("RegionFlowModel", m_regionFlowModel.ToJsonValue(allocator), allocator);
|
|
|
|
|
|
regionObject.AddMember("RegionLeakage", m_regionLeakage.ToJsonValue(allocator), allocator);
|
|
|
|
|
|
|
|
|
|
|
|
// 序列化图元可见性 (m_bPlotVisible)
|
|
|
|
|
|
regionObject.AddMember("PlotVisible", m_bPlotVisible, allocator);
|
|
|
|
|
|
|
|
|
|
|
|
return regionObject; // 返回序列化后的 RapidJSON Value
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 从 RapidJSON Value 反序列化数据到 nmDataRegion
|
|
|
|
|
|
void nmDataRegion::FromJsonValue(const rapidjson::Value& jsonValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 反序列化名称
|
|
|
|
|
|
if (jsonValue.HasMember("RegionName") && jsonValue["RegionName"].IsString()) {
|
|
|
|
|
|
m_sRegionName = QString::fromUtf8(jsonValue["RegionName"].GetString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 反序列化点 (m_vecPts)
|
|
|
|
|
|
if (jsonValue.HasMember("RegionPoints") && jsonValue["RegionPoints"].IsArray()) {
|
|
|
|
|
|
m_vecPts.clear(); // 清空当前点列表
|
|
|
|
|
|
const rapidjson::Value& pointsArray = jsonValue["RegionPoints"]; // 获取点数组节点
|
|
|
|
|
|
// 遍历数组,将每个点对象反序列化到 m_vecPts
|
|
|
|
|
|
for (rapidjson::SizeType i = 0; i < pointsArray.Size(); ++i) {
|
|
|
|
|
|
if (pointsArray[i].IsObject() &&
|
|
|
|
|
|
pointsArray[i].HasMember("x") && pointsArray[i]["x"].IsDouble() &&
|
|
|
|
|
|
pointsArray[i].HasMember("y") && pointsArray[i]["y"].IsDouble()) {
|
|
|
|
|
|
m_vecPts.append(QPointF(pointsArray[i]["x"].GetDouble(), pointsArray[i]["y"].GetDouble()));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 反序列化 nmDataAttribute 类型的成员
|
|
|
|
|
|
// 调用 nmDataAttribute 自身的 FromJsonValue 方法进行递归反序列化
|
|
|
|
|
|
if (jsonValue.HasMember("RegionFlowModel") && jsonValue["RegionFlowModel"].IsObject()) {
|
|
|
|
|
|
m_regionFlowModel.FromJsonValue(jsonValue["RegionFlowModel"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (jsonValue.HasMember("RegionLeakage") && jsonValue["RegionLeakage"].IsObject()) {
|
|
|
|
|
|
m_regionLeakage.FromJsonValue(jsonValue["RegionLeakage"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 反序列化图元可见性 (m_bPlotVisible)
|
|
|
|
|
|
if (jsonValue.HasMember("PlotVisible") && jsonValue["PlotVisible"].IsBool()) {
|
|
|
|
|
|
m_bPlotVisible = jsonValue["PlotVisible"].GetBool();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString nmDataRegion::getRegoinName() const {
|
|
|
|
|
|
return m_sRegionName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmDataRegion::setRegionName(QString sRegionName) {
|
|
|
|
|
|
m_sRegionName = sRegionName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVector<QPointF> nmDataRegion::getVecPts() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_vecPts;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmDataRegion::setVecPts(const QVector<QPointF>& vecPts)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_vecPts = vecPts;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Getter and Setter for m_regionFlowModel
|
|
|
|
|
|
nmDataAttribute& nmDataRegion::getRegionFlowModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_regionFlowModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmDataRegion::setRegionFlowModel(const nmDataAttribute& regionFlowModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_regionFlowModel = regionFlowModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Getter and Setter for m_regionLeakage
|
|
|
|
|
|
nmDataAttribute& nmDataRegion::getRegionLeakage()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_regionLeakage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmDataRegion::setRegionLeakage(const nmDataAttribute& regionLeakage)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_regionLeakage = regionLeakage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Getter and Setter for m_regionMarkData
|
|
|
|
|
|
nmDataRegionMark* nmDataRegion::getRegionMarkData() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_regionMarkData;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmDataRegion::setRegionMarkData(nmDataRegionMark* regionMarkData)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_regionMarkData = regionMarkData;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool nmDataRegion::getPlotVisible() const{
|
|
|
|
|
|
return m_bPlotVisible;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmDataRegion::setPlotVisible(const bool newState) {
|
|
|
|
|
|
m_bPlotVisible = newState;
|
|
|
|
|
|
}
|