### P1.x 内核对齐(P1 遗留收口)
- 原生 .vde 序列化(serializer/vde_format/vde_text)迁入内核 vde_brep;C API 序列化回迁 vde_kernel_capi;
PMI/MBD 拆为内核数据模型(vde_brep)+ 3D-PDF 导出(vde_io/pmi_export.cpp),消除 kernel→io 反向依赖;
- make_geometry_host_services() 迁入内核 vde_brep,kernel-only 下 PluginManager+宿主服务可用;
- kernel-only 约 40 个测试 target + 4 个 examples 门控;六业务 OFF 的 2 个测试 target 门控;
- vde_version() 返回 0.5.0 既有缺陷修复;kernel SDK consumer 实测 1.0.47;
### P2-1 vde_cae 官方模块
- include/vde/cae/*、src/cae/*、tests/cae/*;旧路径转发头兼容;VDE_BUILD_CAE 开关;
- vde_io 移除 fea_mesh/fluid_domain;ctest 用例数保持(95 项 CAE 测试);CAE=OFF 构建 937/937;
### P2-2 插件 ABI 1.2:CAE solver / CAM strategy 扩展点
- VdeCaeSolverPlugin/VdeCamStrategyPlugin + Registration 尾部扩展(旧插件兼容);
- PluginManager cae_solvers()/cam_strategies()/solve_cae()/invoke_cam(),加载校验/失败隔离;
- plugins/sample_cae、sample_cam_post、abi11_compat、external/{runner,sample_stl_converter};
- docs/design/vde-service-protocol.md 进程外服务协议草案;test_plugin_extensions 9/9;
### VDE-1249 三阻塞修复
- fix1 共享边采样性能悬崖:sagitta 自适应段数 + 自由曲面证据触发 + fast planar loop 256 + IncrementalMesher 复用 mesh_face_diag;
box+16 孔 legacy 3.3-3.6s→69.5ms、rebuild 4095→103ms;box+25 孔 5.1s→190.9ms;n42 链 ≤222ms;open=0/面积体积正确;
- fix2 fillet/blend 破损体护栏(fillet_edges_checked:watertight/dangling 护栏 + heal 重试 + 显式失败/诊断;
静默 no-op success → 显式失败)+ delete_face_with_heal/fill_hole 边环重排(26 面盒 0/26→6/6,box 2/6→6/6);
- fix3 wireframe tight payload:WireframeOptions.include_segment_info + C API VdeWireframeOptions 尾扩展 +
vde_body_to_wireframe_opt2(旧 ABI 安全);tight≈49-61% full(与 1.0.12 旧风格差 4B/段);
### 工程
- 修复 .gitignore `*.txt` 误伤:`!CMakeLists.txt`,把 plugins/**、tools/、tests/plugin、tests/cae 等漏入库的
CMakeLists.txt 纳入版本库(保证干净 checkout 可构建);
- 版本 1.0.47(CMake/version.h/test_version/README/docs index/module-manual 同步);
验证:全量构建 0 error(334 targets);全量 ctest 7395 注册、7300/7300 PASS(0 failed,24 skipped,194.39s);
kernel-only(-DVDE_BUILD_IO=OFF + BUILD_TESTS=ON)全量构建 0 failed、plugin 30/12 + capi_split 7 全绿;
六业务 OFF 全量测试构建 0 failed;CAE 95/95;插件 ctest 61/61;VDE-1249 repro 前后数字见 CHANGELOG。
170 lines
6.6 KiB
C++
170 lines
6.6 KiB
C++
// 示例 CAM 策略/后处理插件(VDE 微内核 P2 / 插件 ABI 1.2;纯 C ABI,不链接内核)。
|
|
//
|
|
// 演示 VdeCamStrategyPlugin 扩展点:输入 VDE 序列化模型 + 参数 JSON,输出
|
|
// Fanuc 风格 G-code 文本("演示级":在包围盒顶面做等距光栅刀路,不考虑毛坯/
|
|
// 残料/碰撞;目的是验证扩展点契约、宿主服务 body_from_serialized/body_bbox 与
|
|
// host->alloc 输出所有权)。
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <string>
|
|
|
|
#include "vde/plugin/vde_plugin_api.h"
|
|
|
|
namespace {
|
|
|
|
int cam_fail(const VdePluginHost* host, int code, const char* message) {
|
|
if (host && host->set_error) host->set_error(message);
|
|
return code;
|
|
}
|
|
|
|
int validate_host(const VdePluginHost* host) {
|
|
if (!host) return VDE_PLUGIN_ERR_INVALID_ARG;
|
|
if (host->abi_major != VDE_PLUGIN_ABI_MAJOR)
|
|
return cam_fail(host, VDE_PLUGIN_ERR_ABI, "sample_cam_post: 宿主 ABI major 不兼容");
|
|
if (!host->alloc || !host->free || !host->set_error)
|
|
return cam_fail(host, VDE_PLUGIN_ERR_UNSUPPORTED,
|
|
"sample_cam_post: 宿主缺少 alloc/free/set_error");
|
|
if (!host->body_from_serialized || !host->body_bbox || !host->body_destroy)
|
|
return cam_fail(host, VDE_PLUGIN_ERR_UNSUPPORTED,
|
|
"sample_cam_post: 宿主缺少 body_from_serialized/bbox/destroy");
|
|
return VDE_PLUGIN_OK;
|
|
}
|
|
|
|
double json_number(const char* text, const char* key, double fallback) {
|
|
if (!text || !key) return fallback;
|
|
const std::string pattern = std::string("\"") + key + "\"";
|
|
const char* pos = std::strstr(text, pattern.c_str());
|
|
if (!pos) return fallback;
|
|
pos += pattern.size();
|
|
while (*pos == ' ' || *pos == '\t' || *pos == '\r' || *pos == '\n') ++pos;
|
|
if (*pos != ':') return fallback;
|
|
++pos;
|
|
char* end = nullptr;
|
|
const double value = std::strtod(pos, &end);
|
|
if (end == pos) return fallback;
|
|
return value;
|
|
}
|
|
|
|
int cam_invoke(const VdePluginHost* host, const void* model_data, size_t model_size,
|
|
const char* args_json, VdeBuffer* out) {
|
|
if (out) {
|
|
out->data = nullptr;
|
|
out->size = 0;
|
|
}
|
|
if (!out) return cam_fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "sample_cam_post: out 为空");
|
|
const int host_rc = validate_host(host);
|
|
if (host_rc != VDE_PLUGIN_OK) return host_rc;
|
|
if (!model_data || model_size == 0)
|
|
return cam_fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "sample_cam_post: 模型数据为空");
|
|
|
|
VdeBody body = host->body_from_serialized(model_data, model_size);
|
|
if (!body)
|
|
return cam_fail(host, VDE_PLUGIN_ERR_PARSE,
|
|
"sample_cam_post: 无法反序列化模型(见宿主错误信息)");
|
|
double bmin[3] = {0.0, 0.0, 0.0};
|
|
double bmax[3] = {0.0, 0.0, 0.0};
|
|
const int rc = host->body_bbox(body, bmin, bmax);
|
|
host->body_destroy(body);
|
|
if (rc != VDE_PLUGIN_OK)
|
|
return cam_fail(host, VDE_PLUGIN_ERR_INTERNAL, "sample_cam_post: body_bbox 失败");
|
|
|
|
const double stepover = json_number(args_json, "stepover", 5.0);
|
|
const double feed = json_number(args_json, "feed", 300.0);
|
|
const double rapid = json_number(args_json, "rapid", 1000.0);
|
|
const double clearance = json_number(args_json, "clearance", 5.0);
|
|
const double safe_step = (stepover > 1e-6) ? stepover : 5.0;
|
|
const double top_z = bmax[2] + ((clearance > 0.0) ? clearance : 5.0);
|
|
const double x0 = bmin[0];
|
|
const double x1 = bmax[0];
|
|
const double y0 = bmin[1];
|
|
const double y1 = bmax[1];
|
|
|
|
std::string code;
|
|
char line[256];
|
|
code += "; VDE sample CAM post (fanuc-style, demo only)\n";
|
|
std::snprintf(line, sizeof(line), "; stock: X[%.6g,%.6g] Y[%.6g,%.6g] Z[%.6g,%.6g]\n",
|
|
bmin[0], bmax[0], bmin[1], bmax[1], bmin[2], bmax[2]);
|
|
code += line;
|
|
code += "G21 G90 G17 G40 G49\n";
|
|
std::snprintf(line, sizeof(line), "G0 Z%.6g\n", top_z);
|
|
code += line;
|
|
std::snprintf(line, sizeof(line), "G0 X%.6g Y%.6g\n", x0, y0);
|
|
code += line;
|
|
bool forward = true;
|
|
int passes = 0;
|
|
for (double y = y0; y <= y1 + 1e-9; y += safe_step) {
|
|
const double target_x = forward ? x1 : x0;
|
|
std::snprintf(line, sizeof(line), "G1 X%.6g Y%.6g F%.6g\n", target_x, y, feed);
|
|
code += line;
|
|
++passes;
|
|
if (y + safe_step > y1 + 1e-9) break;
|
|
std::snprintf(line, sizeof(line), "G1 Y%.6g F%.6g\n", y + safe_step, feed);
|
|
code += line;
|
|
forward = !forward;
|
|
}
|
|
std::snprintf(line, sizeof(line), "G0 Z%.6g\n", top_z + 10.0);
|
|
code += line;
|
|
code += "M30\n";
|
|
code += "; postprocessor: fanuc; machine: generic-3axis\n";
|
|
|
|
void* buffer = host->alloc(code.size() + 1);
|
|
if (!buffer) return cam_fail(host, VDE_PLUGIN_ERR_BUFFER, "sample_cam_post: 输出缓冲分配失败");
|
|
std::memcpy(buffer, code.c_str(), code.size() + 1);
|
|
out->data = buffer;
|
|
out->size = code.size();
|
|
(void)rapid;
|
|
(void)passes;
|
|
return VDE_PLUGIN_OK;
|
|
}
|
|
|
|
const char* cam_describe() {
|
|
return "VDE sample CAM post-processor: Fanuc-style raster G-code (demo only, ABI 1.2)";
|
|
}
|
|
|
|
const VdeCamStrategyPlugin kStrategy = [] {
|
|
VdeCamStrategyPlugin strategy{};
|
|
strategy.struct_size = static_cast<uint32_t>(sizeof(VdeCamStrategyPlugin));
|
|
strategy.strategy_id = "cam.post.gcode";
|
|
strategy.postprocessor_id = "fanuc";
|
|
strategy.machine_id = "generic-3axis";
|
|
strategy.invoke = &cam_invoke;
|
|
strategy.describe = &cam_describe;
|
|
return strategy;
|
|
}();
|
|
|
|
} // namespace
|
|
|
|
extern "C" {
|
|
|
|
VDE_PLUGIN_EXPORT int vde_plugin_query(uint32_t host_abi_major, VdePluginInfo* info) {
|
|
if (!info || info->struct_size < sizeof(VdePluginInfo)) return VDE_PLUGIN_ERR_ABI;
|
|
if (host_abi_major != VDE_PLUGIN_ABI_MAJOR) return VDE_PLUGIN_ERR_ABI;
|
|
info->id = "com.vde.sample.cam_post";
|
|
info->name = "VDE Sample CAM Fanuc Post-processor";
|
|
info->version = "0.1.0";
|
|
info->kind = VDE_PLUGIN_KIND_CAM_STRATEGY;
|
|
info->abi_major = VDE_PLUGIN_ABI_MAJOR;
|
|
info->abi_minor = VDE_PLUGIN_ABI_MINOR;
|
|
info->capabilities = "cam_strategy:post.gcode";
|
|
info->license = "Apache-2.0";
|
|
return VDE_PLUGIN_OK;
|
|
}
|
|
|
|
VDE_PLUGIN_EXPORT int vde_plugin_init(const VdePluginHost* host,
|
|
VdePluginRegistration* reg) {
|
|
if (!reg || reg->struct_size < sizeof(VdePluginRegistration))
|
|
return VDE_PLUGIN_ERR_ABI;
|
|
const int host_rc = validate_host(host);
|
|
if (host_rc != VDE_PLUGIN_OK) return host_rc;
|
|
reg->kind = VDE_PLUGIN_KIND_CAM_STRATEGY;
|
|
reg->format = nullptr;
|
|
reg->cae_solver = nullptr;
|
|
reg->cam_strategy = &kStrategy;
|
|
return VDE_PLUGIN_OK;
|
|
}
|
|
|
|
VDE_PLUGIN_EXPORT void vde_plugin_shutdown() {}
|
|
|
|
} // extern "C"
|