#pragma once /** * @file drawing_standards.h * @brief 工程制图标准 — ISO 128/129, ASME Y14.5, JIS B 0001 * * 提供三大国际制图标准的完整规则配置: * - IsoStandard: ISO 128/129(线型/字体/箭头/公差格式) * - AnsiStandard: ASME Y14.5-2018(尺寸与公差标注) * - JisStandard: JIS B 0001(机械制图) * * 支持一键应用标准(apply_standard/apply_standard_by_name) * 自动配置尺寸样式、视图投影角度(第一角/第三角) * * @ingroup brep */ #include #include #include namespace vde::brep { // ═══════════════════════════════════════════════════════════ // 线型枚举 // ═══════════════════════════════════════════════════════════ /// 标准线型(对应 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; ///< 作者 }; // ═══════════════════════════════════════════════════════════ // 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 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 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(前向声明) // ═══════════════════════════════════════════════════════════ struct DrawSegment; struct ProjectionView; /// 制图标准命名空间 namespace drawing { /// 应用标准后的制图上下文 struct DrawingContext { std::vector views; DimensionStyle style; StandardOptions options; std::string standard_name; ///< "ISO", "ANSI", "JIS" ProjectionAngle view_projection = ProjectionAngle::FirstAngle; }; /** * @brief 一键应用标准到制图 * * 根据标准自动配置: * - 尺寸样式 * - 视图投影角度(第一角/第三角) * - 线型/字体/箭头样式 * * @param views 制图视图 * @param style 样式配置 * @param options 标准选项 * @return DrawingContext 应用后的制图上下文 */ [[nodiscard]] DrawingContext apply_standard( const std::vector& views, const DimensionStyle& style, const StandardOptions& options); /** * @brief 按标准名称一键应用 * * @param views 制图视图 * @param standard_name "ISO", "ANSI", "JIS" * @param options 标准选项 * @return DrawingContext */ [[nodiscard]] DrawingContext apply_standard_by_name( const std::vector& views, const std::string& standard_name, const StandardOptions& options); /// 验证样式是否符合指定标准 [[nodiscard]] std::vector validate_style( const DimensionStyle& style, const std::string& standard_name); /// 列出所有支持的标准 [[nodiscard]] std::vector available_standards(); /// 获取标准描述 [[nodiscard]] std::string standard_description(const std::string& standard_name); } // namespace drawing } // namespace vde::brep