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": [