Files

83 lines
3.4 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include "vde_cam/cam_toolpath.h"
#include "vde_cam/cam_5axis.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);
// ═══════════════════════════════════════════════════════════
// B-7 深度:5 轴后处理 G-code 输出 / 重导入(往返一致)
// ═══════════════════════════════════════════════════════════
/// 由机床旋转角 (A/B/C, 度) 正解刀具轴矢量(与 export_gcode_5axis 互逆)
[[nodiscard]] Vector3D tool_axis_from_machine_angles(
const MachineConfig& config, double a_deg, double b_deg, double c_deg);
/// 5 轴刀路后处理为 G-code(X/Y/Z + A/B/C + F),可直接被
/// import_gcode_5axis 重导入(位置/刀轴/进给往返一致)。
[[nodiscard]] std::string export_gcode_5axis(
const AxisToolpath5& toolpath, const MachineConfig& config);
/// 重新导入 5 轴 G-code(X/Y/Z/A/B/C/F),按机床构型反解刀具轴,
/// 与 export_gcode_5axis 构成闭环。
[[nodiscard]] AxisToolpath5 import_gcode_5axis(
const std::string& gcode_text, const MachineConfig& config);
} // namespace vde::cam