feat: 开洞支持任意 AecDbBDPipeBase 母体(异形构筑物/柱/梁/堰)

原来 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 时自动扣掉)。
This commit is contained in:
company-desktop committed 2026-10-30 22:05:22 +08:00
1 parent aab5e724a2
commit cabdd0601e
3 files changed
+104 -22

No files matched your search

@@ -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 (...)
@@ -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";
@@ -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": [