feat: 管线标注文字改成从被标注实体自动拼(与命令格式一致) #156
No files matched your search
@@ -26,6 +26,9 @@
|
||||
|
||||
#include "AecDbObjXDataMap.h"
|
||||
#include "AecDbEwPipeDim.h"
|
||||
#include "AecDbX3dPartEntity.h"
|
||||
#include "AecDbBDPipeBase.h"
|
||||
#include "AecDbCurveBase.h"
|
||||
#include "AecDbObjXDataMap.h"
|
||||
#include "CoreTools.h"
|
||||
#include "KTCadUtility.h"
|
||||
@@ -48,6 +51,128 @@ namespace
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// 标注文字的"自动拼":按 kind 从被标注实体的专业数据里算
|
||||
// 对照命令里的格式(PL_DKBZ / PL_TGBZ / PL_YHBZ / PL_FMBZ / PL_XHBZ):
|
||||
// 洞口: "预留D%d洞口"(圆, +0.2) / "预留%dx%d洞口"(矩形, +0.5)
|
||||
// 套管: "预埋<类型>" + "D%dx%.1f 中心标高 %.3f" 或 "%.1fx%.1f t=%.1f 中心标高 %.3f"
|
||||
// 翼环: "翼环D%s 数量%d个"(PIPE_TOD / PIPE_YMS)
|
||||
// 阀门: 实体专业数据里的 KEY_NAME
|
||||
// 单位:command 里 m_bUnitM=是就用米(/=1000),这里用 unit 参数控;dElvBase 是标高基准。
|
||||
// 返回 false 表示这条 kind 拼不出来(比如序号类要人给),由调用方回退到 text 参数。
|
||||
bool ComposeDimText(AcDbEntity* pTarget, const std::wstring& sKind, bool bUnitM, double dElvBase,
|
||||
std::wstring& sUp, std::wstring& sDown)
|
||||
{
|
||||
sUp.clear();
|
||||
sDown.clear();
|
||||
if (pTarget == NULL) return false;
|
||||
|
||||
const int nUnit = bUnitM ? 1000 : 1;
|
||||
|
||||
// 洞口 / 套管:AecDbX3dPartEntity 的接口数据
|
||||
if (sKind == L"opening" || sKind == L"casing")
|
||||
{
|
||||
AecDbX3dPartEntity* pPart = AecDbX3dPartEntity::cast(pTarget);
|
||||
if (pPart == NULL) return false;
|
||||
|
||||
AecInterface inf;
|
||||
::memset(&inf, 0, sizeof(AecInterface));
|
||||
if (!pPart->GetInterface(0, inf)) return false;
|
||||
|
||||
const double dEl = inf.ptPos.z / nUnit + dElvBase / nUnit;
|
||||
const bool bCircle = (inf.nSectType == (short)eCircle);
|
||||
|
||||
CString cUp, cDwn;
|
||||
if (sKind == L"opening")
|
||||
{
|
||||
if (bCircle)
|
||||
cUp.Format(_T("预留D%d洞口"), (int)(inf.dSize1 + 0.2));
|
||||
else
|
||||
cUp.Format(_T("预留%dx%d洞口"), (int)(inf.dSize1 + 0.5), (int)(inf.dSize2 + 0.5));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 套管:类型名取专业数据里的 PIPE_TYPE,没有就用"套管"
|
||||
CString sType;
|
||||
if (!pPart->GetSpecialtyData(AcDb::kForRead)->GetAt(KEY_PIPETYPE, sType) || sType.IsEmpty())
|
||||
sType = _T("套管");
|
||||
cUp.Format(_T("预埋%s"), (LPCTSTR)sType);
|
||||
|
||||
double dT = 0.0;
|
||||
if (!pPart->GetSpecialtyData(AcDb::kForRead)->GetAt(PIPE_THICK, dT) || dT <= 0.0)
|
||||
pPart->GetSpecialtyData(AcDb::kForRead)->GetAt(_T("dT"), dT); // 套管的壁厚存在 dT
|
||||
if (bCircle)
|
||||
// 厚度我们按图纸单位存(不是 mm),所以不再除 nUnit
|
||||
cDwn.Format(_T("D%dx%.1f 中心标高 %.3f"), (int)(inf.dSize1 + 0.2), dT, dEl);
|
||||
else
|
||||
cDwn.Format(_T("%.1fx%.1f t=%.1f 中心标高 %.3f"), inf.dSize1, inf.dSize2, dT, dEl);
|
||||
}
|
||||
if (sKind == L"opening")
|
||||
cDwn.Format(_T("中心标高 %.3f"), dEl);
|
||||
|
||||
sUp = std::wstring((LPCTSTR)cUp);
|
||||
sDown = std::wstring((LPCTSTR)cDwn);
|
||||
return !sUp.empty();
|
||||
}
|
||||
|
||||
// 翼环:PIPE_TOD 外径(字符串)+ PIPE_YMS 数量(int)
|
||||
if (sKind == L"ring")
|
||||
{
|
||||
AecDbBDPipeBase* pBase = AecDbBDPipeBase::cast(pTarget);
|
||||
AecDbEntityBase* pEntBase = AecDbEntityBase::cast(pTarget);
|
||||
if (pBase == NULL && pEntBase == NULL) return false;
|
||||
|
||||
AecDbObjXDataMap* pMap = (pBase != NULL) ? pBase->GetSpecialtyData(AcDb::kForRead)
|
||||
: pEntBase->GetSpecialtyData(AcDb::kForRead);
|
||||
if (pMap == NULL) return false;
|
||||
|
||||
CString sD2;
|
||||
int nD2 = 0;
|
||||
if (!pMap->GetAt(PIPE_TOD, sD2)) return false;
|
||||
pMap->GetAt(PIPE_YMS, nD2);
|
||||
|
||||
CString cUp;
|
||||
cUp.Format(_T("翼环D%s 数量%d个"), (LPCTSTR)sD2, nD2);
|
||||
sUp = std::wstring((LPCTSTR)cUp);
|
||||
return !sUp.empty();
|
||||
}
|
||||
|
||||
// 阀门 / 标注管件:库里存的 KEY_NAME
|
||||
if (sKind == L"valve" || sKind == L"iso_valve" || sKind == L"iso_fitting")
|
||||
{
|
||||
AecDbCurveBase* pCur = AecDbCurveBase::cast(pTarget);
|
||||
AecDbEntityBase* pEntBase = AecDbEntityBase::cast(pTarget);
|
||||
AecDbObjXDataMap* pMap = NULL;
|
||||
if (pCur != NULL) pMap = pCur->GetSpecialtyData(AcDb::kForRead);
|
||||
else if (pEntBase != NULL) pMap = pEntBase->GetSpecialtyData(AcDb::kForRead);
|
||||
if (pMap == NULL) return false;
|
||||
|
||||
CString sName;
|
||||
if (!pMap->GetAt(KEY_NAME, sName) || sName.IsEmpty()) return false;
|
||||
sUp = std::wstring((LPCTSTR)sName);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 序号类:实体上可能存着 KEY_BOMNO,有就用它当默认;没有就只能让调用方给 text
|
||||
if (sKind == L"seq" || sKind == L"seq_batch")
|
||||
{
|
||||
AecDbCurveBase* pCur = AecDbCurveBase::cast(pTarget);
|
||||
AecDbEntityBase* pEntBase = AecDbEntityBase::cast(pTarget);
|
||||
AecDbObjXDataMap* pMap = NULL;
|
||||
if (pCur != NULL) pMap = pCur->GetSpecialtyData(AcDb::kForRead);
|
||||
else if (pEntBase != NULL) pMap = pEntBase->GetSpecialtyData(AcDb::kForRead);
|
||||
if (pMap == NULL) return false;
|
||||
|
||||
CString sBomNo;
|
||||
if (!pMap->GetAt(KEY_BOMNO, sBomNo) || sBomNo.IsEmpty()) return false;
|
||||
sUp = std::wstring((LPCTSTR)sBomNo);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 8 个命令各自的 dim style(命令里写死的取值,没给的用 3=序号标注)
|
||||
int StyleOfKind(const std::wstring& sKind)
|
||||
{
|
||||
@@ -107,8 +232,10 @@ public:
|
||||
"description": "标注种类(决定 dim style 与语义),缺省 seq" },
|
||||
"points": { "type": "array", "items": { "type": "array", "items": { "type": "number" } },
|
||||
"description": "两个点:[[引出起点],[文字位置]]" },
|
||||
"text": { "type": "string", "description": "上排文字(序号/洞洞尺寸等)" },
|
||||
"text_down": { "type": "string", "description": "下排文字(如中心标高)" },
|
||||
"text": { "type": "string", "description": "上排文字;不给就按 kind 从被标注实体自动拼(与命令一致)" },
|
||||
"text_down": { "type": "string", "description": "下排文字;不给就自动拼" },
|
||||
"unit": { "type": "string", "enum": [ "m", "mm" ], "description": "尺寸/标高的单位,缺省 m(命令里 m_bUnitM)" },
|
||||
"elevation_base": { "type": "number", "description": "标高基准(命令里的 dElv),缺省 0" },
|
||||
"dim_style": { "type": "integer", "description": "标注样式编号,缺省按 kind" },
|
||||
"dim_dir": { "type": "integer", "description": "标注方向,缺省 0" },
|
||||
"text_up_down": { "type": "integer", "description": "上下标记:1 上 / -1 下,缺省 1" },
|
||||
@@ -119,7 +246,7 @@ public:
|
||||
"text_style": { "type": "string", "description": "文字样式,缺省 Pipe_Dim" },
|
||||
"color": { "type": "integer" }
|
||||
},
|
||||
"required": [ "target", "points", "text" ]
|
||||
"required": [ "target", "points" ]
|
||||
})");
|
||||
}
|
||||
|
||||
@@ -163,8 +290,27 @@ public:
|
||||
pDim->SetTextWidthScale(numOr(args, "text_width_scale", 0.75));
|
||||
if (hasKey(args, "color")) pDim->setColorIndex((Adesk::UInt16)intOr(args, "color", 256));
|
||||
|
||||
const std::wstring sUp = wstrOr(args, "text", L"");
|
||||
const std::wstring sDown = hasKey(args, "text_down") ? wstrOr(args, "text_down", L"") : std::wstring();
|
||||
// 文字:传了就用传的;没传就按 kind 从被标注实体自动拼(与命令一致)
|
||||
std::wstring sUp, sDown;
|
||||
if (hasKey(args, "text"))
|
||||
{
|
||||
sUp = wstrOr(args, "text", L"");
|
||||
if (hasKey(args, "text_down")) sDown = wstrOr(args, "text_down", L"");
|
||||
}
|
||||
else
|
||||
{
|
||||
const bool bUnitM = (wstrOr(args, "unit", L"m") != L"mm");
|
||||
AcDbEntity* pT = openByHandle(sTarget, AcDb::kForRead);
|
||||
const bool bComposed = ComposeDimText(pT, wstrOr(args, "kind", L"seq"), bUnitM,
|
||||
numOr(args, "elevation_base", 0.0), sUp, sDown);
|
||||
if (pT != NULL) pT->close();
|
||||
if (!bComposed)
|
||||
{
|
||||
delete pDim;
|
||||
return errJson(kErrBadParam,
|
||||
L"这个 kind 拼不出文字(序号类要实体上有编号,其它类要实体数据齐全),请传 text / text_down");
|
||||
}
|
||||
}
|
||||
pDim->AddDimText(sUp.c_str(), sDown.empty() ? NULL : sDown.c_str());
|
||||
|
||||
bool bPointsOk = false;
|
||||
|
||||
@@ -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、引出起点+文字位置两个点、上/下文字。注意:命令里文字是按被标注实体数据自动拼的(如\"预留D300洞口\"),这版要调用方自己传 text。",
|
||||
"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。",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -5692,11 +5692,11 @@
|
||||
},
|
||||
"text": {
|
||||
"type": "string",
|
||||
"description": "上排文字"
|
||||
"description": "上排文字;不给就按 kind 从被标注实体自动拼(与命令一致)"
|
||||
},
|
||||
"text_down": {
|
||||
"type": "string",
|
||||
"description": "下排文字"
|
||||
"description": "下排文字;不给就自动拼"
|
||||
},
|
||||
"layer": {
|
||||
"type": "string",
|
||||
@@ -5732,12 +5732,23 @@
|
||||
"p_scale": {
|
||||
"type": "number",
|
||||
"description": "出图比例,缺省 100"
|
||||
},
|
||||
"unit": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"m",
|
||||
"mm"
|
||||
],
|
||||
"description": "尺寸/标高的单位,缺省 m"
|
||||
},
|
||||
"elevation_base": {
|
||||
"type": "number",
|
||||
"description": "标高基准(命令里的 dElv),缺省 0"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"target",
|
||||
"points",
|
||||
"text"
|
||||
"points"
|
||||
]
|
||||
},
|
||||
"backend": {
|
||||
|
||||
+25
-1
@@ -101,7 +101,7 @@ if (IS_ZWCAD OR CAD_SDK_VERSION GREATER_EQUAL 20)
|
||||
| `list_aec_pipe_hangers` / `add_aec_pipe_hanger` / `update_aec_pipe_hanger` | 管道托架/支座(`AecDbPipeHanger`,图集 03S42):`PL_DGTJ` 单管托架 / `PL_SGTJ` 双管托架 / `PL_LGTJ` 立管托架 / `PL_PGZZ` 平管支座 / `PL_WGZZ` 弯管支座。型号来自 `<安装目录>/Support/Holder`(Holder0~4.txt + .pms + .csv) | `kind`、`index`/`name`/`pms`、`csv_row`、`vars`(覆盖参数)、`position`/`rotation_deg`/`rows`/`row_spacing`/`direction`、`elbow`/`elbow_od`(弯管支座) |
|
||||
| `add_aec_boss_holder` / `update_aec_boss_holder` | 沿路径摆支墩(`AecDbBossHolder`,`PL_FZZD`) | `points`/`spacing`/`bottom_elevation`、`holder_type`/`width`/`thickness`/`length`/`channel_c`/`channel_b`/`layer_count`/`step_height`/`support_height`/`material`/`no` |
|
||||
| `add_aec_ditch` / `update_aec_ditch` | 建/改沟渠(`AecDbEwPipeBase`,`PL_LSJM`):走向 `points` + U 形断面(总宽/总高/内底宽/坡度角/壁厚) | `points`、`width`/`height`/`inner_width`/`angle`/`wall_thickness`/`bottom_elevation`/`material`/`purpose` |
|
||||
| `add_aec_pipe_dim` / `update_aec_pipe_dim` | 建/改管线标注(`AecDbEwPipeDim`,纯 2D):覆盖 序号/序号批标/洞口/套管/翼环/阀门/标注阀门/标注管件 8 个命令 | `target`、`kind`、`points`(引出点+文字点)、`text`/`text_down`、`dim_style`/`dim_dir`/`text_up_down`/`text_height`/`text_width_scale`/`p_scale` |
|
||||
| `add_aec_pipe_dim` / `update_aec_pipe_dim` | 建/改管线标注(`AecDbEwPipeDim`,纯 2D):覆盖 序号/序号批标/洞口/套管/翼环/阀门/标注阀门/标注管件 8 个命令。**文字默认从被标注实体的数据自动拼**(与命令格式一致),`text`/`text_down` 可选覆盖 | `target`、`kind`、`points`(引出点+文字点)、`unit`(m/mm)、`elevation_base`、`text`/`text_down`、`dim_style`/`dim_dir`/`text_up_down`/`text_height`/`text_width_scale`/`p_scale` |
|
||||
| `add_aec_apron` / `update_aec_apron` | 建/改散水(`AecDbXApron`,`PL_FZSS`):走向 `points` | `points`、`width`/`inside_thickness`/`outside_thickness`/`offset_from_wall`/`elevation` |
|
||||
| `add_aec_window` / `update_aec_window` | 建/改普通门窗(`AecDbXOpening`,`PL_QTCC` 等"插入门窗"):给墙 handle + 定位点(自动投影到墙中心线)+ 门窗块 + 宽高窗台高,内部扣墙的 2D 洞口并挂到墙的关联件 | `wall`、`position`、`block`/`block_3d`、`type`(window/door)、`width`/`height`/`sill_height`/`thickness`、`no`/`name`/`material`/`factory` |
|
||||
| `add_aec_sfp_stair` / `update_aec_sfp_stair` | 建/改双分·双平行家族楼梯(`SFPXStair` 一套数据,7 种实体 + `kind`):双平行/双分转角/双分三跑/交叉/剪刀/三角/矩形转角 | `kind`、`start`+`direction_point`、`height`/`steep_*`/`total_width`/`run_width`/`mid_run_width`/`well_width`/`rest_platform_width`/`platform_thickness`、扶手栏杆开关与高度、`material`/`rail_material`;update 另收边梯/中梯/剖切步数、内外边梁、上梯位置、踏步取齐、层显示、平台形状、加强筋、扶手/栏杆截面与伸出、双分系列的对称与 1~4 跑跑数跑宽 |
|
||||
@@ -996,3 +996,27 @@ mode:0 单管 / 1 双管 / 2 立管 / 3 平管 / 4 弯管。
|
||||
bbox `0~8600 × −1200~0`;改成 8/8/8 + 侧梁 80 后回读正确。
|
||||
立管固架(墙 8000×4000 厚 240、立管 DN100 从 −500 到 3500)→ 位置 `(3025, 120, 833)`,
|
||||
正好是"墙厚中点 + 半个(外径+角钢宽)"、标高 `−500 + 4000/3`。
|
||||
|
||||
**标注文字改成"从实体自动拼"(作者定的方向)**
|
||||
|
||||
原来要调用方自己传 `text`/`text_down`,容易和图上的实际尺寸/标高高不上;现在
|
||||
`add_aec_pipe_dim` 只给 `target`(被标注实体 handle)+ `kind` + 两个点,文字由工具按
|
||||
命令的格式从实体数据算:
|
||||
|
||||
| kind | 数据来源 | 拼出来的样子 |
|
||||
| --- | --- | --- |
|
||||
| `opening` 洞口 | `AecDbX3dPartEntity::GetInterface(0)` → `nSectType` / `dSize1` / `dSize2` / `ptPos` | 圆 `预留D%d洞口`(+0.2 取整)、矩形 `预留%dx%d洞口`(+0.5);下排 `中心标高 %.3f` |
|
||||
| `casing` 套管 | 同上 + `KEY_PIPETYPE`(类型)+ `PIPE_THICK`(没有就用 `dT`) | 上排 `预埋<类型>`;下排 `D%dx%.1f 中心标高 %.3f` / `%.1fx%.1f t=%.1f 中心标高 %.3f` |
|
||||
| `ring` 翼环 | `PIPE_TOD`(外径字符串)+ `PIPE_YMS`(数量) | `翼环D%s 数量%d个` |
|
||||
| `valve` / `iso_valve` / `iso_fitting` | 实体专业数据的 `KEY_NAME` | 直接就是名称 |
|
||||
| `seq` / `seq_batch` 序号 | 实体专业数据的 `KEY_BOMNO` | 有编号就自动用;没有则**明确报错**要求传 `text`(序号本质要人来定) |
|
||||
|
||||
补充两个参数:`unit`(`m`/`mm`,对应命令里的 `m_bUnitM`,缺省 m)和 `elevation_base`
|
||||
(命令里的 `dElv`,标高基准,缺省 0)。传了 `text`/`text_down` 就以传的为准(覆盖)。
|
||||
|
||||
**坑**:套管的壁厚存的是图纸单位(不是 mm),所以拼下排文字时**不能再除 1000**,
|
||||
否则会打成 `D300x0.0`。
|
||||
|
||||
**实测**(R230 Debug,空图):板上 D400 圆洞 → 标注自动出 `预留D400洞口` + `中心标高 0.150`;
|
||||
同一个洞传 `text` 覆盖 → 用的是传进来的文字;D300 柔性防水套管 → `预埋柔性防水套管` +
|
||||
`D300x15.0 中心标高 0.150`;对没有编号的洞要 `kind=seq` → 报错要求传 text。
|
||||
Reference in new issue
Block a user