docs: 记录套管(洞口另一半)的实现与两个坑(§8.5) #138

Merged
gjm merged 2 commits from company-desktop/company-desktop-computer/feat-aec-casing AGit into main 2026-10-30 20:19:57 +08:00
3 changed files with 255 additions and 10 deletions

No files matched your search

@@ -1835,6 +1835,101 @@ namespace
}
}
// 套管:同一类 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, 法向)
// 再写 MATERIAL / PIPETYPE / PIPE_TOD(翼环外径) / PIPE_YMS(翼环数量),图层 LAY_CASEPIPE
// 注意 SetAsPipe 的矩形分支里参数是"反着存"的:传 (dH=高, dW=宽) → xdata 存 dL=宽、dW=高。
bool ApplyCasing(AecDbX3dPartEntity* pPart, const AcGePoint3d& ptCen, const AcGeVector3d& vtDirIn,
double dDepthDefault, const nlohmann::json& a, bool bCreate, std::wstring& err)
{
const AecDbObjXDataMap* pX = pPart->GetSpecialtyData(AcDb::kForRead);
// 形状:SetAsPipe 按 0=circle / 1=rect 分派(对话框约定);
// 而 xdata 里存的 nShape 是 ESection(eRect=1 / eCircle=2),读回来要换算。
bool bRect = false;
if (hasKey(a, "shape"))
{
const std::wstring s = wstrOr(a, "shape", L"circle");
if (s == L"rect") bRect = true;
else if (s == L"circle") bRect = false;
else
{
err = L"套管只支持 circle / rect(异形洞不能做套管)";
return false;
}
}
else if (pX != NULL)
{
int nOld = eCircle;
pX->GetAt(_T("nShape"), nOld);
bRect = (nOld == eRect);
}
const int nShape = bRect ? 1 : 0;
AcGeVector3d vtDir = vtDirIn;
if (vtDir.length() < 1e-9)
vtDir = AcGeVector3d::kZAxis;
// 尺寸:没传就沿用实体里已有的(update 场景)
const double dLen = numOr(a, "casing_length", XDataD(pX, _T("dH"), dDepthDefault));
const double dT = numOr(a, "casing_wall_thickness", XDataD(pX, _T("dT"), 0.0));
const double dExt1 = numOr(a, "casing_extend1", XDataD(pX, _T("dEx1"), 0.0));
const double dExt2 = numOr(a, "casing_extend2", XDataD(pX, _T("dEx2"), 0.0));
const BOOL bExt = hasKey(a, "casing_extend") ? (intOr(a, "casing_extend", 0) != 0)
: (XDataD(pX, _T("bExt"), 0.0) != 0.0);
if (dLen <= 0.0 || dT <= 0.0)
{
err = L"套管需要 casing_length(套管长)与 casing_wall_thickness(壁厚),且都 > 0";
return false;
}
if (bCreate)
pPart->GetSpecialtyData()->SetAt(KEY_SETASWELL, TRUE);
bool bOk = false;
if (bRect)
{
const double dW = numOr(a, "width", XDataD(pX, _T("dL"), 0.0));
const double dH = numOr(a, "height", XDataD(pX, _T("dW"), 0.0));
if (dW <= 0.0 || dH <= 0.0)
{
err = L"矩形套管需要 width 与 height,且都 > 0";
return false;
}
bOk = pPart->SetAsPipe(ptCen, nShape, dH, dW, dT, dLen, bExt, dExt1, dExt2, vtDir);
}
else
{
const double dD = numOr(a, "diameter", XDataD(pX, _T("dD"), 0.0));
if (dD <= 0.0)
{
err = L"圆套管需要 diameter > 0";
return false;
}
bOk = pPart->SetAsPipe(ptCen, nShape, dD, 0.0, dT, dLen, bExt, dExt1, dExt2, vtDir);
}
if (!bOk)
{
err = L"SetAsPipe 失败(参数或几何不合法)";
return false;
}
if (hasKey(a, "material"))
pPart->GetSpecialtyData()->SetAt(KEY_MATERIAL, wstrOr(a, "material", L"").c_str());
if (hasKey(a, "pipe_type"))
pPart->GetSpecialtyData()->SetAt(KEY_PIPETYPE, wstrOr(a, "pipe_type", L"").c_str());
if (hasKey(a, "ring_od")) // 翼环外径(命令里存字符串)
pPart->GetSpecialtyData()->SetAt(PIPE_TOD, wstrOr(a, "ring_od", L"").c_str());
if (hasKey(a, "ring_count")) // 翼环数量
pPart->GetSpecialtyData()->SetAt(PIPE_YMS, intOr(a, "ring_count", 0));
if (hasKey(a, "no"))
pPart->GetSpecialtyData()->SetAt(KEY_NO, wstrOr(a, "no", L"").c_str());
return true;
}
class ToolAddOpening : public mcp_Tool
{
public:
@@ -1943,15 +2038,28 @@ public:
vtUnit.normalize();
ptCen += vtUnit * 0.5 * dDepth;
// 套管:给了 casing / casing_length / casing_wall_thickness 就走 SetAsPipe 那条
const bool bCasing = hasKey(args, "casing")
? (intOr(args, "casing", 0) != 0)
: (hasKey(args, "casing_length") || hasKey(args, "casing_wall_thickness"));
AecDbX3dPartEntity* pPart = new AecDbX3dPartEntity();
std::wstring err;
if (!ApplyHole(pPart, pEnt, ptCen, dDepth, vtDir, args, true, err))
const bool bApplied = bCasing
? ApplyCasing(pPart, ptCen, vtDir, dDepth, args, true, err)
: ApplyHole(pPart, pEnt, ptCen, dDepth, vtDir, args, true, err);
if (!bApplied)
{
delete pPart;
pEnt->close();
return errJson(kErrBadParam, err);
}
// 母体关联 + 中心/法向:update 与"洞↔套管互转"都要用
pPart->GetSpecialtyData()->SetAt(KEY_ASSOIC, pEnt->objectId());
pPart->GetSpecialtyData()->SetAt(kHoleCenKey, ptCen);
pPart->GetSpecialtyData()->SetAt(kHoleDirKey, vtDir);
// 图层:缺省 LAY_HOLE,与命令一致
if (hasKey(args, "layer"))
{
@@ -2002,7 +2110,7 @@ public:
std::string private_description() const override
{
return "修改已有洞口:改形状/直径/宽高/深度/管嘴/编号/用途。改尺寸会重建洞的几何。";
return "修改已有洞口或套管:改形状/直径/宽高/深度/管嘴/编号/用途;也可以 casing=true/false 在洞口与套管之间切换。改尺寸会重建几何。";
}
nlohmann::json private_input_schema() const override
@@ -2016,7 +2124,13 @@ public:
"diameter": { "type": "number" }, "width": { "type": "number" },
"height": { "type": "number" }, "depth": { "type": "number" },
"nozzle": { "type": "boolean" }, "no": { "type": "string" },
"for_use": { "type": "string" }
"for_use": { "type": "string" },
"casing": { "type": "boolean", "description": "true=改成套管 / false=改回洞口(缺省保持原样)" },
"casing_length": { "type": "number" }, "casing_wall_thickness": { "type": "number" },
"casing_extend": { "type": "boolean" }, "casing_extend1": { "type": "number" },
"casing_extend2": { "type": "number" }, "material": { "type": "string" },
"pipe_type": { "type": "string" }, "ring_od": { "type": "string" },
"ring_count": { "type": "integer" }
},
"required": [ "handle" ]
})");
@@ -2049,6 +2163,11 @@ public:
else if (pWall != NULL) WallCenter(pWall, ptCen);
}
// 现在是不是套管:按实体名字判断(SetAsPipe 写的是"套管")
const CString sCurName = pPart->GetName();
const bool bCasingNow = (sCurName.CompareNoCase(_T("套管")) == 0);
const bool bCasing = hasKey(args, "casing") ? (intOr(args, "casing", 0) != 0) : bCasingNow;
double dDepth = numOr(args, "depth", 0.0);
if (dDepth <= 0.0 && pSlab != NULL)
dDepth = pSlab->GetThick();
@@ -2060,6 +2179,8 @@ public:
dDepth = wd.dThick;
}
if (dDepth <= 0.0)
pPart->GetSpecialtyData()->GetAt(_T("m_dT"), dDepth); // 洞口建的时候存的深度
if (dDepth <= 0.0 && !bCasing) // 套管用 casing_length,不依赖 depth
{
if (pHost != NULL) pHost->close();
pPart->close();
@@ -2078,15 +2199,25 @@ public:
}
std::wstring msg;
if (!ApplyHole(pPart, pHost, ptCen, dDepth, vtDir, args, false, msg))
const bool bApplied = bCasing
? ApplyCasing(pPart, ptCen, vtDir, dDepth, args, false, msg)
: ApplyHole(pPart, pHost, ptCen, dDepth, vtDir, args, false, msg);
if (!bApplied)
{
if (pHost != NULL) pHost->close();
pPart->close();
return errJson(kErrBadParam, msg);
}
// 洞 / 套管 切换后图层要跟着换(命令里就是 LAY_HOLE / LAY_CASEPIPE)
if (!hasKey(args, "layer"))
{
AcDbObjectId idLay = layerIdByName(bCasing ? L"LAY_CASEPIPE" : L"LAY_HOLE");
if (!idLay.isNull()) pPart->setLayer(idLay);
}
if (pHost != NULL) pHost->close();
return finishUpdate(pPart, args["handle"].get<std::string>(), "opening");
return finishUpdate(pPart, args["handle"].get<std::string>(), bCasing ? "casing" : "opening");
}
};
@@ -2069,7 +2069,7 @@
},
{
"name": "add_aec_opening",
"description": "在板或墙上开洞(对应菜单命令 平板开洞 PL_CDKD / 墙体开洞 PL_CBKD):给母体(板或墙)的 handle 与洞口参数,生成洞口实体(AecDbX3dPartEntity)并自动与母体做布尔、挂到母体下(LAY_HOLE 图层)。尺寸用图纸单位;depth 缺省取母体厚度(板厚/墙厚),洞口方向自动取板法向或墙厚方向。返回洞口实体 handle。",
"description": "在板或墙上开洞(PL_CDKD 平板开洞 / PL_CBKD 墙体开洞),也可以做成套管:给母体(板或墙)handle 与洞口参数,生成 AecDbX3dPartEntity 并自动与母体布尔、挂到母体下(洞=LAY_HOLE / 套管=LAY_CASEPIPE)。casing=true 时走 SetAsPipe(只支持 circle/rect)+ 套管长/壁厚/外伸/材质/翼环。尺寸用图纸单位;depth 缺省取母体厚度;方向自动取板法向或墙厚方向。",
"inputSchema": {
"type": "object",
"properties": {
@@ -2123,7 +2123,7 @@
},
"layer": {
"type": "string",
"description": "图层,缺省 LAY_HOLE"
"description": "图层,缺省 洞=LAY_HOLE / 套管=LAY_CASEPIPE"
},
"points": {
"type": "array",
@@ -2141,6 +2141,46 @@
"type": "number"
},
"description": "与 points 对应的凸度(可选)"
},
"casing": {
"type": "boolean",
"description": "true=做成套管(SetAsPipe,只支持 circle/rect);缺省否"
},
"casing_length": {
"type": "number",
"description": "套管长度(缺省取母体厚度)"
},
"casing_wall_thickness": {
"type": "number",
"description": "套管壁厚"
},
"casing_extend": {
"type": "boolean",
"description": "套管两端是否外伸"
},
"casing_extend1": {
"type": "number",
"description": "外伸长度 1"
},
"casing_extend2": {
"type": "number",
"description": "外伸长度 2"
},
"material": {
"type": "string",
"description": "套管材质"
},
"pipe_type": {
"type": "string",
"description": "套管类型"
},
"ring_od": {
"type": "string",
"description": "翼环外径"
},
"ring_count": {
"type": "integer",
"description": "翼环数量"
}
},
"required": [
@@ -2155,7 +2195,7 @@
},
{
"name": "update_aec_opening",
"description": "修改已有洞口:改形状/直径/宽高/深度/管嘴/编号/用途,改尺寸会重建洞的几何。",
"description": "修改已有洞口或套管:改形状/直径/宽高/深度/管嘴/编号/用途,也可以 casing=true/false 在洞口与套管之间切换(图层自动换)。改尺寸会重建几何。",
"inputSchema": {
"type": "object",
"properties": {
@@ -2212,6 +2252,46 @@
"items": {
"type": "number"
}
},
"casing": {
"type": "boolean",
"description": "true=改成套管 / false=改回洞口(缺省保持原样)"
},
"casing_length": {
"type": "number",
"description": "套管长度(缺省取母体厚度)"
},
"casing_wall_thickness": {
"type": "number",
"description": "套管壁厚"
},
"casing_extend": {
"type": "boolean",
"description": "套管两端是否外伸"
},
"casing_extend1": {
"type": "number",
"description": "外伸长度 1"
},
"casing_extend2": {
"type": "number",
"description": "外伸长度 2"
},
"material": {
"type": "string",
"description": "套管材质"
},
"pipe_type": {
"type": "string",
"description": "套管类型"
},
"ring_od": {
"type": "string",
"description": "翼环外径"
},
"ring_count": {
"type": "integer",
"description": "翼环数量"
}
},
"required": [
+36 -2
View File
@@ -60,7 +60,7 @@ if (IS_ZWCAD OR CAD_SDK_VERSION GREATER_EQUAL 20)
| `add_aec_beam` / `update_aec_beam` | 建/改梁(`AecDbBeam`) | `start`/`end`、`width`、`height` |
| `add_aec_climb_stair` / `update_aec_climb_stair` | 建/改爬梯(`AecDbClimbStair`) | `start`/`end`、`width`、`cage_diameter`、`height`、`bar_diameter`、`step_height`、`facing` |
| `add_aec_fitting` / `update_aec_fitting` | 建/改管件(`AecDbEwFitting`) | `position`、`direction`/`branch_direction`、`dn_mm`/`od_mm`/`wall_thickness_mm`、`type`(elbow/tee/reduce/flange/cap/…) |
| `add_aec_opening` / `update_aec_opening` | 板/墙上开洞(`AecDbX3dPartEntity`) | `host`、`shape`(circle/rect/polygon)、`position`、`diameter` 或 `width`/`height`,异形洞用 `points` |
| `add_aec_opening` / `update_aec_opening` | 板/墙上开洞**或做套管**(`AecDbX3dPartEntity`) | `host`、`shape`(circle/rect/polygon)、`position`、`diameter` 或 `width`/`height`、异形洞 `points`;`casing=true` 时走套管(`casing_length`/`casing_wall_thickness`/`casing_extend*`/`material`/`pipe_type`/`ring_od`/`ring_count`) |
| `add_aec_well` / `update_aec_well` | 池底板上加/改井(方井/圆井/方圆井/异形井) | `host`、`shape`(rect/circle/rect_circle/polygon)、`position`、`length`/`width`/`diameter`、异形井用 `top_points`/`bottom_points`、`height`、`wall_thickness` |
**单位约定**(写进了每个工具的 description):
@@ -394,7 +394,7 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
| `PL_CBKD` 墙体开洞 | 墙 + 圆/矩形洞 | ✅ 同上 | `host` 传墙;法向自动取"墙基线切线转 90°",深度取墙厚 |
| `PL_YXKD` 异形开洞 | 板/墙 + 任意闭合轮廓 | ✅ 同上 | `shape=polygon` + `points`(可选 `bulges`) |
| 洞口改属性 | 改尺寸/位置/编号/用途/管嘴 | ✅ `update_aec_opening` | 参数集照 `DBL_AEC_X3DPART` 里"开洞"分支 |
| 洞口 ↔ 套管 | 把洞做成套管(`SetAsPipe` + `LAY_CASEPIPE`) | ❌ 未做 | 参数在 `CCDKDDlg`:套管长/壁厚/外伸 `m_bExt`/`m_dExt1`/`m_dExt2`/材质/翼环 `PIPE_TOD`/`PIPE_YMS` |
| 洞口 ↔ 套管 | 把洞做成套管、或改回洞口 | ✅ `add_aec_opening(casing=true)` / `update_aec_opening(casing=)` | `SetAsPipe` + `LAY_CASEPIPE`,详见 §8.5 |
| `PL_ZLKD` 阵列开洞 | 一次开一排/矩阵洞 | ❌ 未做 | 要定工具形态(给角点+行列数,还是方向+数量) |
| `PL_YXCG` 穿管开洞 | 按管道位置 + 套管开洞 | ❌ 未做 | 要引用管道实体(handle)取位置/方向/口径,本质是"套管 + 位置来自管道" |
@@ -408,3 +408,37 @@ xdata 键:`dL/dW/dH/dSlabThick/dBomThick/Ang`(注意这里的 `dBomThick`
与其它井不同)。工具里就是 `shape="sump"` + 可选 `angle_deg`(对话框默认 22.5°,范围 0~75)。
实测:默认 22.5° 建出 J-1(包围盒 x 1178~4821),改 高1500→1800 且角度 22.5→30 后
包围盒 z 下移 300、x 范围变宽,说明放坡与高度都生效。
### 8.5 套管(洞口的另一半)
命令里的规则:**洞口可以带套管**,套管走 `SetAsPipe` 而不是 `SetAsHole`
(`PL_CDKD` / `PL_QTKD` 都是 `if (dlg.m_bHasCase && 形状 != 异形) 套管 else 洞`)。
墙洞、板洞都一样,只是法向不同。
| 项 | 洞(SetAsHole) | 套管(SetAsPipe) |
| --- | --- | --- |
| 参数 | 中心 + 尺寸 + 深度 + 法向 | 中心 + 尺寸 + **套管长** + 壁厚 + 外伸(`bExt`/`dEx1`/`dEx2`) + 法向 |
| xdata | `m_dL/m_dW/m_dT/vtDir` | `dH`(套管长)/`dD`(圆)/`dL`,`dW`(矩形)/`dT`(壁厚)/`bExt`/`dEx1`/`dEx2`/`vtDir` |
| 额外 | — | `KEY_MATERIAL`/`KEY_PIPETYPE`/`PIPE_TOD`(翼环外径)/`PIPE_YMS`(翼环数) |
| 图层 | `LAY_HOLE` | `LAY_CASEPIPE` |
| 实体名 | `开洞` | `套管` |
**两个坑(都踩过)**:
1. `SetAsPipe` 的形状参数用的是**对话框约定** `0=circle / 1=rect`,
而它写进 xdata 的 `nShape` 是 `ESection`(`eRect=1 / eCircle=2`)——读回来必须换算,
否则圆套管会被当成矩形,然后报"缺 width/height"。
2. `SetAsPipe` 的矩形分支把两个尺寸**反着存**(传 `dH`→存 `dW`,传 `dW`→存 `dL`),
工具里按 `width/height` 语义对齐后调用,回读才对得上。
**工具行为**:
- `add_aec_opening`:给 `casing=true`(或给了 `casing_length`/`casing_wall_thickness`)就走套管;
只支持 `circle`/`rect`(异形洞不能做套管,命令里也是这样);缺省图层 `LAY_CASEPIPE`。
- `update_aec_opening`:按实体名字(`套管` / `开洞`)自己判断,也可用 `casing=true/false`
在两者间**互转**;转完图层跟着换,中心/法向沿用创建时记的 `AECMCP_HOLE_CEN/_DIR`。
- 创建时把 `KEY_ASSOIC`(母体板/墙)一起记下,update 才能反查母体厚度/标高。
实测(R230 Debug,pcf_1.dwg):
- 板上圆套管 D400/长600/壁厚20 → 3A1,包围盒 x,y 1800~2200、z -150~450(居中于板厚);
- 墙上矩形套管 800x600/长400 → 3A3,包围盒 x 7700~8100(墙厚 200)、z 1200~1800;
- 3A1 `casing=false` → 名字变 `开洞`、位置仍 (2000,2000,150);再 `casing=true`(长 800、壁厚 25)
→ 名字回 `套管`、包围盒 z 变 -250~550 —— **洞↔套管互转正常**。