530 lines
18 KiB
C++
530 lines
18 KiB
C++
#pragma execution_character_set("utf-8")
|
|
#include "MenuUIFunction.h"
|
|
#include "Logger.h"
|
|
|
|
#define BIND(func) std::bind(&MenuUIFunction::func, this, std::placeholders::_1)
|
|
|
|
MenuUIFunction::MenuUIFunction():m_vRecentOpenFileObj(5)
|
|
{
|
|
ccsMessageHandle::instance()->register_callback(BIND(new_file), CMD_menu_files_new_file);
|
|
|
|
ccsMessageHandle::instance()->register_callback(BIND(update_3d_json), CMD_update_3d);
|
|
|
|
ccsMessageHandle::instance()->register_callback(BIND(open_file), CMD_menu_files_open_file);
|
|
ccsMessageHandle::instance()->register_callback(BIND(save_file), CMD_menu_files_save);
|
|
ccsMessageHandle::instance()->register_callback(BIND(save_as_file), CMD_menu_files_save_as);
|
|
ccsMessageHandle::instance()->register_callback(BIND(import_xls), CMD_menu_files_import_xls);
|
|
ccsMessageHandle::instance()->register_callback(BIND(import_xls_ok), CMD_menu_files_import_xls_ok);
|
|
|
|
ccsMessageHandle::instance()->register_callback(BIND(import_iges), CMD_menu_files_import_iges);
|
|
ccsMessageHandle::instance()->register_callback(BIND(import_iges_ok), CMD_menu_files_import_iges_ok);
|
|
|
|
ccsMessageHandle::instance()->register_callback(BIND(import_dxf), CMD_menu_files_import_dxf);
|
|
ccsMessageHandle::instance()->register_callback(BIND(import_ship), CMD_menu_files_import_ship);
|
|
|
|
ccsMessageHandle::instance()->register_callback(BIND(export_iges), CMD_menu_files_export_iges);
|
|
ccsMessageHandle::instance()->register_callback(BIND(export_iges_ok), CMD_menu_files_export_iges_ok);
|
|
|
|
ccsMessageHandle::instance()->register_callback(BIND(load_recent_file), CMD_menu_files_load_recent_file);
|
|
ccsMessageHandle::instance()->register_callback(BIND(init_recent_file_list), CMD_menu_files_init_recent_file_list);
|
|
ccsMessageHandle::instance()->register_callback(BIND(init_color_setting), CMD_menu_files_init_color_value);
|
|
|
|
setCurentUsingFilePath("");
|
|
QString configFile = PathUtil::bin_dir() + "config.ini";
|
|
m_vRecentOpenFileObj.loadFromFile(configFile);
|
|
|
|
|
|
LOG_DEBUG("MenuUIFunction Constructed");
|
|
}
|
|
|
|
MenuUIFunction::~MenuUIFunction()
|
|
{
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_new_file);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_update_3d);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_open_file);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_save);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_save_as);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_import_xls);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_import_xls_ok);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_import_iges);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_import_iges_ok);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_import_dxf);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_import_ship);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_export_iges);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_export_iges_ok);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_load_recent_file);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_init_recent_file_list);
|
|
ccsMessageHandle::instance()->unregister_callback(CMD_menu_files_init_color_value);
|
|
|
|
QString configFile = PathUtil::bin_dir() + "config.ini";
|
|
m_vRecentOpenFileObj.saveToFile(configFile);
|
|
|
|
|
|
|
|
LOG_DEBUG("MenuUIFunction Destroyed");
|
|
}
|
|
|
|
void MenuUIFunction::from(const json& j)
|
|
{
|
|
|
|
}
|
|
void MenuUIFunction::to(json)
|
|
{
|
|
|
|
}
|
|
|
|
void MenuUIFunction::new_file(const QString& message)
|
|
{
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
QString msg = "";
|
|
QString data = "";
|
|
reSetStabilityModel();
|
|
setCurentUsingFilePath("");
|
|
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_new_file, errorCode,msg, data);
|
|
|
|
update_ui_state();
|
|
}
|
|
|
|
|
|
void MenuUIFunction::update_3d_json(const QString& message)
|
|
{
|
|
QString msg = "";
|
|
QString data = "";
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
|
|
json outjson = json::object();
|
|
m_pStabilityModer->update3dToJson(outjson,E_GEO_3D_OBJ_TYPE_ALL,0);
|
|
|
|
data = QString::fromStdString(outjson.dump());
|
|
|
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, errorCode,msg, data);
|
|
}
|
|
|
|
json MenuUIFunction::createRecentFilesJson()
|
|
{
|
|
return m_vRecentOpenFileObj.toJson();
|
|
}
|
|
|
|
|
|
|
|
void MenuUIFunction::open_file(const QString& message)
|
|
{
|
|
LOG_INFO("json recv : {}", message.toStdString());
|
|
QString strSelectFilePath = "";
|
|
QString strSelectFileName = "";
|
|
QString msg = "";
|
|
QString data = "";
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
int iRet = open_select_file_dlg(strSelectFilePath,strSelectFileName);
|
|
if (iRet == EXECUTE_SUCCESS)
|
|
{
|
|
reSetStabilityModel();
|
|
m_pStabilityModer->readFile(XMLFile_Type_csx, strSelectFilePath);
|
|
m_vRecentOpenFileObj.addRecord(strSelectFilePath);
|
|
|
|
json result = m_vRecentOpenFileObj.toJson();
|
|
json resultOut = json::object();
|
|
resultOut["open_file"] = result;
|
|
data = QString::fromStdString(resultOut.dump());
|
|
|
|
msg = "加载完成";
|
|
QString strlog = strSelectFilePath + msg + PathUtil::getLogEndLine();
|
|
m_pStabilityModer->addShowWindowsLog(strlog);
|
|
|
|
setCurentUsingFilePath(strSelectFilePath);
|
|
|
|
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_open_file, errorCode,msg, data);
|
|
|
|
QString message_tmp = "";
|
|
update_3d_json(message_tmp);
|
|
}
|
|
else
|
|
{
|
|
msg = "加载失败";
|
|
QString strlog = strSelectFilePath + msg + PathUtil::getLogEndLine();
|
|
errorCode = EXECUTE_FAIL;
|
|
|
|
m_pStabilityModer->addShowWindowsLog(strlog);
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_open_file, errorCode,msg, data);
|
|
}
|
|
|
|
}
|
|
|
|
void MenuUIFunction::save_file(const QString& message)
|
|
{
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
QString msg = "";
|
|
QString data = "";
|
|
LOG_INFO("json recv : {}", message.toStdString());
|
|
bool bRet = true;
|
|
QString usingFilePath = getCurentUsingFilePath();
|
|
if(usingFilePath == "")
|
|
{
|
|
if(open_save_as_dlg(usingFilePath) != EXECUTE_SUCCESS)
|
|
{
|
|
bRet = false;
|
|
}
|
|
}
|
|
|
|
if(bRet)
|
|
{
|
|
m_pStabilityModer->saveFile(usingFilePath);
|
|
m_vRecentOpenFileObj.addRecord(usingFilePath);
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_save, errorCode,msg, data);
|
|
}
|
|
else
|
|
{
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_save, EXECUTE_FAIL,msg, data);
|
|
}
|
|
|
|
|
|
// LOG_INFO("json ret : {}", data.toStdString());
|
|
// LOG_INFO("json ret");
|
|
}
|
|
void MenuUIFunction::save_as_file(const QString& message)
|
|
{
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
QString msg = "";
|
|
QString data = "";
|
|
|
|
QString str_save_path = "";
|
|
int iRet = open_save_as_dlg(str_save_path);
|
|
if(iRet == EXECUTE_SUCCESS)
|
|
{
|
|
m_pStabilityModer->saveFile(str_save_path);
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_save_as, errorCode,"保存成功", data);
|
|
}
|
|
else
|
|
{
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_save_as, EXECUTE_FAIL,"保存失败", data);
|
|
}
|
|
}
|
|
void MenuUIFunction::import_xls(const QString& message)
|
|
{
|
|
QString strSelectFilePath = "";
|
|
QString strSelectFileName = "";
|
|
QString msg = "";
|
|
QString data = "";
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
|
|
//QString filefitle = "iges files(.iges);;igs files(*.igs)";
|
|
QString filefitle = "files(*.xlsx)";
|
|
int iRet = open_select_file_dlg(strSelectFilePath, strSelectFileName, filefitle);
|
|
if (iRet == EXECUTE_SUCCESS)
|
|
{
|
|
json file_menu_import = json::object();
|
|
json jret = json::object();
|
|
jret["file_path"] = strSelectFilePath.toStdString();
|
|
file_menu_import["file_menu_import_xls"] = jret;
|
|
data = QString::fromStdString(file_menu_import.dump());
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_import_xls, EXECUTE_SUCCESS, "选择文件成功", data);
|
|
}
|
|
else
|
|
{
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_import_xls, EXECUTE_FAIL, "选择文件失败", data);
|
|
}
|
|
}
|
|
|
|
void MenuUIFunction::import_xls_ok(const QString& message)
|
|
{
|
|
QString strSelectFilePath = "";
|
|
QString msg = "";
|
|
QString data = "";
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
nlohmann::json jsonData = nlohmann::json::parse(message.toStdString());
|
|
std::string strFilePath = "";
|
|
if (jsonData.contains("file_path"))
|
|
{
|
|
strFilePath = jsonData["file_path"];
|
|
}
|
|
|
|
int bCreate_wl = jsonData["create_wl"];
|
|
int bCreate_bl = jsonData["create_bl"];
|
|
double bfy = jsonData["bfy"];
|
|
|
|
ImportOffsetOption _option;
|
|
|
|
_option.setBfY(bfy);
|
|
_option.setCreateWL((bool)bCreate_wl);
|
|
_option.setCreateBL((bool)bCreate_bl);
|
|
|
|
m_pStabilityModer->setImportOffsetOption(_option);
|
|
m_pStabilityModer->readFile(XMLFile_Type_xls, QString::fromStdString(strFilePath));
|
|
|
|
std::vector<std::string>& vTransverseProfileCom = m_pStabilityModer->getTransverseProfile_commad();
|
|
std::vector<std::string>& vCamber_commad = m_pStabilityModer->getCamber_commad();
|
|
std::vector<std::string>& vLongitudinalProfile_commad = m_pStabilityModer->getLongitudinalProfile_commad();
|
|
std::vector<std::string>& vWaterLine_commad = m_pStabilityModer->getWaterLine_commad();
|
|
std::vector<std::string>& vSpaceLine_commad = m_pStabilityModer->getSpaceLine_commad();
|
|
|
|
std::string allCommand = "";
|
|
|
|
if (vTransverseProfileCom.size() > 0)
|
|
{
|
|
for (std::string& str : vTransverseProfileCom)
|
|
{
|
|
allCommand += str;
|
|
}
|
|
allCommand += PathUtil::getEndMark().toStdString();
|
|
}
|
|
|
|
|
|
if (vCamber_commad.size() > 0)
|
|
{
|
|
for (std::string& str : vCamber_commad)
|
|
{
|
|
allCommand += str;
|
|
}
|
|
allCommand += PathUtil::getEndMark().toStdString();
|
|
}
|
|
|
|
if (vLongitudinalProfile_commad.size() > 0)
|
|
{
|
|
for (std::string str : vLongitudinalProfile_commad)
|
|
{
|
|
allCommand += str;
|
|
}
|
|
allCommand += PathUtil::getEndMark().toStdString();
|
|
}
|
|
|
|
if (vWaterLine_commad.size() > 0)
|
|
{
|
|
for (std::string str : vWaterLine_commad)
|
|
{
|
|
allCommand += str;
|
|
}
|
|
allCommand += PathUtil::getEndMark().toStdString();
|
|
}
|
|
|
|
|
|
if (vSpaceLine_commad.size() > 0)
|
|
{
|
|
for (std::string str : vSpaceLine_commad)
|
|
{
|
|
allCommand += str;
|
|
}
|
|
allCommand += PathUtil::getEndMark().toStdString();
|
|
}
|
|
|
|
if (allCommand == "")
|
|
{
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_import_xls_ok, EXECUTE_FAIL, "加载失败", "");
|
|
}
|
|
else
|
|
{
|
|
std::thread t(&MenuUIFunction::command_stream_modeling_async, this, allCommand);
|
|
t.detach();
|
|
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_import_xls_ok, EXECUTE_SUCCESS, "加载成功", "");
|
|
}
|
|
|
|
|
|
|
|
}
|
|
void MenuUIFunction::import_iges(const QString& message)
|
|
{
|
|
QString strSelectFilePath = "";
|
|
QString strSelectFileName = "";
|
|
QString msg = "";
|
|
QString data = "";
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
|
|
// QString filefitle = "iges files(.iges);;igs files(*.igs)";
|
|
QString filefitle = "files(*.iges;*.igs)";
|
|
int iRet = open_select_file_dlg(strSelectFilePath, strSelectFileName, filefitle);
|
|
if (iRet == EXECUTE_SUCCESS)
|
|
{
|
|
json file_menu_import_iges = json::object();
|
|
json jret = json::object();
|
|
jret["file_path"] = strSelectFilePath.toStdString();
|
|
file_menu_import_iges["file_menu_import_iges"] = jret;
|
|
data = QString::fromStdString(file_menu_import_iges.dump());
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_import_iges, EXECUTE_SUCCESS, "选择文件成功", data);
|
|
}
|
|
else
|
|
{
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_import_iges, EXECUTE_FAIL, "选择文件失败", data);
|
|
}
|
|
}
|
|
|
|
void MenuUIFunction::import_iges_ok(const QString &message)
|
|
{
|
|
QString strSelectFilePath = "";
|
|
QString msg = "";
|
|
QString data = "";
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
nlohmann::json jsonData = nlohmann::json::parse(message.toStdString());
|
|
|
|
getStabilityModelPtr()->ImportIGES(jsonData);
|
|
|
|
json jret = json::object();
|
|
jret["imort_file_path"] = strSelectFilePath.toStdString();
|
|
|
|
data = QString::fromStdString(jret.dump());
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_import_iges_ok, EXECUTE_SUCCESS, "导入成功成功", data);
|
|
|
|
QString message_tmp = "";
|
|
update_3d_json(message_tmp);
|
|
}
|
|
|
|
void MenuUIFunction::export_iges(const QString &message)
|
|
{
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
QString msg = "";
|
|
QString data = "";
|
|
|
|
QString str_file_fitle = "IGES File(*.igs)";
|
|
QString str_save_path = "";
|
|
int iRet = open_save_as_dlg(str_save_path, str_file_fitle);
|
|
if (iRet == EXECUTE_SUCCESS)
|
|
{
|
|
json file_menu_export_iges = json::object();
|
|
json jret = json::object();
|
|
jret["file_path"] = str_save_path.toStdString();
|
|
file_menu_export_iges["file_menu_export_iges"] = jret;
|
|
data = QString::fromStdString(file_menu_export_iges.dump());
|
|
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_export_iges, errorCode, "保存成功", data);
|
|
}
|
|
else
|
|
{
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_export_iges, EXECUTE_FAIL, "保存失败", data);
|
|
}
|
|
}
|
|
|
|
void MenuUIFunction::export_iges_ok(const QString &message)
|
|
{
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
QString msg = "";
|
|
QString data = "";
|
|
|
|
nlohmann::json jsonData = nlohmann::json::parse(message.toStdString());
|
|
|
|
m_pStabilityModer->ExportIGES(jsonData);
|
|
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_export_iges_ok, errorCode, "保存成功", data);
|
|
}
|
|
|
|
void MenuUIFunction::import_dxf(const QString &message)
|
|
{
|
|
QString strSelectFilePath = "";
|
|
QString strSelectFileName = "";
|
|
QString msg = "";
|
|
QString data = "";
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
|
|
// QString filefitle = "iges files(.iges);;igs files(*.igs)";
|
|
QString filefitle = "CAD files(*.dxf)";
|
|
int iRet = open_select_file_dlg(strSelectFilePath, strSelectFileName, filefitle);
|
|
if (iRet == EXECUTE_SUCCESS)
|
|
{
|
|
getStabilityModelPtr()->ImportDXF(strSelectFilePath);
|
|
|
|
// data = QString::fromStdString(jret.dump());
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_import_dxf, EXECUTE_SUCCESS, "选择文件成功", data);
|
|
|
|
QString message_tmp = "";
|
|
update_3d_json(message_tmp);
|
|
}
|
|
else
|
|
{
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_import_dxf, EXECUTE_FAIL, "选择文件失败", data);
|
|
}
|
|
}
|
|
void MenuUIFunction::import_ship(const QString &message)
|
|
{
|
|
}
|
|
|
|
void MenuUIFunction::load_recent_file(const QString &message)
|
|
{
|
|
int errorCode = EXECUTE_FAIL;
|
|
QString msg = "";
|
|
QString data = "";
|
|
nlohmann::json jsonData = nlohmann::json::parse(message.toStdString());
|
|
|
|
if (jsonData.contains("path"))
|
|
{
|
|
QString filePath = PathUtil::jsonContainsKeyToQString(jsonData, "path");
|
|
m_pStabilityModer->readFile(XMLFile_Type_csx, filePath);
|
|
|
|
setCurentUsingFilePath(filePath);
|
|
errorCode = EXECUTE_SUCCESS;
|
|
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_load_recent_file, errorCode, msg, data);
|
|
|
|
QString message_tmp = "";
|
|
update_3d_json(message_tmp);
|
|
}
|
|
else
|
|
{
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_load_recent_file, errorCode, msg, data);
|
|
}
|
|
|
|
int a = 0;
|
|
}
|
|
|
|
void MenuUIFunction::init_recent_file_list(const QString &message)
|
|
{
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
QString msg = "";
|
|
QString data = "";
|
|
|
|
json result = m_vRecentOpenFileObj.toJson();
|
|
json resultOut = json::object();
|
|
resultOut["open_file"] = result;
|
|
data = QString::fromStdString(resultOut.dump());
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_init_recent_file_list, errorCode, msg, data);
|
|
}
|
|
|
|
void MenuUIFunction::init_color_setting(const QString &message)
|
|
{
|
|
int errorCode = EXECUTE_SUCCESS;
|
|
QString msg = "";
|
|
QString data = "";
|
|
|
|
bool isShowName[15] = {false};
|
|
int iColor[15] = {0};
|
|
|
|
for (int i = 0; i < 15; i++)
|
|
{
|
|
m_pStabilityModer->get3DObjColor(i, iColor[i], isShowName[i]);
|
|
int a = 0;
|
|
}
|
|
|
|
json resultOut = json::object();
|
|
|
|
resultOut["color_point3d"] = iColor[0]; // 点
|
|
resultOut["color_curve"] = iColor[1]; // 线
|
|
resultOut["color_surface"] = iColor[2]; // 面
|
|
resultOut["color_solid"] = iColor[3]; // 体
|
|
resultOut["color_maindecksurf"] = iColor[4]; // 主甲板
|
|
resultOut["color_shellsurf"] = iColor[5]; // 外板
|
|
resultOut["color_value6"] = iColor[6]; // 待定
|
|
resultOut["color_value7"] = iColor[7];
|
|
resultOut["color_value8"] = iColor[8];
|
|
resultOut["color_value9"] = iColor[9];
|
|
resultOut["color_space"] = iColor[10]; // 舱室
|
|
resultOut["color_appendage"] = iColor[11]; // 附体
|
|
resultOut["color_hull"] = iColor[12]; // 主船体
|
|
resultOut["color_backcolor"] = iColor[13]; // 背景色
|
|
resultOut["color_lightcolor"] = iColor[14]; // 高亮色
|
|
resultOut["show_point3d_name"] = isShowName[0]; // 0 不显示 1 显示 点名
|
|
resultOut["show_curve_name"] = isShowName[1]; // 0 不显示 1 显示 线名
|
|
resultOut["show_surface_name"] = isShowName[2]; // 0 不显示 1 显示 面名
|
|
resultOut["show_solid_name"] = isShowName[3]; // 0 不显示 1 显示 体名
|
|
resultOut["show_maindecksurf_name"] = isShowName[4]; // 0 不显示 1 显示 主甲板名
|
|
resultOut["show_shellsurf_name"] = isShowName[5]; // 0 不显示 1 显示 外板名
|
|
resultOut["show_value6_name"] = isShowName[6]; // 待定
|
|
resultOut["show_value7_name"] = isShowName[7];
|
|
resultOut["show_value8_name"] = isShowName[8];
|
|
resultOut["show_value9_name"] = isShowName[9];
|
|
resultOut["show_space_name"] = isShowName[10]; // 0 不显示 1 显示 舱室名
|
|
resultOut["show_appendage_name"] = isShowName[11]; // 0 不显示 1 显示 附体名
|
|
resultOut["show_hull_name"] = isShowName[12]; // 0 不显示 1 显示 主船体名
|
|
|
|
data = QString::fromStdString(resultOut.dump());
|
|
QtToWebFunction::getInstance().qt2web(CMD_menu_files_init_color_value, errorCode, msg, data);
|
|
}
|