diff --git a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_pipehanger_tools.cpp b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_pipehanger_tools.cpp new file mode 100644 index 0000000..525766c --- /dev/null +++ b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_pipehanger_tools.cpp @@ -0,0 +1,556 @@ +// ============================================================================ +// aec_mcp_pipehanger_tools.cpp +// cad_mcp_aec 的"管道托架/支座"工具(工作计划第 6 项) +// list_aec_pipe_hangers / add_aec_pipe_hanger / update_aec_pipe_hanger +// 实体:AecDbPipeHanger(图集 03S42 那一套托架/支座) +// +// 5 个命令(PipeHanger/PipeHangerCmd.cpp 注册,实现在 PipeHanger/command.cpp): +// PL_DGTJ 单管托架(mode 0) / PL_SGTJ 双管托架(1) / PL_LGTJ 立管托架(2) / +// PL_PGZZ 平管支座(3) / PL_WGZZ 弯管支座(4) +// 做法一样: +// CGZDJDlg(ShowType(mode) 选分类、再选型号)-> GetHolderData(name, mpData, pms路径) +// -> new AecDbPipeHanger -> AddVar(&mpData) -> LoadPmsFile(pms) -> Insert(pt, dRot) +// 沿方向按 hf(层高,m)摆 nRows 个;弯管支座多一步 SetElbow(arc, OD) +// +// 数据在 <安装目录>/Support/Holder: +// Holder.txt 型号清单,每行 "中文名称/.jpg" +// .pms 建模脚本(EX / PCP / PCP6 … 指令) +// .csv 参数表(首行 "序号,DN,保温类型,L1,L2,hf,A,L,t,Q…") +// .jpg 预览图 +// ============================================================================ + +#include "StdAfx.h" +#include "KTCad.h" +#include "aec_mcp_common.h" +#include "mcp_plugin_api.h" + +#include "AecDbPipeHanger.h" +#include "AecDbObjXDataMap.h" +#include "CoreTools.h" +#include "KTSetting.h" + +using namespace aec_mcp; + +namespace +{ + const TCHAR* kPmsKey = _T("MCP_PMS_PATH"); // 自己记一份 pms 路径,update 要用 + + 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; + } + + bool ModeOfKind(const std::wstring& sKind, int& nMode) + { + if (sKind == L"single") { nMode = 0; return true; } // 单管托架 + if (sKind == L"double") { nMode = 1; return true; } // 双管托架 + if (sKind == L"vertical") { nMode = 2; return true; } // 立管托架 + if (sKind == L"horizontal") { nMode = 3; return true; } // 平管支座 + if (sKind == L"bend") { nMode = 4; return true; } // 弯管支座 + return false; + } + + bool HolderDir(CString& sDir) + { + CString sPs; + if (!KTSetting::GetKTPsPath(sPs) || sPs.IsEmpty()) return false; + sDir = sPs; + if (sDir[sDir.GetLength() - 1] != _T('\\')) sDir += _T("\\"); + sDir += _T("Support\\Holder\\"); + return true; + } + + // Holder.txt 每行 "中文名称/.jpg" + bool ReadHolderList(int nMode, std::vector >& arItems, CString& sDir, + std::wstring& err) + { + if (!HolderDir(sDir)) { err = L"取不到安装目录(KTSetting::GetKTPsPath 失败)"; return false; } + CString sFile; + sFile.Format(_T("%sHolder%d.txt"), (LPCTSTR)sDir, nMode); + + CStdioFile file; + if (!file.Open(sFile, CFile::modeRead | CFile::typeText)) + { + err = L"打不开型号清单:" + std::wstring((LPCTSTR)sFile); + return false; + } + CString sLn; + while (file.ReadString(sLn)) + { + sLn.Trim(); + if (sLn.IsEmpty()) continue; + const int nPos = sLn.ReverseFind(_T('/')); + if (nPos <= 0) continue; + arItems.push_back(std::make_pair(sLn.Left(nPos), sLn.Mid(nPos + 1))); + } + file.Close(); + if (arItems.empty()) { err = L"型号清单是空的:" + std::wstring((LPCTSTR)sFile); return false; } + return true; + } + + // "64.jpg" -> "64" + CString StemOfJpg(const CString& sJpg) + { + CString s = sJpg; + const int nDot = s.ReverseFind(_T('.')); + if (nDot > 0) s = s.Left(nDot); + return s; + } + + CString SplitField(const CString& sLn, int& nStart, int nIdx, std::vector* pCols) + { + int nComma = sLn.Find(_T(','), nStart); + if (nComma < 0) nComma = sLn.GetLength(); + CString s = sLn.Mid(nStart, nComma - nStart); + s.Trim(); + nStart = nComma + 1; + return s; + } + + // 读 csv:列名 + 第 nRow 行(1 基,无表头)里"能转成数字"的列 + bool ReadCsvRow(const CString& sCsvPath, int nRow, std::vector >& arVars, + std::vector* pCols, int* pRowCount, std::wstring& err) + { + CStdioFile file; + if (!file.Open(sCsvPath, CFile::modeRead | CFile::typeText)) + { + err = L"打不开参数表:" + std::wstring((LPCTSTR)sCsvPath); + return false; + } + CString sLn; + if (!file.ReadString(sLn)) { file.Close(); err = L"参数表是空的"; return false; } + + std::vector arCols; + { + int nStart = 0; + while (nStart <= sLn.GetLength()) + arCols.push_back(SplitField(sLn, nStart, 0, NULL)); + } + if (pCols != NULL) *pCols = arCols; + + int nCur = 0; + bool bFound = false; + while (file.ReadString(sLn)) + { + sLn.Trim(); + if (sLn.IsEmpty()) continue; + ++nCur; + if (nCur == nRow) + { + int nStart = 0, nIdx = 0; + while (nStart <= sLn.GetLength() && nIdx < (int)arCols.size()) + { + const CString sVal = SplitField(sLn, nStart, nIdx, NULL); + if (!sVal.IsEmpty() && + (_istdigit((unsigned short)sVal[0]) || sVal[0] == _T('-') || sVal[0] == _T('+'))) + arVars.push_back(std::make_pair(arCols[nIdx], _ttof((LPCTSTR)sVal))); + ++nIdx; + } + bFound = true; + } + } + file.Close(); + if (pRowCount != NULL) *pRowCount = nCur; + if (!bFound) { err = L"参数表里没有第 " + std::to_wstring(nRow) + L" 行"; return false; } + return !arVars.empty(); + } + + void MergeVars(AecDbObjXDataMap* pMap, const nlohmann::json& vars) + { + if (pMap == NULL || !vars.is_object()) return; + for (nlohmann::json::const_iterator it = vars.begin(); it != vars.end(); ++it) + { + if (!it.value().is_number()) continue; + const std::wstring sKey = utf8ToWstr(it.key()); + pMap->SetAt(sKey.c_str(), it.value().get()); + } + } + + nlohmann::json VarsToJson(AecDbObjXDataMap* pMap) + { + nlohmann::json o = nlohmann::json::object(); + if (pMap == NULL) return o; + AecDbObjXDataMap::It it = pMap->Begin(); + CString sKey; + AecXData xd; + int nGuard = 0; + while (pMap->GetNext(it, sKey, xd) && nGuard++ < 500) + { + if (xd.nVt == VT_R8) o[acharToUtf8((LPCTSTR)sKey)] = xd.dVal[0]; + else if (xd.nVt == VT_I4) o[acharToUtf8((LPCTSTR)sKey)] = (double)xd.nVal; + } + return o; + } +} + +// --------------------------------------------------------------------------- +// list_aec_pipe_hangers —— 列出型号 +// --------------------------------------------------------------------------- +class ToolListPipeHangers : public mcp_Tool +{ +public: + std::string private_name() const override { return "list_aec_pipe_hangers"; } + + std::string private_description() const override + { + return "列出管道托架/支座的图集型号(数据在 <安装目录>/Support/Holder)。\n" + "kind: single 单管托架(PL_DGTJ) / double 双管托架(PL_SGTJ) / vertical 立管托架(PL_LGTJ) /\n" + " horizontal 平管支座(PL_PGZZ) / bend 弯管支座(PL_WGZZ)。\n" + "返回型号名、pms 文件名、csv 列名、数据行数,供 add_aec_pipe_hanger 用。"; + } + + nlohmann::json private_input_schema() const override + { + return nlohmann::json::parse(R"({ + "type": "object", + "properties": { + "kind": { "type": "string", "enum": [ "single", "double", "vertical", "horizontal", "bend" ], + "description": "分类,缺省 single" } + } + })"); + } + + nlohmann::json Execute(const nlohmann::json& args) override + { + if (workingDb() == NULL) return errJson(kErrNoDocument, L"没有活动图纸"); + DocLock lock; + if (!lock.isLocked()) return errJson(kErrInternal, L"拿不到图纸写锁(有别的命令在跑?)"); + + int nMode = 0; + if (!ModeOfKind(wstrOr(args, "kind", L"single"), nMode)) + return errJson(kErrBadParam, L"kind 只支持 single / double / vertical / horizontal / bend"); + + std::vector > arItems; + CString sDir; + std::wstring err; + if (!ReadHolderList(nMode, arItems, sDir, err)) return errJson(kErrNotFound, err); + + nlohmann::json arOut = nlohmann::json::array(); + for (size_t i = 0; i < arItems.size(); ++i) + { + const CString sStem = StemOfJpg(arItems[i].second); + nlohmann::json o; + o["index"] = (int)i; + o["name"] = acharToUtf8((LPCTSTR)arItems[i].first); + o["pms"] = acharToUtf8((LPCTSTR)(sStem + _T(".pms"))); + + CString sCsv; + sCsv.Format(_T("%s%s.csv"), (LPCTSTR)sDir, (LPCTSTR)sStem); + std::vector > arVars; + std::vector arCols; + int nRows = 0; + std::wstring sErr2; + if (ReadCsvRow(sCsv, 1, arVars, &arCols, &nRows, sErr2)) + { + nlohmann::json arC = nlohmann::json::array(); + for (size_t k = 0; k < arCols.size(); ++k) + arC.push_back(acharToUtf8((LPCTSTR)arCols[k])); + o["columns"] = arC; + o["rows"] = nRows; + nlohmann::json arFirst = nlohmann::json::object(); + for (size_t k = 0; k < arVars.size(); ++k) + arFirst[acharToUtf8((LPCTSTR)arVars[k].first)] = arVars[k].second; + o["first_row"] = arFirst; + } + else + { + o["columns_error"] = acharToUtf8(sErr2.c_str()); + } + arOut.push_back(o); + } + + nlohmann::json body; + body["ok"] = true; + body["kind"] = acharToUtf8(wstrOr(args, "kind", L"single").c_str()); + body["dir"] = acharToUtf8((LPCTSTR)sDir); + body["count"] = (int)arOut.size(); + body["items"] = arOut; + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolListPipeHangers, ListAecPipeHangersTool) + +// --------------------------------------------------------------------------- +// add_aec_pipe_hanger —— 插入托架/支座 +// --------------------------------------------------------------------------- +class ToolAddPipeHanger : public mcp_Tool +{ +public: + std::string private_name() const override { return "add_aec_pipe_hanger"; } + + std::string private_description() const override + { + return "插入管道托架/支座(AecDbPipeHanger,图集 03S42):用 list_aec_pipe_hangers 拿型号,\n" + "再给 kind + index(或 pms 文件名)+ 插入点 + 旋转角;参数默认取该型号 csv 的第 csv_row 行,\n" + "也可用 vars 覆盖单个参数(如 {\\\"L1\\\":600})。rows/row_spacing 可以沿方向摆一串(命令里也是这么做的)。\n" + "弯管支座(kind=bend)还要给 elbow(圆弧 handle)和 elbow_od。图层 LAY_SUPPORT。"; + } + + nlohmann::json private_input_schema() const override + { + return nlohmann::json::parse(R"({ + "type": "object", + "properties": { + "kind": { "type": "string", "enum": [ "single", "double", "vertical", "horizontal", "bend" ], + "description": "分类,缺省 single" }, + "index": { "type": "integer", "description": "型号在清单里的序号(list_aec_pipe_hangers 返回的 index)" }, + "name": { "type": "string", "description": "或者给型号名称(清单里的 name)" }, + "pms": { "type": "string", "description": "或者直接给 pms 文件名(如 64.pms)" }, + "csv_row": { "type": "integer", "description": "参数取 csv 的第几行(1 基,缺省 1)" }, + "vars": { "type": "object", "description": "覆盖参数,如 {\"L1\":600,\"t\":5}" }, + "position": { "type": "array", "items": { "type": "number" }, "description": "插入点 [x,y,z]" }, + "rotation_deg": { "type": "number", "description": "旋转角(度),缺省 0" }, + "rows": { "type": "integer", "description": "沿方向摆几个(命令里由长度/hf 算),缺省 1" }, + "row_spacing": { "type": "number", "description": "每个之间的间距(图纸单位),缺省取 hf*1000" }, + "direction": { "type": "array", "items": { "type": "number" }, "description": "摆列方向 [x,y,z],缺省 +X" }, + "elbow": { "type": "string", "description": "弯管支座用:弯头的圆弧 handle" }, + "elbow_od": { "type": "number", "description": "弯管支座用:管外径" }, + "layer": { "type": "string", "description": "图层,缺省 LAY_SUPPORT" }, + "color": { "type": "integer" } + }, + "required": [ "position" ] + })"); + } + + 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 ptIns(0.0, 0.0, 0.0); + if (!readPoint(args, "position", ptIns)) + return errJson(kErrBadParam, L"需要 position(插入点)"); + + int nMode = 0; + if (!ModeOfKind(wstrOr(args, "kind", L"single"), nMode)) + return errJson(kErrBadParam, L"kind 只支持 single / double / vertical / horizontal / bend"); + + std::vector > arItems; + CString sDir; + std::wstring err; + if (!ReadHolderList(nMode, arItems, sDir, err)) return errJson(kErrNotFound, err); + + // 定位型号:index > name > pms + CString sStem; + if (hasKey(args, "index")) + { + const int n = intOr(args, "index", -1); + if (n < 0 || n >= (int)arItems.size()) + return errJson(kErrBadParam, L"index 超范围(0~" + std::to_wstring(arItems.size() - 1) + L")"); + sStem = StemOfJpg(arItems[n].second); + } + else if (hasKey(args, "name")) + { + const std::wstring sName = wstrOr(args, "name", L""); + for (size_t i = 0; i < arItems.size(); ++i) + { + if (std::wstring((LPCTSTR)arItems[i].first) == sName) + { + sStem = StemOfJpg(arItems[i].second); + break; + } + } + if (sStem.IsEmpty()) return errJson(kErrNotFound, L"清单里没有这个型号名:" + sName); + } + else if (hasKey(args, "pms")) + { + CString sPms = CString(wstrOr(args, "pms", L"").c_str()); + const int nDot = sPms.ReverseFind(_T('.')); + sStem = (nDot > 0) ? sPms.Left(nDot) : sPms; + } + else + { + return errJson(kErrBadParam, L"要给 index / name / pms 之一来指定型号"); + } + + CString sPmsPath; + sPmsPath.Format(_T("%s%s.pms"), (LPCTSTR)sDir, (LPCTSTR)sStem); + if (GetFileAttributes(sPmsPath) == INVALID_FILE_ATTRIBUTES) + return errJson(kErrNotFound, L"pms 文件不存在:" + utf8ToWstr(acharToUtf8((LPCTSTR)sPmsPath))); + + // 参数:csv 那行 + vars 覆盖 + CString sCsvPath; + sCsvPath.Format(_T("%s%s.csv"), (LPCTSTR)sDir, (LPCTSTR)sStem); + std::vector > arVars; + std::wstring sErr2; + ReadCsvRow(sCsvPath, intOr(args, "csv_row", 1), arVars, NULL, NULL, sErr2); + + AecDbObjXDataMap mpData; + for (size_t i = 0; i < arVars.size(); ++i) + mpData.SetAt((LPCTSTR)arVars[i].first, arVars[i].second); + if (hasKey(args, "vars")) MergeVars(&mpData, args["vars"]); + + // 摆列参数(命令里:hf 是层高 m,沿方向摆 nRows 个) + double dhf = 1.5; + mpData.GetAt(_T("hf"), dhf); + double dSpacing = numOr(args, "row_spacing", 0.0); + if (dSpacing <= 0.0) dSpacing = dhf * 1000.0; + int nRows = intOr(args, "rows", 1); + if (nRows < 1) nRows = 1; + + AcGePoint3d ptDir(0.0, 0.0, 0.0); + AcGeVector3d vtDir = AcGeVector3d::kXAxis; + if (readPoint(args, "direction", ptDir) && ptDir.asVector().length() > 1e-9) + vtDir = ptDir.asVector(); + vtDir.normalize(); + + const double dRot = CoreTools::A2R(numOr(args, "rotation_deg", 0.0)); + + // 弯管支座:需要圆弧 + 外径 + AcDbArc* pElbow = NULL; + if (nMode == 4) + { + if (!hasKey(args, "elbow")) return errJson(kErrBadParam, L"弯管支座需要 elbow(圆弧 handle)"); + const std::wstring sElbow = wstrOr(args, "elbow", L""); + AcDbEntity* pEnt = openByHandle(acharToUtf8(sElbow.c_str()), AcDb::kForRead); + pElbow = (pEnt != NULL) ? AcDbArc::cast(pEnt) : NULL; + if (pElbow == NULL) + { + if (pEnt != NULL) pEnt->close(); + return errJson(kErrWrongType, L"elbow 必须是圆弧(ARC):" + sElbow); + } + } + + 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(); + AcGePoint3d ptCur = ptIns; + for (int i = 0; i < nRows; ++i) + { + AecDbPipeHanger* pHg = new AecDbPipeHanger(); + if (!idLay.isNull()) pHg->setLayer(idLay); + if (hasKey(args, "color")) pHg->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + + pHg->AddVar(&mpData); + pHg->LoadPmsFile(sPmsPath); + if (pElbow != NULL) pHg->SetElbow(pElbow, numOr(args, "elbow_od", 0.0)); + pHg->GetSpecialtyData()->SetAt(kPmsKey, (LPCTSTR)sPmsPath); + + if (!pHg->Insert(ptCur, dRot)) + { + delete pHg; + if (pElbow != NULL) pElbow->close(); + return errJson(kErrInternal, L"Insert 失败(pms 脚本或参数不对)"); + } + + AcDbObjectId idNew; + if (addToSpace(pHg, &idNew) != Acad::eOk) + { + delete pHg; + continue; + } + touchEntity(pHg); + pHg->close(); + arHandles.push_back(HandleOfId(idNew)); + ptCur += vtDir * dSpacing; + } + if (pElbow != NULL) pElbow->close(); + + nlohmann::json body; + body["ok"] = !arHandles.empty(); + body["type"] = "pipe_hanger"; + body["pms"] = acharToUtf8((LPCTSTR)sPmsPath); + body["count"] = (int)arHandles.size(); + body["handles"] = arHandles; + if (!arHandles.empty()) body["handle"] = arHandles[0]; + body["vars"] = VarsToJson(&mpData); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolAddPipeHanger, AddAecPipeHangerTool) + +// --------------------------------------------------------------------------- +// update_aec_pipe_hanger —— 改参数(重建几何) +// --------------------------------------------------------------------------- +class ToolUpdatePipeHanger : public mcp_Tool +{ +public: + std::string private_name() const override { return "update_aec_pipe_hanger"; } + + std::string private_description() const override + { + return "改管道托架/支座(AecDbPipeHanger)的参数:给 vars 覆盖(如 {\"L1\":600})," + "或给 rotation_deg 改旋转角。实体是按 pms 脚本现场生成的,改参数等于按新参数重建几何" + "(位置沿用原来的)。pms 路径是创建时记下的,换型号请删了重建。"; + } + + nlohmann::json private_input_schema() const override + { + return nlohmann::json::parse(R"({ + "type": "object", + "properties": { + "handle": { "type": "string", "description": "托架/支座实体 handle" }, + "vars": { "type": "object", "description": "要覆盖的参数" }, + "rotation_deg": { "type": "number", "description": "新的旋转角(度)" }, + "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)); + + AecDbPipeHanger* pHg = AecDbPipeHanger::cast(pEnt); + if (pHg == NULL) + { + const std::string sCls = classNameOf(pEnt); + pEnt->close(); + return errJson(kErrWrongType, L"实体 " + utf8ToWstr(sCls) + L" 不是管道托架/支座(AecDbPipeHanger)"); + } + + CString sPms; + if (!pHg->GetSpecialtyData()->GetAt(kPmsKey, sPms) || sPms.IsEmpty()) + { + pEnt->close(); + return errJson(kErrBadParam, L"这个实体不是用 add_aec_pipe_hanger 建的(没有记 pms 路径),改不了"); + } + + // 现有参数 + 覆盖 + AecDbObjXDataMap xData; + pHg->GetVar(xData); + if (hasKey(args, "vars")) MergeVars(&xData, args["vars"]); + + const AcGePoint3d ptPos = pHg->position(); + const double dRot = hasKey(args, "rotation_deg") + ? CoreTools::A2R(numOr(args, "rotation_deg", 0.0)) + : pHg->rotation(); + + pHg->AddVar(&xData); + pHg->LoadPmsFile((LPCTSTR)sPms); + if (!pHg->Insert(ptPos, dRot)) + { + pEnt->close(); + return errJson(kErrInternal, L"按新参数重建失败(pms 脚本或参数不对)"); + } + if (hasKey(args, "color")) pHg->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + touchEntity(pHg); + + nlohmann::json body; + body["ok"] = true; + body["type"] = "pipe_hanger"; + body["handle"] = sHandle; + body["pms"] = acharToUtf8((LPCTSTR)sPms); + body["position"] = { ptPos.x, ptPos.y, ptPos.z }; + body["vars"] = VarsToJson(&xData); + pEnt->close(); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolUpdatePipeHanger, UpdateAecPipeHangerTool) diff --git a/SourceCode/Code2026/cad_mcp_aec/cmakelists.txt b/SourceCode/Code2026/cad_mcp_aec/cmakelists.txt index b17370d..1163db1 100644 --- a/SourceCode/Code2026/cad_mcp_aec/cmakelists.txt +++ b/SourceCode/Code2026/cad_mcp_aec/cmakelists.txt @@ -12,6 +12,7 @@ set(SOURCES "aec_mcp_window_tools.cpp" "aec_mcp_zline_window_tools.cpp" "aec_mcp_holder_tools.cpp" + "aec_mcp_pipehanger_tools.cpp" "aec_mcp_attachment_tools.cpp" "aec_mcp_dim_tools.cpp" "aec_mcp_roof_tools.cpp" diff --git a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json index 1b3ed23..5468fbd 100644 --- a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json +++ b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json @@ -6411,6 +6411,152 @@ "dll_name": "cad_mcp_aec.dll", "factory_function": "UpdateAecBossHolderTool" } + }, + { + "name": "list_aec_pipe_hangers", + "description": "列出管道托架/支座的图集型号(数据在 <安装目录>/Support/Holder)。kind: single 单管托架(PL_DGTJ) / double 双管托架(PL_SGTJ) / vertical 立管托架(PL_LGTJ) / horizontal 平管支座(PL_PGZZ) / bend 弯管支座(PL_WGZZ)。返回型号名、pms 文件名、csv 列名、行数。", + "inputSchema": { + "type": "object", + "properties": { + "kind": { + "type": "string", + "enum": [ + "single", + "double", + "vertical", + "horizontal", + "bend" + ], + "description": "分类,缺省 single" + } + } + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "ListAecPipeHangersTool" + } + }, + { + "name": "add_aec_pipe_hanger", + "description": "插入管道托架/支座(AecDbPipeHanger,图集 03S42):先用 list_aec_pipe_hangers 拿型号,再给 kind + index(或 name / pms)+ 插入点 + 旋转角;参数默认取该型号 csv 的第 csv_row 行,可用 vars 覆盖单项。rows/row_spacing 可沿 direction 摆一串(命令里也是这么摆的)。弯管支座还要 elbow(圆弧 handle)+ elbow_od。图层 LAY_SUPPORT。", + "inputSchema": { + "type": "object", + "properties": { + "kind": { + "type": "string", + "enum": [ + "single", + "double", + "vertical", + "horizontal", + "bend" + ], + "description": "分类,缺省 single" + }, + "index": { + "type": "integer", + "description": "型号在清单里的序号" + }, + "name": { + "type": "string", + "description": "或型号名称" + }, + "pms": { + "type": "string", + "description": "或 pms 文件名(如 64.pms)" + }, + "csv_row": { + "type": "integer", + "description": "参数取 csv 第几行(1 基,缺省 1)" + }, + "vars": { + "type": "object", + "description": "覆盖参数,如 {\"L1\":600}" + }, + "position": { + "type": "array", + "items": { + "type": "number" + }, + "description": "插入点 [x,y,z]" + }, + "rotation_deg": { + "type": "number", + "description": "旋转角(度),缺省 0" + }, + "rows": { + "type": "integer", + "description": "沿方向摆几个,缺省 1" + }, + "row_spacing": { + "type": "number", + "description": "间距(缺省 hf*1000)" + }, + "direction": { + "type": "array", + "items": { + "type": "number" + }, + "description": "摆列方向,缺省 +X" + }, + "elbow": { + "type": "string", + "description": "弯管支座:弯头圆弧 handle" + }, + "elbow_od": { + "type": "number", + "description": "弯管支座:管外径" + }, + "layer": { + "type": "string", + "description": "图层,缺省 LAY_SUPPORT" + }, + "color": { + "type": "integer" + } + }, + "required": [ + "position" + ] + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "AddAecPipeHangerTool" + } + }, + { + "name": "update_aec_pipe_hanger", + "description": "改管道托架/支座的参数:vars 覆盖某项(如 {\"L1\":600})或 rotation_deg 改旋转角。实体按 pms 脚本现场生成,改参数等于按新参数重建几何(位置沿用)。换型号请删了重建。", + "inputSchema": { + "type": "object", + "properties": { + "handle": { + "type": "string", + "description": "托架/支座实体 handle" + }, + "vars": { + "type": "object", + "description": "要覆盖的参数" + }, + "rotation_deg": { + "type": "number", + "description": "新旋转角(度)" + }, + "color": { + "type": "integer" + } + }, + "required": [ + "handle" + ] + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "UpdateAecPipeHangerTool" + } } ] } diff --git a/cad-mcp-aec-item6-progress.md b/cad-mcp-aec-item6-progress.md index c146597..1f3cf93 100644 --- a/cad-mcp-aec-item6-progress.md +++ b/cad-mcp-aec-item6-progress.md @@ -34,6 +34,7 @@ | `PL_FZSS` | 放置散水 | `AecDbXApron` | `add/update_aec_apron` | | `PL_LSJM` | 绘制沟渠 | `AecDbEwPipeBase` | `add/update_aec_ditch` | | 标注 8 个 | 序号/批标/洞口/套管/翼环/阀门/标注阀门/标注管件 | `AecDbEwPipeDim` | `add/update_aec_pipe_dim` + `kind` | +| 托架/支座 5 个 | `PL_DGTJ` 单管 / `PL_SGTJ` 双管 / `PL_LGTJ` 立管 / `PL_PGZZ` 平管 / `PL_WGZZ` 弯管 | `AecDbPipeHanger` | `list/add/update_aec_pipe_hanger` + `kind` | | `PL_PTLT` | 直线钢梯 | `AecDbLineStair` | `add/update_aec_line_stair` | | `PL_FZHN` | 放置护栏 | `AecDbGuardBar` | `add/update_aec_guard_bar` | | `PL_QXHN` | 曲线护栏 | `AecDbGuardBar` | 同上(`curve` 给已有曲线 handle) | diff --git a/cad-mcp-aec.md b/cad-mcp-aec.md index 817afd3..a2fd3e1 100644 --- a/cad-mcp-aec.md +++ b/cad-mcp-aec.md @@ -21,10 +21,11 @@ SourceCode/Code2026/cad_mcp_aec/ ├── aec_mcp_window_tools.cpp 普通门窗:add/update_aec_window(AecDbXOpening,2 个) ├── aec_mcp_zline_window_tools.cpp 带形窗:add/update_aec_strip_window(AecDbZLineXOpening,2 个) ├── aec_mcp_holder_tools.cpp 支吊架:支架/吊架/支墩(AecDbHolder / AecDbHanger / AecDbBossHolder,6 个) +├── aec_mcp_pipehanger_tools.cpp 管道托架/支座:list/add/update_aec_pipe_hanger(AecDbPipeHanger,3 个) ├── aec_mcp_attachment_tools.cpp 附属构件:阳台/台阶/坡道/散水/沟渠(各 add+update,10 个) ├── aec_mcp_dim_tools.cpp 标注:add/update_aec_pipe_dim(AecDbEwPipeDim,2 个) ├── aec_mcp_query.cpp query_aec_entities / get_aec_entity_detail(2 个) -└── mcp_config.json 运行期配置(89 个工具:26 个 cad_mcp_plugins + 61 个本插件 + 2 个 lisp_inline) +└── mcp_config.json 运行期配置(92 个工具:26 个 cad_mcp_plugins + 64 个本插件 + 2 个 lisp_inline) ``` 顶层 `cmakelists.txt` 里挂在 `cad_mcp_frame` 同一处: @@ -53,7 +54,7 @@ if (IS_ZWCAD OR CAD_SDK_VERSION GREATER_EQUAL 20) 插件的头文件里必须保持默认的 `dllimport`。`cad_mcp_plugins` 里定义了它们, 那是因为它不使用这些类;本插件用了,定义了就变成"导出自己没有的符号"。 -## 3. 工具清单(本插件 61 个;`mcp_config.json` 合计 89 个) +## 3. 工具清单(本插件 64 个;`mcp_config.json` 合计 92 个) 工具名和参数都按仓库既有工具的写法(`add_line` / `query_entities` / `get_entity_detail`): **动词_名词、点用 `[x,y]` 或 `[x,y,z]` 数组、颜色用 `color`(ACI,256=ByLayer)**。 @@ -94,6 +95,7 @@ if (IS_ZWCAD OR CAD_SDK_VERSION GREATER_EQUAL 20) | `add_aec_strip_window` / `update_aec_strip_window` | 建/改带形窗(`AecDbZLineXOpening`,`PL_DXCH`):墙 handle + 沿墙起止点 + 外侧点;add 给窗高/窗台高/柱距/凸窗,update 收全套框料/玻璃/外伸/挑出/挡板 | `wall`/`start`/`end`/`side_point`、`height`/`sill_height`/`column_space`/`bay_window`/`to_floor`、`frame_thickness`/`frame_width`/`glass_thickness`/`top_row_height`/`out1`/`out2`/`extend1`/`extend2`/`glass_offset_in`/`baffle_thickness`/`add_baffle1`/`add_baffle2` | | `add_aec_holder` / `update_aec_holder` | 沿路径摆支架(`AecDbHolder`,`PL_FZZJ`) | `points`/`spacing`/`bottom_elevation`/`direction_point`、`post_length`/`arm_length`/`steel_width`/`steel_thickness`/`material`/`no`/`purpose` | | `add_aec_hanger` / `update_aec_hanger` | 沿路径摆吊架(`AecDbHanger`,`PL_FZDJ`) | `points`/`spacing`/`top_elevation`/`direction_point`、`row_count`/`rod_diameter`/`rod_as_angle`/`post_length`/`arm_length`/`steel_width`/`steel_thickness` | +| `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` | @@ -166,7 +168,7 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命 ## 5. 端到端实测(AutoCAD 2020 / R230 Debug) 做法:把仓库里的 `mcp_config.json` 拷到部署目录,用 `/b` 脚本加载 `cad_mcp_frame.arx`, -然后用裸 socket 打 JSON-RPC。`tools/list` 现在返回 **89** 个工具(本插件 61 个), +然后用裸 socket 打 JSON-RPC。`tools/list` 现在返回 **92** 个工具(本插件 64 个), `%TEMP%\mcp_plugin_load.log` 里每个工厂都是 `[try ] ... create=... destroy=...` 成功。 **第一轮(只有 12 个工具时)的建/改实测**(仍然有效): @@ -185,12 +187,12 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命 | 类型不匹配 | ✅ `update_aec_wall` 传板的 handle → `-32004`「实体是 XSlab,不是 AecDbXWall」 | | 不存在的 handle | ✅ `-32002` | -导出表:61 个工厂(`aec_mcp_entity_tools.cpp` 18 + `aec_mcp_stair_tools.cpp` 10 + +导出表:64 个工厂(`aec_mcp_entity_tools.cpp` 18 + `aec_mcp_stair_tools.cpp` 10 + `aec_mcp_attachment_tools.cpp` 10 + `aec_mcp_holder_tools.cpp` 6 + `aec_mcp_shape_tools.cpp` 5 + `aec_mcp_roof_tools.cpp` 2 + `aec_mcp_sfp_stair_tools.cpp` 2 + `aec_mcp_window_tools.cpp` 2 + -`aec_mcp_zline_window_tools.cpp` 2 + `aec_mcp_dim_tools.cpp` 2 + `aec_mcp_query.cpp` 2)+ -`Destroy_*` + `g_mcpPluginApiVersion`,与 `mcp_config.json` 里 `dll_name=cad_mcp_aec.dll` -的 61 条一一对应(少一条 backend 就不会被注册,见 §6)。 +`aec_mcp_zline_window_tools.cpp` 2 + `aec_mcp_pipehanger_tools.cpp` 3 + `aec_mcp_dim_tools.cpp` 2 + +`aec_mcp_query.cpp` 2)+ `Destroy_*` + `g_mcpPluginApiVersion`,与 `mcp_config.json` 里 +`dll_name=cad_mcp_aec.dll` 的 64 条一一对应(少一条 backend 就不会被注册,见 §6)。 **后续各轮补的东西(都在 R230 Debug + pcf_1.dwg / 空图上实测过)**: @@ -230,8 +232,8 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命 `cad-mcp-frame.json`),重启 CAD。 注意:`set_debug_post_build()` 只拷构建产物,**配置文件不自动部署**,需要手工拷一次。 - 仓库里这份 `mcp_config.json` 是"26 个 `cad_mcp_plugins` + 61 个本插件 + 2 个 `lisp_inline`" - = 89 的合集,拷过去就等于全量替换。 + 仓库里这份 `mcp_config.json` 是"26 个 `cad_mcp_plugins` + 64 个本插件 + 2 个 `lisp_inline`" + = 92 的合集,拷过去就等于全量替换。 **每条工具都必须有 `backend`**(`{"type":"c++_dll","dll_name":"cad_mcp_aec.dll", "factory_function":"AddAecShapeTool"}`):只写 `name`/`description`/`inputSchema` @@ -249,9 +251,9 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命 - 造型里只有 7 种基本体能 `update_aec_shape`;曲线类(loft/extrude/revolve/sweep/cut/weir) 的截面/路径没存在实体里,要改只能删了重建。 - 没有事务/撤销包装:调用即改库。批量改图建议先 `query_aec_entities` 拿 handle,再逐条 `update`。 -- `mcp_config.json` 里的 89 个工具现在都能加载(`tools/list` = 89)。 +- `mcp_config.json` 里的 92 个工具现在都能加载(`tools/list` = 92)。 其中 26 个属于 `cad_mcp_plugins`(含从 CadProject 合并过来的批注/编辑类工具), - 61 个属于本插件,2 个是 lisp_inline。 + 64 个属于本插件,2 个是 lisp_inline。 移植那批工具时踩到两个本仓库差异(已修,见那次提交): 1. 上游 `dll` 的写库工具没有文档锁,在本仓库的运行方式下会返回 `cannot open target space for write`(`eLockViolation`)—— 补了 `dwg_annotate::DocLock`; @@ -336,11 +338,11 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命 |EL_HBLD|绘避雷带|AecDbEwFlexiblePipe|(未实现)|| |EL_JSSJ|加伸缩缝|AecDb3dRoadAxisLine|(未实现)|| |EL_FWBR|<-翻弯避让|AecDb3dRoadAxisLine|(未实现)|| -|PL_DGTJ|单管托架|AecDbPipeHanger|(未实现)|| -|PL_SGTJ|双管托架|AecDbPipeHanger|(未实现)|| -|PL_LGTJ|立管托架|AecDbPipeHanger|(未实现)|| -|PL_PGZZ|平管支座|AecDbPipeHanger|(未实现)|| -|PL_WGZZ|弯管支座|AecDbPipeHanger|(未实现)|| +|PL_DGTJ|单管托架|AecDbPipeHanger|add_aec_pipe_hanger(kind=single)|update_aec_pipe_hanger| +|PL_SGTJ|双管托架|AecDbPipeHanger|add_aec_pipe_hanger(kind=double)|update_aec_pipe_hanger| +|PL_LGTJ|立管托架|AecDbPipeHanger|add_aec_pipe_hanger(kind=vertical)|update_aec_pipe_hanger| +|PL_PGZZ|平管支座|AecDbPipeHanger|add_aec_pipe_hanger(kind=horizontal)|update_aec_pipe_hanger| +|PL_WGZZ|弯管支座|AecDbPipeHanger|add_aec_pipe_hanger(kind=bend)|update_aec_pipe_hanger| |PL_SBLG|设备连管|AecDbEwPipe|add_aec_pipe|update_aec_pipe| |PL_RYGZ|任意管嘴|AecDbEwEquipment|(未实现)|| |PL_XHBZ|序号标注|AecDbEwPipeDim|add_aec_pipe_dim(kind=seq)|update_aec_pipe_dim| @@ -928,3 +930,34 @@ iso_valve / iso_fitting),`update_aec_pipe_dim` 改文字/样式/字高。 bbox x 967~9000;精修框料 80/玻璃 40/首排 900/加挡板 后回读正确。 支架(路径 9000、间距 1500)→ 6 个;吊架(间距 2000)→ 4 个;支墩(间距 2000)→ 4 个; 三者 update(臂长/吊杆直径+排数/支墩类型+槽钢 c)都回读正确。 + +**第八批:管道托架/支座(`AecDbPipeHanger`,图集 03S42)** + +5 个命令 `PL_DGTJ` 单管 / `PL_SGTJ` 双管 / `PL_LGTJ` 立管 / `PL_PGZZ` 平管 / `PL_WGZZ` 弯管 +都在 **PipeHanger 模块**(不是 CoreCommand),但实体 `AecDbPipeHanger` 在 CoreLibrary 里, +所以本插件能直接 new。做法固定: + +``` +CGZDJDlg(ShowType(mode) 选分类 -> 选型号)-> GetHolderData(name, mpData, pms路径) +new AecDbPipeHanger -> AddVar(&mpData) -> LoadPmsFile(pms) -> Insert(pt, dRot) +沿方向按 hf(层高 m)摆 nRows 个;弯管支座多一步 SetElbow(arc, OD) +``` + +**型号数据在 `<安装目录>/Support/Holder`**(注意是安装目录,不是 `sys`): +`Holder.txt`(型号清单,每行 `中文名称/.jpg`)、`.pms`(建模脚本)、 +`.csv`(参数表,首行如 `序号,DN,保温类型,L1,L2,hf,A,L,t,Q`)、`.jpg`。 +mode:0 单管 / 1 双管 / 2 立管 / 3 平管 / 4 弯管。 + +工具: +- `list_aec_pipe_hangers(kind)`:读 `Holder.txt` + 对应 csv 的列名与首行,返回型号清单 +- `add_aec_pipe_hanger(kind, index|name|pms, position, csv_row?, vars?, rows/row_spacing/direction?, elbow?/elbow_od?)` + —— 参数默认取 csv 那一行(只收数字列,"保温类型"这类文字列跳过),`vars` 可覆盖单项; + 一次可沿方向摆一串,返回 `count` + `handles` +- `update_aec_pipe_hanger(handle, vars?, rotation_deg?)` —— 读回原参数合并后 + `AddVar + LoadPmsFile + Insert(position, rot)` 重建几何;pms 路径在创建时记进 + `MCP_PMS_PATH`,所以换型号请删了重建 + +**实测**(R230 Debug,空图):`list_aec_pipe_hangers(single)` 拿到 4 个型号 + 列名/首行 +(L1=110、L2=100、hf=1.5、A=153、L=45、t=4、Q=10、DN=15); +按 index 0 插入(rows=3、间距 1500)→ 3 个实例、pms 指向 `Support\Holder4.pms`; +`update` 改 `L1=600` 后回读正确;`single`/`double` 两个分类都能建。