Files
hm caf3ebae68 补齐 DIN/BSI/GOST 内置标准列表(D-09 尾项)
vde_drafting:
- 新增 DinStandard(DIN 6771 / DIN ISO 128):DIMTXT/DIMASZ 3.5、第一角、
  公制、小数位 2、线宽组 0.35/0.50/0.70,含 description/preferred_scales/
  paper_size_spec(DIN 476)。
- builtin_style 支持 DIN;registry 增加 din 条目(共 7 项);find 与
  is_valid_standard 归一化大小写、版本后缀("DIN:2006" 等)并把对外名称
  "BSI" 归一为注册 id "bs";standard_description 走归一化解析。
- GOST 样式对齐 GOST:2006 标准族:箭头 3.5、字宽比 1.0、线宽 0.30/0.60;
  BS 样式对齐 BSI:2020:箭头 3.5、字宽比 1.0、线宽 0.25/0.50。

brep/auto_dimensioning:
- standard_defaults 的 DIN/BS/GOST 箭头尺寸 3.0 → 3.5(DIMASZ 契约)。
- dimension_standards 支持 "BSI" 与版本后缀名称("DIN:2006"/"GOST:2006"
  等),未知名称仍回退 ISO。

测试:
- 新增 tests/drafting/test_drawing_standards_profiles.cpp(12 项断言:DIN/
  BSI/GOST 指标、名称解析、registry、以名切换)。
- test_auto_dimensioning 追加 DIN/BS/GOST 默认值与名称解析、ISO/ANSI/JIS
  默认值回归断言。

回归:ISO/ANSI/JIS 默认样式与既有黄金字节不变(drawing_sheet、
drafting_intelligence、layer_standards、tolerance_chain、auto_dimensioning、
constraint_solver_3d、dwg_tables、dxf_tables、dwg_writer 全绿)。
2026-11-17 21:21:53 +08:00

819 lines
34 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
/**
* @file drawing_standards.h
* @brief 工程制图标准 — ISO 128/129、ASME Y14.5、JIS B 0001、GB/T 4458、
* BS 8888、DIN 6771、GOST 2.305
*
* 提供主流制图标准的完整规则配置:
* - IsoStandard: ISO 128/129(线型/字体/箭头/公差格式)
* - AnsiStandard: ASME Y14.5-2018(尺寸与公差标注)
* - JisStandard: JIS B 0001(机械制图)
* - GbStandard: GB/T 4458(中国机械制图)
* - BsStandard: BS 8888:2020(英国技术产品文档)
* - DinStandard: DIN 6771 / DIN ISO 128(德国制图)
* - GostStandard: GOST R 2.305-2008(俄罗斯 ЕСКД)
*
* 支持一键应用标准(apply_standard/apply_standard_by_name)
* 自动配置尺寸样式、视图投影角度(第一角/第三角)
*
* @ingroup brep
*/
#include <string>
#include <vector>
#include <sstream>
#include <optional>
#include <utility>
// ProjectionView 定义在 brep/brep_drawing.h 中,drafting 需要使用它
#include "vde/brep/brep_drawing.h"
namespace vde::drafting {
// Import ProjectionView from brep namespace (defined in brep_drawing.h)
using brep::ProjectionView;
// ═══════════════════════════════════════════════════════════
// 线型枚举
// ═══════════════════════════════════════════════════════════
/// 标准线型(对应 ISO 128-20 / ASME Y14.2 / JIS B 0001)
enum class LineType {
Continuous, ///< 实线(可见轮廓线)— ISO 01.1 / ASME visible
Dashed, ///< 虚线(隐藏线)— ISO 02.1 / ASME hidden
Chain, ///< 点划线(中心线)— ISO 04.1 / ASME center
DoubleChain, ///< 双点划线(假想线/相邻零件轮廓)— ISO 05.1
Dotted, ///< 点线 — ISO 07.1
ContinuousThin, ///< 细实线(尺寸线/指引线/剖面线)
ContinuousThick, ///< 粗实线(可见轮廓线,主视图)
ContinuousFreehand ///< 徒手线(断裂线)
};
/// 线型名称
[[nodiscard]] inline const char* line_type_name(LineType lt) {
switch (lt) {
case LineType::Continuous: return "Continuous";
case LineType::Dashed: return "Dashed";
case LineType::Chain: return "Chain";
case LineType::DoubleChain: return "DoubleChain";
case LineType::Dotted: return "Dotted";
case LineType::ContinuousThin: return "ContinuousThin";
case LineType::ContinuousThick: return "ContinuousThick";
case LineType::ContinuousFreehand: return "ContinuousFreehand";
}
return "Unknown";
}
// ═══════════════════════════════════════════════════════════
// 样式枚举
// ═══════════════════════════════════════════════════════════
/// 字体样式
enum class FontStyle {
Normal,
Italic,
Bold
};
/// 箭头样式
enum class ArrowStyle {
Filled, ///< 实心箭头(ISO/ANSI 默认)
Open, ///< 空心箭头(ISO 128-22 允许)
Oblique, ///< 斜线标记(建筑图常用)
Architectural, ///< 建筑标记(短线)
Dot, ///< 圆点
Integral ///< 积分标记(原点指示)
};
/// 公差格式
enum class ToleranceFormat {
None, ///< 无公差(仅基本尺寸)
Symmetric, ///< ±x 对称公差
Deviation, ///< 上下偏差(+x / -y)
Limits, ///< 极限尺寸(Max / Min)
Basic, ///< 基本尺寸(方框 — ASME Y14.5 理论正确尺寸)
Reference ///< 参考尺寸(圆括号 — 仅供参考)
};
/// 投影角度
enum class ProjectionAngle {
FirstAngle, ///< 第一角投影(ISO / JIS / GB)
ThirdAngle ///< 第三角投影(ASME / ANSI)
};
/// 尺寸单位
enum class DimensionUnit {
Millimeter,
Inch,
Centimeter
};
// ═══════════════════════════════════════════════════════════
// DimensionStyle — 尺寸样式
// ═══════════════════════════════════════════════════════════
/// 完整的尺寸标注样式配置
struct DimensionStyle {
// ── 文字 ──
double text_height = 3.5; ///< 文字高度(mm)
FontStyle text_font = FontStyle::Normal;
double text_width_factor = 0.7; ///< 文字宽高比
double text_gap = 0.5; ///< 文字与尺寸线间距
// ── 箭头 ──
double arrow_length = 3.5; ///< 箭头长度(mm)
double arrow_width = 1.0; ///< 箭头宽度(mm)
double arrow_angle = 15.0; ///< 箭头夹角(°)
ArrowStyle arrow_style = ArrowStyle::Filled;
// ── 线宽(mm)─ 对应 ISO 128 线宽系列 ──
double line_width_thin = 0.25; ///< 细线(尺寸线/指引线)
double line_width_thick = 0.50; ///< 粗线(可见轮廓线)
double line_width_medium = 0.35; ///< 中线(隐藏线)
// ── 尺寸界线 ──
double extension_line_offset = 1.0; ///< 尺寸界线起点偏移(mm)
double extension_line_extend = 2.0; ///< 尺寸界线超出(mm)
// ── 线型 ──
LineType visible_line = LineType::Continuous;
LineType hidden_line = LineType::Dashed;
LineType center_line = LineType::Chain;
LineType phantom_line = LineType::DoubleChain;
LineType dimension_line = LineType::ContinuousThin;
LineType leader_line = LineType::ContinuousThin;
LineType section_line = LineType::ContinuousThin;
LineType cutting_plane = LineType::DoubleChain;
// ── 公差 ──
ToleranceFormat tolerance_format = ToleranceFormat::None;
int decimal_places = 2; ///< 小数位数
double tolerance_upper = 0.0; ///< 上偏差(mm)
double tolerance_lower = 0.0; ///< 下偏差(mm)
bool show_trailing_zeros = true; ///< 显示末尾零(ASME 要求)
bool use_basic_box = true; ///< 基本尺寸方框
// ── 投影 ──
ProjectionAngle projection_angle = ProjectionAngle::FirstAngle;
// ── 单位 ──
DimensionUnit unit = DimensionUnit::Millimeter;
bool show_unit_symbol = false; ///< 是否标注 mm 符号
// ── 显示控制 ──
bool show_hidden_lines = true;
bool show_center_lines = true;
bool show_center_marks = true;
bool show_threads_simplified = true;
double center_mark_size = 3.0;
double gap_between_dimension_lines = 7.0; ///< 尺寸线间距
// ── 页面 ──
double drawing_scale = 1.0;
};
// ═══════════════════════════════════════════════════════════
// StandardOptions — 标准选项
// ═══════════════════════════════════════════════════════════
/// 应用标准时的配置选项
struct StandardOptions {
std::string paper_size = "A4"; ///< 图纸大小 A0-A4, Letter等
double scale = 1.0; ///< 缩放比例
bool apply_to_dimensions = true; ///< 应用到尺寸标注
bool apply_to_views = true; ///< 应用到视图配置
std::string revision = "A"; ///< 修订版本
std::string title; ///< 图纸标题
std::string author; ///< 作者
};
// ═══════════════════════════════════════════════════════════
// 剖面线材质与样式(VDE-441)
// ═══════════════════════════════════════════════════════════
/**
* @brief 剖面线材质(决定剖面线角度/间距/线宽/是否交叉)
*
* 依据 GB/T 17450 / GB/T 4457.5 与 ISO 128-50 对常用工程材料
* 规定的剖面符号。
*/
enum class HatchMaterial {
Metal_General, ///< 金属(一般):45° 细实线
Metal_Steel, ///< 钢:45° 粗实线
NonMetal, ///< 非金属:135° 细实线
Plastic_Rubber, ///< 塑料/橡胶:交叉网格
Concrete, ///< 混凝土:交叉线(点+三角形近似)
Wood, ///< 木材:顺纹水平纹理线
Glass, ///< 玻璃:无剖面线(spacing = 0)
Liquid ///< 液体:水平细实线
};
/// 剖面线样式参数
struct HatchPattern {
double angle_deg = 45.0; ///< 剖面线倾角(°)
double spacing_mm = 3.0; ///< 线间距(mm);0 表示无剖面线
double line_width = 0.25; ///< 线宽(mm)
bool cross_hatch = false; ///< 是否双方向交叉剖面线
/// 是否为"无剖面线"样式(如玻璃)
[[nodiscard]] bool is_none() const { return spacing_mm <= 0.0; }
};
/// 按材质取标准剖面线样式(GB/T 17450 / ISO 128-50)
[[nodiscard]] HatchPattern get_standard_hatch(HatchMaterial material);
// ═══════════════════════════════════════════════════════════
// IsoStandard — ISO 128/129 标准
// ═══════════════════════════════════════════════════════════
/**
* @brief ISO 128/129 制图标准
*
* ISO 128: 技术制图的一般表示原则
* - Part 20: 线型基本规定(01-15系列线型编号)
* - Part 22: 指引线和参考线
* - Part 24: 机械工程制图用线
* - Part 30: 视图基本规定
* - Part 34: 机械工程制图视图
* - Part 40: 剖视图和断面图
* - Part 50: 尺寸标注
*
* ISO 129: 技术制图 — 尺寸和公差的标注方法
* - 线性尺寸标注规则
* - 角度尺寸标注规则
* - 圆弧半径/直径标注规则
*
* 默认配置:
* - 第一角投影
* - 文字高度 3.5mm(ISO 3098 B型)
* - 线宽系列 0.25/0.35/0.50mm
* - 空心箭头或实心填充箭头
*/
class IsoStandard {
public:
/// 创建 ISO 标准样式
[[nodiscard]] static DimensionStyle create_style();
/// ISO 标准描述
[[nodiscard]] static std::string description();
/// ISO 128 线宽系列(mm):0.13, 0.18, 0.25, 0.35, 0.5, 0.7, 1.0, 1.4, 2.0
/// @param group 线宽组索引 0-8
[[nodiscard]] static double line_width_group(int group);
/// ISO 128 线型编号名称
/// @param lt 线型
/// @return ISO 128 编号描述(如 "01.1" 表示连续细线)
[[nodiscard]] static std::string line_type_iso_name(LineType lt);
/// ISO 3098 字体尺寸系列
[[nodiscard]] static std::vector<double> text_height_series();
/// ISO 7200 标题栏尺寸(A4)
[[nodiscard]] static std::string title_block_spec();
};
// ═══════════════════════════════════════════════════════════
// AnsiStandard — ASME Y14.5 标准
// ═══════════════════════════════════════════════════════════
/**
* @brief ASME Y14.5-2018 尺寸与公差标注标准
*
* 核心规则:
* - 第三角投影
* - 英寸/毫米双单位支持
* - 包容原则(Rule #1: Envelope Principle)
* - 不依赖原则的独立标注(Rule #2)
* - MMC/LMC/RFS 材料条件修饰符
* - 基准参考框架(DRF)6个自由度约束
* - 特征控制框格式
*
* Y14.5 公差原则:
* - Form controls: Straightness, Flatness, Circularity, Cylindricity
* - Orientation: Parallelism, Perpendicularity, Angularity
* - Location: Position, Concentricity, Symmetry
* - Runout: Circular runout, Total runout
* - Profile: Profile of a line, Profile of a surface
*/
class AnsiStandard {
public:
/// 创建 ASME Y14.5 标准样式
[[nodiscard]] static DimensionStyle create_style();
/// ASME Y14.5 标准描述
[[nodiscard]] static std::string description();
/// 包容原则(Rule #1)是否默认启用
[[nodiscard]] static bool envelope_principle_default();
/// MMC(最大实体条件)是否默认标注
[[nodiscard]] static bool mmc_default();
/// ASME Y14.5 符号表
[[nodiscard]] static std::string gdt_symbols_summary();
/// 特征控制框格式规范
[[nodiscard]] static std::string feature_control_frame_format();
/// ASME Y14.2 线型对 ASME Y14.5 的映射
[[nodiscard]] static std::string line_type_spec(LineType lt);
};
// ═══════════════════════════════════════════════════════════
// JisStandard — JIS B 0001 标准
// ═══════════════════════════════════════════════════════════
/**
* @brief JIS B 0001 机械制图标准
*
* 核心规则:
* - 第一角投影(日本采用的投影法)
* - 公制单位(mm)
* - 表面粗糙度符号(▽ 旧/JIS B 0601 → Ra/Rz 新)
* - 焊接符号(JIS Z 3021)
* - 螺纹简化画法
* - JIS B 0401 公差等级
*
* 与 ISO 的对应关系:
* - JIS B 0001 积极向 ISO 128 靠拢
* - 尺寸标注规则与 ISO 129 基本一致
* - 表面粗糙度: JIS B 0601 (对应 ISO 1302)
*/
class JisStandard {
public:
/// 创建 JIS B 0001 标准样式
[[nodiscard]] static DimensionStyle create_style();
/// JIS B 0001 标准描述
[[nodiscard]] static std::string description();
/// JIS 表面粗糙度符号
[[nodiscard]] static std::string surface_texture_symbol();
/// JIS B 0001 推荐缩放比例
[[nodiscard]] static std::vector<double> preferred_scales();
/// JIS 公差等级对应(h7, H7 等)
[[nodiscard]] static std::string tolerance_grade_desc(const std::string& grade);
/// JIS B 0001 图纸尺寸系列(A0-A4 的毫米尺寸)
[[nodiscard]] static std::string paper_size_spec(const std::string& size_name);
};
// ═══════════════════════════════════════════════════════════
// Drawing(ProjectionView 已通过 brep_drawing.h 引入)
// ═══════════════════════════════════════════════════════════
struct DrawSegment;
// ═══════════════════════════════════════════════════════════
// GbStandard — GB/T 4458 / GB/T 18229 标准
// ═══════════════════════════════════════════════════════════
/**
* @brief GB/T 4458 / GB/T 18229 中国国家标准
*
* GB/T 4458.4-2003: 机械制图 — 尺寸注法
* GB/T 4458.5-2003: 机械制图 — 尺寸公差与配合注法
* GB/T 1182-2008: 产品几何技术规范(GPS) — 几何公差
* GB/T 18229-2000: CAD工程制图规则
*
* 核心规则:
* - 第一角投影(中国标准)
* - 公制单位(mm)
* - 字体:仿宋_GB2312,宽高比 0.7
* - 文字高度系列:2.5, 3.5, 5, 7, 10mm
* - 公差标注:上下偏差格式
*/
class GbStandard {
public:
/// 创建 GB/T 4458 标准样式
[[nodiscard]] static DimensionStyle create_style();
/// GB/T 4458 标准描述
[[nodiscard]] static std::string description();
/// GB/T 18229 字体规范
[[nodiscard]] static std::string font_spec();
/// GB/T 4458 公差格式规范
[[nodiscard]] static std::string tolerance_format_spec();
/// GB/T 14691 文字高度系列 (2.5, 3.5, 5, 7, 10)
[[nodiscard]] static std::vector<double> text_height_series();
/// GB/T 4458.4-2003 尺寸标注
[[nodiscard]] static DimensionStyle create_4458();
/// GB/T 18229-2000 CAD图层
[[nodiscard]] static DimensionStyle create_18229();
};
// ═══════════════════════════════════════════════════════════
// GostStandard — GOST R 2.305 标准 (VDE-395)
// ═══════════════════════════════════════════════════════════
/**
* @brief GOST R 2.305-2008 俄罗斯国家标准
*
* Единая система конструкторской документации (ЕСКД)
*
* 核心规则:
* - 第一角投影
* - 公制单位 (mm)
* - 字体 GOST 2.304-81 Type A
* - 偏差格式公差标注
*/
class GostStandard {
public:
[[nodiscard]] static DimensionStyle create_style();
[[nodiscard]] static std::string description();
[[nodiscard]] static std::string font_spec();
[[nodiscard]] static std::vector<double> preferred_scales();
[[nodiscard]] static std::string paper_size_spec(const std::string& size_name);
};
// ═══════════════════════════════════════════════════════════
// BsStandard — BS 8888 标准
// ═══════════════════════════════════════════════════════════
/**
* @brief BS 8888 英国技术产品规范标准
*
* BS 8888:2020 — Technical product documentation and specification
*
* 核心规则:
* - 第一角投影(英制标准)
* - 公制单位(mm),允许英寸辅助
* - 箭头:实心填充
* - 公差:对称/偏差格式
* - 配合 ISO 128/129 框架
*/
class BsStandard {
public:
/// 创建 BS 8888 标准样式
[[nodiscard]] static DimensionStyle create_style();
/// BS 8888 标准描述
[[nodiscard]] static std::string description();
/// BS 8888 推荐缩放比例
[[nodiscard]] static std::vector<double> preferred_scales();
/// BS EN ISO 5457 图纸尺寸信息
[[nodiscard]] static std::string paper_size_spec(const std::string& size_name);
};
// ═══════════════════════════════════════════════════════════
// DinStandard — DIN 6771 / DIN ISO 128 标准 (D-09 尾项)
// ═══════════════════════════════════════════════════════════
/**
* @brief DIN 6771 / DIN ISO 128 德国制图标准
*
* DIN 6771-1 标题栏、DIN 476 图幅、DIN ISO 128 制图规则,尺寸标注
* 按 DIN ISO 129-1。样式指标与宿主 DIN:2006 标准族规格对齐:
* - 第一角投影,公制单位(mm)
* - 字高 3.5 mm,实心箭头,箭头长 3.5 mm,文字宽度因子 1.0
* - 线宽组:细线 0.35 mm / 中线 0.50 mm / 粗线 0.70 mm(DIN ISO 128-20)
* - A 系列图幅(DIN 476):A0–A4
*/
class DinStandard {
public:
/// 创建 DIN 6771 / DIN ISO 128 标准样式
[[nodiscard]] static DimensionStyle create_style();
/// DIN 制图标准描述
[[nodiscard]] static std::string description();
/// DIN 6776 推荐缩放比例
[[nodiscard]] static std::vector<double> preferred_scales();
/// DIN 476 图纸尺寸信息
[[nodiscard]] static std::string paper_size_spec(const std::string& size_name);
};
// ═══════════════════════════════════════════════════════════
// 增强验证 — 结构化诊断
// ═══════════════════════════════════════════════════════════
/// 验证严重程度
enum class ValidationSeverity {
Info, ///< 信息性提示
Warning, ///< 非关键警告
Error, ///< 标准违反
Critical ///< 严重违反(阻止导出)
};
/// 样式违反详情
struct StyleViolation {
std::string field; ///< 字段名("text_height", "arrow_style", "projection_angle")
ValidationSeverity severity = ValidationSeverity::Info;
std::string message; ///< 人类可读消息
std::string observed; ///< 观察值
std::string expected; ///< 期望值
std::string fix_suggestion; ///< 修复建议
bool auto_fixable = false; ///< 是否可自动修复
};
/// 结构化验证报告
struct StyleValidationReport {
std::string standard_name; ///< 标准名称
std::vector<StyleViolation> violations; ///< 违反列表
int total_checks = 0; ///< 总检查项数
double pass_rate = 1.0; ///< 通过率 (0.0-1.0)
/// 序列化为 JSON
[[nodiscard]] std::string to_json() const;
};
// ═══════════════════════════════════════════════════════════
// 标准注册表
// ═══════════════════════════════════════════════════════════
namespace standards {
/// 标准元信息
struct StandardInfo {
std::string id; ///< "iso", "ansi", "jis", "gb", "bs", "din", "gost"("bsi" 为 "bs" 的别名)
std::string name; ///< 显示名称
std::string description; ///< 简要描述
ProjectionAngle projection = ProjectionAngle::FirstAngle;
DimensionUnit preferred_unit = DimensionUnit::Millimeter;
std::vector<std::string> supported_paper_sizes; ///< 支持的图纸尺寸
};
/// 获取所有已注册标准的元信息列表
[[nodiscard]] std::vector<StandardInfo> registry();
/// 按 ID 查找标准
[[nodiscard]] std::optional<StandardInfo> find(const std::string& id);
/// 检查标准 ID 是否有效
[[nodiscard]] bool is_valid_standard(const std::string& id);
// ═══════════════════════════════════════════════════════════
// VDE-395 §2: 自定义(企业)标准
// ═══════════════════════════════════════════════════════════
/**
* @brief 自定义(企业)标准注册表
*
* 允许用户以 id + DimensionStyle 注册公司专用标准,并参与
* `drawing::apply_standard_by_name` 解析。
*/
class CustomStandard {
public:
/// 注册/覆盖一个自定义标准;返回其元信息
static StandardInfo register_custom(const std::string& id, const DimensionStyle& style);
/// 注销自定义标准(不存在时无操作)
static void unregister(const std::string& id);
/// 列出全部自定义标准(按 id 升序)
static std::vector<StandardInfo> list_custom();
/// 取自定义标准样式(不存在返回 nullopt)
[[nodiscard]] static std::optional<DimensionStyle> style_of(const std::string& id);
};
// ═══════════════════════════════════════════════════════════
// VDE-395 §3: 标准差异比较
// ═══════════════════════════════════════════════════════════
/// 两个标准的逐字段差异
struct StandardsDiff {
std::vector<std::string> changed_fields; ///< 变化字段名(有序)
std::vector<std::pair<std::string, std::string>> value_differences; ///< {field, "old -> new"}
[[nodiscard]] bool empty() const { return changed_fields.empty(); }
};
/// 比较两个标准(名称或自定义 id)的每一个尺寸样式字段
[[nodiscard]] StandardsDiff diff_standards(const std::string& a, const std::string& b);
} // namespace standards
/// 制图标准命名空间
namespace drawing {
/// 应用标准后的制图上下文
struct DrawingContext {
std::vector<ProjectionView> views;
DimensionStyle style;
StandardOptions options;
std::string standard_name; ///< 标准名("ISO"/"ANSI"/"JIS"/"GB"/"BS"/"BSI"/"DIN"/"GOST",可带版本后缀)
ProjectionAngle view_projection = ProjectionAngle::FirstAngle;
};
/**
* @brief 一键应用标准到制图
*
* 根据标准自动配置:
* - 尺寸样式
* - 视图投影角度(第一角/第三角)
* - 线型/字体/箭头样式
*
* @param views 制图视图
* @param style 样式配置
* @param options 标准选项
* @return DrawingContext 应用后的制图上下文
*/
[[nodiscard]] DrawingContext apply_standard(
const std::vector<ProjectionView>& views,
const DimensionStyle& style,
const StandardOptions& options);
/**
* @brief 按标准名称一键应用
*
* @param views 制图视图
* @param standard_name 标准名(大小写不敏感):"ISO"/"ANSI"/"JIS"/"GB"/
* "BS"/"BSI"/"DIN"/"GOST";可带版本后缀(如 "DIN:2006")
* @param options 标准选项
* @return DrawingContext
*/
[[nodiscard]] DrawingContext apply_standard_by_name(
const std::vector<ProjectionView>& views,
const std::string& standard_name,
const StandardOptions& options);
/// 验证样式是否符合指定标准
[[nodiscard]] std::vector<std::string> validate_style(
const DimensionStyle& style, const std::string& standard_name);
/// 结构化验证:返回详细的 StyleValidationReport(含严重程度、修复建议)
[[nodiscard]] StyleValidationReport validate_style_detailed(
const DimensionStyle& style, const std::string& standard_name);
/// 列出所有支持的内置标准(ISO/ANSI/DIN/JIS/BSI/GOST/GB)
[[nodiscard]] std::vector<std::string> available_standards();
/// 获取标准描述(支持标准 id、显示名与版本后缀,如 "DIN" / "din" / "DIN:2006")
[[nodiscard]] std::string standard_description(const std::string& standard_name);
// ═══════════════════════════════════════════════════════════
// VDE-395: real_time_std_switch + standard_compliance_check
// ═══════════════════════════════════════════════════════════
/**
* @brief 预览切换到目标标准后会发生变化的字段(不提交)— VDE-395 §1
*
* 逐字段比较 `current` 与目标标准的内置/自定义样式,返回人类可读的
* "field: old -> new" 列表;两标准一致时为空。
*
* @param current 当前尺寸样式
* @param target_standard 目标标准名(ISO/ANSI/… 或自定义 id)
* @return 变化描述列表
*/
[[nodiscard]] std::vector<std::string> preview_changes(
const DimensionStyle& current, const std::string& target_standard);
/**
* @brief Real-time standard switching manager
*/
class RealTimeStdSwitch {
public:
RealTimeStdSwitch();
/// Switch to a different standard
bool switch_to(const std::string& standard_name);
/// Get current dimension style
[[nodiscard]] DimensionStyle current_style() const;
/// Get current standard name
[[nodiscard]] std::string current_standard() const;
/// Get switch count
[[nodiscard]] int switch_count() const;
/// Preview what switching to `standard_name` would change (no commit)
[[nodiscard]] std::vector<std::string> preview_changes(const std::string& standard_name) const;
/// Apply current standard to views
void apply_to_views(std::vector<ProjectionView>& views);
private:
std::string current_standard_;
DimensionStyle current_style_;
int switch_count_ = 0;
};
/// Comprehensive standard compliance check
/// @param style Dimension style to check
/// @param standard_name Target standard name
/// @return Structured validation report
[[nodiscard]] StyleValidationReport standard_compliance_check(
const DimensionStyle& style, const std::string& standard_name);
// ═══════════════════════════════════════════════════════════
// VDE-395 §4: 标准图纸模板(图框 + 标题栏)
// ═══════════════════════════════════════════════════════════
/// 2D 图纸线段(mm)
struct Segment {
double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0;
};
/// 标准图纸模板
struct SheetTemplate {
double width = 0.0; ///< 图纸宽 (mm)
double height = 0.0; ///< 图纸高 (mm)
std::vector<Segment> border; ///< 外图框线段
std::vector<Segment> title_block; ///< 标题栏线段
};
/**
* @brief 按标准与图纸规格生成图框 + 标题栏(ISO 7200 / ASME Y14.1 / JIS B 0001)
*
* @param standard_name 标准名(ISO/ANSI/JIS/GB/BS/GOST)
* @param paper_size 图纸规格(A0-A4 / Letter;未知时按 A4)
* @return 图纸模板
*/
[[nodiscard]] SheetTemplate generate_sheet_template(
const std::string& standard_name, const std::string& paper_size);
} // namespace drawing
// ═══════════════════════════════════════════════════════════
// VDE B-5:制图标准合规检查器(GB/ISO/ASME 基础规则 10 类)
// ═══════════════════════════════════════════════════════════
/// 合规规则编号(每条规则一个 id,可单独检出/定位/建议)
enum class DraftingRuleId {
DimensionLineSpacing, ///< R1 尺寸线间距小于标准值
ArrowLength, ///< R2 箭头长度不在标准范围
ArrowWidthRatio, ///< R3 箭头宽/长比不在标准范围
TextHeightSeries, ///< R4 字高不在标准字高系列
TextOrientation, ///< R5 文字方向非 0°/90°
MissingLayer, ///< R6 引用了未定义图层
LineWidthMapping, ///< R7 图层线宽与用途映射不符
LineTypeMapping, ///< R8 线型与用途映射不符(如虚线用实线)
UnitSuffix, ///< R9 非毫米单位缺单位后缀(或毫米图多余后缀)
TextEmpty, ///< R10 尺寸文本为空
};
/// 规则 id 名称("R1".."R10")
[[nodiscard]] const char* drafting_rule_id_name(DraftingRuleId id);
/// 待检查的尺寸标注条目(图纸坐标系,mm)
struct DraftingDimensionEntry {
std::string id;
double x = 0.0, y = 0.0;
std::string text; ///< 尺寸文本(不含前后缀时用于单位后缀检查)
double text_height = 3.5;
double angle_deg = 0.0;
double arrow_length = 3.5;
double arrow_width = 1.0;
double line_spacing_to_prev = 10.0;
std::string layer; ///< 所属图层名
};
/// 图层定义(用途 → 期望线型/线宽映射)
struct DraftingLayerDef {
std::string name;
std::string role; ///< "visible"/"hidden"/"center"/"dimension"/"leader"
std::string line_type; ///< 实际线型名("Continuous"/"Dashed"/"Chain"...)
double line_width = 0.25;
};
/// 待检查图纸样本
struct DraftingStandardSample {
int standard = 0; ///< 0=ISO 1=ASME 2=JIS 3=DIN 4=GB 5=BS 6=GOST
std::vector<DraftingDimensionEntry> dimensions;
std::vector<DraftingLayerDef> layers;
bool unit_mm = true; ///< true=毫米图纸(不标单位),false=英寸(必须标单位)
// 标准限值(可按标准覆盖;默认 ISO/GB 常用值)
double min_line_spacing = 7.0;
double arrow_length_min = 2.5;
double arrow_length_max = 4.5;
double arrow_ratio_min = 0.25;
double arrow_ratio_max = 0.45;
double text_height_min = 2.5;
double text_height_max = 5.0;
std::vector<double> text_height_series = {1.8, 2.5, 3.5, 5.0, 7.0};
};
/// 单条违规(规则 id / 位置 / 建议)
struct DraftingViolation {
DraftingRuleId rule = DraftingRuleId::TextEmpty;
std::string rule_id; ///< "R1".."R10"
std::string element_id; ///< 违规尺寸条目 id
double x = 0.0, y = 0.0; ///< 位置(图纸坐标)
std::string message;
std::string suggestion;
};
/// 合规检查报告
struct DraftingComplianceReport {
std::string standard_name;
int checked_dimensions = 0;
int checked_rules = 10;
std::vector<DraftingViolation> violations;
[[nodiscard]] bool ok() const { return violations.empty(); }
[[nodiscard]] std::string to_string() const;
};
/**
* @brief 制图标准合规检查(10 类基础规则)
*
* 对每个尺寸条目检查:尺寸线间距、箭头长度、箭头宽长比、字高系列、文字方向、
* 图层存在性、图层线宽/线型映射、单位后缀、空文本。返回违规列表(规则 id、
* 条目 id、位置、建议),合规图纸返回空列表(0 误报)。
*/
[[nodiscard]] DraftingComplianceReport check_drafting_compliance(
const DraftingStandardSample& sample);
} // namespace vde::drafting