一、带形窗 AecDbZLineXOpening(新文件 aec_mcp_zline_window_tools.cpp) 命令:GetPathOnWall 取墙路径 -> CDXCHDlg 的 OpeningData(dXData[0..10] 存柱距/首排高/ 框料厚宽/玻璃厚/外伸×2/挑出×2/玻璃内偏/挡板厚)-> SetOpeningData(data, arIds)(数组重载) + SetZLinePoints + KEY_StartDir -> 入库后逐面墙 AppendAssocPart + SubtractDraw2d。 按总原则:add 只给窗高/窗台高/柱距/凸窗,update 收全套框料/玻璃/外伸/挑出/挡板。 二、支吊架(新文件 aec_mcp_holder_tools.cpp,6 个工具) - PL_FZZJ 支架 AecDbHolder、PL_FZDJ 吊架 AecDbHanger、PL_FZZD 支墩 AecDbBossHolder 套路一致:对话框填结构体 -> jig 画路径 -> 点一下给支臂方向 -> 沿路径按 "个数=路径长/间距" 摆一串,每个 SetPosition(ptPos, vtLL) + LAY_SUPPORT。 工具里 points/spacing/direction_point,一次建整串,返回 count + handles。 顺带把"沿墙取路径"从附属构件里提到 aec_mcp_common(buildWallPath), 带形窗与阳台/台阶共用;前向声明放全局,避免和 using namespace aec_mcp 打架。 两个坑: 1. PL_FZDJ 建的是 AecDbHanger,不是 AecDbPipeHanger(后者没被这条命令用到) 2. AcDbCurve::getFirstDeriv 收参数、getPointAtDist 收距离,混用会报"沿路径取点/切线失败"; 改成 getParamAtDist 再取切线 做不了的:PL_ZJCH 转角窗 —— PL_ZJCHCmdFnc 打开对话框后函数体是空的、注册也被注释掉了。 实测(R230 Debug,空图): - 带形窗(墙 12000、沿墙 1000~9000、柱距 1200)-> 311,bbox x 967~9000; 精修框料 80/玻璃 40/首排 900/加挡板 回读正确 - 支架(9000 路径 / 间距 1500)-> 6 个;吊架 -> 4 个;支墩 -> 4 个;三者 update 都回读正确 工具总数 81 -> 89(本插件 53 -> 61),R230/Z2026 都编过。
794 lines
29 KiB
C++
794 lines
29 KiB
C++
// ============================================================================
|
||
// aec_mcp_holder_tools.cpp
|
||
// cad_mcp_aec 的支吊架工具(工作计划第 6 项)
|
||
// * add/update_aec_holder —— 支架 AecDbHolder(PL_FZZJ)
|
||
// * add/update_aec_hanger —— 吊架 AecDbHanger(PL_FZDJ)【不是 AecDbPipeHanger,
|
||
// PL_FZDJ 建的是 AecDbHanger】
|
||
// * add/update_aec_boss_holder —— 支墩 AecDbBossHolder(PL_FZZD)
|
||
//
|
||
// 三个命令的套路一样(Pool3dCmd/pool3dcmdCmd.cpp PL_FZZJ/PL_FZDJ/PL_FZZD):
|
||
// 对话框填结构体(XHolder / XHanger / XBossHolder)
|
||
// -> 用 jig 画一条路径
|
||
// -> 再点一下给出"支臂方向"
|
||
// -> 沿路径按间距 m_dX 摆 nXs = 路径长 / 间距 个实例:
|
||
// new AecDbXxx; SetXxx(data); SetPosition(ptPos, vtLL); setLayer(LAY_SUPPORT);
|
||
// (支架还会把支持的管线系统写进 KEY_SYSCNT / KEY_SYS%d)
|
||
// 工具里:`points` 给路径,`spacing` 给间距,`direction_point` 给支臂方向(可选),
|
||
// 沿路径按同样规则摆一串实例;单个实例的"改"用 handle + update。
|
||
// ============================================================================
|
||
|
||
#include "StdAfx.h"
|
||
#include "KTCad.h"
|
||
#include "aec_mcp_common.h"
|
||
#include "mcp_plugin_api.h"
|
||
|
||
#include "AecDbHolder.h"
|
||
#include "AecDbHanger.h"
|
||
#include "AecDbBossHolder.h"
|
||
#include "AecDbObjXDataMap.h"
|
||
#include "CoreTools.h"
|
||
#include "KTSetting.h"
|
||
|
||
using namespace aec_mcp;
|
||
|
||
namespace
|
||
{
|
||
std::string HandleOfId(const AcDbObjectId& id)
|
||
{
|
||
if (id.isNull()) return std::string();
|
||
AcDbObject* pObj = NULL;
|
||
if (Acad::eOk != acdbOpenObject(pObj, id, AcDb::kForRead)) return std::string();
|
||
const std::string s = handleOf(pObj);
|
||
pObj->close();
|
||
return s;
|
||
}
|
||
|
||
void CopyStr(TCHAR* pszDst, int nSize, const std::wstring& sSrc)
|
||
{
|
||
if (pszDst == NULL || nSize <= 0) return;
|
||
_tcsncpy(pszDst, sSrc.c_str(), nSize - 1);
|
||
pszDst[nSize - 1] = 0;
|
||
}
|
||
|
||
// 路径点 -> 多段线(用来算切线;命令行和工具都按"沿路径均匀分布"来摆)
|
||
AcDbPolyline* PathOfPoints(const nlohmann::json& a, std::wstring& err)
|
||
{
|
||
if (!hasKey(a, "points") || !a["points"].is_array() || a["points"].size() < 2)
|
||
{
|
||
err = L"需要 points:[[x,y],...](支吊架沿这条路径摆,至少 2 点)";
|
||
return NULL;
|
||
}
|
||
AcDbPolyline* pPl = new AcDbPolyline((int)a["points"].size());
|
||
int nIdx = 0;
|
||
for (size_t i = 0; i < a["points"].size(); ++i)
|
||
{
|
||
const nlohmann::json& pt = a["points"][i];
|
||
if (!pt.is_array() || pt.size() < 2) continue;
|
||
pPl->addVertexAt(nIdx++, AcGePoint2d(pt[0].get<double>(), pt[1].get<double>()), 0.0, 0.0, 0.0);
|
||
}
|
||
if (nIdx < 2) { delete pPl; err = L"points 有效点少于 2 个"; return NULL; }
|
||
return pPl;
|
||
}
|
||
|
||
// 支臂方向:命令里是 vtLL = vtL.orthoProject(切线) 再归一化;
|
||
// 若结果长度为 0(用户给的方向正好垂直于路径),退回"切线绕 Z 转 90°"。
|
||
bool ArmDir(const AcGeVector3d& vtPick, const AcGeVector3d& vtTan, AcGeVector3d& vtOut)
|
||
{
|
||
AcGeVector3d vtT = vtTan;
|
||
vtT.normalize();
|
||
vtOut = vtPick;
|
||
if (vtOut.length() < 1e-9)
|
||
{
|
||
vtOut = AcGeVector3d::kZAxis.crossProduct(vtT);
|
||
}
|
||
else
|
||
{
|
||
vtOut = vtT * vtOut.dotProduct(vtT); // orthoProject(vtT)
|
||
if (vtOut.length() < 1e-9)
|
||
vtOut = AcGeVector3d::kZAxis.crossProduct(vtT);
|
||
}
|
||
if (vtOut.length() < 1e-9) return false;
|
||
vtOut.normalize();
|
||
return true;
|
||
}
|
||
|
||
// 沿路径算每个实例的落点与方向(与命令一致:nXs = 路径长 / 间距,按等分取)
|
||
bool LayoutAlongPath(AcDbCurve* pPath, double dSpacing, double dEl, const AcGeVector3d& vtPick,
|
||
AcGePoint3dArray& arPts, AcArray<AcGeVector3d>& arDirs, std::wstring& err)
|
||
{
|
||
if (dSpacing <= 0.0) { err = L"spacing 必须 > 0"; return false; }
|
||
|
||
// 注意:getFirstDeriv 收的是**参数**,getPointAtDist 收的是**距离**,
|
||
// 一开始混用导致"沿路径取点/切线失败";这里用 getParamAtDist 把距离换成参数。
|
||
double dEndParam = 0.0, dLen = 0.0;
|
||
if (pPath->getEndParam(dEndParam) != Acad::eOk ||
|
||
pPath->getDistAtParam(dEndParam, dLen) != Acad::eOk)
|
||
{
|
||
err = L"取路径长度失败";
|
||
return false;
|
||
}
|
||
int nXs = (int)(dLen / dSpacing);
|
||
if (nXs < 1) nXs = 1;
|
||
if (nXs > 500) nXs = 500;
|
||
const double dStep = dLen / nXs;
|
||
|
||
for (int i = 0; i < nXs; ++i)
|
||
{
|
||
AcGePoint3d ptPos(0.0, 0.0, 0.0);
|
||
AcGeVector3d vtTan(1.0, 0.0, 0.0), vtOut(0.0, 1.0, 0.0);
|
||
const double dPos = dStep * i;
|
||
double dParam = 0.0;
|
||
if (pPath->getPointAtDist(dPos, ptPos) != Acad::eOk ||
|
||
pPath->getParamAtDist(dPos, dParam) != Acad::eOk ||
|
||
pPath->getFirstDeriv(dParam, vtTan) != Acad::eOk ||
|
||
!ArmDir(vtPick, vtTan, vtOut))
|
||
{
|
||
err = L"沿路径取点/切线失败";
|
||
return false;
|
||
}
|
||
ptPos.z = dEl;
|
||
arPts.append(ptPos);
|
||
arDirs.append(vtOut);
|
||
}
|
||
return true;
|
||
}
|
||
|
||
// 三个实体共用的"支臂方向"入参
|
||
bool PickDirFromArgs(const nlohmann::json& a, const AcGePoint3d& ptFirst, AcGeVector3d& vtPick)
|
||
{
|
||
AcGePoint3d ptDir(0.0, 0.0, 0.0);
|
||
if (!readPoint(a, "direction_point", ptDir)) return false;
|
||
vtPick = ptDir - ptFirst;
|
||
return true;
|
||
}
|
||
}
|
||
|
||
// ===========================================================================
|
||
// 支架(PL_FZZJ,AecDbHolder)
|
||
// ===========================================================================
|
||
namespace
|
||
{
|
||
// CFZZJDlg 构造函数里的缺省值
|
||
void InitXHolder(XHolder& d)
|
||
{
|
||
::memset(&d, 0, sizeof(XHolder));
|
||
d.N = 3;
|
||
d.bNoEquDis = FALSE;
|
||
d.V = 500.0; // 支柱垂直长度
|
||
d.L = 800.0; // 支架臂长
|
||
d.W = 30.0; // 角钢宽
|
||
d.t = 3.0; // 角钢厚
|
||
d.dBomEl = 0.0;
|
||
CopyStr(d.szMat, 33, L"普通碳钢");
|
||
}
|
||
|
||
void HolderFromArgs(XHolder& d, const nlohmann::json& a, bool bMerge)
|
||
{
|
||
if (!bMerge) InitXHolder(d);
|
||
if (hasKey(a, "count")) d.N = intOr(a, "count", d.N);
|
||
if (hasKey(a, "post_length")) d.V = numOr(a, "post_length", d.V);
|
||
if (hasKey(a, "arm_length")) d.L = numOr(a, "arm_length", d.L);
|
||
if (hasKey(a, "steel_width")) d.W = numOr(a, "steel_width", d.W);
|
||
if (hasKey(a, "steel_thickness")) d.t = numOr(a, "steel_thickness", d.t);
|
||
if (hasKey(a, "bottom_elevation")) d.dBomEl = numOr(a, "bottom_elevation", d.dBomEl);
|
||
if (hasKey(a, "material")) CopyStr(d.szMat, 33, wstrOr(a, "material", L""));
|
||
if (hasKey(a, "no")) CopyStr(d.szNo, 33, wstrOr(a, "no", L""));
|
||
if (hasKey(a, "purpose")) CopyStr(d.szUsage, 33, wstrOr(a, "purpose", L""));
|
||
}
|
||
|
||
nlohmann::json HolderToJson(const XHolder& d)
|
||
{
|
||
nlohmann::json o;
|
||
o["count"] = d.N;
|
||
o["post_length"] = d.V;
|
||
o["arm_length"] = d.L;
|
||
o["steel_width"] = d.W;
|
||
o["steel_thickness"] = d.t;
|
||
o["bottom_elevation"] = d.dBomEl;
|
||
o["material"] = acharToUtf8(d.szMat);
|
||
o["no"] = acharToUtf8(d.szNo);
|
||
o["purpose"] = acharToUtf8(d.szUsage);
|
||
return o;
|
||
}
|
||
}
|
||
|
||
class ToolAddHolder : public mcp_Tool
|
||
{
|
||
public:
|
||
std::string private_name() const override { return "add_aec_holder"; }
|
||
|
||
std::string private_description() const override
|
||
{
|
||
return "沿路径摆一串管道支架(菜单 PL_FZZJ 放置支架,实体 AecDbHolder):给路径 points + 间距 + "
|
||
"底标高,再给支柱长/支架臂长/角钢宽厚/材质(缺省照抄 CFZZJDlg)。"
|
||
"按命令的规则:个数 = 路径长 / spacing(等分),每个支架的支臂方向取 direction_point"
|
||
"(不给就用路径切线绕 Z 转 90°)。图层 LAY_SUPPORT。返回第一个实例的 handle 和全部 handle。";
|
||
}
|
||
|
||
nlohmann::json private_input_schema() const override
|
||
{
|
||
return nlohmann::json::parse(R"({
|
||
"type": "object",
|
||
"properties": {
|
||
"points": { "type": "array", "items": { "type": "array", "items": { "type": "number" } },
|
||
"description": "支吊架沿的路径 [[x,y],...]" },
|
||
"spacing": { "type": "number", "description": "间距,缺省 1000" },
|
||
"bottom_elevation": { "type": "number", "description": "底标高,缺省 0" },
|
||
"direction_point": { "type": "array", "items": { "type": "number" },
|
||
"description": "支臂方向的参考点 [x,y](相对路径起点)" },
|
||
"count": { "type": "integer", "description": "支架个数(命令里由路径长/间距算,这里可覆盖单个实例的数据)" },
|
||
"post_length": { "type": "number", "description": "支柱垂直长度,缺省 500" },
|
||
"arm_length": { "type": "number", "description": "支架臂长,缺省 800" },
|
||
"steel_width": { "type": "number", "description": "角钢宽,缺省 30" },
|
||
"steel_thickness": { "type": "number", "description": "角钢厚,缺省 3" },
|
||
"material": { "type": "string", "description": "材质,缺省 普通碳钢" },
|
||
"no": { "type": "string", "description": "编号" },
|
||
"purpose": { "type": "string", "description": "用途" },
|
||
"layer": { "type": "string", "description": "图层,缺省 LAY_SUPPORT" },
|
||
"color": { "type": "integer" }
|
||
},
|
||
"required": [ "points", "spacing" ]
|
||
})");
|
||
}
|
||
|
||
nlohmann::json Execute(const nlohmann::json& args) override
|
||
{
|
||
if (workingDb() == NULL) return errJson(kErrNoDocument, L"没有活动图纸");
|
||
DocLock lock;
|
||
if (!lock.isLocked()) return errJson(kErrInternal, L"拿不到图纸写锁(有别的命令在跑?)");
|
||
|
||
std::wstring err;
|
||
AcDbPolyline* pPath = PathOfPoints(args, err);
|
||
if (pPath == NULL) return errJson(kErrBadParam, err);
|
||
|
||
AcGePoint3d ptFirst(0.0, 0.0, 0.0);
|
||
pPath->getStartPoint(ptFirst);
|
||
AcGeVector3d vtPick(0.0, 0.0, 0.0);
|
||
PickDirFromArgs(args, ptFirst, vtPick);
|
||
|
||
XHolder data;
|
||
HolderFromArgs(data, args, false);
|
||
const double dEl = numOr(args, "bottom_elevation", data.dBomEl);
|
||
|
||
AcGePoint3dArray arPts;
|
||
AcArray<AcGeVector3d> arDirs;
|
||
const bool bOk = LayoutAlongPath(pPath, numOr(args, "spacing", 1000.0), dEl, vtPick, arPts, arDirs, err);
|
||
delete pPath;
|
||
if (!bOk) return errJson(kErrBadParam, err);
|
||
|
||
std::wstring sLay = hasKey(args, "layer") ? wstrOr(args, "layer", L"") : L"";
|
||
if (sLay.empty()) sLay = L"LAY_SUPPORT";
|
||
AcDbObjectId idLay = KTSetting::InitLayer(sLay.c_str());
|
||
|
||
nlohmann::json arHandles = nlohmann::json::array();
|
||
for (int i = 0; i < arPts.length(); ++i)
|
||
{
|
||
AecDbHolder* pHolder = new AecDbHolder();
|
||
pHolder->SetHolder(data);
|
||
pHolder->SetPosition(arPts[i], arDirs[i]);
|
||
if (!idLay.isNull()) pHolder->setLayer(idLay);
|
||
if (hasKey(args, "color")) pHolder->setColorIndex((Adesk::UInt16)intOr(args, "color", 256));
|
||
|
||
AcDbObjectId idNew;
|
||
if (addToSpace(pHolder, &idNew) != Acad::eOk)
|
||
{
|
||
delete pHolder;
|
||
continue;
|
||
}
|
||
touchEntity(pHolder);
|
||
pHolder->close();
|
||
arHandles.push_back(HandleOfId(idNew));
|
||
}
|
||
|
||
nlohmann::json body;
|
||
body["ok"] = !arHandles.empty();
|
||
body["type"] = "holder";
|
||
body["count"] = (int)arHandles.size();
|
||
body["handles"] = arHandles;
|
||
if (!arHandles.empty()) body["handle"] = arHandles[0];
|
||
body["params"] = HolderToJson(data);
|
||
return okJson(body);
|
||
}
|
||
};
|
||
EXPORT_MCP_TOOL(ToolAddHolder, AddAecHolderTool)
|
||
|
||
class ToolUpdateHolder : public mcp_Tool
|
||
{
|
||
public:
|
||
std::string private_name() const override { return "update_aec_holder"; }
|
||
|
||
std::string private_description() const override
|
||
{
|
||
return "改单个支架(AecDbHolder):个数/支柱长/臂长/角钢宽厚/底标高/材质编号用途,只传要改的字段。"
|
||
"位置与支臂方向不能改(要挪就删了用 add_aec_holder 重摆)。";
|
||
}
|
||
|
||
nlohmann::json private_input_schema() const override
|
||
{
|
||
return nlohmann::json::parse(R"({
|
||
"type": "object",
|
||
"properties": {
|
||
"handle": { "type": "string", "description": "支架实体 handle" },
|
||
"count": { "type": "integer" }, "post_length": { "type": "number" },
|
||
"arm_length": { "type": "number" }, "steel_width": { "type": "number" },
|
||
"steel_thickness": { "type": "number" }, "bottom_elevation": { "type": "number" },
|
||
"material": { "type": "string" }, "no": { "type": "string" },
|
||
"purpose": { "type": "string" }, "color": { "type": "integer" }
|
||
},
|
||
"required": [ "handle" ]
|
||
})");
|
||
}
|
||
|
||
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, "handle")) return errJson(kErrBadParam, L"缺少 handle");
|
||
const std::string sHandle = args["handle"].get<std::string>();
|
||
AcDbEntity* pEnt = openByHandle(sHandle, AcDb::kForWrite);
|
||
if (pEnt == NULL) return errJson(kErrNotFound, L"按 handle 打不开实体:" + utf8ToWstr(sHandle));
|
||
|
||
AecDbHolder* pHolder = AecDbHolder::cast(pEnt);
|
||
if (pHolder == NULL)
|
||
{
|
||
const std::string sCls = classNameOf(pEnt);
|
||
pEnt->close();
|
||
return errJson(kErrWrongType, L"实体 " + utf8ToWstr(sCls) + L" 不是支架(AecDbHolder)");
|
||
}
|
||
|
||
XHolder data;
|
||
::memset(&data, 0, sizeof(XHolder));
|
||
pHolder->GetHolder(data);
|
||
HolderFromArgs(data, args, true);
|
||
pHolder->SetHolder(data);
|
||
if (hasKey(args, "color")) pHolder->setColorIndex((Adesk::UInt16)intOr(args, "color", 256));
|
||
touchEntity(pHolder);
|
||
|
||
nlohmann::json body;
|
||
body["ok"] = true;
|
||
body["type"] = "holder";
|
||
body["handle"] = sHandle;
|
||
body["params"] = HolderToJson(data);
|
||
pEnt->close();
|
||
return okJson(body);
|
||
}
|
||
};
|
||
EXPORT_MCP_TOOL(ToolUpdateHolder, UpdateAecHolderTool)
|
||
|
||
// ===========================================================================
|
||
// 吊架(PL_FZDJ,AecDbHanger)
|
||
// ===========================================================================
|
||
namespace
|
||
{
|
||
void InitXHanger(XHanger& d)
|
||
{
|
||
::memset(&d, 0, sizeof(XHanger));
|
||
d.nHs = 2; // 吊点排数
|
||
d.N = 3; // 个数
|
||
d.V = 600.0; // 中间吊高
|
||
d.L = 1000.0; // 吊架臂长
|
||
d.W = 60.0; // 角钢宽
|
||
d.t = 3.0; // 角钢厚
|
||
d.dD = 8.0; // 吊杆直径
|
||
d.bdDAsW = FALSE;
|
||
CopyStr(d.szMat, 33, L"普通碳钢");
|
||
}
|
||
|
||
void HangerFromArgs(XHanger& d, const nlohmann::json& a, bool bMerge)
|
||
{
|
||
if (!bMerge) InitXHanger(d);
|
||
if (hasKey(a, "row_count")) d.nHs = intOr(a, "row_count", d.nHs);
|
||
if (hasKey(a, "count")) d.N = intOr(a, "count", d.N);
|
||
if (hasKey(a, "rod_diameter")) d.dD = numOr(a, "rod_diameter", d.dD);
|
||
if (hasKey(a, "rod_as_angle")) d.bdDAsW = intOr(a, "rod_as_angle", 0) ? TRUE : FALSE;
|
||
if (hasKey(a, "post_length")) d.V = numOr(a, "post_length", d.V);
|
||
if (hasKey(a, "arm_length")) d.L = numOr(a, "arm_length", d.L);
|
||
if (hasKey(a, "steel_width")) d.W = numOr(a, "steel_width", d.W);
|
||
if (hasKey(a, "steel_thickness")) d.t = numOr(a, "steel_thickness", d.t);
|
||
if (hasKey(a, "material")) CopyStr(d.szMat, 33, wstrOr(a, "material", L""));
|
||
if (hasKey(a, "purpose")) CopyStr(d.szUsage, 33, wstrOr(a, "purpose", L""));
|
||
}
|
||
|
||
nlohmann::json HangerToJson(const XHanger& d)
|
||
{
|
||
nlohmann::json o;
|
||
o["row_count"] = d.nHs;
|
||
o["count"] = d.N;
|
||
o["rod_diameter"] = d.dD;
|
||
o["rod_as_angle"] = (d.bdDAsW != FALSE);
|
||
o["post_length"] = d.V;
|
||
o["arm_length"] = d.L;
|
||
o["steel_width"] = d.W;
|
||
o["steel_thickness"] = d.t;
|
||
o["material"] = acharToUtf8(d.szMat);
|
||
o["purpose"] = acharToUtf8(d.szUsage);
|
||
return o;
|
||
}
|
||
}
|
||
|
||
class ToolAddHanger : public mcp_Tool
|
||
{
|
||
public:
|
||
std::string private_name() const override { return "add_aec_hanger"; }
|
||
|
||
std::string private_description() const override
|
||
{
|
||
return "沿路径摆一串管道吊架(菜单 PL_FZDJ 放置吊架,实体 AecDbHanger):给路径 points + 间距 + 顶标高,"
|
||
"再给吊点排数/吊杆直径/臂长/角钢宽厚/材质(缺省照抄 CFZDJDlg)。图层 LAY_SUPPORT。";
|
||
}
|
||
|
||
nlohmann::json private_input_schema() const override
|
||
{
|
||
return nlohmann::json::parse(R"({
|
||
"type": "object",
|
||
"properties": {
|
||
"points": { "type": "array", "items": { "type": "array", "items": { "type": "number" } } },
|
||
"spacing": { "type": "number", "description": "间距,缺省 1000" },
|
||
"top_elevation": { "type": "number", "description": "顶标高,缺省 0" },
|
||
"direction_point": { "type": "array", "items": { "type": "number" } },
|
||
"row_count": { "type": "integer", "description": "吊点排数,缺省 2" },
|
||
"count": { "type": "integer", "description": "个数,缺省 3" },
|
||
"rod_diameter": { "type": "number", "description": "吊杆直径,缺省 8" },
|
||
"rod_as_angle": { "type": "boolean", "description": "吊杆是否用角钢" },
|
||
"post_length": { "type": "number", "description": "中间吊高,缺省 600" },
|
||
"arm_length": { "type": "number", "description": "吊架臂长,缺省 1000" },
|
||
"steel_width": { "type": "number", "description": "角钢宽,缺省 60" },
|
||
"steel_thickness": { "type": "number", "description": "角钢厚,缺省 3" },
|
||
"material": { "type": "string", "description": "材质,缺省 普通碳钢" },
|
||
"purpose": { "type": "string", "description": "用途" },
|
||
"layer": { "type": "string", "description": "图层,缺省 LAY_SUPPORT" },
|
||
"color": { "type": "integer" }
|
||
},
|
||
"required": [ "points", "spacing" ]
|
||
})");
|
||
}
|
||
|
||
nlohmann::json Execute(const nlohmann::json& args) override
|
||
{
|
||
if (workingDb() == NULL) return errJson(kErrNoDocument, L"没有活动图纸");
|
||
DocLock lock;
|
||
if (!lock.isLocked()) return errJson(kErrInternal, L"拿不到图纸写锁(有别的命令在跑?)");
|
||
|
||
std::wstring err;
|
||
AcDbPolyline* pPath = PathOfPoints(args, err);
|
||
if (pPath == NULL) return errJson(kErrBadParam, err);
|
||
|
||
AcGePoint3d ptFirst(0.0, 0.0, 0.0);
|
||
pPath->getStartPoint(ptFirst);
|
||
AcGeVector3d vtPick(0.0, 0.0, 0.0);
|
||
PickDirFromArgs(args, ptFirst, vtPick);
|
||
|
||
XHanger data;
|
||
HangerFromArgs(data, args, false);
|
||
const double dEl = numOr(args, "top_elevation", 0.0);
|
||
|
||
AcGePoint3dArray arPts;
|
||
AcArray<AcGeVector3d> arDirs;
|
||
const bool bOk = LayoutAlongPath(pPath, numOr(args, "spacing", 1000.0), dEl, vtPick, arPts, arDirs, err);
|
||
delete pPath;
|
||
if (!bOk) return errJson(kErrBadParam, err);
|
||
|
||
std::wstring sLay = hasKey(args, "layer") ? wstrOr(args, "layer", L"") : L"";
|
||
if (sLay.empty()) sLay = L"LAY_SUPPORT";
|
||
AcDbObjectId idLay = KTSetting::InitLayer(sLay.c_str());
|
||
|
||
nlohmann::json arHandles = nlohmann::json::array();
|
||
for (int i = 0; i < arPts.length(); ++i)
|
||
{
|
||
AecDbHanger* pHanger = new AecDbHanger();
|
||
pHanger->SetHanger(data);
|
||
pHanger->SetPosition(arPts[i], arDirs[i]);
|
||
if (!idLay.isNull()) pHanger->setLayer(idLay);
|
||
if (hasKey(args, "color")) pHanger->setColorIndex((Adesk::UInt16)intOr(args, "color", 256));
|
||
|
||
AcDbObjectId idNew;
|
||
if (addToSpace(pHanger, &idNew) != Acad::eOk)
|
||
{
|
||
delete pHanger;
|
||
continue;
|
||
}
|
||
touchEntity(pHanger);
|
||
pHanger->close();
|
||
arHandles.push_back(HandleOfId(idNew));
|
||
}
|
||
|
||
nlohmann::json body;
|
||
body["ok"] = !arHandles.empty();
|
||
body["type"] = "hanger";
|
||
body["count"] = (int)arHandles.size();
|
||
body["handles"] = arHandles;
|
||
if (!arHandles.empty()) body["handle"] = arHandles[0];
|
||
body["params"] = HangerToJson(data);
|
||
return okJson(body);
|
||
}
|
||
};
|
||
EXPORT_MCP_TOOL(ToolAddHanger, AddAecHangerTool)
|
||
|
||
class ToolUpdateHanger : public mcp_Tool
|
||
{
|
||
public:
|
||
std::string private_name() const override { return "update_aec_hanger"; }
|
||
|
||
std::string private_description() const override
|
||
{
|
||
return "改单个吊架(AecDbHanger):吊点排数/吊杆直径/臂长/角钢宽厚/材质用途,只传要改的字段。";
|
||
}
|
||
|
||
nlohmann::json private_input_schema() const override
|
||
{
|
||
return nlohmann::json::parse(R"({
|
||
"type": "object",
|
||
"properties": {
|
||
"handle": { "type": "string", "description": "吊架实体 handle" },
|
||
"row_count": { "type": "integer" }, "count": { "type": "integer" },
|
||
"rod_diameter": { "type": "number" }, "rod_as_angle": { "type": "boolean" },
|
||
"post_length": { "type": "number" }, "arm_length": { "type": "number" },
|
||
"steel_width": { "type": "number" }, "steel_thickness": { "type": "number" },
|
||
"material": { "type": "string" }, "purpose": { "type": "string" },
|
||
"color": { "type": "integer" }
|
||
},
|
||
"required": [ "handle" ]
|
||
})");
|
||
}
|
||
|
||
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, "handle")) return errJson(kErrBadParam, L"缺少 handle");
|
||
const std::string sHandle = args["handle"].get<std::string>();
|
||
AcDbEntity* pEnt = openByHandle(sHandle, AcDb::kForWrite);
|
||
if (pEnt == NULL) return errJson(kErrNotFound, L"按 handle 打不开实体:" + utf8ToWstr(sHandle));
|
||
|
||
AecDbHanger* pHanger = AecDbHanger::cast(pEnt);
|
||
if (pHanger == NULL)
|
||
{
|
||
const std::string sCls = classNameOf(pEnt);
|
||
pEnt->close();
|
||
return errJson(kErrWrongType, L"实体 " + utf8ToWstr(sCls) + L" 不是吊架(AecDbHanger)");
|
||
}
|
||
|
||
XHanger data;
|
||
::memset(&data, 0, sizeof(XHanger));
|
||
pHanger->GetHanger(data);
|
||
HangerFromArgs(data, args, true);
|
||
pHanger->SetHanger(data);
|
||
if (hasKey(args, "color")) pHanger->setColorIndex((Adesk::UInt16)intOr(args, "color", 256));
|
||
touchEntity(pHanger);
|
||
|
||
nlohmann::json body;
|
||
body["ok"] = true;
|
||
body["type"] = "hanger";
|
||
body["handle"] = sHandle;
|
||
body["params"] = HangerToJson(data);
|
||
pEnt->close();
|
||
return okJson(body);
|
||
}
|
||
};
|
||
EXPORT_MCP_TOOL(ToolUpdateHanger, UpdateAecHangerTool)
|
||
|
||
// ===========================================================================
|
||
// 支墩(PL_FZZD,AecDbBossHolder)
|
||
// ===========================================================================
|
||
namespace
|
||
{
|
||
void InitBossHolder(XBossHolder& d)
|
||
{
|
||
::memset(&d, 0, sizeof(XBossHolder));
|
||
d.nType = 0; // 0 混凝土 / 1 角钢 / 2 槽钢
|
||
d.W = 500.0;
|
||
d.t = 600.0;
|
||
d.L = 500.0;
|
||
d.C = 18.0;
|
||
d.B = 100.0;
|
||
d.N = 1;
|
||
d.V = 1.0;
|
||
d.H = 600.0;
|
||
CopyStr(d.szMat, MAX_PATH, L"混凝土");
|
||
CopyStr(d.szNo, MAX_PATH, L"D-001");
|
||
}
|
||
|
||
void BossHolderFromArgs(XBossHolder& d, const nlohmann::json& a, bool bMerge)
|
||
{
|
||
if (!bMerge) InitBossHolder(d);
|
||
if (hasKey(a, "holder_type")) d.nType = intOr(a, "holder_type", d.nType);
|
||
if (hasKey(a, "width")) d.W = numOr(a, "width", d.W);
|
||
if (hasKey(a, "thickness")) d.t = numOr(a, "thickness", d.t);
|
||
if (hasKey(a, "length")) d.L = numOr(a, "length", d.L);
|
||
if (hasKey(a, "channel_c")) d.C = numOr(a, "channel_c", d.C);
|
||
if (hasKey(a, "channel_b")) d.B = numOr(a, "channel_b", d.B);
|
||
if (hasKey(a, "layer_count")) d.N = intOr(a, "layer_count", d.N);
|
||
if (hasKey(a, "step_height")) d.V = numOr(a, "step_height", d.V);
|
||
if (hasKey(a, "support_height")) d.H = numOr(a, "support_height", d.H);
|
||
if (hasKey(a, "material")) CopyStr(d.szMat, MAX_PATH, wstrOr(a, "material", L""));
|
||
if (hasKey(a, "no")) CopyStr(d.szNo, MAX_PATH, wstrOr(a, "no", L""));
|
||
}
|
||
|
||
nlohmann::json BossHolderToJson(const XBossHolder& d)
|
||
{
|
||
nlohmann::json o;
|
||
o["holder_type"] = d.nType;
|
||
o["width"] = d.W;
|
||
o["thickness"] = d.t;
|
||
o["length"] = d.L;
|
||
o["channel_c"] = d.C;
|
||
o["channel_b"] = d.B;
|
||
o["layer_count"] = d.N;
|
||
o["step_height"] = d.V;
|
||
o["support_height"] = d.H;
|
||
o["material"] = acharToUtf8(d.szMat);
|
||
o["no"] = acharToUtf8(d.szNo);
|
||
return o;
|
||
}
|
||
}
|
||
|
||
class ToolAddBossHolder : public mcp_Tool
|
||
{
|
||
public:
|
||
std::string private_name() const override { return "add_aec_boss_holder"; }
|
||
|
||
std::string private_description() const override
|
||
{
|
||
return "沿路径摆一串管道支墩(菜单 PL_FZZD 放置支墩,实体 AecDbBossHolder):给路径 points + 间距 + 底标高,"
|
||
"再给支墩类型(0 混凝土 / 1 角钢 / 2 槽钢)、宽厚长、层数/步高/支撑高度、材质编号"
|
||
"(缺省照抄 CFZZDDlg)。图层 LAY_SUPPORT。";
|
||
}
|
||
|
||
nlohmann::json private_input_schema() const override
|
||
{
|
||
return nlohmann::json::parse(R"({
|
||
"type": "object",
|
||
"properties": {
|
||
"points": { "type": "array", "items": { "type": "array", "items": { "type": "number" } } },
|
||
"spacing": { "type": "number", "description": "间距,缺省 1000" },
|
||
"bottom_elevation": { "type": "number", "description": "底标高,缺省 0" },
|
||
"direction_point": { "type": "array", "items": { "type": "number" } },
|
||
"holder_type": { "type": "integer", "description": "0 混凝土 / 1 角钢 / 2 槽钢" },
|
||
"width": { "type": "number", "description": "宽,缺省 500" },
|
||
"thickness": { "type": "number", "description": "厚,缺省 600" },
|
||
"length": { "type": "number", "description": "长,缺省 500" },
|
||
"channel_c": { "type": "number", "description": "槽钢 c,缺省 18" },
|
||
"channel_b": { "type": "number", "description": "槽钢 b,缺省 100" },
|
||
"layer_count": { "type": "integer", "description": "层数,缺省 1" },
|
||
"step_height": { "type": "number", "description": "步高,缺省 1" },
|
||
"support_height": { "type": "number", "description": "支撑高度,缺省 600" },
|
||
"material": { "type": "string", "description": "材质,缺省 混凝土" },
|
||
"no": { "type": "string", "description": "编号,缺省 D-001" },
|
||
"layer": { "type": "string", "description": "图层,缺省 LAY_SUPPORT" },
|
||
"color": { "type": "integer" }
|
||
},
|
||
"required": [ "points", "spacing" ]
|
||
})");
|
||
}
|
||
|
||
nlohmann::json Execute(const nlohmann::json& args) override
|
||
{
|
||
if (workingDb() == NULL) return errJson(kErrNoDocument, L"没有活动图纸");
|
||
DocLock lock;
|
||
if (!lock.isLocked()) return errJson(kErrInternal, L"拿不到图纸写锁(有别的命令在跑?)");
|
||
|
||
std::wstring err;
|
||
AcDbPolyline* pPath = PathOfPoints(args, err);
|
||
if (pPath == NULL) return errJson(kErrBadParam, err);
|
||
|
||
AcGePoint3d ptFirst(0.0, 0.0, 0.0);
|
||
pPath->getStartPoint(ptFirst);
|
||
AcGeVector3d vtPick(0.0, 0.0, 0.0);
|
||
PickDirFromArgs(args, ptFirst, vtPick);
|
||
|
||
XBossHolder data;
|
||
BossHolderFromArgs(data, args, false);
|
||
const double dEl = numOr(args, "bottom_elevation", 0.0);
|
||
|
||
AcGePoint3dArray arPts;
|
||
AcArray<AcGeVector3d> arDirs;
|
||
const bool bOk = LayoutAlongPath(pPath, numOr(args, "spacing", 1000.0), dEl, vtPick, arPts, arDirs, err);
|
||
delete pPath;
|
||
if (!bOk) return errJson(kErrBadParam, err);
|
||
|
||
std::wstring sLay = hasKey(args, "layer") ? wstrOr(args, "layer", L"") : L"";
|
||
if (sLay.empty()) sLay = L"LAY_SUPPORT";
|
||
AcDbObjectId idLay = KTSetting::InitLayer(sLay.c_str());
|
||
|
||
nlohmann::json arHandles = nlohmann::json::array();
|
||
for (int i = 0; i < arPts.length(); ++i)
|
||
{
|
||
AecDbBossHolder* pBoss = new AecDbBossHolder();
|
||
pBoss->SetHolder(data);
|
||
pBoss->SetPosition(arPts[i], arDirs[i]);
|
||
if (!idLay.isNull()) pBoss->setLayer(idLay);
|
||
if (hasKey(args, "color")) pBoss->setColorIndex((Adesk::UInt16)intOr(args, "color", 256));
|
||
|
||
AcDbObjectId idNew;
|
||
if (addToSpace(pBoss, &idNew) != Acad::eOk)
|
||
{
|
||
delete pBoss;
|
||
continue;
|
||
}
|
||
touchEntity(pBoss);
|
||
pBoss->close();
|
||
arHandles.push_back(HandleOfId(idNew));
|
||
}
|
||
|
||
nlohmann::json body;
|
||
body["ok"] = !arHandles.empty();
|
||
body["type"] = "boss_holder";
|
||
body["count"] = (int)arHandles.size();
|
||
body["handles"] = arHandles;
|
||
if (!arHandles.empty()) body["handle"] = arHandles[0];
|
||
body["params"] = BossHolderToJson(data);
|
||
return okJson(body);
|
||
}
|
||
};
|
||
EXPORT_MCP_TOOL(ToolAddBossHolder, AddAecBossHolderTool)
|
||
|
||
class ToolUpdateBossHolder : public mcp_Tool
|
||
{
|
||
public:
|
||
std::string private_name() const override { return "update_aec_boss_holder"; }
|
||
|
||
std::string private_description() const override
|
||
{
|
||
return "改单个支墩(AecDbBossHolder):类型/宽厚长/槽钢参数/层数步高/支撑高度/材质编号,只传要改的字段。";
|
||
}
|
||
|
||
nlohmann::json private_input_schema() const override
|
||
{
|
||
return nlohmann::json::parse(R"({
|
||
"type": "object",
|
||
"properties": {
|
||
"handle": { "type": "string", "description": "支墩实体 handle" },
|
||
"holder_type": { "type": "integer" }, "width": { "type": "number" },
|
||
"thickness": { "type": "number" }, "length": { "type": "number" },
|
||
"channel_c": { "type": "number" }, "channel_b": { "type": "number" },
|
||
"layer_count": { "type": "integer" }, "step_height": { "type": "number" },
|
||
"support_height": { "type": "number" },
|
||
"material": { "type": "string" }, "no": { "type": "string" },
|
||
"color": { "type": "integer" }
|
||
},
|
||
"required": [ "handle" ]
|
||
})");
|
||
}
|
||
|
||
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, "handle")) return errJson(kErrBadParam, L"缺少 handle");
|
||
const std::string sHandle = args["handle"].get<std::string>();
|
||
AcDbEntity* pEnt = openByHandle(sHandle, AcDb::kForWrite);
|
||
if (pEnt == NULL) return errJson(kErrNotFound, L"按 handle 打不开实体:" + utf8ToWstr(sHandle));
|
||
|
||
AecDbBossHolder* pBoss = AecDbBossHolder::cast(pEnt);
|
||
if (pBoss == NULL)
|
||
{
|
||
const std::string sCls = classNameOf(pEnt);
|
||
pEnt->close();
|
||
return errJson(kErrWrongType, L"实体 " + utf8ToWstr(sCls) + L" 不是支墩(AecDbBossHolder)");
|
||
}
|
||
|
||
XBossHolder data;
|
||
::memset(&data, 0, sizeof(XBossHolder));
|
||
pBoss->GetHolder(data);
|
||
BossHolderFromArgs(data, args, true);
|
||
pBoss->SetHolder(data);
|
||
if (hasKey(args, "color")) pBoss->setColorIndex((Adesk::UInt16)intOr(args, "color", 256));
|
||
touchEntity(pBoss);
|
||
|
||
nlohmann::json body;
|
||
body["ok"] = true;
|
||
body["type"] = "boss_holder";
|
||
body["handle"] = sHandle;
|
||
body["params"] = BossHolderToJson(data);
|
||
pEnt->close();
|
||
return okJson(body);
|
||
}
|
||
};
|
||
EXPORT_MCP_TOOL(ToolUpdateBossHolder, UpdateAecBossHolderTool)
|