Files
ViewDesignEngine/include/vde/brep/quality_feedback.h
T

211 lines
7.7 KiB
C++
Raw Normal View History

#pragma once
/**
* @file quality_feedback.h
* @brief 设计质量闭环 — 规则检查、可制造性、成本估算、综合评分
*
* 从设计数据(BrepModel)出发,进行:
* - 设计规则检查(DRC):壁厚、圆角、拔模角、最小特征等
* - 可制造性分析(DFM):机加工/注塑/增材可行性
* - 成本估算:材料+加工成本
* - 质量评分:综合 0-100 分
*
* @ingroup brep
*/
#include "vde/brep/brep.h"
#include "vde/core/point.h"
#include "vde/mesh/halfedge_mesh.h"
#include <vector>
#include <string>
#include <map>
namespace vde::brep {
using core::Point3D;
using core::Vector3D;
// ═══════════════════════════════════════════════════════════
// 设计规则
// ═══════════════════════════════════════════════════════════
/// 单项设计规则
struct DesignRule {
std::string name; ///< 规则名称
std::string description; ///< 规则描述
double min_value; ///< 最小值(< 0 = 不检查下限)
double max_value; ///< 最大值(< 0 = 不检查上限)
double weight; ///< 权重 [0,1](用于综合评分)
bool critical; ///< 是否为关键规则(不通过则整体失败)
};
/// 设计规则检查结果
struct DesignRuleResult {
std::string rule_name; ///< 规则名称
double actual_value;///< 实际检测值
double min_allowed; ///< 允许下限
double max_allowed; ///< 允许上限
bool passed; ///< 是否通过
std::string message; ///< 检测信息
double score; ///< 单项得分 [0, 1]
};
/// DRC 报告
struct DRCRreport {
std::vector<DesignRuleResult> results; ///< 各规则检测结果
int total_rules; ///< 总规则数
int passed_count; ///< 通过数
int failed_count; ///< 失败数
double overall_score; ///< 综合得分 [0, 1]
bool all_critical_passed; ///< 所有关键规则是否通过
};
// ═══════════════════════════════════════════════════════════
// 可制造性分析
// ═══════════════════════════════════════════════════════════
/// 制造工艺类型
enum class ManufacturingProcess {
Machining, ///< 机加工(铣削/车削)
InjectionMolding,///< 注塑成型
Additive, ///< 增材制造/3D打印
SheetMetal, ///< 钣金
Casting, ///< 铸造
};
/// 可制造性问题
struct MfgIssue {
std::string description; ///< 问题描述
std::string location; ///< 问题位置(如面 ID
int severity; ///< 严重度 1-51=提示,5=致命)
std::string suggestion; ///< 改进建议
};
/// 可制造性分析报告
struct MfgReport {
ManufacturingProcess process; ///< 分析工艺
std::vector<MfgIssue> issues; ///< 问题列表
int total_issues; ///< 总问题数
int critical_issues; ///< 严重问题数(severity>=4
double feasibility; ///< 可行性 [0, 1]
double dfm_score; ///< DFM 得分 [0, 100]
};
// ═══════════════════════════════════════════════════════════
// 成本估算
// ═══════════════════════════════════════════════════════════
/// 材料类型
struct MaterialInfo {
std::string name; ///< 材料名称
double density_kgm3; ///< 密度 (kg/m³)
double cost_per_kg; ///< 材料单价 (元/kg)
std::string grade; ///< 材料牌号
};
/// 成本估算结果
struct CostEstimate {
double volume_m3; ///< 零件体积 (m³)
double mass_kg; ///< 零件质量 (kg)
double material_cost; ///< 材料成本
double machining_cost; ///< 加工成本
double tooling_cost; ///< 工装/模具成本
double finishing_cost; ///< 表面处理成本
double overhead; ///< 管理/间接费用
double total_cost; ///< 总成本
std::string currency; ///< 币种
MaterialInfo material; ///< 材料信息
};
// ═══════════════════════════════════════════════════════════
// 综合质量评分
// ═══════════════════════════════════════════════════════════
/// 质量评分报告
struct QualityReport {
double geometric_score; ///< 几何质量 [0, 100] — 连续性、公差
double rule_score; ///< 规则检查得分 [0, 100]
double dfm_score; ///< 可制造性得分 [0, 100]
double cost_score; ///< 成本效益得分 [0, 100]
double overall_score; ///< 综合质量评分 [0, 100]
std::string grade; ///< 评级: A(≥90) B(≥75) C(≥60) D(<60)
std::vector<std::string> recommendations; ///< 改进建议
};
// ═══════════════════════════════════════════════════════════
// 函数声明
// ═══════════════════════════════════════════════════════════
/**
* @brief 设计规则检查(DRC
*
* 对 BrepModel 执行一组设计规则检查。
* 如果 rules 为空,使用默认规则集(壁厚、最小圆角、拔模角等)。
*
* @param body BrepModel
* @param rules 规则列表(空 = 默认规则)
* @return DRCReport
*
* @ingroup brep
*/
DRCRreport design_rule_check(const BrepModel& body,
const std::vector<DesignRule>& rules = {});
/**
* @brief 可制造性分析(DFM
*
* 根据指定工艺评估设计的可制造性。
*
* @param body BrepModel
* @param process 目标制造工艺
* @return MfgReport
*
* @ingroup brep
*/
MfgReport manufacturability_analysis(const BrepModel& body,
ManufacturingProcess process);
/**
* @brief 成本估算
*
* 基于零件体积和材料估算制造成本。
*
* @param body BrepModel
* @param material 材料信息
* @return CostEstimate
*
* @ingroup brep
*/
CostEstimate cost_estimation(const BrepModel& body,
const MaterialInfo& material);
/**
* @brief 综合质量评分
*
* 综合几何质量、规则检查、可制造性、成本效益,
* 给出 0-100 分质量评分与改进建议。
*
* @param body BrepModel
* @return QualityReport
*
* @ingroup brep
*/
QualityReport quality_score(const BrepModel& body);
/**
* @brief 获取默认设计规则集
*
* 包括:最小壁厚、最小圆角半径、拔模角、最小孔直径、
* 最大纵横比、最小特征尺寸等通用工程规则。
*
* @return 默认规则列表
*/
std::vector<DesignRule> default_design_rules();
/**
* @brief 获取常用材料库
*
* @return 常用工程材料列表
*/
std::vector<MaterialInfo> material_library();
} // namespace vde::brep