COMPASSi/trunk/code/inc/DataManager/DataManagerInterface/include/DataCheck.h

198 lines
6.6 KiB
C
Raw Permalink Normal View History

2025-06-25 15:06:42 +08:00
#ifndef IDATACHECK_H
#define IDATACHECK_H
#include "nlohmann/json.hpp"
#include <unordered_set>
#include <QDebug>
#include <QRegularExpression>
// 稳性衡准标准
enum StabCrRule
{
CN_IS_2011 = 1, // 内法规2011
CN_IS_2015 = 2, // 内法规2015
CN_IS_2016 = 3, // 内法规2016
CN_IS_2018 = 4, // 内法规2018 //20190705 added by czb
CN_IS_2019 = 5, // 内法规2019 //20200428 by czbadded
CN_IB_2009 = 101, // 内河散化船法规2009
CN_IC_2009 = 201, // 内河液化船法规2009
CN_RS_2018 = 1001, // 特定航线江海直达2018 //20180701 added by czb
CN_OF_2019 = 2001, // 远洋渔船法规2019 //20201214 added by czb
};
// 模型数据检查 前端json
class DataCheck
{
public:
virtual std::string data_check(const nlohmann::json &j) = 0;
std::string check_basic_inf(const nlohmann::json &j);
std::string check_shell(const nlohmann::json &j);
std::string check_limit_static_point(const nlohmann::json &j);
std::string check_compartment(const nlohmann::json &j);
std::string check_case(const nlohmann::json &j);
std::string check_lwt(const nlohmann::json &j);
std::string check_partial_load(const nlohmann::json &j);
std::string check_partial_load_item(const nlohmann::json &j);
std::string check_wind(const nlohmann::json &j);
std::string check_cr_rule(const nlohmann::json &j);
std::string find_paramid_value(const nlohmann::json &j_array, const std::string &paramid);
public:
StabCrRule _CrRule = CN_IS_2016;
std::string seperator = ":;,  \t";
};
// 新增多分隔符分割函数支持类似C#的Split
static std::vector<std::string> SplitString(const std::string &str_in)
{
QString str = QString::fromStdString(str_in);
QStringList qStringList = str.split(QRegularExpression("[,;:\\s]+"), Qt::SkipEmptyParts);
std::vector<std::string> stdVector;
stdVector.reserve(qStringList.size());
for (const QString &str : qStringList)
{
stdVector.emplace_back(str.toUtf8().constData());
}
return stdVector;
};
enum ShipType
{
PassengerShip = 1,
DryCargoShip = 2,
Tanker = 3,
Tug = 4,
FireBoat = 5,
ContainerShip = 6,
CraneShip = 7,
Dredger = 8,
Pontoon = 9,
T_BulkcargoShip = 101, // 江海直达散货船
T_ContainerShip = 102, // 江海直达集装箱船
T_RoRoShip = 103, // 江海直达商品汽车滚装船
O_GeneralFisher = 201, // 远洋普通渔船
O_TrussTrawler = 202, // 远洋桁拖网渔船
O_NetFisher = 203, // 远洋罩网船
O_CageFisher = 204, // 远洋笼捕船
};
enum ChildShipType
{
None = 0,
LimitedPassengerShip = 101,
LijiangCruiseShip = 102, // 20200428 by czbadded 漓江游览船
HydrofoilShip = 111, // cqr-20190302 高速船,水翼船
AirCushionCraft = 112, // 全垫升气垫船
SurfaceEffectCraft = 113, // 水面效应船
BulkCementShip = 201,
OilRecoveryShip = 301, // 20200428 by czb, added 浮油回收船
RotatableArm_CraneShip = 701,
FixedArm_CraneShip = 702,
PilingShip = 703,
RotatableArm_SelfunloadingShip = 704,
CutterSuction_Dredger = 801, // 绞吸式挖泥船
TrailingSuction_Dredger = 802, // 耙吸式挖泥船
ChainBucket_Dredger = 803, // 链斗式挖泥船
Grab_Dredger = 804 // 抓斗式挖泥船
};
// 将ShipType枚举转换为字符串
static std::string ShipTypeToString(ShipType type)
{
static const std::unordered_map<ShipType, std::string> typeToString = {
{ShipType::PassengerShip, "PassengerShip"},
{ShipType::DryCargoShip, "DryCargoShip"},
{ShipType::Tanker, "Tanker"},
{ShipType::Tug, "Tug"},
{ShipType::FireBoat, "FireBoat"},
{ShipType::ContainerShip, "ContainerShip"},
{ShipType::CraneShip, "CraneShip"},
{ShipType::Dredger, "Dredger"},
{ShipType::Pontoon, "Pontoon"},
{ShipType::T_BulkcargoShip, "T_BulkcargoShip"},
{ShipType::T_ContainerShip, "T_ContainerShip"},
{ShipType::T_RoRoShip, "T_RoRoShip"},
{ShipType::O_GeneralFisher, "O_GeneralFisher"},
{ShipType::O_TrussTrawler, "O_TrussTrawler"},
{ShipType::O_NetFisher, "O_NetFisher"},
{ShipType::O_CageFisher, "O_CageFisher"}
};
auto it = typeToString.find(type);
if (it != typeToString.end()) {
return it->second;
}
return "UnknownShipType";
};
// 将ChildShipType枚举转换为字符串
static std::string ChildShipTypeToString(ChildShipType type)
{
static const std::unordered_map<ChildShipType, std::string> typeToString = {
{ChildShipType::None, "None"},
{ChildShipType::LimitedPassengerShip, "LimitedPassengerShip"},
{ChildShipType::LijiangCruiseShip, "LijiangCruiseShip"},
{ChildShipType::HydrofoilShip, "HydrofoilShip"},
{ChildShipType::AirCushionCraft, "AirCushionCraft"},
{ChildShipType::SurfaceEffectCraft, "SurfaceEffectCraft"},
{ChildShipType::BulkCementShip, "BulkCementShip"},
{ChildShipType::OilRecoveryShip, "OilRecoveryShip"},
{ChildShipType::RotatableArm_CraneShip, "RotatableArm_CraneShip"},
{ChildShipType::FixedArm_CraneShip, "FixedArm_CraneShip"},
{ChildShipType::PilingShip, "PilingShip"},
{ChildShipType::RotatableArm_SelfunloadingShip, "RotatableArm_SelfunloadingShip"},
{ChildShipType::CutterSuction_Dredger, "CutterSuction_Dredger"},
{ChildShipType::TrailingSuction_Dredger, "TrailingSuction_Dredger"},
{ChildShipType::ChainBucket_Dredger, "ChainBucket_Dredger"},
{ChildShipType::Grab_Dredger, "Grab_Dredger"}
};
auto it = typeToString.find(type);
if (it != typeToString.end()) {
return it->second;
}
return "UnknownChildShipType";
};
static const std::vector<std::string> LWTSumID = {"船体钢料汇总", "木作舾装汇总", "机电设备汇总", "固定压载汇总", "其他重量汇总", "空船汇总"};
static bool IsInLWTSumID(const std::string &id)
{
return std::find(LWTSumID.begin(), LWTSumID.end(), id) != LWTSumID.end();
}
static const std::vector<std::string> WindSumID = {"主甲板以下", "满实", "非满实", "全船"};
static bool IsInWindSumID(const std::string &id)
{
return std::find(WindSumID.begin(), WindSumID.end(), id) != WindSumID.end();
}
#include <sstream>
#include <iomanip> // 需要包含此头文件
static std::string to_precision_string(double value, int precision = 2)
{
std::ostringstream oss;
oss << std::fixed << std::setprecision(precision) << value;
return oss.str();
}
#endif