#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 #include #include 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& 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 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& created); } // namespace dwg_annotate