feat: cad_mcp_aec 补上阵列开洞与穿管开洞,统一进 add_aec_opening
同族实体不新增工具,靠参数选型: - 阵列开洞(PL_ZLKD):rows / columns + spacing_x / spacing_y,position 是第一个洞的中心; 墙:列沿墙方向(法向绕 Z 转 -90°)、行沿 +Z;板:列 X、行 Y。 与命令的 m_dX(沿墙)/ m_dY(竖向)含义一致,只是把"参考点+距离"换成直接给 position。 返回 handles 数组(handle = 第一个),阵列里每个洞都能单独 update。 - 穿管开洞(PL_YXCG):source = 管线 handle(管道/风管/桥架),洞口中心取管线轴线 与母体中面的交点(命令用布尔求交再取中点,结果等价);圆管道自动用 PIPE_OD, 没写外径就退回 PIPE_DN,显式给 diameter/width 则以给的为准;再给 casing=true 即成套管。 顺带修的三处: - 洞/套管缺省图层改用 KTSetting::InitLayer(图层不存在就建),与命令一致; 之前 layerIdByName 查不到就落到 0 层,实际图层名是 HOLE / CasePipe。 - 洞转套管时的尺寸回退:圆的 diameter 退回 2*m_dL(洞的 m_dL 存半径)、 套管长退回 m_dT,否则 update 报"圆套管需要 diameter > 0"。 - add_aec_opening 的 schema 之前一直没列 casing/source/阵列参数(上版漏改),补上。 实测(R230 Debug,pcf_1.dwg): - 墙阵列 3x4(D300,2500/900)→ 12 个洞,中心 x=2000/4500/7000/9500、z=1200/2100/3000,图层 HOLE; - 矩形阵列 2x3(600x400,3000/1000)→ 6 个; - 竖管 D150 穿板 → 套管中心 (6000,10000,-850)、source_diameter 0.15、图层 CasePipe; - 横管 D250 穿墙 → 洞中心 (4000,20100,1000)、图层 HOLE,casing 互转后位置不动。 注:SetAsHole 的洞几何要等母体重绘才生成,geomExtents 查出来是 ±1e20,属正常; SetAsPipe 的套管当场建 solid,包围盒立即可用。
This commit is contained in:
1 parent
82e75a8082
commit
81327a80e8
2 files changed
+199
-63
No files matched your search
@@ -1872,7 +1872,9 @@ namespace
|
||||
vtDir = AcGeVector3d::kZAxis;
|
||||
|
||||
// 尺寸:没传就沿用实体里已有的(update 场景)
|
||||
const double dLen = numOr(a, "casing_length", XDataD(pX, _T("dH"), dDepthDefault));
|
||||
double dLen = numOr(a, "casing_length", XDataD(pX, _T("dH"), dDepthDefault));
|
||||
if (dLen <= 0.0 && !hasKey(a, "casing_length"))
|
||||
dLen = XDataD(pX, _T("m_dT"), 0.0); // 洞转套管:洞的 m_dT 存的是洞深
|
||||
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));
|
||||
@@ -1902,7 +1904,9 @@ namespace
|
||||
}
|
||||
else
|
||||
{
|
||||
const double dD = numOr(a, "diameter", XDataD(pX, _T("dD"), 0.0));
|
||||
double dD = numOr(a, "diameter", XDataD(pX, _T("dD"), 0.0));
|
||||
if (dD <= 0.0 && !hasKey(a, "diameter"))
|
||||
dD = 2.0 * XDataD(pX, _T("m_dL"), 0.0); // 洞转套管:洞的 m_dL 存的是半径
|
||||
if (dD <= 0.0)
|
||||
{
|
||||
err = L"圆套管需要 diameter > 0";
|
||||
@@ -1937,9 +1941,12 @@ public:
|
||||
|
||||
std::string private_description() const override
|
||||
{
|
||||
return "在板或墙上开洞(对应菜单命令 平板开洞 PL_CDKD / 墙体开洞 PL_CBKD):给母体的 handle 与洞口参数,"
|
||||
"生成 AecDbX3dPartEntity 并自动与母体做布尔、挂到母体下(LAY_HOLE 图层)。"
|
||||
"尺寸用图纸单位;depth 缺省取母体厚度(板厚/墙厚)。洞口方向自动取板法向或墙厚方向。返回洞口实体 handle。";
|
||||
return "在板或墙上开洞(对应菜单命令 平板开洞 PL_CDKD / 墙体开洞 PL_CBKD / 阵列开洞 PL_ZLKD / 穿管开洞 PL_YXCG),"
|
||||
"也可以做成套管:给母体的 handle 与洞口参数,生成 AecDbX3dPartEntity 并自动与母体做布尔、挂到母体下"
|
||||
"(洞=LAY_HOLE / 套管=LAY_CASEPIPE)。尺寸用图纸单位;depth 缺省取母体厚度(板厚/墙厚);"
|
||||
"洞口方向自动取板法向或墙厚方向。阵列给 rows/columns + spacing_x/spacing_y;"
|
||||
"穿管开洞给 source=管线 handle(圆管道自动取外径);casing=true 走 SetAsPipe。"
|
||||
"返回洞口/套管实体 handle,阵列时另给 handles 数组。";
|
||||
}
|
||||
|
||||
nlohmann::json private_input_schema() const override
|
||||
@@ -1958,7 +1965,22 @@ public:
|
||||
"nozzle": { "type": "boolean", "description": "是否要管嘴(缺省否)" },
|
||||
"no": { "type": "string", "description": "洞口编号" },
|
||||
"for_use":{ "type": "string", "description": "洞口用途" },
|
||||
"layer": { "type": "string", "description": "图层,缺省 LAY_HOLE" }
|
||||
"layer": { "type": "string", "description": "图层,缺省 洞=LAY_HOLE / 套管=LAY_CASEPIPE" },
|
||||
"source": { "type": "string", "description": "穿管开洞(PL_YXCG):管线 handle(管道/风管/桥架),洞口中心取管线轴线与母体中面的交点;圆管道自动取外径" },
|
||||
"rows": { "type": "integer", "description": "阵列开洞(PL_ZLKD)行数,缺省 1" },
|
||||
"columns": { "type": "integer", "description": "阵列开洞列数,缺省 1" },
|
||||
"spacing_x": { "type": "number", "description": "阵列列间距(墙=沿墙方向 / 板=X 方向)" },
|
||||
"spacing_y": { "type": "number", "description": "阵列行间距(墙=竖向 / 板=Y 方向)" },
|
||||
"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": [ "host" ]
|
||||
})");
|
||||
@@ -1972,7 +1994,10 @@ public:
|
||||
|
||||
if (!hasKey(args, "host")) return errJson(kErrBadParam, L"缺少 host(母体板的 handle)");
|
||||
|
||||
const std::string sHost = args["host"].get<std::string>();
|
||||
// 局部副本:穿管开洞(source)要往里补缺省直径
|
||||
nlohmann::json a(args);
|
||||
|
||||
const std::string sHost = a["host"].get<std::string>();
|
||||
AcDbEntity* pEnt = openByHandle(sHost, AcDb::kForWrite);
|
||||
if (pEnt == NULL)
|
||||
return errJson(kErrNotFound, L"按 handle 打不开母体:" + utf8ToWstr(sHost));
|
||||
@@ -1990,10 +2015,14 @@ public:
|
||||
|
||||
// 洞口中心:没给就用母体中心(板=板中心,墙=基线中点)
|
||||
AcGePoint3d ptCen(0.0, 0.0, 0.0);
|
||||
const bool bHasPos = readPoint(args, "position", ptCen);
|
||||
const bool bHasPos = readPoint(a, "position", ptCen);
|
||||
|
||||
AcGeVector3d vtDir = AcGeVector3d::kZAxis; // 洞口法向 = 深度方向
|
||||
double dDepth = numOr(args, "depth", 0.0);
|
||||
double dDepth = numOr(a, "depth", 0.0);
|
||||
WallData wd;
|
||||
::memset(&wd, 0, sizeof(WallData));
|
||||
if (pWall != NULL)
|
||||
pWall->GetWallData(wd);
|
||||
|
||||
if (pSlab != NULL)
|
||||
{
|
||||
@@ -2009,9 +2038,6 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
WallData wd;
|
||||
::memset(&wd, 0, sizeof(WallData));
|
||||
pWall->GetWallData(wd);
|
||||
if (dDepth <= 0.0)
|
||||
dDepth = wd.dThick;
|
||||
if (dDepth <= 0.0)
|
||||
@@ -2027,7 +2053,7 @@ public:
|
||||
}
|
||||
// 法向 = 墙厚方向;给了 direction 就用给的
|
||||
AcGePoint3d ptGiven;
|
||||
if (readPoint(args, "direction", ptGiven))
|
||||
if (readPoint(a, "direction", ptGiven))
|
||||
vtDir = ptGiven.asVector();
|
||||
else if (!WallNormalAt(pWall, ptCen, vtDir))
|
||||
vtDir = AcGeVector3d::kZAxis;
|
||||
@@ -2038,66 +2064,156 @@ 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;
|
||||
const bool bApplied = bCasing
|
||||
? ApplyCasing(pPart, ptCen, vtDir, dDepth, args, true, err)
|
||||
: ApplyHole(pPart, pEnt, ptCen, dDepth, vtDir, args, true, err);
|
||||
if (!bApplied)
|
||||
// 穿管开洞(PL_YXCG):source 给管线 handle,洞口中心取"管线轴线与母体中面"的交点,
|
||||
// 直径缺省取管道外径(PIPE_OD 已是图纸单位)。
|
||||
// shortcut: 这里只对圆管道自动取外径,风管/桥架请自己给 diameter 或 width+height。
|
||||
std::string sSrc;
|
||||
double dSrcDia = 0.0;
|
||||
if (hasKey(a, "source"))
|
||||
{
|
||||
delete pPart;
|
||||
pEnt->close();
|
||||
return errJson(kErrBadParam, err);
|
||||
const std::string sIn = a["source"].get<std::string>();
|
||||
AcDbEntity* pSrc = openByHandle(sIn, AcDb::kForRead);
|
||||
AcDbCurve* pCur = (pSrc != NULL) ? AcDbCurve::cast(pSrc) : NULL;
|
||||
if (pCur == NULL)
|
||||
{
|
||||
if (pSrc != NULL) pSrc->close();
|
||||
if (pSlab != NULL) pSlab->close(); else pWall->close();
|
||||
return errJson(kErrWrongType, L"source 必须是曲线类管线(管道/风管/桥架),handle=" + utf8ToWstr(sIn));
|
||||
}
|
||||
|
||||
AcGePoint3d ptS(0.0, 0.0, 0.0), ptE(0.0, 0.0, 0.0);
|
||||
pCur->getStartPoint(ptS);
|
||||
pCur->getEndPoint(ptE);
|
||||
|
||||
AecDbEwPipe* pPipe = AecDbEwPipe::cast(pSrc);
|
||||
if (pPipe != NULL)
|
||||
{
|
||||
const AecDbObjXDataMap* pXPipe = pPipe->GetSpecialtyData(AcDb::kForRead);
|
||||
if (pXPipe != NULL)
|
||||
{
|
||||
double dOd = 0.0, dDn = 0.0;
|
||||
pXPipe->GetAt(PIPE_OD, dOd);
|
||||
pXPipe->GetAt(PIPE_DN, dDn);
|
||||
dSrcDia = (dOd > 0.0) ? dOd : dDn; // 没写外径就用公称直径
|
||||
}
|
||||
}
|
||||
|
||||
// 轴线与"过 ptCen、法向 vtUnit"的平面求交
|
||||
const AcGeVector3d vtAxis = ptE - ptS;
|
||||
const double dDen = vtAxis.dotProduct(vtUnit);
|
||||
if (fabs(dDen) > 1e-9)
|
||||
ptCen = ptS + vtAxis * ((ptCen - ptS).dotProduct(vtUnit) / dDen);
|
||||
|
||||
sSrc = sIn;
|
||||
pSrc->close();
|
||||
|
||||
if (dSrcDia > 0.0 && !hasKey(a, "diameter") && !hasKey(a, "width"))
|
||||
a["diameter"] = dSrcDia;
|
||||
}
|
||||
|
||||
// 母体关联 + 中心/法向:update 与"洞↔套管互转"都要用
|
||||
pPart->GetSpecialtyData()->SetAt(KEY_ASSOIC, pEnt->objectId());
|
||||
pPart->GetSpecialtyData()->SetAt(kHoleCenKey, ptCen);
|
||||
pPart->GetSpecialtyData()->SetAt(kHoleDirKey, vtDir);
|
||||
// 套管:给了 casing / casing_length / casing_wall_thickness 就走 SetAsPipe 那条
|
||||
const bool bCasing = hasKey(a, "casing")
|
||||
? (intOr(a, "casing", 0) != 0)
|
||||
: (hasKey(a, "casing_length") || hasKey(a, "casing_wall_thickness"));
|
||||
|
||||
// 图层:缺省 LAY_HOLE,与命令一致
|
||||
if (hasKey(args, "layer"))
|
||||
std::wstring err;
|
||||
std::string sFail;
|
||||
// 单个洞/套管:阵列时同一套参数只换中心
|
||||
auto makeOne = [&](const AcGePoint3d& pt) -> std::string
|
||||
{
|
||||
const std::wstring sLay = wstrOr(args, "layer", L"");
|
||||
if (!sLay.empty())
|
||||
AecDbX3dPartEntity* pPart = new AecDbX3dPartEntity();
|
||||
const bool bApplied = bCasing
|
||||
? ApplyCasing(pPart, pt, vtDir, dDepth, a, true, err)
|
||||
: ApplyHole(pPart, pEnt, pt, dDepth, vtDir, a, true, err);
|
||||
if (!bApplied)
|
||||
{
|
||||
AcDbObjectId idLay = layerIdByName(sLay);
|
||||
if (!idLay.isNull()) pPart->setLayer(idLay);
|
||||
delete pPart;
|
||||
return std::string();
|
||||
}
|
||||
|
||||
// 母体关联 + 中心/法向:update 与"洞↔套管互转"都要用
|
||||
pPart->GetSpecialtyData()->SetAt(KEY_ASSOIC, pEnt->objectId());
|
||||
pPart->GetSpecialtyData()->SetAt(kHoleCenKey, pt);
|
||||
pPart->GetSpecialtyData()->SetAt(kHoleDirKey, vtDir);
|
||||
|
||||
// 图层:缺省 洞=LAY_HOLE / 套管=LAY_CASEPIPE,与命令一致
|
||||
std::wstring sLay;
|
||||
if (hasKey(a, "layer"))
|
||||
sLay = wstrOr(a, "layer", L"");
|
||||
if (sLay.empty())
|
||||
sLay = bCasing ? L"LAY_CASEPIPE" : L"LAY_HOLE";
|
||||
AcDbObjectId idLay = KTSetting::InitLayer(sLay.c_str()); // 图层不存在就建,与命令一致
|
||||
if (!idLay.isNull())
|
||||
pPart->setLayer(idLay);
|
||||
|
||||
AcDbObjectId idHole;
|
||||
Acad::ErrorStatus es = addToSpace(pPart, &idHole);
|
||||
if (es != Acad::eOk)
|
||||
{
|
||||
delete pPart;
|
||||
sFail = "加入模型空间失败,err=" + std::to_string((int)es);
|
||||
return std::string();
|
||||
}
|
||||
|
||||
// 与母体建立关联:持久反应器 + 母体的关联件表(绘制时母体据此做布尔)
|
||||
pPart->addPersistentReactor(pEnt->objectId());
|
||||
if (pSlab != NULL)
|
||||
pSlab->AppendAssocPart(idHole);
|
||||
else
|
||||
pWall->AppendAssocPart(idHole);
|
||||
pPart->close();
|
||||
return handleOfId(idHole);
|
||||
};
|
||||
|
||||
// 阵列开洞(PL_ZLKD):rows/columns + spacing_x(墙=沿墙、板=X)/ spacing_y(墙=竖向、板=Y)
|
||||
int nRows = intOr(a, "rows", 1);
|
||||
int nCols = intOr(a, "columns", 1);
|
||||
if (nRows < 1) nRows = 1;
|
||||
if (nCols < 1) nCols = 1;
|
||||
const double dSpX = numOr(a, "spacing_x", 0.0);
|
||||
const double dSpY = numOr(a, "spacing_y", 0.0);
|
||||
|
||||
AcGeVector3d vtColDir = AcGeVector3d::kXAxis;
|
||||
AcGeVector3d vtRowDir = AcGeVector3d::kYAxis;
|
||||
if (pWall != NULL)
|
||||
{
|
||||
// 墙:列沿墙方向(法向绕 Z 转 -90°),行沿 +Z
|
||||
if (WallNormalAt(pWall, ptCen, vtColDir))
|
||||
vtColDir.rotateBy(-PI / 2.0, AcGeVector3d::kZAxis);
|
||||
else
|
||||
vtColDir = AcGeVector3d::kXAxis;
|
||||
vtRowDir = AcGeVector3d::kZAxis;
|
||||
}
|
||||
|
||||
nlohmann::json arHandles = nlohmann::json::array();
|
||||
for (int i = 0; i < nRows; ++i)
|
||||
{
|
||||
for (int j = 0; j < nCols; ++j)
|
||||
{
|
||||
const AcGePoint3d pt = ptCen + vtColDir * (j * dSpX) + vtRowDir * (i * dSpY);
|
||||
const std::string sH = makeOne(pt);
|
||||
if (sH.empty())
|
||||
{
|
||||
if (pSlab != NULL) pSlab->close(); else pWall->close();
|
||||
return errJson(kErrBadParam, !err.empty() ? err : utf8ToWstr(sFail));
|
||||
}
|
||||
arHandles.push_back(sH);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AcDbObjectId idLay = layerIdByName(L"LAY_HOLE");
|
||||
if (!idLay.isNull()) pPart->setLayer(idLay);
|
||||
}
|
||||
|
||||
AcDbObjectId idHole;
|
||||
Acad::ErrorStatus es = addToSpace(pPart, &idHole);
|
||||
if (es != Acad::eOk)
|
||||
{
|
||||
delete pPart;
|
||||
pEnt->close();
|
||||
return errJson(kErrInternal, std::wstring(L"加入模型空间失败,err=") + std::to_wstring((int)es));
|
||||
}
|
||||
|
||||
// 与母体建立关联:持久反应器 + 母体的关联件表(绘制时母体据此做布尔)
|
||||
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();
|
||||
pEnt->close();
|
||||
if (pSlab != NULL) pSlab->close(); else pWall->close();
|
||||
|
||||
nlohmann::json body;
|
||||
body["type"] = "opening";
|
||||
body["handle"] = handleOfId(idHole);
|
||||
body["type"] = bCasing ? "casing" : "opening";
|
||||
body["host"] = sHost;
|
||||
body["handle"] = arHandles[0];
|
||||
body["count"] = (int)arHandles.size();
|
||||
body["handles"] = arHandles;
|
||||
if (!sSrc.empty())
|
||||
{
|
||||
body["source"] = sSrc;
|
||||
if (dSrcDia > 0.0) body["source_diameter"] = dSrcDia;
|
||||
}
|
||||
return okJson(body);
|
||||
}
|
||||
};
|
||||
@@ -2212,7 +2328,7 @@ public:
|
||||
// 洞 / 套管 切换后图层要跟着换(命令里就是 LAY_HOLE / LAY_CASEPIPE)
|
||||
if (!hasKey(args, "layer"))
|
||||
{
|
||||
AcDbObjectId idLay = layerIdByName(bCasing ? L"LAY_CASEPIPE" : L"LAY_HOLE");
|
||||
AcDbObjectId idLay = KTSetting::InitLayer(bCasing ? L"LAY_CASEPIPE" : L"LAY_HOLE");
|
||||
if (!idLay.isNull()) pPart->setLayer(idLay);
|
||||
}
|
||||
|
||||
|
||||
@@ -2069,7 +2069,7 @@
|
||||
},
|
||||
{
|
||||
"name": "add_aec_opening",
|
||||
"description": "在板或墙上开洞(PL_CDKD 平板开洞 / PL_CBKD 墙体开洞),也可以做成套管:给母体(板或墙)handle 与洞口参数,生成 AecDbX3dPartEntity 并自动与母体布尔、挂到母体下(洞=LAY_HOLE / 套管=LAY_CASEPIPE)。casing=true 时走 SetAsPipe(只支持 circle/rect)+ 套管长/壁厚/外伸/材质/翼环。尺寸用图纸单位;depth 缺省取母体厚度;方向自动取板法向或墙厚方向。",
|
||||
"description": "在板或墙上开洞(PL_CDKD 平板 / PL_CBKD 墙体 / PL_ZLKD 阵列 / PL_YXCG 穿管),也可以做成套管:给母体(板或墙)handle 与洞口参数,生成 AecDbX3dPartEntity 并自动与母体布尔、挂到母体下(洞=LAY_HOLE / 套管=LAY_CASEPIPE)。尺寸用图纸单位;depth 缺省取母体厚度;方向自动取板法向或墙厚方向。阵列给 rows/columns + spacing_x/spacing_y;穿管开洞给 source=管线 handle(圆管道自动取外径);casing=true 走 SetAsPipe。返回 handle,阵列时另给 handles 数组。",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -2181,6 +2181,26 @@
|
||||
"ring_count": {
|
||||
"type": "integer",
|
||||
"description": "翼环数量"
|
||||
},
|
||||
"source": {
|
||||
"type": "string",
|
||||
"description": "穿管开洞(PL_YXCG):管线 handle(管道/风管/桥架),洞口中心取管线轴线与母体中面的交点;圆管道自动取外径"
|
||||
},
|
||||
"rows": {
|
||||
"type": "integer",
|
||||
"description": "阵列开洞(PL_ZLKD)行数,缺省 1"
|
||||
},
|
||||
"columns": {
|
||||
"type": "integer",
|
||||
"description": "阵列开洞列数,缺省 1"
|
||||
},
|
||||
"spacing_x": {
|
||||
"type": "number",
|
||||
"description": "阵列列间距(墙=沿墙方向 / 板=X 方向)"
|
||||
},
|
||||
"spacing_y": {
|
||||
"type": "number",
|
||||
"description": "阵列行间距(墙=竖向 / 板=Y 方向)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
Reference in new issue
Block a user