docs: 记录标注的自动定位 placement 与「引出/垂直不用搬」的结论(§8.9) #158

Merged
gjm merged 2 commits from company-desktop/company-desktop-computer/feat-aec-dim-autotext AGit into main 2026-10-31 12:33:38 +08:00
3 changed files with 205 additions and 9 deletions

No files matched your search

@@ -64,6 +64,78 @@ namespace
}
// ------------------------------------------------------------------------
// 「在线/线上/线下标注」的两点定位(照 AecPlumbingDrawWDimonX):
// 管轴向 vtDir(按象限规整,保证文字朝右上)→ 法向 vtV = 轴向绕 Z 转 90°
// 第1点 = 拾取点在管轴上的投影 + vtV * (DN/2)
// 第2点 = 第1点 + vtDir * leadLen(命令里是 500)
// DN 在库里按图纸单位存(产品的管是 mm;我们自己建的管按 AS_MUNIT 存米,
// 所以 <10 时按米换成图纸单位),与 ComposeSystemText 里的处理一致。
bool ComputeOnlinePoints(AcDbEntity* pTarget, const AcGePoint3d& ptPick, double dLeadLen,
AcGePoint3d& pt1, AcGePoint3d& pt2, double& dDnDraw, std::wstring& err)
{
AcDbCurve* pCrv = AcDbCurve::cast(pTarget);
if (pCrv == NULL) { err = L"被标注实体不是曲线(算不出管轴)"; return false; }
AcGePoint3d ptSta(0.0, 0.0, 0.0), ptEnd(0.0, 0.0, 0.0);
if (pCrv->getStartPoint(ptSta) != Acad::eOk || pCrv->getEndPoint(ptEnd) != Acad::eOk)
{
err = L"取不到被标注实体的起终点";
return false;
}
// 管径(图纸单位)
dDnDraw = 0.0;
{
AecDbObjXDataMap xObj;
AecDbCurveBase* pCurBase = AecDbCurveBase::cast(pTarget);
if (pCurBase != NULL)
xObj.CopyFrom(pCurBase->GetSpecialtyData(AcDb::kForRead));
else
XDataOfPlain(pTarget, xObj);
xObj.GetAt(PIPE_DN, dDnDraw);
if (dDnDraw > 0.0 && dDnDraw < 10.0) dDnDraw *= 1000.0; // 米 -> 图纸单位
}
// 拾取点投影到管轴:ptOn = ptSta + t*(ptEnd-ptSta)
const AcGeVector3d vtAxis = ptEnd - ptSta;
const double dLen2 = vtAxis.dotProduct(vtAxis);
if (dLen2 < 1e-18) { err = L"管轴长度为 0"; return false; }
double t = (ptPick - ptSta).dotProduct(vtAxis) / dLen2;
if (t < 0.0) t = 0.0;
if (t > 1.0) t = 1.0;
AcGePoint3d ptOn = ptSta + vtAxis * t;
// 轴向 + 法向(象限规整)
AcGeVector3d vtDir = ptEnd - ptSta;
if (vtDir.length() < 1e-9) { err = L"管轴长度为 0"; return false; }
vtDir.normalize();
if (vtDir.isParallelTo(AcGeVector3d::kYAxis)) vtDir = AcGeVector3d::kYAxis;
if (vtDir.isParallelTo(AcGeVector3d::kXAxis)) vtDir = AcGeVector3d::kXAxis;
AcGeVector3d vtV = vtDir;
if (vtDir.x < -1.0e-10 && vtDir.y > 1.0e-10) // 第 2 象限
{
vtV.rotateBy(-PI / 2.0, AcGeVector3d::kZAxis);
vtDir *= -1.0; // 转成第 4 象限
}
else if (vtDir.x < -1.0e-10 && vtDir.y < -1.0e-10) // 第 3 象限
{
vtDir.negate(); // 转成第 1 象限
vtV.rotateBy(-PI / 2.0, AcGeVector3d::kZAxis);
}
else
{
vtV.rotateBy(PI / 2.0, AcGeVector3d::kZAxis);
}
ptOn += vtV * (dDnDraw * 0.5);
pt1 = ptOn;
pt2 = ptOn + vtDir * dLeadLen;
return true;
}
// ------------------------------------------------------------------------
// 「系统标注」的字段脚本引擎(等价于 PipelineCmd 里 PipelineTools::FormatDimText)
//
@@ -529,6 +601,11 @@ public:
"unit": { "type": "string", "enum": [ "m", "mm" ], "description": "尺寸/标高的单位,缺省 m(命令里 m_bUnitM)" },
"elevation_base": { "type": "number", "description": "标高基准(命令里的 dElv),缺省 0" },
"elevation": { "type": "number", "description": "kind=system 时给管线标高(填 {5} 字段),缺省 0" },
"placement": { "type": "string", "enum": [ "on_line", "above", "below", "custom" ],
"description": "放置方式:on_line 在线(上下排都写)/ above 线上(只写上排)/ below 线下(只写下排);给了就用 pick 自动算两点,不用再给 points" },
"pick": { "type": "array", "items": { "type": "number" }, "description": "placement 用:在管上点一个位置(会自动投影到管轴)" },
"lead_length": { "type": "number", "description": "placement 用:沿管轴的引出长度,缺省 500(命令里就是这个值)" },
"dim_updown_space": { "type": "number", "description": "上下排文字间距,缺省按放置方式给(在线=管径,引出/垂直=0)" },
"dim_style": { "type": "integer", "description": "标注样式编号,缺省按 kind" },
"dim_dir": { "type": "integer", "description": "标注方向,缺省 0" },
"text_up_down": { "type": "integer", "description": "上下标记:1 上 / -1 下,缺省 1" },
@@ -539,7 +616,7 @@ public:
"text_style": { "type": "string", "description": "文字样式,缺省 Pipe_Dim" },
"color": { "type": "integer" }
},
"required": [ "target", "points" ]
"required": [ "target" ]
})");
}
@@ -619,13 +696,65 @@ public:
}
pDim->AddDimText(sUp.c_str(), sDown.empty() ? NULL : sDown.c_str());
bool bPointsOk = false;
AppendPoints(pDim, args, bPointsOk);
if (!bPointsOk)
AcGePoint3d ptPlaced1(0.0, 0.0, 0.0), ptPlaced2(0.0, 0.0, 0.0);
bool bHasPlaced = false;
// 放置方式:在线/线上/线下(照 AecPlumbingDrawWDimonX 自动算两点)
const std::wstring sPlace = hasKey(args, "placement") ? wstrOr(args, "placement", L"") : std::wstring();
double dUpdownSpace = numOr(args, "dim_updown_space", -1.0);
if (!sPlace.empty() && sPlace != L"custom")
{
delete pDim;
return errJson(kErrBadParam, L"points 要给两个点:[[引出起点],[文字位置]]");
AcGePoint3d ptPick(0.0, 0.0, 0.0);
if (!readPoint(args, "pick", ptPick))
{
delete pDim;
return errJson(kErrBadParam, L"placement 需要 pick(在管上点一个位置)");
}
AcDbEntity* pT = openByHandle(sTarget, AcDb::kForRead);
AcGePoint3d pt1(0.0, 0.0, 0.0), pt2(0.0, 0.0, 0.0);
double dDnDraw = 0.0;
std::wstring sErr;
const bool bOk = ComputeOnlinePoints(pT, ptPick, numOr(args, "lead_length", 500.0),
pt1, pt2, dDnDraw, sErr);
if (pT != NULL) pT->close();
if (!bOk)
{
delete pDim;
return errJson(kErrBadParam, sErr);
}
pDim->SetDimStyle((short)(hasKey(args, "dim_style") ? intOr(args, "dim_style", 1) : 1));
pDim->AppendPoint(pt1);
pDim->AppendPoint(pt2);
ptPlaced1 = pt1; // 回给调用方核对位置
ptPlaced2 = pt2;
bHasPlaced = true;
if (dUpdownSpace < 0.0) dUpdownSpace = dDnDraw; // 命令:SetDimupdownSpace(dDn)
// above=线上(只写上排)/ below=线下(只写下排)/ on_line=在线(两排都写)
if (!hasKey(args, "text") && !hasKey(args, "text_down"))
{
if (sPlace == L"above" && !sDown.empty()) sDown.clear();
if (sPlace == L"below" && !sUp.empty()) sUp.clear();
// 文字是上面拼好的,这里要重新写一遍
CString sUpAll, sDownAll;
pDim->RemoveAll(1);
pDim->RemoveAll(-1);
pDim->AddDimText(CString(sUp.c_str()), sDown.empty() ? NULL : (LPCTSTR)CString(sDown.c_str()));
}
}
else
{
bool bPointsOk = false;
AppendPoints(pDim, args, bPointsOk);
if (!bPointsOk)
{
delete pDim;
return errJson(kErrBadParam, L"points 要给两个点:[[引出起点],[文字位置]](或用 placement + pick 自动算)");
}
}
if (dUpdownSpace >= 0.0) pDim->SetDimupdownSpace(dUpdownSpace);
AcDbObjectId idNew;
Acad::ErrorStatus es = addToSpace(pDim, &idNew);
@@ -650,6 +779,12 @@ public:
body["ok"] = true;
body["type"] = "pipe_dim";
body["params"] = o;
if (bHasPlaced)
{
body["points"] = nlohmann::json::array();
body["points"].push_back({ ptPlaced1.x, ptPlaced1.y, ptPlaced1.z });
body["points"].push_back({ ptPlaced2.x, ptPlaced2.y, ptPlaced2.z });
}
pDim->close();
body["handle"] = HandleOfId(idNew);
return okJson(body);
@@ -5658,7 +5658,7 @@
},
{
"name": "add_aec_pipe_dim",
"description": "建管线标注(AecDbEwPipeDim,纯 2D 无 3D 显示)。覆盖 8 个标注命令:seq=PL_XHBZ 序号 / seq_batch=PL_XHPB 序号批标 / opening=PL_DKBZ 洞口 / casing=PL_TGBZ 套管 / ring=PL_YHBZ 翼环 / valve=PL_FMBZ 阀门 / iso_valve=IS_BZFM 标注阀门 / iso_fitting=IS_GZGJ 标注管件。给被标注实体 handle + 引出起点/文字位置两个点;**文字默认从实体数据自动拼**(洞口·套管读 AecInterface,翼环读 PIPE_TOD/PIPE_YMS,阀门读 KEY_NAME,序号读 KEY_BOMNO),格式与命令一致;想覆盖就传 text / text_down。另外 kind=system 时走「系统标注」那套:读模型里的标注设置(KTModelLayoutXData 的 ScriptT/ScriptB 字段脚本),用实体数据替换 {0}~{13}(公称直径/介质/管号/压力等级/外径×壁厚/标高/保温伴热/弯头比率/材质/区号/系统/单元号);{6} 类型字段原版要查设备库,本插件不查库、留空。",
"description": "建管线标注(AecDbEwPipeDim,纯 2D 无 3D 显示)。覆盖 8 个标注命令:seq=PL_XHBZ 序号 / seq_batch=PL_XHPB 序号批标 / opening=PL_DKBZ 洞口 / casing=PL_TGBZ 套管 / ring=PL_YHBZ 翼环 / valve=PL_FMBZ 阀门 / iso_valve=IS_BZFM 标注阀门 / iso_fitting=IS_GZGJ 标注管件。给被标注实体 handle + 引出起点/文字位置两个点;**文字默认从实体数据自动拼**(洞口·套管读 AecInterface,翼环读 PIPE_TOD/PIPE_YMS,阀门读 KEY_NAME,序号读 KEY_BOMNO),格式与命令一致;想覆盖就传 text / text_down。另外 kind=system 时走「系统标注」那套:读模型里的标注设置(KTModelLayoutXData 的 ScriptT/ScriptB 字段脚本),用实体数据替换 {0}~{13}(公称直径/介质/管号/压力等级/外径×壁厚/标高/保温伴热/弯头比率/材质/区号/系统/单元号);{6} 类型字段原版要查设备库,本插件不查库、留空。placement=on_line/above/below 时按命令(AecPlumbingDrawWDimonX)的规则自动定位:pick 投影到管轴 → 法向偏 DN/2 → 再沿线 lead_length(500) 得到第二个点,并只保留对应那一排文字(above 只上排 / below 只下排),上下排间距缺省取管径。",
"inputSchema": {
"type": "object",
"properties": {
@@ -5749,11 +5749,35 @@
"elevation": {
"type": "number",
"description": "kind=system 时给管线标高(填 {5} 字段),缺省 0"
},
"placement": {
"type": "string",
"enum": [
"on_line",
"above",
"below",
"custom"
],
"description": "放置方式:on_line 在线(上下排都写)/ above 线上(只写上排)/ below 线下(只写下排);给了就用 pick 自动算两点,不用再给 points"
},
"pick": {
"type": "array",
"items": {
"type": "number"
},
"description": "placement 用:在管上点一个位置(自动投影到管轴)"
},
"lead_length": {
"type": "number",
"description": "placement 用:沿管轴的引出长度,缺省 500(命令里的值)"
},
"dim_updown_space": {
"type": "number",
"description": "上下排文字间距,缺省按放置方式(在线=管径,引出/垂直=0)"
}
},
"required": [
"target",
"points"
"target"
]
},
"backend": {
+37
View File
@@ -1114,3 +1114,40 @@ KTModelLayoutXData::ReadModelXData(KT_PIPEINIT, xDataMap) // AecRxBase 导出
**还没做**:17 个命令各自的"放置方式"(在线/线上/线下只是决定写哪一排文字;引出、垂直那几种的
点位与引出线规则还没搬),以及 {6} 类型字段的查库。
**「在线 / 线上 / 线下」标注的自动定位(`placement`)**
命令那边只有这一组会**自己算两点**(`AecPlumbingDrawWDimonX`),规则照搬进工具了:
```
管轴向 vtDir = 管线起终点方向;先按象限规整(第2、3象限要旋转/取反到第1、4象限)
法向 vtV = 规整后的轴向绕 Z 转 90°
第1点 = pick 在管轴上的投影 + vtV × (DN/2) ← 贴着管子表面起
第2点 = 第1点 + vtDir × lead_length(缺省 500) ← 沿管轴引出
SetDimStyle(1),SetDimupdownSpace(DN)
```
`nPos` 只决定写哪一排(不改变位置):
| placement | 对应命令 | 文字 |
| --- | --- | --- |
| `on_line` | `PL_ZXBZ` 在线标注 `WDimonX(2)` | 上下排都写 |
| `above` | `PL_XSBZ` 线上标注 `WDimonX(0)` | 只写上排 |
| `below` | `PL_XXBZ` 线下标注 `WDimonX(1)` | 只写下排 |
| `custom` | — | 用调用方给的 `points`(原行为) |
给了 `placement` + `pick` 就不用再传 `points`;返回值里会带上算出来的两个点,方便核对。
**引出标注/引出上标、垂直标注/垂直侧标不用搬**:它们本来就是"用户点两个点"
(`AecPlumbingDrawWDimldrxx` / `WdImldryyx` 都是 `acedGetPoint` 取第二点),
差别只在 `SetDimStyle(0)`、`SetDimDir(0 或 1)`、`SetDimupdownSpace(0)`:
| 想要的命令 | 现在怎么写 |
| --- | --- |
| `PL_YCBZ` 引出标注 / `PL_YCSB` 引出上标 | `dim_style=0`、`dim_dir=0`、`dim_updown_space=0`,`points` 给两点(第一点落在实体上) |
| `PL_ZZBZ` 垂直标注 | 同上,但 `dim_dir=1` |
| `PL_ZZCB` 垂直侧标 | `dim_dir=1` + `text_up_down=0` |
**实测**(R230 Debug,空图):DN100 管沿 +X、`placement=on_line`、`pick=(3000,0,1000)`
→ 返回两点 `(3000, 50, 1000)` 与 `(3500, 50, 1000)`(法向偏 DN/2=50、沿线 +500,符合规则);
`above` 只剩上排 `100`、`below` 只剩下排 `114x4.0-<标高符号>1.000m`。