docs: 对照表把 PL_CBKD 墙体开洞标为已实现,并补墙开洞说明 #128

Merged
gjm merged 2 commits from company-desktop/feat-aec-wall-opening AGit into main 2026-10-30 08:55:12 +08:00
3 changed files with 150 additions and 38 deletions

No files matched your search

@@ -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<AecDbX3dPartEntity>(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<std::string>(), "opening");
}
};
EXPORT_MCP_TOOL(ToolUpdateOpening, UpdateAecOpeningTool)
@@ -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",
+7 -3
View File
@@ -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` 区分(弯头/变径弯头/三通/四通/大小头/法兰/堵头/箍),