docs: 第6项第一批(§8.9 楼梯/护栏)+ 剩余清单与待拍板项 #146
No files matched your search
@@ -76,7 +76,8 @@ void AecDbGuardBar::SetGuardBarData(const GuardBar& bar)
|
||||
m_mapSpecXData.SetAt(KEY_VERDRAW,bar.bVerDraw);
|
||||
|
||||
m_mapSpecXData.SetAt(KEY_MATERIAL,bar.m_sMaterial);
|
||||
m_mapSpecXData.SetAt(KEY_MATERIAL,bar.m_sNo);
|
||||
m_mapSpecXData.SetAt(KEY_FACTORY,bar.m_sFactory);
|
||||
m_mapSpecXData.SetAt(KEY_NO,bar.m_sNo); // 原来这里错写成 KEY_MATERIAL,编号把材质盖掉了
|
||||
}
|
||||
|
||||
bool AecDbGuardBar::GetGuardBarData(GuardBar& bar) const
|
||||
@@ -98,7 +99,12 @@ bool AecDbGuardBar::GetGuardBarData(GuardBar& bar) const
|
||||
m_mapSpecXData.GetAt(KEY_MATERIAL,sTemp);
|
||||
_tcscpy(bar.m_sMaterial,(LPCTSTR)sTemp);
|
||||
|
||||
m_mapSpecXData.GetAt(KEY_MATERIAL,sTemp);
|
||||
m_mapSpecXData.GetAt(KEY_FACTORY,sTemp);
|
||||
_tcscpy(bar.m_sFactory,(LPCTSTR)sTemp);
|
||||
|
||||
// 老数据把编号存在 KEY_MATERIAL 里(上面的 Set 写错了),读不到 KEY_NO 时退回老位置
|
||||
if (!m_mapSpecXData.GetAt(KEY_NO,sTemp))
|
||||
m_mapSpecXData.GetAt(KEY_MATERIAL,sTemp);
|
||||
_tcscpy(bar.m_sNo,(LPCTSTR)sTemp);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,600 @@
|
||||
// ============================================================================
|
||||
// aec_mcp_stair_tools.cpp
|
||||
// cad_mcp_aec 的楼梯 / 护栏工具(工作计划第 6 项)
|
||||
// * PL_PTLT 直线钢梯 -> AecDbLineStair(AecDbBaseStair 派生)
|
||||
// * PL_FZHN 放置护栏 / PL_QXHN 曲线护栏 -> AecDbGuardBar(AecDbEwPipeBase 派生)
|
||||
//
|
||||
// 两个命令的建模序列(Pool3dCmd/pool3dcmdCmd.cpp):
|
||||
// 建实体 -> setLayer(LAY_CSTAIR / LAY_GBAR) -> SetLineStairData / SetGuardBarData
|
||||
// -> SetSection(...) -> SetBaseCurve(&line / &polyline) -> KEY_2DSTYLE=0 -> 入库
|
||||
// 参数全部来自各自的对话框(CPTLTDlg / CFZHNDlg),缺省值照抄对话框构造函数,
|
||||
// 尺寸用图纸单位。
|
||||
// ============================================================================
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "KTCad.h"
|
||||
#include "aec_mcp_common.h"
|
||||
#include "mcp_plugin_api.h"
|
||||
|
||||
#include "AecDbLineStair.h"
|
||||
#include "AecDbGuardBar.h"
|
||||
#include "AecDbObjXDataMap.h"
|
||||
#include "CoreTools.h"
|
||||
#include "KTSetting.h"
|
||||
|
||||
using namespace aec_mcp;
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string HandleOfId(const AcDbObjectId& id)
|
||||
{
|
||||
if (id.isNull()) return std::string();
|
||||
AcDbObject* pObj = NULL;
|
||||
if (Acad::eOk != acdbOpenObject(pObj, id, AcDb::kForRead)) return std::string();
|
||||
const std::string s = handleOf(pObj);
|
||||
pObj->close();
|
||||
return s;
|
||||
}
|
||||
|
||||
nlohmann::json PointJson(const AcGePoint3d& pt)
|
||||
{
|
||||
nlohmann::json o;
|
||||
o["x"] = pt.x;
|
||||
o["y"] = pt.y;
|
||||
o["z"] = pt.z;
|
||||
return o;
|
||||
}
|
||||
|
||||
void CopyStr(TCHAR* pszDst, int nSize, const std::wstring& sSrc)
|
||||
{
|
||||
if (pszDst == NULL || nSize <= 0) return;
|
||||
_tcsncpy(pszDst, sSrc.c_str(), nSize - 1);
|
||||
pszDst[nSize - 1] = 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 护栏
|
||||
// GuardBar 的缺省值照抄 CFZHNDlg 构造函数
|
||||
void InitGuardBar(GuardBar& bar)
|
||||
{
|
||||
::memset(&bar, 0, sizeof(GuardBar));
|
||||
bar.dD = 40.0; // 管材直径
|
||||
bar.dt = 2.5; // 管材厚(命令里写死 2.5)
|
||||
bar.dBomEl = 0.0; // 底标高
|
||||
bar.dH1 = 650.0; // 底层横杆高
|
||||
bar.dH = 1080.0; // 顶部扶手高
|
||||
bar.dP = 1200.0; // 立柱间距
|
||||
bar.bNoBomLever = FALSE;
|
||||
bar.bIsRectLever = FALSE;
|
||||
bar.bVerDraw = FALSE;
|
||||
CopyStr(bar.m_sMaterial, 256, L"镜亮不锈钢型材");
|
||||
CopyStr(bar.m_sFactory, 256, L"厂家自制");
|
||||
CopyStr(bar.m_sNo, 256, L"HL-01");
|
||||
}
|
||||
|
||||
void GuardBarFromArgs(GuardBar& bar, const nlohmann::json& a, bool bMerge)
|
||||
{
|
||||
if (!bMerge) InitGuardBar(bar);
|
||||
if (hasKey(a, "diameter")) bar.dD = numOr(a, "diameter", bar.dD);
|
||||
if (hasKey(a, "bar_thickness")) bar.dt = numOr(a, "bar_thickness", bar.dt);
|
||||
if (hasKey(a, "bottom_elevation")) bar.dBomEl = numOr(a, "bottom_elevation", bar.dBomEl);
|
||||
if (hasKey(a, "top_height")) bar.dH = numOr(a, "top_height", bar.dH);
|
||||
if (hasKey(a, "first_height")) bar.dH1 = numOr(a, "first_height", bar.dH1);
|
||||
if (hasKey(a, "post_space")) bar.dP = numOr(a, "post_space", bar.dP);
|
||||
if (hasKey(a, "rect_post")) bar.bIsRectLever = intOr(a, "rect_post", 0) ? TRUE : FALSE;
|
||||
if (hasKey(a, "no_bottom_rail")) bar.bNoBomLever = intOr(a, "no_bottom_rail", 0) ? TRUE : FALSE;
|
||||
if (hasKey(a, "vertical_draw")) bar.bVerDraw = intOr(a, "vertical_draw", 0) ? TRUE : FALSE;
|
||||
if (hasKey(a, "material")) CopyStr(bar.m_sMaterial, 256, wstrOr(a, "material", L""));
|
||||
if (hasKey(a, "factory")) CopyStr(bar.m_sFactory, 256, wstrOr(a, "factory", L""));
|
||||
if (hasKey(a, "no")) CopyStr(bar.m_sNo, 256, wstrOr(a, "no", L""));
|
||||
}
|
||||
|
||||
nlohmann::json GuardBarToJson(const GuardBar& bar)
|
||||
{
|
||||
nlohmann::json o;
|
||||
o["diameter"] = bar.dD;
|
||||
o["bar_thickness"] = bar.dt;
|
||||
o["bottom_elevation"] = bar.dBomEl;
|
||||
o["top_height"] = bar.dH;
|
||||
o["first_height"] = bar.dH1;
|
||||
o["post_space"] = bar.dP;
|
||||
o["rect_post"] = (bar.bIsRectLever != FALSE);
|
||||
o["no_bottom_rail"] = (bar.bNoBomLever != FALSE);
|
||||
o["vertical_draw"] = (bar.bVerDraw != FALSE);
|
||||
o["material"] = acharToUtf8(bar.m_sMaterial);
|
||||
o["factory"] = acharToUtf8(bar.m_sFactory);
|
||||
o["no"] = acharToUtf8(bar.m_sNo);
|
||||
return o;
|
||||
}
|
||||
|
||||
// 二维点串 -> 多段线(护栏的基准曲线,elevation 固定 0,与命令一致)
|
||||
AcDbPolyline* PolylineOfPoints(const nlohmann::json& a, std::wstring& err)
|
||||
{
|
||||
if (!hasKey(a, "points") || !a["points"].is_array() || a["points"].size() < 2)
|
||||
{
|
||||
err = L"需要 points:[[x,y],...](至少 2 点)";
|
||||
return NULL;
|
||||
}
|
||||
AcDbPolyline* pPl = new AcDbPolyline((int)a["points"].size());
|
||||
int nIdx = 0;
|
||||
for (size_t i = 0; i < a["points"].size(); ++i)
|
||||
{
|
||||
const nlohmann::json& pt = a["points"][i];
|
||||
if (!pt.is_array() || pt.size() < 2) continue;
|
||||
pPl->addVertexAt(nIdx++, AcGePoint2d(pt[0].get<double>(), pt[1].get<double>()), 0.0, 0.0, 0.0);
|
||||
}
|
||||
if (nIdx < 2)
|
||||
{
|
||||
delete pPl;
|
||||
err = L"points 有效点少于 2 个";
|
||||
return NULL;
|
||||
}
|
||||
pPl->setElevation(0.0); // 命令里是"视图 elevation=0 时绘制",这里固定 0
|
||||
return pPl;
|
||||
}
|
||||
|
||||
// 已有曲线(圆弧/圆/多段线/样条)-> 多段线,供 PL_QXHN 那种"沿已有曲线"的用法
|
||||
AcDbPolyline* PolylineOfHandle(const std::wstring& sHandle, std::wstring& err)
|
||||
{
|
||||
AcDbEntity* pEnt = openByHandle(acharToUtf8(sHandle.c_str()), AcDb::kForRead);
|
||||
if (pEnt == NULL)
|
||||
{
|
||||
err = L"按 handle 打不开曲线:" + sHandle;
|
||||
return NULL;
|
||||
}
|
||||
AcDbCurve* pCrv = AcDbCurve::cast(pEnt);
|
||||
if (pCrv == NULL)
|
||||
{
|
||||
pEnt->close();
|
||||
err = L"curve 必须是曲线类实体(直线/圆弧/圆/多段线/样条)";
|
||||
return NULL;
|
||||
}
|
||||
AcDbPolyline* pPl = AcDbPolyline::cast(pEnt) ? (AcDbPolyline*)pCrv->clone()
|
||||
: CoreTools::MakePolyline(pCrv);
|
||||
pEnt->close();
|
||||
if (pPl == NULL)
|
||||
{
|
||||
err = L"曲线转多段线失败";
|
||||
return NULL;
|
||||
}
|
||||
pPl->setElevation(0.0);
|
||||
return pPl;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 直线钢梯
|
||||
// LineStair 的缺省值照抄 CPTLTDlg 构造函数
|
||||
void InitLineStair(LineStair& data)
|
||||
{
|
||||
::memset(&data, 0, sizeof(LineStair));
|
||||
InitGuardBar(data.bar);
|
||||
data.bar.dD = 30.0; // 钢梯的栏管直径缺省 30
|
||||
data.bar.dH = 1080.0;
|
||||
data.bar.dH1 = 650.0;
|
||||
data.bar.dP = 1200.0;
|
||||
data.bar.dt = 2.0;
|
||||
|
||||
data.dSteepH = 200.0; // 踏步高
|
||||
data.dSteept = 8.0; // 踏步厚
|
||||
data.dSteepW = 400.0; // 踏步宽
|
||||
data.dSideW = 200.0; // 梯梁宽
|
||||
data.dSidet = 40.0; // 梯梁厚
|
||||
data.dW = 1000.0; // 梯宽
|
||||
data.dBomEl = 0.0;
|
||||
data.dTopEl = 4000.0;
|
||||
CopyStr(data.m_sMaterial, 256, L"不锈钢");
|
||||
CopyStr(data.m_sFactory, 256, L"厂家自制");
|
||||
}
|
||||
|
||||
void LineStairFromArgs(LineStair& data, const nlohmann::json& a, bool bMerge)
|
||||
{
|
||||
if (!bMerge) InitLineStair(data);
|
||||
GuardBarFromArgs(data.bar, a, true);
|
||||
|
||||
if (hasKey(a, "width")) data.dW = numOr(a, "width", data.dW);
|
||||
if (hasKey(a, "steep_height")) data.dSteepH = numOr(a, "steep_height", data.dSteepH);
|
||||
if (hasKey(a, "steep_width")) data.dSteepW = numOr(a, "steep_width", data.dSteepW);
|
||||
if (hasKey(a, "steep_thickness")) data.dSteept = numOr(a, "steep_thickness", data.dSteept);
|
||||
if (hasKey(a, "side_width")) data.dSideW = numOr(a, "side_width", data.dSideW);
|
||||
if (hasKey(a, "side_thickness")) data.dSidet = numOr(a, "side_thickness", data.dSidet);
|
||||
if (hasKey(a, "bottom_elevation")) data.dBomEl = numOr(a, "bottom_elevation", data.dBomEl);
|
||||
if (hasKey(a, "top_elevation")) data.dTopEl = numOr(a, "top_elevation", data.dTopEl);
|
||||
if (hasKey(a, "with_rail")) data.bGuardBar = intOr(a, "with_rail", 0) ? TRUE : FALSE;
|
||||
if (hasKey(a, "material")) CopyStr(data.m_sMaterial, 256, wstrOr(a, "material", L""));
|
||||
if (hasKey(a, "factory")) CopyStr(data.m_sFactory, 256, wstrOr(a, "factory", L""));
|
||||
if (hasKey(a, "no")) CopyStr(data.m_sNo, 256, wstrOr(a, "no", L""));
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// add_aec_line_stair —— 直线钢梯(PL_PTLT)
|
||||
// ---------------------------------------------------------------------------
|
||||
class ToolAddLineStair : public mcp_Tool
|
||||
{
|
||||
public:
|
||||
std::string private_name() const override { return "add_aec_line_stair"; }
|
||||
|
||||
std::string private_description() const override
|
||||
{
|
||||
return "建直线钢梯(菜单 PL_PTLT 直线钢梯,实体 AecDbLineStair):"
|
||||
"给起点/终点平面位置 + 底/顶标高,再给梯宽、踏步、梯梁、栏管参数(都有缺省,照抄 CPTLTDlg)。"
|
||||
"尺寸用图纸单位;起点 z 取 bottom_elevation、终点 z 取 top_elevation。图层 LAY_CSTAIR。";
|
||||
}
|
||||
|
||||
nlohmann::json private_input_schema() const override
|
||||
{
|
||||
return nlohmann::json::parse(R"({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"start": { "type": "array", "items": { "type": "number" }, "description": "起点 [x,y](z 用 bottom_elevation)" },
|
||||
"end": { "type": "array", "items": { "type": "number" }, "description": "终点 [x,y](z 用 top_elevation)" },
|
||||
"bottom_elevation": { "type": "number", "description": "底标高,缺省 0" },
|
||||
"top_elevation": { "type": "number", "description": "顶标高,缺省 4000" },
|
||||
"width": { "type": "number", "description": "梯宽,缺省 1000" },
|
||||
"steep_height": { "type": "number", "description": "踏步高,缺省 200" },
|
||||
"steep_width": { "type": "number", "description": "踏步宽,缺省 400" },
|
||||
"steep_thickness": { "type": "number", "description": "踏步厚,缺省 8" },
|
||||
"side_width": { "type": "number", "description": "梯梁宽,缺省 200" },
|
||||
"side_thickness": { "type": "number", "description": "梯梁厚,缺省 40" },
|
||||
"diameter": { "type": "number", "description": "栏管直径(也是钢梯截面),缺省 30" },
|
||||
"top_height": { "type": "number", "description": "扶手高,缺省 1080" },
|
||||
"first_height": { "type": "number", "description": "底层横杆高,缺省 650" },
|
||||
"post_space": { "type": "number", "description": "立柱间距,缺省 1200" },
|
||||
"with_rail": { "type": "boolean", "description": "是否带护栏" },
|
||||
"material": { "type": "string", "description": "材质,缺省 不锈钢" },
|
||||
"factory": { "type": "string", "description": "厂家,缺省 厂家自制" },
|
||||
"no": { "type": "string", "description": "编号" },
|
||||
"layer": { "type": "string", "description": "图层,缺省 LAY_CSTAIR" },
|
||||
"color": { "type": "integer", "description": "ACI 颜色号,256=ByLayer" }
|
||||
},
|
||||
"required": [ "start", "end" ]
|
||||
})");
|
||||
}
|
||||
|
||||
nlohmann::json Execute(const nlohmann::json& args) override
|
||||
{
|
||||
if (workingDb() == NULL) return errJson(kErrNoDocument, L"没有活动图纸");
|
||||
DocLock lock;
|
||||
if (!lock.isLocked()) return errJson(kErrInternal, L"拿不到图纸写锁(有别的命令在跑?)");
|
||||
|
||||
AcGePoint3d ptS(0.0, 0.0, 0.0), ptE(0.0, 0.0, 0.0);
|
||||
if (!readPoint(args, "start", ptS) || !readPoint(args, "end", ptE))
|
||||
return errJson(kErrBadParam, L"需要 start / end([x,y] 或 [x,y,z])");
|
||||
if (ptS.distanceTo(ptE) < 1.0)
|
||||
return errJson(kErrBadParam, L"start 与 end 距离太近(命令里 <1 也拒绝)");
|
||||
|
||||
LineStair data;
|
||||
LineStairFromArgs(data, args, false);
|
||||
ptS.z = data.dBomEl;
|
||||
ptE.z = data.dTopEl;
|
||||
|
||||
AcDbLine ln(ptS, ptE);
|
||||
AecDbLineStair* pStair = new AecDbLineStair();
|
||||
std::wstring sLay = hasKey(args, "layer") ? wstrOr(args, "layer", L"") : L"";
|
||||
if (sLay.empty()) sLay = L"LAY_CSTAIR";
|
||||
AcDbObjectId idLay = KTSetting::InitLayer(sLay.c_str());
|
||||
if (!idLay.isNull()) pStair->setLayer(idLay);
|
||||
if (hasKey(args, "color")) pStair->setColorIndex((Adesk::UInt16)intOr(args, "color", 256));
|
||||
|
||||
// 顺序有讲究:SetBaseCurve() 内部会重算截面/清专业数据,所以必须放在
|
||||
// SetLineStairData 之前;命令里是反的(Data -> SetSection -> SetBaseCurve),
|
||||
// 结果材质/编号会被 SetBaseCurve 清掉。
|
||||
pStair->SetBaseCurve(&ln);
|
||||
pStair->SetLineStairData(data);
|
||||
pStair->GetSpecialtyData()->SetAt(KEY_2DSTYLE, 0);
|
||||
|
||||
AcDbObjectId idNew;
|
||||
Acad::ErrorStatus es = addToSpace(pStair, &idNew);
|
||||
if (es != Acad::eOk)
|
||||
{
|
||||
delete pStair;
|
||||
return errJson(kErrInternal, std::wstring(L"加入模型空间失败,err=") + std::to_wstring((int)es));
|
||||
}
|
||||
touchEntity(pStair);
|
||||
pStair->close();
|
||||
|
||||
nlohmann::json body;
|
||||
body["ok"] = true;
|
||||
body["type"] = "line_stair";
|
||||
body["handle"] = HandleOfId(idNew);
|
||||
body["start"] = PointJson(ptS);
|
||||
body["end"] = PointJson(ptE);
|
||||
return okJson(body);
|
||||
}
|
||||
};
|
||||
EXPORT_MCP_TOOL(ToolAddLineStair, AddAecLineStairTool)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// update_aec_line_stair —— 改直线钢梯
|
||||
// ---------------------------------------------------------------------------
|
||||
class ToolUpdateLineStair : public mcp_Tool
|
||||
{
|
||||
public:
|
||||
std::string private_name() const override { return "update_aec_line_stair"; }
|
||||
|
||||
std::string private_description() const override
|
||||
{
|
||||
return "改直线钢梯:起终点、梯宽/踏步/梯梁/栏管尺寸、材质编号,只传要改的字段。"
|
||||
"改尺寸会重建几何;不传 start/end 就保持原来的走向。";
|
||||
}
|
||||
|
||||
nlohmann::json private_input_schema() const override
|
||||
{
|
||||
return nlohmann::json::parse(R"({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"handle": { "type": "string", "description": "钢梯实体 handle" },
|
||||
"start": { "type": "array", "items": { "type": "number" }, "description": "新起点 [x,y]" },
|
||||
"end": { "type": "array", "items": { "type": "number" }, "description": "新终点 [x,y]" },
|
||||
"bottom_elevation": { "type": "number" }, "top_elevation": { "type": "number" },
|
||||
"width": { "type": "number" }, "steep_height": { "type": "number" },
|
||||
"steep_width": { "type": "number" }, "steep_thickness": { "type": "number" },
|
||||
"side_width": { "type": "number" }, "side_thickness": { "type": "number" },
|
||||
"diameter": { "type": "number" }, "top_height": { "type": "number" },
|
||||
"first_height": { "type": "number" }, "post_space": { "type": "number" },
|
||||
"with_rail": { "type": "boolean" },
|
||||
"material": { "type": "string" }, "factory": { "type": "string" }, "no": { "type": "string" },
|
||||
"color": { "type": "integer" }
|
||||
},
|
||||
"required": [ "handle" ]
|
||||
})");
|
||||
}
|
||||
|
||||
nlohmann::json Execute(const nlohmann::json& args) override
|
||||
{
|
||||
if (workingDb() == NULL) return errJson(kErrNoDocument, L"没有活动图纸");
|
||||
DocLock lock;
|
||||
if (!lock.isLocked()) return errJson(kErrInternal, L"拿不到图纸写锁(有别的命令在跑?)");
|
||||
|
||||
if (!hasKey(args, "handle")) return errJson(kErrBadParam, L"缺少 handle");
|
||||
const std::string sHandle = args["handle"].get<std::string>();
|
||||
AcDbEntity* pEnt = openByHandle(sHandle, AcDb::kForWrite);
|
||||
if (pEnt == NULL) return errJson(kErrNotFound, L"按 handle 打不开实体:" + utf8ToWstr(sHandle));
|
||||
|
||||
AecDbLineStair* pStair = AecDbLineStair::cast(pEnt);
|
||||
if (pStair == NULL)
|
||||
{
|
||||
const std::string sCls = classNameOf(pEnt);
|
||||
pEnt->close();
|
||||
return errJson(kErrWrongType, L"实体 " + utf8ToWstr(sCls) + L" 不是直线钢梯(AecDbLineStair)");
|
||||
}
|
||||
|
||||
LineStair data;
|
||||
::memset(&data, 0, sizeof(LineStair));
|
||||
pStair->GetLineStairData(data);
|
||||
|
||||
AcGePoint3d ptS(0.0, 0.0, 0.0), ptE(0.0, 0.0, 0.0);
|
||||
AcDbCurve* pCrv = AcDbCurve::cast(pEnt);
|
||||
bool bHasCurve = (pCrv != NULL && pCrv->getStartPoint(ptS) == Acad::eOk &&
|
||||
pCrv->getEndPoint(ptE) == Acad::eOk);
|
||||
|
||||
LineStairFromArgs(data, args, true);
|
||||
if (readPoint(args, "start", ptS)) bHasCurve = bHasCurve || true;
|
||||
if (readPoint(args, "end", ptE)) bHasCurve = bHasCurve || true;
|
||||
ptS.z = data.dBomEl;
|
||||
ptE.z = data.dTopEl;
|
||||
|
||||
if (bHasCurve && ptS.distanceTo(ptE) > 1.0)
|
||||
{
|
||||
AcDbLine ln(ptS, ptE);
|
||||
pStair->SetBaseCurve(&ln);
|
||||
}
|
||||
|
||||
pStair->SetLineStairData(data); // 必须在 SetBaseCurve 之后(它会清专业数据)
|
||||
if (hasKey(args, "color")) pStair->setColorIndex((Adesk::UInt16)intOr(args, "color", 256));
|
||||
pStair->ReCreateDraw3d();
|
||||
touchEntity(pStair);
|
||||
pStair->close();
|
||||
|
||||
nlohmann::json body;
|
||||
body["ok"] = true;
|
||||
body["type"] = "line_stair";
|
||||
body["handle"] = sHandle;
|
||||
body["start"] = PointJson(ptS);
|
||||
body["end"] = PointJson(ptE);
|
||||
// 注意:材质/厂家/编号在 LineStair 自己的成员里,不在 bar 里
|
||||
// (GetLineStairData 只回填 bar 的直径/间距那些)
|
||||
body["params"] = GuardBarToJson(data.bar);
|
||||
body["params"]["material"] = acharToUtf8(data.m_sMaterial);
|
||||
body["params"]["factory"] = acharToUtf8(data.m_sFactory);
|
||||
body["params"]["no"] = acharToUtf8(data.m_sNo);
|
||||
body["params"]["width"] = data.dW;
|
||||
body["params"]["steep_height"] = data.dSteepH;
|
||||
body["params"]["steep_width"] = data.dSteepW;
|
||||
body["params"]["steep_thickness"] = data.dSteept;
|
||||
body["params"]["side_width"] = data.dSideW;
|
||||
body["params"]["side_thickness"] = data.dSidet;
|
||||
return okJson(body);
|
||||
}
|
||||
};
|
||||
EXPORT_MCP_TOOL(ToolUpdateLineStair, UpdateAecLineStairTool)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// add_aec_guard_bar —— 护栏(PL_FZHN 直接绘制 / PL_QXHN 沿已有曲线)
|
||||
// ---------------------------------------------------------------------------
|
||||
class ToolAddGuardBar : public mcp_Tool
|
||||
{
|
||||
public:
|
||||
std::string private_name() const override { return "add_aec_guard_bar"; }
|
||||
|
||||
std::string private_description() const override
|
||||
{
|
||||
return "建护栏(菜单 PL_FZHN 放置护栏 / PL_QXHN 曲线护栏,实体 AecDbGuardBar):"
|
||||
"轮廓给 points([[x,y],...],自己画的)或 curve(已有曲线实体的 handle,圆弧/圆/多段线都行)。"
|
||||
"栏管直径/扶手高/立柱间距等缺省照抄 CFZHNDlg。护栏按视图 elevation=0 绘制,基准曲线标高固定 0,"
|
||||
"实际高度由 bottom_elevation 决定。图层 LAY_GBAR。";
|
||||
}
|
||||
|
||||
nlohmann::json private_input_schema() const override
|
||||
{
|
||||
return nlohmann::json::parse(R"({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"points": { "type": "array", "items": { "type": "array", "items": { "type": "number" } },
|
||||
"description": "护栏走向 [[x,y],...](至少 2 点)" },
|
||||
"curve": { "type": "string", "description": "或者给一条已有曲线的 handle(PL_QXHN 的做法)" },
|
||||
"diameter": { "type": "number", "description": "栏管直径,缺省 40" },
|
||||
"bar_thickness": { "type": "number", "description": "栏管壁厚,缺省 2.5" },
|
||||
"bottom_elevation": { "type": "number", "description": "底标高,缺省 0" },
|
||||
"top_height": { "type": "number", "description": "扶手高,缺省 1080" },
|
||||
"first_height": { "type": "number", "description": "底层横杆高,缺省 650" },
|
||||
"post_space": { "type": "number", "description": "立柱间距,缺省 1200" },
|
||||
"rect_post": { "type": "boolean", "description": "立柱是否方管" },
|
||||
"no_bottom_rail": { "type": "boolean", "description": "是否没有底部栏杆" },
|
||||
"vertical_draw": { "type": "boolean", "description": "是否竖向出图" },
|
||||
"material": { "type": "string", "description": "材质,缺省 镜亮不锈钢型材" },
|
||||
"factory": { "type": "string", "description": "厂家,缺省 厂家自制" },
|
||||
"no": { "type": "string", "description": "编号,缺省 HL-01" },
|
||||
"layer": { "type": "string", "description": "图层,缺省 LAY_GBAR" },
|
||||
"color": { "type": "integer", "description": "ACI 颜色号,256=ByLayer" }
|
||||
}
|
||||
})");
|
||||
}
|
||||
|
||||
nlohmann::json Execute(const nlohmann::json& args) override
|
||||
{
|
||||
if (workingDb() == NULL) return errJson(kErrNoDocument, L"没有活动图纸");
|
||||
DocLock lock;
|
||||
if (!lock.isLocked()) return errJson(kErrInternal, L"拿不到图纸写锁(有别的命令在跑?)");
|
||||
|
||||
std::wstring err;
|
||||
AcDbPolyline* pPl = NULL;
|
||||
if (hasKey(args, "curve"))
|
||||
pPl = PolylineOfHandle(wstrOr(args, "curve", L""), err);
|
||||
else
|
||||
pPl = PolylineOfPoints(args, err);
|
||||
if (pPl == NULL) return errJson(kErrBadParam, err);
|
||||
|
||||
GuardBar bar;
|
||||
GuardBarFromArgs(bar, args, false);
|
||||
|
||||
AecDbGuardBar* pBar = new AecDbGuardBar();
|
||||
std::wstring sLay = hasKey(args, "layer") ? wstrOr(args, "layer", L"") : L"";
|
||||
if (sLay.empty()) sLay = L"LAY_GBAR";
|
||||
AcDbObjectId idLay = KTSetting::InitLayer(sLay.c_str());
|
||||
if (!idLay.isNull()) pBar->setLayer(idLay);
|
||||
|
||||
// 命令里:方管立柱 SetSection(dD, dD, 0),其它 SetSection(dD, 0)
|
||||
if (bar.bIsRectLever)
|
||||
pBar->SetSection(bar.dD, bar.dD, 0.0);
|
||||
else
|
||||
pBar->SetSection(bar.dD, 0.0);
|
||||
pBar->SetBaseCurve(pPl);
|
||||
pBar->SetGuardBarData(bar);
|
||||
pBar->GetSpecialtyData()->SetAt(KEY_2DSTYLE, 0);
|
||||
if (hasKey(args, "color")) pBar->setColorIndex((Adesk::UInt16)intOr(args, "color", 256));
|
||||
|
||||
delete pPl; // SetBaseCurve 会自己 clone
|
||||
|
||||
AcDbObjectId idNew;
|
||||
Acad::ErrorStatus es = addToSpace(pBar, &idNew);
|
||||
if (es != Acad::eOk)
|
||||
{
|
||||
delete pBar;
|
||||
return errJson(kErrInternal, std::wstring(L"加入模型空间失败,err=") + std::to_wstring((int)es));
|
||||
}
|
||||
touchEntity(pBar);
|
||||
pBar->close();
|
||||
|
||||
nlohmann::json body;
|
||||
body["ok"] = true;
|
||||
body["type"] = "guard_bar";
|
||||
body["handle"] = HandleOfId(idNew);
|
||||
body["params"] = GuardBarToJson(bar);
|
||||
return okJson(body);
|
||||
}
|
||||
};
|
||||
EXPORT_MCP_TOOL(ToolAddGuardBar, AddAecGuardBarTool)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// update_aec_guard_bar —— 改护栏
|
||||
// ---------------------------------------------------------------------------
|
||||
class ToolUpdateGuardBar : public mcp_Tool
|
||||
{
|
||||
public:
|
||||
std::string private_name() const override { return "update_aec_guard_bar"; }
|
||||
|
||||
std::string private_description() const override
|
||||
{
|
||||
return "改护栏:栏管直径/高度/立柱间距/材质编号,只传要改的字段;给 points 或 curve 可以换走向。";
|
||||
}
|
||||
|
||||
nlohmann::json private_input_schema() const override
|
||||
{
|
||||
return nlohmann::json::parse(R"({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"handle": { "type": "string", "description": "护栏实体 handle" },
|
||||
"points": { "type": "array", "items": { "type": "array", "items": { "type": "number" } },
|
||||
"description": "新的护栏走向(可选)" },
|
||||
"curve": { "type": "string", "description": "或者给一条新曲线的 handle(可选)" },
|
||||
"diameter": { "type": "number" }, "bar_thickness": { "type": "number" },
|
||||
"bottom_elevation": { "type": "number" }, "top_height": { "type": "number" },
|
||||
"first_height": { "type": "number" }, "post_space": { "type": "number" },
|
||||
"rect_post": { "type": "boolean" }, "no_bottom_rail": { "type": "boolean" },
|
||||
"vertical_draw": { "type": "boolean" },
|
||||
"material": { "type": "string" }, "factory": { "type": "string" }, "no": { "type": "string" },
|
||||
"color": { "type": "integer" }
|
||||
},
|
||||
"required": [ "handle" ]
|
||||
})");
|
||||
}
|
||||
|
||||
nlohmann::json Execute(const nlohmann::json& args) override
|
||||
{
|
||||
if (workingDb() == NULL) return errJson(kErrNoDocument, L"没有活动图纸");
|
||||
DocLock lock;
|
||||
if (!lock.isLocked()) return errJson(kErrInternal, L"拿不到图纸写锁(有别的命令在跑?)");
|
||||
|
||||
if (!hasKey(args, "handle")) return errJson(kErrBadParam, L"缺少 handle");
|
||||
const std::string sHandle = args["handle"].get<std::string>();
|
||||
AcDbEntity* pEnt = openByHandle(sHandle, AcDb::kForWrite);
|
||||
if (pEnt == NULL) return errJson(kErrNotFound, L"按 handle 打不开实体:" + utf8ToWstr(sHandle));
|
||||
|
||||
AecDbGuardBar* pBar = AecDbGuardBar::cast(pEnt);
|
||||
if (pBar == NULL)
|
||||
{
|
||||
const std::string sCls = classNameOf(pEnt);
|
||||
pEnt->close();
|
||||
return errJson(kErrWrongType, L"实体 " + utf8ToWstr(sCls) + L" 不是护栏(AecDbGuardBar)");
|
||||
}
|
||||
|
||||
GuardBar bar;
|
||||
::memset(&bar, 0, sizeof(GuardBar));
|
||||
if (!pBar->GetGuardBarData(bar)) InitGuardBar(bar);
|
||||
GuardBarFromArgs(bar, args, true);
|
||||
|
||||
std::wstring err;
|
||||
AcDbPolyline* pPl = NULL;
|
||||
if (hasKey(args, "curve"))
|
||||
pPl = PolylineOfHandle(wstrOr(args, "curve", L""), err);
|
||||
else if (hasKey(args, "points"))
|
||||
pPl = PolylineOfPoints(args, err);
|
||||
if (!err.empty())
|
||||
{
|
||||
pEnt->close();
|
||||
return errJson(kErrBadParam, err);
|
||||
}
|
||||
if (pPl != NULL)
|
||||
{
|
||||
pBar->SetBaseCurve(pPl);
|
||||
delete pPl;
|
||||
}
|
||||
|
||||
if (bar.bIsRectLever)
|
||||
pBar->SetSection(bar.dD, bar.dD, 0.0);
|
||||
else
|
||||
pBar->SetSection(bar.dD, 0.0);
|
||||
pBar->SetGuardBarData(bar);
|
||||
if (hasKey(args, "color")) pBar->setColorIndex((Adesk::UInt16)intOr(args, "color", 256));
|
||||
pBar->ReCreateDraw3d();
|
||||
touchEntity(pBar);
|
||||
pBar->close();
|
||||
|
||||
nlohmann::json body;
|
||||
body["ok"] = true;
|
||||
body["type"] = "guard_bar";
|
||||
body["handle"] = sHandle;
|
||||
body["params"] = GuardBarToJson(bar);
|
||||
return okJson(body);
|
||||
}
|
||||
};
|
||||
EXPORT_MCP_TOOL(ToolUpdateGuardBar, UpdateAecGuardBarTool)
|
||||
@@ -7,6 +7,7 @@ set(SOURCES
|
||||
"aec_mcp_common.cpp"
|
||||
"aec_mcp_entity_tools.cpp"
|
||||
"aec_mcp_shape_tools.cpp"
|
||||
"aec_mcp_stair_tools.cpp"
|
||||
"aec_mcp_query.cpp"
|
||||
"StdAfx.cpp"
|
||||
)
|
||||
|
||||
@@ -3023,6 +3023,404 @@
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "DeleteAecShapeTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "add_aec_line_stair",
|
||||
"description": "建直线钢梯(菜单 PL_PTLT 直线钢梯,实体 AecDbLineStair):给起点/终点平面位置 + 底/顶标高,再给梯宽、踏步、梯梁、栏管参数(都有缺省,照抄 CPTLDlg)。尺寸用图纸单位;起点 z 取 bottom_elevation、终点 z 取 top_elevation。图层 LAY_CSTAIR。",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"start": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number"
|
||||
},
|
||||
"description": "起点 [x,y](z 用 bottom_elevation)"
|
||||
},
|
||||
"end": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number"
|
||||
},
|
||||
"description": "终点 [x,y](z 用 top_elevation)"
|
||||
},
|
||||
"bottom_elevation": {
|
||||
"type": "number",
|
||||
"description": "底标高"
|
||||
},
|
||||
"top_elevation": {
|
||||
"type": "number",
|
||||
"description": "顶标高,缺省 4000"
|
||||
},
|
||||
"width": {
|
||||
"type": "number",
|
||||
"description": "梯宽,缺省 1000"
|
||||
},
|
||||
"steep_height": {
|
||||
"type": "number",
|
||||
"description": "踏步高,缺省 200"
|
||||
},
|
||||
"steep_width": {
|
||||
"type": "number",
|
||||
"description": "踏步宽,缺省 400"
|
||||
},
|
||||
"steep_thickness": {
|
||||
"type": "number",
|
||||
"description": "踏步厚,缺省 8"
|
||||
},
|
||||
"side_width": {
|
||||
"type": "number",
|
||||
"description": "梯梁宽,缺省 200"
|
||||
},
|
||||
"side_thickness": {
|
||||
"type": "number",
|
||||
"description": "梯梁厚,缺省 40"
|
||||
},
|
||||
"with_rail": {
|
||||
"type": "boolean",
|
||||
"description": "是否带护栏"
|
||||
},
|
||||
"layer": {
|
||||
"type": "string",
|
||||
"description": "图层,缺省 LAY_CSTAIR"
|
||||
},
|
||||
"color": {
|
||||
"type": "integer",
|
||||
"description": "ACI 颜色号,256=ByLayer"
|
||||
},
|
||||
"diameter": {
|
||||
"type": "number",
|
||||
"description": "栏管直径"
|
||||
},
|
||||
"bar_thickness": {
|
||||
"type": "number",
|
||||
"description": "栏管壁厚"
|
||||
},
|
||||
"top_height": {
|
||||
"type": "number",
|
||||
"description": "扶手高"
|
||||
},
|
||||
"first_height": {
|
||||
"type": "number",
|
||||
"description": "底层横杆高"
|
||||
},
|
||||
"post_space": {
|
||||
"type": "number",
|
||||
"description": "立柱间距"
|
||||
},
|
||||
"rect_post": {
|
||||
"type": "boolean",
|
||||
"description": "立柱是否方管"
|
||||
},
|
||||
"no_bottom_rail": {
|
||||
"type": "boolean",
|
||||
"description": "是否没有底部栏杆"
|
||||
},
|
||||
"vertical_draw": {
|
||||
"type": "boolean",
|
||||
"description": "是否竖向出图"
|
||||
},
|
||||
"material": {
|
||||
"type": "string",
|
||||
"description": "材质"
|
||||
},
|
||||
"factory": {
|
||||
"type": "string",
|
||||
"description": "厂家"
|
||||
},
|
||||
"no": {
|
||||
"type": "string",
|
||||
"description": "编号"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"start",
|
||||
"end"
|
||||
]
|
||||
},
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "AddAecLineStairTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "update_aec_line_stair",
|
||||
"description": "改直线钢梯:起终点、梯宽/踏步/梯梁/栏管尺寸、材质编号,只传要改的字段。改尺寸会重建几何;不传 start/end 就保持原来的走向。",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"handle": {
|
||||
"type": "string",
|
||||
"description": "钢梯实体 handle"
|
||||
},
|
||||
"start": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"end": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"bottom_elevation": {
|
||||
"type": "number",
|
||||
"description": "底标高"
|
||||
},
|
||||
"top_elevation": {
|
||||
"type": "number"
|
||||
},
|
||||
"width": {
|
||||
"type": "number"
|
||||
},
|
||||
"steep_height": {
|
||||
"type": "number"
|
||||
},
|
||||
"steep_width": {
|
||||
"type": "number"
|
||||
},
|
||||
"steep_thickness": {
|
||||
"type": "number"
|
||||
},
|
||||
"side_width": {
|
||||
"type": "number"
|
||||
},
|
||||
"side_thickness": {
|
||||
"type": "number"
|
||||
},
|
||||
"with_rail": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"color": {
|
||||
"type": "integer"
|
||||
},
|
||||
"diameter": {
|
||||
"type": "number",
|
||||
"description": "栏管直径"
|
||||
},
|
||||
"bar_thickness": {
|
||||
"type": "number",
|
||||
"description": "栏管壁厚"
|
||||
},
|
||||
"top_height": {
|
||||
"type": "number",
|
||||
"description": "扶手高"
|
||||
},
|
||||
"first_height": {
|
||||
"type": "number",
|
||||
"description": "底层横杆高"
|
||||
},
|
||||
"post_space": {
|
||||
"type": "number",
|
||||
"description": "立柱间距"
|
||||
},
|
||||
"rect_post": {
|
||||
"type": "boolean",
|
||||
"description": "立柱是否方管"
|
||||
},
|
||||
"no_bottom_rail": {
|
||||
"type": "boolean",
|
||||
"description": "是否没有底部栏杆"
|
||||
},
|
||||
"vertical_draw": {
|
||||
"type": "boolean",
|
||||
"description": "是否竖向出图"
|
||||
},
|
||||
"material": {
|
||||
"type": "string",
|
||||
"description": "材质"
|
||||
},
|
||||
"factory": {
|
||||
"type": "string",
|
||||
"description": "厂家"
|
||||
},
|
||||
"no": {
|
||||
"type": "string",
|
||||
"description": "编号"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"handle"
|
||||
]
|
||||
},
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "UpdateAecLineStairTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "add_aec_guard_bar",
|
||||
"description": "建护栏(菜单 PL_FZHN 放置护栏 / PL_QXHN 曲线护栏,实体 AecDbGuardBar):轮廓给 points(自己画)或 curve(已有曲线 handle,圆弧/圆/多段线都行)。栏管直径/扶手高/立柱间距等缺省照抄 CFZHNDlg。护栏按视图 elevation=0 绘制,基准曲线标高固定 0,实际高度由 bottom_elevation 决定。图层 LAY_GBAR。",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"points": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"description": "护栏走向 [[x,y],...](至少 2 点)"
|
||||
},
|
||||
"curve": {
|
||||
"type": "string",
|
||||
"description": "或者给一条已有曲线的 handle(PL_QXHN 的做法)"
|
||||
},
|
||||
"layer": {
|
||||
"type": "string",
|
||||
"description": "图层,缺省 LAY_GBAR"
|
||||
},
|
||||
"color": {
|
||||
"type": "integer",
|
||||
"description": "ACI 颜色号,256=ByLayer"
|
||||
},
|
||||
"diameter": {
|
||||
"type": "number",
|
||||
"description": "栏管直径"
|
||||
},
|
||||
"bar_thickness": {
|
||||
"type": "number",
|
||||
"description": "栏管壁厚"
|
||||
},
|
||||
"bottom_elevation": {
|
||||
"type": "number",
|
||||
"description": "底标高"
|
||||
},
|
||||
"top_height": {
|
||||
"type": "number",
|
||||
"description": "扶手高"
|
||||
},
|
||||
"first_height": {
|
||||
"type": "number",
|
||||
"description": "底层横杆高"
|
||||
},
|
||||
"post_space": {
|
||||
"type": "number",
|
||||
"description": "立柱间距"
|
||||
},
|
||||
"rect_post": {
|
||||
"type": "boolean",
|
||||
"description": "立柱是否方管"
|
||||
},
|
||||
"no_bottom_rail": {
|
||||
"type": "boolean",
|
||||
"description": "是否没有底部栏杆"
|
||||
},
|
||||
"vertical_draw": {
|
||||
"type": "boolean",
|
||||
"description": "是否竖向出图"
|
||||
},
|
||||
"material": {
|
||||
"type": "string",
|
||||
"description": "材质"
|
||||
},
|
||||
"factory": {
|
||||
"type": "string",
|
||||
"description": "厂家"
|
||||
},
|
||||
"no": {
|
||||
"type": "string",
|
||||
"description": "编号"
|
||||
}
|
||||
}
|
||||
},
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "AddAecGuardBarTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "update_aec_guard_bar",
|
||||
"description": "改护栏:栏管直径/高度/立柱间距/材质编号,只传要改的字段;给 points 或 curve 可以换走向。",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"handle": {
|
||||
"type": "string",
|
||||
"description": "护栏实体 handle"
|
||||
},
|
||||
"points": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"description": "新的护栏走向(可选)"
|
||||
},
|
||||
"curve": {
|
||||
"type": "string",
|
||||
"description": "或者给一条新曲线的 handle(可选)"
|
||||
},
|
||||
"color": {
|
||||
"type": "integer"
|
||||
},
|
||||
"diameter": {
|
||||
"type": "number",
|
||||
"description": "栏管直径"
|
||||
},
|
||||
"bar_thickness": {
|
||||
"type": "number",
|
||||
"description": "栏管壁厚"
|
||||
},
|
||||
"bottom_elevation": {
|
||||
"type": "number",
|
||||
"description": "底标高"
|
||||
},
|
||||
"top_height": {
|
||||
"type": "number",
|
||||
"description": "扶手高"
|
||||
},
|
||||
"first_height": {
|
||||
"type": "number",
|
||||
"description": "底层横杆高"
|
||||
},
|
||||
"post_space": {
|
||||
"type": "number",
|
||||
"description": "立柱间距"
|
||||
},
|
||||
"rect_post": {
|
||||
"type": "boolean",
|
||||
"description": "立柱是否方管"
|
||||
},
|
||||
"no_bottom_rail": {
|
||||
"type": "boolean",
|
||||
"description": "是否没有底部栏杆"
|
||||
},
|
||||
"vertical_draw": {
|
||||
"type": "boolean",
|
||||
"description": "是否竖向出图"
|
||||
},
|
||||
"material": {
|
||||
"type": "string",
|
||||
"description": "材质"
|
||||
},
|
||||
"factory": {
|
||||
"type": "string",
|
||||
"description": "厂家"
|
||||
},
|
||||
"no": {
|
||||
"type": "string",
|
||||
"description": "编号"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"handle"
|
||||
]
|
||||
},
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "UpdateAecGuardBarTool"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
# 第 6 项进度(cad_mcp_aec 插件扩充-3)
|
||||
|
||||
> 来源:`工作计划.md` 第 6 项,清单从 `cad-mcp-aec.md` §8 摘的。
|
||||
> 规则:需要拍板的先记在这里、跳过,等确认后再做。
|
||||
|
||||
## 已完成(第一批,PR 见提交说明)
|
||||
|
||||
| 命令 | 实体 | 工具 | 状态 |
|
||||
| --- | --- | --- | --- |
|
||||
| `PL_PTLT` 直线钢梯 | `AecDbLineStair` | `add/update_aec_line_stair` | ✅ 实测通过 |
|
||||
| `PL_FZHN` 放置护栏 | `AecDbGuardBar` | `add/update_aec_guard_bar` | ✅ 实测通过 |
|
||||
| `PL_QXHN` 曲线护栏 | `AecDbGuardBar` | 同上,`curve` 参数给已有曲线 handle | ✅ 实测通过 |
|
||||
|
||||
顺手修的上游 bug:`AecDbGuardBar::Set/GetGuardBarData` 把编号写进 `KEY_MATERIAL`
|
||||
(材质永远显示编号、厂家从来没存),已在 CoreLibrary 修好并兼容旧图。
|
||||
详见 `cad-mcp-aec.md` §8.9。
|
||||
|
||||
## 剩余(按类分组,附我查到的入口,方便下一轮直接做)
|
||||
|
||||
### A. 楼梯族(10 个独立类,都是 `AecDbBaseStair` 派生)
|
||||
|
||||
| 命令 | 4字名 | 类 | 入口/参数来源 |
|
||||
| --- | --- | --- | --- |
|
||||
| `PL_SPLT` | 双跑楼梯 | `AecDbZLineStair` | `ZLineStair` 结构体(nZs/nKind/dSteepH/dSteepW/nSteeps1/nSteeps2/dStairTW/dStairSW…) |
|
||||
| `PL_SFPX` | 双平行梯 | `AecDbParaLlelStair` | `SFPXData` 结构体 |
|
||||
| `PL_SFZJ` | 双分转角 | `AecDbCornerStair` | 同上族 |
|
||||
| `PL_SFSP` | 双分三跑 | `AecDbDoubleMulStair` | 同上族 |
|
||||
| `PL_JCLT` | 交叉楼梯 | `AecDbScissorsStair` | 同上族 |
|
||||
| `PL_JDLT` | 剪刀楼梯 | `AecDbCrossStair` | 同上族 |
|
||||
| `PL_SJLT` | 三角楼梯 | `AecDbTriangleStair` | 同上族 |
|
||||
| `PL_JXZJ` | 矩形转角 | `AecDbRectCornerStair` | 同上族 |
|
||||
| `PL_DDLT` | 多段楼梯 | `AecDbMRPLineStair` | 同上族 |
|
||||
| `PL_YHLT` | 圆弧楼梯 | `AecDbArcStair` | 同上族(基准曲线是圆弧) |
|
||||
| `PL_ZXLT` | 直线楼梯 | `AecDbLineSegStair` | 同上族(与钢梯类似,钢筋混凝土版) |
|
||||
|
||||
### B. 屋顶(`AecDbXRoof` 一个类,4 种 style)
|
||||
|
||||
| 命令 | 4字名 | style | 关键设置函数 |
|
||||
| --- | --- | --- | --- |
|
||||
| `PL_RYPD` | 任意屋顶 | `kSlopeRoof` | `InitEqualSlope(pPl, dElevMove, ang)` + `SetSlabThick` + `SetEavesLen` |
|
||||
| `PL_RZPD` | 人字屋顶 | `kDualRoof` | 左右坡角/屋脊标高,`CalAngle(...)` |
|
||||
| `PL_ZJPD` | 攒尖屋顶 | `kCuspRoof` | `SetRadius`/`SetRoofHeight`/`SetSideNum`/`SetEavesLen`/`SetElevation` |
|
||||
| `PL_JXPD` | 矩形屋顶 | `kMountRoof` | `SetMountHeight`/`SetSlopeAngle2`/`SetRoofType`… |
|
||||
|
||||
都需要一条封闭多段线当轮廓(工具里用 `points` 生成,和 `add_aec_slab` 一样)。
|
||||
|
||||
### C. 门窗(5)
|
||||
|
||||
| 命令 | 4字名 | 类 |
|
||||
| --- | --- | --- |
|
||||
| `PL_ZHMC` | 组合门窗 | `AecDbGroupXOpening` / `AecDbXOpening` |
|
||||
| `PL_DXCH` | 带形窗户 | `AecDbZLineXOpening` |
|
||||
| `PL_ZJCH` | 转角窗户 | `AecDbZLineXOpening` |
|
||||
| `PL_JLHC` | 加老虎窗 | `AecDbXDormerWindow` |
|
||||
|
||||
### D. 附属构件(6)
|
||||
|
||||
`PL_JBWC` 加保温层 `AecDbInsulation` / `PL_FZYT` 放置阳台 `AecDbBalcony` /
|
||||
`PL_FZTJ` 放置台阶 `AecDbXStep` / `PL_FZPD` 放置坡道 `AecDbAscent` /
|
||||
`PL_FZSS` 放置散水 `AecDbXApron` / `PL_LSJM` 绘制沟渠 `AecDbEwPipeBase`
|
||||
|
||||
### E. 标注(8,都是 `AecDbEwPipeDim`)
|
||||
|
||||
`PL_XHBZ` 序号标注 / `PL_XHPB` 序号批标 / `PL_DKBZ` 洞口标注 / `PL_TGBZ` 套管标注 /
|
||||
`PL_YHBZ` 翼环标注 / `PL_FMBZ` 阀门标注 / `IS_BZFM` 标注阀门 / `IS_GZGJ` 标注管件。
|
||||
共同模式:选实体(管/洞/套管/管件)→ 取数据 → 生成标注实体,样式参数来自各自对话框。
|
||||
|
||||
## 需要你拍板的(先跳过)
|
||||
|
||||
1. **楼梯族的参数粒度**:`ZLineStair`/`SFPXData` 这些结构体有 30~50 个字段,
|
||||
全暴露成工具参数会很难用;建议只暴露关键尺寸(台阶高宽、梯段宽、踏步数、梯井宽…),
|
||||
其余用对话框缺省。要不要这样做?
|
||||
2. **楼梯族做几个**:11 个类每个都要单独读对话框 + 测。建议先做常用的
|
||||
(双跑 `SPLT`、直线 `ZXLT`、圆弧 `YHLT`),其余按需再说。做全还是挑?
|
||||
3. **屋顶是 4 个工具还是 1 个**:我倾向 `add_aec_roof` 一个工具 + `style`(slope/dual/cusp/mount),
|
||||
与"同族一个工具"的既有取向一致。认可吗?
|
||||
4. **标注类要不要做**:这 8 个是"提取数据 + 生成标注",与建实体不是一类;
|
||||
而且要定标注文字样式/图层/箭头等。优先级比实体低?
|
||||
5. **门窗/附属构件**里有没有你暂时不用的?先做哪个?
|
||||
|
||||
## 下一步(不需要拍板就能继续的)
|
||||
|
||||
- 屋顶 4 种(如果第 3 条认可为"一个工具 + style")
|
||||
- 楼梯族里挑 2~3 个(如果第 2 条认可"先做常用的")
|
||||
- 门窗:先读对话框再定
|
||||
+54
-13
@@ -15,8 +15,9 @@ SourceCode/Code2026/cad_mcp_aec/
|
||||
├── aec_mcp_common.h/.cpp 参数解析、handle<->ObjectId、文档锁、结果信封、entityBBox
|
||||
├── aec_mcp_entity_tools.cpp 管道/墙/板/柱/梁/爬梯/管件/洞口·套管/井 的 add+update(18 个)
|
||||
├── aec_mcp_shape_tools.cpp 造型:add_aec_multipart + add/list/update/delete_aec_shape(5 个)
|
||||
├── aec_mcp_stair_tools.cpp 楼梯/护栏:add+update_aec_line_stair、add+update_aec_guard_bar(4 个)
|
||||
├── aec_mcp_query.cpp query_aec_entities / get_aec_entity_detail(2 个)
|
||||
└── mcp_config.json 运行期配置(53 个工具:26 个 cad_mcp_plugins + 25 个本插件 + 2 个 lisp_inline)
|
||||
└── mcp_config.json 运行期配置(57 个工具:26 个 cad_mcp_plugins + 29 个本插件 + 2 个 lisp_inline)
|
||||
```
|
||||
|
||||
顶层 `cmakelists.txt` 里挂在 `cad_mcp_frame` 同一处:
|
||||
@@ -45,7 +46,7 @@ if (IS_ZWCAD OR CAD_SDK_VERSION GREATER_EQUAL 20)
|
||||
插件的头文件里必须保持默认的 `dllimport`。`cad_mcp_plugins` 里定义了它们,
|
||||
那是因为它不使用这些类;本插件用了,定义了就变成"导出自己没有的符号"。
|
||||
|
||||
## 3. 工具清单(本插件 25 个;`mcp_config.json` 合计 53 个)
|
||||
## 3. 工具清单(本插件 29 个;`mcp_config.json` 合计 57 个)
|
||||
|
||||
工具名和参数都按仓库既有工具的写法(`add_line` / `query_entities` / `get_entity_detail`):
|
||||
**动词_名词、点用 `[x,y]` 或 `[x,y,z]` 数组、颜色用 `color`(ACI,256=ByLayer)**。
|
||||
@@ -71,6 +72,13 @@ if (IS_ZWCAD OR CAD_SDK_VERSION GREATER_EQUAL 20)
|
||||
| `add_aec_opening` / `update_aec_opening` | 开洞**或做套管**(`AecDbX3dPartEntity`)。母体可以是板/墙,也可以是**任意 `AecDbBDPipeBase`**(异形构筑物/柱/梁/堰) | `host`、`shape`(circle/rect/polygon)、`position`、`direction`、`diameter` 或 `width`/`height`、异形洞 `points`、`depth`;阵列 `rows`/`columns`/`spacing_x`/`spacing_y`;穿管 `source`(管线 handle);套管 `casing=true` + `casing_length`/`casing_wall_thickness`/`casing_extend*`/`material`/`pipe_type`/`ring_od`/`ring_count` |
|
||||
| `add_aec_well` / `update_aec_well` | 池底板上加/改井(方井/圆井/方圆井/异形偏心井/集水坑) | `host`、`shape`(rect/circle/rect_circle/polygon/sump)、`position`、`length`/`width`/`diameter`、异形井用 `top_points`/`bottom_points`、`height`、`wall_thickness`、`slab_thickness`/`angle_deg`(集水坑) |
|
||||
|
||||
**楼梯 / 护栏(4 个,见 §8.9)**
|
||||
|
||||
| 工具 | 作用 | 关键参数 |
|
||||
| --- | --- | --- |
|
||||
| `add_aec_line_stair` / `update_aec_line_stair` | 建/改直线钢梯(`AecDbLineStair`,`PL_PTLT`) | `start`/`end`、`bottom_elevation`/`top_elevation`、`width`、`steep_height`/`steep_width`/`steep_thickness`、`side_width`/`side_thickness`、`diameter`/`top_height`/`first_height`/`post_space`、`material`/`factory`/`no` |
|
||||
| `add_aec_guard_bar` / `update_aec_guard_bar` | 建/改护栏(`AecDbGuardBar`,`PL_FZHN` 画 / `PL_QXHN` 沿已有曲线) | `points` 或 `curve`(曲线 handle)、`diameter`/`bar_thickness`、`top_height`/`first_height`/`post_space`、`bottom_elevation`、`rect_post`/`no_bottom_rail`/`vertical_draw`、`material`/`factory`/`no` |
|
||||
|
||||
**造型 / 异形构筑物(5 个,见 §8.7)**
|
||||
|
||||
| 工具 | 作用 | 关键参数 |
|
||||
@@ -122,7 +130,7 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
|
||||
## 5. 端到端实测(AutoCAD 2020 / R230 Debug)
|
||||
|
||||
做法:把仓库里的 `mcp_config.json` 拷到部署目录,用 `/b` 脚本加载 `cad_mcp_frame.arx`,
|
||||
然后用裸 socket 打 JSON-RPC。`tools/list` 现在返回 **53** 个工具(本插件 25 个),
|
||||
然后用裸 socket 打 JSON-RPC。`tools/list` 现在返回 **57** 个工具(本插件 29 个),
|
||||
`%TEMP%\mcp_plugin_load.log` 里每个工厂都是 `[try ] ... create=... destroy=...` 成功。
|
||||
|
||||
**第一轮(只有 12 个工具时)的建/改实测**(仍然有效):
|
||||
@@ -141,9 +149,10 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
|
||||
| 类型不匹配 | ✅ `update_aec_wall` 传板的 handle → `-32004`「实体是 XSlab,不是 AecDbXWall」 |
|
||||
| 不存在的 handle | ✅ `-32002` |
|
||||
|
||||
导出表:25 个工厂(`aec_mcp_entity_tools.cpp` 18 + `aec_mcp_shape_tools.cpp` 5 +
|
||||
`aec_mcp_query.cpp` 2)+ `Destroy_*` + `g_mcpPluginApiVersion`,与 `mcp_config.json` 里
|
||||
`dll_name=cad_mcp_aec.dll` 的 25 条一一对应(少一条 backend 就不会被注册,见 §6)。
|
||||
导出表:29 个工厂(`aec_mcp_entity_tools.cpp` 18 + `aec_mcp_shape_tools.cpp` 5 +
|
||||
`aec_mcp_stair_tools.cpp` 4 + `aec_mcp_query.cpp` 2)+ `Destroy_*` + `g_mcpPluginApiVersion`,
|
||||
与 `mcp_config.json` 里 `dll_name=cad_mcp_aec.dll` 的 29 条一一对应
|
||||
(少一条 backend 就不会被注册,见 §6)。
|
||||
|
||||
**后续各轮补的东西(都在 R230 Debug + pcf_1.dwg / 空图上实测过)**:
|
||||
|
||||
@@ -183,8 +192,8 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
|
||||
`cad-mcp-frame.json`),重启 CAD。
|
||||
|
||||
注意:`set_debug_post_build()` 只拷构建产物,**配置文件不自动部署**,需要手工拷一次。
|
||||
仓库里这份 `mcp_config.json` 是"26 个 `cad_mcp_plugins` + 25 个本插件 + 2 个 `lisp_inline`"
|
||||
= 53 的合集,拷过去就等于全量替换。
|
||||
仓库里这份 `mcp_config.json` 是"26 个 `cad_mcp_plugins` + 29 个本插件 + 2 个 `lisp_inline`"
|
||||
= 57 的合集,拷过去就等于全量替换。
|
||||
|
||||
**每条工具都必须有 `backend`**(`{"type":"c++_dll","dll_name":"cad_mcp_aec.dll",
|
||||
"factory_function":"AddAecShapeTool"}`):只写 `name`/`description`/`inputSchema`
|
||||
@@ -202,9 +211,9 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
|
||||
- 造型里只有 7 种基本体能 `update_aec_shape`;曲线类(loft/extrude/revolve/sweep/cut/weir)
|
||||
的截面/路径没存在实体里,要改只能删了重建。
|
||||
- 没有事务/撤销包装:调用即改库。批量改图建议先 `query_aec_entities` 拿 handle,再逐条 `update`。
|
||||
- `mcp_config.json` 里的 53 个工具现在都能加载(`tools/list` = 53)。
|
||||
- `mcp_config.json` 里的 57 个工具现在都能加载(`tools/list` = 57)。
|
||||
其中 26 个属于 `cad_mcp_plugins`(含从 CadProject 合并过来的批注/编辑类工具),
|
||||
25 个属于本插件,2 个是 lisp_inline。
|
||||
29 个属于本插件,2 个是 lisp_inline。
|
||||
移植那批工具时踩到两个本仓库差异(已修,见那次提交):
|
||||
1. 上游 `dll` 的写库工具没有文档锁,在本仓库的运行方式下会返回
|
||||
`cannot open target space for write`(`eLockViolation`)—— 补了 `dwg_annotate::DocLock`;
|
||||
@@ -239,7 +248,7 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
|
||||
|PL_QTDY|墙体倒圆|AecDbX3dPartEntity|(内部构件,不单独建)||
|
||||
|PL_ZXPT|直段爬梯|AecDbClimbStair|add_aec_climb_stair|update_aec_climb_stair|
|
||||
|PL_YHZT|圆护爬梯|AecDbClimbStair|add_aec_climb_stair|update_aec_climb_stair|
|
||||
|PL_PTLT|直线钢梯|AecDbLineStair|(内部构件,不单独建)||
|
||||
|PL_PTLT|直线钢梯|AecDbLineStair|add_aec_line_stair|update_aec_line_stair|
|
||||
|PL_SPLT|双跑楼梯|AecDbZLineStair|(未实现)||
|
||||
|PL_SFPX|双平行梯|AecDbParaLlelStair|(未实现)||
|
||||
|PL_SFZJ|双分转角|AecDbCornerStair|(未实现)||
|
||||
@@ -265,8 +274,8 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
|
||||
|PL_FZTJ|放置台阶|AecDbXStep|(未实现)||
|
||||
|PL_FZPD|放置坡道|AecDbAscent|(未实现)||
|
||||
|PL_FZSS|放置散水|AecDbXApron|(未实现)||
|
||||
|PL_FZHN|放置护栏|AecDbGuardBar|(内部构件,不单独建)||
|
||||
|PL_QXHN|<-曲线护栏|AecDbGuardBar|(内部构件,不单独建)||
|
||||
|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|
|
||||
|PL_JYZJ|添加圆井|AecDbX3dPartEntity|add_aec_well|update_aec_well|
|
||||
|PL_JFYJ|加方圆井|AecDbX3dPartEntity|add_aec_well|update_aec_well|
|
||||
@@ -697,3 +706,35 @@ add_aec_opening(host=310, shape=polygon, position=[0,-500,500],
|
||||
"以中心两方向减"那段),所以法向不是 Z 也能用。前提是 `vtZ` 要么平行、要么垂直于 XY 平面
|
||||
(`AcGePlane::kXYPlane.isParallelTo / isPerpendicularTo` 两个分支),斜法向会直接返回 false。
|
||||
本次实测的是侧面(法向 +Y)多边形洞,能建、洞心正确;斜面上的异形洞没测。
|
||||
|
||||
### 8.9 楼梯 / 护栏(第 6 项,第一批)
|
||||
|
||||
**PL_PTLT 直线钢梯 → `AecDbLineStair`(`AecDbBaseStair` 派生)**
|
||||
|
||||
命令序列(`pool3dcmdCmd.cpp` `PL_PTLTCmdFnc`):两点 + `CPTLTDlg` → `SetLineStairData(data)`
|
||||
→ `SetSection(bar.dD, 0.0)` → `SetBaseCurve(&line)` → `KEY_2DSTYLE=0` → 图层 `LAY_CSTAIR`。
|
||||
工具 `add/update_aec_line_stair` 的参数就照 `CPTLTDlg` 的字段(缺省值抄构造函数:
|
||||
梯宽 1000、踏步 200/400/8、梯梁 200/40、栏管 30/1080/650/1200、钢梯顶标高 4000)。
|
||||
|
||||
**PL_FZHN 放置护栏 / PL_QXHN 曲线护栏 → `AecDbGuardBar`**
|
||||
|
||||
两者是同一个实体,区别只是基准曲线哪来:`FZHN` 自己画(jig 出来的多段线),`QXHN` 选已有曲线。
|
||||
工具里 `points` = 自己画,`curve` = 给已有曲线 handle(内部 `CoreTools::MakePolyline` 转多段线)。
|
||||
序列:`SetSection(dD[, dD], 0)` → `SetBaseCurve` → `SetGuardBarData` → `KEY_2DSTYLE=0` → `LAY_GBAR`。
|
||||
|
||||
**三个坑**:
|
||||
|
||||
1. **`SetBaseCurve()` 会清专业数据**。命令里的顺序是 `SetLineStairData` → `SetSection` →
|
||||
`SetBaseCurve`,结果刚写进去的 材质/厂家/编号 被最后一步清掉(UI 里也是一样)。
|
||||
工具改成 `SetBaseCurve` → `SetLineStairData`,数据才留得住。
|
||||
2. **`AecDbGuardBar::SetGuardBarData` 把编号写进了 `KEY_MATERIAL`**(`SetAt(KEY_MATERIAL, m_sNo)`),
|
||||
`GetGuardBarData` 又从 `KEY_MATERIAL` 读两遍、厂家从来没存过 —— 护栏的"材质"永远显示编号。
|
||||
已在 CoreLibrary 修好(写 KEY_MATERIAL/KEY_FACTORY/KEY_NO,读时若没有 KEY_NO 退回老位置,
|
||||
兼容旧图)。
|
||||
3. 钢梯的 `GetLineStairData` 只回填 `bar` 的直径/间距,**材质/厂家/编号在 `LineStair` 自己的成员里**,
|
||||
组装返回 JSON 时别从 `bar` 取。
|
||||
|
||||
**实测**(R230 Debug,空图):钢梯 (0,0)→(4000,0) 建完 bbox x −208~4015、z 0~4015;
|
||||
改 `width=1200/top_height=1100` 后材质 `不锈钢`、编号 `LT-01` 都还在。
|
||||
护栏 points 2 点建完 bbox 含 40 的管半径;改 `diameter=50` 后 material/no/factory 正确回读;
|
||||
`curve` 走一条 3 点多段线也能建(handle `31B`)。
|
||||
Reference in new issue
Block a user