From 51081ab8496400a2933a760b65649c2a8d4d9a82 Mon Sep 17 00:00:00 2001 From: company-desktop-computer Date: Fri, 30 Oct 2026 06:46:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=BC=80=E6=B4=9E=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=94=AF=E6=8C=81=E5=A2=99=E4=BD=93=EF=BC=88PL=5FCBKD?= =?UTF-8?q?=20=E5=A2=99=E4=BD=93=E5=BC=80=E6=B4=9E=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上一步只支持平板开洞;这次把同一个工具扩成"板/墙都能开",不再新增工具名: add_aec_opening / update_aec_opening 的 host 传板(AecDbXSlab)或墙(AecDbXWall)。 墙的处理与命令 PL_QTKDCmdFnc(Pool3dCmd/pool3dcmdCmd.cpp:13051)一致: - 法向 = 墙基线最近点的切线绕 Z 转 90°(新增 WallNormalAt 助手),也可用 direction 参数指定; - 深度缺省取墙厚(WallData.dThick); - 没给 position 时用"基线中点 + 墙底标高 + 半高"(新增 WallCenter 助手,墙没有 ClosestPointToCen); - 中心同样挪到墙厚中点,然后 SetAsHole + KEY_ASSOIC + LAY_HOLE + AppendAssocPart + 持久反应器。 - 洞口中心/法向都记在专业数据里(AECMCP_HOLE_CEN / AECMCP_HOLE_DIR),update 时复用。 实测(AutoCAD 2020 / R230 Debug,pcf_1.dwg): - 建 6m 长、200 厚、3m 高的墙(3A0),在其上开 DN800 圆洞 -> 洞口 3A4; - get_aec_entity_detail 读回 host=3A0 / no=WH-1 / position=(3000, 100, 1500) (y=100 = 墙厚一半,说明法向和"挪到厚度中点"都对); - update 改直径成功;平板开洞(矩形 800x600)回归验证仍正常。 --- .../cad_mcp_aec/aec_mcp_entity_tools.cpp | 174 ++++++++++++++---- .../Code2026/cad_mcp_aec/mcp_config.json | 4 +- 2 files changed, 143 insertions(+), 35 deletions(-) diff --git a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_entity_tools.cpp b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_entity_tools.cpp index 7226344..e1d648e 100644 --- a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_entity_tools.cpp +++ b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_entity_tools.cpp @@ -1416,9 +1416,52 @@ EXPORT_MCP_TOOL(ToolUpdateFitting, UpdateAecFittingTool) namespace { const TCHAR* kHoleCenKey = _T("AECMCP_HOLE_CEN"); // 记洞口中心,供 update 复用 + const TCHAR* kHoleDirKey = _T("AECMCP_HOLE_DIR"); // 记洞口法向(墙厚方向) - bool ApplyHole(AecDbX3dPartEntity* pPart, AecDbXSlab* pSlab, - const AcGePoint3d& ptCen, double dDepth, const nlohmann::json& a, bool bCreate, std::wstring& err) + // 墙的放样中心:基线中点(墙没有 ClosestPointToCen) + void WallCenter(AecDbXWall* pWall, AcGePoint3d& ptCen) + { + if (pWall == NULL) return; + AcDbCurve* pBase = pWall->GetBaseCurve(false); + if (pBase == NULL) return; + AcGePoint3d ptS, ptE; + if (pBase->getStartPoint(ptS) == Acad::eOk && pBase->getEndPoint(ptE) == Acad::eOk) + ptCen = AcGePoint3d((ptS.x + ptE.x) * 0.5, (ptS.y + ptE.y) * 0.5, ptCen.z); + delete pBase; + } + + // 墙厚方向:在墙基线上取最近点,把切线绕 Z 转 90 度(与 PL_QTKDCmdFnc 的算法一致) + bool WallNormalAt(AecDbXWall* pWall, const AcGePoint3d& ptOn, AcGeVector3d& vtNormal) + { + if (pWall == NULL) return false; + + AcDbCurve* pBase = pWall->GetBaseCurve(false); + if (pBase == NULL) return false; + + AcGePoint3d ptWall; + bool bOk = (pBase->getClosestPointTo(ptOn, ptWall, Adesk::kFalse) == Acad::eOk); + if (bOk) + { + AcGeVector3d vt; + bOk = (pBase->getFirstDeriv(ptWall, vt) == Acad::eOk); + if (bOk) + { + vt.rotateBy(PI / 2.0, AcGeVector3d::kZAxis); + vt.z = 0.0; + if (vt.length() > 1e-9) + vt.normalize(); + else + bOk = false; + vtNormal = vt; + } + } + delete pBase; + return bOk; + } + + bool ApplyHole(AecDbX3dPartEntity* pPart, AcDbEntity* pHost, + const AcGePoint3d& ptCen, double dDepth, const AcGeVector3d& vtDir, + const nlohmann::json& a, bool bCreate, std::wstring& err) { // 形状:circle / rect int nShape = 0; // 0 圆 1 矩形 @@ -1439,7 +1482,8 @@ namespace const double dH = numOr(a, "height", 0.0); const bool bNozz = hasKey(a, "nozzle") ? (intOr(a, "nozzle", 0) != 0) : false; - AcGeVector3d vtZ = AcGeVector3d::kZAxis; + AcGeVector3d vtZ = vtDir; + if (vtZ.length() < 1e-9) vtZ = AcGeVector3d::kZAxis; vtZ.normalize(); if (nShape == 0) @@ -1471,6 +1515,7 @@ namespace // 记录中心,方便后续 update(SetAsHole 自己会把 KEY_NOPOS 挪到侧边) pPart->GetSpecialtyData()->SetAt(kHoleCenKey, ptCen); + pPart->GetSpecialtyData()->SetAt(kHoleDirKey, vtZ); if (hasKey(a, "no")) pPart->GetSpecialtyData()->SetAt(KEY_NO, wstrOr(a, "no", L"").c_str()); @@ -1479,7 +1524,7 @@ namespace if (bCreate) { - pPart->GetSpecialtyData()->SetAt(KEY_ASSOIC, pSlab->objectId()); + pPart->GetSpecialtyData()->SetAt(KEY_ASSOIC, pHost->objectId()); } return true; } @@ -1492,9 +1537,9 @@ public: std::string private_description() const override { - return "在板上开洞(对应菜单命令 平板开洞 PL_CDKD):给母体板的 handle 与洞口参数," - "生成 AecDbX3dPartEntity 并自动与板做布尔、挂到板下(LAY_HOLE 图层)。" - "尺寸用图纸单位;depth 缺省取板厚。返回洞口实体的 handle。"; + return "在板或墙上开洞(对应菜单命令 平板开洞 PL_CDKD / 墙体开洞 PL_CBKD):给母体的 handle 与洞口参数," + "生成 AecDbX3dPartEntity 并自动与母体做布尔、挂到母体下(LAY_HOLE 图层)。" + "尺寸用图纸单位;depth 缺省取母体厚度(板厚/墙厚)。洞口方向自动取板法向或墙厚方向。返回洞口实体 handle。"; } nlohmann::json private_input_schema() const override @@ -1532,35 +1577,73 @@ public: if (pEnt == NULL) return errJson(kErrNotFound, L"按 handle 打不开母体:" + utf8ToWstr(sHost)); + // 母体可以是板(Z 方向开洞)或墙(沿墙厚方向开洞) AecDbXSlab* pSlab = AecDbXSlab::cast(pEnt); - if (pSlab == NULL) + AecDbXWall* pWall = (pSlab == NULL) ? AecDbXWall::cast(pEnt) : NULL; + if (pSlab == NULL && pWall == NULL) { const std::string sCls = classNameOf(pEnt); pEnt->close(); return errJson(kErrWrongType, L"handle " + utf8ToWstr(sHost) + L" 是 " + - utf8ToWstr(sCls) + L",不是板(AecDbXSlab)"); + utf8ToWstr(sCls) + L",不是板(AecDbXSlab)或墙(AecDbXWall)"); } - // 洞口中心:没给就用板中心 + // 洞口中心:没给就用母体中心(板=板中心,墙=基线中点) AcGePoint3d ptCen(0.0, 0.0, 0.0); - if (!readPoint(args, "position", ptCen)) - pSlab->ClosestPointToCen(ptCen); + const bool bHasPos = readPoint(args, "position", ptCen); - const double dThick = numOr(args, "depth", pSlab->GetThick()); - if (dThick <= 0.0) + AcGeVector3d vtDir = AcGeVector3d::kZAxis; // 洞口法向 = 深度方向 + double dDepth = numOr(args, "depth", 0.0); + + if (pSlab != NULL) { - pSlab->close(); - return errJson(kErrBadParam, L"板厚取不到,请显式给 depth"); + if (!bHasPos) + pSlab->ClosestPointToCen(ptCen); + if (dDepth <= 0.0) + dDepth = pSlab->GetThick(); + if (dDepth <= 0.0) + { + pSlab->close(); + return errJson(kErrBadParam, L"板厚取不到,请显式给 depth"); + } } - // 命令里是把中心挪到板厚中点 - ptCen += AcGeVector3d::kZAxis * 0.5 * dThick; + else + { + WallData wd; + ::memset(&wd, 0, sizeof(WallData)); + pWall->GetWallData(wd); + if (dDepth <= 0.0) + dDepth = wd.dThick; + if (dDepth <= 0.0) + { + pWall->close(); + return errJson(kErrBadParam, L"墙厚取不到,请显式给 depth"); + } + if (!bHasPos) + { + // 墙基线中点 + 墙底标高 + 半高 + WallCenter(pWall, ptCen); + ptCen.z = wd.dBomEl + 0.5 * wd.dH; + } + // 法向 = 墙厚方向;给了 direction 就用给的 + AcGePoint3d ptGiven; + if (readPoint(args, "direction", ptGiven)) + vtDir = ptGiven.asVector(); + else if (!WallNormalAt(pWall, ptCen, vtDir)) + vtDir = AcGeVector3d::kZAxis; + } + + // 命令里是把中心挪到厚度中点 + AcGeVector3d vtUnit = vtDir; + vtUnit.normalize(); + ptCen += vtUnit * 0.5 * dDepth; AecDbX3dPartEntity* pPart = new AecDbX3dPartEntity(); std::wstring err; - if (!ApplyHole(pPart, pSlab, ptCen, dThick, args, true, err)) + if (!ApplyHole(pPart, pEnt, ptCen, dDepth, vtDir, args, true, err)) { delete pPart; - pSlab->close(); + pEnt->close(); return errJson(kErrBadParam, err); } @@ -1585,15 +1668,18 @@ public: if (es != Acad::eOk) { delete pPart; - pSlab->close(); + pEnt->close(); return errJson(kErrInternal, std::wstring(L"加入模型空间失败,err=") + std::to_wstring((int)es)); } // 与母体建立关联:持久反应器 + 母体的关联件表(绘制时母体据此做布尔) - pPart->addPersistentReactor(pSlab->objectId()); - pSlab->AppendAssocPart(idHole); + pPart->addPersistentReactor(pEnt->objectId()); + if (AecDbXSlab* pS = AecDbXSlab::cast(pEnt)) + pS->AppendAssocPart(idHole); + else if (AecDbXWall* pW = AecDbXWall::cast(pEnt)) + pW->AppendAssocPart(idHole); pPart->close(); - pSlab->close(); + pEnt->close(); nlohmann::json body; body["type"] = "opening"; @@ -1641,40 +1727,62 @@ public: AecDbX3dPartEntity* pPart = openTyped(args, L"AecDbX3dPartEntity", err); if (pPart == NULL) return err; - // 母体与中心:母体从关联数据里取,中心用创建时记下的那个 + // 母体与中心/法向:都从创建时记下的数据里取,拿不到再按母体重算 AcDbObjectId idHost; pPart->GetSpecialtyData()->GetAt(KEY_ASSOIC, idHost); - AecDbXSlab* pSlab = NULL; + AcDbEntity* pHost = NULL; if (!idHost.isNull()) - acdbOpenObject(pSlab, idHost, AcDb::kForRead); + acdbOpenObject(pHost, idHost, AcDb::kForRead); + AecDbXSlab* pSlab = (pHost != NULL) ? AecDbXSlab::cast(pHost) : NULL; + AecDbXWall* pWall = (pSlab == NULL && pHost != NULL) ? AecDbXWall::cast(pHost) : NULL; AcGePoint3d ptCen(0.0, 0.0, 0.0); if (!readPoint(args, "position", ptCen) && !pPart->GetSpecialtyData()->GetAt(kHoleCenKey, ptCen)) { - if (pSlab != NULL) pSlab->ClosestPointToCen(ptCen); + if (pSlab != NULL) pSlab->ClosestPointToCen(ptCen); + else if (pWall != NULL) WallCenter(pWall, ptCen); } double dDepth = numOr(args, "depth", 0.0); if (dDepth <= 0.0 && pSlab != NULL) dDepth = pSlab->GetThick(); + if (dDepth <= 0.0 && pWall != NULL) + { + WallData wd; + ::memset(&wd, 0, sizeof(WallData)); + pWall->GetWallData(wd); + dDepth = wd.dThick; + } if (dDepth <= 0.0) { - if (pSlab != NULL) pSlab->close(); + if (pHost != NULL) pHost->close(); pPart->close(); return errJson(kErrBadParam, L"取不到深度,请显式给 depth"); } - std::wstring msg; - if (!ApplyHole(pPart, pSlab, ptCen, dDepth, args, false, msg)) + // 法向:优先用创建时记下的;没有就按母体重算(墙=墙厚方向,板=Z) + AcGeVector3d vtDir = AcGeVector3d::kZAxis; + AcGePoint3d ptDirGiven; + if (readPoint(args, "direction", ptDirGiven)) + vtDir = ptDirGiven.asVector(); + else if (!pPart->GetSpecialtyData()->GetAt(kHoleDirKey, vtDir)) { - if (pSlab != NULL) pSlab->close(); + if (pWall != NULL && !WallNormalAt(pWall, ptCen, vtDir)) + vtDir = AcGeVector3d::kZAxis; + } + + std::wstring msg; + if (!ApplyHole(pPart, pHost, ptCen, dDepth, vtDir, args, false, msg)) + { + if (pHost != NULL) pHost->close(); pPart->close(); return errJson(kErrBadParam, msg); } - if (pSlab != NULL) pSlab->close(); + if (pHost != NULL) pHost->close(); return finishUpdate(pPart, args["handle"].get(), "opening"); } }; + EXPORT_MCP_TOOL(ToolUpdateOpening, UpdateAecOpeningTool) diff --git a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json index 72dbd83..71eabdf 100644 --- a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json +++ b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json @@ -2069,13 +2069,13 @@ }, { "name": "add_aec_opening", - "description": "在板上开洞(对应菜单命令 平板开洞 PL_CDKD):给母体板的 handle 与洞口参数,生成洞口实体(AecDbX3dPartEntity)并自动与板做布尔、挂到板下(LAY_HOLE 图层)。尺寸用图纸单位;depth 缺省取板厚。返回洞口实体的 handle。", + "description": "在板或墙上开洞(对应菜单命令 平板开洞 PL_CDKD / 墙体开洞 PL_CBKD):给母体(板或墙)的 handle 与洞口参数,生成洞口实体(AecDbX3dPartEntity)并自动与母体做布尔、挂到母体下(LAY_HOLE 图层)。尺寸用图纸单位;depth 缺省取母体厚度(板厚/墙厚),洞口方向自动取板法向或墙厚方向。返回洞口实体 handle。", "inputSchema": { "type": "object", "properties": { "host": { "type": "string", - "description": "母体板的 handle(AecDbXSlab)" + "description": "母体 handle:板(AecDbXSlab)或墙(AecDbXWall)" }, "shape": { "type": "string", -- 2.54.0 From 00994bb352c5fbd8fef597039bf06398730c5791 Mon Sep 17 00:00:00 2001 From: company-desktop-computer Date: Fri, 30 Oct 2026 06:46:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?docs:=20=E5=AF=B9=E7=85=A7=E8=A1=A8?= =?UTF-8?q?=E6=8A=8A=20PL=5FCBKD=20=E5=A2=99=E4=BD=93=E5=BC=80=E6=B4=9E?= =?UTF-8?q?=E6=A0=87=E4=B8=BA=E5=B7=B2=E5=AE=9E=E7=8E=B0=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E8=A1=A5=E5=A2=99=E5=BC=80=E6=B4=9E=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 墙体开洞与平板开洞共用 add_aec_opening / update_aec_opening(host 传板或墙): 法向取墙基线切线转 90 度、深度取墙厚、中心自动挪到厚度中点; 附实测(200 厚墙开 DN800 洞,中心 y=100 即墙厚一半)。异形洞(PL_YXKD)仍未接。 --- cad-mcp-aec.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cad-mcp-aec.md b/cad-mcp-aec.md index 9cfe7fa..96e8195 100644 --- a/cad-mcp-aec.md +++ b/cad-mcp-aec.md @@ -322,17 +322,21 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命 |IS_CRBJ|插入变径|AecDbEwFitting|add_aec_fitting|update_aec_fitting| |PL_CDKD|平板开洞|AecDbX3dPartEntity|add_aec_opening|update_aec_opening| -|PL_CBKD|墙体开洞|AecDbX3dPartEntity|(未实现:墙体母体还没接)|| +|PL_CBKD|墙体开洞|AecDbX3dPartEntity|add_aec_opening|update_aec_opening| |PL_YXKD|异形开洞|AecDbX3dPartEntity|(未实现:异形点串格式未接)|| |PL_ZLKD|阵列开洞|AecDbX3dPartEntity|(未实现)|| |PL_YXCG|穿管开洞|AecDbX3dPartEntity|(未实现)|| -> 开洞(上表 PL_CDKD 一行):洞不是普通实体,是 `AecDbX3dPartEntity` + 对母体做布尔, +> 开洞(上表 PL_CDKD / PL_CBKD):洞不是普通实体,是 `AecDbX3dPartEntity` + 对母体做布尔, > 工具收 `host`(板的 handle)+ 洞口参数,内部照 `PL_CDKDCmdFnc` > (Pool3dCmd/pool3dcmdCmd.cpp:14763)的序列:`SetAsHole(中心,尺寸,板厚,法向)` > → `KEY_ASSOIC` 记母体 → `LAY_HOLE` 图层 → 入库 → 给母体 `AppendAssocPart` + > `addPersistentReactor`。已实测:在新建的板上开 DN600 圆洞成功,读回 > `host/no/position`(z 自动落在板厚中点)。目前只支持**平板 + 圆/矩形**; -> 墙体开洞(母体是墙)和异形洞(点串脚本格式)还没接。 +> **墙**(PL_CBKD / PL_TBKD 同族):同一个工具,`host` 传墙的 handle 即可 —— +> 法向取"墙基线最近点切线绕 Z 转 90°"(与 `PL_QTKDCmdFnc` 一致),深度缺省取墙厚, +> 中心会自动挪到墙厚中点。已实测:3m 高、200 厚的墙上开 DN800 圆洞, +> 读回 center=(3000, **100**, 1500)(y=100 正是墙厚一半),改直径后仍正常。 +> 异形洞(点串脚本格式,PL_YXKD)还没接。 > 管件族(上表最后 39 行):这些都是同一个实体类 `AecDbEwFitting`,只靠专业数据 > `KEY_RUNTIME` 区分(弯头/变径弯头/三通/四通/大小头/法兰/堵头/箍), -- 2.54.0