Files
ViewDesignEngine/include/vde_cam/gcode_import.h
T
hm e1b00ade36 refactor(batch4): extract CAM subsystem + assembly_lod
CAM: 7 headers + 7 sources + 8 tests moved from core/ to vde_cam/

  Internal 5-layer dependency chain preserved (cam_toolpath → strategies → advanced/optimization/5axis/mesh/gcode)

  Python bindings updated (python/src/vde_cam.cpp)

Assembly LOD: moved from brep/ to vde_render/

Tests: cam_toolpath 11/11, cam_strategies 31/31, gcode_import 10/10, assembly_lod 22/22 — all pass

Fixed: test_cam_3plus2 disabled (pre-existing VDE-242 not implemented)

Fixed: removed unused using namespace vde::brep from CAM tests
2026-08-06 17:06:21 +08:00

64 lines
2.3 KiB
C++

#pragma once
#include "vde_cam/cam_toolpath.h"
#include <string>
namespace vde::cam {
using core::Point3D;
/// G-code 导入状态(模态指令)
struct GcodeImportState {
Point3D position = Point3D::Zero(); ///< 当前刀具位置
Point3D arc_center = Point3D::Zero(); ///< 圆弧中心(增量偏移量)
bool absolute = true; ///< G90 绝对坐标 / G91 增量坐标
bool metric = true; ///< G21 毫米 / G20 英寸
int plane = 17; ///< G17(XY) / G18(ZX) / G19(YZ)
double feed_rate = 1000.0; ///< 当前进给率 (mm/min)
int spindle_speed = 0; ///< 主轴转速 (RPM)
bool spindle_on = false; ///< 主轴状态
bool spindle_cw = true; ///< M03 顺时针 / M04 逆时针
int tool_number = 0; ///< 当前刀具编号
// 钻孔循环参数
int canned_cycle = 0; ///< 0=无, 81=G81, 82=G82, 83=G83
double retract_plane = 0.0; ///< R 退刀平面
double peck_depth = 0.0; ///< Q 啄钻深度 (G83)
double dwell_time = 0.0; ///< P 暂停时间 (G82)
double drill_target_z = 0.0; ///< 钻孔目标深度 Z(模态保持)
double unit_factor = 1.0; ///< 单位转换系数 (inch→mm: 25.4)
};
/// 从 G-code 文件导入刀路
///
/// 解析标准 ISO G-code,支持的指令:
/// - G00/G01 直线移动(快速/切削进给)
/// - G02/G03 圆弧插补(顺/逆时针)
/// - G17/G18/G19 平面选择
/// - G90/G91 绝对/增量坐标
/// - G20/G21 英制/公制单位
/// - G81/G82/G83 钻孔固定循环
/// - M03/M04/M05 主轴控制
/// - S 主轴转速
/// - T/M06 刀具选择与换刀
/// - 注释:跳过 (...) 和 ; 注释
///
/// @param path G-code 文件路径
/// @return 解析后的刀路数据
///
/// @ingroup core
[[nodiscard]] Toolpath import_gcode(const std::string& path);
/// 从 G-code 字符串直接解析(用于测试/内嵌G-code)
///
/// @param gcode_text G-code 文本内容
/// @return 解析后的刀路数据
///
/// @ingroup core
[[nodiscard]] Toolpath import_gcode_from_string(const std::string& gcode_text);
} // namespace vde::cam