From 7104655cbd0037f870c66e20d8b47bc47322b96a Mon Sep 17 00:00:00 2001 From: company-desktop-computer Date: Sat, 31 Oct 2026 13:00:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=98=80=E9=97=A8=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E6=97=B6=E6=8A=8A=E7=AE=A1=E7=BA=BF=E6=96=AD=E5=BC=80=EF=BC=88?= =?UTF-8?q?=E7=9F=AD=E7=AE=A1=EF=BC=89=EF=BC=8C=E5=AF=B9=E5=BA=94=E8=80=81?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=87=8C=E7=9A=84=20SplitWPipe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 老代码是 TDbPipeLine::SplitWPipe + Add2Flange(都在 PipelineCmd 模块,我们链不到), 但它收尾时用的是 AecDbEwPipe::SetStartPoint/SetEndPoint 挪管端,按这个思路自己实现: - 取阀门两端接口 AecMInterfaces::GetInterface(0/1) 的 ptPos - 离管起点近的那端 -> 原管 end 缩到这里 - 另一端 -> 克隆出来的新管 start 从这里开始(end 沿用原终点),新管入库 add_aec_valve 新增 break_pipe(缺省 true),返回值带 pipe_split / split_error。 注意 pipe 现在以 kForWrite 打开(要改端点),不能再以 kForRead 二次打开同一对象 (第一版就是重复打开失败,导致 pipe_split 一直是 false)。 实测(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。 --- .../cad_mcp_aec/aec_mcp_valve_tools.cpp | 84 ++++++++++++++++++- .../Code2026/cad_mcp_aec/mcp_config.json | 4 + cad-mcp-aec.md | 22 +++++ 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_valve_tools.cpp b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_valve_tools.cpp index 1fa89b8..4a175fb 100644 --- a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_valve_tools.cpp +++ b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_valve_tools.cpp @@ -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(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); } }; diff --git a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json index 8f1daa6..cdfba9d 100644 --- a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json +++ b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json @@ -6935,6 +6935,10 @@ }, "color": { "type": "integer" + }, + "break_pipe": { + "type": "boolean", + "description": "是否在插入处把管线断开(缺省是);法兰对接还没做" } }, "required": [ diff --git a/cad-mcp-aec.md b/cad-mcp-aec.md index 37e4ddf..d8ad703 100644 --- a/cad-mcp-aec.md +++ b/cad-mcp-aec.md @@ -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)` 那套建法兰,垫片厚度先用参数给(不查库)。