feat: 阀门插入时把管线断开(短管),对应老代码里的 SplitWPipe #160

Merged
gjm merged 1 commits from company-desktop/company-desktop-computer/feat-aec-valve-break-pipe AGit into main 2026-10-31 13:01:16 +08:00
3 changed files with 109 additions and 1 deletions

No files matched your search

@@ -94,6 +94,72 @@ namespace
return false;
}
// 断管:把管线在阀门两端各切一刀,原来的管留一段、克隆出来一段。
// 老代码里是 TDbPipeLine::SplitWPipe(PipelineCmd 模块,我们链不到),
// 但它收尾时用的就是 AecDbEwPipe::SetStartPoint/SetEndPoint 挪管端,
// 这里照那个思路做:靠起点的那端给原管、另一端给克隆出来的新管。
bool SplitPipeAtValve(AecDbEwPipe* pPipe, AecDbEwEquipment* pEqu, std::wstring& err)
{
if (pPipe == NULL || pEqu == NULL) { err = L"断管缺管线或阀门"; return false; }
AcGePoint3d ptA(0.0, 0.0, 0.0), ptB(0.0, 0.0, 0.0);
AecInterface inf1, inf2;
::memset(&inf1, 0, sizeof(AecInterface));
::memset(&inf2, 0, sizeof(AecInterface));
AecMInterfaces* pInf = dynamic_cast<AecMInterfaces*>(pEqu);
if (pInf == NULL || pInf->GetInterfaceCount() < 2) { err = L"阀门取不到两个接口"; return false; }
if (!pInf->GetInterface(0, inf1) || !pInf->GetInterface(1, inf2))
{
err = L"阀门接口取点失败";
return false;
}
AcGePoint3d ptSta(0.0, 0.0, 0.0), ptEnd(0.0, 0.0, 0.0);
pPipe->getStartPoint(ptSta);
pPipe->getEndPoint(ptEnd);
// 哪一端离管起点近,就把那一端留给原管
if (inf1.ptPos.distanceTo(ptSta) <= inf2.ptPos.distanceTo(ptSta))
{
ptA = inf1.ptPos; // 原管 end
ptB = inf2.ptPos; // 新管 start
}
else
{
ptA = inf2.ptPos;
ptB = inf1.ptPos;
}
// 新的一段:从阀门另一端到原来的终点
AcDbEntity* pClone = (AcDbEntity*)pPipe->clone();
AecDbEwPipe* pNewPipe = (pClone != NULL) ? AecDbEwPipe::cast(pClone) : NULL;
if (pNewPipe == NULL)
{
delete pClone;
err = L"复制管线失败";
return false;
}
pNewPipe->SetStartPoint(ptB);
pNewPipe->SetEndPoint(ptEnd);
AcDbObjectId idNew;
if (addToSpace(pNewPipe, &idNew) != Acad::eOk)
{
delete pNewPipe;
err = L"新管段入库失败";
return false;
}
touchEntity(pNewPipe);
pNewPipe->close();
// 原管:终点缩到阀门这一端
pPipe->SetEndPoint(ptA);
touchEntity(pPipe);
return true;
}
// 收尾:图层 + 管网系统 + 母体管线 + 入库
bool PlaceEquipment(AecDbEwEquipment* pEqu, AcDbEntity* pPipe, const AcGePoint3d& ptIns,
const AcGeVector3d& vtDir, const nlohmann::json& a, std::wstring& err)
@@ -160,6 +226,7 @@ public:
"dn_mm": { "type": "number", "description": "公称直径 DN(毫米)" },
"pn": { "type": "number", "description": "压力等级(MPa),缺省 1.0" },
"has_flange": { "type": "boolean", "description": "是否带法兰,缺省否" },
"break_pipe": { "type": "boolean", "description": "是否在插入处把管线断开(缺省是);法兰对接还没做" },
"idx": { "type": "integer", "description": "同类型有多个规格时选第几个(0 起),缺省 0" },
"system": { "type": "string", "description": "管网系统名(缺省跟管线)" },
"layer": { "type": "string", "description": "图层,缺省 LAY_PIPE_OUTSIDE" },
@@ -185,7 +252,7 @@ public:
if (hasKey(args, "pipe"))
{
const std::wstring sPipe = wstrOr(args, "pipe", L"");
pPipe = openByHandle(acharToUtf8(sPipe.c_str()), AcDb::kForRead);
pPipe = openByHandle(acharToUtf8(sPipe.c_str()), AcDb::kForWrite); // 断管要改端点
if (pPipe == NULL)
return errJson(kErrNotFound, L"按 handle 打不开管线:" + sPipe);
}
@@ -256,6 +323,19 @@ public:
return errJson(kErrInternal, std::wstring(L"加入模型空间失败,err=") + std::to_wstring((int)es));
}
touchEntity(pEqu);
// 断管(老代码里的 SplitWPipe):缺省开,管线要在插入点断开
bool bSplit = hasKey(args, "break_pipe") ? (intOr(args, "break_pipe", 1) != 0) : true;
bool bSplitOk = false;
if (bSplit && pPipe != NULL)
{
AecDbEwPipe* pPW = AecDbEwPipe::cast(pPipe);
if (pPW != NULL)
bSplitOk = SplitPipeAtValve(pPW, pEqu, err);
else
err = L"pipe 不是管道(AecDbEwPipe),不打断管";
}
pEqu->close();
if (pPipe != NULL) pPipe->close();
@@ -267,6 +347,8 @@ public:
body["position"] = { ptIns.x, ptIns.y, ptIns.z };
body["direction"] = { vtDir.x, vtDir.y, vtDir.z };
body["handle"] = HandleOfId(idNew);
body["pipe_split"] = bSplitOk;
if (!bSplitOk && bSplit) body["split_error"] = acharToUtf8(err.c_str());
return okJson(body);
}
};
@@ -6935,6 +6935,10 @@
},
"color": {
"type": "integer"
},
"break_pipe": {
"type": "boolean",
"description": "是否在插入处把管线断开(缺省是);法兰对接还没做"
}
},
"required": [
+22
View File
@@ -1202,3 +1202,25 @@ SetDimStyle(1),SetDimupdownSpace(DN)
**限制**:`shortcut:` 还没做插入时的"断管 + 法兰对接"(命令里是 `InsertValAtInfPos`,约 150 行),
阀门只是摆在管线上的位置与方向,管段不会自动断开。
**第十一批:阀门插入时的短管(断管)**
老代码是 `TDbPipeLine::SplitWPipe` + `Add2Flange`(都在 **PipelineCmd 模块**,我们链不到),
但它收尾时用的是 `AecDbEwPipe::SetStartPoint/SetEndPoint` 挪管端 —— 按这个思路自己实现了断管:
```
取阀门两端接口 AecMInterfaces::GetInterface(0/1) 的 ptPos
离管起点近的那端 → 原管 end 缩到这里
另一端 → 克隆出来的新管 start 从这里开始(end 沿用原终点)
新管入库(专业数据、图层、系统都跟着 clone 走)
```
`add_aec_valve` 新增 `break_pipe`(缺省 **true**),返回值里带 `pipe_split` / `split_error`。
注意 `pipe` 现在是以 **kForWrite** 打开的(要改端点),不要再用 kForRead 二次打开同一对象。
**实测**(R230 Debug,空图,DN100 管线 0→10000 在 x=5000 插闸阀):`pipe_split: true`,
`query_aec_entities(type=pipe)` 从 1 根变成 2 根(`290` 原管 + `320` 新段)。
**还没做(下一步)**:断口处的**法兰对接** —— 老代码 `Add2Flange` 会按 DN/压力查
`Plumbing.db` 的 `QueryFlangData`/`QueryGasketData` 取法兰与垫片尺寸再生成法兰件;
我们这边可以复用 `add_aec_fitting(type=flange)` 那套建法兰,垫片厚度先用参数给(不查库)。