#include "ObjectInterpreter.h" #include "../Infrastructure.Interface/Arithmetics/ChangeFSPos.h" #include #include #include #include "DataManager.h" #include "Constants.h" #include #include "DllImportOccModeling.h" #include "Geometry.h" ObjectInterpreter::ObjectInterpreter() { } void ObjectInterpreter::ExecuteCommand(std::vector &commandLines) { } int ObjectInterpreter::ParseBoolSymbolFromName(std::string &objName) { // // protected int PareseSolidName(ref string solidname) int solidandtype = 0; if(StringHelper::startsWith(objName,"+")) { objName = objName.substr(1); } else if (StringHelper::startsWith(objName,"-")) { // solidandtype = 1; objName = objName.substr(1); solidandtype = 1; } else if (StringHelper::startsWith(objName,"*")) { // solidandtype = 2; objName = objName.substr(1); solidandtype = 2; } if (!ValidSyntaxOfName(objName)) // 20170801 新增 by czb { throw std::runtime_error("名称不合法,请检查是否包含关键字等!"); } return solidandtype; } bool ObjectInterpreter::ParseName(IModel& o, std::string &objName, const std::string &commandLine) { id2DelOrReplace = -1; genNewID = false; int renameSrcID = -1; std::vector lineName = StringHelper::GetWords(commandLine); // 20180320 modified by czb //.toUpper().GetWords(); std::string name = ""; if (lineName.size() < 2) { { // // 生成名称流水号 add by yangchen 20151119 int i = 0; while (true) { // // 反复生成默认名称,直到不存在重名 name = GenerateObjectName(o) + std::to_string(++i); id2DelOrReplace = FindIDByName(name, true,typeid(o).name(), false); // int id2DelOrReplace1 = FindIDByNameFromInteract(name, true, o->GetType(), false); if (id2DelOrReplace == -1) { objName = name; return true; } } } } else { name = lineName[1]; // // 名称合法性验证,例如关键字冲突等 if (!ValidSyntaxOfName(name)) // 20170801 新增 by czb { throw std::runtime_error("名称不合法,请检查是否包含关键字等!"); } id2DelOrReplace = FindIDByName(name, true, typeid(o).name(), false); if (id2DelOrReplace == -2) { // // 重名图元不可被替换 return false; } else if (id2DelOrReplace == -1) { // // 无重名图元,名称可以使用 if (renameSrcID != -1) { id2DelOrReplace = renameSrcID; } } else { // if (renameSrcID != -1) // { // throw ErrorSyntaxException("存在不可替换的重名图元:" + name); // } // else // { // std::string stp = DataDictionary::TypeNameCnDic[Global::RootWorkItem::Services::Get>().GetObjectByID(id2DelOrReplace)->GetType()]; // if (AppSetting::Default->SameNameRule == 0) // 更新 // { // // // if (!o->GetType()->Equals(Global::RootWorkItem::Services::Get>().GetObjectByID(id2DelOrReplace)->GetType())) // { // throw ErrorSyntaxException("指定的对象名称" + name + "相同,但不是同一类型的对象,无法更新"); // } // } // else if (AppSetting::Default->SameNameRule == 1) // 放弃 // { // throw ErrorSyntaxException("命令放弃执行.\r\n存在重名图元:" + stp + "\"" + name + "\"" + "\r\n"); // } // else if (AppSetting::Default->SameNameRule == 2) // 询问 // { // // string strtext = "存在重名图元:" + stp + "\"" + name + "\",确定要覆盖吗?"; // // strtext += "\r" + "\r" + "如不需要重名弹窗提示,可在“工具”-“选项”-“系统设置”将“同名规则”设置为“更新对象”"; //cqr-20210304 增加提示 // // cqr-20210416 修改为在弹窗可直接设置同名规则 // std::string strtext = "存在重名图元:" + stp + "\"" + name + "\",是否要覆盖?"; // strtext += "\r" + "\r" + "如不需要重名弹窗提示,可点击“取消”设置为“直接覆盖,不再弹窗”"; // std::shared_ptr dr = MessageBox::Show(strtext, "图元重名", MessageBoxButtons::YesNoCancel, MessageBoxIcon::Warning, MessageBoxDefaultButton::Button3, MessageBoxOptions::ServiceNotification); // if (dr == DialogResult::No) // cqr-20210416 // { // throw ErrorSyntaxException("命令放弃执行.\r\n存在重名图元:" + stp + "\"" + name + "\"" + "\r\n"); // } // else // { // if (!o->GetType()->Equals(Global::RootWorkItem::Services::Get>().GetObjectByID(id2DelOrReplace)->GetType())) // { // throw ErrorSyntaxException("指定的对象名称" + name + "相同,但不是同一类型的对象,无法更新"); // } // if (dr == DialogResult::Cancel) // cqr-20210416 // { // AppSetting::Default->SameNameRule = 0; // 同名规则为更新 // } // } // } // } } // // 无重名图元或重名图元可被替换 objName = name; return true; } } bool ObjectInterpreter::ParseInputName(IModel &o, std::string &objName, const std::string &inputName) { id2DelOrReplace = -1; genNewID = false; int renameSrcID = -1; std::string name = ""; if (inputName.empty() || StringHelper::trim(inputName) == "") { ////// 未指定名称 // 生成名称流水号 int i = 0; while (true) { // 反复生成默认名称,直到不存在重名 name = GenerateObjectName(o) + std::to_string(++i); id2DelOrReplace = FindIDByName(name, true, typeid(o).name(), false); // int id2DelOrReplace1 = FindIDByNameFromInteract(name, true, o.GetType(), false); if (id2DelOrReplace == -1) { objName = name; return true; } } } else { //// 指定名称 name = inputName; // 名称合法性验证,例如关键字冲突等 if (!ValidSyntaxOfName(name)) { throw std::runtime_error("名称不合法:" + name); } id2DelOrReplace = FindIDByName(name, true, typeid(o).name()); if (id2DelOrReplace == -2) { // 重名图元不可被替换 return false; } else if (id2DelOrReplace == -1) { // 无重名图元,名称可以使用 if (renameSrcID != -1) { id2DelOrReplace = renameSrcID; } } // else // { // //// 有重名图元,则不可重命名 // if (renameSrcID != -1) // { // throw std::runtime_error("存在不可替换的重名图元:" + name); // } // else // { // std::string stp = TypeNameCn[typeid(DataManager::GetObjectByID(id2DelOrReplace)).name()]; // if (AppSetting::Default->SameNameRule == 0) // 更新 // { // if (!o->GetType()->Equals(Global::RootWorkItem::Services::Get>().GetObjectByID(id2DelOrReplace)->GetType())) // { // throw std::runtime_error("指定的对象名称" + name + "相同,但不是同一类型的对象,无法更新"); // } // } // else if (AppSetting::Default->SameNameRule == 1) // 放弃 // { // throw std::runtime_error("命令放弃执行.\r\n存在重名图元:" + stp + "\"" + name + "\"" + "\r\n"); // } // else if (AppSetting::Default->SameNameRule == 2) // 询问 // { // // string strtext = "存在重名图元:" + stp + "\"" + name + "\",确定要覆盖吗?"; // // strtext += "\r" + "\r" + "如不需要重名弹窗提示,可在“工具”-“选项”-“系统设置”将“同名规则”设置为“更新对象”"; //cqr-20210304 增加提示 // // cqr-20210416 修改为在弹窗可直接设置同名规则 // std::string strtext = "存在重名图元:" + stp + "\"" + name + "\",是否要覆盖?"; // strtext += "\r" + "\r" + "如不需要重名弹窗提示,可点击“取消”设置为“直接覆盖,不再弹窗”"; // std::shared_ptr dr = MessageBox::Show(strtext, "图元重名", MessageBoxButtons::YesNoCancel, MessageBoxIcon::Warning, MessageBoxDefaultButton::Button3, MessageBoxOptions::ServiceNotification); // if (dr == DialogResult::No) // cqr-20210416 // { // throw ErrorSyntaxException("命令放弃执行.\r\n存在重名图元:" + stp + "\"" + name + "\"" + "\r\n"); // } // else // { // if (!o->GetType()->Equals(Global::RootWorkItem::Services::Get>().GetObjectByID(id2DelOrReplace)->GetType())) // { // throw ErrorSyntaxException("指定的对象名称" + name + "相同,但不是同一类型的对象,无法更新"); // } // if (dr == DialogResult::Cancel) // cqr-20210416 // { // AppSetting::Default->SameNameRule = 0; // 同名规则为更新 // } // } // } // } // } // 无重名图元或重名图元可被替换 objName = name; return true; } } bool ObjectInterpreter::ParseInputName(std::string &objName, const std::string &inputName) { id2DelOrReplace = -1; genNewID = false; int renameSrcID = -1; std::string name; name = inputName; // 名称合法性验证 if (!ValidSyntaxOfName(name)) { throw std::runtime_error("名称不合法:" + name); } id2DelOrReplace = FindIDByName(name); // 查找是否存在相同名称 if (id2DelOrReplace == -2) { // 重名图元不可被替换 return false; } else if (id2DelOrReplace == -1) { // 无重名图元,名称可以使用 if (renameSrcID != -1) { id2DelOrReplace = renameSrcID; } } // else // { // if (renameSrcID != -1) // { // throw ErrorSyntaxException("存在不可替换的重名图元:" + name); // } // else // { // std::string stp = DataDictionary::TypeNameCnDic[Global::RootWorkItem->GetObjectByID(id2DelOrReplace)]; // if (AppSetting::SameNameRule == 0) // { // 更新 // // 更新逻辑,暂无操作 // } // else if (AppSetting::SameNameRule == 1) // { // 放弃 // throw ErrorSyntaxException("命令放弃执行.\n存在重名图元:" + stp + "\"" + name + "\"\n"); // } // else if (AppSetting::SameNameRule == 2) // { // 询问 // std::string strtext = "存在重名图元:" + stp + "\"" + name + "\",是否要覆盖?\n\n"; // strtext += "如不需要重名弹窗提示,可点击“取消”设置为“直接覆盖,不再弹窗”"; // DialogResult dr = MessageBox(strtext, "图元重名"); // if (dr == DialogResult::No) // { // throw ErrorSyntaxException("命令放弃执行.\n存在重名图元:" + stp + "\"" + name + "\"\n"); // } // else if (dr == DialogResult::Cancel) // { // AppSetting::SameNameRule = 0; // 更新规则 // } // } // } //} // 无重名图元或可替换图元 objName = name; return true; } bool ObjectInterpreter::ValidSyntaxOfName(const std::string& objName) { if (objName.empty()) return false; // 正则表达式匹配 std::regex regexPattern(R"(^[A-Za-z][A-Za-z0-9-_.]*$)"); if (!std::regex_match(objName, regexPattern)) { return false; } std::string upperName = StringHelper::toUpper(objName); // 将字符串转换为大写; if( std::find(CommandKeyWords.begin(), CommandKeyWords.end(), upperName) != CommandKeyWords.end()) { return false; } return true; } // bool ObjectInterpreter::ParseInputName(std::string &objName, const std::string &inputName) // { // id2DelOrReplace = -1; // genNewID = false; // int renameSrcID = -1; // std::string name = ""; // { // //// 指定名称 // name = inputName; // // 名称合法性验证,例如关键字冲突等 // if (!Statics::ValidSyntaxOfName(name)) // { // throw NameSyntaxErrorException(); // } // id2DelOrReplace = FindIDByName(name); //???存疑,有可能覆盖原有对象,并且不检查被覆盖的对象类型是否相同 // if (id2DelOrReplace == -2) // { // // 重名图元不可被替换 // return false; // } // else if (id2DelOrReplace == -1) // { // // 无重名图元,名称可以使用 // if (renameSrcID != -1) // { // id2DelOrReplace = renameSrcID; // } // } // else // { // //// 有重名图元,则不可重命名 // if (renameSrcID != -1) // { // throw ErrorSyntaxException("存在不可替换的重名图元:" + name); // } // else // { // std::string stp = DataDictionary::TypeNameCnDic[Global::RootWorkItem::Services::Get>().GetObjectByID(id2DelOrReplace)->GetType()]; // if (AppSetting::Default->SameNameRule == 0) // 更新 // { // } // else if (AppSetting::Default->SameNameRule == 1) // 放弃 // { // throw ErrorSyntaxException("命令放弃执行.\r\n存在重名图元:" + stp + "\"" + name + "\"" + "\r\n"); // } // else if (AppSetting::Default->SameNameRule == 2) // 询问 // { // // string strtext = "存在重名图元:" + stp + "\"" + name + "\",确定要覆盖吗?"; // // strtext += "\r" + "\r" + "如不需要重名弹窗提示,可在“工具”-“选项”-“系统设置”将“同名规则”设置为“更新对象”"; //cqr-20210304 增加提示 // // DialogResult dr = MessageBox.Show(strtext, "图元重名", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3, MessageBoxOptions.ServiceNotification); // // cqr-20210416 修改为在弹窗可直接设置同名规则 // std::string strtext = "存在重名图元:" + stp + "\"" + name + "\",是否要覆盖?"; // strtext += "\r" + "\r" + "如不需要重名弹窗提示,可点击“取消”设置为“直接覆盖,不再弹窗”"; // std::shared_ptr dr = MessageBox::Show(strtext, "图元重名", MessageBoxButtons::YesNoCancel, MessageBoxIcon::Warning, MessageBoxDefaultButton::Button3, MessageBoxOptions::ServiceNotification); // if (dr == DialogResult::No) // cqr-20210416 // { // throw ErrorSyntaxException("命令放弃执行.\r\n存在重名图元:" + stp + "\"" + name + "\"" + "\r\n"); // } // else // { // if (dr == DialogResult::Cancel) // cqr-20210416 // { // AppSetting::Default->SameNameRule = 0; // 同名规则为更新 // } // } // // if (dr == DialogResult.Cancel) // //{ // // throw new ErrorSyntaxException("命令放弃执行.\r\n存在重名图元:" + stp + "\"" + name + "\"" + "\r\n"); // // } // // else // //{ // // } // } // } // } // // 无重名图元或重名图元可被替换 // objName = name; // return true; // } // } std::string ObjectInterpreter::ParseNameMirror(IModel *o, const std::string &commandLine) { id2DelOrReplace = -1; genNewID = false; int renameSrcID = -1; std::vector lineName = StringHelper::GetWords(commandLine); std::vector lineNameU = StringHelper::GetWords(StringHelper::toUpper(commandLine)); if (std::find(lineNameU.begin(), lineNameU.end(), "RENAME") != lineNameU.end()) { auto it = std::find(lineNameU.begin(), lineNameU.end(), "RENAME"); size_t idx = std::distance(lineNameU.begin(), it); if (idx == lineName.size() - 1) { throw std::runtime_error("参数错误!"); } std::string srenameSrc = lineName[idx + 1]; renameSrcID = DataManager::GetObjectIDByName(srenameSrc); if (renameSrcID == -1) { throw std::runtime_error("未找到对象:" + srenameSrc); } } std::string name; if (lineName.size() < 2) { // 未指定名称 if (typeid(*o) == typeid(Hull)) { name = ParseNameHull(); } else { name = ParseNameSuffix(o, "_M"); } } else { // 指定名称 name = lineName[1]; // 名称合法性验证 if (!ValidSyntaxOfName(name)) { throw std::runtime_error("名称语法错误!"); } id2DelOrReplace = FindIDByName(name, true, typeid(*o).name()); if (id2DelOrReplace == -2) { throw std::runtime_error(name + " 不可被替换!"); } else if (id2DelOrReplace == -1) { if (renameSrcID != -1) { id2DelOrReplace = renameSrcID; } } //同类型同名问题由前端首先处理弹窗后再进入函数 ,这里不再做这种处理 // else // { // if (renameSrcID != -1) // { // throw std::runtime_error("存在不可替换的重名图元:" + name); // } // std::string stp = DataDictionary::TypeNameCnDic[Global::RootWorkItem->Services->Get()->GetObjectByID(id2DelOrReplace)->GetType()]; // if (AppSetting::Default::SameNameRule == 0) // 更新 // { // if (typeid(*o) != typeid(*Global::RootWorkItem->Services->Get()->GetObjectByID(id2DelOrReplace))) // { // throw std::runtime_error("指定的对象名称 " + name + " 相同,但不是同一类型的对象,无法更新!"); // } // } // else if (AppSetting::Default::SameNameRule == 1) // 放弃 // { // throw std::runtime_error("命令放弃执行。\n存在重名图元:" + stp + " \"" + name + "\"\n"); // } // else if (AppSetting::Default::SameNameRule == 2) // 询问 // { // std::string strtext = "存在重名图元:" + stp + " \"" + name + "\", 是否要覆盖?\n\n如不需要重名弹窗提示,可点击“取消”设置为“直接覆盖,不再弹窗”。"; // DialogResult dr = MessageBox::Show(strtext, "图元重名", MessageBoxButtons::YesNoCancel, MessageBoxIcon::Warning, MessageBoxDefaultButton::Button3, MessageBoxOptions::ServiceNotification); // if (dr == DialogResult::No) // { // throw std::runtime_error("命令放弃执行。\n存在重名图元:" + stp + " \"" + name + "\"\n"); // } // else // { // if (typeid(*o) != typeid(*Global::RootWorkItem->Services->Get()->GetObjectByID(id2DelOrReplace))) // { // throw std::runtime_error("指定的对象名称 " + name + " 相同,但不是同一类型的对象,无法更新!"); // } // if (dr == DialogResult::Cancel) // { // AppSetting::Default::SameNameRule = 0; // 同名规则为更新 // } // } // } // } } return name; } // std::string ObjectInterpreter::ParseNameMirror(std::shared_ptr o) // { // if (std::dynamic_pointer_cast(o) != nullptr || std::dynamic_pointer_cast(o) != nullptr || std::dynamic_pointer_cast(o) != nullptr || std::dynamic_pointer_cast(o) != nullptr) // { // return GenerateObjectNameSec(o, (std::dynamic_pointer_cast(o))->SecID); // } // else // { // std::string name = o->Name + "_M"; // // 未指定名称 // int i = 0; // while (true) // { // // 反复生成默认名称,直到不存在重名 // id2DelOrReplace = FindIDByName(name, false, o->GetType()); // update zyy // if (id2DelOrReplace == -1) // { // return name; // } // i++; // name = name + std::to_string(i); // } // } // } std::string ObjectInterpreter::ParseNameByPre(const std::string &preName) { std::string name = preName; // 未指定名称 int i = 0; while (true) { // 反复生成默认名称,直到不存在重名 int id = DataManager::GetGeomObjectIDByName(name); if (id == -1) { return name; } i++; name = preName + std::to_string(i); } } std::string ObjectInterpreter::ParseNameByPre(const std::string &preName, int &baseNum) { std::string name = preName + std::to_string(baseNum); // 未指定名称 int i = baseNum; while (true) { // 反复生成默认名称,直到不存在重名 int id = DataManager::GetGeomObjectIDByName(name); if (id == -1) { baseNum = i; return name; } i++; name = preName + std::to_string(i); } } std::string ObjectInterpreter::ParseNameHull() { { std::string preName = "Hull_"; std::string name; // 未指定名称 int i = 1; while (true) { // 反复生成默认名称,直到不存在重名 name = preName + std::to_string(i); // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: id2DelOrReplace = FindIDByName(name, false, typeid(Hull).name()); // update zyy if (id2DelOrReplace == -1) { return name; } i++; } } } std::string ObjectInterpreter::ParseNameSuffix(IModel *o, const std::string &sSuffix) { std::string name = o->m_Name.toStdString() + sSuffix; int i = 0; while (true) { // 反复生成默认名称,直到不存在重名 id2DelOrReplace = FindIDByName(name, false, typeid(*o).name()); if (id2DelOrReplace == -1) { //旧代码这个逻辑很奇怪不知道为什么要这样 // bool sameF = false; // for (IModel3D *oo : Statics::Objects2Interact) // { // if (oo->m_Name == name) // { // sameF = true; // break; // } // } // if (!sameF) // { // return name; // } return name; } i++; name = name + std::to_string(i); } } bool ObjectInterpreter::ParsePointLoc(Point3D_M &o, const std::string &loc, bool withRef) { if (loc.front() == '(' && loc.back() == ')') { // 坐标形式 (x1,y1,z1) std::string content = loc.substr(1, loc.length() - 2); std::vector xyz = StringHelper::split(content, {WORD_SPLITTER, WORD_SPLITTER_2}); if (xyz.size() != 3) { throw std::runtime_error("坐标格式错误."); } o.m_X = GetX(xyz[0]); o.m_Y = std::stod(xyz[1]); o.m_Z = std::stod(xyz[2]); o.m_Type = 0; return true; } else if (loc.find(SLASH) != std::string::npos && loc.find(EQUAL) != std::string::npos) { // 截取 c/y=? c/n=? std::vector locs = StringHelper::split(loc, std::vector{SLASH}); if (locs.size() < 2) { throw std::runtime_error("坐标格式错误."); } int baseCurve = DataManager::GetObjectIDByName(locs[0]); if (baseCurve == -1) { throw std::runtime_error("未找到曲线" + locs[0]); } //o.m_Src.reserve(ModelData::ARRAY_SIZE_NORMAL); o.m_Src[0] = baseCurve; std::vector locxyz = StringHelper::split(locs[1], std::vector{EQUAL}); bool IsN = false; if (StringHelper::toUpper(locxyz[0]) == "X") { o.m_CutDir = 0; o.m_Cut = GetX(locxyz[1]); } else if (StringHelper::toUpper(locxyz[0]) == "Y") { o.m_CutDir = 1; o.m_Cut = std::stod(locxyz[1]); } else if (StringHelper::toUpper(locxyz[0]) == "Z") { o.m_CutDir = 2; o.m_Cut = std::stod(locxyz[1]); } else if (StringHelper::toUpper(locxyz[0]) == "N") { IsN = true; } else { throw std::runtime_error("坐标格式错误."); } if (locs.size() == 2) { if (IsN) { int index = std::stoi(locxyz[1]); IModel *baseModel = DataManager::GetObjectByID(baseCurve); // 返回 IModel* 类型 struct Curve_M *model = dynamic_cast(baseModel); if (model) { // 成功转换,进行处理 // 使用 model 访问 Curve_M 类型的成员 } else { // 转换失败,处理错误 qWarning() << "Failed to cast IModel to Curve_M"; } if (model->m_KnotID.empty()) { model->m_KnotID.reserve(ModelData::ARRAY_SIZE_NORMAL); } int len = 0; for (size_t j = 0; j < model->m_KnotID.size(); j++) { if (model->m_KnotID[j] == 0) { len = j; break; } } if (index == 0 || index < -len || index >= len) { throw std::runtime_error("坐标格式错误."); } if (index < 0) { index += len; } else { index -= 1; } Point3D_M * pSrc = dynamic_cast(DataManager::GetObjectByID(model->m_KnotID[index])); if (pSrc == nullptr) { throw std::runtime_error("未找到曲线" + locs[0]); } ParseRes(o, "N=" + locxyz[1]); o.m_Type = 10; o.m_X = pSrc->m_X; o.m_Y = pSrc->m_Y; o.m_Z = pSrc->m_Z; } else { ParseRes(o, locs[1]); o.m_Type = 1; Point3D temp_o = o.getGeoPoint(); if ( OCCModeling::CheckPoint(&temp_o)) { // throw std::runtime_error(Global::RootWorkItem.Services.Get()->GetErrInfo() + "."); throw std::runtime_error("坐标格式错误."); } o.m_X = temp_o.X; o.m_Y = temp_o.Y; o.m_Z = temp_o.Z; if (!withRef) { o.m_Type = 0; } } } return true; } else if (loc.find(SLASH) != std::string::npos) { // 相交 c1/c2 std::vector locs = StringHelper::split(loc, std::vector{SLASH}); if (locs.size() < 2) { throw std::runtime_error("坐标格式错误."); } int baseCurve0 = DataManager::GetObjectIDByName(locs[0]); if (baseCurve0 == -1) { throw std::runtime_error("未找到曲线" + locs[0]); } int baseCurve1 = DataManager::GetObjectIDByName(locs[1]); if (baseCurve1 == -1) { throw std::runtime_error("未找到曲线" + locs[1]); } if (baseCurve0 == baseCurve1) { throw std::runtime_error("相交曲线不可为同一曲线."); } //o.m_Src.reserve(ModelData::ARRAY_SIZE_NORMAL); o.m_Src[0] = baseCurve0; o.m_Src[1] = baseCurve1; if (locs.size() > 2) { ParseRes(o, locs[2]); } o.m_Type = 2; Point3D temp_o = o.getGeoPoint(); if ( OCCModeling::CheckPoint(&temp_o)) { // throw std::runtime_error(Global::RootWorkItem.Services.Get()->GetErrInfo() + "."); throw std::runtime_error("坐标格式错误."); } o.m_X = temp_o.X; o.m_Y = temp_o.Y; o.m_Z = temp_o.Z; if (!withRef) { o.m_Type = 0; } return true; } else { // 点图元名称 int basePnt = DataManager::GetObjectIDByName(loc); if (basePnt == -1) { throw std::runtime_error("未找到点" + loc); } Point3D_M * basep = dynamic_cast(DataManager::GetObjectByID(basePnt)); if (basep == nullptr) { throw std::runtime_error("未找到曲线" + basePnt); } o.m_X = basep->m_X; o.m_Y = basep->m_Y; o.m_Z = basep->m_Z; //o.m_Src.reserve(ModelData::ARRAY_SIZE_NORMAL); o.m_Src[0] = basePnt; o.m_Type = 11; Point3D temp_o = o.getGeoPoint(); if ( OCCModeling::CheckPoint(&temp_o)) { // throw std::runtime_error(Global::RootWorkItem.Services.Get()->GetErrInfo() + "."); throw std::runtime_error("坐标格式错误."); } o.m_X = temp_o.X; o.m_Y = temp_o.Y; o.m_Z = temp_o.Z; if (!withRef) { o.m_Type = 0; } return true; } } void ObjectInterpreter::ParsePointLoc2D(Point3D_M &o, const std::string &loc, const std::string &cutdir, double cutoff) { o.m_Src.resize(ModelData::ARRAY_SIZE_NORMAL); if (loc.front() == '(' && loc.back() == ')') // 数值表达式 { // // 坐标形式 (x1,y1) std::vector cds; std::string loc_sub = loc.substr(1, loc.size() - 2); std::stringstream ss(loc_sub); std::string temp; while (std::getline(ss, temp, ' ')) { cds.push_back(temp); } if (cds.size() != 2) { throw std::runtime_error("坐标格式错误."); } std::string cd1 = cds[0]; std::string cd2 = cds[1]; switch (cutdir[0]) { case 'X': o.m_X = cutoff; o.m_Y = std::stod(cd1); o.m_Z = std::stod(cd2); break; case 'Y': o.m_X = GetX(cd1); o.m_Y = cutoff; o.m_Z = std::stod(cd2); break; case 'Z': o.m_X = GetX(cd1); o.m_Y = std::stod(cd2); o.m_Z = cutoff; break; default: break; } o.m_Type = 0; } else // 引用表达式 { std::vector locs; std::stringstream ss(loc); std::string temp; while (std::getline(ss, temp, '/')) { locs.push_back(temp); } if (locs.size() < 1) { throw std::runtime_error("坐标格式错误."); } int baseCurve = DataManager::GetObjectIDByName(locs[0]); if (baseCurve>=1000000 && baseCurve<2000000) // 引用曲线 C1 { int crossCurve = -1; if (locs.size() > 1) { crossCurve = DataManager::GetObjectIDByName(locs[1]); } if (crossCurve != -1) // C2 曲线相交 "C1/C2" { o.m_Src[0] = baseCurve; o.m_Src[1] = crossCurve; if (locs.size() > 2) // 可能是类似的表达式? { ParseRes(o, locs[2]); } o.m_Type = 2; // 曲线相交 Point3D temp_o = o.getGeoPoint(); bool b = OCCModeling::CheckPoint(&temp_o); if (b == false) { throw std::runtime_error("坐标格式错误."); } o.m_X = temp_o.X; o.m_Y = temp_o.Y; o.m_Z = temp_o.Z; switch (cutdir[0]) { case 'X': o.m_X = cutoff; break; case 'Y': o.m_Y = cutoff; break; case 'Z': o.m_Z = cutoff; break; default: break; } } else // 曲线上截取 C/X=? C/N=? C/Y>? C/Z~? { o.m_Src[0] = baseCurve; switch (cutdir[0]) { case 'X': o.m_CutDir = 0; break; case 'Y': o.m_CutDir = 1; break; case 'Z': o.m_CutDir = 2; break; default: throw std::runtime_error("坐标格式错误."); } o.m_Cut = cutoff; if (locs.size() > 1) { ParseRes(o, locs[1]); // 判断引用表达式的类型,设置 o.ResType 和 o.Type } if(o.m_Type == 10) // C/N=? { // // 引用已有点 int curveID = DataManager::GetObjectIDByName(locs[0]); Curve_M * model = dynamic_cast(DataManager::GetObjectByID(curveID)); int index = static_cast(o.m_Res); int len = 0; for (int j = 0; j < model->m_KnotID.size(); j++) { if (model->m_KnotID[j] == 0) { len = j; break; } } if (index == 0) { std::runtime_error("坐标格式错误."); } else if (index > 0) { index -= 1; } else { index += len; } if (index < 0 || index > len) { throw std::runtime_error("坐标格式错误."); } int pointId = model->m_KnotID[index]; // 取点 Point3D_M * basep = dynamic_cast(DataManager::GetObjectByID(pointId)); switch (cutdir[0]) { case 'X': o.m_X = cutoff; o.m_Y = basep->m_Y; o.m_Z = basep->m_Z; break; case 'Y': o.m_X = basep->m_X; o.m_Y = cutoff; o.m_Z = basep->m_Z; break; case 'Z': o.m_X = basep->m_X; o.m_Y = basep->m_Y; o.m_Z = cutoff; break; default: break; } o.m_Type = 1; } else // C/X=? C/Y>? C/Z~? { o.m_Type = 1; if ((o.m_CutDir == (o.m_ResDir - 1))) // && (o.ResType == 0) o.m_Cut = o.m_Res; Point3D temp_o = o.getGeoPoint(); bool b = OCCModeling::CheckPoint(&temp_o); if (b == false) { throw std::runtime_error("坐标格式错误."); } o.m_X = temp_o.X; o.m_Y = temp_o.Y; o.m_Z = temp_o.Z; switch (cutdir[0]) // 处理 X, Y, Z { case 'X': o.m_X = cutoff; break; case 'Y': o.m_Y = cutoff; break; case 'Z': o.m_Z = cutoff; break; default: break; } } } } else // 引用点 { int basePnt = DataManager::GetObjectIDByName(locs[0]); if (basePnt == -1 || basePnt >= 1000000) { throw std::runtime_error("未找到点" + locs[0]); } Point3D_M * basep = dynamic_cast(DataManager::GetObjectByID(basePnt)); o.m_Src[0] = basePnt; switch (cutdir[0]) { case 'X': o.m_X = cutoff; o.m_Y = basep->m_Y; o.m_Z = basep->m_Z; break; case 'Y': o.m_X = basep->m_X; o.m_Y = cutoff; o.m_Z = basep->m_Z; break; case 'Z': o.m_X = basep->m_X; o.m_Y = basep->m_Y; o.m_Z = cutoff; break; default: break; } o.m_Type = 11; } } } // std::shared_ptr ObjectInterpreter::CreateTempCurve(std::shared_ptr p, const std::string &cutdir) // { // std::shared_ptr c = std::make_shared(); // c->Type = 5; // c->KnotID = std::vector(ModelData::ARRAY_SIZE_NORMAL); // 20170501 by czb // c->KnotDir = std::vector(ModelData::ARRAY_SIZE_NORMAL); // c->KnotDirII = std::vector(ModelData::ARRAY_SIZE_NORMAL); // c->KnotAX = std::vector(ModelData::ARRAY_SIZE_NORMAL); // c->KnotAY = std::vector(ModelData::ARRAY_SIZE_NORMAL); // c->KnotAZ = std::vector(ModelData::ARRAY_SIZE_NORMAL); // c->KnotAXII = std::vector(ModelData::ARRAY_SIZE_NORMAL); // c->KnotAYII = std::vector(ModelData::ARRAY_SIZE_NORMAL); // c->KnotAZII = std::vector(ModelData::ARRAY_SIZE_NORMAL); // std::shared_ptr tp = std::make_shared(); // std::shared_ptr ep = std::make_shared(); // tp = p; // ep = p; // tp->Type = 0; // ep->Type = 0; // // C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic: // // switch (cutdir) // // ORIGINAL LINE: case "X": // if (cutdir == "X") // { // tp->X = -10000; // ep->X = 10000; // } // // ORIGINAL LINE: case "Y": // else if (cutdir == "Y") // { // tp->Y = -10000; // ep->Y = 10000; // } // // ORIGINAL LINE: case "Z": // else if (cutdir == "Z") // { // tp->Z = -10000; // ep->Z = 10000; // } // else // { // } // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // tp->ID = GenerateObjectID(typeof(Point3D)); // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // ep->ID = GenerateObjectID(typeof(Point3D)); // Add2ModelOrInteract(tp); // Add2ModelOrInteract(ep); // c->KnotID[0] = tp->ID; // c->KnotID[0] = ep->ID; // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // c->ID = GenerateObjectID(typeof(Curve)); // std::shared_ptr adapter = Global::RootWorkItem::Services::Get>(); // std::vector order; // std::vector> crv; // std::vector> sur; // crv.push_back(c); // order.push_back(c->ID); // adapter->AddObj(-1, order.size(), order.ToArray(), 0, nullptr, 0, nullptr, crv.size(), crv.ToArray(), 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr); // return c; // } // void ObjectInterpreter::ParsePointLoc(std::shared_ptr &o, std::shared_ptr p, const std::string &cutdir, int baseCurve) // { // std::shared_ptr c2 = CreateTempCurve(p, cutdir); // o->Src = std::vector(ModelData::ARRAY_SIZE_NORMAL); // o->Src[0] = baseCurve; // o->Src[1] = c2->ID; // o->Type = 2; // 曲线相交 // bool b = Global::RootWorkItem::Services::Get>().CheckPoint(o); // if (b == false) // { // throw ErrorSyntaxException(Global::RootWorkItem::Services::Get>().GetErrInfo() + "."); // } // } void ObjectInterpreter::ParseRes(Point3D_M &o, const std::string &res) { if (res.find(CLOSE2) != std::string::npos) { o.m_ResType = 3; } else if (res.find(EQUAL) != std::string::npos) { o.m_ResType = 0; } else if (res.find(LESS) != std::string::npos) { o.m_ResType = 1; } else if (res.find(GREATER) != std::string::npos) { o.m_ResType = 2; } std::vector ss = StringHelper::split(res, {EQUAL, LESS, GREATER, CLOSE2}); if (ss.size() < 2) { std::runtime_error("数据错误."); } // C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic: // switch (ss[0].toUpper()) // ORIGINAL LINE: case "X": if (StringHelper::toUpper(ss[0]) == "X") { o.m_ResDir = 1; } // ORIGINAL LINE: case "Y": else if (StringHelper::toUpper(ss[0]) == "Y") { o.m_ResDir = 2; } // ORIGINAL LINE: case "Z": else if (StringHelper::toUpper(ss[0]) == "Z") { o.m_ResDir = 3; } // ORIGINAL LINE: case "N": else if (StringHelper::toUpper(ss[0]) == "N") { o.m_Type = 10; } else { } if (o.m_ResDir == 1) // 20161107 by czb { o.m_Res = GetX(ss[1]); return; } o.m_Res = std::stod(ss[1]); } // void ObjectInterpreter::Add2ModelOrInteract(std::shared_ptr o) // { // if (std::dynamic_pointer_cast(o) != nullptr) // { // Global::RootWorkItem::Services::Get>().Add2Interact(std::dynamic_pointer_cast(o)); // } // else // { // Global::RootWorkItem::Services::Get>().Add2Model(o); // } // } void ObjectInterpreter::Add2ModelOrInteractWithIdtf(IModel *o, bool bSetCommand) { o->m_Visible = 1; o->m_Color = -1; o->m_Transparency = 1.0; if(id2DelOrReplace<=0) { o->m_ID = GenerateObjectID(o); } else { o->m_ID = id2DelOrReplace; } // 等出现问题在考虑这部分补丁有没有用 // 20161117 by czb,创建命令中无图元名称时,将图元名称添加到命令中 // std::vector commands = DataManagement::Services::DataManager::SplitCommand(o->Command); // if (commands[0].GetWords()->Length == 1) // 仅有命令,无对象名称时,20170601 by czb,解决重命名对象的问题 // { // commands[0] = commands[0].FirstWord() + " " + o->Name; // o->Command = std::string::Join(Constants->LINE_SPLITTER, commands); // } //我们没有这个结构 不需要加 // Add2ModelOrInteract(o); } int ObjectInterpreter::GenerateObjectID(IModel *o) { // 生成新图元ID // int max = TypeNameMaxId[typeid(*o).name()]; // if(max) // { // TypeNameMaxId[typeid(*o).name()] = max + 1; // return max; // } // int prefix = TypeNamePrefixId[typeid(*o).name()]; // //生成新的图元ID的时候这个Max值也需要更新为后面使用 // TypeNameMaxId[typeid(*o).name()] = prefix * MAX_SIZE_OF_OBJECT_GROUP + max + 1; // return prefix * MAX_SIZE_OF_OBJECT_GROUP + max; int max=0; string typeName = typeid(*o).name(); auto it = Model3D_MCommanData::TypeNameMaxId.find(typeName); if (it != Model3D_MCommanData::TypeNameMaxId.end()) { max = ++Model3D_MCommanData::TypeNameMaxId[typeName]; } int prefix = Model3D_MCommanData::TypeNamePrefixId[typeName]; return prefix * MAX_SIZE_OF_OBJECT_GROUP + max; //else if (Global.RootWorkItem.Services.Get().Calculation.MaxIDs.ContainsKey(typeName)) //{ max = ++Global.RootWorkItem.Services.Get().Calculation.MaxIDs[typeName]; } // int prefix = ModelData.TypeIDPrefixDic[typeName]; //int prefix = DataDictionary.TypeIDPrefixDic[typeName]; //return prefix * DataDictionary.MAX_SIZE_OF_OBJECT_GROUP + max; } // void ObjectInterpreter::InitialObjectID(std::type_info t) // { // // 生成新图元ID // std::shared_ptr model = Global::RootWorkItem::Services::Get>().Model; // std::string typeName = t.name(); // model->MaxIDs[typeName] = 0; // Global::RootWorkItem::Services::Get>().Calculation::MaxIDs[typeName] = 0; // } std::string ObjectInterpreter::GenerateObjectName(IModel &o) { // if (Space* s = dynamic_cast(o)) { // 判断是否为 Space 类型 // if (s->isUnit) { // return "SpaceUnit"; // } // } //// 根据默认规则生成新图元名称 typeid(o).name(); std::string prefix = Model3D_MCommanData::TypeNamePrefixDic[typeid(o).name()]; return prefix; } // std::string ObjectInterpreter::GenerateObjectNameSec(std::shared_ptr o, int secid) // { // if (std::dynamic_pointer_cast(o) != nullptr || std::dynamic_pointer_cast(o) != nullptr || std::dynamic_pointer_cast(o) != nullptr || std::dynamic_pointer_cast(o) != nullptr) // { // int max = 0; // auto items = Global::RootWorkItem::Services::Get>().Model::ObjectDics[o->GetType()->Name]->Values; // for (auto item : items) // { // if (std::dynamic_pointer_cast(item) != nullptr && (std::dynamic_pointer_cast(item))->SecID == secid) // { // int n = 0; // try // { // n = std::stoi((std::dynamic_pointer_cast(item))->Name); // } // catch (const std::runtime_error &e1) // { // } // if (n > max) // { // max = n; // } // } // } // max++; // return std::to_string(max); // } // else // { // return GenerateObjectName(o); // } // } int ObjectInterpreter::FindIDByName(const std::string& name, bool replace, const char* typeName, bool throwEx) { int id = DataManager::GetGeomObjectIDByName(name); if (id != -1) { // 如果找到 ID if (replace) { IModel* tempmodel = DataManager::GetObjectByID(id); if (tempmodel == nullptr || std::string(typeid(*tempmodel).name()) != typeName) { return -2; // 如果 tempmodel 为 nullptr 或类型不匹配,返回 -2 } } return id; } // 格式验证 if (typeName) { bool isHull = std::regex_match(name, std::regex (Reg_HULL)); bool isMdeck = std::regex_match(name, std::regex (Reg_MDECKSURF)); bool isShell = std::regex_match(name, std::regex (Reg_SHELLSURF)); if (typeName == typeid(Hull_M).name() && !isHull) { throw std::runtime_error("主船体命名格式不正确."); return -1; } //下面这些现在都没有 用不上 // if (typeName == "MAINDECKSURF" && !isMdeck) { // if (throwEx) throw std::runtime_error("主甲板面命名格式不正确."); // return -1; // } // if (typeName == "SHELLSURF" && !isShell) { // if (throwEx) throw std::runtime_error("外板面命名格式不正确."); // return -1; // } // if (typeName != "HULL" && typeName != "MAINDECKSURF" && typeName != "SHELLSURF") { // if (isHull) throw std::runtime_error("与主船体命名格式冲突."); // if (isMdeck) throw std::runtime_error("与主甲板面命名格式冲突."); // if (isShell) throw std::runtime_error("与外板面命名格式冲突."); // } } return -1; } // int ObjectInterpreter::FindIDByNameFromInteract(const std::string &name, bool replace, std::type_info t, bool throwEx) // { // std::vector> listM = Statics::Objects2Interact; // for (auto m : listM) // { // if (m->Name != nullptr && m->Name.Equals(name)) // { // return m->ID; // } // } // return -1; // } // std::shared_ptr ObjectInterpreter::CopyObjectWithSrc(int id, bool add2Model, bool mirror, double dx, double dy, double dz, double kx, double ky, double kz, std::unordered_map &dicCopyed) // { // if (dicCopyed.empty()) // { // dicCopyed = std::unordered_map(); // } // return CopyObjectWithSrcPriv(dicCopyed, id, add2Model, mirror, dx, dy, dz, kx, ky, kz); // } // std::shared_ptr ObjectInterpreter::CopyObjectWithSrcPriv(std::unordered_map &dicCopyed, int id, bool add2Model, bool mirror, double dx, double dy, double dz, double kx, double ky, double kz) // { // // 获取待拷贝图元 // std::shared_ptr src = Global::RootWorkItem::Services::Get>().GetObjectByID(id); // if (src == nullptr) // { // return nullptr; // } // if (dicCopyed.contains(src->ID)) // { // return nullptr; // } // // 拷贝数据 // std::shared_ptr o = std::dynamic_pointer_cast(Statics::CopyObject(src)); // // 拷贝其依赖图元 // if (src->Src != nullptr) // { // o->Src = std::vector(ModelData::ARRAY_SIZE_NORMAL); // for (int i = 0; i < src->Src->Length; i++) // { // int srcid = src->Src[i]; // if (srcid == 0) // { // break; // } // else if (dicCopyed.contains(srcid)) // { // o->Src[i] = dicCopyed[srcid]; // } // else // { // std::shared_ptr copyM = CopyObjectWithSrcPriv(dicCopyed, src->Src[i], true, mirror, dx, dy, dz, kx, ky, kz); // if (copyM != nullptr) // { // o->Src[i] = copyM->ID; // } // } // } // } // // 拷贝节点ID KnotID 20170601 by czb // if (std::dynamic_pointer_cast(src) != nullptr) // { // std::shared_ptr cc = std::static_pointer_cast(src); // if (cc->KnotID != nullptr) // { // std::shared_ptr oo = std::static_pointer_cast(o); // oo->KnotID = std::vector(ModelData::ARRAY_SIZE_NORMAL); // auto srcList = cc->Src.ToList(); // for (int i = 0; i < cc->KnotID->Length; i++) // { // int cid = cc->KnotID[i]; // if (cid == 0) // { // break; // } // int index = VectorHelper::indexOf(srcList, cid); // oo->KnotID[i] = oo->Src[index]; // } // o = oo; // } // } // // 偏移量,修改X、Y、Z坐标属性 // std::vector> fields = o->GetType()->GetFields(); // for (auto f : fields) // { // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // if (f->GetCustomAttributes(typeof(OffsetPropAttribute), true).Count() > 0 && f->FieldType == typeof(double)) // { // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // std::shared_ptr att = std::dynamic_pointer_cast(f->GetCustomAttributes(typeof(OffsetPropAttribute), true)[0]); // double v = std::any_cast(f->GetValue(o)); // switch (att->Type) // { // case OffsetType::X: // f->SetValue(o, kx * v + dx); // break; // case OffsetType::Y: // f->SetValue(o, ky * v + dy); // break; // case OffsetType::Z: // f->SetValue(o, kz * v + dz); // break; // default: // break; // } // } // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // else if (f->GetCustomAttributes(typeof(OffsetArrayAttribute), true).Count() > 0) // { // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // std::shared_ptr att = std::dynamic_pointer_cast(f->GetCustomAttributes(typeof(OffsetArrayAttribute), true)[0]); // std::shared_ptr arr = std::dynamic_pointer_cast(f->GetValue(o)); // if (arr != nullptr) // { // for (int i = 0; i < arr->Length; i++) // { // double v = std::any_cast(arr->GetValue(i)); // double vv = v; // switch (att->Type) // { // case OffsetType::X: // vv = kx * v + dx; // break; // case OffsetType::Y: // vv = ky * v + dy; // break; // case OffsetType::Z: // vv = kz * v + dz; // break; // default: // break; // } // arr->SetValue(vv, i); // } // f->SetValue(o, arr); // } // } // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // else if ((f->GetCustomAttributes(typeof(CutArrayAttribute), true).Count() > 0) && mirror) // { // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // std::shared_ptr att = std::dynamic_pointer_cast(f->GetCustomAttributes(typeof(CutArrayAttribute), true)[0]); // std::shared_ptr arr = std::dynamic_pointer_cast(f->GetValue(o)); // if (arr != nullptr) // { // for (int i = 0; i < arr->Length; i++) // { // double v = std::any_cast(arr->GetValue(i)); // double vv = v; // switch (att->Type) // { // case OffsetType::X: // vv = kx * v + dx; // break; // case OffsetType::Y: // vv = ky * v + dy; // break; // case OffsetType::Z: // vv = kz * v + dz; // break; // default: // break; // } // arr->SetValue(vv, i); // } // f->SetValue(o, arr); // } // } // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // else if (f->GetCustomAttributes(typeof(AngleAttribute), true).Count() > 0 && f->FieldType == typeof(double)) // { // if (mirror) // { // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // std::shared_ptr att = std::dynamic_pointer_cast(f->GetCustomAttributes(typeof(AngleAttribute), true)[0]); // double v = std::any_cast(f->GetValue(o)); // f->SetValue(o, 360 - v); // } // } // } // if (mirror) // { // double temp1 = -1; // double temp2 = -1; // for (auto f : fields) // { // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // if (f->GetCustomAttributes(typeof(AngleAttribute), true).Count() > 0 && f->FieldType == typeof(double)) // { // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // std::shared_ptr att = std::dynamic_pointer_cast(f->GetCustomAttributes(typeof(AngleAttribute), true)[0]); // double v = std::any_cast(f->GetValue(o)); // if (att->Type == AngleType::A1) // { // temp1 = v; // } // if (att->Type == AngleType::A2) // { // temp2 = v; // } // } // } // for (auto f : fields) // { // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // if (f->GetCustomAttributes(typeof(AngleAttribute), true).Count() > 0 && f->FieldType == typeof(double)) // { // // C# TO C++ CONVERTER TASK: There is no C++ equivalent to the C# 'typeof' operator: // std::shared_ptr att = std::dynamic_pointer_cast(f->GetCustomAttributes(typeof(AngleAttribute), true)[0]); // double v = std::any_cast(f->GetValue(o)); // if (att->Type == AngleType::A1) // { // f->SetValue(o, temp2); // } // if (att->Type == AngleType::A2) // { // f->SetValue(o, temp1); // } // } // } // } // o->Name = nullptr; // // 置入数据集 // if (add2Model) // { // if (mirror && src->Name != nullptr) // { // o->Name = ParseNameMirror(src); // } // // o.Command = cmd.ToString().Substring(2); // o->ID = GenerateObjectID(o->GetType()); // // Add2ModelOrInteract(o);by yangchen20170227 // // by yangchen 20170418 // if (std::dynamic_pointer_cast(o) != nullptr) // { // Add2ModelOrInteract(o); // // Global.RootWorkItem.Services.Get().Add2Model(o); //20170601 by czb // } // } // dicCopyed.emplace(src->ID, o->ID); // return o; // } double ObjectInterpreter::GetX(const std::string &str) { // C++ 正则表达式 std::regex reg(Reg_LONGCOORDFULL); // 需要替换为实际的正则表达式 if (!std::regex_match(str, reg)) { throw std::runtime_error( "纵向坐标定义格式不正确, 请参照格式(1)数字(最多五位小数),(2)#整数±数字(最多一位小数),(3)$数字(三位小数)±数字(最多一位小数)" ); } return ChangeFSPos::ShowX(str); } // void ObjectInterpreter::ParsePointLoc2D(std::shared_ptr &o, const std::string &loc, const std::string &cutdir, double cutoff, std::shared_ptr sur) // { // if (loc.starts_with("(") && loc.ends_with(")")) // 坐标形式 // { // std::vector cds = loc.substr(1, loc.length() - 2).Split({Constants->SPACE}, StringSplitOptions::RemoveEmptyEntries); // if (cds.size() != 2) // { // throw ErrorParameterException(); // } // std::string cd1 = cds[0]; // std::string cd2 = cds[1]; // // C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic: // // switch (cutdir) // // ORIGINAL LINE: case "X": // if (cutdir == "X") // { // o->X = cutoff; // o->Y = std::stod(cd1); // o->Z = std::stod(cd2); // } // // ORIGINAL LINE: case "Y": // else if (cutdir == "Y") // { // o->X = GetX(cd1); // o->Y = cutoff; // o->Z = std::stod(cd2); // } // // ORIGINAL LINE: case "Z": // else if (cutdir == "Z") // { // o->X = GetX(cd1); // o->Y = std::stod(cd2); // o->Z = cutoff; // } // else // { // } // o->Type = 0; // } // else // 引用表达式 // { // std::vector locs = loc.Split({Constants->SLASH}, StringSplitOptions::RemoveEmptyEntries); // if (locs.size() < 1) // { // throw ErrorParameterException(); // } // int baseCurve = Global::RootWorkItem::Services::Get>().GetObjectIDByName>(locs[0]); // if (baseCurve != -1) // 引用线 // { // int crossCurve = -1; // if (locs.size() > 1) // { // crossCurve = Global::RootWorkItem::Services::Get>().GetObjectIDByName>(locs[1]); // } // if (crossCurve != -1) // 曲线相交 // { // o->Src = std::vector(ModelData::ARRAY_SIZE_NORMAL); // o->Src[0] = baseCurve; // o->Src[1] = crossCurve; // if (locs.size() > 2) // { // ParseRes(o, locs[2]); // } // o->Type = 2; // bool b = Global::RootWorkItem::Services::Get>().CheckPoint(o); // if (b == false) // { // throw ErrorSyntaxException(Global::RootWorkItem::Services::Get>().GetErrInfo() + "."); // } // // C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic: // // switch (cutdir) // // ORIGINAL LINE: case "X": // if (cutdir == "X") // { // o->X = cutoff; // } // // ORIGINAL LINE: case "Y": // else if (cutdir == "Y") // { // o->Y = cutoff; // } // // ORIGINAL LINE: case "Z": // else if (cutdir == "Z") // { // o->Z = cutoff; // } // else // { // } // } // else // 曲线和曲面相交截取 // { // o->Src = std::vector(ModelData::ARRAY_SIZE_NORMAL); // o->Src[0] = baseCurve; // o->Src[1] = sur->ID; // // C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic: // // switch (cutdir) // // ORIGINAL LINE: case "X": // if (cutdir == "X") // { // o->CutDir = 0; // } // // ORIGINAL LINE: case "Y": // else if (cutdir == "Y") // { // o->CutDir = 1; // } // // ORIGINAL LINE: case "Z": // else if (cutdir == "Z") // { // o->CutDir = 2; // } // else // { // throw ErrorParameterException(); // } // o->Cut = cutoff; // if (locs.size() > 1) // { // ParseRes(o, locs[1]); // } // o->Type = 3; // bool b = Global::RootWorkItem::Services::Get>().CheckPoint(o); // if (b == false) // { // throw ErrorSyntaxException(Global::RootWorkItem::Services::Get>().GetErrInfo() + "."); // } // // C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic: // // switch (cutdir) //20170501 by czb,新增 // // ORIGINAL LINE: case "X": // if (cutdir == "X") // { // o->X = cutoff; // } // // ORIGINAL LINE: case "Y": // else if (cutdir == "Y") // { // o->Y = cutoff; // } // // ORIGINAL LINE: case "Z": // else if (cutdir == "Z") // { // o->Z = cutoff; // } // else // { // } // } // } // else // 引用点 // { // int basePnt = Global::RootWorkItem::Services::Get>().GetObjectIDByName>(locs[0]); // if (basePnt == -1) // { // throw ObjectNotFoundException(locs[0]); // } // std::shared_ptr basep = std::static_pointer_cast(Global::RootWorkItem::Services::Get>().GetObjectByID(basePnt)); // // C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic: // // switch (cutdir) // // ORIGINAL LINE: case "X": // if (cutdir == "X") // { // o->X = cutoff; // o->Y = basep->Y; // o->Z = basep->Z; // } // // ORIGINAL LINE: case "Y": // else if (cutdir == "Y") // { // o->X = basep->X; // o->Y = cutoff; // o->Z = basep->Z; // } // // ORIGINAL LINE: case "Z": // else if (cutdir == "Z") // { // o->X = basep->X; // o->Y = basep->Y; // o->Z = cutoff; // } // else // { // } // o->Type = 0; // } // } // } Point3D_M ObjectInterpreter::ParseLoc(std::vector &linePara1b, const std::string &cutdir, double &offset) { Point3D_M pt; if (linePara1b[1].find("/") != std::string::npos) { if (ParsePointLoc(pt, linePara1b[1], true)) { // // C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic: // // switch (cutdir) // // ORIGINAL LINE: case "X": if (cutdir == "X") offset = pt.m_X; // offset = pt->X; // } // // ORIGINAL LINE: case "Y": else if (cutdir == "Y") offset = pt.m_Y; // { // offset = pt->Y; // } // // ORIGINAL LINE: case "Z": else if (cutdir == "Z") offset = pt.m_Z; // { // offset = pt->Z; // } // else // { // } } else { throw std::runtime_error("数据错误."); } } else { std::string dir = StringHelper::toUpper(linePara1b[0]); if (dir == "X") { offset = GetX(linePara1b[1]); } else { offset = std::stod(linePara1b[1]); } } return pt; }