diff --git a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_dim_tools.cpp b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_dim_tools.cpp index 5123b37..8a0e1e5 100644 --- a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_dim_tools.cpp +++ b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_dim_tools.cpp @@ -29,6 +29,7 @@ #include "AecDbX3dPartEntity.h" #include "AecDbBDPipeBase.h" #include "AecDbCurveBase.h" +#include "KTModelLayoutXData.h" #include "AecDbObjXDataMap.h" #include "CoreTools.h" #include "KTCadUtility.h" @@ -62,6 +63,190 @@ namespace return xdata.Read(pEnt, BIMDATA_APP) == TRUE; } + + // ------------------------------------------------------------------------ + // 「系统标注」的字段脚本引擎(等价于 PipelineCmd 里 PipelineTools::FormatDimText) + // + // 标注配置存在模型 xdata 里(KTModelLayoutXData,AecRxBase 导出): + // ScriptT / ScriptB = 上/下排脚本,形如 "{0}{-}{1}{-}{2}{-}{3}" + // DNPRE / DPRE / ADPRE = 是否加 DN / D / 统一前缀 + // ElType / ElDescr = 标高写法(0 符号 / 1 简写 / 2 自定义) + // InsTra = 保温伴热 0/1/2 + // 字段表(与 FormatDimText 一致): + // {0} 公称直径 {1} 介质 {2} 管号 {3} 压力等级 {4} 外径x壁厚 {5} 标高 + // {6} 类型(按图层查库,这里留空) {7} 保温伴热 {8} 弯头比率 {9} 标准(空) + // {10} 材质 {11} 区号 {12} 系统 {13} 单元号 + // 区别:{6} 原版要查 SQLite 设备库(GetSystemDimkeyByLayer),本插件不碰库 → 留空。 + bool ComposeSystemText(AcDbEntity* pTarget, double dEl, std::wstring& sUp, std::wstring& sDown, + std::wstring& err) + { + sUp.clear(); + sDown.clear(); + if (pTarget == NULL) { err = L"被标注实体为空"; return false; } + + // 标注配置 + AecDbObjXDataMap xCfg; + bool bUseDefaultCfg = false; + if (!KTModelLayoutXData::ReadModelXData(KT_PIPEINIT, xCfg)) + { + // 图上还没做过"标注设置":用 KTModelLayoutXData::ReSet 的出厂默认脚本 + // (默认上标是 "{0}{-}{1}{-}{2}{-}{3}" = 公称直径-介质-管号-压力等级) + AecDbObjXDataMap xDef; + KTModelLayoutXData::ReSet(xDef); + xCfg.CopyFrom(&xDef); + bUseDefaultCfg = true; + } + + CString cUp, cDown; + xCfg.GetAt(DOC_SCRIPTT, cUp); + xCfg.GetAt(DOC_SCRIPTB, cDown); + if (cUp.IsEmpty() && cDown.IsEmpty()) + { + err = L"标注设置里上/下排脚本都是空的"; + return false; + } + + // 实体专业数据:仓库实体读专业数据,普通实体读 BIMDATA 扩展数据 + AecDbObjXDataMap xObj; + // 管线/管件是 AecDbCurveBase 派生(不是 AecDbEntityBase);其它仓库实体再试 EntityBase + AecDbCurveBase* pCurBase = AecDbCurveBase::cast(pTarget); + AecDbEntityBase* pEntBase = (pCurBase == NULL) ? AecDbEntityBase::cast(pTarget) : NULL; + if (pCurBase != NULL) + xObj.CopyFrom(pCurBase->GetSpecialtyData(AcDb::kForRead)); + else if (pEntBase != NULL) + xObj.CopyFrom(pEntBase->GetSpecialtyData(AcDb::kForRead)); + else if (!XDataOfPlain(pTarget, xObj)) + { + err = L"取不到被标注实体的专业数据(既不是仓库实体,也没有 BIMDATA 扩展数据)"; + return false; + } + + BOOL bDNP = FALSE, bDP = FALSE, bADP = FALSE; + xCfg.GetAt(DOC_DNPRE, bDNP); + xCfg.GetAt(DOC_DPRE, bDP); + xCfg.GetAt(DOC_ADPRE, bADP); + + CString sTemp; + + // {0} 公称直径 + double dDn = 0.0; + xObj.GetAt(PIPE_DN, dDn); + if (dDn > 0.0 && dDn < 10.0) dDn *= 1000.0; // 库里存米,拼文字用毫米 + if (bADP) sTemp.Format(_T("%%%%c%d"), (int)dDn); + else if (bDNP) sTemp.Format(_T("DN%d"), (int)dDn); + else sTemp.Format(_T("%d"), (int)dDn); + cUp.Replace(_T("{0}"), sTemp); cDown.Replace(_T("{0}"), sTemp); + + // {1} 介质 {2} 管号 {3} 压力等级 + CString sVal; + xObj.GetAt(PIPE_MEDIA, sVal); cUp.Replace(_T("{1}"), sVal); cDown.Replace(_T("{1}"), sVal); + xObj.GetAt(PIPE_NO, sVal); cUp.Replace(_T("{2}"), sVal); cDown.Replace(_T("{2}"), sVal); + xObj.GetAt(PIPE_LEVEL, sVal); cUp.Replace(_T("{3}"), sVal); cDown.Replace(_T("{3}"), sVal); + + // {4} 外径 x 壁厚 + double dOd = dDn, dTh = 0.0; + xObj.GetAt(PIPE_OD, dOd); + xObj.GetAt(PIPE_THICK, dTh); + if (dOd > 0.0 && dOd < 10.0) dOd *= 1000.0; // 同上:米 -> 毫米 + if (dTh > 0.0 && dTh < 10.0) dTh *= 1000.0; + if (bADP) sTemp.Format(_T("%%%%c%dx%.1f"), (int)dOd, dTh); + else if (bDP) sTemp.Format(_T("D%dx%.1f"), (int)dOd, dTh); + else sTemp.Format(_T("%dx%.1f"), (int)dOd, dTh); + cUp.Replace(_T("{4}"), sTemp); cDown.Replace(_T("{4}"), sTemp); + + // {5} 标高(写法照 FormatDimText:ElType 0 符号 / 1 简写 / 2 自定义描述) + { + const bool bMeter = CoreTools::IsMeterUnitForPipeElevDim(); + const int nPrec = CoreTools::getPrecForPipeElevDim(); + CString sEl; + sEl.Format(bMeter ? _T("%.*fm") : _T("%.*fmm"), nPrec, bMeter ? dEl * 0.001 : dEl); + + int nElType = 0; + xCfg.GetAt(DOC_ELTYPE, nElType); + CString sElDescr; + xCfg.GetAt(DOC_ELDESCR, sElDescr); + + if (nElType == 0) sTemp.Format(_T("%s%s"), DIM_CEN_EL, (LPCTSTR)sEl); + else if (nElType == 1) sTemp.Format(_T("%s%s"), PIPE_CEN_EL, (LPCTSTR)sEl); + else + { + // 自定义:描述串用 | 分段,第 3 段是标高前缀(与 FormatDimText 一致) + CString sFirst = sElDescr; + int nBar = sElDescr.Find(KT_SEPARATOR_CHAR); + for (int i = 0; i < 2 && nBar >= 0; ++i) + { + sFirst = sElDescr.Mid(nBar + 1); + nBar = sFirst.Find(KT_SEPARATOR_CHAR); + } + if (nBar >= 0) sFirst = sFirst.Left(nBar); + sTemp.Format(_T("%s%s"), (LPCTSTR)sFirst, (LPCTSTR)sEl); + } + cUp.Replace(_T("{5}"), sTemp); cDown.Replace(_T("{5}"), sTemp); + } + + // {6} 类型:原版按图层查设备库,这里留空 + cUp.Replace(_T("{6}"), _T("")); cDown.Replace(_T("{6}"), _T("")); + + // {7} 保温伴热 + int nIns = 0; + xObj.GetAt(DOC_INSTRATAG, nIns); + sTemp = (nIns == 1) ? CString(_T("保温")) : ((nIns == 2) ? CString(_T("保温加伴热")) : CString(_T("无保温伴热"))); + cUp.Replace(_T("{7}"), sTemp); cDown.Replace(_T("{7}"), sTemp); + + // {8} 弯头比率 + double dRatio = 1.0; + xObj.GetAt(PIPE_RATIO, dRatio); + sTemp.Format(_T("%.1f"), dRatio); + cUp.Replace(_T("{8}"), sTemp); cDown.Replace(_T("{8}"), sTemp); + + // {9} 标准:原版也是空 + cUp.Replace(_T("{9}"), _T("")); cDown.Replace(_T("{9}"), _T("")); + + // {10} 材质(管件用 MaterialFT) + xObj.GetAt(PIPE_MATERIAL, sTemp); + { + int nRuntime = 0; + xObj.GetAt(KEY_RUNTIME, nRuntime); + if (nRuntime != ePipe) xObj.GetAt(PIPE_MATERIALFT, sTemp); + } + cUp.Replace(_T("{10}"), sTemp); cDown.Replace(_T("{10}"), sTemp); + + // {11} 区号 {12} 系统(去掉"管"再加"管") {13} 单元号 + xObj.GetAt(PIPE_ZONE, sTemp); + cUp.Replace(_T("{11}"), sTemp); cDown.Replace(_T("{11}"), sTemp); + + xObj.GetAt(PIPE_SYS, sTemp); + sTemp.Replace(_T("管"), _T("")); + sTemp += _T("管"); + cUp.Replace(_T("{12}"), sTemp); cDown.Replace(_T("{12}"), sTemp); + + sTemp = _T(""); + xObj.GetAt(PIPE_UNITNO, sTemp); + cUp.Replace(_T("{13}"), sTemp); cDown.Replace(_T("{13}"), sTemp); + + // 收尾:剪掉两端多余的 _ 和 -,去掉没替换掉的 {} 占位 + LPCTSTR aszTrim[] = { _T("_"), _T("-") }; + for (int pass = 0; pass < 3; ++pass) + { + for (int i = 0; i < 2; ++i) + { + cUp.TrimRight(aszTrim[i]); cUp.TrimLeft(aszTrim[i]); + cDown.TrimRight(aszTrim[i]); cDown.TrimLeft(aszTrim[i]); + } + cUp.Replace(_T("{"), _T("")); cUp.Replace(_T("}"), _T("")); + cDown.Replace(_T("{"), _T("")); cDown.Replace(_T("}"), _T("")); + } + + sUp = std::wstring((LPCTSTR)cUp); + sDown = std::wstring((LPCTSTR)cDown); + if (sUp.empty() && sDown.empty()) + { + err = L"按标注设置拼出来的文字是空的(检查标注设置里的字段脚本)"; + return false; + } + return true; + } + // ------------------------------------------------------------------------ // 标注文字的"自动拼":按 kind 从被标注实体的专业数据里算 // 对照命令里的格式(PL_DKBZ / PL_TGBZ / PL_YHBZ / PL_FMBZ / PL_XHBZ): @@ -335,14 +520,15 @@ public: "properties": { "target": { "type": "string", "description": "被标注实体的 handle(管/洞/套管/管件…)" }, "kind": { "type": "string", - "enum": [ "seq", "seq_batch", "opening", "casing", "ring", "valve", "iso_valve", "iso_fitting" ], - "description": "标注种类(决定 dim style 与语义),缺省 seq" }, + "enum": [ "seq", "seq_batch", "opening", "casing", "ring", "valve", "iso_valve", "iso_fitting", "system" ], + "description": "标注种类(决定 dim style 与语义),缺省 seq;system=按模型里的\"标注设置\"字段脚本拼(系统标注那 17 个命令用的就是这个)" }, "points": { "type": "array", "items": { "type": "array", "items": { "type": "number" } }, "description": "两个点:[[引出起点],[文字位置]]" }, "text": { "type": "string", "description": "上排文字;不给就按 kind 从被标注实体自动拼(与命令一致)" }, "text_down": { "type": "string", "description": "下排文字;不给就自动拼" }, "unit": { "type": "string", "enum": [ "m", "mm" ], "description": "尺寸/标高的单位,缺省 m(命令里 m_bUnitM)" }, "elevation_base": { "type": "number", "description": "标高基准(命令里的 dElv),缺省 0" }, + "elevation": { "type": "number", "description": "kind=system 时给管线标高(填 {5} 字段),缺省 0" }, "dim_style": { "type": "integer", "description": "标注样式编号,缺省按 kind" }, "dim_dir": { "type": "integer", "description": "标注方向,缺省 0" }, "text_up_down": { "type": "integer", "description": "上下标记:1 上 / -1 下,缺省 1" }, @@ -398,7 +584,7 @@ public: if (hasKey(args, "color")) pDim->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); // 文字:传了就用传的;没传就按 kind 从被标注实体自动拼(与命令一致) - std::wstring sUp, sDown; + std::wstring sUp, sDown, errMsg; if (hasKey(args, "text")) { sUp = wstrOr(args, "text", L""); @@ -406,16 +592,29 @@ public: } else { + const std::wstring sKind = wstrOr(args, "kind", L"seq"); const bool bUnitM = (wstrOr(args, "unit", L"m") != L"mm"); AcDbEntity* pT = openByHandle(sTarget, AcDb::kForRead); - const bool bComposed = ComposeDimText(pT, wstrOr(args, "kind", L"seq"), bUnitM, - numOr(args, "elevation_base", 0.0), sUp, sDown); + bool bComposed = false; + if (sKind == L"system") + { + // 「系统标注」:按模型里的标注设置(字段脚本)拼 + std::wstring sErr; + bComposed = ComposeSystemText(pT, numOr(args, "elevation", 0.0), sUp, sDown, sErr); + if (!bComposed && sErr.size() > 0) errMsg = sErr; + } + else + { + bComposed = ComposeDimText(pT, sKind, bUnitM, + numOr(args, "elevation_base", 0.0), sUp, sDown); + } if (pT != NULL) pT->close(); if (!bComposed) { delete pDim; - return errJson(kErrBadParam, - L"这个 kind 拼不出文字(序号类要实体上有编号,其它类要实体数据齐全),请传 text / text_down"); + return errJson(kErrBadParam, errMsg.empty() + ? std::wstring(L"这个 kind 拼不出文字(序号类要实体上有编号,其它类要实体数据齐全),请传 text / text_down") + : errMsg); } } pDim->AddDimText(sUp.c_str(), sDown.empty() ? NULL : sDown.c_str()); diff --git a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json index c945803..bbb6f2a 100644 --- a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json +++ b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json @@ -5658,7 +5658,7 @@ }, { "name": "add_aec_pipe_dim", - "description": "建管线标注(AecDbEwPipeDim,纯 2D 无 3D 显示)。覆盖 8 个标注命令:seq=PL_XHBZ 序号 / seq_batch=PL_XHPB 序号批标 / opening=PL_DKBZ 洞口 / casing=PL_TGBZ 套管 / ring=PL_YHBZ 翼环 / valve=PL_FMBZ 阀门 / iso_valve=IS_BZFM 标注阀门 / iso_fitting=IS_GZGJ 标注管件。给被标注实体 handle + 引出起点/文字位置两个点;**文字默认从实体数据自动拼**(洞口·套管读 AecInterface,翼环读 PIPE_TOD/PIPE_YMS,阀门读 KEY_NAME,序号读 KEY_BOMNO),格式与命令一致;想覆盖就传 text / text_down。", + "description": "建管线标注(AecDbEwPipeDim,纯 2D 无 3D 显示)。覆盖 8 个标注命令:seq=PL_XHBZ 序号 / seq_batch=PL_XHPB 序号批标 / opening=PL_DKBZ 洞口 / casing=PL_TGBZ 套管 / ring=PL_YHBZ 翼环 / valve=PL_FMBZ 阀门 / iso_valve=IS_BZFM 标注阀门 / iso_fitting=IS_GZGJ 标注管件。给被标注实体 handle + 引出起点/文字位置两个点;**文字默认从实体数据自动拼**(洞口·套管读 AecInterface,翼环读 PIPE_TOD/PIPE_YMS,阀门读 KEY_NAME,序号读 KEY_BOMNO),格式与命令一致;想覆盖就传 text / text_down。另外 kind=system 时走「系统标注」那套:读模型里的标注设置(KTModelLayoutXData 的 ScriptT/ScriptB 字段脚本),用实体数据替换 {0}~{13}(公称直径/介质/管号/压力等级/外径×壁厚/标高/保温伴热/弯头比率/材质/区号/系统/单元号);{6} 类型字段原版要查设备库,本插件不查库、留空。", "inputSchema": { "type": "object", "properties": { @@ -5676,9 +5676,10 @@ "ring", "valve", "iso_valve", - "iso_fitting" + "iso_fitting", + "system" ], - "description": "标注种类,缺省 seq" + "description": "标注种类(决定 dim style 与语义),缺省 seq;system=按模型里的\"标注设置\"字段脚本拼(统计出图→系统标注那批命令用的就是这个)" }, "points": { "type": "array", @@ -5744,6 +5745,10 @@ "elevation_base": { "type": "number", "description": "标高基准(命令里的 dElv),缺省 0" + }, + "elevation": { + "type": "number", + "description": "kind=system 时给管线标高(填 {5} 字段),缺省 0" } }, "required": [