feat(annotate): 新增图纸批注工具集(云线/文字/多段线/引线等 8 个工具)

- 新增 dwg_annotate_common/draw/edit(命名前缀 dwg_annotate)
- 工具:draw_revision_cloud、add_text、add_mtext、add_polyline、
  add_line、add_leader_annotation、delete_entities、set_entity_properties
- 批注默认落在 AI_REVIEW 图层(不存在则自动创建)
- 同步 cmakelists.txt 与 cad-mcp-frame.json(工具数 18 -> 26)
- 记录 UTF-8 BOM 编译约定到 ai.memory
This commit is contained in:
gjm committed 2026-10-09 15:17:54 +08:00
1 parent e25aa0a650
commit 5b81a71be9
7 files changed
+1118

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
#pragma once
// ============================================================================
// dwg_annotate_common.h
// 图纸批注工具集 - 公共辅助层
//
// 供 dwg_annotate_draw / dwg_annotate_edit 共用,避免重复实现:
// - 批注图层自动创建(默认 AI_REVIEW)
// - 以 kForWrite 打开目标空间
// - UTF-8 <-> 宽字符、点/窗口参数解析
// - 图层/颜色设置、实体 append 与关闭
// - 统一创建结果构造
//
// 依赖 dwg_review_common(复用其 handleOf / makeJsonResult / makeError /
// objectIdFromHandle / kErr* 等)。
// ============================================================================
#include "cadsdk.h"
#include "dwg_review_common.h"
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
namespace dwg_annotate
{
// 默认批注图层名
extern const char* kDefaultAnnotLayer;
// 确保图层存在(不存在则以给定 ACI 颜色创建)
bool ensureLayer(AcDbDatabase* pDb, const std::string& name, int aciColor);
// 以 kForWrite 打开指定空间的块表记录(成功返回的对象需调用者 close)
AcDbBlockTableRecord* openWriteSpace(AcDbDatabase* pDb, const std::string& space);
// UTF-8 -> 宽字符
std::wstring utf8ToWStr(const std::string& s);
// ---------- 参数解析 ----------
// 点:[x,y] / [x,y,z] / {"x":..,"y":..,"z":..}
bool parsePoint(const nlohmann::json& j, AcGePoint3d& out);
bool parsePoints(const nlohmann::json& arr, std::vector<AcGePoint3d>& out);
// 窗口:window 对象 或 min_x/min_y/max_x/max_y 或 p1/p2 两角点
bool parseWindow(const nlohmann::json& args, double& x1, double& y1, double& x2, double& y2);
// 句柄列表:handle / handles
std::vector<std::string> collectHandlesArg(const nlohmann::json& args);
// ---------- 公共参数默认值 ----------
std::string getLayerArg(const nlohmann::json& args); // 默认 AI_REVIEW
int getColorArg(const nlohmann::json& args, int def = 256); // 默认 ByLayer
std::string getSpaceArg(const nlohmann::json& args); // 默认 Model
// ---------- 实体写入 ----------
void applyLayerColor(AcDbEntity* pEnt, const std::string& layer, int aciColor);
// append 到空间并 close 实体,返回 ObjectId(kNull = 失败)
AcDbObjectId appendToSpace(AcDbBlockTableRecord* pSpace, AcDbEntity* pEnt);
std::string handleOfId(AcDbDatabase* pDb, const AcDbObjectId& id);
// ---------- 结果构造 ----------
nlohmann::json makeCreatedItem(AcDbDatabase* pDb, const AcDbObjectId& id,
const std::string& type, const std::string& layer);
// 包装为 MCP 文本信封:{"ok":true,"count":N,"created":[...]}
nlohmann::json createdResult(const std::vector<nlohmann::json>& created);
} // namespace dwg_annotate