From b951f985f9f117daf6b9d0b1b316c9457301f244 Mon Sep 17 00:00:00 2001 From: company-desktop-computer Date: Sat, 31 Oct 2026 12:28:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=A0=87=E6=B3=A8=E8=A1=A5?= =?UTF-8?q?=E4=B8=8A=E3=80=8C=E5=9C=A8=E7=BA=BF/=E7=BA=BF=E4=B8=8A/?= =?UTF-8?q?=E7=BA=BF=E4=B8=8B=E3=80=8D=E7=9A=84=E8=87=AA=E5=8A=A8=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D=EF=BC=88placement=EF=BC=89=E4=B8=8E=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E6=8E=92=E9=97=B4=E8=B7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 按 AecPlumbingDrawWDimonX 的规则把两点定位搬进工具: 管轴向 vtDir(按象限规整,第2/3象限旋转或取反到第1/4象限) 法向 vtV = 轴向绕 Z 转 90° 第1点 = pick 在管轴上的投影 + vtV × DN/2 第2点 = 第1点 + vtDir × lead_length(命令里是 500) SetDimStyle(1) + SetDimupdownSpace(DN) 新增参数: - placement = on_line(PL_ZXBZ 在线,上下排都写) / above(PL_XSBZ 线上,只上排) / below(PL_XXBZ 线下,只下排) / custom(用调用方给的 points,原行为) - pick = 在管上点一个位置(自动投影到管轴) - lead_length= 沿轴引出长度,缺省 500 - dim_updown_space = 上下排间距,缺省按放置方式(在线=管径) 返回值多给一个 points 数组(算出来的两点),方便核对。 顺带确认:引出标注/引出上标、垂直标注/垂直侧标**不用搬** —— 它们本身就是 acedGetPoint 让用户点第二点,差别只在 SetDimStyle(0)、SetDimDir(0/1)、SetDimupdownSpace(0), 现有 dim_style / dim_dir / dim_updown_space / text_up_down 参数已经能等价表达。 实测(R230 Debug,空图):DN100 管沿 +X、placement=on_line、pick=(3000,0,1000) -> 返回两点 (3000,50,1000) 与 (3500,50,1000)(法向偏 DN/2=50、沿线 +500); above 只剩上排 "100"、below 只剩下排 "114x4.0-<标高>1.000m"。 R230/Z2026 都编过。 --- .../cad_mcp_aec/aec_mcp_dim_tools.cpp | 147 +++++++++++++++++- .../Code2026/cad_mcp_aec/mcp_config.json | 30 +++- 2 files changed, 168 insertions(+), 9 deletions(-) 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 8a0e1e5..b76db83 100644 --- a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_dim_tools.cpp +++ b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_dim_tools.cpp @@ -64,6 +64,78 @@ namespace } + + // ------------------------------------------------------------------------ + // 「在线/线上/线下标注」的两点定位(照 AecPlumbingDrawWDimonX): + // 管轴向 vtDir(按象限规整,保证文字朝右上)→ 法向 vtV = 轴向绕 Z 转 90° + // 第1点 = 拾取点在管轴上的投影 + vtV * (DN/2) + // 第2点 = 第1点 + vtDir * leadLen(命令里是 500) + // DN 在库里按图纸单位存(产品的管是 mm;我们自己建的管按 AS_MUNIT 存米, + // 所以 <10 时按米换成图纸单位),与 ComposeSystemText 里的处理一致。 + bool ComputeOnlinePoints(AcDbEntity* pTarget, const AcGePoint3d& ptPick, double dLeadLen, + AcGePoint3d& pt1, AcGePoint3d& pt2, double& dDnDraw, std::wstring& err) + { + AcDbCurve* pCrv = AcDbCurve::cast(pTarget); + if (pCrv == NULL) { err = L"被标注实体不是曲线(算不出管轴)"; return false; } + + AcGePoint3d ptSta(0.0, 0.0, 0.0), ptEnd(0.0, 0.0, 0.0); + if (pCrv->getStartPoint(ptSta) != Acad::eOk || pCrv->getEndPoint(ptEnd) != Acad::eOk) + { + err = L"取不到被标注实体的起终点"; + return false; + } + + // 管径(图纸单位) + dDnDraw = 0.0; + { + AecDbObjXDataMap xObj; + AecDbCurveBase* pCurBase = AecDbCurveBase::cast(pTarget); + if (pCurBase != NULL) + xObj.CopyFrom(pCurBase->GetSpecialtyData(AcDb::kForRead)); + else + XDataOfPlain(pTarget, xObj); + xObj.GetAt(PIPE_DN, dDnDraw); + if (dDnDraw > 0.0 && dDnDraw < 10.0) dDnDraw *= 1000.0; // 米 -> 图纸单位 + } + + // 拾取点投影到管轴:ptOn = ptSta + t*(ptEnd-ptSta) + const AcGeVector3d vtAxis = ptEnd - ptSta; + const double dLen2 = vtAxis.dotProduct(vtAxis); + if (dLen2 < 1e-18) { err = L"管轴长度为 0"; return false; } + double t = (ptPick - ptSta).dotProduct(vtAxis) / dLen2; + if (t < 0.0) t = 0.0; + if (t > 1.0) t = 1.0; + AcGePoint3d ptOn = ptSta + vtAxis * t; + + // 轴向 + 法向(象限规整) + AcGeVector3d vtDir = ptEnd - ptSta; + if (vtDir.length() < 1e-9) { err = L"管轴长度为 0"; return false; } + vtDir.normalize(); + if (vtDir.isParallelTo(AcGeVector3d::kYAxis)) vtDir = AcGeVector3d::kYAxis; + if (vtDir.isParallelTo(AcGeVector3d::kXAxis)) vtDir = AcGeVector3d::kXAxis; + + AcGeVector3d vtV = vtDir; + if (vtDir.x < -1.0e-10 && vtDir.y > 1.0e-10) // 第 2 象限 + { + vtV.rotateBy(-PI / 2.0, AcGeVector3d::kZAxis); + vtDir *= -1.0; // 转成第 4 象限 + } + else if (vtDir.x < -1.0e-10 && vtDir.y < -1.0e-10) // 第 3 象限 + { + vtDir.negate(); // 转成第 1 象限 + vtV.rotateBy(-PI / 2.0, AcGeVector3d::kZAxis); + } + else + { + vtV.rotateBy(PI / 2.0, AcGeVector3d::kZAxis); + } + + ptOn += vtV * (dDnDraw * 0.5); + pt1 = ptOn; + pt2 = ptOn + vtDir * dLeadLen; + return true; + } + // ------------------------------------------------------------------------ // 「系统标注」的字段脚本引擎(等价于 PipelineCmd 里 PipelineTools::FormatDimText) // @@ -529,6 +601,11 @@ public: "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" }, + "placement": { "type": "string", "enum": [ "on_line", "above", "below", "custom" ], + "description": "放置方式:on_line 在线(上下排都写)/ above 线上(只写上排)/ below 线下(只写下排);给了就用 pick 自动算两点,不用再给 points" }, + "pick": { "type": "array", "items": { "type": "number" }, "description": "placement 用:在管上点一个位置(会自动投影到管轴)" }, + "lead_length": { "type": "number", "description": "placement 用:沿管轴的引出长度,缺省 500(命令里就是这个值)" }, + "dim_updown_space": { "type": "number", "description": "上下排文字间距,缺省按放置方式给(在线=管径,引出/垂直=0)" }, "dim_style": { "type": "integer", "description": "标注样式编号,缺省按 kind" }, "dim_dir": { "type": "integer", "description": "标注方向,缺省 0" }, "text_up_down": { "type": "integer", "description": "上下标记:1 上 / -1 下,缺省 1" }, @@ -539,7 +616,7 @@ public: "text_style": { "type": "string", "description": "文字样式,缺省 Pipe_Dim" }, "color": { "type": "integer" } }, - "required": [ "target", "points" ] + "required": [ "target" ] })"); } @@ -619,13 +696,65 @@ public: } pDim->AddDimText(sUp.c_str(), sDown.empty() ? NULL : sDown.c_str()); - bool bPointsOk = false; - AppendPoints(pDim, args, bPointsOk); - if (!bPointsOk) + AcGePoint3d ptPlaced1(0.0, 0.0, 0.0), ptPlaced2(0.0, 0.0, 0.0); + bool bHasPlaced = false; + + // 放置方式:在线/线上/线下(照 AecPlumbingDrawWDimonX 自动算两点) + const std::wstring sPlace = hasKey(args, "placement") ? wstrOr(args, "placement", L"") : std::wstring(); + double dUpdownSpace = numOr(args, "dim_updown_space", -1.0); + + if (!sPlace.empty() && sPlace != L"custom") { - delete pDim; - return errJson(kErrBadParam, L"points 要给两个点:[[引出起点],[文字位置]]"); + AcGePoint3d ptPick(0.0, 0.0, 0.0); + if (!readPoint(args, "pick", ptPick)) + { + delete pDim; + return errJson(kErrBadParam, L"placement 需要 pick(在管上点一个位置)"); + } + AcDbEntity* pT = openByHandle(sTarget, AcDb::kForRead); + AcGePoint3d pt1(0.0, 0.0, 0.0), pt2(0.0, 0.0, 0.0); + double dDnDraw = 0.0; + std::wstring sErr; + const bool bOk = ComputeOnlinePoints(pT, ptPick, numOr(args, "lead_length", 500.0), + pt1, pt2, dDnDraw, sErr); + if (pT != NULL) pT->close(); + if (!bOk) + { + delete pDim; + return errJson(kErrBadParam, sErr); + } + + pDim->SetDimStyle((short)(hasKey(args, "dim_style") ? intOr(args, "dim_style", 1) : 1)); + pDim->AppendPoint(pt1); + pDim->AppendPoint(pt2); + ptPlaced1 = pt1; // 回给调用方核对位置 + ptPlaced2 = pt2; + bHasPlaced = true; + if (dUpdownSpace < 0.0) dUpdownSpace = dDnDraw; // 命令:SetDimupdownSpace(dDn) + + // above=线上(只写上排)/ below=线下(只写下排)/ on_line=在线(两排都写) + if (!hasKey(args, "text") && !hasKey(args, "text_down")) + { + if (sPlace == L"above" && !sDown.empty()) sDown.clear(); + if (sPlace == L"below" && !sUp.empty()) sUp.clear(); + // 文字是上面拼好的,这里要重新写一遍 + CString sUpAll, sDownAll; + pDim->RemoveAll(1); + pDim->RemoveAll(-1); + pDim->AddDimText(CString(sUp.c_str()), sDown.empty() ? NULL : (LPCTSTR)CString(sDown.c_str())); + } } + else + { + bool bPointsOk = false; + AppendPoints(pDim, args, bPointsOk); + if (!bPointsOk) + { + delete pDim; + return errJson(kErrBadParam, L"points 要给两个点:[[引出起点],[文字位置]](或用 placement + pick 自动算)"); + } + } + if (dUpdownSpace >= 0.0) pDim->SetDimupdownSpace(dUpdownSpace); AcDbObjectId idNew; Acad::ErrorStatus es = addToSpace(pDim, &idNew); @@ -650,6 +779,12 @@ public: body["ok"] = true; body["type"] = "pipe_dim"; body["params"] = o; + if (bHasPlaced) + { + body["points"] = nlohmann::json::array(); + body["points"].push_back({ ptPlaced1.x, ptPlaced1.y, ptPlaced1.z }); + body["points"].push_back({ ptPlaced2.x, ptPlaced2.y, ptPlaced2.z }); + } pDim->close(); body["handle"] = HandleOfId(idNew); return okJson(body); diff --git a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json index bbb6f2a..4334c93 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。另外 kind=system 时走「系统标注」那套:读模型里的标注设置(KTModelLayoutXData 的 ScriptT/ScriptB 字段脚本),用实体数据替换 {0}~{13}(公称直径/介质/管号/压力等级/外径×壁厚/标高/保温伴热/弯头比率/材质/区号/系统/单元号);{6} 类型字段原版要查设备库,本插件不查库、留空。", + "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} 类型字段原版要查设备库,本插件不查库、留空。placement=on_line/above/below 时按命令(AecPlumbingDrawWDimonX)的规则自动定位:pick 投影到管轴 → 法向偏 DN/2 → 再沿线 lead_length(500) 得到第二个点,并只保留对应那一排文字(above 只上排 / below 只下排),上下排间距缺省取管径。", "inputSchema": { "type": "object", "properties": { @@ -5749,11 +5749,35 @@ "elevation": { "type": "number", "description": "kind=system 时给管线标高(填 {5} 字段),缺省 0" + }, + "placement": { + "type": "string", + "enum": [ + "on_line", + "above", + "below", + "custom" + ], + "description": "放置方式:on_line 在线(上下排都写)/ above 线上(只写上排)/ below 线下(只写下排);给了就用 pick 自动算两点,不用再给 points" + }, + "pick": { + "type": "array", + "items": { + "type": "number" + }, + "description": "placement 用:在管上点一个位置(自动投影到管轴)" + }, + "lead_length": { + "type": "number", + "description": "placement 用:沿管轴的引出长度,缺省 500(命令里的值)" + }, + "dim_updown_space": { + "type": "number", + "description": "上下排文字间距,缺省按放置方式(在线=管径,引出/垂直=0)" } }, "required": [ - "target", - "points" + "target" ] }, "backend": { -- 2.54.0 From eaa296d135e1c64609c0a47e7f2d24c750be5243 Mon Sep 17 00:00:00 2001 From: company-desktop-computer Date: Sat, 31 Oct 2026 12:28:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?docs:=20=E8=AE=B0=E5=BD=95=E6=A0=87?= =?UTF-8?q?=E6=B3=A8=E7=9A=84=E8=87=AA=E5=8A=A8=E5=AE=9A=E4=BD=8D=20placem?= =?UTF-8?q?ent=20=E4=B8=8E=E3=80=8C=E5=BC=95=E5=87=BA/=E5=9E=82=E7=9B=B4?= =?UTF-8?q?=E4=B8=8D=E7=94=A8=E6=90=AC=E3=80=8D=E7=9A=84=E7=BB=93=E8=AE=BA?= =?UTF-8?q?=EF=BC=88=C2=A78.9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cad-mcp-aec.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/cad-mcp-aec.md b/cad-mcp-aec.md index deaf967..32853bf 100644 --- a/cad-mcp-aec.md +++ b/cad-mcp-aec.md @@ -1114,3 +1114,40 @@ KTModelLayoutXData::ReadModelXData(KT_PIPEINIT, xDataMap) // AecRxBase 导出 **还没做**:17 个命令各自的"放置方式"(在线/线上/线下只是决定写哪一排文字;引出、垂直那几种的 点位与引出线规则还没搬),以及 {6} 类型字段的查库。 + +**「在线 / 线上 / 线下」标注的自动定位(`placement`)** + +命令那边只有这一组会**自己算两点**(`AecPlumbingDrawWDimonX`),规则照搬进工具了: + +``` +管轴向 vtDir = 管线起终点方向;先按象限规整(第2、3象限要旋转/取反到第1、4象限) +法向 vtV = 规整后的轴向绕 Z 转 90° +第1点 = pick 在管轴上的投影 + vtV × (DN/2) ← 贴着管子表面起 +第2点 = 第1点 + vtDir × lead_length(缺省 500) ← 沿管轴引出 +SetDimStyle(1),SetDimupdownSpace(DN) +``` + +`nPos` 只决定写哪一排(不改变位置): + +| placement | 对应命令 | 文字 | +| --- | --- | --- | +| `on_line` | `PL_ZXBZ` 在线标注 `WDimonX(2)` | 上下排都写 | +| `above` | `PL_XSBZ` 线上标注 `WDimonX(0)` | 只写上排 | +| `below` | `PL_XXBZ` 线下标注 `WDimonX(1)` | 只写下排 | +| `custom` | — | 用调用方给的 `points`(原行为) | + +给了 `placement` + `pick` 就不用再传 `points`;返回值里会带上算出来的两个点,方便核对。 + +**引出标注/引出上标、垂直标注/垂直侧标不用搬**:它们本来就是"用户点两个点" +(`AecPlumbingDrawWDimldrxx` / `WdImldryyx` 都是 `acedGetPoint` 取第二点), +差别只在 `SetDimStyle(0)`、`SetDimDir(0 或 1)`、`SetDimupdownSpace(0)`: + +| 想要的命令 | 现在怎么写 | +| --- | --- | +| `PL_YCBZ` 引出标注 / `PL_YCSB` 引出上标 | `dim_style=0`、`dim_dir=0`、`dim_updown_space=0`,`points` 给两点(第一点落在实体上) | +| `PL_ZZBZ` 垂直标注 | 同上,但 `dim_dir=1` | +| `PL_ZZCB` 垂直侧标 | `dim_dir=1` + `text_up_down=0` | + +**实测**(R230 Debug,空图):DN100 管沿 +X、`placement=on_line`、`pick=(3000,0,1000)` +→ 返回两点 `(3000, 50, 1000)` 与 `(3500, 50, 1000)`(法向偏 DN/2=50、沿线 +500,符合规则); +`above` 只剩上排 `100`、`below` 只剩下排 `114x4.0-<标高符号>1.000m`。 -- 2.54.0