231 lines
8.9 KiB
C++
231 lines
8.9 KiB
C++
|
|
#pragma once
|
|||
|
|
/**
|
|||
|
|
* @file auto_dimensioning.h
|
|||
|
|
* @brief Automatic dimensioning and drawing standards
|
|||
|
|
*
|
|||
|
|
* Automatically generates linear, angular, radius/diameter dimensions
|
|||
|
|
* from B-Rep models. Supports ISO, ANSI, and JIS drawing standards.
|
|||
|
|
*
|
|||
|
|
* @ingroup brep
|
|||
|
|
*/
|
|||
|
|
#include "vde/brep/brep.h"
|
|||
|
|
#include "vde/core/point.h"
|
|||
|
|
#include <vector>
|
|||
|
|
#include <string>
|
|||
|
|
#include <map>
|
|||
|
|
|
|||
|
|
namespace vde::brep {
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// Drawing Standard
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
/// Drawing standard enumeration
|
|||
|
|
enum class DrawingStandard {
|
|||
|
|
ISO, ///< ISO 129 / ISO 1101
|
|||
|
|
ANSI, ///< ANSI Y14.5 / ASME Y14.5
|
|||
|
|
JIS, ///< JIS B 0001 / JIS B 0021
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// Dimension Types
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
/// Dimension type enumeration
|
|||
|
|
enum class DimensionType {
|
|||
|
|
Linear, ///< Distance between parallel edges
|
|||
|
|
Angular, ///< Angle between non-parallel edges
|
|||
|
|
Radius, ///< Arc/circle radius
|
|||
|
|
Diameter, ///< Circle diameter
|
|||
|
|
Ordinate, ///< Ordinate dimension (baseline)
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// Material condition modifier for dimensions
|
|||
|
|
enum class MaterialCondition {
|
|||
|
|
RFS, ///< Regardless of Feature Size (default)
|
|||
|
|
MMC, ///< Maximum Material Condition
|
|||
|
|
LMC, ///< Least Material Condition
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// Dimension Data Structures
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
/// A single dimension annotation
|
|||
|
|
struct Dimension {
|
|||
|
|
DimensionType type = DimensionType::Linear;
|
|||
|
|
double value = 0.0; ///< Nominal dimension value
|
|||
|
|
double tolerance_upper = 0.0; ///< Upper tolerance deviation
|
|||
|
|
double tolerance_lower = 0.0; ///< Lower tolerance deviation
|
|||
|
|
MaterialCondition mat_condition = MaterialCondition::RFS;
|
|||
|
|
|
|||
|
|
/// 2D placement position (in view coordinates)
|
|||
|
|
core::Point3D text_position;
|
|||
|
|
|
|||
|
|
/// Reference points (2 in view coordinates for linear/angular, center for radial)
|
|||
|
|
std::vector<core::Point3D> reference_points;
|
|||
|
|
|
|||
|
|
/// IDs of associated B-Rep edges/faces
|
|||
|
|
std::vector<int> associated_edges;
|
|||
|
|
std::vector<int> associated_faces;
|
|||
|
|
|
|||
|
|
/// Dimension text override (empty = auto-generated from value)
|
|||
|
|
std::string text_override;
|
|||
|
|
|
|||
|
|
/// View this dimension belongs to
|
|||
|
|
std::string view_name;
|
|||
|
|
|
|||
|
|
/// Prefix/suffix for dimension text
|
|||
|
|
std::string prefix; ///< e.g. "Ø", "R", "2×"
|
|||
|
|
std::string suffix; ///< e.g. " THRU", " TYP"
|
|||
|
|
|
|||
|
|
/// Check if this dimension has tolerance
|
|||
|
|
[[nodiscard]] bool has_tolerance() const {
|
|||
|
|
return tolerance_upper != 0.0 || tolerance_lower != 0.0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// Get formatted dimension text
|
|||
|
|
[[nodiscard]] std::string to_text() const;
|
|||
|
|
|
|||
|
|
/// Get dimension text suitable for DXF
|
|||
|
|
[[nodiscard]] std::string to_dxf_text() const;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// Drawing Configuration
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
/// Standard-specific configuration parameters
|
|||
|
|
struct StandardConfig {
|
|||
|
|
DrawingStandard standard = DrawingStandard::ISO;
|
|||
|
|
double text_height = 3.5; ///< Default text height (mm)
|
|||
|
|
double arrow_size = 3.0; ///< Arrow size (mm)
|
|||
|
|
double extension_line_offset = 1.0; ///< Offset from feature to extension line start
|
|||
|
|
double extension_line_overshoot = 2.0; ///< Overshoot beyond dimension line
|
|||
|
|
double dimension_line_spacing = 10.0; ///< Spacing between dimension lines
|
|||
|
|
double baseline_spacing = 7.0; ///< Spacing for baseline dimensions
|
|||
|
|
std::string unit = "mm"; ///< Default unit
|
|||
|
|
int decimal_places = 2; ///< Number of decimal places
|
|||
|
|
bool trailing_zeros = false; ///< Show trailing zeros (ANSI)
|
|||
|
|
bool leading_zero = true; ///< Show leading zero (ISO)
|
|||
|
|
|
|||
|
|
/// Get standard name
|
|||
|
|
[[nodiscard]] std::string standard_name() const;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// Drawing settings container for standard compliance
|
|||
|
|
struct DrawingSettings {
|
|||
|
|
StandardConfig config;
|
|||
|
|
std::vector<Dimension> dimensions;
|
|||
|
|
std::string title;
|
|||
|
|
std::string drawing_number;
|
|||
|
|
std::string revision;
|
|||
|
|
double scale = 1.0;
|
|||
|
|
std::string projection_method = "first"; ///< "first" or "third" angle projection
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// Auto-Dimensioning API
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Automatically generate dimensions from a B-Rep model
|
|||
|
|
*
|
|||
|
|
* Detects linear distances (parallel edges), angles (non-parallel edges),
|
|||
|
|
* radius/diameter (arcs/circles), and places them intelligently to avoid
|
|||
|
|
* overlap based on the given view direction.
|
|||
|
|
*
|
|||
|
|
* @param model B-Rep model to dimension
|
|||
|
|
* @param view_direction View direction for dimension placement
|
|||
|
|
* @return Vector of auto-generated dimensions
|
|||
|
|
*/
|
|||
|
|
[[nodiscard]] std::vector<Dimension> auto_dimension(
|
|||
|
|
const BrepModel& model,
|
|||
|
|
const core::Vector3D& view_direction);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Auto-dimension with configuration control
|
|||
|
|
*
|
|||
|
|
* @param model B-Rep model
|
|||
|
|
* @param view_direction View direction
|
|||
|
|
* @param config Drawing standard configuration
|
|||
|
|
* @return Vector of dimensions
|
|||
|
|
*/
|
|||
|
|
[[nodiscard]] std::vector<Dimension> auto_dimension_with_config(
|
|||
|
|
const BrepModel& model,
|
|||
|
|
const core::Vector3D& view_direction,
|
|||
|
|
const StandardConfig& config);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Apply a drawing standard to a set of dimensions
|
|||
|
|
*
|
|||
|
|
* Formats dimensions according to ISO/ANSI/JIS standards,
|
|||
|
|
* adjusting tolerances, decimal places, text positions, etc.
|
|||
|
|
*
|
|||
|
|
* @param drawing Drawing settings to modify
|
|||
|
|
* @param standard Target standard
|
|||
|
|
*/
|
|||
|
|
void apply_standard(DrawingSettings& drawing, DrawingStandard standard);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Apply standard with custom overrides
|
|||
|
|
*
|
|||
|
|
* @param drawing Drawing settings to modify
|
|||
|
|
* @param standard Target standard
|
|||
|
|
* @param overrides Custom config values merged with standard defaults
|
|||
|
|
*/
|
|||
|
|
void apply_standard_with_overrides(DrawingSettings& drawing,
|
|||
|
|
DrawingStandard standard,
|
|||
|
|
const StandardConfig& overrides);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Get default configuration for a drawing standard
|
|||
|
|
*
|
|||
|
|
* @param standard The standard
|
|||
|
|
* @return Default StandardConfig
|
|||
|
|
*/
|
|||
|
|
[[nodiscard]] StandardConfig standard_defaults(DrawingStandard standard);
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// Dimension Placement Helpers
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Place dimensions avoiding overlaps (smart placement)
|
|||
|
|
*
|
|||
|
|
* Rearranges dimension text positions so they don't overlap.
|
|||
|
|
*
|
|||
|
|
* @param dimensions Dimensions to arrange (modified in-place)
|
|||
|
|
* @param view_direction View direction for projection
|
|||
|
|
*/
|
|||
|
|
void smart_placement(std::vector<Dimension>& dimensions,
|
|||
|
|
const core::Vector3D& view_direction);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Create baseline dimensions from reference face
|
|||
|
|
*
|
|||
|
|
* @param model B-Rep model
|
|||
|
|
* @param reference_face_id Reference face for baseline
|
|||
|
|
* @param view_direction View direction
|
|||
|
|
* @return Vector of ordinate dimensions from baseline
|
|||
|
|
*/
|
|||
|
|
[[nodiscard]] std::vector<Dimension> baseline_dimensions(
|
|||
|
|
const BrepModel& model,
|
|||
|
|
int reference_face_id,
|
|||
|
|
const core::Vector3D& view_direction);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Create chain dimensions along a feature
|
|||
|
|
*
|
|||
|
|
* @param model B-Rep model
|
|||
|
|
* @param face_ids Sequence of face IDs to chain
|
|||
|
|
* @param view_direction View direction
|
|||
|
|
* @return Vector of chained dimensions
|
|||
|
|
*/
|
|||
|
|
[[nodiscard]] std::vector<Dimension> chain_dimensions(
|
|||
|
|
const BrepModel& model,
|
|||
|
|
const std::vector<int>& face_ids,
|
|||
|
|
const core::Vector3D& view_direction);
|
|||
|
|
|
|||
|
|
} // namespace vde::brep
|