diff --git a/SourceCode/Code2026/CoreLibrary/AecDbGuardBar.cpp b/SourceCode/Code2026/CoreLibrary/AecDbGuardBar.cpp index 283c64f..fc91146 100644 --- a/SourceCode/Code2026/CoreLibrary/AecDbGuardBar.cpp +++ b/SourceCode/Code2026/CoreLibrary/AecDbGuardBar.cpp @@ -76,7 +76,8 @@ void AecDbGuardBar::SetGuardBarData(const GuardBar& bar) m_mapSpecXData.SetAt(KEY_VERDRAW,bar.bVerDraw); m_mapSpecXData.SetAt(KEY_MATERIAL,bar.m_sMaterial); - m_mapSpecXData.SetAt(KEY_MATERIAL,bar.m_sNo); + m_mapSpecXData.SetAt(KEY_FACTORY,bar.m_sFactory); + m_mapSpecXData.SetAt(KEY_NO,bar.m_sNo); // 原来这里错写成 KEY_MATERIAL,编号把材质盖掉了 } bool AecDbGuardBar::GetGuardBarData(GuardBar& bar) const @@ -98,7 +99,12 @@ bool AecDbGuardBar::GetGuardBarData(GuardBar& bar) const m_mapSpecXData.GetAt(KEY_MATERIAL,sTemp); _tcscpy(bar.m_sMaterial,(LPCTSTR)sTemp); - m_mapSpecXData.GetAt(KEY_MATERIAL,sTemp); + m_mapSpecXData.GetAt(KEY_FACTORY,sTemp); + _tcscpy(bar.m_sFactory,(LPCTSTR)sTemp); + + // 老数据把编号存在 KEY_MATERIAL 里(上面的 Set 写错了),读不到 KEY_NO 时退回老位置 + if (!m_mapSpecXData.GetAt(KEY_NO,sTemp)) + m_mapSpecXData.GetAt(KEY_MATERIAL,sTemp); _tcscpy(bar.m_sNo,(LPCTSTR)sTemp); return true; diff --git a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_stair_tools.cpp b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_stair_tools.cpp new file mode 100644 index 0000000..277f27a --- /dev/null +++ b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_stair_tools.cpp @@ -0,0 +1,600 @@ +// ============================================================================ +// aec_mcp_stair_tools.cpp +// cad_mcp_aec 的楼梯 / 护栏工具(工作计划第 6 项) +// * PL_PTLT 直线钢梯 -> AecDbLineStair(AecDbBaseStair 派生) +// * PL_FZHN 放置护栏 / PL_QXHN 曲线护栏 -> AecDbGuardBar(AecDbEwPipeBase 派生) +// +// 两个命令的建模序列(Pool3dCmd/pool3dcmdCmd.cpp): +// 建实体 -> setLayer(LAY_CSTAIR / LAY_GBAR) -> SetLineStairData / SetGuardBarData +// -> SetSection(...) -> SetBaseCurve(&line / &polyline) -> KEY_2DSTYLE=0 -> 入库 +// 参数全部来自各自的对话框(CPTLTDlg / CFZHNDlg),缺省值照抄对话框构造函数, +// 尺寸用图纸单位。 +// ============================================================================ + +#include "StdAfx.h" +#include "KTCad.h" +#include "aec_mcp_common.h" +#include "mcp_plugin_api.h" + +#include "AecDbLineStair.h" +#include "AecDbGuardBar.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; + } + + nlohmann::json PointJson(const AcGePoint3d& pt) + { + nlohmann::json o; + o["x"] = pt.x; + o["y"] = pt.y; + o["z"] = pt.z; + return o; + } + + 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; + } + + // ---------------------------------------------------------------- 护栏 + // GuardBar 的缺省值照抄 CFZHNDlg 构造函数 + void InitGuardBar(GuardBar& bar) + { + ::memset(&bar, 0, sizeof(GuardBar)); + bar.dD = 40.0; // 管材直径 + bar.dt = 2.5; // 管材厚(命令里写死 2.5) + bar.dBomEl = 0.0; // 底标高 + bar.dH1 = 650.0; // 底层横杆高 + bar.dH = 1080.0; // 顶部扶手高 + bar.dP = 1200.0; // 立柱间距 + bar.bNoBomLever = FALSE; + bar.bIsRectLever = FALSE; + bar.bVerDraw = FALSE; + CopyStr(bar.m_sMaterial, 256, L"镜亮不锈钢型材"); + CopyStr(bar.m_sFactory, 256, L"厂家自制"); + CopyStr(bar.m_sNo, 256, L"HL-01"); + } + + void GuardBarFromArgs(GuardBar& bar, const nlohmann::json& a, bool bMerge) + { + if (!bMerge) InitGuardBar(bar); + if (hasKey(a, "diameter")) bar.dD = numOr(a, "diameter", bar.dD); + if (hasKey(a, "bar_thickness")) bar.dt = numOr(a, "bar_thickness", bar.dt); + if (hasKey(a, "bottom_elevation")) bar.dBomEl = numOr(a, "bottom_elevation", bar.dBomEl); + if (hasKey(a, "top_height")) bar.dH = numOr(a, "top_height", bar.dH); + if (hasKey(a, "first_height")) bar.dH1 = numOr(a, "first_height", bar.dH1); + if (hasKey(a, "post_space")) bar.dP = numOr(a, "post_space", bar.dP); + if (hasKey(a, "rect_post")) bar.bIsRectLever = intOr(a, "rect_post", 0) ? TRUE : FALSE; + if (hasKey(a, "no_bottom_rail")) bar.bNoBomLever = intOr(a, "no_bottom_rail", 0) ? TRUE : FALSE; + if (hasKey(a, "vertical_draw")) bar.bVerDraw = intOr(a, "vertical_draw", 0) ? TRUE : FALSE; + if (hasKey(a, "material")) CopyStr(bar.m_sMaterial, 256, wstrOr(a, "material", L"")); + if (hasKey(a, "factory")) CopyStr(bar.m_sFactory, 256, wstrOr(a, "factory", L"")); + if (hasKey(a, "no")) CopyStr(bar.m_sNo, 256, wstrOr(a, "no", L"")); + } + + nlohmann::json GuardBarToJson(const GuardBar& bar) + { + nlohmann::json o; + o["diameter"] = bar.dD; + o["bar_thickness"] = bar.dt; + o["bottom_elevation"] = bar.dBomEl; + o["top_height"] = bar.dH; + o["first_height"] = bar.dH1; + o["post_space"] = bar.dP; + o["rect_post"] = (bar.bIsRectLever != FALSE); + o["no_bottom_rail"] = (bar.bNoBomLever != FALSE); + o["vertical_draw"] = (bar.bVerDraw != FALSE); + o["material"] = acharToUtf8(bar.m_sMaterial); + o["factory"] = acharToUtf8(bar.m_sFactory); + o["no"] = acharToUtf8(bar.m_sNo); + return o; + } + + // 二维点串 -> 多段线(护栏的基准曲线,elevation 固定 0,与命令一致) + AcDbPolyline* PolylineOfPoints(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(), pt[1].get()), 0.0, 0.0, 0.0); + } + if (nIdx < 2) + { + delete pPl; + err = L"points 有效点少于 2 个"; + return NULL; + } + pPl->setElevation(0.0); // 命令里是"视图 elevation=0 时绘制",这里固定 0 + return pPl; + } + + // 已有曲线(圆弧/圆/多段线/样条)-> 多段线,供 PL_QXHN 那种"沿已有曲线"的用法 + AcDbPolyline* PolylineOfHandle(const std::wstring& sHandle, std::wstring& err) + { + AcDbEntity* pEnt = openByHandle(acharToUtf8(sHandle.c_str()), AcDb::kForRead); + if (pEnt == NULL) + { + err = L"按 handle 打不开曲线:" + sHandle; + return NULL; + } + AcDbCurve* pCrv = AcDbCurve::cast(pEnt); + if (pCrv == NULL) + { + pEnt->close(); + err = L"curve 必须是曲线类实体(直线/圆弧/圆/多段线/样条)"; + return NULL; + } + AcDbPolyline* pPl = AcDbPolyline::cast(pEnt) ? (AcDbPolyline*)pCrv->clone() + : CoreTools::MakePolyline(pCrv); + pEnt->close(); + if (pPl == NULL) + { + err = L"曲线转多段线失败"; + return NULL; + } + pPl->setElevation(0.0); + return pPl; + } + + // ---------------------------------------------------------------- 直线钢梯 + // LineStair 的缺省值照抄 CPTLTDlg 构造函数 + void InitLineStair(LineStair& data) + { + ::memset(&data, 0, sizeof(LineStair)); + InitGuardBar(data.bar); + data.bar.dD = 30.0; // 钢梯的栏管直径缺省 30 + data.bar.dH = 1080.0; + data.bar.dH1 = 650.0; + data.bar.dP = 1200.0; + data.bar.dt = 2.0; + + data.dSteepH = 200.0; // 踏步高 + data.dSteept = 8.0; // 踏步厚 + data.dSteepW = 400.0; // 踏步宽 + data.dSideW = 200.0; // 梯梁宽 + data.dSidet = 40.0; // 梯梁厚 + data.dW = 1000.0; // 梯宽 + data.dBomEl = 0.0; + data.dTopEl = 4000.0; + CopyStr(data.m_sMaterial, 256, L"不锈钢"); + CopyStr(data.m_sFactory, 256, L"厂家自制"); + } + + void LineStairFromArgs(LineStair& data, const nlohmann::json& a, bool bMerge) + { + if (!bMerge) InitLineStair(data); + GuardBarFromArgs(data.bar, a, true); + + if (hasKey(a, "width")) data.dW = numOr(a, "width", data.dW); + if (hasKey(a, "steep_height")) data.dSteepH = numOr(a, "steep_height", data.dSteepH); + if (hasKey(a, "steep_width")) data.dSteepW = numOr(a, "steep_width", data.dSteepW); + if (hasKey(a, "steep_thickness")) data.dSteept = numOr(a, "steep_thickness", data.dSteept); + if (hasKey(a, "side_width")) data.dSideW = numOr(a, "side_width", data.dSideW); + if (hasKey(a, "side_thickness")) data.dSidet = numOr(a, "side_thickness", data.dSidet); + if (hasKey(a, "bottom_elevation")) data.dBomEl = numOr(a, "bottom_elevation", data.dBomEl); + if (hasKey(a, "top_elevation")) data.dTopEl = numOr(a, "top_elevation", data.dTopEl); + if (hasKey(a, "with_rail")) data.bGuardBar = intOr(a, "with_rail", 0) ? TRUE : FALSE; + if (hasKey(a, "material")) CopyStr(data.m_sMaterial, 256, wstrOr(a, "material", L"")); + if (hasKey(a, "factory")) CopyStr(data.m_sFactory, 256, wstrOr(a, "factory", L"")); + if (hasKey(a, "no")) CopyStr(data.m_sNo, 256, wstrOr(a, "no", L"")); + } +} + +// --------------------------------------------------------------------------- +// add_aec_line_stair —— 直线钢梯(PL_PTLT) +// --------------------------------------------------------------------------- +class ToolAddLineStair : public mcp_Tool +{ +public: + std::string private_name() const override { return "add_aec_line_stair"; } + + std::string private_description() const override + { + return "建直线钢梯(菜单 PL_PTLT 直线钢梯,实体 AecDbLineStair):" + "给起点/终点平面位置 + 底/顶标高,再给梯宽、踏步、梯梁、栏管参数(都有缺省,照抄 CPTLTDlg)。" + "尺寸用图纸单位;起点 z 取 bottom_elevation、终点 z 取 top_elevation。图层 LAY_CSTAIR。"; + } + + nlohmann::json private_input_schema() const override + { + return nlohmann::json::parse(R"({ + "type": "object", + "properties": { + "start": { "type": "array", "items": { "type": "number" }, "description": "起点 [x,y](z 用 bottom_elevation)" }, + "end": { "type": "array", "items": { "type": "number" }, "description": "终点 [x,y](z 用 top_elevation)" }, + "bottom_elevation": { "type": "number", "description": "底标高,缺省 0" }, + "top_elevation": { "type": "number", "description": "顶标高,缺省 4000" }, + "width": { "type": "number", "description": "梯宽,缺省 1000" }, + "steep_height": { "type": "number", "description": "踏步高,缺省 200" }, + "steep_width": { "type": "number", "description": "踏步宽,缺省 400" }, + "steep_thickness": { "type": "number", "description": "踏步厚,缺省 8" }, + "side_width": { "type": "number", "description": "梯梁宽,缺省 200" }, + "side_thickness": { "type": "number", "description": "梯梁厚,缺省 40" }, + "diameter": { "type": "number", "description": "栏管直径(也是钢梯截面),缺省 30" }, + "top_height": { "type": "number", "description": "扶手高,缺省 1080" }, + "first_height": { "type": "number", "description": "底层横杆高,缺省 650" }, + "post_space": { "type": "number", "description": "立柱间距,缺省 1200" }, + "with_rail": { "type": "boolean", "description": "是否带护栏" }, + "material": { "type": "string", "description": "材质,缺省 不锈钢" }, + "factory": { "type": "string", "description": "厂家,缺省 厂家自制" }, + "no": { "type": "string", "description": "编号" }, + "layer": { "type": "string", "description": "图层,缺省 LAY_CSTAIR" }, + "color": { "type": "integer", "description": "ACI 颜色号,256=ByLayer" } + }, + "required": [ "start", "end" ] + })"); + } + + nlohmann::json Execute(const nlohmann::json& args) override + { + if (workingDb() == NULL) return errJson(kErrNoDocument, L"没有活动图纸"); + DocLock lock; + if (!lock.isLocked()) return errJson(kErrInternal, L"拿不到图纸写锁(有别的命令在跑?)"); + + AcGePoint3d ptS(0.0, 0.0, 0.0), ptE(0.0, 0.0, 0.0); + if (!readPoint(args, "start", ptS) || !readPoint(args, "end", ptE)) + return errJson(kErrBadParam, L"需要 start / end([x,y] 或 [x,y,z])"); + if (ptS.distanceTo(ptE) < 1.0) + return errJson(kErrBadParam, L"start 与 end 距离太近(命令里 <1 也拒绝)"); + + LineStair data; + LineStairFromArgs(data, args, false); + ptS.z = data.dBomEl; + ptE.z = data.dTopEl; + + AcDbLine ln(ptS, ptE); + AecDbLineStair* pStair = new AecDbLineStair(); + std::wstring sLay = hasKey(args, "layer") ? wstrOr(args, "layer", L"") : L""; + if (sLay.empty()) sLay = L"LAY_CSTAIR"; + AcDbObjectId idLay = KTSetting::InitLayer(sLay.c_str()); + if (!idLay.isNull()) pStair->setLayer(idLay); + if (hasKey(args, "color")) pStair->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + + // 顺序有讲究:SetBaseCurve() 内部会重算截面/清专业数据,所以必须放在 + // SetLineStairData 之前;命令里是反的(Data -> SetSection -> SetBaseCurve), + // 结果材质/编号会被 SetBaseCurve 清掉。 + pStair->SetBaseCurve(&ln); + pStair->SetLineStairData(data); + pStair->GetSpecialtyData()->SetAt(KEY_2DSTYLE, 0); + + AcDbObjectId idNew; + Acad::ErrorStatus es = addToSpace(pStair, &idNew); + if (es != Acad::eOk) + { + delete pStair; + return errJson(kErrInternal, std::wstring(L"加入模型空间失败,err=") + std::to_wstring((int)es)); + } + touchEntity(pStair); + pStair->close(); + + nlohmann::json body; + body["ok"] = true; + body["type"] = "line_stair"; + body["handle"] = HandleOfId(idNew); + body["start"] = PointJson(ptS); + body["end"] = PointJson(ptE); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolAddLineStair, AddAecLineStairTool) + +// --------------------------------------------------------------------------- +// update_aec_line_stair —— 改直线钢梯 +// --------------------------------------------------------------------------- +class ToolUpdateLineStair : public mcp_Tool +{ +public: + std::string private_name() const override { return "update_aec_line_stair"; } + + std::string private_description() const override + { + return "改直线钢梯:起终点、梯宽/踏步/梯梁/栏管尺寸、材质编号,只传要改的字段。" + "改尺寸会重建几何;不传 start/end 就保持原来的走向。"; + } + + nlohmann::json private_input_schema() const override + { + return nlohmann::json::parse(R"({ + "type": "object", + "properties": { + "handle": { "type": "string", "description": "钢梯实体 handle" }, + "start": { "type": "array", "items": { "type": "number" }, "description": "新起点 [x,y]" }, + "end": { "type": "array", "items": { "type": "number" }, "description": "新终点 [x,y]" }, + "bottom_elevation": { "type": "number" }, "top_elevation": { "type": "number" }, + "width": { "type": "number" }, "steep_height": { "type": "number" }, + "steep_width": { "type": "number" }, "steep_thickness": { "type": "number" }, + "side_width": { "type": "number" }, "side_thickness": { "type": "number" }, + "diameter": { "type": "number" }, "top_height": { "type": "number" }, + "first_height": { "type": "number" }, "post_space": { "type": "number" }, + "with_rail": { "type": "boolean" }, + "material": { "type": "string" }, "factory": { "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(); + AcDbEntity* pEnt = openByHandle(sHandle, AcDb::kForWrite); + if (pEnt == NULL) return errJson(kErrNotFound, L"按 handle 打不开实体:" + utf8ToWstr(sHandle)); + + AecDbLineStair* pStair = AecDbLineStair::cast(pEnt); + if (pStair == NULL) + { + const std::string sCls = classNameOf(pEnt); + pEnt->close(); + return errJson(kErrWrongType, L"实体 " + utf8ToWstr(sCls) + L" 不是直线钢梯(AecDbLineStair)"); + } + + LineStair data; + ::memset(&data, 0, sizeof(LineStair)); + pStair->GetLineStairData(data); + + AcGePoint3d ptS(0.0, 0.0, 0.0), ptE(0.0, 0.0, 0.0); + AcDbCurve* pCrv = AcDbCurve::cast(pEnt); + bool bHasCurve = (pCrv != NULL && pCrv->getStartPoint(ptS) == Acad::eOk && + pCrv->getEndPoint(ptE) == Acad::eOk); + + LineStairFromArgs(data, args, true); + if (readPoint(args, "start", ptS)) bHasCurve = bHasCurve || true; + if (readPoint(args, "end", ptE)) bHasCurve = bHasCurve || true; + ptS.z = data.dBomEl; + ptE.z = data.dTopEl; + + if (bHasCurve && ptS.distanceTo(ptE) > 1.0) + { + AcDbLine ln(ptS, ptE); + pStair->SetBaseCurve(&ln); + } + + pStair->SetLineStairData(data); // 必须在 SetBaseCurve 之后(它会清专业数据) + if (hasKey(args, "color")) pStair->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + pStair->ReCreateDraw3d(); + touchEntity(pStair); + pStair->close(); + + nlohmann::json body; + body["ok"] = true; + body["type"] = "line_stair"; + body["handle"] = sHandle; + body["start"] = PointJson(ptS); + body["end"] = PointJson(ptE); + // 注意:材质/厂家/编号在 LineStair 自己的成员里,不在 bar 里 + // (GetLineStairData 只回填 bar 的直径/间距那些) + body["params"] = GuardBarToJson(data.bar); + body["params"]["material"] = acharToUtf8(data.m_sMaterial); + body["params"]["factory"] = acharToUtf8(data.m_sFactory); + body["params"]["no"] = acharToUtf8(data.m_sNo); + body["params"]["width"] = data.dW; + body["params"]["steep_height"] = data.dSteepH; + body["params"]["steep_width"] = data.dSteepW; + body["params"]["steep_thickness"] = data.dSteept; + body["params"]["side_width"] = data.dSideW; + body["params"]["side_thickness"] = data.dSidet; + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolUpdateLineStair, UpdateAecLineStairTool) + +// --------------------------------------------------------------------------- +// add_aec_guard_bar —— 护栏(PL_FZHN 直接绘制 / PL_QXHN 沿已有曲线) +// --------------------------------------------------------------------------- +class ToolAddGuardBar : public mcp_Tool +{ +public: + std::string private_name() const override { return "add_aec_guard_bar"; } + + std::string private_description() const override + { + return "建护栏(菜单 PL_FZHN 放置护栏 / PL_QXHN 曲线护栏,实体 AecDbGuardBar):" + "轮廓给 points([[x,y],...],自己画的)或 curve(已有曲线实体的 handle,圆弧/圆/多段线都行)。" + "栏管直径/扶手高/立柱间距等缺省照抄 CFZHNDlg。护栏按视图 elevation=0 绘制,基准曲线标高固定 0," + "实际高度由 bottom_elevation 决定。图层 LAY_GBAR。"; + } + + 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],...](至少 2 点)" }, + "curve": { "type": "string", "description": "或者给一条已有曲线的 handle(PL_QXHN 的做法)" }, + "diameter": { "type": "number", "description": "栏管直径,缺省 40" }, + "bar_thickness": { "type": "number", "description": "栏管壁厚,缺省 2.5" }, + "bottom_elevation": { "type": "number", "description": "底标高,缺省 0" }, + "top_height": { "type": "number", "description": "扶手高,缺省 1080" }, + "first_height": { "type": "number", "description": "底层横杆高,缺省 650" }, + "post_space": { "type": "number", "description": "立柱间距,缺省 1200" }, + "rect_post": { "type": "boolean", "description": "立柱是否方管" }, + "no_bottom_rail": { "type": "boolean", "description": "是否没有底部栏杆" }, + "vertical_draw": { "type": "boolean", "description": "是否竖向出图" }, + "material": { "type": "string", "description": "材质,缺省 镜亮不锈钢型材" }, + "factory": { "type": "string", "description": "厂家,缺省 厂家自制" }, + "no": { "type": "string", "description": "编号,缺省 HL-01" }, + "layer": { "type": "string", "description": "图层,缺省 LAY_GBAR" }, + "color": { "type": "integer", "description": "ACI 颜色号,256=ByLayer" } + } + })"); + } + + 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* pPl = NULL; + if (hasKey(args, "curve")) + pPl = PolylineOfHandle(wstrOr(args, "curve", L""), err); + else + pPl = PolylineOfPoints(args, err); + if (pPl == NULL) return errJson(kErrBadParam, err); + + GuardBar bar; + GuardBarFromArgs(bar, args, false); + + AecDbGuardBar* pBar = new AecDbGuardBar(); + std::wstring sLay = hasKey(args, "layer") ? wstrOr(args, "layer", L"") : L""; + if (sLay.empty()) sLay = L"LAY_GBAR"; + AcDbObjectId idLay = KTSetting::InitLayer(sLay.c_str()); + if (!idLay.isNull()) pBar->setLayer(idLay); + + // 命令里:方管立柱 SetSection(dD, dD, 0),其它 SetSection(dD, 0) + if (bar.bIsRectLever) + pBar->SetSection(bar.dD, bar.dD, 0.0); + else + pBar->SetSection(bar.dD, 0.0); + pBar->SetBaseCurve(pPl); + pBar->SetGuardBarData(bar); + pBar->GetSpecialtyData()->SetAt(KEY_2DSTYLE, 0); + if (hasKey(args, "color")) pBar->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + + delete pPl; // SetBaseCurve 会自己 clone + + AcDbObjectId idNew; + Acad::ErrorStatus es = addToSpace(pBar, &idNew); + if (es != Acad::eOk) + { + delete pBar; + return errJson(kErrInternal, std::wstring(L"加入模型空间失败,err=") + std::to_wstring((int)es)); + } + touchEntity(pBar); + pBar->close(); + + nlohmann::json body; + body["ok"] = true; + body["type"] = "guard_bar"; + body["handle"] = HandleOfId(idNew); + body["params"] = GuardBarToJson(bar); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolAddGuardBar, AddAecGuardBarTool) + +// --------------------------------------------------------------------------- +// update_aec_guard_bar —— 改护栏 +// --------------------------------------------------------------------------- +class ToolUpdateGuardBar : public mcp_Tool +{ +public: + std::string private_name() const override { return "update_aec_guard_bar"; } + + std::string private_description() const override + { + return "改护栏:栏管直径/高度/立柱间距/材质编号,只传要改的字段;给 points 或 curve 可以换走向。"; + } + + nlohmann::json private_input_schema() const override + { + return nlohmann::json::parse(R"({ + "type": "object", + "properties": { + "handle": { "type": "string", "description": "护栏实体 handle" }, + "points": { "type": "array", "items": { "type": "array", "items": { "type": "number" } }, + "description": "新的护栏走向(可选)" }, + "curve": { "type": "string", "description": "或者给一条新曲线的 handle(可选)" }, + "diameter": { "type": "number" }, "bar_thickness": { "type": "number" }, + "bottom_elevation": { "type": "number" }, "top_height": { "type": "number" }, + "first_height": { "type": "number" }, "post_space": { "type": "number" }, + "rect_post": { "type": "boolean" }, "no_bottom_rail": { "type": "boolean" }, + "vertical_draw": { "type": "boolean" }, + "material": { "type": "string" }, "factory": { "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(); + AcDbEntity* pEnt = openByHandle(sHandle, AcDb::kForWrite); + if (pEnt == NULL) return errJson(kErrNotFound, L"按 handle 打不开实体:" + utf8ToWstr(sHandle)); + + AecDbGuardBar* pBar = AecDbGuardBar::cast(pEnt); + if (pBar == NULL) + { + const std::string sCls = classNameOf(pEnt); + pEnt->close(); + return errJson(kErrWrongType, L"实体 " + utf8ToWstr(sCls) + L" 不是护栏(AecDbGuardBar)"); + } + + GuardBar bar; + ::memset(&bar, 0, sizeof(GuardBar)); + if (!pBar->GetGuardBarData(bar)) InitGuardBar(bar); + GuardBarFromArgs(bar, args, true); + + std::wstring err; + AcDbPolyline* pPl = NULL; + if (hasKey(args, "curve")) + pPl = PolylineOfHandle(wstrOr(args, "curve", L""), err); + else if (hasKey(args, "points")) + pPl = PolylineOfPoints(args, err); + if (!err.empty()) + { + pEnt->close(); + return errJson(kErrBadParam, err); + } + if (pPl != NULL) + { + pBar->SetBaseCurve(pPl); + delete pPl; + } + + if (bar.bIsRectLever) + pBar->SetSection(bar.dD, bar.dD, 0.0); + else + pBar->SetSection(bar.dD, 0.0); + pBar->SetGuardBarData(bar); + if (hasKey(args, "color")) pBar->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + pBar->ReCreateDraw3d(); + touchEntity(pBar); + pBar->close(); + + nlohmann::json body; + body["ok"] = true; + body["type"] = "guard_bar"; + body["handle"] = sHandle; + body["params"] = GuardBarToJson(bar); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolUpdateGuardBar, UpdateAecGuardBarTool) diff --git a/SourceCode/Code2026/cad_mcp_aec/cmakelists.txt b/SourceCode/Code2026/cad_mcp_aec/cmakelists.txt index 9ecd22c..2b407e2 100644 --- a/SourceCode/Code2026/cad_mcp_aec/cmakelists.txt +++ b/SourceCode/Code2026/cad_mcp_aec/cmakelists.txt @@ -7,6 +7,7 @@ set(SOURCES "aec_mcp_common.cpp" "aec_mcp_entity_tools.cpp" "aec_mcp_shape_tools.cpp" + "aec_mcp_stair_tools.cpp" "aec_mcp_query.cpp" "StdAfx.cpp" ) diff --git a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json index f929e0e..9954a11 100644 --- a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json +++ b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json @@ -3023,6 +3023,404 @@ "dll_name": "cad_mcp_aec.dll", "factory_function": "DeleteAecShapeTool" } + }, + { + "name": "add_aec_line_stair", + "description": "建直线钢梯(菜单 PL_PTLT 直线钢梯,实体 AecDbLineStair):给起点/终点平面位置 + 底/顶标高,再给梯宽、踏步、梯梁、栏管参数(都有缺省,照抄 CPTLDlg)。尺寸用图纸单位;起点 z 取 bottom_elevation、终点 z 取 top_elevation。图层 LAY_CSTAIR。", + "inputSchema": { + "type": "object", + "properties": { + "start": { + "type": "array", + "items": { + "type": "number" + }, + "description": "起点 [x,y](z 用 bottom_elevation)" + }, + "end": { + "type": "array", + "items": { + "type": "number" + }, + "description": "终点 [x,y](z 用 top_elevation)" + }, + "bottom_elevation": { + "type": "number", + "description": "底标高" + }, + "top_elevation": { + "type": "number", + "description": "顶标高,缺省 4000" + }, + "width": { + "type": "number", + "description": "梯宽,缺省 1000" + }, + "steep_height": { + "type": "number", + "description": "踏步高,缺省 200" + }, + "steep_width": { + "type": "number", + "description": "踏步宽,缺省 400" + }, + "steep_thickness": { + "type": "number", + "description": "踏步厚,缺省 8" + }, + "side_width": { + "type": "number", + "description": "梯梁宽,缺省 200" + }, + "side_thickness": { + "type": "number", + "description": "梯梁厚,缺省 40" + }, + "with_rail": { + "type": "boolean", + "description": "是否带护栏" + }, + "layer": { + "type": "string", + "description": "图层,缺省 LAY_CSTAIR" + }, + "color": { + "type": "integer", + "description": "ACI 颜色号,256=ByLayer" + }, + "diameter": { + "type": "number", + "description": "栏管直径" + }, + "bar_thickness": { + "type": "number", + "description": "栏管壁厚" + }, + "top_height": { + "type": "number", + "description": "扶手高" + }, + "first_height": { + "type": "number", + "description": "底层横杆高" + }, + "post_space": { + "type": "number", + "description": "立柱间距" + }, + "rect_post": { + "type": "boolean", + "description": "立柱是否方管" + }, + "no_bottom_rail": { + "type": "boolean", + "description": "是否没有底部栏杆" + }, + "vertical_draw": { + "type": "boolean", + "description": "是否竖向出图" + }, + "material": { + "type": "string", + "description": "材质" + }, + "factory": { + "type": "string", + "description": "厂家" + }, + "no": { + "type": "string", + "description": "编号" + } + }, + "required": [ + "start", + "end" + ] + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "AddAecLineStairTool" + } + }, + { + "name": "update_aec_line_stair", + "description": "改直线钢梯:起终点、梯宽/踏步/梯梁/栏管尺寸、材质编号,只传要改的字段。改尺寸会重建几何;不传 start/end 就保持原来的走向。", + "inputSchema": { + "type": "object", + "properties": { + "handle": { + "type": "string", + "description": "钢梯实体 handle" + }, + "start": { + "type": "array", + "items": { + "type": "number" + } + }, + "end": { + "type": "array", + "items": { + "type": "number" + } + }, + "bottom_elevation": { + "type": "number", + "description": "底标高" + }, + "top_elevation": { + "type": "number" + }, + "width": { + "type": "number" + }, + "steep_height": { + "type": "number" + }, + "steep_width": { + "type": "number" + }, + "steep_thickness": { + "type": "number" + }, + "side_width": { + "type": "number" + }, + "side_thickness": { + "type": "number" + }, + "with_rail": { + "type": "boolean" + }, + "color": { + "type": "integer" + }, + "diameter": { + "type": "number", + "description": "栏管直径" + }, + "bar_thickness": { + "type": "number", + "description": "栏管壁厚" + }, + "top_height": { + "type": "number", + "description": "扶手高" + }, + "first_height": { + "type": "number", + "description": "底层横杆高" + }, + "post_space": { + "type": "number", + "description": "立柱间距" + }, + "rect_post": { + "type": "boolean", + "description": "立柱是否方管" + }, + "no_bottom_rail": { + "type": "boolean", + "description": "是否没有底部栏杆" + }, + "vertical_draw": { + "type": "boolean", + "description": "是否竖向出图" + }, + "material": { + "type": "string", + "description": "材质" + }, + "factory": { + "type": "string", + "description": "厂家" + }, + "no": { + "type": "string", + "description": "编号" + } + }, + "required": [ + "handle" + ] + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "UpdateAecLineStairTool" + } + }, + { + "name": "add_aec_guard_bar", + "description": "建护栏(菜单 PL_FZHN 放置护栏 / PL_QXHN 曲线护栏,实体 AecDbGuardBar):轮廓给 points(自己画)或 curve(已有曲线 handle,圆弧/圆/多段线都行)。栏管直径/扶手高/立柱间距等缺省照抄 CFZHNDlg。护栏按视图 elevation=0 绘制,基准曲线标高固定 0,实际高度由 bottom_elevation 决定。图层 LAY_GBAR。", + "inputSchema": { + "type": "object", + "properties": { + "points": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + }, + "description": "护栏走向 [[x,y],...](至少 2 点)" + }, + "curve": { + "type": "string", + "description": "或者给一条已有曲线的 handle(PL_QXHN 的做法)" + }, + "layer": { + "type": "string", + "description": "图层,缺省 LAY_GBAR" + }, + "color": { + "type": "integer", + "description": "ACI 颜色号,256=ByLayer" + }, + "diameter": { + "type": "number", + "description": "栏管直径" + }, + "bar_thickness": { + "type": "number", + "description": "栏管壁厚" + }, + "bottom_elevation": { + "type": "number", + "description": "底标高" + }, + "top_height": { + "type": "number", + "description": "扶手高" + }, + "first_height": { + "type": "number", + "description": "底层横杆高" + }, + "post_space": { + "type": "number", + "description": "立柱间距" + }, + "rect_post": { + "type": "boolean", + "description": "立柱是否方管" + }, + "no_bottom_rail": { + "type": "boolean", + "description": "是否没有底部栏杆" + }, + "vertical_draw": { + "type": "boolean", + "description": "是否竖向出图" + }, + "material": { + "type": "string", + "description": "材质" + }, + "factory": { + "type": "string", + "description": "厂家" + }, + "no": { + "type": "string", + "description": "编号" + } + } + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "AddAecGuardBarTool" + } + }, + { + "name": "update_aec_guard_bar", + "description": "改护栏:栏管直径/高度/立柱间距/材质编号,只传要改的字段;给 points 或 curve 可以换走向。", + "inputSchema": { + "type": "object", + "properties": { + "handle": { + "type": "string", + "description": "护栏实体 handle" + }, + "points": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + }, + "description": "新的护栏走向(可选)" + }, + "curve": { + "type": "string", + "description": "或者给一条新曲线的 handle(可选)" + }, + "color": { + "type": "integer" + }, + "diameter": { + "type": "number", + "description": "栏管直径" + }, + "bar_thickness": { + "type": "number", + "description": "栏管壁厚" + }, + "bottom_elevation": { + "type": "number", + "description": "底标高" + }, + "top_height": { + "type": "number", + "description": "扶手高" + }, + "first_height": { + "type": "number", + "description": "底层横杆高" + }, + "post_space": { + "type": "number", + "description": "立柱间距" + }, + "rect_post": { + "type": "boolean", + "description": "立柱是否方管" + }, + "no_bottom_rail": { + "type": "boolean", + "description": "是否没有底部栏杆" + }, + "vertical_draw": { + "type": "boolean", + "description": "是否竖向出图" + }, + "material": { + "type": "string", + "description": "材质" + }, + "factory": { + "type": "string", + "description": "厂家" + }, + "no": { + "type": "string", + "description": "编号" + } + }, + "required": [ + "handle" + ] + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "UpdateAecGuardBarTool" + } } ] }