forked from 1b-agent/opencadstudio-upstream
The codec and kernel repositories and crates are renamed opencadcodec and opencadkernel. Inside OCS they are depended on under short keys, so code reads `codec::`, `kernel::` and the new `graph::` (opencadgraph, the node graph engine). File-format and protocol spellings stay as they were: the ACIS product id `acadrust`, the ACADRUST_* switches and the plugin version keys `acadrust_version` / `acadrust_source`. A button left of MCP on the command line opens a translucent node graph over the viewport, with a palette of object, input, math, logic, list, text and geometry nodes added by click or drag. An object node owns drawing entities and its rows are the Properties panel's own rows for them: the single-object page is extracted from refresh_properties as entity_property_sections, values use the control protocol's property_json, and writes go through set_property_value with a property target override, so the panel, MCP and the graph share one read/write path. A list reaching an object row makes one entity per element. Each graph action is one undo step; the canvas pans and zooms. Co-Authored-By: Claude Opus 5.5 <[email protected]>
75 lines
2.6 KiB
Rust
75 lines
2.6 KiB
Rust
//! Export a kernel [`Body`] to an exact ACIS `SatDocument`.
|
|
//!
|
|
//! Analytic surfaces remain analytic instead of becoming facets.
|
|
|
|
use kernel::acis::append;
|
|
use codec::entities::acis::{SabReader, SabWriter, SatDocument};
|
|
use kernel::brep::Body;
|
|
|
|
/// Returns `None` when the body contains an unsupported record form.
|
|
pub fn solid_to_sat(body: &Body) -> Option<SatDocument> {
|
|
let mut document = SatDocument::new();
|
|
append(body, &mut document).ok()?;
|
|
let document = SatDocument::parse(&document.to_sat_string()).ok()?;
|
|
let valid = |candidate: &SatDocument| {
|
|
let (restored, loss) = kernel::acis::lift(candidate);
|
|
loss.is_empty() && restored.len() == 1 && restored[0].validate().is_empty()
|
|
};
|
|
if !valid(&document) {
|
|
return None;
|
|
}
|
|
let binary = SabWriter::write(&document);
|
|
valid(&SabReader::read(&binary).ok()?).then_some(document)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use kernel::geom2d::{Arc, Curve};
|
|
use kernel::space::Plane;
|
|
|
|
fn circle_section(z: f64, radius: f64) -> (Plane, Vec<Curve>) {
|
|
let curves = (0..4)
|
|
.map(|part| {
|
|
let start = std::f64::consts::FRAC_PI_2 * part as f64;
|
|
Curve::Arc(Arc {
|
|
centre: [0.0, 0.0],
|
|
radius,
|
|
start_angle: start,
|
|
end_angle: start + std::f64::consts::FRAC_PI_2,
|
|
})
|
|
})
|
|
.collect();
|
|
(
|
|
Plane::from_axes([0.0, 0.0, z], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]),
|
|
curves,
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn a_curved_loft_round_trips_through_text_and_binary_acis() {
|
|
let body = kernel::brep::loft(&[
|
|
circle_section(0.0, 5.0),
|
|
circle_section(10.0, 2.0),
|
|
])
|
|
.unwrap();
|
|
assert!(body.validate().is_empty());
|
|
|
|
let mut document = SatDocument::new();
|
|
kernel::acis::append(&body, &mut document).unwrap();
|
|
let text = document.to_sat_string();
|
|
let parsed = SatDocument::parse(&text).unwrap();
|
|
let (restored, text_loss) = kernel::acis::lift(&parsed);
|
|
assert!(text_loss.is_empty(), "{text_loss:?}");
|
|
assert_eq!(restored.len(), 1);
|
|
assert!(restored[0].validate().is_empty());
|
|
|
|
let binary = SabWriter::write(&parsed);
|
|
let parsed_binary = SabReader::read(&binary).unwrap();
|
|
let (restored, binary_loss) = kernel::acis::lift(&parsed_binary);
|
|
assert!(binary_loss.is_empty(), "{binary_loss:?}");
|
|
assert_eq!(restored.len(), 1);
|
|
assert!(restored[0].validate().is_empty());
|
|
}
|
|
}
|