468 lines
14 KiB
C++
468 lines
14 KiB
C++
|
#pragma execution_character_set("utf-8")
|
|||
|
#include "UIFunctionBase.h"
|
|||
|
#include <QFileDialog>
|
|||
|
#include <QApplication>
|
|||
|
#include <QWidget>
|
|||
|
#include <QObject>
|
|||
|
#include <QFile>
|
|||
|
#include "Logger.h"
|
|||
|
#include "qmessagebox.h"
|
|||
|
|
|||
|
StabilityModel *UIFunctionBase::m_pStabilityModer = nullptr;
|
|||
|
StructureModel *UIFunctionBase::m_pStructureModer = nullptr;
|
|||
|
CertiModel* UIFunctionBase::m_pCertiModer = nullptr;
|
|||
|
|
|||
|
#define BIND(func) std::bind(&UIFunctionBase::func, this, std::placeholders::_1)
|
|||
|
|
|||
|
UIFunctionBase::UIFunctionBase()
|
|||
|
{
|
|||
|
m_pStabilityModer = nullptr;
|
|||
|
getStabilityModelPtr();
|
|||
|
m_pStructureModer = nullptr;
|
|||
|
getStructureModelPtr();
|
|||
|
m_pCertiModer = nullptr;
|
|||
|
getCertiModelPtr();
|
|||
|
|
|||
|
ccsMessageHandle::instance()->register_callback(BIND(update_2d_json), CMD_update_2d);
|
|||
|
ccsMessageHandle::instance()->register_callback(BIND(cmd_update_ui_state), CMD_update_ui_state);
|
|||
|
|
|||
|
LOG_DEBUG("UIFunctionBase Constructed");
|
|||
|
}
|
|||
|
|
|||
|
void UIFunctionBase::reSetStabilityModel()
|
|||
|
{
|
|||
|
|
|||
|
StabilityModel::destroy();
|
|||
|
m_pStabilityModer = nullptr;
|
|||
|
getStabilityModelPtr();
|
|||
|
}
|
|||
|
|
|||
|
void UIFunctionBase::reSetStructureModel()
|
|||
|
{
|
|||
|
|
|||
|
StructureModel::destroy();
|
|||
|
m_pStructureModer = nullptr;
|
|||
|
getStructureModelPtr();
|
|||
|
}
|
|||
|
|
|||
|
void UIFunctionBase::reSetCertiModel()
|
|||
|
{
|
|||
|
|
|||
|
CertiModel::destroy();
|
|||
|
m_pCertiModer = nullptr;
|
|||
|
getCertiModelPtr();
|
|||
|
}
|
|||
|
|
|||
|
UIFunctionBase::~UIFunctionBase()
|
|||
|
{
|
|||
|
StabilityModel::destroy();
|
|||
|
m_pStabilityModer = nullptr;
|
|||
|
|
|||
|
StructureModel::destroy();
|
|||
|
m_pStructureModer = nullptr;
|
|||
|
|
|||
|
ccsMessageHandle::instance()->unregister_callback(CMD_update_2d);
|
|||
|
ccsMessageHandle::instance()->unregister_callback(CMD_update_ui_state);
|
|||
|
LOG_DEBUG("UIFunctionBase Destroyed");
|
|||
|
}
|
|||
|
|
|||
|
void UIFunctionBase::from(const json &j)
|
|||
|
{
|
|||
|
}
|
|||
|
void UIFunctionBase::to(json)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
StabilityModel *UIFunctionBase::getStabilityModelPtr()
|
|||
|
{
|
|||
|
|
|||
|
m_pStabilityModer = StabilityModel::getStabilityModelInstance();
|
|||
|
|
|||
|
return m_pStabilityModer;
|
|||
|
}
|
|||
|
|
|||
|
StructureModel *UIFunctionBase::getStructureModelPtr()
|
|||
|
{
|
|||
|
|
|||
|
m_pStructureModer = StructureModel::getStructureModelInstance();
|
|||
|
|
|||
|
return m_pStructureModer;
|
|||
|
}
|
|||
|
|
|||
|
CertiModel* UIFunctionBase::getCertiModelPtr()
|
|||
|
{
|
|||
|
m_pCertiModer = CertiModel::getCertiModelInstance();
|
|||
|
return m_pCertiModer;
|
|||
|
}
|
|||
|
|
|||
|
int UIFunctionBase::open_select_file_dlg(QString &outSelectFilePath, QString &outFileName, QString strfilter)
|
|||
|
{
|
|||
|
QString filefilter = strfilter;
|
|||
|
|
|||
|
const QString defaultPath = PathUtil::get_default_path(); // <20>滻Ϊ<E6BBBB><CEAA><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>Ĭ<EFBFBD><C4AC>·<EFBFBD><C2B7>
|
|||
|
|
|||
|
QString defaultPath_tmp = "/opt";
|
|||
|
|
|||
|
#ifdef _WIN32
|
|||
|
defaultPath_tmp = defaultPath;
|
|||
|
#else
|
|||
|
|
|||
|
#endif //_WIN32
|
|||
|
|
|||
|
// <20><><EFBFBD>ļ<EFBFBD><C4BC>Ի<EFBFBD><D4BB><EFBFBD>
|
|||
|
QString fileName = QFileDialog::getOpenFileName(
|
|||
|
nullptr, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
QObject::tr("open"), // <20><><EFBFBD><EFBFBD>
|
|||
|
defaultPath_tmp, // Ĭ<><C4AC>·<EFBFBD><C2B7>
|
|||
|
QObject::tr(filefilter.toStdString().c_str()) // <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
);
|
|||
|
|
|||
|
if (fileName.isEmpty())
|
|||
|
{
|
|||
|
return EXECUTE_FAIL;
|
|||
|
}
|
|||
|
|
|||
|
if (!fileName.isEmpty())
|
|||
|
{
|
|||
|
// 获取文件的完整路径
|
|||
|
QFileInfo fileInfo(fileName);
|
|||
|
QString filePath = fileInfo.filePath(); // 完整路径
|
|||
|
QString fileNameOnly = fileInfo.fileName(); // 完整文件名(包括扩展名)
|
|||
|
|
|||
|
outSelectFilePath = filePath;
|
|||
|
outFileName = fileNameOnly;
|
|||
|
}
|
|||
|
|
|||
|
return EXECUTE_SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
int UIFunctionBase::open_save_as_dlg(QString &outSelectFilePath, QString outFileFitle)
|
|||
|
{
|
|||
|
|
|||
|
QString fileName = QFileDialog::getSaveFileName(nullptr, "另存为", "", outFileFitle);
|
|||
|
|
|||
|
if (fileName.isEmpty())
|
|||
|
{
|
|||
|
QMessageBox::warning(nullptr, "文件保存", "请选择文件保存路径");
|
|||
|
return SYSTEM_ERROR;
|
|||
|
}
|
|||
|
// 如果用户选择了文件
|
|||
|
if (!fileName.isEmpty())
|
|||
|
{
|
|||
|
QFile file(fileName);
|
|||
|
if (file.exists())
|
|||
|
{
|
|||
|
QMessageBox::warning(nullptr, "文件保存", "文件已保存:" + fileName);
|
|||
|
return SYSTEM_ERROR;
|
|||
|
}
|
|||
|
}
|
|||
|
outSelectFilePath = fileName;
|
|||
|
return EXECUTE_SUCCESS;
|
|||
|
}
|
|||
|
|
|||
|
void UIFunctionBase::addShowWindowsLog(QString strLog)
|
|||
|
{
|
|||
|
StabilityModel::getStabilityModelInstance()->addShowWindowsLog(strLog);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
int UIFunctionBase::command_stream_modeling_async(std::string cmdstring)
|
|||
|
{
|
|||
|
bool bRet = false;
|
|||
|
bool bFind = false;
|
|||
|
vector<string> all_commandLines = CommandStreamProcessing::SplitToSingleCommand(cmdstring);
|
|||
|
|
|||
|
if (all_commandLines.size() == 0)
|
|||
|
{
|
|||
|
return 0;
|
|||
|
}
|
|||
|
for (auto strCommand : all_commandLines)
|
|||
|
{
|
|||
|
//single command
|
|||
|
e_modeling_operate_type commandType = CommandStreamProcessing::getSingleCommandType(strCommand);
|
|||
|
|
|||
|
switch (commandType)
|
|||
|
{
|
|||
|
case e_modeling_operate_POINT:
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->create_point(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_PARABOLA:
|
|||
|
case e_modeling_operate_ELLIPSE:
|
|||
|
case e_modeling_operate_CURVE:
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->create_line(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_SURF:
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->create_surface(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_SOLID:
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->create_solid(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_SPACEUNIT:
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->create_unit_and_space(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_HULL:
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->create_Hull(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_APPENDAGE:
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->create_Appendage(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_PROP: //obj 显隐
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->setObjVisible(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_COPY: //复制
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->cmd_copy(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_TRIM: //剪切
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->cmd_trim(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_MIRROR: //镜像
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->cmd_mirror(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_INTERSECT: //求交
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->cmd_intersection(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_JOIN: //拼接
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->cmd_join(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_DELETE: //拼接
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->cmd_delete(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case e_modeling_operate_REGENCMD:
|
|||
|
{
|
|||
|
bFind = true;
|
|||
|
QString outJsonData = "";
|
|||
|
bRet = StabilityModel::getStabilityModelInstance()->cmd_tool_show_obj_command(strCommand, outJsonData);
|
|||
|
if (bRet)
|
|||
|
{
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_3d, EXECUTE_SUCCESS, "update_ok", outJsonData);
|
|||
|
//emit update3dFunction(outJsonData);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if (!bFind)
|
|||
|
{
|
|||
|
QString strcmd = "过滤命令:" + QString::fromStdString(strCommand) + PathUtil::getEndMark();
|
|||
|
strcmd += PathUtil::getLogEndLine();
|
|||
|
StabilityModel::getStabilityModelInstance()->addShowWindowsLog(strcmd);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
StabilityModel::getStabilityModelInstance()->autoAddExecutingCmdID();
|
|||
|
update_ui_state();
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
void UIFunctionBase::update_2d_json(const QString &message)
|
|||
|
{
|
|||
|
QString msg = "";
|
|||
|
QString data = "";
|
|||
|
int errorCode = EXECUTE_SUCCESS;
|
|||
|
|
|||
|
json outjson = json::object();
|
|||
|
m_pStructureModer->update2dToJson(outjson);
|
|||
|
|
|||
|
data = QString::fromStdString(outjson.dump());
|
|||
|
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_2d, errorCode, msg, data);
|
|||
|
}
|
|||
|
|
|||
|
void UIFunctionBase::cmd_update_ui_state(const QString& message)
|
|||
|
{
|
|||
|
update_ui_state();
|
|||
|
}
|
|||
|
void UIFunctionBase::update_ui_state()
|
|||
|
{
|
|||
|
QString outjson = StabilityModel::getStabilityModelInstance()->getUpdate_UI_StateJson();
|
|||
|
|
|||
|
QtToWebFunction::getInstance().qt2web(CMD_update_ui_state, EXECUTE_SUCCESS, "", outjson);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void UIFunctionBase::setCurentUsingFilePath(QString path)
|
|||
|
{
|
|||
|
StabilityModel::getStabilityModelInstance()->setCurentUsingFilePath(path);
|
|||
|
}
|
|||
|
|
|||
|
QString UIFunctionBase::getCurentUsingFilePath()
|
|||
|
{
|
|||
|
return StabilityModel::getStabilityModelInstance()->getCurentUsingFilePath();
|
|||
|
}
|
|||
|
|
|||
|
bool UIFunctionBase::getMessageString(const QString& message, std::string& cmdstring, QString& outLog, bool& isCancel)
|
|||
|
{
|
|||
|
QString outMsg;
|
|||
|
if (message.isEmpty())
|
|||
|
{
|
|||
|
outMsg = "传入json为空!";
|
|||
|
return false;
|
|||
|
}
|
|||
|
nlohmann::json myjson;
|
|||
|
try
|
|||
|
{
|
|||
|
myjson = nlohmann::json::parse(message.toStdString());
|
|||
|
}
|
|||
|
catch (const nlohmann::json::parse_error& e)
|
|||
|
{
|
|||
|
outMsg = e.what();
|
|||
|
return false;
|
|||
|
}
|
|||
|
if (!myjson.contains("data"))
|
|||
|
{
|
|||
|
outMsg = "传入json出错!";
|
|||
|
return false;
|
|||
|
}
|
|||
|
if (myjson["data"].is_array())
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
cmdstring = myjson["data"].get<string>();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
if (myjson.contains("cancel"))
|
|||
|
{
|
|||
|
isCancel = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
isCancel = false;
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|