用户给了 E:\桌面\test_pipe.dwg:一条 MCP 建的长管 291、一条 PL_DHGD 手画的短管 31C。 新增调试工具 dump_aec_xdata(handle),吐 AecDbObjXDataMap::List() 的全部 key/value。 注意管线派生自 AecDbCurveBase 而不是 AecDbEntityBase,取专业数据要两边都 cast。 对比:MCP 建的 12 个字段,手画的 70 个。缺的 59 个分五类: 1) 管线自身参数(PIPE_D/PIPE_TDN/TOD/Ratio/KEY_RadRatio/MATERIALFT/KEY_NO/InsThick/ PIDD/DrawDir/EApp/Single/BWeldDot/FLGF/Gasket/IFD/IFD2/IFL/IFL2) -> AecDbEwPipe::SetPipeParam(PipeParam*),命令 PL_wpipedlg 走 TDbPipeJig 也是它。 2) 图纸级参数(PipeMaxDia/PipeMinDia/PerElbowDia/Trade/Project/Unit/Ratio...) -> FillInInitXDataMap:把 KT_PIPEINIT 整份拷到实体。 3) 图层/线型/颜色(CentLay/SingLay/OutDlay/COLOR/PIPE_LINELAYER*/PIPE_LINETYPE*) -> AecDbEwPipe::SetLayerByXDataMap(),按 PIPE_SYS 查系统图层。 4) 常量(RRADFLG=1/PIPCMD/Z2DRAW/IFL3/UnitNo)-> TDbPipeLine::FillConfigXDataMap 里写死。 5) 管子规格(ODNo/STDNO/SHTNO、PIPE_OD=57、PIPE_Thick=3.5)-> 查 sys\Plumbing.db 的管子规格表。 另有出图线宽字段和水暖关联 &FOR&WEIR&(不需要)。 本次补了 1~4,字段数 12 -> 80(手画 70)。踩的坑: - GetPipeParam() 返回 new 出来的指针,用完要 delete; - PipeParam 的 szSys/szMertial/szLevel 是 TCHAR[255],只能用 _tcscpy_s 赋值。 仍缺(下一步):管子规格查库(OD/壁厚/STDNO/SHTNO/ODNo)和几个出图线宽字段。
556 lines
18 KiB
C++
556 lines
18 KiB
C++
// ============================================================================
|
||
// aec_mcp_query.cpp
|
||
// cad_mcp_aec 的"读"工具
|
||
// list_aec_entities : 按类型列出本插件支持的 Envi3D 实体(handle/layer/bbox/关键参数)
|
||
// get_aec_entity : 按 handle 取单个实体的详细参数
|
||
//
|
||
// 返回统一分页信封:{ total, returned, offset, items:[...] },实体 ID 用 handle。
|
||
// ============================================================================
|
||
|
||
#include "StdAfx.h"
|
||
#include "KTCad.h"
|
||
#include "aec_mcp_common.h"
|
||
#include "mcp_plugin_api.h"
|
||
|
||
#include "AecDbEwPipe.h"
|
||
#include "AecDbEntityBase.h"
|
||
#include "AecDbCurveBase.h"
|
||
#include "KTModelLayoutXData.h"
|
||
#include "AecDbWall.h"
|
||
#include "AecDbSlab.h"
|
||
#include "AecDbColumn.h"
|
||
#include "AecDbBeam.h"
|
||
#include "AecDbClimbStair.h"
|
||
#include "AecDbEwFitting.h"
|
||
#include "AecDbX3dPartEntity.h"
|
||
#include "AecDbMultiPartEntity.h"
|
||
#include "AecDbObjXDataMap.h"
|
||
|
||
using namespace aec_mcp;
|
||
|
||
namespace
|
||
{
|
||
|
||
const char* kTypePipe = "pipe";
|
||
const char* kTypeWall = "wall";
|
||
const char* kTypeSlab = "slab";
|
||
const char* kTypeColumn = "column";
|
||
const char* kTypeBeam = "beam";
|
||
const char* kTypeClimb = "climb_stair";
|
||
const char* kTypeFitting = "fitting";
|
||
const char* kTypeOpening = "opening";
|
||
const char* kTypeMultiPart = "multipart"; // 异形构筑物(PL_YXGZ)
|
||
|
||
// 实体 -> 五个受支持类型之一;不是这几类返回空串
|
||
std::string supportedTypeOf(AcDbEntity* pEnt)
|
||
{
|
||
if (pEnt == NULL) return std::string();
|
||
|
||
// 判定顺序按继承深度:梁/墙/板都派生自 AecDbEwPipeBase,必须先判具体类
|
||
if (AecDbEwPipe::cast(pEnt)) return kTypePipe;
|
||
if (AecDbXWall::cast(pEnt)) return kTypeWall;
|
||
if (AecDbXSlab::cast(pEnt)) return kTypeSlab;
|
||
if (AecDbColumn::cast(pEnt)) return kTypeColumn;
|
||
if (AecDbBeam::cast(pEnt)) return kTypeBeam;
|
||
if (AecDbClimbStair::cast(pEnt)) return kTypeClimb;
|
||
if (AecDbEwFitting::cast(pEnt)) return kTypeFitting;
|
||
// 洞口/井/倒角都是这个类,靠专业数据区分;这里统一叫 opening
|
||
if (AecDbX3dPartEntity::cast(pEnt)) return kTypeOpening;
|
||
// 异形构筑物:自己一格,往里加的造型部件由 list_aec_shapes 看
|
||
if (AecDbMultiPartEntity::cast(pEnt)) return kTypeMultiPart;
|
||
return std::string();
|
||
}
|
||
|
||
bool typeWanted(const std::string& sType, const std::string& sFilter)
|
||
{
|
||
if (sFilter.empty() || sFilter == "all") return true;
|
||
return sType == sFilter;
|
||
}
|
||
|
||
nlohmann::json vecJson(const AcGeVector3d& v)
|
||
{
|
||
nlohmann::json o;
|
||
o["x"] = v.x;
|
||
o["y"] = v.y;
|
||
o["z"] = v.z;
|
||
return o;
|
||
}
|
||
|
||
nlohmann::json pointJson(const AcGePoint3d& pt)
|
||
{
|
||
nlohmann::json o;
|
||
o["x"] = pt.x;
|
||
o["y"] = pt.y;
|
||
o["z"] = pt.z;
|
||
return o;
|
||
}
|
||
|
||
// 取起终点(这些实体都有 base curve)
|
||
bool baseCurveEnds(AcDbEntity* pEnt, AcGePoint3d& ptS, AcGePoint3d& ptE)
|
||
{
|
||
AcDbCurve* pCrv = AcDbCurve::cast(pEnt);
|
||
if (pCrv == NULL) return false;
|
||
return pCrv->getStartPoint(ptS) == Acad::eOk && pCrv->getEndPoint(ptE) == Acad::eOk;
|
||
}
|
||
|
||
// 各类型的关键参数(读取时按 kForRead 打开的专业数据)
|
||
nlohmann::json paramsOf(AcDbEntity* pEnt, const std::string& sType)
|
||
{
|
||
nlohmann::json p = nlohmann::json::object();
|
||
|
||
if (sType == kTypeMultiPart)
|
||
{
|
||
AecDbMultiPartEntity* pMp = AecDbMultiPartEntity::cast(pEnt);
|
||
if (pMp == NULL) return p;
|
||
|
||
const AcGePoint3d ptOrg = pMp->GetOrg();
|
||
p["org"] = pointJson(ptOrg);
|
||
p["x_dir"] = vecJson(pMp->GetXDir());
|
||
p["y_dir"] = vecJson(pMp->GetYDir());
|
||
p["z_dir"] = vecJson(pMp->GetZDir());
|
||
|
||
// 部件列表:类型名 + 并/差(造型的尺寸用 list_aec_shapes 查)
|
||
nlohmann::json arShapes = nlohmann::json::array();
|
||
const int nCount = pMp->GetX3dPartCount();
|
||
for (int i = 0; i < nCount; ++i)
|
||
{
|
||
const AecDbX3dPart* pPart = pMp->GetX3dPart(i);
|
||
if (pPart == NULL) continue;
|
||
nlohmann::json o;
|
||
CString sName;
|
||
pPart->GetName(sName);
|
||
o["name"] = acharToUtf8(sName);
|
||
CString sTypeName;
|
||
pPart->GetSpecialtyData()->GetAt(_T("DTYG_TYPE"), sTypeName);
|
||
o["type"] = acharToUtf8(sTypeName);
|
||
o["guid"] = acharToUtf8(pPart->GetGUID());
|
||
o["mode"] = (pPart->GetBoolOperFor() == AcDb::kBoolSubtract) ? "subtract" : "unite";
|
||
arShapes.push_back(o);
|
||
}
|
||
p["shape_count"] = nCount;
|
||
p["shapes"] = arShapes;
|
||
}
|
||
else if (sType == kTypePipe)
|
||
{
|
||
AecDbEwPipe* pPipe = AecDbEwPipe::cast(pEnt);
|
||
if (pPipe == NULL) return p;
|
||
|
||
// 实体这时是按 kForRead 打开的,专业数据也必须用 kForRead 取:
|
||
// GetSpecialtyData() 的缺省参数是 kForWrite,对只读实体取写会直接崩 CAD。
|
||
const AecDbObjXDataMap* pX = pPipe->GetSpecialtyData(AcDb::kForRead);
|
||
if (pX != NULL)
|
||
{
|
||
double d = 0.0;
|
||
if (pX->GetAt(PIPE_DN, d)) p["dn_mm"] = aec_mcp::dwgToMm(d);
|
||
if (pX->GetAt(PIPE_OD, d)) p["od_mm"] = aec_mcp::dwgToMm(d);
|
||
if (pX->GetAt(PIPE_THICK, d)) p["wall_thickness_mm"] = aec_mcp::dwgToMm(d);
|
||
int n2d = 0;
|
||
if (pX->GetAt(KEY_2DSTYLE, n2d)) p["style_2d"] = n2d; // 1=单线 2=双线
|
||
// 调试:BaseDraw2d 里实际用的是 DN - GetPipeDoubleLineMaxD() > 1e-3 判双线,
|
||
// 这里把两个来源的上限都吐出来(KT_PIPEINIT 原值 + EW_EARTHWORMINIT 是否存在)
|
||
{
|
||
AecDbObjXDataMap xInit;
|
||
if (KTModelLayoutXData::ReadModelXData(KT_PIPEINIT, xInit))
|
||
{
|
||
double dMax = 0.0;
|
||
if (xInit.GetAt(DOC_PIPEMAXDIA, dMax)) p["kt_max"] = dMax;
|
||
}
|
||
AecDbObjXDataMap xEw;
|
||
if (KTModelLayoutXData::ReadModelXData(_T("EW_EARTHWORMINIT"), xEw))
|
||
{
|
||
CString sMax;
|
||
if (xEw.GetAt(DOC_PIPEMAXDIA, sMax)) p["ew_max"] = acharToUtf8(sMax);
|
||
}
|
||
}
|
||
|
||
CString s;
|
||
if (pX->GetAt(PIPE_SYS, s)) p["system"] = acharToUtf8(s);
|
||
if (pX->GetAt(PIPE_MATERIAL, s)) p["material"] = acharToUtf8(s);
|
||
|
||
// 与入参统一用 color(ACI);老字段名 color_index 不再输出
|
||
int nClr = 0;
|
||
if (pX->GetAt(_T("COLOR"), nClr)) p["color"] = nClr;
|
||
}
|
||
}
|
||
else if (sType == kTypeWall)
|
||
{
|
||
AecDbXWall* pWall = AecDbXWall::cast(pEnt);
|
||
WallData data;
|
||
::memset(&data, 0, sizeof(WallData));
|
||
if (pWall != NULL && pWall->GetWallData(data))
|
||
{
|
||
p["thickness"] = data.dThick;
|
||
p["height"] = data.dH;
|
||
p["bottom_elevation"] = data.dBomEl;
|
||
p["align"] = (data.kAlign == kLeft) ? "left" : ((data.kAlign == kRight) ? "right" : "center");
|
||
p["material"] = acharToUtf8(data.szMat);
|
||
if (data.dThick2 > 1e-9)
|
||
{
|
||
p["thickness2"] = data.dThick2;
|
||
p["height2"] = data.dH2;
|
||
}
|
||
}
|
||
}
|
||
else if (sType == kTypeSlab)
|
||
{
|
||
AecDbXSlab* pSlab = AecDbXSlab::cast(pEnt);
|
||
if (pSlab == NULL) return p;
|
||
|
||
// 板把板厚存在 KEY_BOMTHICK,标高存在 KEY_ORGPT(见 AecDbXSlab::SetRegionSlab)
|
||
double d = 0.0;
|
||
if (pSlab->GetAt(KEY_BOMTHICK, d)) p["thickness"] = d;
|
||
|
||
AcGePoint3d ptOrg;
|
||
if (pSlab->GetAt(KEY_ORGPT, ptOrg)) p["bottom_elevation"] = ptOrg.z;
|
||
|
||
CString sMat;
|
||
if (pSlab->GetAt(KEY_MATERIAL, sMat)) p["material"] = acharToUtf8(sMat);
|
||
}
|
||
else if (sType == kTypeColumn)
|
||
{
|
||
AecDbColumn* pCol = AecDbColumn::cast(pEnt);
|
||
if (pCol == NULL) return p;
|
||
|
||
p["height"] = pCol->GetHeight();
|
||
const AcGePoint2d rc = pCol->GetRect();
|
||
p["length"] = rc.x;
|
||
p["width"] = rc.y;
|
||
p["rotation_deg"] = pCol->GetRotation() * 180.0 / PI;
|
||
}
|
||
else if (sType == kTypeOpening)
|
||
{
|
||
AecDbX3dPartEntity* pPart = AecDbX3dPartEntity::cast(pEnt);
|
||
if (pPart == NULL) return p;
|
||
|
||
// 名字用来区分:开洞 / 套管 / 方台井 / 圆台井 / 方圆井 / 异形偏心井 …
|
||
CString s;
|
||
s = pPart->GetName();
|
||
if (!s.IsEmpty()) p["name"] = acharToUtf8(s);
|
||
|
||
if (pPart->GetAt(KEY_NO, s)) p["no"] = acharToUtf8(s);
|
||
if (pPart->GetAt(KEY_FORUSE, s)) p["for_use"] = acharToUtf8(s);
|
||
|
||
AcGePoint3d pt;
|
||
if (pPart->GetAt(_T("AECMCP_HOLE_CEN"), pt))
|
||
p["position"] = pointJson(pt);
|
||
|
||
// 母体(洞挂在谁的下面)
|
||
AcDbObjectId idHost;
|
||
if (pPart->GetAt(KEY_ASSOIC, idHost) && !idHost.isNull())
|
||
{
|
||
AcDbObject* pObj = NULL;
|
||
if (acdbOpenObject(pObj, idHost, AcDb::kForRead) == Acad::eOk && pObj != NULL)
|
||
{
|
||
p["host"] = handleOf(pObj);
|
||
pObj->close();
|
||
}
|
||
}
|
||
}
|
||
else if (sType == kTypeFitting)
|
||
{
|
||
AecDbEwFitting* pFit = AecDbEwFitting::cast(pEnt);
|
||
if (pFit == NULL) return p;
|
||
|
||
const AecDbObjXDataMap* pX = pFit->GetSpecialtyData(AcDb::kForRead);
|
||
if (pX != NULL)
|
||
{
|
||
static const char* kTypeNames[] = { "cabletry","pipe","fitting","elbow","reduce_elbow","reduce",
|
||
"tee","valve","cross","equipment","flange" };
|
||
int nType = -1;
|
||
if (pX->GetAt(KEY_RUNTIME, nType) && nType >= 0 && nType <= 10)
|
||
p["type"] = kTypeNames[nType];
|
||
else
|
||
p["type"] = nType;
|
||
|
||
double d = 0.0;
|
||
if (pX->GetAt(PIPE_DN, d)) p["dn_mm"] = d * 1000.0;
|
||
if (pX->GetAt(PIPE_OD, d)) p["od_mm"] = d * 1000.0;
|
||
if (pX->GetAt(PIPE_THICK, d)) p["wall_thickness_mm"] = d * 1000.0;
|
||
if (pX->GetAt(PIPE_RATIO, d)) p["ratio"] = d;
|
||
|
||
AcGePoint3d pt;
|
||
if (pX->GetAt(KEY_MID, pt)) p["position"] = pointJson(pt);
|
||
AcGeVector3d vt;
|
||
if (pX->GetAt(KEY_MAJBR, vt)) p["direction"] = { { "x", vt.x }, { "y", vt.y }, { "z", vt.z } };
|
||
if (pX->GetAt(KEY_MINBR, vt)) p["branch_direction"] = { { "x", vt.x }, { "y", vt.y }, { "z", vt.z } };
|
||
|
||
int nConnect = 0;
|
||
if (pX->GetAt(PIPE_CONNECT, nConnect)) p["connect"] = nConnect;
|
||
CString s;
|
||
if (pX->GetAt(PIPE_SYS, s)) p["system"] = acharToUtf8(s);
|
||
if (pX->GetAt(PIPE_MATERIAL, s)) p["material"] = acharToUtf8(s);
|
||
int nClr = 0;
|
||
if (pX->GetAt(PIPE_COLOR, nClr)) p["color"] = nClr;
|
||
}
|
||
}
|
||
else if (sType == kTypeClimb)
|
||
{
|
||
AecDbClimbStair* pStair = AecDbClimbStair::cast(pEnt);
|
||
ClimbStair data;
|
||
::memset(&data, 0, sizeof(ClimbStair));
|
||
if (pStair != NULL)
|
||
{
|
||
pStair->GetClimbStairData(data);
|
||
p["type"] = data.nType;
|
||
p["cage_diameter"] = data.dD;
|
||
p["width"] = data.dW;
|
||
p["height"] = data.dH;
|
||
p["bottom_elevation"] = data.dBomEl;
|
||
p["step_height"] = data.dSteepH;
|
||
p["step_spacing"] = data.dSegSp;
|
||
p["wall_distance"] = data.dSpWall;
|
||
p["bar_diameter"] = data.dd;
|
||
p["material"] = acharToUtf8(data.m_sMaterial);
|
||
}
|
||
}
|
||
else if (sType == kTypeBeam)
|
||
{
|
||
AecDbBeam* pBeam = AecDbBeam::cast(pEnt);
|
||
ColumnParam data;
|
||
::memset(&data, 0, sizeof(ColumnParam));
|
||
if (pBeam != NULL)
|
||
{
|
||
pBeam->GetBeamData(data);
|
||
p["width"] = data.m_dSizes[0];
|
||
p["height"] = data.m_dSizes[1];
|
||
}
|
||
}
|
||
|
||
return p;
|
||
}
|
||
|
||
// 单个实体摘要
|
||
nlohmann::json summaryOf(AcDbEntity* pEnt)
|
||
{
|
||
nlohmann::json o;
|
||
o["handle"] = handleOf(pEnt);
|
||
o["type"] = supportedTypeOf(pEnt);
|
||
o["layer"] = acharToUtf8(pEnt->layer());
|
||
|
||
AcGePoint3d ptS, ptE;
|
||
if (baseCurveEnds(pEnt, ptS, ptE))
|
||
{
|
||
o["start"] = pointJson(ptS);
|
||
o["end"] = pointJson(ptE);
|
||
}
|
||
|
||
AcGePoint3d ptMin, ptMax;
|
||
if (entityBBox(pEnt, ptMin, ptMax))
|
||
{
|
||
o["bbox"] = { { "min", pointJson(ptMin) }, { "max", pointJson(ptMax) } };
|
||
}
|
||
|
||
return o;
|
||
}
|
||
|
||
} // namespace
|
||
|
||
// ===========================================================================
|
||
// list_aec_entities
|
||
// ===========================================================================
|
||
class ToolListAecEntities : public mcp_Tool
|
||
{
|
||
public:
|
||
std::string private_name() const override { return "query_aec_entities"; }
|
||
|
||
std::string private_description() const override
|
||
{
|
||
return "列出当前图纸里本插件支持的 Envi3D 自定义实体(管道/墙/板/柱/梁/爬梯/管件/洞口井/异形构筑物),"
|
||
"返回 handle、类型、图层、起终点、包围盒。改图之前先用它找 handle。"
|
||
"type 可为 pipe/wall/slab/column/beam/climb_stair/fitting/opening/multipart/all,支持 limit/offset 分页。";
|
||
}
|
||
|
||
nlohmann::json private_input_schema() const override
|
||
{
|
||
return nlohmann::json::parse(R"({
|
||
"type": "object",
|
||
"properties": {
|
||
"type": { "type": "string", "enum": [ "all", "pipe", "wall", "slab", "column", "beam", "climb_stair", "fitting", "opening", "multipart" ],
|
||
"description": "要列出的类型,缺省 all" },
|
||
"space": { "type": "string", "description": "空间名:Model 或布局名,缺省 Model" },
|
||
"limit": { "type": "integer", "description": "最多返回多少条,缺省 200,上限 1000" },
|
||
"offset":{ "type": "integer", "description": "分页偏移,缺省 0" }
|
||
}
|
||
})");
|
||
}
|
||
|
||
nlohmann::json Execute(const nlohmann::json& args) override
|
||
{
|
||
AcDbDatabase* pDb = workingDb();
|
||
if (pDb == NULL) return errJson(kErrNoDocument, L"没有活动图纸");
|
||
|
||
const std::string sFilter = hasKey(args, "type") ? args["type"].get<std::string>() : "all";
|
||
const std::string sSpace = hasKey(args, "space") ? args["space"].get<std::string>() : "Model";
|
||
// 注意别用 std::max/std::min:windows.h 的 max/min 宏会把它顶掉
|
||
int nLimit = intOr(args, "limit", 200);
|
||
if (nLimit < 1) nLimit = 1;
|
||
if (nLimit > 1000) nLimit = 1000;
|
||
int nOffset = intOr(args, "offset", 0);
|
||
if (nOffset < 0) nOffset = 0;
|
||
|
||
// 开空间
|
||
AcDbBlockTable* pBT = NULL;
|
||
if (pDb->getBlockTable(pBT, AcDb::kForRead) != Acad::eOk || pBT == NULL)
|
||
return errJson(kErrInternal, L"取块表失败");
|
||
|
||
AcDbObjectId idSpace;
|
||
Acad::ErrorStatus es = Acad::eKeyNotFound;
|
||
if (sSpace.empty() || sSpace == "Model" || sSpace == "model")
|
||
es = pBT->getAt(ACDB_MODEL_SPACE, idSpace);
|
||
else
|
||
es = pBT->getAt(utf8ToWstr(sSpace).c_str(), idSpace);
|
||
pBT->close();
|
||
|
||
AcDbBlockTableRecord* pRec = NULL;
|
||
if (es != Acad::eOk || acdbOpenObject(pRec, idSpace, AcDb::kForRead) != Acad::eOk || pRec == NULL)
|
||
return errJson(kErrNotFound, L"找不到空间:" + utf8ToWstr(sSpace));
|
||
|
||
nlohmann::json items = nlohmann::json::array();
|
||
int nTotal = 0, nReturned = 0;
|
||
|
||
AcDbBlockTableRecordIterator* pIt = NULL;
|
||
if (pRec->newIterator(pIt) == Acad::eOk && pIt != NULL)
|
||
{
|
||
for (; !pIt->done(); pIt->step())
|
||
{
|
||
AcDbEntity* pEnt = NULL;
|
||
if (pIt->getEntity(pEnt, AcDb::kForRead) != Acad::eOk || pEnt == NULL)
|
||
continue;
|
||
|
||
const std::string sType = supportedTypeOf(pEnt);
|
||
if (!sType.empty() && typeWanted(sType, sFilter))
|
||
{
|
||
++nTotal;
|
||
if (nTotal > nOffset && nReturned < nLimit)
|
||
{
|
||
items.push_back(summaryOf(pEnt));
|
||
++nReturned;
|
||
}
|
||
}
|
||
pEnt->close();
|
||
}
|
||
delete pIt;
|
||
}
|
||
pRec->close();
|
||
|
||
nlohmann::json body;
|
||
body["total"] = nTotal;
|
||
body["returned"] = nReturned;
|
||
body["offset"] = nOffset;
|
||
body["items"] = items;
|
||
return okJson(body);
|
||
}
|
||
};
|
||
EXPORT_MCP_TOOL(ToolListAecEntities, ListAecEntitiesTool)
|
||
|
||
// ===========================================================================
|
||
// get_aec_entity
|
||
// ===========================================================================
|
||
class ToolGetAecEntity : public mcp_Tool
|
||
{
|
||
public:
|
||
std::string private_name() const override { return "get_aec_entity_detail"; }
|
||
|
||
std::string private_description() const override
|
||
{
|
||
return "按 handle 取单个 Envi3D 实体的详细参数(类型、图层、起终点、包围盒,"
|
||
"以及该类型的关键尺寸:管道的 DN/外径/壁厚、墙的厚高标高、板厚、柱截面、梁截面、"
|
||
"异形构筑物的 Org/三轴/造型部件)。";
|
||
}
|
||
|
||
nlohmann::json private_input_schema() const override
|
||
{
|
||
return nlohmann::json::parse(R"({
|
||
"type": "object",
|
||
"properties": {
|
||
"handle": { "type": "string", "description": "实体句柄(十六进制字符串)" }
|
||
},
|
||
"required": [ "handle" ]
|
||
})");
|
||
}
|
||
|
||
nlohmann::json Execute(const nlohmann::json& args) override
|
||
{
|
||
if (workingDb() == NULL) return errJson(kErrNoDocument, L"没有活动图纸");
|
||
if (!hasKey(args, "handle")) return errJson(kErrBadParam, L"缺少 handle");
|
||
|
||
const std::string sHandle = args["handle"].get<std::string>();
|
||
AcDbEntity* pEnt = openByHandle(sHandle, AcDb::kForRead);
|
||
if (pEnt == NULL)
|
||
return errJson(kErrNotFound, L"按 handle 打不开实体:" + utf8ToWstr(sHandle));
|
||
|
||
const std::string sType = supportedTypeOf(pEnt);
|
||
if (sType.empty())
|
||
{
|
||
const std::string sCls = classNameOf(pEnt);
|
||
pEnt->close();
|
||
return errJson(kErrWrongType,
|
||
L"实体 " + utf8ToWstr(sCls) + L" 不在本插件支持的范围内"
|
||
L"(只支持管道/墙/板/柱/梁)");
|
||
}
|
||
|
||
nlohmann::json body = summaryOf(pEnt);
|
||
body["params"] = paramsOf(pEnt, sType);
|
||
pEnt->close();
|
||
|
||
return okJson(body);
|
||
}
|
||
};
|
||
EXPORT_MCP_TOOL(ToolGetAecEntity, GetAecEntityTool)
|
||
|
||
// 调试用:把实体的专业数据(AecDbObjXDataMap)整份吐出来,key/value 一行一条。
|
||
// 用来对比"MCP 建的实体"和"命令建的实体"差哪些字段。
|
||
class ToolDumpXData : public mcp_Tool
|
||
{
|
||
public:
|
||
std::string private_name() const override { return "dump_aec_xdata"; }
|
||
std::string private_description() const override
|
||
{
|
||
return "调试用:输出实体专业数据(xdata)的全部 key/value,便于和命令建的实体对比。";
|
||
}
|
||
nlohmann::json private_input_schema() const override
|
||
{
|
||
return nlohmann::json::parse(R"({"type":"object","properties":{"handle":{"type":"string","description":"实体 handle"}},"required":["handle"]})");
|
||
}
|
||
nlohmann::json Execute(const nlohmann::json& args) override
|
||
{
|
||
if (workingDb() == NULL) return errJson(kErrNoDocument, L"没有活动图纸");
|
||
if (!hasKey(args, "handle")) return errJson(kErrBadParam, L"缺少 handle");
|
||
|
||
const std::string sHandle = args["handle"].get<std::string>();
|
||
AcDbEntity* pEnt = openByHandle(sHandle, AcDb::kForRead);
|
||
if (pEnt == NULL) return errJson(kErrNotFound, L"按 handle 打不开实体:" + utf8ToWstr(sHandle));
|
||
|
||
// 管线派生自 AecDbCurveBase,其他实体派生自 AecDbEntityBase,两边都试一次
|
||
const AecDbObjXDataMap* pX = NULL;
|
||
if (AecDbCurveBase* pCB = AecDbCurveBase::cast(pEnt)) pX = pCB->GetSpecialtyData(AcDb::kForRead);
|
||
else if (AecDbEntityBase* pBE = AecDbEntityBase::cast(pEnt)) pX = pBE->GetSpecialtyData(AcDb::kForRead);
|
||
if (pX == NULL)
|
||
{
|
||
pEnt->close();
|
||
return errJson(kErrWrongType, L"不是本产品的实体(取不到专业数据)");
|
||
}
|
||
nlohmann::json ar = nlohmann::json::array();
|
||
if (pX != NULL)
|
||
{
|
||
std::vector<CString> lst;
|
||
pX->List(lst);
|
||
for (size_t i = 0; i + 1 < lst.size(); i += 2)
|
||
{
|
||
nlohmann::json it;
|
||
it["key"] = acharToUtf8(lst[i]);
|
||
it["value"] = acharToUtf8(lst[i + 1]);
|
||
ar.push_back(it);
|
||
}
|
||
}
|
||
pEnt->close();
|
||
|
||
nlohmann::json body;
|
||
body["handle"] = sHandle;
|
||
body["count"] = (int)ar.size();
|
||
body["data"] = ar;
|
||
return okJson(body);
|
||
}
|
||
};
|
||
EXPORT_MCP_TOOL(ToolDumpXData, DumpAecXDataTool)
|