From cabdd0601e2a384a678ac1b19d9db230d753f2ec Mon Sep 17 00:00:00 2001 From: company-desktop-computer Date: Fri, 30 Oct 2026 22:05:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=BC=80=E6=B4=9E=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BB=BB=E6=84=8F=20AecDbBDPipeBase=20=E6=AF=8D?= =?UTF-8?q?=E4=BD=93=EF=BC=88=E5=BC=82=E5=BD=A2=E6=9E=84=E7=AD=91=E7=89=A9?= =?UTF-8?q?/=E6=9F=B1/=E6=A2=81/=E5=A0=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原来 add_aec_opening 只认板/墙。其实洞口挂载用的是 AecDbBDPipeBase 上的通用接口 (AppendAssocPart + 绘制时 BoolSubtractAssoc),所以异形构筑物等实体一样能开洞。 - 母体判断放宽到 AecDbBDPipeBase;AppendAssocPart 统一走 pBase - 板/墙保持原来的缺省(Z / 墙厚方向 / 板厚 / 墙厚) - 其它母体没有"厚度"概念:必须给 direction,position 缺省用包围盒中心, 洞深缺省 = 母体沿法向的尺寸(打穿整个实体) - 开完调母体 ReCreateDraw3d(),与造型工具一致 两个实测撞出来的坑: 1. AecDb* 实体的 3D 缓存没建时,getGeomExtents() 照样返回 eOk,但给的是"未设置"的 ±1e20。直接算洞深会得到 2e20,洞心飞到 1e20。现在 entityBBox() 校验这种值 (>1e19 或 min>max 判失败),并新增 HostSizeAlong():bbox 不可用时当场向实体要 一份 3D solid 来量,量完删掉。 2. 穿管开洞不能挪半深:其它洞的 position 是"厚度方向的起点(面/底面)",工具会自己 +depth/2 挪到厚度中点;但 PL_YXCG 命令是拿管线与实体交点中点当洞心,position 已经 是洞心。所以 source 存在时跳过偏移,否则洞会贴在面上。 实测(空图,R230 Debug):异形构筑物 + 1000x1000x1000 立方体(x,y∈[-500,500], z∈[0,1000]) - 穿管开洞:管道 DN200 沿 X 穿过,source 定位 -> 洞心 (0,0,500)、外径 0.20、洞深自动 1000 - 顶面圆洞:position=[0,0,1000]、direction=[0,0,-1]、D300/深1200 -> 洞心 (0,0,400) - 侧面异形洞:position=[0,-500,500]、direction=[0,1,0]、400x400 多边形 -> 洞心 (0,100,500) 三个洞口图层都是 HOLE,都挂在构筑物的关联件表里(Draw3d 时自动扣掉)。 --- .../Code2026/cad_mcp_aec/aec_mcp_common.cpp | 16 ++- .../cad_mcp_aec/aec_mcp_entity_tools.cpp | 99 +++++++++++++++---- .../Code2026/cad_mcp_aec/mcp_config.json | 11 ++- 3 files changed, 104 insertions(+), 22 deletions(-) diff --git a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_common.cpp b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_common.cpp index e965e4e..fb95135 100644 --- a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_common.cpp +++ b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_common.cpp @@ -261,8 +261,20 @@ bool entityBBox(AcDbEntity* pEnt, AcGePoint3d& ptMin, AcGePoint3d& ptMax) { AcDbExtents ext; if (pEnt->getGeomExtents(ext) != Acad::eOk) return false; - ptMin = ext.minPoint(); - ptMax = ext.maxPoint(); + + // AecDb* 实体的 3D 缓存还没建时,getGeomExtents 照样返回 eOk, + // 但给的是"未设置"值 ±1e20 —— 直接当有效值用会把洞深算成 2e20。 + const AcGePoint3d mn = ext.minPoint(); + const AcGePoint3d mx = ext.maxPoint(); + for (int i = 0; i < 3; ++i) + { + const double a = (i == 0) ? mn.x : (i == 1) ? mn.y : mn.z; + const double b = (i == 0) ? mx.x : (i == 1) ? mx.y : mx.z; + if (fabs(a) > 1e19 || fabs(b) > 1e19) return false; + if (a > b) return false; + } + ptMin = mn; + ptMax = mx; return true; } catch (...) 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 d3e6af0..b1778eb 100644 --- a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_entity_tools.cpp +++ b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_entity_tools.cpp @@ -1835,6 +1835,34 @@ namespace } } + // 母体沿某方向的尺寸 = 洞深缺省值。 + // 3D 缓存没建时 entityBBox 拿不到,就当场要一份 3D solid 来量(不挂缓存,量完删掉)。 + bool HostSizeAlong(AecDbBDPipeBase* pBase, const AcGeVector3d& vtDir, double& dOut) + { + dOut = 0.0; + if (pBase == NULL) return false; + + AcGeVector3d vtN = vtDir; + vtN.normalize(); + + AcGePoint3d ptMin(0.0, 0.0, 0.0), ptMax(0.0, 0.0, 0.0); + if (entityBBox(pBase, ptMin, ptMax)) + { + dOut = fabs((ptMax - ptMin).dotProduct(vtN)); + if (dOut > 1e-9) return true; + } + + AcDb3dSolid* pSolid = pBase->GetDraw3dSolid(false, 0, false); // 不扣洞,量原始体 + if (pSolid == NULL) return false; + AcDbExtents ext; + const bool bOk = (pSolid->getGeomExtents(ext) == Acad::eOk); + delete pSolid; + if (!bOk) return false; + + dOut = fabs((ext.maxPoint() - ext.minPoint()).dotProduct(vtN)); + return dOut > 1e-9; + } + // 套管:同一类 AecDbX3dPartEntity,但用 SetAsPipe 而不是 SetAsHole。 // 命令里(PL_CDKD / PL_QTKD 的 dlg.m_bHasCase 分支): // SetAsPipe(ptOrg, nShape, dlg.m_dDL, dlg.m_dW, dlg.m_dT, 套管长, bExt, dEx1, dEx2, 法向) @@ -1954,14 +1982,14 @@ public: return nlohmann::json::parse(R"({ "type": "object", "properties": { - "host": { "type": "string", "description": "母体板的 handle(AecDbXSlab)" }, + "host": { "type": "string", "description": "母体 handle:板/墙,或任意 AecDbBDPipeBase 派生实体(异形构筑物/柱/梁/堰);后几种必须给 direction" }, "shape": { "type": "string", "enum": [ "circle", "rect" ], "description": "洞口形状,缺省 circle" }, "position": { "type": "array", "items": { "type": "number" }, - "description": "洞口中心 [x,y] 或 [x,y,z];不给则用板中心" }, + "description": "洞口位置 [x,y] 或 [x,y,z]:普通洞是洞在厚度方向的起点(面/底面),穿管洞(source)直接是洞心;不给则用母体中心" }, "diameter": { "type": "number", "description": "圆洞直径,图纸单位" }, "width": { "type": "number", "description": "矩形洞宽(X 向)" }, "height": { "type": "number", "description": "矩形洞高(Y 向)" }, - "depth": { "type": "number", "description": "洞深,缺省取板厚" }, + "depth": { "type": "number", "description": "洞深:板缺省=板厚、墙缺省=墙厚、其它母体缺省=沿 direction 的实体尺寸" }, "nozzle": { "type": "boolean", "description": "是否要管嘴(缺省否)" }, "no": { "type": "string", "description": "洞口编号" }, "for_use":{ "type": "string", "description": "洞口用途" }, @@ -2002,15 +2030,17 @@ public: if (pEnt == NULL) return errJson(kErrNotFound, L"按 handle 打不开母体:" + utf8ToWstr(sHost)); - // 母体可以是板(Z 方向开洞)或墙(沿墙厚方向开洞) + // 母体:板(Z 方向开洞)、墙(沿墙厚方向)或任意 AecDbBDPipeBase + // (异形构筑物/柱/梁/堰/设备)——后几种没有"厚度"概念,必须给 position/direction AecDbXSlab* pSlab = AecDbXSlab::cast(pEnt); AecDbXWall* pWall = (pSlab == NULL) ? AecDbXWall::cast(pEnt) : NULL; - if (pSlab == NULL && pWall == NULL) + AecDbBDPipeBase* pBase = AecDbBDPipeBase::cast(pEnt); + if (pBase == NULL) { const std::string sCls = classNameOf(pEnt); pEnt->close(); return errJson(kErrWrongType, L"handle " + utf8ToWstr(sHost) + L" 是 " + - utf8ToWstr(sCls) + L",不是板(AecDbXSlab)或墙(AecDbXWall)"); + utf8ToWstr(sCls) + L",不能开洞(需要板/墙/异形构筑物等 AecDbBDPipeBase 派生实体)"); } // 洞口中心:没给就用母体中心(板=板中心,墙=基线中点) @@ -2032,17 +2062,17 @@ public: dDepth = pSlab->GetThick(); if (dDepth <= 0.0) { - pSlab->close(); + pEnt->close(); return errJson(kErrBadParam, L"板厚取不到,请显式给 depth"); } } - else + else if (pWall != NULL) { if (dDepth <= 0.0) dDepth = wd.dThick; if (dDepth <= 0.0) { - pWall->close(); + pEnt->close(); return errJson(kErrBadParam, L"墙厚取不到,请显式给 depth"); } if (!bHasPos) @@ -2058,11 +2088,46 @@ public: else if (!WallNormalAt(pWall, ptCen, vtDir)) vtDir = AcGeVector3d::kZAxis; } + else + { + // 其它 AecDbBDPipeBase(异形构筑物/柱/梁/堰…):没有"厚度",得靠参数 + AcGePoint3d ptGiven; + if (readPoint(a, "direction", ptGiven) && ptGiven.asVector().length() > 1e-9) + vtDir = ptGiven.asVector(); + else + { + pEnt->close(); + return errJson(kErrBadParam, L"这种母体没有固定厚度/法向,请给 direction(洞口法向)"); + } - // 命令里是把中心挪到厚度中点 + if (!bHasPos) + { + AcGePoint3d ptMin, ptMax; + if (!entityBBox(pEnt, ptMin, ptMax)) + { + pEnt->close(); + return errJson(kErrBadParam, L"取不到母体中心,请给 position"); + } + ptCen = AcGePoint3d(0.5 * (ptMin.x + ptMax.x), 0.5 * (ptMin.y + ptMax.y), 0.5 * (ptMin.z + ptMax.z)); + } + + // 洞深:没给就用母体沿法向的尺寸(打穿整个实体) + if (dDepth <= 0.0) + HostSizeAlong(pBase, vtDir, dDepth); + if (dDepth <= 0.0) + { + pEnt->close(); + return errJson(kErrBadParam, L"算不出洞深,请给 depth"); + } + } + + // 命令里是把中心挪到厚度中点。 + // 但穿管开洞(PL_YXCG)例外:命令直接用管线与实体交点的中点当洞心, + // 这时 position 给的就是"洞心",不能再挪半深,否则洞会贴在面上。 AcGeVector3d vtUnit = vtDir; vtUnit.normalize(); - ptCen += vtUnit * 0.5 * dDepth; + if (!hasKey(a, "source")) + ptCen += vtUnit * 0.5 * dDepth; // 穿管开洞(PL_YXCG):source 给管线 handle,洞口中心取"管线轴线与母体中面"的交点, // 直径缺省取管道外径(PIPE_OD 已是图纸单位)。 @@ -2077,7 +2142,7 @@ public: if (pCur == NULL) { if (pSrc != NULL) pSrc->close(); - if (pSlab != NULL) pSlab->close(); else pWall->close(); + pEnt->close(); return errJson(kErrWrongType, L"source 必须是曲线类管线(管道/风管/桥架),handle=" + utf8ToWstr(sIn)); } @@ -2157,10 +2222,8 @@ public: // 与母体建立关联:持久反应器 + 母体的关联件表(绘制时母体据此做布尔) pPart->addPersistentReactor(pEnt->objectId()); - if (pSlab != NULL) - pSlab->AppendAssocPart(idHole); - else - pWall->AppendAssocPart(idHole); + pBase->AppendAssocPart(idHole); + pBase->ReCreateDraw3d(); // 母体 3D 缓存要重建(命令里是 regen) pPart->close(); return handleOfId(idHole); }; @@ -2194,14 +2257,14 @@ public: const std::string sH = makeOne(pt); if (sH.empty()) { - if (pSlab != NULL) pSlab->close(); else pWall->close(); + pEnt->close(); return errJson(kErrBadParam, !err.empty() ? err : utf8ToWstr(sFail)); } arHandles.push_back(sH); } } - if (pSlab != NULL) pSlab->close(); else pWall->close(); + pEnt->close(); nlohmann::json body; body["type"] = bCasing ? "casing" : "opening"; diff --git a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json index eda9492..f929e0e 100644 --- a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json +++ b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json @@ -2070,13 +2070,13 @@ }, { "name": "add_aec_opening", - "description": "在板或墙上开洞(PL_CDKD 平板 / PL_CBKD 墙体 / PL_ZLKD 阵列 / PL_YXCG 穿管),也可以做成套管:给母体(板或墙)handle 与洞口参数,生成 AecDbX3dPartEntity 并自动与母体布尔、挂到母体下(洞=LAY_HOLE / 套管=LAY_CASEPIPE)。尺寸用图纸单位;depth 缺省取母体厚度;方向自动取板法向或墙厚方向。阵列给 rows/columns + spacing_x/spacing_y;穿管开洞给 source=管线 handle(圆管道自动取外径);casing=true 走 SetAsPipe。返回 handle,阵列时另给 handles 数组。", + "description": "在板/墙/异形构筑物等 AecDbBDPipeBase 实体上开洞:PL_CDKD 平板 / PL_CBKD 墙体 / PL_ZLKD 阵列 / PL_YXCG 穿管 / PL_YXKD 异形(shape=polygon)。建 AecDbX3dPartEntity 并自动与母体布尔、挂到母体下(洞=LAY_HOLE / 套管=LAY_CASEPIPE)。尺寸用图纸单位;板缺省 depth=板厚、墙缺省=墙厚,其它母体缺省=沿法向的实体尺寸;方向缺省板=Z、墙=墙厚方向。阵列给 rows/columns + spacing_x/y;穿管开洞给 source=管线 handle(圆管道自动取外径);casing=true 走 SetAsPipe。返回 handle,阵列另给 handles 数组。", "inputSchema": { "type": "object", "properties": { "host": { "type": "string", - "description": "母体 handle:板(AecDbXSlab)或墙(AecDbXWall)" + "description": "母体 handle:板/墙,或任意 AecDbBDPipeBase 派生实体(异形构筑物/柱/梁/堰)。后几种没有固定厚度,必须给 direction,洞深缺省取母体沿法向尺寸" }, "shape": { "type": "string", @@ -2202,6 +2202,13 @@ "spacing_y": { "type": "number", "description": "阵列行间距(墙=竖向 / 板=Y 方向)" + }, + "direction": { + "type": "array", + "items": { + "type": "number" + }, + "description": "洞口法向(洞往这个方向开)。板缺省 Z、墙缺省墙厚方向;异形构筑物等其它母体必填" } }, "required": [ -- 2.54.0 From 392e5495afabb7be13599056c27ad5e6ec3b6120 Mon Sep 17 00:00:00 2001 From: company-desktop-computer Date: Fri, 30 Oct 2026 22:05:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?docs:=20=E8=AE=B0=E5=BD=95=E5=9C=A8?= =?UTF-8?q?=E5=BC=82=E5=BD=A2=E6=9E=84=E7=AD=91=E7=89=A9=E4=B8=8A=E5=BC=80?= =?UTF-8?q?=E6=B4=9E=EF=BC=88=C2=A78.8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 母体分板/墙/其它三类时 position、direction、depth 的取值规则; - 两个坑:3D 缓存未建时 getGeomExtents 返回 ±1e20(entityBBox 校验 + HostSizeAlong 现场量 solid);穿管开洞 position 已是洞心,不能挪半深; - 多边形异形洞的方向说明(SetAsHole 内部沿 ±vtZ 各拉 dH/2,前提是法向平行/垂直于 XY 平面;斜法向会返回 false,未测); - 实测数据:穿管洞 (0,0,500)、顶面圆洞 (0,0,400)、侧面多边形洞 (0,100,500)。 --- cad-mcp-aec.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/cad-mcp-aec.md b/cad-mcp-aec.md index aa86170..89243d2 100644 --- a/cad-mcp-aec.md +++ b/cad-mcp-aec.md @@ -604,3 +604,54 @@ PL_DTYG 对话框上的几何体现在**全部支持**: `AecDbX3dPart::AddX3dSolid / SetOrgPoint / SetAxis / SetName / setBimDatas`、 `AecDbBDPipeBase::AddX3dPart / GetX3dPart / RemoveX3dPart / GetX3dPartCount`、 `AecDbMultiPartEntity::SetBaseCurve / SetSection / SetOrg / SetXDir(Y,Z)`。 + +### 8.8 在异形构筑物(AecDbMultiPartEntity)上开洞 + +开洞工具原来只认板/墙(`AecDbXSlab` / `AecDbXWall`)。实际上洞口挂载靠的是一对通用接口 +(`AppendAssocPart` + 绘制时的 `BoolSubtractAssoc`),它们在 **`AecDbBDPipeBase`** 上, +所以异形构筑物、柱、梁、堰都能开洞 —— 现在 `add_aec_opening` 的 host 放宽到任意 +`AecDbBDPipeBase` 派生实体。 + +母体会分三类处理: + +| 母体 | 位置 | 法向 | 洞深 | +| --- | --- | --- | --- | +| 板 | 缺省板中心 | Z | 板厚 | +| 墙 | 缺省基线中点 + 半高 | 墙厚方向 | 墙厚 | +| 其它(构筑物/柱/梁/堰) | 必须给 `position`,缺省用包围盒中心 | **必须给 `direction`** | 缺省 = 沿法向的实体尺寸 | + +**两个坑(这轮实测撞出来的)**: + +1. `AecDb*` 实体的 3D 缓存还没建时,`getGeomExtents()` **照样返回 eOk,但给的是"未设置"的 + ±1e20**。直接拿来算洞深会得到 2e20,洞心飞到天上去(实测 x=1e20)。 + 现在 `entityBBox()` 会校验这种值(>`1e19` 或 min>max 就判失败), + 并且新增 `HostSizeAlong()`:bbox 不可用时当场向实体要一份 3D solid 来量,量完删掉。 +2. **穿管开洞不能挪半深**。其它洞的 `position` 是"厚度方向的起点(面/底面)", + 工具会自己 +depth/2 挪到厚度中点;但 `PL_YXCG` 命令是拿管线与实体两个交点的中点当洞心, + 这时的 `position` 已经是洞心。所以 `source` 存在时跳过那个偏移,否则洞会贴在面上。 + +**实测**(R230 Debug,空图): + +``` +add_aec_multipart -> 310 +add_aec_shape(shape=box, 1000x1000x1000, 中心在原点) -> x,y ∈ [-500,500], z ∈ [0,1000] +add_aec_pipe(-2500,0,500 → 2500,0,500, DN200) -> 311(沿 X 轴穿过立方体) +add_aec_opening(host=310, source=311, + position=[0,0,500], direction=[1,0,0]) + -> 洞心 (0,0,500)、source_diameter 0.20、图层 HOLE,洞深自动取 1000 +add_aec_opening(host=310, shape=circle, position=[0,0,1000], + direction=[0,0,-1], diameter=300, depth=1200) + -> 洞心 (0,0,400)(从 z=1000 的顶面反着法向开进去) +add_aec_opening(host=310, shape=polygon, position=[0,-500,500], + direction=[0,1,0], depth=1200, points=400x400 方) + -> 洞心 (0,100,500)(侧面异形洞) +``` + +三个洞都挂在构筑物的关联件表里,`AecDbBDPipeBase::Draw3d` → `GetDraw3dSolid` → +`BoolSubtractAssoc` 会自动扣掉,不需要额外 regen。 + +**关于多边形异形洞的方向**:`SetAsHole(pt, 点串, dH, vtZ)` 内部会先取点串所在平面的 +最近点、把轮廓平移到洞心,再沿 `±vtZ` 各拉伸 `dH/2`(见 `AecDbX3dPartEntity.cpp` 里 +"以中心两方向减"那段),所以法向不是 Z 也能用。前提是 `vtZ` 要么平行、要么垂直于 XY 平面 +(`AcGePlane::kXYPlane.isParallelTo / isPerpendicularTo` 两个分支),斜法向会直接返回 false。 +本次实测的是侧面(法向 +Y)多边形洞,能建、洞心正确;斜面上的异形洞没测。 -- 2.54.0