forked from 1b-agent/opencadstudio-upstream
IMPORT: read SAT, STEP, IGES and WMF files; ACISIN and WMFIN
ACIS text files come in one object per body (3DSOLID, REGION or SURFACE). STEP B-rep models become a block per product with component inserts at their placements, scaled to the drawing's units; IGES manifold solids come in as 3DSOLIDs scaled to the drawing's units with their colours. Splines that are exactly analytic shapes are kept as those shapes. Windows metafiles become a WMF<n> block of polylines and text fitted to half the view, placed at its top-left corner or by WMFIN's insertion prompts. The Import File window lists the four formats as supported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3c9404510f
commit
659bb06cd6
38 files changed
+2400
-113
No files matched your search
@@ -0,0 +1,75 @@
|
||||
//! ACIS text (SAT) files and kernel bodies as drawing objects.
|
||||
//!
|
||||
//! Each body of a file becomes one object: a closed solid a 3DSOLID, a sheet
|
||||
//! whose faces all lie on planes a REGION, any other sheet a SURFACE — the
|
||||
//! classes the ACIS import of the reference application produces.
|
||||
|
||||
use codec::entities::acis::{SatDocument, SatFace, Sidedness};
|
||||
use codec::entities::{AcisData, Region, Solid3D, Surface, SurfaceKind};
|
||||
use codec::EntityType;
|
||||
|
||||
/// What a body restores as.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum Class {
|
||||
Solid,
|
||||
Region,
|
||||
Surface,
|
||||
}
|
||||
|
||||
fn class(document: &SatDocument) -> Option<Class> {
|
||||
let faces: Vec<SatFace<'_>> = document
|
||||
.records
|
||||
.iter()
|
||||
.filter_map(SatFace::from_record)
|
||||
.collect();
|
||||
if faces.is_empty() {
|
||||
return None;
|
||||
}
|
||||
if faces
|
||||
.iter()
|
||||
.all(|face| face.sidedness() != Sidedness::Double)
|
||||
{
|
||||
return Some(Class::Solid);
|
||||
}
|
||||
let planar = faces.iter().all(|face| {
|
||||
face.surface()
|
||||
.index()
|
||||
.and_then(|at| document.record(at))
|
||||
.is_some_and(|surface| surface.entity_type == "plane-surface")
|
||||
});
|
||||
Some(if planar { Class::Region } else { Class::Surface })
|
||||
}
|
||||
|
||||
/// One body's document as its drawing object.
|
||||
fn entity(document: &SatDocument) -> Option<EntityType> {
|
||||
Some(match class(document)? {
|
||||
Class::Solid => {
|
||||
let mut solid = Solid3D::new();
|
||||
solid.set_sat_document(document);
|
||||
EntityType::Solid3D(solid)
|
||||
}
|
||||
Class::Region => {
|
||||
let mut region = Region::new();
|
||||
region.set_sat_document(document);
|
||||
EntityType::Region(region)
|
||||
}
|
||||
Class::Surface => {
|
||||
let mut surface = Surface::new(SurfaceKind::Generic);
|
||||
surface.acis_data = AcisData::from_sat(&document.to_sat_string());
|
||||
EntityType::Surface(Box::new(surface))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// The objects of an ACIS text file, one per body with faces; `None` when
|
||||
/// the text is no ACIS data.
|
||||
pub fn sat_entities(text: &str) -> Option<Vec<EntityType>> {
|
||||
let document = SatDocument::parse(text).ok()?;
|
||||
Some(document.split_bodies().iter().filter_map(entity).collect())
|
||||
}
|
||||
|
||||
/// A kernel body as its drawing object, written as exact ACIS.
|
||||
pub fn body_entity(body: &kernel::brep::Body) -> Option<EntityType> {
|
||||
let document = super::acis_export::solid_to_sat(body)?;
|
||||
entity(&document)
|
||||
}
|
||||
Reference in new issue
Block a user