|
|
#include "nmDataOutline.h"
|
|
|
#include "nmDataJsonTools.h"
|
|
|
|
|
|
// Constructor
|
|
|
nmDataOutline::nmDataOutline()
|
|
|
: m_sName()
|
|
|
, m_vecPts()
|
|
|
, m_vFlowTypeList()
|
|
|
, m_eOutlineType(NM_Rect_Outline_Type)
|
|
|
, m_ptCenter()
|
|
|
, m_dRadius(0.0)
|
|
|
, m_bPlotVisible(true)
|
|
|
{
|
|
|
// 图元可见性,默认为true
|
|
|
}
|
|
|
|
|
|
nmDataOutline::nmDataOutline(const nmDataOutline& other) {
|
|
|
*this = other;
|
|
|
}
|
|
|
|
|
|
nmDataOutline& nmDataOutline::operator=(const nmDataOutline& other) {
|
|
|
if (this != &other) {
|
|
|
m_dRadius = other.m_dRadius;
|
|
|
m_vecPts = other.m_vecPts;
|
|
|
m_vFlowTypeList = other.m_vFlowTypeList;
|
|
|
m_eOutlineType = other.m_eOutlineType;
|
|
|
m_ptCenter = other.m_ptCenter;
|
|
|
m_sName = other.m_sName;
|
|
|
|
|
|
m_bPlotVisible = other.m_bPlotVisible;
|
|
|
}
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
|
// Destructor
|
|
|
nmDataOutline::~nmDataOutline() {
|
|
|
}
|
|
|
|
|
|
// 序列化 nmDataOutline 为 RapidJSON Value
|
|
|
rapidjson::Value nmDataOutline::ToJsonValue(rapidjson::Document::AllocatorType& allocator) const
|
|
|
{
|
|
|
// 创建一个 RapidJSON 对象类型的值
|
|
|
rapidjson::Value outlineObject(rapidjson::kObjectType);
|
|
|
|
|
|
// 序列化名称
|
|
|
// 将 QString 转换为 UTF-8 编码的 C 字符串,并添加到 JSON 中
|
|
|
outlineObject.AddMember("OutlineName", rapidjson::Value(m_sName.toStdString().c_str(), allocator).Move(), allocator);
|
|
|
|
|
|
// 序列化点
|
|
|
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); // 将点对象推入数组
|
|
|
}
|
|
|
outlineObject.AddMember("OutlinePoints", pointsArray, allocator); // 将点数组添加到JSON对象
|
|
|
|
|
|
// 边界压力类型列表
|
|
|
rapidjson::Value flowArry(rapidjson::kArrayType);
|
|
|
for (int i = 0; i < m_vFlowTypeList.size(); ++i) {
|
|
|
flowArry.PushBack(m_vFlowTypeList[i], allocator);
|
|
|
}
|
|
|
outlineObject.AddMember("FlowTypeList", flowArry, allocator);
|
|
|
|
|
|
// 边界类型(枚举转 int)
|
|
|
outlineObject.AddMember("OutlineType", static_cast<int>(m_eOutlineType), allocator);
|
|
|
|
|
|
// 如果是圆形,写入 Center 和 Radius
|
|
|
if (m_eOutlineType == NM_Data_Outline_Type::NM_Round_Outline_Type) {
|
|
|
rapidjson::Value cen(rapidjson::kObjectType);
|
|
|
cen.AddMember("x", m_ptCenter.x(), allocator);
|
|
|
cen.AddMember("y", m_ptCenter.y(), allocator);
|
|
|
outlineObject.AddMember("Center", cen, allocator);
|
|
|
|
|
|
outlineObject.AddMember("Radius", m_dRadius, allocator);
|
|
|
}
|
|
|
|
|
|
// 序列化图元可见性 (m_bPlotVisible)
|
|
|
outlineObject.AddMember("PlotVisible", m_bPlotVisible, allocator); // 使用m_bPlotVisible
|
|
|
|
|
|
return outlineObject; // 返回序列化后的 RapidJSON Value
|
|
|
}
|
|
|
|
|
|
// 从 RapidJSON Value 反序列化数据到 nmDataOutline
|
|
|
void nmDataOutline::FromJsonValue(const rapidjson::Value& jsonValue)
|
|
|
{
|
|
|
// 名称
|
|
|
if (jsonValue.HasMember("Name") && jsonValue["Name"].IsString()) {
|
|
|
m_sName = QString::fromUtf8(jsonValue["Name"].GetString());
|
|
|
}
|
|
|
|
|
|
// 反序列化点
|
|
|
if (jsonValue.HasMember("OutlinePoints") && jsonValue["OutlinePoints"].IsArray()) {
|
|
|
m_vecPts.clear(); // 清空当前点列表,使用m_vecPts
|
|
|
const rapidjson::Value& pointsArray = jsonValue["OutlinePoints"]; // 获取点数组节点
|
|
|
// 遍历数组,将每个点对象反序列化到 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()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 压力类型列表
|
|
|
if (jsonValue.HasMember("FlowTypeList") && jsonValue["FlowTypeList"].IsArray()) {
|
|
|
m_vFlowTypeList.clear();
|
|
|
const rapidjson::Value& flowArr = jsonValue["FlowTypeList"];
|
|
|
for (rapidjson::SizeType i = 0; i < flowArr.Size(); ++i) {
|
|
|
if (flowArr[i].IsInt()) {
|
|
|
m_vFlowTypeList.append(flowArr[i].GetInt());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 枚举类型
|
|
|
if (jsonValue.HasMember("OutlineType") && jsonValue["OutlineType"].IsInt()) {
|
|
|
m_eOutlineType = static_cast<NM_Data_Outline_Type>(jsonValue["OutlineType"].GetInt());
|
|
|
}
|
|
|
|
|
|
// 圆形专属字段
|
|
|
if (m_eOutlineType == NM_Data_Outline_Type::NM_Round_Outline_Type) {
|
|
|
if (jsonValue.HasMember("Center") && jsonValue["Center"].IsObject()) {
|
|
|
const rapidjson::Value& c = jsonValue["Center"];
|
|
|
if (c.HasMember("x") && c["x"].IsDouble() && c.HasMember("y") && c["y"].IsDouble()) {
|
|
|
m_ptCenter = QPointF( c["x"].GetDouble(), c["y"].GetDouble());
|
|
|
}
|
|
|
}
|
|
|
if (jsonValue.HasMember("Radius") && jsonValue["Radius"].IsNumber()) {
|
|
|
m_dRadius = jsonValue["Radius"].GetDouble();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 反序列化图元可见性 (m_bPlotVisible)
|
|
|
if (jsonValue.HasMember("PlotVisible") && jsonValue["PlotVisible"].IsBool()) {
|
|
|
m_bPlotVisible = jsonValue["PlotVisible"].GetBool(); // 使用m_bPlotVisible
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Getter and Setter for m_sName
|
|
|
QString nmDataOutline::getName() {
|
|
|
return m_sName;
|
|
|
}
|
|
|
|
|
|
void nmDataOutline::setName(const QString& sName) {
|
|
|
m_sName = sName;
|
|
|
}
|
|
|
|
|
|
// Getter and Setter for m_vecPts
|
|
|
QVector<QPointF> nmDataOutline::getOutlinePoints() {
|
|
|
return m_vecPts;
|
|
|
}
|
|
|
|
|
|
void nmDataOutline::setOutlinePoints(const QVector<QPointF>& vecPts) {
|
|
|
m_vecPts = vecPts;
|
|
|
}
|
|
|
|
|
|
QVector<int> nmDataOutline::getFlowTypeList() const {
|
|
|
return m_vFlowTypeList;
|
|
|
}
|
|
|
|
|
|
void nmDataOutline::setFlowTypeList(const QVector<int>& vecFlowTypeList) {
|
|
|
m_vFlowTypeList = vecFlowTypeList;
|
|
|
}
|
|
|
|
|
|
// Getter for m_eOutlineType
|
|
|
NM_Data_Outline_Type nmDataOutline::getOutlineType() const
|
|
|
{
|
|
|
return m_eOutlineType;
|
|
|
}
|
|
|
|
|
|
// Setter for m_eOutlineType
|
|
|
void nmDataOutline::setOutlineType(NM_Data_Outline_Type eOutlineType)
|
|
|
{
|
|
|
m_eOutlineType = eOutlineType;
|
|
|
}
|
|
|
|
|
|
// Getter for m_ptCenter
|
|
|
QPointF nmDataOutline::getCenter() const
|
|
|
{
|
|
|
return m_ptCenter;
|
|
|
}
|
|
|
|
|
|
// Setter for m_ptCenter
|
|
|
void nmDataOutline::setCenter(const QPointF& ptCenter)
|
|
|
{
|
|
|
m_ptCenter = ptCenter;
|
|
|
}
|
|
|
|
|
|
// Getter for m_dRadius
|
|
|
double nmDataOutline::getRadius() const
|
|
|
{
|
|
|
return m_dRadius;
|
|
|
}
|
|
|
|
|
|
// Setter for m_dRadius
|
|
|
void nmDataOutline::setRadius(double dRadius)
|
|
|
{
|
|
|
m_dRadius = dRadius;
|
|
|
}
|
|
|
|
|
|
bool nmDataOutline::getPlotVisible() const{
|
|
|
return m_bPlotVisible;
|
|
|
}
|
|
|
|
|
|
void nmDataOutline::setPlotVisible(const bool newState) {
|
|
|
m_bPlotVisible = newState;
|
|
|
}
|