feat: 阀门插入时把管线断开(短管),对应老代码里的 SplitWPipe
老代码是 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。
This commit is contained in:
1 parent
30c98f89a6
commit
7104655cbd
3 files changed
+109
-1
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": [
|
||||
|
||||
Reference in new issue
Block a user