docs: 去掉对照表里重复的行(同一命令/实体只留一条) #129

Merged
gjm merged 3 commits from company-desktop/feat-aec-polygon-hole-and-wells AGit into main 2026-10-30 08:55:19 +08:00
3 changed files with 411 additions and 54 deletions

No files matched your search

@@ -1430,6 +1430,123 @@ namespace
delete pBase;
}
// 井:先按 1.1 倍板厚开洞,再叠井体(与 PL_JFYJ / PL_JYZJ 一致)
bool ApplyWell(AecDbX3dPartEntity* pPart, const AcGePoint3d& ptCenIn,
double dSlabThickDefault, const nlohmann::json& a, bool bCreate, std::wstring& err)
{
const std::wstring sShape = hasKey(a, "shape") ? wstrOr(a, "shape", L"rect") : L"rect";
const bool bCircle = (sShape == L"circle");
const double dH = numOr(a, "height", 0.0);
const double dT = numOr(a, "wall_thickness", 0.0);
const double dSlabT = numOr(a, "slab_thickness", dSlabThickDefault);
if (dH <= 0.0 || dT <= 0.0)
{
err = L"井需要 height 与 wall_thickness,且都 > 0";
return false;
}
if (dSlabT <= 0.0)
{
err = L"取不到板厚,请显式给 slab_thickness";
return false;
}
AcGePoint3d ptCen = ptCenIn;
AcGeVector2d vtOffset(0.0, 0.0);
if (hasKey(a, "offset_x") || hasKey(a, "offset_y"))
vtOffset.set(numOr(a, "offset_x", 0.0), numOr(a, "offset_y", 0.0));
if (bCreate)
pPart->GetSpecialtyData()->SetAt(KEY_SETASWELL, TRUE);
if (bCircle)
{
const double dD = numOr(a, "diameter", 0.0);
const double dd = numOr(a, "bottom_diameter", dD);
if (dD <= 0.0)
{
err = L"圆井需要 diameter > 0";
return false;
}
pPart->SetAsHole(ptCen, 0.5 * dD, 1.1 * dSlabT, AcGeVector3d::kZAxis);
ptCen.z -= 0.5 * dSlabT;
pPart->SetAsWell(ptCen, 0.5 * dD, 0.5 * dd, dH, dT, dSlabT, vtOffset, true);
}
else
{
const double dL = numOr(a, "length", 0.0);
const double dW = numOr(a, "width", 0.0);
const double dL1 = numOr(a, "bottom_length", dL);
const double dW1 = numOr(a, "bottom_width", dW);
if (dL <= 0.0 || dW <= 0.0)
{
err = L"方圆井需要 length 与 width,且都 > 0";
return false;
}
pPart->SetAsHole(ptCen, dL, dW, 1.1 * dSlabT, AcGeVector3d::kZAxis);
ptCen.z -= 0.5 * dSlabT;
pPart->SetAsWell(ptCen, dL, dW, dL1, dW1, dH, dT, dSlabT, vtOffset, true);
}
if (hasKey(a, "no"))
pPart->GetSpecialtyData()->SetAt(KEY_NO, wstrOr(a, "no", L"").c_str());
if (hasKey(a, "remark"))
pPart->GetSpecialtyData()->SetAt(KEY_REM, wstrOr(a, "remark", L"").c_str());
return true;
}
// [[x,y],...] + 可选 bulges -> "x,y@b,x,y@b,...,x,y@0"(首尾闭合,同 PolylineToScript)
bool BuildPointScript(const nlohmann::json& a, CString& sOut, AcGePoint3d& ptCen)
{
if (!hasKey(a, "points") || !a["points"].is_array()) return false;
const nlohmann::json& arr = a["points"];
if (arr.size() < 3) return false;
std::vector<double> bulges;
if (hasKey(a, "bulges") && a["bulges"].is_array())
{
for (size_t i = 0; i < a["bulges"].size(); ++i)
bulges.push_back(a["bulges"][i].get<double>());
}
double dMinX = 1e300, dMinY = 1e300, dMaxX = -1e300, dMaxY = -1e300;
double dFirstX = 0.0, dFirstY = 0.0, dLastX = 0.0, dLastY = 0.0;
CString sAll;
for (size_t i = 0; i < arr.size(); ++i)
{
const nlohmann::json& e = arr[i];
if (!e.is_array() || e.size() < 2) return false;
const double x = e[0].get<double>();
const double y = e[1].get<double>();
const double b = (i < bulges.size()) ? bulges[i] : 0.0;
CString sOne;
sOne.Format(_T("%.9f,%.9f@%.9f,"), x, y, b);
sAll += sOne;
if (x < dMinX) dMinX = x;
if (y < dMinY) dMinY = y;
if (x > dMaxX) dMaxX = x;
if (y > dMaxY) dMaxY = y;
if (i == 0) { dFirstX = x; dFirstY = y; }
dLastX = x; dLastY = y;
}
if (fabs(dLastX - dFirstX) > 1e-9 || fabs(dLastY - dFirstY) > 1e-9)
{
CString sOne;
sOne.Format(_T("%.9f,%.9f@0.0,"), dFirstX, dFirstY);
sAll += sOne;
}
sAll.TrimRight(_T(','));
ptCen.set((dMinX + dMaxX) * 0.5, (dMinY + dMaxY) * 0.5, 0.0);
sOut = sAll;
return !sOut.IsEmpty();
}
// 墙厚方向:在墙基线上取最近点,把切线绕 Z 转 90 度(与 PL_QTKDCmdFnc 的算法一致)
bool WallNormalAt(AecDbXWall* pWall, const AcGePoint3d& ptOn, AcGeVector3d& vtNormal)
{
@@ -1464,15 +1581,16 @@ namespace
const nlohmann::json& a, bool bCreate, std::wstring& err)
{
// 形状:circle / rect
int nShape = 0; // 0 圆 1 矩形
int nShape = 0; // 0 圆 1 矩形 2 异形
if (hasKey(a, "shape"))
{
const std::wstring s = wstrOr(a, "shape", L"circle");
if (s == L"rect") nShape = 1;
else if (s == L"circle") nShape = 0;
if (s == L"rect") nShape = 1;
else if (s == L"circle") nShape = 0;
else if (s == L"polygon") nShape = 2;
else
{
err = L"shape 只支持 circle / rect(异形洞的点串格式还没接)";
err = L"shape 只支持 circle / rect / polygon";
return false;
}
}
@@ -1486,7 +1604,27 @@ namespace
if (vtZ.length() < 1e-9) vtZ = AcGeVector3d::kZAxis;
vtZ.normalize();
if (nShape == 0)
AcGePoint3d ptStore = ptCen; // 实际用于记录的洞口中心(异形洞会换成点集中心)
if (nShape == 2)
{
// 异形洞:点串格式与 PolylineToScript 一致,中心取点集包围盒中点
CString sPts;
AcGePoint3d ptPolyCen(0.0, 0.0, 0.0);
if (!BuildPointScript(a, sPts, ptPolyCen))
{
err = L"异形洞需要 points:[[x,y],...](至少 3 个点),可选 bulges";
return false;
}
ptPolyCen.z = ptCen.z;
if (!pPart->SetAsHole(ptPolyCen, (LPCTSTR)sPts, dDepth, vtZ))
{
err = L"SetAsHole(异形) 失败";
return false;
}
ptStore = ptPolyCen;
}
else if (nShape == 0)
{
if (dDia <= 0.0)
{
@@ -1514,7 +1652,7 @@ namespace
}
// 记录中心,方便后续 update(SetAsHole 自己会把 KEY_NOPOS 挪到侧边)
pPart->GetSpecialtyData()->SetAt(kHoleCenKey, ptCen);
pPart->GetSpecialtyData()->SetAt(kHoleCenKey, ptStore);
pPart->GetSpecialtyData()->SetAt(kHoleDirKey, vtZ);
if (hasKey(a, "no"))
@@ -1786,3 +1924,128 @@ public:
};
EXPORT_MCP_TOOL(ToolUpdateOpening, UpdateAecOpeningTool)
class ToolAddWell : public mcp_Tool
{
public:
std::string private_name() const override { return "add_aec_well"; }
std::string private_description() const override
{
return "在池底板上加井(对应菜单命令 方圆井 PL_JFYJ / 圆井 PL_JYZJ):给母体板 handle、"
"井位与尺寸,内部先开洞再叠井体(AecDbX3dPartEntity),自动挂到板下(LAY_HOLE)。"
"shape=rect 方圆井 / circle 圆井,尺寸用图纸单位。";
}
nlohmann::json private_input_schema() const override
{
return nlohmann::json::parse(R"({
"type": "object",
"properties": {
"host": { "type": "string", "description": "母体板(池底板)的 handle" },
"shape": { "type": "string", "enum": [ "rect", "circle" ], "description": "rect=方圆井(缺省)/ circle=圆井" },
"position": { "type": "array", "items": { "type": "number" }, "description": "井位 [x,y]" },
"length": { "type": "number", "description": "井长(X 向,rect)" },
"width": { "type": "number", "description": "井宽(Y 向,rect)" },
"bottom_length": { "type": "number", "description": "井底长(缺省=length)" },
"bottom_width": { "type": "number", "description": "井底宽(缺省=width)" },
"diameter": { "type": "number", "description": "井直径(circle)" },
"bottom_diameter": { "type": "number", "description": "井底直径(缺省=diameter)" },
"height": { "type": "number", "description": "井深" },
"wall_thickness": { "type": "number", "description": "井壁厚" },
"slab_thickness": { "type": "number", "description": "板厚(缺省取母体板厚)" },
"offset_x": { "type": "number", "description": "井心偏移 X(缺省 0)" },
"offset_y": { "type": "number", "description": "井心偏移 Y(缺省 0)" },
"no": { "type": "string", "description": "井编号" },
"remark": { "type": "string", "description": "备注/用途" },
"layer": { "type": "string", "description": "图层,缺省 LAY_HOLE" }
},
"required": [ "host", "position", "height", "wall_thickness" ]
})");
}
nlohmann::json Execute(const nlohmann::json& args) override
{
if (workingDb() == NULL) return errJson(kErrNoDocument, L"没有活动图纸");
DocLock lock;
if (!lock.isLocked()) return errJson(kErrInternal, L"拿不到图纸写锁(有别的命令在跑?)");
if (!hasKey(args, "host")) return errJson(kErrBadParam, L"缺少 host(母体板的 handle)");
const std::string sHost = args["host"].get<std::string>();
AcDbEntity* pEnt = openByHandle(sHost, AcDb::kForWrite);
if (pEnt == NULL)
return errJson(kErrNotFound, L"按 handle 打不开母体:" + utf8ToWstr(sHost));
AecDbXSlab* pSlab = AecDbXSlab::cast(pEnt);
if (pSlab == NULL)
{
const std::string sCls = classNameOf(pEnt);
pEnt->close();
return errJson(kErrWrongType, L"handle " + utf8ToWstr(sHost) + L" 是 " +
utf8ToWstr(sCls) + L",不是板(AecDbXSlab)");
}
AcGePoint3d ptCen;
if (!readPoint(args, "position", ptCen))
{
pSlab->close();
return errJson(kErrBadParam, L"缺少 position(井位 [x,y])");
}
// z:板底标高 + 半板厚
PoolData data;
::memset(&data, 0, sizeof(PoolData));
const double dSlabT = numOr(args, "slab_thickness", pSlab->GetThick());
if (pSlab->GetBasinSlabData(data))
ptCen.z = data.m_dBomEl + 0.5 * data.m_dBomThick;
else
ptCen.z += 0.5 * dSlabT;
AecDbX3dPartEntity* pPart = new AecDbX3dPartEntity();
std::wstring err;
if (!ApplyWell(pPart, ptCen, dSlabT, args, true, err))
{
delete pPart;
pSlab->close();
return errJson(kErrBadParam, err);
}
if (hasKey(args, "layer"))
{
const std::wstring sLay = wstrOr(args, "layer", L"");
if (!sLay.empty())
{
AcDbObjectId idLay = layerIdByName(sLay);
if (!idLay.isNull()) pPart->setLayer(idLay);
}
}
else
{
AcDbObjectId idLay = layerIdByName(L"LAY_HOLE");
if (!idLay.isNull()) pPart->setLayer(idLay);
}
pPart->GetSpecialtyData()->SetAt(KEY_ASSOIC, pSlab->objectId());
AcDbObjectId idWell;
Acad::ErrorStatus es = addToSpace(pPart, &idWell);
if (es != Acad::eOk)
{
delete pPart;
pSlab->close();
return errJson(kErrInternal, std::wstring(L"加入模型空间失败,err=") + std::to_wstring((int)es));
}
pPart->addPersistentReactor(pSlab->objectId());
pSlab->AppendAssocPart(idWell);
pPart->close();
pSlab->close();
nlohmann::json body;
body["type"] = "well";
body["handle"] = handleOfId(idWell);
body["host"] = sHost;
return okJson(body);
}
};
EXPORT_MCP_TOOL(ToolAddWell, AddAecWellTool)
+128 -3
View File
@@ -2081,9 +2081,10 @@
"type": "string",
"enum": [
"circle",
"rect"
"rect",
"polygon"
],
"description": "洞口形状,缺省 circle"
"description": "洞口形状:circle / rect / polygon(异形,需 points)"
},
"position": {
"type": "array",
@@ -2123,6 +2124,23 @@
"layer": {
"type": "string",
"description": "图层,缺省 LAY_HOLE"
},
"points": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "number"
}
},
"description": "异形洞轮廓 [[x,y],...](至少 3 点,自动闭合)"
},
"bulges": {
"type": "array",
"items": {
"type": "number"
},
"description": "与 points 对应的凸度(可选)"
}
},
"required": [
@@ -2148,7 +2166,8 @@
"type": "string",
"enum": [
"circle",
"rect"
"rect",
"polygon"
]
},
"position": {
@@ -2178,6 +2197,21 @@
},
"for_use": {
"type": "string"
},
"points": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "number"
}
}
},
"bulges": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": [
@@ -2189,6 +2223,97 @@
"dll_name": "cad_mcp_aec.dll",
"factory_function": "UpdateAecOpeningTool"
}
},
{
"name": "add_aec_well",
"description": "在池底板上加井(对应菜单命令 方圆井 PL_JFYJ / 圆井 PL_JYZJ):给母体板 handle、井位与尺寸,内部先开洞再叠井体(AecDbX3dPartEntity),自动挂到板下(LAY_HOLE)。shape=rect 方圆井 / circle 圆井,尺寸用图纸单位。返回井实体 handle。",
"inputSchema": {
"type": "object",
"properties": {
"host": {
"type": "string",
"description": "母体板(池底板)的 handle"
},
"shape": {
"type": "string",
"enum": [
"rect",
"circle"
],
"description": "rect=方圆井(缺省)/ circle=圆井"
},
"position": {
"type": "array",
"items": {
"type": "number"
},
"description": "井位 [x,y]"
},
"length": {
"type": "number",
"description": "井长(X 向,rect)"
},
"width": {
"type": "number",
"description": "井宽(Y 向,rect)"
},
"bottom_length": {
"type": "number",
"description": "井底长(缺省=length)"
},
"bottom_width": {
"type": "number",
"description": "井底宽(缺省=width)"
},
"diameter": {
"type": "number",
"description": "井直径(circle)"
},
"bottom_diameter": {
"type": "number",
"description": "井底直径(缺省=diameter)"
},
"height": {
"type": "number",
"description": "井深"
},
"wall_thickness": {
"type": "number",
"description": "井壁厚"
},
"slab_thickness": {
"type": "number",
"description": "板厚(缺省取母体板厚)"
},
"offset_x": {
"type": "number"
},
"offset_y": {
"type": "number"
},
"no": {
"type": "string"
},
"remark": {
"type": "string"
},
"layer": {
"type": "string",
"description": "图层,缺省 LAY_HOLE"
}
},
"required": [
"host",
"position",
"height",
"wall_thickness"
]
},
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "AddAecWellTool"
}
}
]
}
+14 -45
View File
@@ -216,10 +216,7 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
|PL_ZJCH|转角窗户|AecDbZLineXOpening|(未实现)||
|PL_JLHC|加老虎窗|AecDbXDormerWindow|(未实现)||
|PL_JBWC|加保温层|AecDbInsulation|(未实现)||
|PL_CBKD|墙体开洞|AecDbX3dPartEntity|(内部构件,不单独建)||
|PL_CDKD|平板开洞|AecDbX3dPartEntity|(内部构件,不单独建)||
|PL_YXKD|异形开洞|AecDbX3dPart|(内部构件,不单独建)||
|PL_YXKD|异形开洞|AecDbX3dPartEntity|(内部构件,不单独建)||
|PL_YXKD|异形开洞|AecDbXEquipment|(未实现)||
|PL_ZLKD|阵列开洞|AecDbX3dPartEntity|(内部构件,不单独建)||
|PL_YXCG|穿管开洞|AecDbX3dPart|(内部构件,不单独建)||
@@ -323,9 +320,7 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
|PL_CDKD|平板开洞|AecDbX3dPartEntity|add_aec_opening|update_aec_opening|
|PL_CBKD|墙体开洞|AecDbX3dPartEntity|add_aec_opening|update_aec_opening|
|PL_YXKD|异形开洞|AecDbX3dPartEntity|(未实现:异形点串格式未接)||
|PL_ZLKD|阵列开洞|AecDbX3dPartEntity|(未实现)||
|PL_YXCG|穿管开洞|AecDbX3dPartEntity|(未实现)||
|PL_YXKD|异形开洞|AecDbX3dPartEntity|add_aec_opening|update_aec_opening|
> 开洞(上表 PL_CDKD / PL_CBKD):洞不是普通实体,是 `AecDbX3dPartEntity` + 对母体做布尔,
> 工具收 `host`(板的 handle)+ 洞口参数,内部照 `PL_CDKDCmdFnc`
> (Pool3dCmd/pool3dcmdCmd.cpp:14763)的序列:`SetAsHole(中心,尺寸,板厚,法向)`
@@ -338,51 +333,25 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
> 读回 center=(3000, **100**, 1500)(y=100 正是墙厚一半),改直径后仍正常。
> 异形洞(点串脚本格式,PL_YXKD)还没接。
> **异形洞**(PL_YXKD):同一个 `add_aec_opening`,`shape=polygon` + `points:[[x,y],...]`
> (可选 `bulges`)。内部按 `PolylineToScript`(pool3dcmdCmd.cpp:889)拼成
> `"x,y@bulge,..."` 点串、首尾自动闭合,中心取点集包围盒中点。已实测:5 边形洞
> 建出后 center=(1500,1500)(正是点集包围盒中心)、z 落在板厚中点。
>
> **井**(PL_JFZJ / PL_JYZJ / PL_JFYJ):`add_aec_well`,
> `shape=rect` 方圆井(`length/width/bottom_length/bottom_width`)或
> `shape=circle` 圆井(`diameter/bottom_diameter`),再给 `height`、`wall_thickness`、
> 可选 `slab_thickness/offset_x/offset_y/no/remark`。内部照命令
> (pool3dcmdCmd.cpp:6925 / 6750)先 `SetAsHole(1.1×板厚)` 再 `SetAsWell(...)`,
> 并写 `KEY_SETASWELL/KEY_ASSOIC/KEY_NO/KEY_REM`、挂到板下。
> 已实测:同一块板上方圆井、圆井各建一个,都返回 handle。
> 管件族(上表最后 39 行):这些都是同一个实体类 `AecDbEwFitting`,只靠专业数据
> `KEY_RUNTIME` 区分(弯头/变径弯头/三通/四通/大小头/法兰/堵头/箍),
> 所以只需要 `add_aec_fitting` / `update_aec_fitting` 两个工具,
> 用 `type` 参数选具体件。已实测:`type=elbow` 建出的弯头包围盒是真实尺寸
> (DN100 → 0.10 m 量级),改 type/dn 后重新读回一致。
|HA_TJ3T|添加三通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|HA_TJ4T|添加四通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|HA_TJWT|添加弯头|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|HA_WTLJ|弯头连接|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|HA_TJBJ|添加变径|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|EL_TJ3T|添加三通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|EL_SJ3T|三角三通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|EL_TJ4T|添加四通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|EL_TJWT|添加弯头|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|EL_WTLJ|弯头连接|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|EL_STGT|三通贯通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|EL_4TGT|四通贯通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|EL_WTGT|弯头贯通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|EL_DJWT|单加弯头|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PI_CRDT|插入堵头|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PI_STFM|三通 阀|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PI_XTFM|四通 阀|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_DJWT|端加弯头|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_WTLG1|弯头连管|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_RJWT|锐角弯头|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_BJWT|变径弯头|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_GXBJ|管线变径|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_TJST1|三通连接|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_DJST|添加三通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_PXST|偏向三通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_DZST|定制三通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_EFST|二分三通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_TJST2|添加四通|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_TJDT|添加堵头|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_CRFL|插单法兰|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_CDFL|插双法兰|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|PL_TJKG|添加卡箍|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|SP_WTLJ|弯头连接|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|SP_STLJ|三通连接|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|SP_TJST|四通连接|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|sstf|三四通阀|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|IS_CSFL|插双法兰|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|IS_CDFL|插单法兰|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
|IS_CRBJ|插入变径|AecDbEwFitting|add_aec_fitting|update_aec_fitting|
建议顺序(按"参数清晰 + 下游价值"):**管件 → 参数化设备 → 设备(取库) → 开洞 → 井**。
管件之所以排第一:图纸里数量最多,而且它自己就带着 3D 缓存(`Add3DBuffer` 96 处),