STEP export: unique ids, plain curves, right revolution senses; seams on split faces
Vendored truck-stepio (writer only): an intersection curve's second surface was written at the first one's id (duplicate ids for every boolean edge), and revolved surfaces lost their orientation (the modeling-surface sense was always true; inverted or mirrored revolutions came out inside out). Export now writes intersection edges as C1 cubic B-splines through exact points, so files carry plain 3D curves and no redundant surfaces. Vendored truck-meshalgo: hinted parameter searches that run off a B-spline's domain are rejected or clamped (meshing their grid never finished). STEP import: straight revolution profiles are bounded in the meridian plane and stop at the axis; loops on revolutions start away from the axis; face extents include edge end points. Edges between pieces of one split surface draw as seams. kernel::step_validate checks a STEP file (duplicate ids, dangling references, dense numbering); the oracle replay now exports every rebuilt part, validates it and re-imports it with no warnings and the same volume (all 32 rebuildable cases pass). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AS5Tn3xieewUSg3uxrMVdL
This commit is contained in:
1 parent
32e6b2a578
commit
08cf223ced
47 files changed
+10677
-39
No files matched your search
Vendored
+397
@@ -0,0 +1,397 @@
|
||||
use crate::{self as truck_stepio};
|
||||
use derive_more::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use truck_derivers::{DisplayByStep, StepCurve, StepLength, StepSurface};
|
||||
|
||||
/// re-export structs in `truck-geometry` and `truck-polymesh`.
|
||||
pub mod re_exports {
|
||||
pub use truck_geometry::prelude::*;
|
||||
pub use truck_polymesh::*;
|
||||
}
|
||||
pub use re_exports::*;
|
||||
|
||||
/// Errors that occur when converting STEP format
|
||||
pub type StepConvertingError = Box<dyn std::error::Error>;
|
||||
|
||||
/// `ellipse`, realized in `truck`
|
||||
pub type Ellipse<P, M> = Processor<TrimmedCurve<UnitCircle<P>>, M>;
|
||||
/// `hyperbola`, realized in `truck`
|
||||
pub type Hyperbola<P, M> = Processor<TrimmedCurve<UnitHyperbola<P>>, M>;
|
||||
/// `parabola`, realized in `truck`
|
||||
pub type Parabola<P, M> = Processor<TrimmedCurve<UnitParabola<P>>, M>;
|
||||
/// `spherical_surface`, realized in `truck`
|
||||
pub type SphericalSurface = Processor<Sphere, Matrix4>;
|
||||
/// `cylindrical_surface`, realized in `truck`
|
||||
pub type CylindricalSurface = Processor<RevolutedCurve<Line<Point3>>, Matrix4>;
|
||||
/// `toroidal_surface`, realized in `truck`
|
||||
pub type ToroidalSurface = Processor<Torus, Matrix4>;
|
||||
/// `conical_surface`, realized in `truck`
|
||||
pub type ConicalSurface = Processor<RevolutedCurve<Line<Point3>>, Matrix4>;
|
||||
/// `surface_of_linear_extrusion`, realized in `truck`
|
||||
pub type StepExtrudedCurve = ExtrudedCurve<Curve3D, Vector3>;
|
||||
/// `surface_of_revolution`, realized in `truck`
|
||||
pub type StepRevolutedCurve = Processor<RevolutedCurve<Curve3D>, Matrix4>;
|
||||
/// `pcurve`, realized in `truck`
|
||||
pub type PCurve = truck_geometry::prelude::PCurve<Box<Curve2D>, Box<Surface>>;
|
||||
|
||||
/// `conic` in 2D, realized in `truck`
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
PartialEq,
|
||||
From,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
ParametricCurve,
|
||||
BoundedCurve,
|
||||
Cut,
|
||||
Invertible,
|
||||
ParameterDivision1D,
|
||||
SearchParameterD1,
|
||||
SearchNearestParameterD1,
|
||||
TransformedM3,
|
||||
StepLength,
|
||||
DisplayByStep,
|
||||
StepCurve,
|
||||
)]
|
||||
pub enum Conic2D {
|
||||
Ellipse(Ellipse<Point2, Matrix3>),
|
||||
Hyperbola(Hyperbola<Point2, Matrix3>),
|
||||
Parabola(Parabola<Point2, Matrix3>),
|
||||
}
|
||||
|
||||
/// `curve` in 2D, realized in `truck`
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
PartialEq,
|
||||
From,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
ParametricCurve,
|
||||
BoundedCurve,
|
||||
Cut,
|
||||
Invertible,
|
||||
ParameterDivision1D,
|
||||
SearchParameterD1,
|
||||
SearchNearestParameterD1,
|
||||
TransformedM3,
|
||||
StepLength,
|
||||
DisplayByStep,
|
||||
StepCurve,
|
||||
)]
|
||||
|
||||
pub enum Curve2D {
|
||||
Line(Line<Point2>),
|
||||
Polyline(PolylineCurve<Point2>),
|
||||
Conic(Conic2D),
|
||||
BSplineCurve(BSplineCurve<Point2>),
|
||||
NurbsCurve(NurbsCurve<Vector3>),
|
||||
}
|
||||
|
||||
/// `conic` in 3D, realized in `truck`
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
PartialEq,
|
||||
From,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
ParametricCurve,
|
||||
BoundedCurve,
|
||||
Cut,
|
||||
Invertible,
|
||||
ParameterDivision1D,
|
||||
SearchParameterD1,
|
||||
SearchNearestParameterD1,
|
||||
TransformedM4,
|
||||
StepLength,
|
||||
DisplayByStep,
|
||||
StepCurve,
|
||||
)]
|
||||
pub enum Conic3D {
|
||||
Ellipse(Ellipse<Point3, Matrix4>),
|
||||
Hyperbola(Hyperbola<Point3, Matrix4>),
|
||||
Parabola(Parabola<Point3, Matrix4>),
|
||||
}
|
||||
|
||||
/// `curve` in 3D, realized in `truck`
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
PartialEq,
|
||||
From,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
ParametricCurve,
|
||||
BoundedCurve,
|
||||
Cut,
|
||||
Invertible,
|
||||
ParameterDivision1D,
|
||||
SearchParameterD1,
|
||||
SearchNearestParameterD1,
|
||||
TransformedM4,
|
||||
StepLength,
|
||||
DisplayByStep,
|
||||
StepCurve,
|
||||
)]
|
||||
pub enum Curve3D {
|
||||
Line(Line<Point3>),
|
||||
Polyline(PolylineCurve<Point3>),
|
||||
Conic(Conic3D),
|
||||
BSplineCurve(BSplineCurve<Point3>),
|
||||
PCurve(PCurve),
|
||||
NurbsCurve(NurbsCurve<Vector4>),
|
||||
}
|
||||
|
||||
/// `elementary_surface`, realized in `truck`
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
PartialEq,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
ParametricSurface3D,
|
||||
ParameterDivision2D,
|
||||
SearchParameterD2,
|
||||
SearchNearestParameterD2,
|
||||
Invertible,
|
||||
TransformedM4,
|
||||
StepLength,
|
||||
DisplayByStep,
|
||||
StepSurface,
|
||||
)]
|
||||
pub enum ElementarySurface {
|
||||
Plane(Plane),
|
||||
Sphere(SphericalSurface),
|
||||
CylindricalSurface(CylindricalSurface),
|
||||
ToroidalSurface(ToroidalSurface),
|
||||
ConicalSurface(ConicalSurface),
|
||||
}
|
||||
|
||||
/// `swept_surface`, realized in `truck`
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
PartialEq,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
ParametricSurface3D,
|
||||
ParameterDivision2D,
|
||||
SearchParameterD2,
|
||||
SearchNearestParameterD2,
|
||||
Invertible,
|
||||
TransformedM4,
|
||||
StepLength,
|
||||
DisplayByStep,
|
||||
StepSurface,
|
||||
)]
|
||||
pub enum SweptCurve {
|
||||
ExtrudedCurve(StepExtrudedCurve),
|
||||
RevolutedCurve(StepRevolutedCurve),
|
||||
}
|
||||
|
||||
/// `surface`, realized in `truck`
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
PartialEq,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
ParametricSurface3D,
|
||||
ParameterDivision2D,
|
||||
SearchParameterD2,
|
||||
SearchNearestParameterD2,
|
||||
Invertible,
|
||||
TransformedM4,
|
||||
StepLength,
|
||||
StepSurface,
|
||||
)]
|
||||
pub enum Surface {
|
||||
ElementarySurface(Box<ElementarySurface>),
|
||||
SweptCurve(Box<SweptCurve>),
|
||||
BSplineSurface(Box<BSplineSurface<Point3>>),
|
||||
NurbsSurface(Box<NurbsSurface<Vector4>>),
|
||||
}
|
||||
|
||||
impl truck_stepio::out::DisplayByStep for Surface {
|
||||
fn fmt(&self, idx: usize, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
use Surface::*;
|
||||
match self {
|
||||
ElementarySurface(x) => x.fmt(idx, f),
|
||||
SweptCurve(x) => x.fmt(idx, f),
|
||||
BSplineSurface(x) => x.fmt(idx, f),
|
||||
NurbsSurface(x) => x.fmt(idx, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `spherical_surface`, realized in `truck`
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, StepSurface)]
|
||||
pub struct Sphere(pub truck_geometry::prelude::Sphere);
|
||||
|
||||
impl truck_stepio::out::StepSurface for Processor<Sphere, Matrix4> {
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { self.orientation() }
|
||||
}
|
||||
|
||||
mod sphere {
|
||||
use super::*;
|
||||
use std::f64::consts::PI;
|
||||
use std::ops::Bound;
|
||||
impl ParametricSurface for Sphere {
|
||||
type Point = Point3;
|
||||
type Vector = Vector3;
|
||||
#[inline]
|
||||
fn subs(&self, u: f64, v: f64) -> Point3 { self.0.subs(PI / 2.0 - v, u) }
|
||||
#[inline]
|
||||
fn uder(&self, u: f64, v: f64) -> Vector3 { self.0.vder(PI / 2.0 - v, u) }
|
||||
#[inline]
|
||||
fn vder(&self, u: f64, v: f64) -> Vector3 { -self.0.uder(PI / 2.0 - v, u) }
|
||||
#[inline]
|
||||
fn uuder(&self, u: f64, v: f64) -> Vector3 { self.0.vvder(PI / 2.0 - v, u) }
|
||||
#[inline]
|
||||
fn uvder(&self, u: f64, v: f64) -> Vector3 { -self.0.uvder(PI / 2.0 - v, u) }
|
||||
#[inline]
|
||||
fn vvder(&self, u: f64, v: f64) -> Vector3 { self.0.uuder(PI / 2.0 - v, u) }
|
||||
#[inline]
|
||||
fn parameter_range(&self) -> (ParameterRange, ParameterRange) {
|
||||
(
|
||||
(Bound::Included(0.0), Bound::Excluded(2.0 * PI)),
|
||||
(Bound::Included(-PI / 2.0), Bound::Excluded(PI / 2.0)),
|
||||
)
|
||||
}
|
||||
#[inline]
|
||||
fn u_period(&self) -> Option<f64> { Some(2.0 * PI) }
|
||||
}
|
||||
impl ParametricSurface3D for Sphere {
|
||||
#[inline]
|
||||
fn normal(&self, u: f64, v: f64) -> Vector3 { self.0.normal(PI / 2.0 - v, u) }
|
||||
}
|
||||
impl SearchNearestParameter<D2> for Sphere {
|
||||
type Point = Point3;
|
||||
#[inline]
|
||||
fn search_nearest_parameter<H: Into<SPHint2D>>(
|
||||
&self,
|
||||
point: Self::Point,
|
||||
hint: H,
|
||||
trials: usize,
|
||||
) -> Option<(f64, f64)> {
|
||||
self.0
|
||||
.search_nearest_parameter(point, hint, trials)
|
||||
.map(|(u, v)| (v, PI / 2.0 - u))
|
||||
}
|
||||
}
|
||||
impl SearchParameter<D2> for Sphere {
|
||||
type Point = Point3;
|
||||
#[inline]
|
||||
fn search_parameter<H: Into<SPHint2D>>(
|
||||
&self,
|
||||
point: Self::Point,
|
||||
hint: H,
|
||||
trials: usize,
|
||||
) -> Option<(f64, f64)> {
|
||||
self.0
|
||||
.search_parameter(point, hint, trials)
|
||||
.map(|(u, v)| (v, PI / 2.0 - u))
|
||||
}
|
||||
}
|
||||
impl ParameterDivision2D for Sphere {
|
||||
#[inline]
|
||||
fn parameter_division(
|
||||
&self,
|
||||
((u0, u1), (v0, v1)): ((f64, f64), (f64, f64)),
|
||||
tol: f64,
|
||||
) -> (Vec<f64>, Vec<f64>) {
|
||||
let range = ((PI / 2.0 - v1, PI / 2.0 - v0), (u0, u1));
|
||||
let (udiv0, vdiv0) = self.0.parameter_division(range, tol);
|
||||
let vdiv = udiv0.into_iter().map(|u| PI / 2.0 - u).collect();
|
||||
(vdiv0, vdiv)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
proptest::proptest! {
|
||||
#[test]
|
||||
fn surface(
|
||||
center in proptest::array::uniform3(-100.0f64..100.0f64),
|
||||
radius in 0.1f64..100.0f64,
|
||||
(u, v) in (0.0..=2.0 * PI, -PI / 2.0..=PI / 2.0),
|
||||
) {
|
||||
const EPS: f64 = 1.0e-3;
|
||||
let sphere = Sphere(truck_geometry::prelude::Sphere::new(center.into(), radius));
|
||||
|
||||
let uder0 = sphere.uder(u, v);
|
||||
let uder1 = (sphere.subs(u + EPS, v) - sphere.subs(u - EPS, v)) / (2.0 * EPS);
|
||||
assert!(
|
||||
(uder0 - uder1).magnitude2() < EPS,
|
||||
"uder failed: {uder0:?}, {uder1:?}"
|
||||
);
|
||||
|
||||
let vder0 = sphere.vder(u, v);
|
||||
let vder1 = (sphere.subs(u, v + EPS) - sphere.subs(u, v - EPS)) / (2.0 * EPS);
|
||||
assert!(
|
||||
(vder0 - vder1).magnitude2() < EPS,
|
||||
"vder failed: {vder0:?}, {vder1:?}"
|
||||
);
|
||||
|
||||
let uuder0 = sphere.uuder(u, v);
|
||||
let uuder1 = (sphere.uder(u + EPS, v) - sphere.uder(u - EPS, v)) / (2.0 * EPS);
|
||||
assert!(
|
||||
(uuder0 - uuder1).magnitude2() < EPS,
|
||||
"uuder failed: {uuder0:?}, {uuder1:?}"
|
||||
);
|
||||
|
||||
let uvder0 = sphere.uvder(u, v);
|
||||
let uvder1 = (sphere.uder(u, v + EPS) - sphere.uder(u, v - EPS)) / (2.0 * EPS);
|
||||
assert!(
|
||||
(uvder0 - uvder1).magnitude2() < EPS,
|
||||
"uvder failed: {uvder0:?}, {uvder1:?}"
|
||||
);
|
||||
|
||||
let vvder0 = sphere.vvder(u, v);
|
||||
let vvder1 = (sphere.vder(u, v + EPS) - sphere.vder(u, v - EPS)) / (2.0 * EPS);
|
||||
assert!(
|
||||
(vvder0 - vvder1).magnitude2() < EPS,
|
||||
"vvder failed: {vvder0:?}, {vvder1:?}"
|
||||
);
|
||||
|
||||
let n0 = sphere.normal(u, v);
|
||||
let n1 = sphere.uder(u, v).cross(sphere.vder(u, v)).normalize();
|
||||
assert!(
|
||||
(n0 - n1).magnitude2() < EPS,
|
||||
"normal failed: {n0:?}, {n1:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl truck_stepio::out::ConstStepLength for Processor<Sphere, Matrix4> {
|
||||
const LENGTH: usize = Processor::<truck_geometry::prelude::Sphere, Matrix4>::LENGTH;
|
||||
}
|
||||
impl truck_stepio::out::StepLength for Processor<Sphere, Matrix4> {
|
||||
fn step_length(&self) -> usize { <Self as truck_stepio::out::ConstStepLength>::LENGTH }
|
||||
}
|
||||
impl truck_stepio::out::DisplayByStep for Processor<Sphere, Matrix4> {
|
||||
fn fmt(&self, idx: usize, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
Processor::new(self.entity().0)
|
||||
.transformed(*self.transform())
|
||||
.fmt(idx, f)
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation required to apply a closed surface division to a shape parsed from a STEP file.
|
||||
mod from_pcurve {
|
||||
use super::{Curve2D, Curve3D, Surface};
|
||||
use truck_geometry::prelude::*;
|
||||
|
||||
impl From<PCurve<Line<Point2>, Surface>> for Curve3D {
|
||||
fn from(value: PCurve<Line<Point2>, Surface>) -> Self {
|
||||
let (line, surface) = value.decompose();
|
||||
Curve3D::PCurve(PCurve::new(Curve2D::Line(line).into(), surface.into()))
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+2784
File diff suppressed because it is too large.
Load diff
Vendored
+78
@@ -0,0 +1,78 @@
|
||||
//! Reads/writes STEP files from/to truck.
|
||||
//!
|
||||
//! # Current Status
|
||||
//!
|
||||
//! It is possible to output data modeled by truck-modeling.
|
||||
//! Shapes created by set operations cannot be output yet.
|
||||
//! Input will come further down the road.
|
||||
|
||||
// SolveCraft: compiler warnings no longer fail the build.
|
||||
#![deny(clippy::all, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_docs,
|
||||
missing_debug_implementations,
|
||||
trivial_casts,
|
||||
trivial_numeric_casts,
|
||||
unsafe_code,
|
||||
unstable_features,
|
||||
unused_import_braces,
|
||||
unused_qualifications
|
||||
)]
|
||||
|
||||
/// STEP input module
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use truck_stepio::r#in::{*, alias::*};
|
||||
/// use ruststep::tables::EntityTable;
|
||||
/// // read file
|
||||
/// let step_string = include_str!(concat!(
|
||||
/// env!("CARGO_MANIFEST_DIR"),
|
||||
/// "/../resources/step/occt-cube.step",
|
||||
/// ));
|
||||
/// // parse step file
|
||||
/// let exchange = ruststep::parser::parse(&step_string).unwrap();
|
||||
/// // convert the parsing results to a Rust struct
|
||||
/// let table = Table::from_data_section(&exchange.data[0]);
|
||||
/// // get `CartesianPoint` registered in #102
|
||||
/// let step_point = EntityTable::<CartesianPointHolder>::get_owned(&table, 102).unwrap();
|
||||
/// // convert `CartesianPoint` in STEP to `Point3` in cgmath
|
||||
/// let cgmath_point = Point3::from(&step_point);
|
||||
/// // check parse result
|
||||
/// assert_eq!(cgmath_point, Point3::new(0.0, 10.0, 0.0));
|
||||
/// ```
|
||||
#[cfg(feature = "in")]
|
||||
pub mod r#in;
|
||||
/// STEP output module
|
||||
pub mod out;
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! impl_from {
|
||||
($(impl From<&$refed: ty> for $converted: ty {
|
||||
$from_func: item
|
||||
})*) => {
|
||||
$(impl From<&$refed> for $converted {
|
||||
$from_func
|
||||
}
|
||||
impl From<$refed> for $converted {
|
||||
fn from(x: $refed) -> Self { Self::from(&x) }
|
||||
})*
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! impl_try_from {
|
||||
($(impl TryFrom<&$refed: ty> for $converted: ty {
|
||||
$try_from_func: item
|
||||
})*) => {
|
||||
$(impl TryFrom<&$refed> for $converted {
|
||||
type Error = ExpressParseError;
|
||||
$try_from_func
|
||||
}
|
||||
impl TryFrom<$refed> for $converted {
|
||||
type Error = ExpressParseError;
|
||||
fn try_from(x: $refed) -> Result<Self, ExpressParseError> { Self::try_from(&x) }
|
||||
})*
|
||||
};
|
||||
}
|
||||
+813
@@ -0,0 +1,813 @@
|
||||
use super::{Result, *};
|
||||
use truck_geometry::prelude::*;
|
||||
use truck_modeling::{Curve as ModelingCurve, Leader, Surface as ModelingSurface};
|
||||
use truck_polymesh::PolylineCurve;
|
||||
|
||||
impl DisplayByStep for Point2 {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = CARTESIAN_POINT('', {coordinates});\n",
|
||||
coordinates = SliceDisplay(AsRef::<[f64; 2]>::as_ref(self)),
|
||||
))
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Point2, 1);
|
||||
|
||||
impl DisplayByStep for Point3 {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = CARTESIAN_POINT('', {coordinates});\n",
|
||||
coordinates = SliceDisplay(AsRef::<[f64; 3]>::as_ref(self)),
|
||||
))
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Point3, 1);
|
||||
|
||||
/// class for display `DIRECTION`.
|
||||
#[derive(Clone, Debug, Copy)]
|
||||
pub struct VectorAsDirection<V>(pub V);
|
||||
|
||||
impl DisplayByStep for VectorAsDirection<Vector2> {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = DIRECTION('', {direction_ratios});\n",
|
||||
direction_ratios = SliceDisplay(AsRef::<[f64; 2]>::as_ref(&self.0)),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl DisplayByStep for VectorAsDirection<Vector3> {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = DIRECTION('', {direction_ratios});\n",
|
||||
direction_ratios = SliceDisplay(AsRef::<[f64; 3]>::as_ref(&self.0)),
|
||||
))
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(VectorAsDirection<V>, 1, <V>);
|
||||
|
||||
impl<V> DisplayByStep for V
|
||||
where
|
||||
V: InnerSpace<Scalar = f64>,
|
||||
VectorAsDirection<V>: DisplayByStep,
|
||||
{
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let magnitude = self.magnitude();
|
||||
let direction_idx = idx + 1;
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = VECTOR('', #{direction_idx}, {magnitude});\n{direction}",
|
||||
direction = StepDisplay::new(VectorAsDirection(*self / magnitude), direction_idx),
|
||||
magnitude = FloatDisplay(magnitude),
|
||||
))
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Vector2, 2);
|
||||
impl_const_step_length!(Vector3, 2);
|
||||
|
||||
impl<P> DisplayByStep for Line<P>
|
||||
where
|
||||
P: EuclideanSpace + ConstStepLength + DisplayByStep,
|
||||
P::Diff: DisplayByStep,
|
||||
{
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let pnt_idx = idx + 1;
|
||||
let dir_idx = idx + 1 + P::LENGTH;
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = LINE('', #{pnt_idx}, #{dir_idx});\n{pnt}{dir}",
|
||||
pnt = StepDisplay::new(self.0, pnt_idx),
|
||||
dir = StepDisplay::new(self.1 - self.0, dir_idx),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> StepLength for Line<P>
|
||||
where
|
||||
P: EuclideanSpace + ConstStepLength,
|
||||
P::Diff: ConstStepLength,
|
||||
{
|
||||
#[inline(always)]
|
||||
fn step_length(&self) -> usize { <Self as ConstStepLength>::LENGTH }
|
||||
}
|
||||
|
||||
impl<P> ConstStepLength for Line<P>
|
||||
where
|
||||
P: EuclideanSpace + ConstStepLength,
|
||||
P::Diff: ConstStepLength,
|
||||
{
|
||||
const LENGTH: usize = 1 + P::LENGTH + P::Diff::LENGTH;
|
||||
}
|
||||
|
||||
impl<P> StepCurve for Line<P> {}
|
||||
|
||||
impl<P> DisplayByStep for PolylineCurve<P>
|
||||
where P: Copy + ConstStepLength + DisplayByStep
|
||||
{
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = POLYLINE('', {range});\n",
|
||||
range = IndexSliceDisplay(idx + 1..=idx + self.0.len())
|
||||
))?;
|
||||
let closure = |(i, p): (usize, &P)| p.fmt(idx + 1 + i * P::LENGTH, f);
|
||||
self.0.iter().enumerate().try_for_each(closure)
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: ConstStepLength> StepLength for PolylineCurve<P> {
|
||||
#[inline(always)]
|
||||
fn step_length(&self) -> usize { 1 + self.0.len() * P::LENGTH }
|
||||
}
|
||||
|
||||
impl<P> StepCurve for PolylineCurve<P> {}
|
||||
|
||||
impl<P> DisplayByStep for BSplineCurve<P>
|
||||
where P: Copy + ConstStepLength + DisplayByStep
|
||||
{
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let (knots, multi) = self.knot_vec().to_single_multi();
|
||||
let control_points_instances = self
|
||||
.control_points()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, p)| StepDisplay::new(*p, idx + 1 + i * P::LENGTH))
|
||||
.collect::<Vec<_>>();
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = B_SPLINE_CURVE_WITH_KNOTS('', {degree}, {control_points_list}, .UNSPECIFIED., .U., .U., {knot_multiplicities}, {knots}, .UNSPECIFIED.);\n{control_points_instances}",
|
||||
degree = self.degree(),
|
||||
control_points_list = IndexSliceDisplay((idx + 1..=idx + self.control_points().len() * P::LENGTH).step_by(P::LENGTH)),
|
||||
knot_multiplicities = SliceDisplay(&multi),
|
||||
knots = SliceDisplay(&knots),
|
||||
control_points_instances = SliceDisplay(&control_points_instances),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> StepLength for BSplineCurve<P> {
|
||||
#[inline(always)]
|
||||
fn step_length(&self) -> usize { self.control_points().len() + 1 }
|
||||
}
|
||||
|
||||
impl<P> StepCurve for BSplineCurve<P> {}
|
||||
|
||||
impl<V> DisplayByStep for NurbsCurve<V>
|
||||
where
|
||||
V: Homogeneous<f64>,
|
||||
V::Point: ConstStepLength + DisplayByStep,
|
||||
{
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let (knots, multi) = self.knot_vec().to_single_multi();
|
||||
let control_points_instances = self
|
||||
.control_points()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, v)| StepDisplay::new(v.to_point(), idx + 1 + i * V::Point::LENGTH))
|
||||
.collect::<Vec<_>>();
|
||||
let weights = self
|
||||
.control_points()
|
||||
.iter()
|
||||
.map(|v| v.weight())
|
||||
.collect::<Vec<_>>();
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = (
|
||||
BOUNDED_CURVE()
|
||||
B_SPLINE_CURVE({degree}, {control_points_list}, .UNSPECIFIED., .U., .U.)
|
||||
B_SPLINE_CURVE_WITH_KNOTS({knot_multiplicities}, {knots}, .UNSPECIFIED.)
|
||||
CURVE()
|
||||
GEOMETRIC_REPRESENTATION_ITEM()
|
||||
RATIONAL_B_SPLINE_CURVE({weights})
|
||||
REPRESENTATION_ITEM('')
|
||||
);\n{control_points_instances}",
|
||||
degree = self.degree(),
|
||||
control_points_list = IndexSliceDisplay(
|
||||
(idx + 1..=idx + self.control_points().len() * V::Point::LENGTH)
|
||||
.step_by(V::Point::LENGTH)
|
||||
),
|
||||
knot_multiplicities = SliceDisplay(&multi),
|
||||
knots = SliceDisplay(&knots),
|
||||
weights = SliceDisplay(&weights),
|
||||
control_points_instances = SliceDisplay(&control_points_instances),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> StepLength for NurbsCurve<V> {
|
||||
#[inline(always)]
|
||||
fn step_length(&self) -> usize { self.control_points().len() + 1 }
|
||||
}
|
||||
|
||||
impl<V> StepCurve for NurbsCurve<V> {}
|
||||
|
||||
impl DisplayByStep for Processor<TrimmedCurve<UnitCircle<Point2>>, Matrix3> {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let transform = *self.transform();
|
||||
let position_idx = idx + 1;
|
||||
let location_idx = idx + 2;
|
||||
let ref_direction_idx = idx + 3;
|
||||
let r0 = transform[0].magnitude();
|
||||
let r1 = transform[1].magnitude();
|
||||
let ref_direction = VectorAsDirection(transform[0].truncate() / r0);
|
||||
let location = transform[2].to_point();
|
||||
if r0.near(&r1) {
|
||||
let r = FloatDisplay(r0);
|
||||
f.write_fmt(format_args!("#{idx} = CIRCLE('', #{position_idx}, {r});\n"))?;
|
||||
} else {
|
||||
let (r0, r1) = (FloatDisplay(r0), FloatDisplay(r1));
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = ELLIPSE('', #{position_idx}, {r0}, {r1});\n"
|
||||
))?;
|
||||
}
|
||||
f.write_fmt(format_args!(
|
||||
"#{position_idx} = AXIS2_PLACEMENT_2D('', #{location_idx}, #{ref_direction_idx});\n",
|
||||
))?;
|
||||
DisplayByStep::fmt(&location, location_idx, f)?;
|
||||
DisplayByStep::fmt(&ref_direction, ref_direction_idx, f)
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Processor<TrimmedCurve<UnitCircle<Point2>>, Matrix3>, 4);
|
||||
|
||||
impl DisplayByStep for Processor<TrimmedCurve<UnitCircle<Point3>>, Matrix4> {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let transform = self.transform();
|
||||
let position_idx = idx + 1;
|
||||
let location_idx = idx + 2;
|
||||
let axis_idx = idx + 3;
|
||||
let ref_direction_idx = idx + 4;
|
||||
let location = transform[3].to_point();
|
||||
let axis = VectorAsDirection(transform[2].truncate().normalize());
|
||||
let r0 = transform[0].magnitude();
|
||||
let r1 = transform[1].magnitude();
|
||||
let ref_direction = VectorAsDirection(transform[0].truncate() / r0);
|
||||
if r0.near(&r1) {
|
||||
let r = FloatDisplay(r0);
|
||||
f.write_fmt(format_args!("#{idx} = CIRCLE('', #{position_idx}, {r});\n"))?;
|
||||
} else {
|
||||
let (r0, r1) = (FloatDisplay(r0), FloatDisplay(r1));
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = ELLIPSE('', #{position_idx}, {r0}, {r1});\n"
|
||||
))?;
|
||||
}
|
||||
f.write_fmt(format_args!(
|
||||
"#{position_idx} = AXIS2_PLACEMENT_3D('', #{location_idx}, #{axis_idx}, #{ref_direction_idx});\n",
|
||||
))?;
|
||||
DisplayByStep::fmt(&location, location_idx, f)?;
|
||||
DisplayByStep::fmt(&axis, axis_idx, f)?;
|
||||
DisplayByStep::fmt(&ref_direction, ref_direction_idx, f)
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Processor<TrimmedCurve<UnitCircle<Point3>>, Matrix4>, 5);
|
||||
|
||||
impl DisplayByStep for Processor<TrimmedCurve<UnitHyperbola<Point2>>, Matrix3> {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let transform = *self.transform();
|
||||
let position_idx = idx + 1;
|
||||
let location_idx = idx + 2;
|
||||
let ref_direction_idx = idx + 3;
|
||||
let r0 = transform[0].magnitude();
|
||||
let r1 = transform[1].magnitude();
|
||||
let ref_direction_raw = VectorAsDirection(transform[0].truncate() / r0);
|
||||
let ref_direction = StepDisplay::new(ref_direction_raw, ref_direction_idx);
|
||||
let location = StepDisplay::new(transform[2].to_point(), location_idx);
|
||||
let (r0, r1) = (FloatDisplay(r0), FloatDisplay(r1));
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = HYPERBOLA('', #{position_idx}, {r0}, {r1});
|
||||
#{position_idx} = AXIS2_PLACEMENT_2D('', #{location_idx}, #{ref_direction_idx});
|
||||
{location}{ref_direction}"
|
||||
))
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Processor<TrimmedCurve<UnitHyperbola<Point2>>, Matrix3>, 4);
|
||||
|
||||
impl DisplayByStep for Processor<TrimmedCurve<UnitHyperbola<Point3>>, Matrix4> {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let transform = self.transform();
|
||||
let position_idx = idx + 1;
|
||||
let location_idx = idx + 2;
|
||||
let axis_idx = idx + 3;
|
||||
let ref_direction_idx = idx + 4;
|
||||
let location = StepDisplay::new(transform[3].to_point(), location_idx);
|
||||
let axis_raw = VectorAsDirection(transform[2].truncate().normalize());
|
||||
let axis = StepDisplay::new(axis_raw, axis_idx);
|
||||
let r0 = transform[0].magnitude();
|
||||
let r1 = transform[1].magnitude();
|
||||
let ref_direction_raw = VectorAsDirection(transform[0].truncate() / r0);
|
||||
let ref_direction = StepDisplay::new(ref_direction_raw, ref_direction_idx);
|
||||
let (r0, r1) = (FloatDisplay(r0), FloatDisplay(r1));
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = HYPERBOLA('', #{position_idx}, {r0}, {r1});
|
||||
#{position_idx} = AXIS2_PLACEMENT_3D('', #{location_idx}, #{axis_idx}, #{ref_direction_idx});
|
||||
{location}{axis}{ref_direction}"
|
||||
))
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Processor<TrimmedCurve<UnitHyperbola<Point3>>, Matrix4>, 5);
|
||||
|
||||
impl DisplayByStep for Processor<TrimmedCurve<UnitParabola<Point2>>, Matrix3> {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let transform = *self.transform();
|
||||
let position_idx = idx + 1;
|
||||
let location_idx = idx + 2;
|
||||
let ref_direction_idx = idx + 3;
|
||||
let r0 = transform[0].magnitude();
|
||||
let r1 = transform[1].magnitude();
|
||||
let focal_dist = FloatDisplay(r1 * r1 / r0);
|
||||
let ref_direction_raw = VectorAsDirection(transform[0].truncate() / r0);
|
||||
let ref_direction = StepDisplay::new(ref_direction_raw, ref_direction_idx);
|
||||
let location = StepDisplay::new(transform[2].to_point(), location_idx);
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = PARABOLA('', #{position_idx}, {focal_dist});
|
||||
#{position_idx} = AXIS2_PLACEMENT_2D('', #{location_idx}, #{ref_direction_idx});
|
||||
{location}{ref_direction}"
|
||||
))
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Processor<TrimmedCurve<UnitParabola<Point2>>, Matrix3>, 4);
|
||||
|
||||
impl DisplayByStep for Processor<TrimmedCurve<UnitParabola<Point3>>, Matrix4> {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let transform = self.transform();
|
||||
let position_idx = idx + 1;
|
||||
let location_idx = idx + 2;
|
||||
let axis_idx = idx + 3;
|
||||
let ref_direction_idx = idx + 4;
|
||||
let location = StepDisplay::new(transform[3].to_point(), location_idx);
|
||||
let axis_raw = VectorAsDirection(transform[2].truncate().normalize());
|
||||
let axis = StepDisplay::new(axis_raw, axis_idx);
|
||||
let r0 = transform[0].magnitude();
|
||||
let r1 = transform[1].magnitude();
|
||||
let focal_dist = FloatDisplay(r1 * r1 / r0);
|
||||
let ref_direction_raw = VectorAsDirection(transform[0].truncate() / r0);
|
||||
let ref_direction = StepDisplay::new(ref_direction_raw, ref_direction_idx);
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = PARABOLA('', #{position_idx}, {focal_dist});
|
||||
#{position_idx} = AXIS2_PLACEMENT_3D('', #{location_idx}, #{axis_idx}, #{ref_direction_idx});
|
||||
{location}{axis}{ref_direction}"
|
||||
))
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Processor<TrimmedCurve<UnitParabola<Point3>>, Matrix4>, 5);
|
||||
|
||||
impl<C, M: One> StepCurve for Processor<C, M> {
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { self.orientation() }
|
||||
}
|
||||
|
||||
impl<C, S> DisplayByStep for IntersectionCurve<C, S>
|
||||
where
|
||||
C: StepLength + DisplayByStep,
|
||||
S: StepLength + DisplayByStep,
|
||||
{
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let curve_idx = idx + 1;
|
||||
let surface0_idx = curve_idx + self.leader().step_length();
|
||||
let surface1_idx = surface0_idx + self.surface0().step_length();
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = INTERSECTION_CURVE('', #{curve_idx}, (#{surface0_idx}, #{surface1_idx}), .CURVE_3D.);\n"
|
||||
))?;
|
||||
self.leader().fmt(curve_idx, f)?;
|
||||
self.surface0().fmt(surface0_idx, f)?;
|
||||
// SolveCraft: the second surface was written at the first one's index (duplicate ids).
|
||||
self.surface1().fmt(surface1_idx, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: StepLength, S: StepLength> StepLength for IntersectionCurve<C, S> {
|
||||
#[inline(always)]
|
||||
fn step_length(&self) -> usize {
|
||||
1 + self.leader().step_length()
|
||||
+ self.surface0().step_length()
|
||||
+ self.surface1().step_length()
|
||||
}
|
||||
}
|
||||
|
||||
impl<C, S> ConstStepLength for IntersectionCurve<C, S>
|
||||
where
|
||||
C: ConstStepLength,
|
||||
S: ConstStepLength,
|
||||
{
|
||||
const LENGTH: usize = 1 + C::LENGTH + S::LENGTH + S::LENGTH;
|
||||
}
|
||||
|
||||
impl<C: StepCurve, S> StepCurve for IntersectionCurve<C, S> {
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { self.leader().same_sense() }
|
||||
}
|
||||
|
||||
impl<C, S> DisplayByStep for PCurve<C, S>
|
||||
where
|
||||
C: DisplayByStep,
|
||||
S: DisplayByStep + StepLength,
|
||||
{
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let surface_idx = idx + 1;
|
||||
let repr_idx = surface_idx + self.surface().step_length();
|
||||
let context_idx = repr_idx + 1;
|
||||
let curve_idx = repr_idx + 2;
|
||||
let curve = StepDisplay::new(self.curve(), curve_idx);
|
||||
let surface = StepDisplay::new(self.surface(), surface_idx);
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = PCURVE('', #{surface_idx}, #{repr_idx});
|
||||
{surface}#{repr_idx} = DEFINITIONAL_REPRESENTATION('', (#{curve_idx}), #{context_idx});
|
||||
#{context_idx} = (
|
||||
GEOMETRIC_REPRESENTATION_CONTEXT(2)
|
||||
PARAMETRIC_REPRESENTATION_CONTEXT()
|
||||
REPRESENTATION_CONTEXT('2D SPACE', '')
|
||||
);
|
||||
{curve}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: StepLength, S: StepLength> StepLength for PCurve<C, S> {
|
||||
fn step_length(&self) -> usize { 3 + self.curve().step_length() + self.surface().step_length() }
|
||||
}
|
||||
|
||||
impl<C, S> ConstStepLength for PCurve<C, S>
|
||||
where
|
||||
C: ConstStepLength,
|
||||
S: ConstStepLength,
|
||||
{
|
||||
const LENGTH: usize = 3 + C::LENGTH + S::LENGTH;
|
||||
}
|
||||
|
||||
impl<C: StepCurve, S> StepCurve for PCurve<C, S> {
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { self.curve().same_sense() }
|
||||
}
|
||||
|
||||
impl DisplayByStep for Leader {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
match self {
|
||||
Leader::Polyline(x) => DisplayByStep::fmt(x, idx, f),
|
||||
Leader::BSpline(x) => DisplayByStep::fmt(x, idx, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StepLength for Leader {
|
||||
fn step_length(&self) -> usize {
|
||||
match self {
|
||||
Leader::Polyline(x) => x.step_length(),
|
||||
Leader::BSpline(x) => x.step_length(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StepCurve for Leader {}
|
||||
|
||||
impl DisplayByStep for ModelingCurve {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
match self {
|
||||
ModelingCurve::Line(x) => DisplayByStep::fmt(x, idx, f),
|
||||
ModelingCurve::BSplineCurve(x) => DisplayByStep::fmt(x, idx, f),
|
||||
ModelingCurve::NurbsCurve(x) => DisplayByStep::fmt(x, idx, f),
|
||||
ModelingCurve::IntersectionCurve(x) => DisplayByStep::fmt(x, idx, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StepLength for ModelingCurve {
|
||||
fn step_length(&self) -> usize {
|
||||
match self {
|
||||
ModelingCurve::Line(_) => Line::<Point3>::LENGTH,
|
||||
ModelingCurve::BSplineCurve(x) => x.step_length(),
|
||||
ModelingCurve::NurbsCurve(x) => x.step_length(),
|
||||
ModelingCurve::IntersectionCurve(x) => x.step_length(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StepCurve for ModelingCurve {}
|
||||
|
||||
impl DisplayByStep for Plane {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let axis2_placement_idx = idx + 1;
|
||||
let location_idx = idx + 2;
|
||||
let z_axis_idx = idx + 3;
|
||||
let x_axis_idx = idx + 4;
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = PLANE('', #{axis2_placement_idx});
|
||||
#{axis2_placement_idx} = AXIS2_PLACEMENT_3D('', #{location_idx}, #{z_axis_idx}, #{x_axis_idx});
|
||||
{location}{z_axis}{x_axis}",
|
||||
location = StepDisplay::new(self.origin(), location_idx),
|
||||
z_axis = StepDisplay::new(VectorAsDirection(self.normal()), z_axis_idx),
|
||||
x_axis = StepDisplay::new(VectorAsDirection(self.u_axis().normalize()), x_axis_idx)
|
||||
))
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Plane, 5);
|
||||
|
||||
impl StepSurface for Plane {}
|
||||
|
||||
impl DisplayByStep for Processor<Sphere, Matrix4> {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let sphere = *self.entity();
|
||||
let transform = self.transform();
|
||||
let position_idx = idx + 1;
|
||||
let location_idx = idx + 2;
|
||||
let axis_idx = idx + 3;
|
||||
let ref_direction_idx = idx + 4;
|
||||
let location = transform[3].to_point() + sphere.center().to_vec();
|
||||
let axis = VectorAsDirection(transform[2].truncate().normalize());
|
||||
let r0 = transform[0].magnitude();
|
||||
let r1 = transform[1].magnitude();
|
||||
if !r0.near(&r1) {
|
||||
f.write_str("The transform of sphere includes non-uniform scale.")?;
|
||||
return ERR;
|
||||
}
|
||||
let ref_direction = VectorAsDirection(transform[0].truncate() / r0);
|
||||
let r = FloatDisplay(r0 * sphere.radius());
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = SPHERICAL_SURFACE('', #{position_idx}, {r});
|
||||
#{position_idx} = AXIS2_PLACEMENT_3D('', #{location_idx}, #{axis_idx}, #{ref_direction_idx});\n"
|
||||
))?;
|
||||
DisplayByStep::fmt(&location, location_idx, f)?;
|
||||
DisplayByStep::fmt(&axis, axis_idx, f)?;
|
||||
DisplayByStep::fmt(&ref_direction, ref_direction_idx, f)
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Processor<Sphere, Matrix4>, 5);
|
||||
|
||||
impl DisplayByStep for Sphere {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
DisplayByStep::fmt(&Processor::new(*self), idx, f)
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Sphere, 5);
|
||||
impl StepSurface for Sphere {}
|
||||
|
||||
impl DisplayByStep for Processor<Torus, Matrix4> {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let torus = *self.entity();
|
||||
let transform = self.transform();
|
||||
let position_idx = idx + 1;
|
||||
let location_idx = idx + 2;
|
||||
let axis_idx = idx + 3;
|
||||
let ref_direction_idx = idx + 4;
|
||||
let location = transform[3].to_point() + torus.center().to_vec();
|
||||
let axis = VectorAsDirection(transform[2].truncate().normalize());
|
||||
let r0 = transform[0].magnitude();
|
||||
let r1 = transform[1].magnitude();
|
||||
if !r0.near(&r1) {
|
||||
f.write_str("The transform of sphere includes non-uniform scale.")?;
|
||||
return ERR;
|
||||
}
|
||||
let ref_direction = VectorAsDirection(transform[0].truncate() / r0);
|
||||
let greater = FloatDisplay(r0 * torus.large_radius());
|
||||
let lesser = FloatDisplay(r0 * torus.small_radius());
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = TOROIDAL_SURFACE('', #{position_idx}, {greater}, {lesser});
|
||||
#{position_idx} = AXIS2_PLACEMENT_3D('', #{location_idx}, #{axis_idx}, #{ref_direction_idx});\n",
|
||||
))?;
|
||||
DisplayByStep::fmt(&location, location_idx, f)?;
|
||||
DisplayByStep::fmt(&axis, axis_idx, f)?;
|
||||
DisplayByStep::fmt(&ref_direction, ref_direction_idx, f)
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Processor<Torus, Matrix4>, 5);
|
||||
|
||||
impl StepSurface for Processor<Torus, Matrix4> {
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { self.orientation() }
|
||||
}
|
||||
|
||||
impl DisplayByStep for Torus {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
DisplayByStep::fmt(&Processor::new(*self), idx, f)
|
||||
}
|
||||
}
|
||||
impl_const_step_length!(Torus, 5);
|
||||
impl StepSurface for Torus {}
|
||||
|
||||
impl<P> DisplayByStep for BSplineSurface<P>
|
||||
where P: Copy + DisplayByStep
|
||||
{
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let control_points = self.control_points();
|
||||
let control_points_instances = self
|
||||
.control_points()
|
||||
.iter()
|
||||
.flatten()
|
||||
.enumerate()
|
||||
.map(|(i, p)| StepDisplay::new(*p, idx + i + 1))
|
||||
.collect::<Vec<_>>();
|
||||
let mut counter = 0;
|
||||
let control_points_list = control_points
|
||||
.iter()
|
||||
.map(|slice| {
|
||||
counter += slice.len();
|
||||
IndexSliceDisplay(idx + counter - slice.len() + 1..=idx + counter)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let (uknots, umulti) = self.uknot_vec().to_single_multi();
|
||||
let (vknots, vmulti) = self.vknot_vec().to_single_multi();
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = B_SPLINE_SURFACE_WITH_KNOTS('', {u_degree}, {v_degree}, {control_points_list}, .UNSPECIFIED., .U., .U., .U., \
|
||||
{u_multiplicities}, {v_multiplicities}, {u_knots}, {v_knots}, .UNSPECIFIED.);\n{control_points_instances}",
|
||||
u_degree = self.udegree(),
|
||||
v_degree = self.vdegree(),
|
||||
control_points_list = SliceDisplay(&control_points_list),
|
||||
u_multiplicities = SliceDisplay(&umulti),
|
||||
v_multiplicities = SliceDisplay(&vmulti),
|
||||
u_knots = SliceDisplay(&uknots),
|
||||
v_knots = SliceDisplay(&vknots),
|
||||
control_points_instances = SliceDisplay(&control_points_instances),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> StepLength for BSplineSurface<P> {
|
||||
#[inline(always)]
|
||||
fn step_length(&self) -> usize { 1 + self.control_points().iter().map(Vec::len).sum::<usize>() }
|
||||
}
|
||||
impl<P> StepSurface for BSplineSurface<P> {}
|
||||
|
||||
impl<V> DisplayByStep for NurbsSurface<V>
|
||||
where
|
||||
V: Homogeneous<f64>,
|
||||
V::Point: Copy + DisplayByStep,
|
||||
{
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let control_points_instances = self
|
||||
.control_points()
|
||||
.iter()
|
||||
.flatten()
|
||||
.enumerate()
|
||||
.map(|(i, v)| StepDisplay::new(v.to_point(), idx + i + 1))
|
||||
.collect::<Vec<_>>();
|
||||
let mut counter = 0;
|
||||
let control_points_list = self
|
||||
.control_points()
|
||||
.iter()
|
||||
.map(|slice| {
|
||||
counter += slice.len();
|
||||
IndexSliceDisplay(idx + counter - slice.len() + 1..=idx + counter)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let weights = self
|
||||
.control_points()
|
||||
.iter()
|
||||
.map(|slice| slice.iter().map(|v| v.weight()).collect::<Vec<_>>())
|
||||
.collect::<Vec<_>>();
|
||||
let weights = weights
|
||||
.iter()
|
||||
.map(|slice| SliceDisplay(slice))
|
||||
.collect::<Vec<_>>();
|
||||
let (uknots, umulti) = self.uknot_vec().to_single_multi();
|
||||
let (vknots, vmulti) = self.vknot_vec().to_single_multi();
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = (
|
||||
BOUNDED_SURFACE()
|
||||
B_SPLINE_SURFACE({u_degree}, {v_degree}, {control_points_list}, .UNSPECIFIED., .U., .U., .U.)
|
||||
B_SPLINE_SURFACE_WITH_KNOTS({u_multiplicities}, {v_multiplicities}, {u_knots}, {v_knots}, .UNSPECIFIED.)
|
||||
GEOMETRIC_REPRESENTATION_ITEM()
|
||||
RATIONAL_B_SPLINE_SURFACE({weights})
|
||||
REPRESENTATION_ITEM('')
|
||||
SURFACE()
|
||||
);\n{control_points_instances}",
|
||||
u_degree = self.udegree(),
|
||||
v_degree = self.vdegree(),
|
||||
control_points_list = SliceDisplay(&control_points_list),
|
||||
u_multiplicities = SliceDisplay(&umulti),
|
||||
v_multiplicities = SliceDisplay(&vmulti),
|
||||
u_knots = SliceDisplay(&uknots),
|
||||
v_knots = SliceDisplay(&vknots),
|
||||
control_points_instances = SliceDisplay(&control_points_instances),
|
||||
weights = SliceDisplay(&weights),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> StepLength for NurbsSurface<V> {
|
||||
#[inline(always)]
|
||||
fn step_length(&self) -> usize { 1 + self.control_points().iter().map(Vec::len).sum::<usize>() }
|
||||
}
|
||||
impl<V> StepSurface for NurbsSurface<V> {}
|
||||
|
||||
impl<C> DisplayByStep for ExtrudedCurve<C, Vector3>
|
||||
where C: StepLength + DisplayByStep
|
||||
{
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let curve = self.entity_curve();
|
||||
let curve_idx = idx + 1;
|
||||
let vector_idx = idx + 1 + curve.step_length();
|
||||
let vector = self.extruding_vector();
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = SURFACE_OF_LINEAR_EXTRUSION('', #{curve_idx}, #{vector_idx});{}{}",
|
||||
StepDisplay::new(curve, curve_idx),
|
||||
StepDisplay::new(vector, vector_idx),
|
||||
))
|
||||
}
|
||||
}
|
||||
impl<C: StepLength> StepLength for ExtrudedCurve<C, Vector3> {
|
||||
fn step_length(&self) -> usize { 1 + self.entity_curve().step_length() + Vector3::LENGTH }
|
||||
}
|
||||
impl<C: ConstStepLength> ConstStepLength for ExtrudedCurve<C, Vector3> {
|
||||
const LENGTH: usize = 1 + C::LENGTH + Vector3::LENGTH;
|
||||
}
|
||||
impl<C> StepSurface for ExtrudedCurve<C, Vector3> {}
|
||||
|
||||
impl<C, T: One> StepSurface for Processor<ExtrudedCurve<C, Vector3>, T> {
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { self.orientation() }
|
||||
}
|
||||
|
||||
impl<C> DisplayByStep for RevolutedCurve<C>
|
||||
where C: StepLength + DisplayByStep
|
||||
{
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let curve = self.entity_curve();
|
||||
let curve_idx = idx + 1;
|
||||
let axis_idx = curve_idx + curve.step_length();
|
||||
let location_idx = axis_idx + 1;
|
||||
let dir_idx = location_idx + 1;
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = SURFACE_OF_REVOLUTION('', #{curve_idx}, #{axis_idx});
|
||||
{curve}#{axis_idx} = AXIS1_PLACEMENT('', #{location_idx}, #{dir_idx});\n{location}{dir}",
|
||||
curve = StepDisplay::new(curve, curve_idx),
|
||||
location = StepDisplay::new(self.origin(), location_idx),
|
||||
dir = StepDisplay::new(VectorAsDirection(self.axis()), dir_idx),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: StepLength> StepLength for RevolutedCurve<C> {
|
||||
#[inline(always)]
|
||||
fn step_length(&self) -> usize { 4 + self.entity_curve().step_length() }
|
||||
}
|
||||
|
||||
impl<C: ConstStepLength> ConstStepLength for RevolutedCurve<C> {
|
||||
const LENGTH: usize = 4 + C::LENGTH;
|
||||
}
|
||||
|
||||
// SolveCraft: truck revolves right-handed with u along the profile and v around the axis, the
|
||||
// parameterisation of ISO 10303-42 surface_of_revolution, so the normals agree (was `false`).
|
||||
impl<C> StepSurface for RevolutedCurve<C> {
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { true }
|
||||
}
|
||||
|
||||
impl<C> DisplayByStep for Processor<RevolutedCurve<C>, Matrix4>
|
||||
where C: StepLength + Transformed<Matrix4> + DisplayByStep
|
||||
{
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
let surface = self.entity();
|
||||
let transform = self.transform();
|
||||
let (k, a, _) = match transform.iwasawa_decomposition() {
|
||||
Some(x) => x,
|
||||
None => {
|
||||
f.write_str("Transform is not regular")?;
|
||||
return ERR;
|
||||
}
|
||||
};
|
||||
if !a[0][0].near(&a[1][1]) || !a[1][1].near(&a[2][2]) {
|
||||
f.write_str("Transform contains non-uniform scale.")?;
|
||||
return ERR;
|
||||
}
|
||||
let curve = surface.entity_curve().transformed(*transform);
|
||||
let axis = k.transform_vector(surface.axis());
|
||||
let origin = transform.transform_point(surface.origin());
|
||||
let surface = RevolutedCurve::by_revolution(curve, origin, axis);
|
||||
DisplayByStep::fmt(&surface, idx, f)
|
||||
}
|
||||
}
|
||||
impl<C: StepLength> StepLength for Processor<RevolutedCurve<C>, Matrix4> {
|
||||
fn step_length(&self) -> usize { self.entity().step_length() }
|
||||
}
|
||||
|
||||
// SolveCraft: the written surface revolves the transformed profile about the transformed
|
||||
// axis; a mirroring transform reverses the turn, and with it the normal (was `!orientation`).
|
||||
impl<C> StepSurface for Processor<RevolutedCurve<C>, Matrix4> {
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { self.orientation() == (self.transform().determinant() >= 0.0) }
|
||||
}
|
||||
|
||||
impl DisplayByStep for ModelingSurface {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
match self {
|
||||
ModelingSurface::Plane(x) => DisplayByStep::fmt(x, idx, f),
|
||||
ModelingSurface::BSplineSurface(x) => DisplayByStep::fmt(x, idx, f),
|
||||
ModelingSurface::NurbsSurface(x) => DisplayByStep::fmt(x, idx, f),
|
||||
ModelingSurface::RevolutedCurve(x) => DisplayByStep::fmt(x, idx, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StepLength for ModelingSurface {
|
||||
fn step_length(&self) -> usize {
|
||||
match self {
|
||||
ModelingSurface::Plane(_) => Plane::LENGTH,
|
||||
ModelingSurface::BSplineSurface(x) => x.step_length(),
|
||||
ModelingSurface::NurbsSurface(x) => x.step_length(),
|
||||
ModelingSurface::RevolutedCurve(x) => x.entity().step_length(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SolveCraft: was the default (`true`), which dropped an inverted revolution's orientation.
|
||||
impl StepSurface for ModelingSurface {
|
||||
fn same_sense(&self) -> bool {
|
||||
match self {
|
||||
ModelingSurface::RevolutedCurve(x) => StepSurface::same_sense(x),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+388
@@ -0,0 +1,388 @@
|
||||
use std::fmt::{Debug, Display, Formatter, Result};
|
||||
|
||||
use truck_topology::compress::*;
|
||||
|
||||
use self::topology::PreStepModel;
|
||||
|
||||
const ERR: Result = Err(std::fmt::Error);
|
||||
|
||||
#[cfg(feature = "derive")]
|
||||
pub use truck_derivers::{DisplayByStep, StepLength};
|
||||
|
||||
/// display boolean number to step file
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct BooleanDisplay(pub bool);
|
||||
|
||||
impl Display for BooleanDisplay {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
match self.0 {
|
||||
true => f.write_str(".T."),
|
||||
false => f.write_str(".F."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// display float number to step file
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct FloatDisplay(pub f64);
|
||||
|
||||
impl Display for FloatDisplay {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
let FloatDisplay(x) = *self;
|
||||
if f64::abs(x) < 1.0e-2 && x != 0.0 {
|
||||
f.write_fmt(format_args!("{x:.10E}"))
|
||||
} else {
|
||||
f.write_fmt(format_args!("{x:?}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// display step slice
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use truck_stepio::out::SliceDisplay;
|
||||
/// let slice = &[1.0, 2.0, 3.0, 4.0];
|
||||
/// let display = SliceDisplay(slice);
|
||||
/// let step_string = display.to_string();
|
||||
/// assert_eq!(step_string, "(1.0, 2.0, 3.0, 4.0)");
|
||||
/// ```
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SliceDisplay<'a, T>(pub &'a [T]);
|
||||
|
||||
impl<'a> Display for SliceDisplay<'a, f64> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
f.write_str("(")?;
|
||||
self.0.iter().enumerate().try_for_each(|(i, x)| {
|
||||
if i != 0 {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
Display::fmt(&FloatDisplay(*x), f)
|
||||
})?;
|
||||
f.write_str(")")
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for SliceDisplay<'a, usize> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
f.write_str("(")?;
|
||||
self.0.iter().enumerate().try_for_each(|(i, x)| {
|
||||
if i != 0 {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
Display::fmt(x, f)
|
||||
})?;
|
||||
f.write_str(")")
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for SliceDisplay<'a, String> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
f.write_str("(")?;
|
||||
self.0.iter().enumerate().try_for_each(|(i, x)| {
|
||||
if i != 0 {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
f.write_fmt(format_args!("'{x}'"))
|
||||
})?;
|
||||
f.write_str(")")
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for SliceDisplay<'a, SliceDisplay<'a, f64>> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
f.write_str("(")?;
|
||||
self.0.iter().enumerate().try_for_each(|(i, x)| {
|
||||
if i != 0 {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
Display::fmt(x, f)
|
||||
})?;
|
||||
f.write_str(")")
|
||||
}
|
||||
}
|
||||
|
||||
/// display index slice
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use truck_stepio::out::*;
|
||||
/// let indices = [1, 10, 100, 1000, 10000];
|
||||
/// let display = IndexSliceDisplay(indices.into_iter());
|
||||
/// let step_string = display.to_string();
|
||||
/// assert_eq!(step_string, "(#1, #10, #100, #1000, #10000)");
|
||||
/// ```
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct IndexSliceDisplay<I>(pub I);
|
||||
|
||||
impl<I: Clone + IntoIterator<Item = usize>> Display for IndexSliceDisplay<I> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
f.write_str("(")?;
|
||||
self.0
|
||||
.clone()
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.try_for_each(|(i, idx)| {
|
||||
if i != 0 {
|
||||
f.write_fmt(format_args!(", #{idx}"))
|
||||
} else {
|
||||
f.write_fmt(format_args!("#{idx}"))
|
||||
}
|
||||
})?;
|
||||
f.write_str(")")
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, I: Clone + IntoIterator<Item = usize>> Display for SliceDisplay<'a, IndexSliceDisplay<I>> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
f.write_str("(")?;
|
||||
self.0.iter().enumerate().try_for_each(|(i, x)| {
|
||||
if i != 0 {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
Display::fmt(x, f)
|
||||
})?;
|
||||
f.write_str(")")
|
||||
}
|
||||
}
|
||||
|
||||
/// trait for outputting by STEP file format.
|
||||
pub trait DisplayByStep {
|
||||
/// formatter
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result;
|
||||
}
|
||||
|
||||
impl<T: DisplayByStep> DisplayByStep for &T {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result { DisplayByStep::fmt(*self, idx, f) }
|
||||
}
|
||||
|
||||
impl<T: DisplayByStep> DisplayByStep for Box<T> {
|
||||
fn fmt(&self, idx: usize, f: &mut Formatter<'_>) -> Result {
|
||||
DisplayByStep::fmt(self.as_ref(), idx, f)
|
||||
}
|
||||
}
|
||||
|
||||
/// Display struct for outputting some objects to STEP file format.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct StepDisplay<T> {
|
||||
entity: T,
|
||||
idx: usize,
|
||||
}
|
||||
|
||||
impl<'a, T> Display for SliceDisplay<'a, StepDisplay<T>>
|
||||
where StepDisplay<T>: Display
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
self.0.iter().try_for_each(|x| Display::fmt(x, f))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> StepDisplay<T> {
|
||||
/// constructor
|
||||
#[inline]
|
||||
pub const fn new(entity: T, idx: usize) -> Self { Self { entity, idx } }
|
||||
/// return entity
|
||||
#[inline]
|
||||
pub const fn entity(&self) -> &T { &self.entity }
|
||||
/// return index
|
||||
#[inline]
|
||||
pub const fn index(&self) -> usize { self.idx }
|
||||
}
|
||||
|
||||
impl<T: DisplayByStep> Display for StepDisplay<T> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result { DisplayByStep::fmt(&self.entity, self.idx, f) }
|
||||
}
|
||||
|
||||
/// Calculate how many lines are used in outputting an object to a STEP file
|
||||
pub trait StepLength {
|
||||
/// Calculate how many lines are used in outputting an object to a STEP file
|
||||
fn step_length(&self) -> usize;
|
||||
}
|
||||
|
||||
impl<T: StepLength> StepLength for &T {
|
||||
#[inline(always)]
|
||||
fn step_length(&self) -> usize { StepLength::step_length(*self) }
|
||||
}
|
||||
|
||||
impl<T: StepLength> StepLength for Box<T> {
|
||||
#[inline(always)]
|
||||
fn step_length(&self) -> usize { self.as_ref().step_length() }
|
||||
}
|
||||
|
||||
/// Constant numbers of lines for outputting an object to a STEP file.
|
||||
/// `x.step_length() == X::LENGTH` must always hold.
|
||||
pub trait ConstStepLength: StepLength {
|
||||
/// the number of line
|
||||
const LENGTH: usize;
|
||||
}
|
||||
|
||||
impl<T: ConstStepLength> ConstStepLength for &T {
|
||||
const LENGTH: usize = T::LENGTH;
|
||||
}
|
||||
|
||||
impl<T: ConstStepLength> ConstStepLength for Box<T> {
|
||||
const LENGTH: usize = T::LENGTH;
|
||||
}
|
||||
|
||||
macro_rules! impl_const_step_length {
|
||||
($type: ty, $len: expr $(,<$($gen: ident),*>)?) => {
|
||||
impl$(<$($gen),*>)? ConstStepLength for $type {
|
||||
const LENGTH: usize = $len;
|
||||
}
|
||||
impl$(<$($gen),*>)? StepLength for $type {
|
||||
#[inline(always)]
|
||||
fn step_length(&self) -> usize { <Self as ConstStepLength>::LENGTH }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Additional information for output to `edge_curve`.
|
||||
pub trait StepCurve {
|
||||
/// the parameter `same_sense`.
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { true }
|
||||
}
|
||||
|
||||
impl<T: StepCurve> StepCurve for &T {
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { (*self).same_sense() }
|
||||
}
|
||||
|
||||
impl<T: StepCurve> StepCurve for Box<T> {
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { self.as_ref().same_sense() }
|
||||
}
|
||||
|
||||
/// Additional information for output to `face_surface`.
|
||||
pub trait StepSurface {
|
||||
/// the parameter `same_sense`.
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { true }
|
||||
}
|
||||
|
||||
impl<T: StepSurface> StepSurface for &T {
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { (*self).same_sense() }
|
||||
}
|
||||
|
||||
impl<T: StepSurface> StepSurface for Box<T> {
|
||||
#[inline(always)]
|
||||
fn same_sense(&self) -> bool { self.as_ref().same_sense() }
|
||||
}
|
||||
|
||||
/// Describe STEP file header
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct StepHeaderDescriptor {
|
||||
/// file name
|
||||
pub file_name: String,
|
||||
/// time stamp
|
||||
pub time_stamp: String,
|
||||
/// authors
|
||||
pub authors: Vec<String>,
|
||||
/// organization
|
||||
pub organization: Vec<String>,
|
||||
/// organization system
|
||||
pub organization_system: String,
|
||||
/// authorization
|
||||
pub authorization: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct StepHeader {
|
||||
file_name: String,
|
||||
time_stamp: String,
|
||||
authors: Vec<String>,
|
||||
organization: Vec<String>,
|
||||
origination_system: String,
|
||||
authorization: String,
|
||||
schema: String,
|
||||
}
|
||||
|
||||
impl Default for StepHeaderDescriptor {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
file_name: Default::default(),
|
||||
time_stamp: chrono::Utc::now().naive_local().to_string(),
|
||||
authors: Default::default(),
|
||||
organization: Default::default(),
|
||||
organization_system: Default::default(),
|
||||
authorization: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for StepHeader {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
let empty_string = [String::new()];
|
||||
f.write_fmt(format_args!(
|
||||
"HEADER;
|
||||
FILE_DESCRIPTION(('Shape Data from Truck'), '2;1');
|
||||
FILE_NAME('{}', '{}', ({}), ({}), 'truck', '{}', '{}');
|
||||
FILE_SCHEMA(('{}'));
|
||||
ENDSEC;\n",
|
||||
self.file_name,
|
||||
self.time_stamp,
|
||||
if self.authors.is_empty() {
|
||||
SliceDisplay(&empty_string)
|
||||
} else {
|
||||
SliceDisplay(&self.authors)
|
||||
},
|
||||
if self.organization.is_empty() {
|
||||
SliceDisplay(&empty_string)
|
||||
} else {
|
||||
SliceDisplay(&self.organization)
|
||||
},
|
||||
self.origination_system,
|
||||
self.authorization,
|
||||
self.schema,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// Display model with configuations
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct StepModel<'a, P, C, S>(PreStepModel<'a, P, C, S>);
|
||||
|
||||
/// Display models with configuations
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct StepModels<'a, P, C, S> {
|
||||
models: Vec<PreStepModel<'a, P, C, S>>,
|
||||
next_idx: usize,
|
||||
}
|
||||
|
||||
/// Display struct for outputting STEP file format with header.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CompleteStepDisplay<T> {
|
||||
display: T,
|
||||
header: StepHeader,
|
||||
}
|
||||
|
||||
impl<T: Display> Display for CompleteStepDisplay<T> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
f.write_fmt(format_args!(
|
||||
"ISO-10303-21;\n{}DATA;\n{}ENDSEC;\nEND-ISO-10303-21;\n",
|
||||
self.header, self.display,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> CompleteStepDisplay<T> {
|
||||
/// constructor
|
||||
#[inline]
|
||||
pub fn new(display: T, header: StepHeaderDescriptor) -> Self {
|
||||
CompleteStepDisplay {
|
||||
display,
|
||||
header: StepHeader {
|
||||
file_name: header.file_name,
|
||||
time_stamp: header.time_stamp,
|
||||
authors: header.authors,
|
||||
organization: header.organization,
|
||||
origination_system: header.organization_system,
|
||||
authorization: header.authorization,
|
||||
schema: "ISO-10303-042".to_string(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod geometry;
|
||||
mod topology;
|
||||
pub use geometry::VectorAsDirection;
|
||||
+493
@@ -0,0 +1,493 @@
|
||||
use super::{Result, *};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(super) struct StepShell<'a, P, C, S> {
|
||||
entity: &'a CompressedShell<P, C, S>,
|
||||
idx: usize,
|
||||
face_indices: Vec<usize>,
|
||||
ep_edges: usize,
|
||||
ep_vertices: usize,
|
||||
surface_indices: Vec<usize>,
|
||||
curve_indices: Vec<usize>,
|
||||
ep_points: usize,
|
||||
is_open: bool,
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> StepShell<'a, P, C, S>
|
||||
where
|
||||
P: Copy,
|
||||
C: StepLength,
|
||||
S: StepLength,
|
||||
{
|
||||
fn new(shell: &'a CompressedShell<P, C, S>, idx: usize, is_open: bool) -> Self {
|
||||
let faces = &shell.faces;
|
||||
let edges = &shell.edges;
|
||||
let vertices = &shell.vertices;
|
||||
let mut cursor = idx + 1;
|
||||
let face_indices = faces
|
||||
.iter()
|
||||
.map(|f| {
|
||||
let res = cursor;
|
||||
cursor += match f.boundaries.is_empty() {
|
||||
true => 5,
|
||||
false => 1 + f.boundaries.iter().map(|b| 2 + b.len()).sum::<usize>(),
|
||||
};
|
||||
res
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let ep_edges = cursor;
|
||||
let ep_vertices = ep_edges + edges.len();
|
||||
cursor = ep_vertices + vertices.len();
|
||||
let surface_indices = faces
|
||||
.iter()
|
||||
.map(|f| {
|
||||
let res = cursor;
|
||||
cursor += f.surface.step_length();
|
||||
res
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let curve_indices = edges
|
||||
.iter()
|
||||
.map(|e| {
|
||||
let res = cursor;
|
||||
cursor += e.curve.step_length();
|
||||
res
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let ep_points = cursor;
|
||||
StepShell {
|
||||
entity: shell,
|
||||
idx,
|
||||
face_indices,
|
||||
ep_edges,
|
||||
ep_vertices,
|
||||
surface_indices,
|
||||
curve_indices,
|
||||
ep_points,
|
||||
is_open,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> Display for StepShell<'a, P, C, S>
|
||||
where
|
||||
P: DisplayByStep + Copy,
|
||||
C: DisplayByStep + StepCurve,
|
||||
S: DisplayByStep + StepSurface,
|
||||
{
|
||||
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result {
|
||||
let StepShell {
|
||||
entity,
|
||||
idx,
|
||||
face_indices,
|
||||
ep_edges,
|
||||
ep_vertices,
|
||||
surface_indices,
|
||||
curve_indices,
|
||||
ep_points,
|
||||
is_open,
|
||||
} = self;
|
||||
let faces = &entity.faces;
|
||||
let edges = &entity.edges;
|
||||
let vertices = &entity.vertices;
|
||||
let shell_kind = match is_open {
|
||||
true => "OPEN_SHELL",
|
||||
false => "CLOSED_SHELL",
|
||||
};
|
||||
formatter.write_fmt(format_args!(
|
||||
"#{idx} = {shell_kind}('', {face_indices});\n",
|
||||
face_indices = IndexSliceDisplay(self.face_indices.clone()),
|
||||
))?;
|
||||
faces.iter().enumerate().try_for_each(|(i, f)| {
|
||||
let idx = face_indices[i];
|
||||
let mut cursor = idx + 1;
|
||||
let face_geometry = surface_indices[i];
|
||||
let face_bounds = match f.boundaries.is_empty() {
|
||||
true => vec![cursor],
|
||||
false => {
|
||||
let closure = |b: &Vec<CompressedEdgeIndex>| {
|
||||
let res = cursor;
|
||||
cursor += 2 + b.len();
|
||||
res
|
||||
};
|
||||
f.boundaries.iter().map(closure).collect()
|
||||
}
|
||||
};
|
||||
formatter.write_fmt(format_args!(
|
||||
"#{idx} = FACE_SURFACE('', {face_bound}, #{face_geometry}, {same_sense});\n",
|
||||
same_sense = BooleanDisplay(f.orientation == f.surface.same_sense()),
|
||||
face_bound = IndexSliceDisplay(face_bounds.clone()),
|
||||
))?;
|
||||
cursor = idx + 1;
|
||||
if f.boundaries.is_empty() {
|
||||
let face_bound_idx = cursor;
|
||||
let vertex_loop_idx = cursor + 1;
|
||||
let vertex_idx = cursor + 2;
|
||||
let vertex_geometry = cursor + 3;
|
||||
formatter.write_fmt(format_args!(
|
||||
"#{face_bound_idx} = FACE_BOUND('', #{vertex_loop_idx}, .T.);
|
||||
#{vertex_loop_idx} = VERTEX_LOOP('', #{vertex_idx});
|
||||
#{vertex_idx} = VERTEX_POINT('', #{vertex_geometry});
|
||||
#{vertex_geometry} = POINT_ON_SURFACE('', #{face_geometry}, 0.0, 0.0);\n"
|
||||
))?;
|
||||
}
|
||||
f.boundaries.iter().try_for_each(|b| {
|
||||
let face_bound_idx = cursor;
|
||||
let edge_loop_idx = cursor + 1;
|
||||
let ep_oriented_edges = cursor + 2;
|
||||
cursor += 2 + b.len();
|
||||
formatter.write_fmt(format_args!(
|
||||
"#{face_bound_idx} = FACE_BOUND('', #{edge_loop_idx}, {orientation});
|
||||
#{edge_loop_idx} = EDGE_LOOP('', {oriented_edge_indices});\n",
|
||||
orientation = BooleanDisplay(f.orientation),
|
||||
oriented_edge_indices =
|
||||
IndexSliceDisplay(ep_oriented_edges..ep_oriented_edges + b.len()),
|
||||
))?;
|
||||
b.iter().enumerate().try_for_each(|(j, ce)| {
|
||||
formatter.write_fmt(format_args!(
|
||||
"#{idx} = ORIENTED_EDGE('', *, *, #{edge_element}, {orientation});\n",
|
||||
idx = ep_oriented_edges + j,
|
||||
edge_element = ep_edges + ce.index,
|
||||
orientation = if ce.orientation { ".T." } else { ".F." },
|
||||
))
|
||||
})
|
||||
})
|
||||
})?;
|
||||
edges.iter().enumerate().try_for_each(|(i, e)| {
|
||||
let same_sense = if e.curve.same_sense() { ".T." } else { ".F." };
|
||||
formatter.write_fmt(format_args!(
|
||||
"#{idx} = EDGE_CURVE('', #{edge_start}, #{edge_end}, #{edge_geometry}, {same_sense});\n",
|
||||
idx = ep_edges + i,
|
||||
edge_start = ep_vertices + e.vertices.0,
|
||||
edge_end = ep_vertices + e.vertices.1,
|
||||
edge_geometry = curve_indices[i],
|
||||
))
|
||||
})?;
|
||||
(0..vertices.len()).try_for_each(|i| {
|
||||
formatter.write_fmt(format_args!(
|
||||
"#{idx} = VERTEX_POINT('', #{vertex_geometry});\n",
|
||||
idx = ep_vertices + i,
|
||||
vertex_geometry = ep_points + i,
|
||||
))
|
||||
})?;
|
||||
faces.iter().zip(surface_indices).try_for_each(|(f, idx)| {
|
||||
Display::fmt(&StepDisplay::new(&f.surface, *idx), formatter)
|
||||
})?;
|
||||
edges
|
||||
.iter()
|
||||
.zip(curve_indices)
|
||||
.try_for_each(|(e, idx)| Display::fmt(&StepDisplay::new(&e.curve, *idx), formatter))?;
|
||||
vertices
|
||||
.iter()
|
||||
.enumerate()
|
||||
.try_for_each(|(i, v)| Display::fmt(&StepDisplay::new(*v, ep_points + i), formatter))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> StepLength for StepShell<'a, P, C, S> {
|
||||
fn step_length(&self) -> usize {
|
||||
1 + self.ep_points + self.entity.vertices.len() - self.face_indices[0]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(super) struct StepSolid<'a, P, C, S> {
|
||||
idx: usize,
|
||||
boundaries: Vec<StepShell<'a, P, C, S>>,
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> StepSolid<'a, P, C, S>
|
||||
where
|
||||
P: Copy,
|
||||
C: StepLength,
|
||||
S: StepLength,
|
||||
{
|
||||
fn new(solid: &'a CompressedSolid<P, C, S>, idx: usize) -> Self {
|
||||
let mut cursor = idx + 1;
|
||||
let boundaries = solid
|
||||
.boundaries
|
||||
.iter()
|
||||
.map(|shell| {
|
||||
let res = StepShell::new(shell, cursor, false);
|
||||
cursor += 1 + res.step_length();
|
||||
res
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
StepSolid { idx, boundaries }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> Display for StepSolid<'a, P, C, S>
|
||||
where
|
||||
P: DisplayByStep + Copy,
|
||||
C: DisplayByStep + StepLength + StepCurve,
|
||||
S: DisplayByStep + StepLength + StepSurface,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
let StepSolid { idx, boundaries } = self;
|
||||
match boundaries.len() {
|
||||
0 => {
|
||||
f.pad("empty solid!")?;
|
||||
Err(std::fmt::Error)
|
||||
}
|
||||
1 => {
|
||||
let shell_idx = idx + 1;
|
||||
let step_shell = &boundaries[0];
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = MANIFOLD_SOLID_BREP('', #{shell_idx});\n"
|
||||
))?;
|
||||
Display::fmt(step_shell, f)
|
||||
}
|
||||
_ => {
|
||||
let first_shell_idx = boundaries[0].face_indices[0] - 1;
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = BREP_WITH_VOIDS('', #{first_shell_idx}, {other_shells});\n",
|
||||
other_shells = IndexSliceDisplay(
|
||||
boundaries[1..]
|
||||
.iter()
|
||||
.map(|step_shell| step_shell.face_indices[0] - 2)
|
||||
),
|
||||
))?;
|
||||
Display::fmt(&boundaries[0], f)?;
|
||||
boundaries[1..].iter().try_for_each(|step_shell| {
|
||||
let oriented_shell_idx = step_shell.face_indices[0] - 2;
|
||||
let shell_idx = step_shell.face_indices[0] - 1;
|
||||
f.write_fmt(format_args!(
|
||||
"#{oriented_shell_idx} = ORIENTED_CLOSED_SHELL('', *, #{shell_idx}, .T.);\n",
|
||||
))?;
|
||||
Display::fmt(step_shell, f)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> StepLength for StepSolid<'a, P, C, S> {
|
||||
fn step_length(&self) -> usize {
|
||||
let b = &self.boundaries;
|
||||
match b.len() {
|
||||
0 => 0,
|
||||
1 => 1 + b[0].step_length(),
|
||||
_ => b.len() + b.iter().map(StepLength::step_length).sum::<usize>(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(super) enum PreStepModel<'a, P, C, S> {
|
||||
/// shell based surface model
|
||||
Shell(StepShell<'a, P, C, S>),
|
||||
/// solid model
|
||||
Solid(StepSolid<'a, P, C, S>),
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> From<&'a CompressedShell<P, C, S>> for PreStepModel<'a, P, C, S>
|
||||
where
|
||||
P: Copy,
|
||||
C: StepLength,
|
||||
S: StepLength,
|
||||
{
|
||||
fn from(shell: &'a CompressedShell<P, C, S>) -> Self {
|
||||
Self::Shell(StepShell::new(shell, 17, true))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> From<&'a CompressedSolid<P, C, S>> for PreStepModel<'a, P, C, S>
|
||||
where
|
||||
P: Copy,
|
||||
C: StepLength,
|
||||
S: StepLength,
|
||||
{
|
||||
fn from(solid: &'a CompressedSolid<P, C, S>) -> Self { Self::Solid(StepSolid::new(solid, 16)) }
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> Display for PreStepModel<'a, P, C, S>
|
||||
where
|
||||
P: DisplayByStep + Copy,
|
||||
C: DisplayByStep + StepLength + StepCurve,
|
||||
S: DisplayByStep + StepLength + StepSurface,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
match self {
|
||||
Self::Shell(x) => {
|
||||
f.write_fmt(format_args!(
|
||||
"#{idx} = SHELL_BASED_SURFACE_MODEL('', (#{shell_idx}));\n",
|
||||
idx = x.idx - 1,
|
||||
shell_idx = x.idx
|
||||
))?;
|
||||
Display::fmt(&x, f)
|
||||
}
|
||||
Self::Solid(x) => Display::fmt(x, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> StepLength for PreStepModel<'a, P, C, S> {
|
||||
fn step_length(&self) -> usize {
|
||||
match self {
|
||||
Self::Shell(x) => 1 + x.step_length(),
|
||||
Self::Solid(x) => x.step_length(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> From<&'a CompressedShell<P, C, S>> for StepModel<'a, P, C, S>
|
||||
where
|
||||
P: Copy,
|
||||
C: StepLength,
|
||||
S: StepLength,
|
||||
{
|
||||
fn from(shell: &'a CompressedShell<P, C, S>) -> Self { Self(shell.into()) }
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> From<&'a CompressedSolid<P, C, S>> for StepModel<'a, P, C, S>
|
||||
where
|
||||
P: Copy,
|
||||
C: StepLength,
|
||||
S: StepLength,
|
||||
{
|
||||
fn from(solid: &'a CompressedSolid<P, C, S>) -> Self { Self(solid.into()) }
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> Display for StepModel<'a, P, C, S>
|
||||
where
|
||||
P: DisplayByStep + Copy,
|
||||
C: DisplayByStep + StepLength + StepCurve,
|
||||
S: DisplayByStep + StepLength + StepSurface,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
f.pad(
|
||||
"#1 = APPLICATION_PROTOCOL_DEFINITION('international standard', 'automotive_design', 2000, #2);
|
||||
#2 = APPLICATION_CONTEXT('core data for automotive mechanical design processes');
|
||||
#3 = SHAPE_DEFINITION_REPRESENTATION(#4, #10);
|
||||
#4 = PRODUCT_DEFINITION_SHAPE('','', #5);
|
||||
#5 = PRODUCT_DEFINITION('design','', #6, #9);
|
||||
#6 = PRODUCT_DEFINITION_FORMATION('','', #7);
|
||||
#7 = PRODUCT('','','', (#8));
|
||||
#8 = PRODUCT_CONTEXT('', #2, 'mechanical');
|
||||
#9 = PRODUCT_DEFINITION_CONTEXT('part definition', #2, 'design');
|
||||
#10 = ADVANCED_BREP_SHAPE_REPRESENTATION('', (#16), #11);
|
||||
#11 = (
|
||||
GEOMETRIC_REPRESENTATION_CONTEXT(3)
|
||||
GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#15))
|
||||
GLOBAL_UNIT_ASSIGNED_CONTEXT((#12, #13, #14))
|
||||
REPRESENTATION_CONTEXT('Context #1', '3D Context with UNIT and UNCERTAINTY')
|
||||
);
|
||||
#12 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );
|
||||
#13 = ( NAMED_UNIT(*) PLANE_ANGLE_UNIT() SI_UNIT($,.RADIAN.) );
|
||||
#14 = ( NAMED_UNIT(*) SI_UNIT($,.STERADIAN.) SOLID_ANGLE_UNIT() );
|
||||
#15 = UNCERTAINTY_MEASURE_WITH_UNIT(1.0E-6, #12, 'distance_accuracy_value','confusion accuracy');\n"
|
||||
)?;
|
||||
Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> Default for StepModels<'a, P, C, S> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
models: Vec::new(),
|
||||
next_idx: 16,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> StepModels<'a, P, C, S>
|
||||
where
|
||||
P: Copy,
|
||||
C: StepLength,
|
||||
S: StepLength,
|
||||
{
|
||||
/// push a shell to step models
|
||||
pub fn push_shell(&mut self, shell: &'a CompressedShell<P, C, S>) {
|
||||
let model = PreStepModel::Shell(StepShell::new(shell, self.next_idx + 1, true));
|
||||
self.next_idx += model.step_length();
|
||||
self.models.push(model)
|
||||
}
|
||||
/// push a solid to step models
|
||||
pub fn push_solid(&mut self, solid: &'a CompressedSolid<P, C, S>) {
|
||||
let model = PreStepModel::Solid(StepSolid::new(solid, self.next_idx));
|
||||
self.next_idx += model.step_length();
|
||||
self.models.push(model)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> FromIterator<&'a CompressedShell<P, C, S>> for StepModels<'a, P, C, S>
|
||||
where
|
||||
P: Copy,
|
||||
C: StepLength,
|
||||
S: StepLength,
|
||||
{
|
||||
fn from_iter<T: IntoIterator<Item = &'a CompressedShell<P, C, S>>>(iter: T) -> Self {
|
||||
let mut next_idx = 16;
|
||||
let models = iter
|
||||
.into_iter()
|
||||
.map(|shell| {
|
||||
let model = PreStepModel::Shell(StepShell::new(shell, next_idx + 1, true));
|
||||
next_idx += model.step_length();
|
||||
model
|
||||
})
|
||||
.collect();
|
||||
Self { models, next_idx }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> FromIterator<&'a CompressedSolid<P, C, S>> for StepModels<'a, P, C, S>
|
||||
where
|
||||
P: Copy,
|
||||
C: StepLength,
|
||||
S: StepLength,
|
||||
{
|
||||
fn from_iter<T: IntoIterator<Item = &'a CompressedSolid<P, C, S>>>(iter: T) -> Self {
|
||||
let mut next_idx = 16;
|
||||
let models = iter
|
||||
.into_iter()
|
||||
.map(|solid| {
|
||||
let model = PreStepModel::Solid(StepSolid::new(solid, next_idx));
|
||||
next_idx += model.step_length();
|
||||
model
|
||||
})
|
||||
.collect();
|
||||
Self { models, next_idx }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P, C, S> Display for StepModels<'a, P, C, S>
|
||||
where
|
||||
P: DisplayByStep + Copy,
|
||||
C: DisplayByStep + StepLength + StepCurve,
|
||||
S: DisplayByStep + StepLength + StepSurface,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
f.pad(
|
||||
"#1 = APPLICATION_PROTOCOL_DEFINITION('international standard', 'automotive_design', 2000, #2);
|
||||
#2 = APPLICATION_CONTEXT('core data for automotive mechanical design processes');
|
||||
#3 = SHAPE_DEFINITION_REPRESENTATION(#4, #10);
|
||||
#4 = PRODUCT_DEFINITION_SHAPE('','', #5);
|
||||
#5 = PRODUCT_DEFINITION('design','', #6, #9);
|
||||
#6 = PRODUCT_DEFINITION_FORMATION('','', #7);
|
||||
#7 = PRODUCT('','','', (#8));
|
||||
#8 = PRODUCT_CONTEXT('', #2, 'mechanical');
|
||||
#9 = PRODUCT_DEFINITION_CONTEXT('part definition', #2, 'design');\n")?;
|
||||
let models_slice = IndexSliceDisplay(self.models.iter().map(|model| match model {
|
||||
PreStepModel::Shell(x) => x.idx - 1,
|
||||
PreStepModel::Solid(x) => x.idx,
|
||||
}));
|
||||
f.write_fmt(format_args!(
|
||||
"#10 = ADVANCED_BREP_SHAPE_REPRESENTATION('', {models_slice}, #11);\n"
|
||||
))?;
|
||||
f.pad("#11 = (
|
||||
GEOMETRIC_REPRESENTATION_CONTEXT(3)
|
||||
GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#15))
|
||||
GLOBAL_UNIT_ASSIGNED_CONTEXT((#12, #13, #14))
|
||||
REPRESENTATION_CONTEXT('Context #1', '3D Context with UNIT and UNCERTAINTY')
|
||||
);
|
||||
#12 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );
|
||||
#13 = ( NAMED_UNIT(*) PLANE_ANGLE_UNIT() SI_UNIT($,.RADIAN.) );
|
||||
#14 = ( NAMED_UNIT(*) SI_UNIT($,.STERADIAN.) SOLID_ANGLE_UNIT() );
|
||||
#15 = UNCERTAINTY_MEASURE_WITH_UNIT(1.0E-6, #12, 'distance_accuracy_value','confusion accuracy');\n"
|
||||
)?;
|
||||
self.models
|
||||
.iter()
|
||||
.try_for_each(|model| Display::fmt(model, f))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user