diff --git a/SourceCode/Code2026/cad_mcp_aec/aec_mcp_attachment_tools.cpp b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_attachment_tools.cpp new file mode 100644 index 0000000..626eb38 --- /dev/null +++ b/SourceCode/Code2026/cad_mcp_aec/aec_mcp_attachment_tools.cpp @@ -0,0 +1,1051 @@ +// ============================================================================ +// aec_mcp_attachment_tools.cpp +// cad_mcp_aec 的附属构件工具(工作计划第 6 项) +// * add/update_aec_balcony —— 放置阳台 AecDbBalcony(PL_FZYT) +// +// 命令的做法(ArchCmd/command2.cpp PL_FZYTCmdFnc): +// GetPathOnWall() 拿"墙上的路径段 + 墙数据 + 墙侧方向" -> CFZYTDlg 填 BalconyData +// -> data.dBomEl += 墙底标高;data.dRailWidth += 墙厚*0.5 +// -> new AecDbBalcony + SetBalconyData + SetBaseCurve(path) +// + KEY_StartDir = 墙侧方向 + KEY_2DSTYLE = 0 -> 图层 LAY_BALCONY +// +// 命令里的 GetPathOnWall 是交互的(两个点 + 选墙 + 点一下确认墙侧方向)。 +// 工具这版:给 wall handle + start/end(两个点,会投影到墙中心线)+ side_point(确认墙 +// 往外的那一侧),路径用"沿墙中线采样出来的多段线",直墙就是那一段直线。 +// ============================================================================ + +#include "StdAfx.h" +#include "KTCad.h" +#include "aec_mcp_common.h" +#include "mcp_plugin_api.h" + +#include "AecDbBalcony.h" +#include "AecDbXStep.h" +#include "AecDbAscent.h" +#include "AecDbXApron.h" +#include "AecDbWall.h" +#include "AecDbObjXDataMap.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; + } + + // 墙上的路径:把 start/end 投影到墙中心线,沿中线采样成多段线(直墙就是两点) + // vtDir 取"墙中线中点处的法向,朝向 side_pt 那一侧";与命令里 GetPathOnWall 的结果同义。 + AcDbPolyline* BuildWallPath(AecDbXWall* pWall, const AcGePoint3d& ptStart, const AcGePoint3d& ptEnd, + const AcGePoint3d& ptSide, AcGeVector3d& vtDir, std::wstring& err) + { + AcDbCurve* pCrv = AcDbCurve::cast((AcDbEntity*)pWall); + if (pCrv == NULL) { err = L"墙不是曲线,取不到中心线"; return NULL; } + + AcGePoint3d pt1(0.0, 0.0, 0.0), pt2(0.0, 0.0, 0.0); + if (pCrv->getClosestPointTo(ptStart, pt1) != Acad::eOk || + pCrv->getClosestPointTo(ptEnd, pt2) != Acad::eOk) + { + err = L"start / end 投影到墙中心线失败"; + return NULL; + } + + double d1 = 0.0, d2 = 0.0; + if (pCrv->getDistAtPoint(pt1, d1) != Acad::eOk || pCrv->getDistAtPoint(pt2, d2) != Acad::eOk) + { + err = L"取墙中心线上的距离失败"; + return NULL; + } + if (fabs(d2 - d1) < 1e-6) + { + err = L"start 与 end 在墙上的距离太近"; + return NULL; + } + + // 采样:直墙两点就够,弧形按 200 一段 + int nSeg = (int)ceil(fabs(d2 - d1) / 200.0); + if (nSeg < 1) nSeg = 1; + if (nSeg > 200) nSeg = 200; + + AcDbPolyline* pPl = new AcDbPolyline(nSeg + 1); + for (int i = 0; i <= nSeg; ++i) + { + AcGePoint3d ptOn(0.0, 0.0, 0.0); + const double d = d1 + (d2 - d1) * (double)i / (double)nSeg; + if (pCrv->getPointAtDist(d, ptOn) != Acad::eOk) + { + delete pPl; + err = L"沿墙中心线取点失败"; + return NULL; + } + pPl->addVertexAt(i, AcGePoint2d(ptOn.x, ptOn.y), 0.0, 0.0, 0.0); + } + pPl->setElevation(0.0); + + // 墙侧方向:中点切向绕 Z 转 90°,取朝 side 点那一侧 + AcGePoint3d ptMid(0.0, 0.0, 0.0), ptTangPt(0.0, 0.0, 0.0); + AcGeVector3d vtTan(1.0, 0.0, 0.0); + if (pCrv->getPointAtDist(0.5 * (d1 + d2), ptMid) == Acad::eOk && + pCrv->getFirstDeriv(ptMid, vtTan) == Acad::eOk) + { + vtTan.normalize(); + vtDir = AcGeVector3d::kZAxis.crossProduct(vtTan); + if (vtDir.length() < 1e-9) vtDir = AcGeVector3d::kYAxis; + vtDir.normalize(); + if (vtDir.dotProduct(ptSide - ptMid) < 0.0) + vtDir = -vtDir; + } + else + { + err = L"取墙中心线切向失败(side_point 定不了墙侧方向)"; + delete pPl; + return NULL; + } + return pPl; + } + + void InitBalcony(BalconyData& d) + { + ::memset(&d, 0, sizeof(BalconyData)); + d.nRailEdge = 0; + d.dRailHeight = 1200.0; + d.dSlabThick = 100.0; + d.dRailWidth = 1500.0; // 阳台宽(往外挑多少) + d.dGirderThick = 150.0; + d.dBomEl = 160.0; // 相对墙底 + d.dBeamH = 100.0; + d.dBeamW = 100.0; + d.bAddOpening = FALSE; + d.duFrame = 1200.0; + d.dvFrame = 30.0; + d.dWinHeight = 1000.0; + CopyStr(d.m_sMaterial, 256, L"铝合金玻璃"); + CopyStr(d.m_sFactory, 256, L"现场定制"); + } + + // 阳台参数不多,add/update 都给全 + void BalconyFromArgs(BalconyData& d, const nlohmann::json& a, bool bMerge) + { + if (!bMerge) InitBalcony(d); + if (hasKey(a, "rail_height")) d.dRailHeight = numOr(a, "rail_height", d.dRailHeight); + if (hasKey(a, "width")) d.dRailWidth = numOr(a, "width", d.dRailWidth); + if (hasKey(a, "slab_thickness")) d.dSlabThick = numOr(a, "slab_thickness", d.dSlabThick); + if (hasKey(a, "girder_thickness")) d.dGirderThick = numOr(a, "girder_thickness", d.dGirderThick); + if (hasKey(a, "bottom_elevation")) d.dBomEl = numOr(a, "bottom_elevation", d.dBomEl); // 相对墙底 + if (hasKey(a, "beam_height")) d.dBeamH = numOr(a, "beam_height", d.dBeamH); + if (hasKey(a, "beam_width")) d.dBeamW = numOr(a, "beam_width", d.dBeamW); + if (hasKey(a, "rail_edge")) d.nRailEdge = intOr(a, "rail_edge", d.nRailEdge); + if (hasKey(a, "add_opening")) d.bAddOpening = intOr(a, "add_opening", 0) ? TRUE : FALSE; + if (hasKey(a, "frame_vertical")) d.duFrame = numOr(a, "frame_vertical", d.duFrame); + if (hasKey(a, "frame_horizontal")) d.dvFrame = numOr(a, "frame_horizontal", d.dvFrame); + if (hasKey(a, "window_height")) d.dWinHeight = numOr(a, "win_height", d.dWinHeight); + if (hasKey(a, "material")) CopyStr(d.m_sMaterial, 256, wstrOr(a, "material", L"")); + if (hasKey(a, "factory")) CopyStr(d.m_sFactory, 256, wstrOr(a, "factory", L"")); + if (hasKey(a, "no")) CopyStr(d.m_sNo, 256, wstrOr(a, "no", L"")); + } + + nlohmann::json BalconyToJson(const BalconyData& d) + { + nlohmann::json o; + o["rail_height"] = d.dRailHeight; + o["width"] = d.dRailWidth; + o["slab_thickness"] = d.dSlabThick; + o["girder_thickness"] = d.dGirderThick; + o["bottom_elevation"] = d.dBomEl; + o["beam_height"] = d.dBeamH; + o["beam_width"] = d.dBeamW; + o["rail_edge"] = d.nRailEdge; + o["add_opening"] = (d.bAddOpening != FALSE); + o["frame_vertical"] = d.duFrame; + o["frame_horizontal"] = d.dvFrame; + o["window_height"] = d.dWinHeight; + o["material"] = acharToUtf8(d.m_sMaterial); + o["factory"] = acharToUtf8(d.m_sFactory); + o["no"] = acharToUtf8(d.m_sNo); + return o; + } +} + +// --------------------------------------------------------------------------- +// add_aec_balcony —— 放置阳台(PL_FZYT) +// --------------------------------------------------------------------------- +class ToolAddBalcony : public mcp_Tool +{ +public: + std::string private_name() const override { return "add_aec_balcony"; } + + std::string private_description() const override + { + return "沿墙放置阳台(菜单 PL_FZYT 放置阳台,实体 AecDbBalcony):给墙 handle + 起止点" + "(投影到墙中心线)+ 一个确认墙外侧方向的点,再给挑出宽度、栏杆高、板厚、梁尺寸等" + "(缺省照抄 CFZYTDlg)。阳台底标高按\"相对墙底\"给。图层 LAY_BALCONY。"; + } + + nlohmann::json private_input_schema() const override + { + return nlohmann::json::parse(R"({ + "type": "object", + "properties": { + "wall": { "type": "string", "description": "墙(AecDbXWall)的 handle" }, + "start": { "type": "array", "items": { "type": "number" }, "description": "阳台沿墙的起点 [x,y]" }, + "end": { "type": "array", "items": { "type": "number" }, "description": "阳台沿墙的终点 [x,y]" }, + "side_point": { "type": "array", "items": { "type": "number" }, "description": "墙外侧任意一点 [x,y],用来定挑出方向" }, + "width": { "type": "number", "description": "阳台挑出宽度,缺省 1500" }, + "rail_height": { "type": "number", "description": "栏杆高,缺省 1200" }, + "slab_thickness": { "type": "number", "description": "底板厚,缺省 100" }, + "girder_thickness": { "type": "number", "description": "阳台梁厚,缺省 150" }, + "beam_height": { "type": "number", "description": "阳台梁高,缺省 100" }, + "beam_width": { "type": "number", "description": "阳台梁宽,缺省 100" }, + "bottom_elevation": { "type": "number", "description": "底板底标高(相对墙底),缺省 160" }, + "rail_edge": { "type": "integer", "description": "无扶手的边(按对话框选项)" }, + "add_opening": { "type": "boolean", "description": "阳台栏板上加门窗" }, + "frame_vertical": { "type": "number", "description": "竖框高,缺省 1200" }, + "frame_horizontal": { "type": "number", "description": "横框宽,缺省 30" }, + "window_height": { "type": "number", "description": "窗高,缺省 1000" }, + "material": { "type": "string", "description": "材质,缺省 铝合金玻璃" }, + "factory": { "type": "string", "description": "厂家,缺省 现场定制" }, + "no": { "type": "string", "description": "编号" }, + "layer": { "type": "string", "description": "图层,缺省 LAY_BALCONY" }, + "color": { "type": "integer", "description": "ACI 颜色号,256=ByLayer" } + }, + "required": [ "wall", "start", "end", "side_point" ] + })"); + } + + 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), ptSide(0.0, 0.0, 0.0); + if (!readPoint(args, "start", ptS) || !readPoint(args, "end", ptE)) + return errJson(kErrBadParam, L"需要 start / end([x,y])"); + readPoint(args, "side_point", ptSide); + + if (!hasKey(args, "wall")) return errJson(kErrBadParam, L"缺少 wall(墙 handle)"); + const std::wstring sWall = wstrOr(args, "wall", L""); + AcDbEntity* pWallEnt = openByHandle(acharToUtf8(sWall.c_str()), AcDb::kForRead); + if (pWallEnt == NULL) return errJson(kErrNotFound, L"按 handle 打不开墙:" + sWall); + AecDbXWall* pWall = AecDbXWall::cast(pWallEnt); + if (pWall == NULL) + { + const std::string sCls = classNameOf(pWallEnt); + pWallEnt->close(); + return errJson(kErrWrongType, L"handle " + sWall + L" 是 " + utf8ToWstr(sCls) + L",不是墙"); + } + WallData wd; + ::memset(&wd, 0, sizeof(WallData)); + pWall->GetWallData(wd); + + std::wstring err; + AcGeVector3d vtDir(0.0, 1.0, 0.0); + AcDbPolyline* pPath = BuildWallPath(pWall, ptS, ptE, ptSide, vtDir, err); + pWallEnt->close(); + if (pPath == NULL) return errJson(kErrBadParam, err); + + BalconyData data; + BalconyFromArgs(data, args, false); + data.dBomEl += wd.dBomEl; // 命令里:底标高 += 墙底 + data.dRailWidth += wd.dThick * 0.5; // 命令里:挑出宽度 += 半墙厚 + + AecDbBalcony* pBalcony = new AecDbBalcony(); + std::wstring sLay = hasKey(args, "layer") ? wstrOr(args, "layer", L"") : L""; + if (sLay.empty()) sLay = L"LAY_BALCONY"; + AcDbObjectId idLay = KTSetting::InitLayer(sLay.c_str()); + if (!idLay.isNull()) pBalcony->setLayer(idLay); + if (hasKey(args, "color")) pBalcony->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + + pBalcony->SetBalconyData(data); + pBalcony->SetBaseCurve(pPath); + pBalcony->GetSpecialtyData()->SetAt(KEY_StartDir, vtDir); + pBalcony->GetSpecialtyData()->SetAt(KEY_2DSTYLE, 0); + delete pPath; // SetBaseCurve 会自己 clone + + AcDbObjectId idNew; + Acad::ErrorStatus es = addToSpace(pBalcony, &idNew); + if (es != Acad::eOk) + { + delete pBalcony; + return errJson(kErrInternal, std::wstring(L"加入模型空间失败,err=") + std::to_wstring((int)es)); + } + touchEntity(pBalcony); + nlohmann::json body; + body["ok"] = true; + body["type"] = "balcony"; + body["direction"] = { vtDir.x, vtDir.y, vtDir.z }; + body["params"] = BalconyToJson(data); + pBalcony->close(); + body["handle"] = HandleOfId(idNew); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolAddBalcony, AddAecBalconyTool) + +// --------------------------------------------------------------------------- +// update_aec_balcony —— 改阳台(字段全收) +// --------------------------------------------------------------------------- +class ToolUpdateBalcony : public mcp_Tool +{ +public: + std::string private_name() const override { return "update_aec_balcony"; } + + std::string private_description() const override + { + return "修改阳台(AecDbBalcony):只传要改的字段(挑出宽度/栏杆高/板厚/梁尺寸/栏板门窗/材质编号);" + "给 wall+start+end+side_point 可以换位置和走向。注意 bottom_elevation 这里按**绝对标高**给。"; + } + + nlohmann::json private_input_schema() const override + { + return nlohmann::json::parse(R"({ + "type": "object", + "properties": { + "handle": { "type": "string", "description": "阳台实体 handle" }, + "wall": { "type": "string", "description": "新的墙 handle(可选,改位置时一起给)" }, + "start": { "type": "array", "items": { "type": "number" } }, + "end": { "type": "array", "items": { "type": "number" } }, + "side_point": { "type": "array", "items": { "type": "number" } }, + "width": { "type": "number" }, "rail_height": { "type": "number" }, + "slab_thickness": { "type": "number" }, "girder_thickness": { "type": "number" }, + "beam_height": { "type": "number" }, "beam_width": { "type": "number" }, + "bottom_elevation": { "type": "number", "description": "底板底标高(绝对)" }, + "rail_edge": { "type": "integer" }, "add_opening": { "type": "boolean" }, + "frame_vertical": { "type": "number" }, "frame_horizontal": { "type": "number" }, + "window_height": { "type": "number" }, + "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)); + + AecDbBalcony* pBalcony = AecDbBalcony::cast(pEnt); + if (pBalcony == NULL) + { + const std::string sCls = classNameOf(pEnt); + pEnt->close(); + return errJson(kErrWrongType, L"实体 " + utf8ToWstr(sCls) + L" 不是阳台(AecDbBalcony)"); + } + + BalconyData data; + ::memset(&data, 0, sizeof(BalconyData)); + pBalcony->GetBalconyData(data); + BalconyFromArgs(data, args, true); + + // 换位置:需要 wall + start + end(side_point 可选,缺省沿用原方向) + if (hasKey(args, "wall") && hasKey(args, "start") && hasKey(args, "end")) + { + AcGePoint3d ptS(0.0, 0.0, 0.0), ptE(0.0, 0.0, 0.0), ptSide(0.0, 0.0, 0.0); + readPoint(args, "start", ptS); + readPoint(args, "end", ptE); + readPoint(args, "side_point", ptSide); + + const std::wstring sWall = wstrOr(args, "wall", L""); + AcDbEntity* pWallEnt = openByHandle(acharToUtf8(sWall.c_str()), AcDb::kForRead); + AecDbXWall* pWall = (pWallEnt != NULL) ? AecDbXWall::cast(pWallEnt) : NULL; + if (pWall == NULL) + { + if (pWallEnt != NULL) pWallEnt->close(); + pEnt->close(); + return errJson(kErrWrongType, L"wall 不是墙或打不开:" + sWall); + } + if (!hasKey(args, "side_point")) + { + AcGeVector3d vtOld(0.0, 0.0, 0.0); + if (pBalcony->GetSpecialtyData()->GetAt(KEY_StartDir, vtOld)) + ptSide = ptS + vtOld * 1000.0; + else + ptSide = ptS + AcGeVector3d(0.0, 1000.0, 0.0); + } + std::wstring err; + AcGeVector3d vtDir(0.0, 1.0, 0.0); + AcDbPolyline* pPath = BuildWallPath(pWall, ptS, ptE, ptSide, vtDir, err); + pWallEnt->close(); + if (pPath == NULL) + { + pEnt->close(); + return errJson(kErrBadParam, err); + } + pBalcony->SetBaseCurve(pPath); + delete pPath; + pBalcony->GetSpecialtyData()->SetAt(KEY_StartDir, vtDir); + } + + pBalcony->SetBalconyData(data); + if (hasKey(args, "color")) pBalcony->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + pBalcony->ReCreateDraw3d(); + touchEntity(pBalcony); + nlohmann::json body; + body["ok"] = true; + body["type"] = "balcony"; + body["handle"] = sHandle; + body["params"] = BalconyToJson(data); + pEnt->close(); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolUpdateBalcony, UpdateAecBalconyTool) + +// =========================================================================== +// 台阶(PL_FZTJ,AecDbXStep)—— 沿墙路径 +// =========================================================================== +namespace +{ + void InitXStep(XStepData& d) + { + ::memset(&d, 0, sizeof(XStepData)); + d.dW = 450.0; // 台阶总宽 + d.dSteepW = 300.0; + d.dSteepH = 150.0; + d.nSteepS = 3; + d.dBaseEl = 0.0; // 相对墙底 + d.dBaseW = 2000.0; // 平台进深 + d.nBaseA = 0; + d.nStpStyle = 0; + d.nStrStyle = 0; + } + + void XStepFromArgs(XStepData& d, const nlohmann::json& a, bool bMerge) + { + if (!bMerge) InitXStep(d); + if (hasKey(a, "width")) d.dW = numOr(a, "width", d.dW); + if (hasKey(a, "steep_width")) d.dSteepW = numOr(a, "steep_width", d.dSteepW); + if (hasKey(a, "steep_height")) d.dSteepH = numOr(a, "steep_height", d.dSteepH); + if (hasKey(a, "steep_count")) d.nSteepS = intOr(a, "steep_count", d.nSteepS); + if (hasKey(a, "bottom_elevation")) d.dBaseEl = numOr(a, "bottom_elevation", d.dBaseEl); + if (hasKey(a, "base_width")) d.dBaseW = numOr(a, "base_width", d.dBaseW); + if (hasKey(a, "base_align")) d.nBaseA = intOr(a, "base_align", d.nBaseA); + if (hasKey(a, "step_style")) d.nStpStyle = intOr(a, "step_style", d.nStpStyle); + if (hasKey(a, "struct_style")) d.nStrStyle = intOr(a, "struct_style", d.nStrStyle); + } + + nlohmann::json XStepToJson(const XStepData& d) + { + nlohmann::json o; + o["width"] = d.dW; + o["steep_width"] = d.dSteepW; + o["steep_height"] = d.dSteepH; + o["steep_count"] = d.nSteepS; + o["bottom_elevation"] = d.dBaseEl; + o["base_width"] = d.dBaseW; + o["base_align"] = d.nBaseA; + o["step_style"] = d.nStpStyle; + o["struct_style"] = d.nStrStyle; + return o; + } +} + +class ToolAddXStep : public mcp_Tool +{ +public: + std::string private_name() const override { return "add_aec_xstep"; } + + std::string private_description() const override + { + return "沿墙放置台阶(菜单 PL_FZTJ 放置台阶,实体 AecDbXStep):给墙 handle + 起止点" + "(投影到墙中心线)+ 墙外侧点,再给台阶宽/踏步/平台进深等(缺省照抄 CFZTJDlg)。" + "bottom_elevation 按相对墙底给。图层 LAY_BALCONY。"; + } + + nlohmann::json private_input_schema() const override + { + return nlohmann::json::parse(R"({ + "type": "object", + "properties": { + "wall": { "type": "string", "description": "墙(AecDbXWall)的 handle" }, + "start": { "type": "array", "items": { "type": "number" } }, + "end": { "type": "array", "items": { "type": "number" } }, + "side_point": { "type": "array", "items": { "type": "number" }, "description": "墙外侧任意一点,定台阶朝外方向" }, + "width": { "type": "number", "description": "台阶总宽,缺省 450" }, + "steep_width": { "type": "number", "description": "踏步宽,缺省 300" }, + "steep_height": { "type": "number", "description": "踏步高,缺省 150" }, + "steep_count": { "type": "integer", "description": "踏步数,缺省 3" }, + "bottom_elevation": { "type": "number", "description": "底标高(相对墙底),缺省 0" }, + "base_width": { "type": "number", "description": "平台进深,缺省 2000" }, + "base_align": { "type": "integer", "description": "0 平台左 / 1 平台右" }, + "step_style": { "type": "integer", "description": "台阶方式" }, + "struct_style": { "type": "integer", "description": "结构形式" }, + "layer": { "type": "string", "description": "图层,缺省 LAY_BALCONY" }, + "color": { "type": "integer" } + }, + "required": [ "wall", "start", "end", "side_point" ] + })"); + } + + 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), ptSide(0.0, 0.0, 0.0); + if (!readPoint(args, "start", ptS) || !readPoint(args, "end", ptE)) + return errJson(kErrBadParam, L"需要 start / end([x,y])"); + readPoint(args, "side_point", ptSide); + + if (!hasKey(args, "wall")) return errJson(kErrBadParam, L"缺少 wall(墙 handle)"); + const std::wstring sWall = wstrOr(args, "wall", L""); + AcDbEntity* pWallEnt = openByHandle(acharToUtf8(sWall.c_str()), AcDb::kForRead); + if (pWallEnt == NULL) return errJson(kErrNotFound, L"按 handle 打不开墙:" + sWall); + AecDbXWall* pWall = AecDbXWall::cast(pWallEnt); + if (pWall == NULL) + { + const std::string sCls = classNameOf(pWallEnt); + pWallEnt->close(); + return errJson(kErrWrongType, L"handle " + sWall + L" 是 " + utf8ToWstr(sCls) + L",不是墙"); + } + WallData wd; + ::memset(&wd, 0, sizeof(WallData)); + pWall->GetWallData(wd); + + std::wstring err; + AcGeVector3d vtDir(0.0, 1.0, 0.0); + AcDbPolyline* pPath = BuildWallPath(pWall, ptS, ptE, ptSide, vtDir, err); + pWallEnt->close(); + if (pPath == NULL) return errJson(kErrBadParam, err); + + XStepData data; + XStepFromArgs(data, args, false); + data.dBaseEl += wd.dBomEl; // 命令里:底标高 += 墙底 + + AecDbXStep* pStep = new AecDbXStep(); + std::wstring sLay = hasKey(args, "layer") ? wstrOr(args, "layer", L"") : L""; + if (sLay.empty()) sLay = L"LAY_BALCONY"; + AcDbObjectId idLay = KTSetting::InitLayer(sLay.c_str()); + if (!idLay.isNull()) pStep->setLayer(idLay); + if (hasKey(args, "color")) pStep->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + + pStep->SetXStepData(data); + pStep->SetBaseCurve(pPath); + pStep->GetSpecialtyData()->SetAt(KEY_StartDir, vtDir); + pStep->GetSpecialtyData()->SetAt(KEY_2DSTYLE, 0); + delete pPath; + + AcDbObjectId idNew; + Acad::ErrorStatus es = addToSpace(pStep, &idNew); + if (es != Acad::eOk) + { + delete pStep; + return errJson(kErrInternal, std::wstring(L"加入模型空间失败,err=") + std::to_wstring((int)es)); + } + touchEntity(pStep); + nlohmann::json body; + body["ok"] = true; + body["type"] = "xstep"; + body["direction"] = { vtDir.x, vtDir.y, vtDir.z }; + body["params"] = XStepToJson(data); + pStep->close(); + body["handle"] = HandleOfId(idNew); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolAddXStep, AddAecXStepTool) + +class ToolUpdateXStep : public mcp_Tool +{ +public: + std::string private_name() const override { return "update_aec_xstep"; } + + std::string private_description() const override + { + return "改台阶(AecDbXStep):台阶宽/踏步/平台进深/样式,只传要改的字段;" + "给 wall+start+end+side_point 可以换位置。bottom_elevation 这里按绝对标高给。"; + } + + nlohmann::json private_input_schema() const override + { + return nlohmann::json::parse(R"({ + "type": "object", + "properties": { + "handle": { "type": "string", "description": "台阶实体 handle" }, + "wall": { "type": "string" }, "start": { "type": "array", "items": { "type": "number" } }, + "end": { "type": "array", "items": { "type": "number" } }, + "side_point": { "type": "array", "items": { "type": "number" } }, + "width": { "type": "number" }, "steep_width": { "type": "number" }, + "steep_height": { "type": "number" }, "steep_count": { "type": "integer" }, + "bottom_elevation": { "type": "number", "description": "底标高(绝对)" }, + "base_width": { "type": "number" }, "base_align": { "type": "integer" }, + "step_style": { "type": "integer" }, "struct_style": { "type": "integer" }, + "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)); + + AecDbXStep* pStep = AecDbXStep::cast(pEnt); + if (pStep == NULL) + { + const std::string sCls = classNameOf(pEnt); + pEnt->close(); + return errJson(kErrWrongType, L"实体 " + utf8ToWstr(sCls) + L" 不是台阶(AecDbXStep)"); + } + + XStepData data; + ::memset(&data, 0, sizeof(XStepData)); + pStep->GetXStepData(data); + XStepFromArgs(data, args, true); + + if (hasKey(args, "wall") && hasKey(args, "start") && hasKey(args, "end")) + { + AcGePoint3d ptS(0.0, 0.0, 0.0), ptE(0.0, 0.0, 0.0), ptSide(0.0, 0.0, 0.0); + readPoint(args, "start", ptS); + readPoint(args, "end", ptE); + if (!readPoint(args, "side_point", ptSide)) + { + AcGeVector3d vtOld(0.0, 0.0, 0.0); + if (pStep->GetSpecialtyData()->GetAt(KEY_StartDir, vtOld)) ptSide = ptS + vtOld * 1000.0; + else ptSide = ptS + AcGeVector3d(0.0, 1000.0, 0.0); + } + const std::wstring sWall = wstrOr(args, "wall", L""); + AcDbEntity* pWallEnt = openByHandle(acharToUtf8(sWall.c_str()), AcDb::kForRead); + AecDbXWall* pWall = (pWallEnt != NULL) ? AecDbXWall::cast(pWallEnt) : NULL; + if (pWall == NULL) + { + if (pWallEnt != NULL) pWallEnt->close(); + pEnt->close(); + return errJson(kErrWrongType, L"wall 不是墙或打不开:" + sWall); + } + std::wstring err; + AcGeVector3d vtDir(0.0, 1.0, 0.0); + AcDbPolyline* pPath = BuildWallPath(pWall, ptS, ptE, ptSide, vtDir, err); + pWallEnt->close(); + if (pPath == NULL) { pEnt->close(); return errJson(kErrBadParam, err); } + pStep->SetBaseCurve(pPath); + delete pPath; + pStep->GetSpecialtyData()->SetAt(KEY_StartDir, vtDir); + } + + pStep->SetXStepData(data); + if (hasKey(args, "color")) pStep->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + pStep->ReCreateDraw3d(); + touchEntity(pStep); + nlohmann::json body; + body["ok"] = true; + body["type"] = "xstep"; + body["handle"] = sHandle; + body["params"] = XStepToJson(data); + pEnt->close(); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolUpdateXStep, UpdateAecXStepTool) + +// =========================================================================== +// 坡道(PL_FZPD,AecDbAscent)—— 两点 +// =========================================================================== +namespace +{ + void InitAscent(AscentData& d) + { + ::memset(&d, 0, sizeof(AscentData)); + d.dLx = 2100.0; + d.dLy = 450.0; + d.dW = 3000.0; + d.dSideW = 300.0; + d.dTopEl = 450.0; + d.bAlignL = FALSE; + d.bAlignR = FALSE; + d.bNonslip = FALSE; + } + + void AscentFromArgs(AscentData& d, const nlohmann::json& a, bool bMerge) + { + if (!bMerge) InitAscent(d); + if (hasKey(a, "run_length")) d.dLx = numOr(a, "run_length", d.dLx); + if (hasKey(a, "rise")) d.dLy = numOr(a, "rise", d.dLy); + if (hasKey(a, "width")) d.dW = numOr(a, "width", d.dW); + if (hasKey(a, "side_width")) d.dSideW = numOr(a, "side_width", d.dSideW); + if (hasKey(a, "top_elevation")) d.dTopEl = numOr(a, "top_elevation", d.dTopEl); + if (hasKey(a, "align_left")) d.bAlignL = intOr(a, "align_left", 0) ? TRUE : FALSE; + if (hasKey(a, "align_right")) d.bAlignR = intOr(a, "align_right", 0) ? TRUE : FALSE; + if (hasKey(a, "nonslip")) d.bNonslip = intOr(a, "nonslip", 0) ? TRUE : FALSE; + } + + nlohmann::json AscentToJson(const AscentData& d) + { + nlohmann::json o; + o["run_length"] = d.dLx; + o["rise"] = d.dLy; + o["width"] = d.dW; + o["side_width"] = d.dSideW; + o["top_elevation"] = d.dTopEl; + o["align_left"] = (d.bAlignL != FALSE); + o["align_right"] = (d.bAlignR != FALSE); + o["nonslip"] = (d.bNonslip != FALSE); + return o; + } +} + +class ToolAddAscent : public mcp_Tool +{ +public: + std::string private_name() const override { return "add_aec_ascent"; } + + std::string private_description() const override + { + return "放置坡道(菜单 PL_FZPD 放置坡道,实体 AecDbAscent):给起点和终点(坡道走向)," + "再给水平投影长/坡高/坡宽/翻边宽/顶标高等(缺省照抄 CFZPDDlg)。图层 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]" }, + "end": { "type": "array", "items": { "type": "number" }, "description": "坡道终点 [x,y]" }, + "run_length": { "type": "number", "description": "水平投影长,缺省 2100" }, + "rise": { "type": "number", "description": "坡高,缺省 450" }, + "width": { "type": "number", "description": "坡宽,缺省 3000" }, + "side_width": { "type": "number", "description": "翻边宽,缺省 300" }, + "top_elevation": { "type": "number", "description": "顶标高,缺省 450" }, + "align_left": { "type": "boolean" }, "align_right": { "type": "boolean" }, + "nonslip": { "type": "boolean", "description": "是否有防滑条" }, + "layer": { "type": "string", "description": "图层,缺省 LAY_CSTAIR" }, + "color": { "type": "integer" } + }, + "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])"); + if (ptS.distanceTo(ptE) < 1.0) + return errJson(kErrBadParam, L"坡道起点和终点太近"); + + AscentData data; + AscentFromArgs(data, args, false); + + AecDbAscent* pAscent = new AecDbAscent(); + 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()) pAscent->setLayer(idLay); + if (hasKey(args, "color")) pAscent->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + + pAscent->SetAscentData(data); + pAscent->SetBaseCurve(ptS, ptE); + + AcDbObjectId idNew; + Acad::ErrorStatus es = addToSpace(pAscent, &idNew); + if (es != Acad::eOk) + { + delete pAscent; + return errJson(kErrInternal, std::wstring(L"加入模型空间失败,err=") + std::to_wstring((int)es)); + } + touchEntity(pAscent); + nlohmann::json body; + body["ok"] = true; + body["type"] = "ascent"; + body["params"] = AscentToJson(data); + pAscent->close(); + body["handle"] = HandleOfId(idNew); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolAddAscent, AddAecAscentTool) + +class ToolUpdateAscent : public mcp_Tool +{ +public: + std::string private_name() const override { return "update_aec_ascent"; } + + std::string private_description() const override + { + return "改坡道(AecDbAscent):水平投影长/坡高/坡宽/翻边/顶标高/对齐/防滑条," + "只传要改的字段;给 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" } }, + "end": { "type": "array", "items": { "type": "number" } }, + "run_length": { "type": "number" }, "rise": { "type": "number" }, + "width": { "type": "number" }, "side_width": { "type": "number" }, + "top_elevation": { "type": "number" }, + "align_left": { "type": "boolean" }, "align_right": { "type": "boolean" }, + "nonslip": { "type": "boolean" }, "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)); + + AecDbAscent* pAscent = AecDbAscent::cast(pEnt); + if (pAscent == NULL) + { + const std::string sCls = classNameOf(pEnt); + pEnt->close(); + return errJson(kErrWrongType, L"实体 " + utf8ToWstr(sCls) + L" 不是坡道(AecDbAscent)"); + } + + AscentData data; + ::memset(&data, 0, sizeof(AscentData)); + pAscent->GetAscentData(data); + AscentFromArgs(data, args, true); + + AcGePoint3d ptS(0.0, 0.0, 0.0), ptE(0.0, 0.0, 0.0); + if (readPoint(args, "start", ptS) && readPoint(args, "end", ptE) && ptS.distanceTo(ptE) > 1.0) + pAscent->SetBaseCurve(ptS, ptE); + + pAscent->SetAscentData(data); + if (hasKey(args, "color")) pAscent->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + pAscent->ReCreateDraw3d(); + touchEntity(pAscent); + nlohmann::json body; + body["ok"] = true; + body["type"] = "ascent"; + body["handle"] = sHandle; + body["params"] = AscentToJson(data); + pEnt->close(); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolUpdateAscent, UpdateAecAscentTool) + +// =========================================================================== +// 散水(PL_FZSS,AecDbXApron)—— 闭合路径 +// =========================================================================== +class ToolAddApron : public mcp_Tool +{ +public: + std::string private_name() const override { return "add_aec_apron"; } + + std::string private_description() const override + { + return "放置散水(菜单 PL_FZSS 放置散水,实体 AecDbXApron):给一条走向 points(自动闭合)," + "再给散水宽/内边厚/外边厚/离墙偏移/顶标高等(缺省照抄 CFZSSDlg)。图层 LAY_BALCONY。"; + } + + 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 点,自动闭合)" }, + "width": { "type": "number", "description": "散水宽" }, + "inside_thickness": { "type": "number", "description": "内侧厚" }, + "outside_thickness": { "type": "number", "description": "外侧厚" }, + "offset_from_wall": { "type": "number", "description": "离墙偏移" }, + "elevation": { "type": "number", "description": "顶标高" }, + "layer": { "type": "string", "description": "图层,缺省 LAY_BALCONY" }, + "color": { "type": "integer" } + }, + "required": [ "points", "width" ] + })"); + } + + 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, "points") || !args["points"].is_array() || args["points"].size() < 2) + return errJson(kErrBadParam, L"需要 points:[[x,y],...](至少 2 点)"); + const double dW = numOr(args, "width", 0.0); + if (dW <= 0.0) return errJson(kErrBadParam, L"width 必须 > 0"); + + AcDbPolyline* pPl = new AcDbPolyline((int)args["points"].size()); + int nIdx = 0; + for (size_t i = 0; i < args["points"].size(); ++i) + { + const nlohmann::json& pt = args["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; return errJson(kErrBadParam, L"points 有效点少于 2 个"); } + pPl->setClosed(Adesk::kTrue); + + AecDbXApron* pApron = new AecDbXApron(); + std::wstring sLay = hasKey(args, "layer") ? wstrOr(args, "layer", L"") : L""; + if (sLay.empty()) sLay = L"LAY_BALCONY"; + AcDbObjectId idLay = KTSetting::InitLayer(sLay.c_str()); + if (!idLay.isNull()) pApron->setLayer(idLay); + if (hasKey(args, "color")) pApron->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + + pApron->SetBaseCurve(pPl); + pApron->SetSection(10.0, 10.0, 0.0); // 与命令一致的占位截面 + pApron->SetConstantWidth(dW); + if (hasKey(args, "inside_thickness")) pApron->SetInsideThick(numOr(args, "inside_thickness", 0.0)); + if (hasKey(args, "outside_thickness")) pApron->SetOutSideThick(numOr(args, "outside_thickness", 0.0)); + if (hasKey(args, "offset_from_wall")) pApron->SetOffsetFromWall(numOr(args, "offset_from_wall", 0.0)); + pApron->GetSpecialtyData()->SetAt(KEY_BOMEL, numOr(args, "elevation", 0.0)); + AcGeVector3d vtZero(0.0, 0.0, 0.0); + pApron->GetSpecialtyData()->SetAt(KEY_StartDir, vtZero); + delete pPl; + + AcDbObjectId idNew; + Acad::ErrorStatus es = addToSpace(pApron, &idNew); + if (es != Acad::eOk) + { + delete pApron; + return errJson(kErrInternal, std::wstring(L"加入模型空间失败,err=") + std::to_wstring((int)es)); + } + touchEntity(pApron); + + nlohmann::json o; + o["width"] = dW; + o["inside_thickness"] = pApron->GetInsideThick(); + o["outside_thickness"] = pApron->GetOutSideThick(); + o["offset_from_wall"] = pApron->GetOffsetFromWall(); + + nlohmann::json body; + body["ok"] = true; + body["type"] = "apron"; + body["params"] = o; + pApron->close(); + body["handle"] = HandleOfId(idNew); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolAddApron, AddAecApronTool) + +class ToolUpdateApron : public mcp_Tool +{ +public: + std::string private_name() const override { return "update_aec_apron"; } + + std::string private_description() const override + { + return "改散水(AecDbXApron):散水宽/内边厚/外边厚/离墙偏移/顶标高,只传要改的字段;" + "给 points 可以换走向。"; + } + + 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" } } }, + "width": { "type": "number" }, + "inside_thickness": { "type": "number" }, "outside_thickness": { "type": "number" }, + "offset_from_wall": { "type": "number" }, "elevation": { "type": "number" }, + "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)); + + AecDbXApron* pApron = AecDbXApron::cast(pEnt); + if (pApron == NULL) + { + const std::string sCls = classNameOf(pEnt); + pEnt->close(); + return errJson(kErrWrongType, L"实体 " + utf8ToWstr(sCls) + L" 不是散水(AecDbXApron)"); + } + + if (hasKey(args, "points") && args["points"].is_array() && args["points"].size() >= 2) + { + AcDbPolyline* pPl = new AcDbPolyline((int)args["points"].size()); + int nIdx = 0; + for (size_t i = 0; i < args["points"].size(); ++i) + { + const nlohmann::json& pt = args["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) + { + pPl->setClosed(Adesk::kTrue); + pApron->SetBaseCurve(pPl); + } + delete pPl; + } + + if (hasKey(args, "width")) pApron->SetConstantWidth(numOr(args, "width", 0.0)); + if (hasKey(args, "inside_thickness")) pApron->SetInsideThick(numOr(args, "inside_thickness", 0.0)); + if (hasKey(args, "outside_thickness")) pApron->SetOutSideThick(numOr(args, "outside_thickness", 0.0)); + if (hasKey(args, "offset_from_wall")) pApron->SetOffsetFromWall(numOr(args, "offset_from_wall", 0.0)); + if (hasKey(args, "elevation")) pApron->GetSpecialtyData()->SetAt(KEY_BOMEL, numOr(args, "elevation", 0.0)); + if (hasKey(args, "color")) pApron->setColorIndex((Adesk::UInt16)intOr(args, "color", 256)); + pApron->ReCreateDraw3d(); + touchEntity(pApron); + + nlohmann::json o; + o["width"] = pApron->GetWidth(0); + o["inside_thickness"] = pApron->GetInsideThick(); + o["outside_thickness"] = pApron->GetOutSideThick(); + o["offset_from_wall"] = pApron->GetOffsetFromWall(); + + nlohmann::json body; + body["ok"] = true; + body["type"] = "apron"; + body["handle"] = sHandle; + body["params"] = o; + pEnt->close(); + return okJson(body); + } +}; +EXPORT_MCP_TOOL(ToolUpdateApron, UpdateAecApronTool) diff --git a/SourceCode/Code2026/cad_mcp_aec/cmakelists.txt b/SourceCode/Code2026/cad_mcp_aec/cmakelists.txt index c509c2b..5caa72d 100644 --- a/SourceCode/Code2026/cad_mcp_aec/cmakelists.txt +++ b/SourceCode/Code2026/cad_mcp_aec/cmakelists.txt @@ -10,6 +10,7 @@ set(SOURCES "aec_mcp_stair_tools.cpp" "aec_mcp_sfp_stair_tools.cpp" "aec_mcp_window_tools.cpp" + "aec_mcp_attachment_tools.cpp" "aec_mcp_roof_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 bc00953..73fd898 100644 --- a/SourceCode/Code2026/cad_mcp_aec/mcp_config.json +++ b/SourceCode/Code2026/cad_mcp_aec/mcp_config.json @@ -4749,6 +4749,632 @@ "dll_name": "cad_mcp_aec.dll", "factory_function": "UpdateAecWindowTool" } + }, + { + "name": "add_aec_balcony", + "description": "沿墙放置阳台(菜单 PL_FZYT,实体 AecDbBalcony):给墙 handle + 起止点(投影到墙中心线)+ 一个确认墙外侧方向的点,再给挑出宽度/栏杆高/板厚/梁尺寸等(缺省照抄 CFZYTDlg)。bottom_elevation 按\"相对墙底\"给。图层 LAY_BALCONY。", + "inputSchema": { + "type": "object", + "properties": { + "wall": { + "type": "string", + "description": "墙(AecDbXWall)的 handle" + }, + "start": { + "type": "array", + "items": { + "type": "number" + }, + "description": "阳台沿墙的起点 [x,y]" + }, + "end": { + "type": "array", + "items": { + "type": "number" + }, + "description": "阳台沿墙的终点 [x,y]" + }, + "side_point": { + "type": "array", + "items": { + "type": "number" + }, + "description": "墙外侧任意一点 [x,y],用来定挑出方向" + }, + "bottom_elevation": { + "type": "number", + "description": "底板底标高(相对墙底),缺省 160" + }, + "layer": { + "type": "string", + "description": "图层,缺省 LAY_BALCONY" + }, + "color": { + "type": "integer", + "description": "ACI 颜色号,256=ByLayer" + }, + "width": { + "type": "number", + "description": "阳台挑出宽度" + }, + "rail_height": { + "type": "number", + "description": "栏杆高" + }, + "slab_thickness": { + "type": "number", + "description": "底板厚" + }, + "girder_thickness": { + "type": "number", + "description": "阳台梁厚" + }, + "beam_height": { + "type": "number", + "description": "阳台梁高" + }, + "beam_width": { + "type": "number", + "description": "阳台梁宽" + }, + "rail_edge": { + "type": "integer", + "description": "无扶手的边(按对话框选项)" + }, + "add_opening": { + "type": "boolean", + "description": "阳台栏板上加门窗" + }, + "frame_vertical": { + "type": "number", + "description": "竖框高" + }, + "frame_horizontal": { + "type": "number", + "description": "横框宽" + }, + "window_height": { + "type": "number", + "description": "窗高" + }, + "material": { + "type": "string", + "description": "材质" + }, + "factory": { + "type": "string", + "description": "厂家" + }, + "no": { + "type": "string", + "description": "编号" + } + }, + "required": [ + "wall", + "start", + "end", + "side_point" + ] + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "AddAecBalconyTool" + } + }, + { + "name": "update_aec_balcony", + "description": "修改阳台(AecDbBalcony):只传要改的字段(挑出宽度/栏杆高/板厚/梁尺寸/栏板门窗/材质编号);给 wall+start+end+side_point 可以换位置和走向。bottom_elevation 这里按绝对标高给。", + "inputSchema": { + "type": "object", + "properties": { + "handle": { + "type": "string", + "description": "阳台实体 handle" + }, + "wall": { + "type": "string", + "description": "新的墙 handle(改位置时一起给)" + }, + "start": { + "type": "array", + "items": { + "type": "number" + } + }, + "end": { + "type": "array", + "items": { + "type": "number" + } + }, + "side_point": { + "type": "array", + "items": { + "type": "number" + } + }, + "bottom_elevation": { + "type": "number", + "description": "底板底标高(绝对)" + }, + "color": { + "type": "integer" + }, + "width": { + "type": "number", + "description": "阳台挑出宽度" + }, + "rail_height": { + "type": "number", + "description": "栏杆高" + }, + "slab_thickness": { + "type": "number", + "description": "底板厚" + }, + "girder_thickness": { + "type": "number", + "description": "阳台梁厚" + }, + "beam_height": { + "type": "number", + "description": "阳台梁高" + }, + "beam_width": { + "type": "number", + "description": "阳台梁宽" + }, + "rail_edge": { + "type": "integer", + "description": "无扶手的边(按对话框选项)" + }, + "add_opening": { + "type": "boolean", + "description": "阳台栏板上加门窗" + }, + "frame_vertical": { + "type": "number", + "description": "竖框高" + }, + "frame_horizontal": { + "type": "number", + "description": "横框宽" + }, + "window_height": { + "type": "number", + "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": "UpdateAecBalconyTool" + } + }, + { + "name": "add_aec_xstep", + "description": "沿墙放置台阶(菜单 PL_FZTJ,实体 AecDbXStep):给墙 handle + 起止点(投影到墙中心线)+ 墙外侧点,再给台阶宽/踏步/平台进深等(缺省照抄 CFZTJDlg)。bottom_elevation 相对墙底。图层 LAY_BALCONY。", + "inputSchema": { + "type": "object", + "properties": { + "wall": { + "type": "string", + "description": "墙 handle" + }, + "bottom_elevation": { + "type": "number", + "description": "底标高(相对墙底),缺省 0" + }, + "layer": { + "type": "string" + }, + "color": { + "type": "integer" + }, + "start": { + "type": "array", + "items": { + "type": "number" + }, + "description": "沿墙起点 [x,y]" + }, + "end": { + "type": "array", + "items": { + "type": "number" + }, + "description": "沿墙终点 [x,y]" + }, + "side_point": { + "type": "array", + "items": { + "type": "number" + }, + "description": "墙外侧任意一点,定朝外方向" + }, + "width": { + "type": "number", + "description": "台阶总宽,缺省 450" + }, + "steep_width": { + "type": "number", + "description": "踏步宽,缺省 300" + }, + "steep_height": { + "type": "number", + "description": "踏步高,缺省 150" + }, + "steep_count": { + "type": "integer", + "description": "踏步数,缺省 3" + }, + "base_width": { + "type": "number", + "description": "平台进深,缺省 2000" + }, + "base_align": { + "type": "integer", + "description": "0 平台左 / 1 平台右" + }, + "step_style": { + "type": "integer", + "description": "台阶方式" + }, + "struct_style": { + "type": "integer", + "description": "结构形式" + } + }, + "required": [ + "wall", + "start", + "end", + "side_point" + ] + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "AddAecXStepTool" + } + }, + { + "name": "update_aec_xstep", + "description": "改台阶(AecDbXStep):台阶宽/踏步/平台进深/样式,只传要改的字段;给 wall+start+end+side_point 可以换位置。bottom_elevation 这里按绝对标高。", + "inputSchema": { + "type": "object", + "properties": { + "handle": { + "type": "string" + }, + "wall": { + "type": "string" + }, + "bottom_elevation": { + "type": "number" + }, + "color": { + "type": "integer" + }, + "start": { + "type": "array", + "items": { + "type": "number" + }, + "description": "沿墙起点 [x,y]" + }, + "end": { + "type": "array", + "items": { + "type": "number" + }, + "description": "沿墙终点 [x,y]" + }, + "side_point": { + "type": "array", + "items": { + "type": "number" + }, + "description": "墙外侧任意一点,定朝外方向" + }, + "width": { + "type": "number", + "description": "台阶总宽,缺省 450" + }, + "steep_width": { + "type": "number", + "description": "踏步宽,缺省 300" + }, + "steep_height": { + "type": "number", + "description": "踏步高,缺省 150" + }, + "steep_count": { + "type": "integer", + "description": "踏步数,缺省 3" + }, + "base_width": { + "type": "number", + "description": "平台进深,缺省 2000" + }, + "base_align": { + "type": "integer", + "description": "0 平台左 / 1 平台右" + }, + "step_style": { + "type": "integer", + "description": "台阶方式" + }, + "struct_style": { + "type": "integer", + "description": "结构形式" + } + }, + "required": [ + "handle" + ] + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "UpdateAecXStepTool" + } + }, + { + "name": "add_aec_ascent", + "description": "放置坡道(菜单 PL_FZPD,实体 AecDbAscent):给起点和终点,再给水平投影长/坡高/坡宽/翻边/顶标高等(缺省照抄 CFZPDDlg)。图层 LAY_CSTAIR。", + "inputSchema": { + "type": "object", + "properties": { + "start": { + "type": "array", + "items": { + "type": "number" + } + }, + "end": { + "type": "array", + "items": { + "type": "number" + } + }, + "layer": { + "type": "string" + }, + "color": { + "type": "integer" + }, + "run_length": { + "type": "number", + "description": "水平投影长,缺省 2100" + }, + "rise": { + "type": "number", + "description": "坡高,缺省 450" + }, + "width": { + "type": "number", + "description": "坡宽,缺省 3000" + }, + "side_width": { + "type": "number", + "description": "翻边宽,缺省 300" + }, + "top_elevation": { + "type": "number", + "description": "顶标高,缺省 450" + }, + "align_left": { + "type": "boolean" + }, + "align_right": { + "type": "boolean" + }, + "nonslip": { + "type": "boolean", + "description": "是否有防滑条" + } + }, + "required": [ + "start", + "end" + ] + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "AddAecAscentTool" + } + }, + { + "name": "update_aec_ascent", + "description": "改坡道(AecDbAscent):只传要改的字段;给 start+end 可以换走向。", + "inputSchema": { + "type": "object", + "properties": { + "handle": { + "type": "string" + }, + "start": { + "type": "array", + "items": { + "type": "number" + } + }, + "end": { + "type": "array", + "items": { + "type": "number" + } + }, + "color": { + "type": "integer" + }, + "run_length": { + "type": "number", + "description": "水平投影长,缺省 2100" + }, + "rise": { + "type": "number", + "description": "坡高,缺省 450" + }, + "width": { + "type": "number", + "description": "坡宽,缺省 3000" + }, + "side_width": { + "type": "number", + "description": "翻边宽,缺省 300" + }, + "top_elevation": { + "type": "number", + "description": "顶标高,缺省 450" + }, + "align_left": { + "type": "boolean" + }, + "align_right": { + "type": "boolean" + }, + "nonslip": { + "type": "boolean", + "description": "是否有防滑条" + } + }, + "required": [ + "handle" + ] + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "UpdateAecAscentTool" + } + }, + { + "name": "add_aec_apron", + "description": "放置散水(菜单 PL_FZSS,实体 AecDbXApron):给走向 points(自动闭合)再给散水宽/内外边厚/离墙偏移/顶标高(缺省照抄 CFZSSDlg)。图层 LAY_BALCONY。", + "inputSchema": { + "type": "object", + "properties": { + "layer": { + "type": "string" + }, + "color": { + "type": "integer" + }, + "points": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + }, + "description": "散水走向 [[x,y],...](自动闭合)" + }, + "width": { + "type": "number", + "description": "散水宽" + }, + "inside_thickness": { + "type": "number", + "description": "内侧厚" + }, + "outside_thickness": { + "type": "number", + "description": "外侧厚" + }, + "offset_from_wall": { + "type": "number", + "description": "离墙偏移" + }, + "elevation": { + "type": "number", + "description": "顶标高" + } + }, + "required": [ + "points", + "width" + ] + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "AddAecApronTool" + } + }, + { + "name": "update_aec_apron", + "description": "改散水(AecDbXApron):只传要改的字段;给 points 可以换走向。", + "inputSchema": { + "type": "object", + "properties": { + "handle": { + "type": "string" + }, + "color": { + "type": "integer" + }, + "points": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + }, + "description": "散水走向 [[x,y],...](自动闭合)" + }, + "width": { + "type": "number", + "description": "散水宽" + }, + "inside_thickness": { + "type": "number", + "description": "内侧厚" + }, + "outside_thickness": { + "type": "number", + "description": "外侧厚" + }, + "offset_from_wall": { + "type": "number", + "description": "离墙偏移" + }, + "elevation": { + "type": "number", + "description": "顶标高" + } + }, + "required": [ + "handle" + ] + }, + "backend": { + "type": "c++_dll", + "dll_name": "cad_mcp_aec.dll", + "factory_function": "UpdateAecApronTool" + } } ] } diff --git a/cad-mcp-aec-item6-progress.md b/cad-mcp-aec-item6-progress.md index e104afc..98cf877 100644 --- a/cad-mcp-aec-item6-progress.md +++ b/cad-mcp-aec-item6-progress.md @@ -28,6 +28,10 @@ | 命令 | 4字名 | 实体 | 工具 | | --- | --- | --- | --- | | `PL_QTCC` | 墙体插窗(普通门窗) | `AecDbXOpening` | `add/update_aec_window` | +| `PL_FZYT` | 放置阳台 | `AecDbBalcony` | `add/update_aec_balcony` | +| `PL_FZTJ` | 放置台阶 | `AecDbXStep` | `add/update_aec_xstep` | +| `PL_FZPD` | 放置坡道 | `AecDbAscent` | `add/update_aec_ascent` | +| `PL_FZSS` | 放置散水 | `AecDbXApron` | `add/update_aec_apron` | | `PL_PTLT` | 直线钢梯 | `AecDbLineStair` | `add/update_aec_line_stair` | | `PL_FZHN` | 放置护栏 | `AecDbGuardBar` | `add/update_aec_guard_bar` | | `PL_QXHN` | 曲线护栏 | `AecDbGuardBar` | 同上(`curve` 给已有曲线 handle) | @@ -104,7 +108,13 @@ 老虎窗单独 `add_aec_dormer_window`(`roof` handle + 位置/尺寸);组合门窗做成 `group_aec_openings`(`openings`=已有门窗 handle 数组)。 -### C. 附属构件 6 个 +### C. 附属构件:4 个 ✅ 已做(阳台/台阶/坡道/散水),保温不做,沟渠待做 + +> `add/update_aec_balcony`、`add/update_aec_xstep`、`add/update_aec_ascent`、`add/update_aec_apron` +> 已完成并实测(见上表)。共用 `BuildWallPath`(把点投影到墙中心线再采样成多段线)。 +> 剩下 **`PL_LSJM` 沟渠**:断面由 `CHZGQDlg::GetSection()` 现算 region,要先把那段构造逻辑搬出来。 + +原始调查记录: | 命令 | 4字名 | 实体 | handler | 对话框 | 说明 | | --- | --- | --- | --- | --- | --- | @@ -162,7 +172,8 @@ 1. ~~楼梯族 8 个~~ ✅ 已完成 2. ~~普通门窗 `AecDbXOpening`~~ ✅ 已完成(`add/update_aec_window`); 组合门窗/带形窗/转角窗/老虎窗**挂起**。 -3. **附属构件 5 个**(保温不做):阳台/台阶/坡道/散水/沟渠,测试前要先造母实体(墙/屋顶)。 +3. **附属构件**:阳台/台阶/坡道/散水 ✅ 已完成;剩 **沟渠 PL_LSJM**(断面 region + 路径, + 要搬 `CHZGQDlg::GetSection` 的逻辑);保温按拍板不做。 4. **标注 8 个**:先摸 `AecDbEwPipeDim` 的创建接口。 5. **补齐已有楼梯的 update 精细字段**:钢梯/双跑/直线/圆弧目前只暴露了关键项, 按总原则要补到对话框字段级别。 diff --git a/cad-mcp-aec.md b/cad-mcp-aec.md index 73081e3..db1c0fd 100644 --- a/cad-mcp-aec.md +++ b/cad-mcp-aec.md @@ -19,8 +19,9 @@ SourceCode/Code2026/cad_mcp_aec/ ├── aec_mcp_roof_tools.cpp 屋顶:add/update_aec_roof(一个工具 + style,4 种样式,2 个) ├── aec_mcp_sfp_stair_tools.cpp 双分/双平行家族楼梯:add/update_aec_sfp_stair(一个工具 + kind,7 种,2 个) ├── aec_mcp_window_tools.cpp 普通门窗:add/update_aec_window(AecDbXOpening,2 个) +├── aec_mcp_attachment_tools.cpp 附属构件:阳台/台阶/坡道/散水(各 add+update,8 个) ├── aec_mcp_query.cpp query_aec_entities / get_aec_entity_detail(2 个) -└── mcp_config.json 运行期配置(69 个工具:26 个 cad_mcp_plugins + 41 个本插件 + 2 个 lisp_inline) +└── mcp_config.json 运行期配置(77 个工具:26 个 cad_mcp_plugins + 49 个本插件 + 2 个 lisp_inline) ``` 顶层 `cmakelists.txt` 里挂在 `cad_mcp_frame` 同一处: @@ -49,7 +50,7 @@ if (IS_ZWCAD OR CAD_SDK_VERSION GREATER_EQUAL 20) 插件的头文件里必须保持默认的 `dllimport`。`cad_mcp_plugins` 里定义了它们, 那是因为它不使用这些类;本插件用了,定义了就变成"导出自己没有的符号"。 -## 3. 工具清单(本插件 41 个;`mcp_config.json` 合计 69 个) +## 3. 工具清单(本插件 49 个;`mcp_config.json` 合计 77 个) 工具名和参数都按仓库既有工具的写法(`add_line` / `query_entities` / `get_entity_detail`): **动词_名词、点用 `[x,y]` 或 `[x,y,z]` 数组、颜色用 `color`(ACI,256=ByLayer)**。 @@ -84,6 +85,10 @@ if (IS_ZWCAD OR CAD_SDK_VERSION GREATER_EQUAL 20) | `add_aec_z_stair` / `update_aec_z_stair` | 建/改双跑楼梯(`AecDbZLineStair`,`PL_SPLT`) | `start`+`direction_point`、`steep_height`/`steep_width`/`steep_count1`/`steep_count2`、`total_width`/`run_width`/`well_width`、`rest_platform_width`/`platform_thickness`、`bar_height`/`bar_space`、`up_side_right`、`bottom_elevation`、`material`/`rail_material` | | `add_aec_line_seg_stair` / `update_aec_line_seg_stair` | 建/改直线楼梯(`AecDbLineSegStair`,`PL_ZXLT`,钢筋混凝土) | `start`+`direction_point`、`width`、`steep_height`/`steep_width`/`steep_count`、`side_width`/`side_thickness`、`with_rail`/`in_slab_3d`、`material`/`factory`/`no` | | `add_aec_arc_stair` / `update_aec_arc_stair` | 建/改圆弧楼梯(`AecDbArcStair`,`PL_YHLT`) | 中心线 `curve`(ARC handle) 或 `center`+`radius`+`start_angle`/`end_angle`;`width`、`steep_*`、`side_*`、`diameter`/`top_height`、`start_at_bottom`、`material`/`factory`/`no` | +| `add_aec_balcony` / `update_aec_balcony` | 建/改阳台(`AecDbBalcony`,`PL_FZYT`):墙 handle + 沿墙起止点 + 外侧点 + 挑出宽/栏杆高/板厚/梁尺寸 | `wall`/`start`/`end`/`side_point`、`width`/`rail_height`/`slab_thickness`/`girder_thickness`/`beam_*`/`bottom_elevation`/`material`/`factory`/`no` | +| `add_aec_xstep` / `update_aec_xstep` | 建/改台阶(`AecDbXStep`,`PL_FZTJ`):墙 handle + 沿墙起止点 + 外侧点 | `wall`/`start`/`end`/`side_point`、`width`/`steep_width`/`steep_height`/`steep_count`/`base_width`/`base_align`/`step_style`/`struct_style`/`bottom_elevation` | +| `add_aec_ascent` / `update_aec_ascent` | 建/改坡道(`AecDbAscent`,`PL_FZPD`):起点+终点 | `start`/`end`、`run_length`/`rise`/`width`/`side_width`/`top_elevation`/`align_left`/`align_right`/`nonslip` | +| `add_aec_apron` / `update_aec_apron` | 建/改散水(`AecDbXApron`,`PL_FZSS`):走向 `points` | `points`、`width`/`inside_thickness`/`outside_thickness`/`offset_from_wall`/`elevation` | | `add_aec_window` / `update_aec_window` | 建/改普通门窗(`AecDbXOpening`,`PL_QTCC` 等"插入门窗"):给墙 handle + 定位点(自动投影到墙中心线)+ 门窗块 + 宽高窗台高,内部扣墙的 2D 洞口并挂到墙的关联件 | `wall`、`position`、`block`/`block_3d`、`type`(window/door)、`width`/`height`/`sill_height`/`thickness`、`no`/`name`/`material`/`factory` | | `add_aec_sfp_stair` / `update_aec_sfp_stair` | 建/改双分·双平行家族楼梯(`SFPXStair` 一套数据,7 种实体 + `kind`):双平行/双分转角/双分三跑/交叉/剪刀/三角/矩形转角 | `kind`、`start`+`direction_point`、`height`/`steep_*`/`total_width`/`run_width`/`mid_run_width`/`well_width`/`rest_platform_width`/`platform_thickness`、扶手栏杆开关与高度、`material`/`rail_material`;update 另收边梯/中梯/剖切步数、内外边梁、上梯位置、踏步取齐、层显示、平台形状、加强筋、扶手/栏杆截面与伸出、双分系列的对称与 1~4 跑跑数跑宽 | | `add_aec_roof` / `update_aec_roof` | 建/改屋顶(`AecDbXRoof`,`PL_RYPD`/`PL_RZPD`/`PL_ZJPD`/`PL_JXPD`),一个工具 + `style` | `style`(slope/dual/cusp/mount)、`points`、`ridge_start`/`ridge_end`、`left_angle`/`right_angle`、`center`/`radius`/`side_count`、`location`、`roof_height`、`slope_angle`/`mount_height`/`mount_length`、`elevation`/`bottom_elevation`、`eaves_length`、`slab_thickness`、`material`/`factory` | @@ -152,7 +157,7 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命 ## 5. 端到端实测(AutoCAD 2020 / R230 Debug) 做法:把仓库里的 `mcp_config.json` 拷到部署目录,用 `/b` 脚本加载 `cad_mcp_frame.arx`, -然后用裸 socket 打 JSON-RPC。`tools/list` 现在返回 **69** 个工具(本插件 41 个), +然后用裸 socket 打 JSON-RPC。`tools/list` 现在返回 **77** 个工具(本插件 49 个), `%TEMP%\mcp_plugin_load.log` 里每个工厂都是 `[try ] ... create=... destroy=...` 成功。 **第一轮(只有 12 个工具时)的建/改实测**(仍然有效): @@ -171,11 +176,11 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命 | 类型不匹配 | ✅ `update_aec_wall` 传板的 handle → `-32004`「实体是 XSlab,不是 AecDbXWall」 | | 不存在的 handle | ✅ `-32002` | -导出表:41 个工厂(`aec_mcp_entity_tools.cpp` 18 + `aec_mcp_stair_tools.cpp` 10 + -`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_query.cpp` 2)+ `Destroy_*` + `g_mcpPluginApiVersion`, -与 `mcp_config.json` 里 `dll_name=cad_mcp_aec.dll` 的 41 条一一对应 -(少一条 backend 就不会被注册,见 §6)。 +导出表:49 个工厂(`aec_mcp_entity_tools.cpp` 18 + `aec_mcp_stair_tools.cpp` 10 + +`aec_mcp_shape_tools.cpp` 5 + `aec_mcp_attachment_tools.cpp` 8 + `aec_mcp_roof_tools.cpp` 2 + +`aec_mcp_sfp_stair_tools.cpp` 2 + `aec_mcp_window_tools.cpp` 2 + `aec_mcp_query.cpp` 2)+ +`Destroy_*` + `g_mcpPluginApiVersion`,与 `mcp_config.json` 里 `dll_name=cad_mcp_aec.dll` +的 49 条一一对应(少一条 backend 就不会被注册,见 §6)。 **后续各轮补的东西(都在 R230 Debug + pcf_1.dwg / 空图上实测过)**: @@ -215,8 +220,8 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命 `cad-mcp-frame.json`),重启 CAD。 注意:`set_debug_post_build()` 只拷构建产物,**配置文件不自动部署**,需要手工拷一次。 - 仓库里这份 `mcp_config.json` 是"26 个 `cad_mcp_plugins` + 41 个本插件 + 2 个 `lisp_inline`" - = 69 的合集,拷过去就等于全量替换。 + 仓库里这份 `mcp_config.json` 是"26 个 `cad_mcp_plugins` + 49 个本插件 + 2 个 `lisp_inline`" + = 77 的合集,拷过去就等于全量替换。 **每条工具都必须有 `backend`**(`{"type":"c++_dll","dll_name":"cad_mcp_aec.dll", "factory_function":"AddAecShapeTool"}`):只写 `name`/`description`/`inputSchema` @@ -234,9 +239,9 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命 - 造型里只有 7 种基本体能 `update_aec_shape`;曲线类(loft/extrude/revolve/sweep/cut/weir) 的截面/路径没存在实体里,要改只能删了重建。 - 没有事务/撤销包装:调用即改库。批量改图建议先 `query_aec_entities` 拿 handle,再逐条 `update`。 -- `mcp_config.json` 里的 69 个工具现在都能加载(`tools/list` = 69)。 - 其中 26 个属于 `cad_mcp_plugins`(含从 CadProject 合并过来的批注/编辑类工具), - 41 个属于本插件,2 个是 lisp_inline。 +- `mcp_config.json` 里的 77 个工具现在都能加载(`tools/list` = 77)。 + 其中 26 个属于 `cad_mcp_plugins`(含从 CadProject 合并过来的批量注/编辑类工具), + 49 个属于本插件,2 个是 lisp_inline。 移植那批工具时踩到两个本仓库差异(已修,见那次提交): 1. 上游 `dll` 的写库工具没有文档锁,在本仓库的运行方式下会返回 `cannot open target space for write`(`eLockViolation`)—— 补了 `dwg_annotate::DocLock`; @@ -293,11 +298,11 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命 |PL_DXCH|带形窗户|AecDbZLineXOpening|(未实现)|| |PL_ZJCH|转角窗户|AecDbZLineXOpening|(未实现)|| |PL_JLHC|加老虎窗|AecDbXDormerWindow|(未实现)|| -|PL_JBWC|加保温层|AecDbInsulation|(未实现)|| -|PL_FZYT|放置阳台|AecDbBalcony|(未实现)|| -|PL_FZTJ|放置台阶|AecDbXStep|(未实现)|| -|PL_FZPD|放置坡道|AecDbAscent|(未实现)|| -|PL_FZSS|放置散水|AecDbXApron|(未实现)|| +|PL_JBWC|加保温层|AecDbInsulation|(不做:作者拍板)|| +|PL_FZYT|放置阳台|AecDbBalcony|add_aec_balcony|update_aec_balcony| +|PL_FZTJ|放置台阶|AecDbXStep|add_aec_xstep|update_aec_xstep| +|PL_FZPD|放置坡道|AecDbAscent|add_aec_ascent|update_aec_ascent| +|PL_FZSS|放置散水|AecDbXApron|add_aec_apron|update_aec_apron| |PL_FZHN|放置护栏|AecDbGuardBar|add_aec_guard_bar|update_aec_guard_bar| |PL_QXHN|<-曲线护栏|AecDbGuardBar|add_aec_guard_bar(curve=已有曲线)|update_aec_guard_bar| |PL_JFZJ|添加方井|AecDbX3dPartEntity|add_aec_well|update_aec_well| @@ -839,3 +844,26 @@ pOpen->GetStandardDraw2d(win2d, false); // 2D 表示,用来扣墙 插 C1518(1500×1800、窗台 900)→ 返回 handle `316`,`params` 里 thickness 自动取 240、 bottom_elevation = 900;`update_aec_window` 改 1800×2100/窗台 600/编号 C1821/厂家 后回读正确; 再插一个门(1000×2100、窗台 0)→ handle `317`。 + +**第五批:附属构件(阳台 / 台阶 / 坡道 / 散水;保温层不做)** + +四个命令里,阳台/台阶都要先"沿墙取一段路径",命令用的是交互版 `GetPathOnWall` +(两点 + 选墙 + 点一下确认墙侧方向,内部还要把多段墙的基线拼起来)。工具里做了等价但更简单的版本: +`BuildWallPath(wall, start, end, side_point)` —— 把 start/end 投影到墙中心线,按距离采样成多段线 +(直墙就是两点),`vtDir` 取中点法向、朝向 `side_point` 那一侧。 + +| 命令 | 实体 | 关键点 | +| --- | --- | --- | +| `PL_FZYT` 阳台 | `AecDbBalcony` | `SetBalconyData` + `SetBaseCurve(path)` + `KEY_StartDir`;底标高 += 墙底、挑出宽 += 半墙厚(命令里的两步) | +| `PL_FZTJ` 台阶 | `AecDbXStep` | `SetXStepData` + `SetBaseCurve(path)`;底标高 += 墙底 | +| `PL_FZPD` 坡道 | `AecDbAscent` | 只要两点:`SetAscentData` + `SetBaseCurve(pt,pt)` | +| `PL_FZSS` 散水 | `AecDbXApron` | 命令用 jig 画闭合多段线,工具直接给 `points`;`SetSection(10,10,0)` 占位 + `SetConstantWidth/InsideThick/OutSideThick/OffsetFromWall` + `KEY_BOMEL` | +| `PL_JBWC` 加保温层 | `AecDbInsulation` | **不做**(作者拍板) | + +**实测**(R230 Debug,空图,先造一面 10000×3000 厚 240 的墙当母体): +台阶(沿墙 2000~4000、朝 −Y、4 级)→ handle `312`,bbox 2000~4000 × −2950~−50; +坡道(6000,0 → 6000,−3000)→ `319`;散水(沿墙外 500、宽 600)→ `31A`; +三者的 update(台阶 5 级/平台 2500、坡道防滑条+翻边 400、散水宽 800)都回读正确。 + +还没做:**沟渠 `PL_LSJM`**(`AecDbEwPipeBase`)—— 断面由 `CHZGQDlg::GetSection()` 从 +宽/高/坡度角/壁厚现算一个 region,再沿 jig 路径扫;要先把 `GetSection` 的构造逻辑搬出来。