forked from 1b-agent/opencadstudio-upstream
Merge pull request #1632 from ramox81/codex/sweep-miter-history
Sweep history records in the reference layout. Pins resolved to upstream: codec bff95f5 (#93, #94, #95, #96, #97 and review fixes), kernel 6146d31 (#75 and review fixes), graph 9635ba7.
This commit is contained in:
commit
0149a276ef
9 files changed
+65
-23
No files matched your search
@@ -486,6 +486,8 @@ impl OpenCADStudio {
|
||||
.iter()
|
||||
.map(|(_, entity)| entity.clone())
|
||||
.collect::<Vec<_>>();
|
||||
// Group 294: a base point the user picked.
|
||||
let picked_base = options.base_point.is_some();
|
||||
let options = sweep_model::sweep_selection_options(&selection, options);
|
||||
let pending = if profiles.is_empty() {
|
||||
None
|
||||
@@ -496,7 +498,8 @@ impl OpenCADStudio {
|
||||
let mut consumed = Vec::new();
|
||||
for (handle, profile) in profiles {
|
||||
let result = path.as_ref().zip(options).and_then(|(path, options)| {
|
||||
let record = sweep_model::sweep_record(&profile, path, options)?;
|
||||
let mut record = sweep_model::sweep_record(&profile, path, options)?;
|
||||
record.flags_294_296[0] |= picked_base;
|
||||
let (_, _, closed) = kernel::acis::sweep_profile_geometry(
|
||||
record.sweep_entity.as_ref()?,
|
||||
record.sweep_entity_transform,
|
||||
|
||||
@@ -315,7 +315,7 @@ fn history_operation_text(operation: &SolidHistoryOperation) -> String {
|
||||
value.base_face
|
||||
),
|
||||
SolidHistoryOperation::Sweep(value) | SolidHistoryOperation::Extrusion(value) => format!(
|
||||
"{}; sweep {}; path {}; direction {:.6},{:.6},{:.6}; draft {:.6}; scale {:.6}; twist {:.6}; align {:.6}; bank {}; intersections {}",
|
||||
"{}; sweep {}; path {}; direction {:.6},{:.6},{:.6}; draft {:.6}; scale {:.6}; twist {:.6}; align {:.6}; align start {}; bank {}",
|
||||
history_base_text(&value.base),
|
||||
embedded_name(value.sweep_entity.as_ref()),
|
||||
embedded_name(value.path_entity.as_ref()),
|
||||
@@ -326,8 +326,8 @@ fn history_operation_text(operation: &SolidHistoryOperation) -> String {
|
||||
value.scale_factor,
|
||||
value.twist_angle,
|
||||
value.align_angle,
|
||||
value.bank,
|
||||
value.check_intersections
|
||||
value.align_start,
|
||||
value.bank
|
||||
),
|
||||
SolidHistoryOperation::Loft(value) => format!(
|
||||
"{}; cross sections {}; guides {}",
|
||||
|
||||
@@ -651,7 +651,7 @@ pub fn extrusion_surface_data(
|
||||
path_entity_transform: value.path_entity_transform,
|
||||
is_solid: false,
|
||||
sweep_alignment_flags: value.align_option as i16,
|
||||
align_start: value.has_align_start,
|
||||
align_start: value.align_start,
|
||||
bank: value.bank,
|
||||
base_point_set: true,
|
||||
reference_vector: value.reference_point,
|
||||
|
||||
@@ -17,6 +17,24 @@ fn embedded_sweep_profile(entity: &EntityType) -> Option<(codec::entities::Embed
|
||||
}
|
||||
}
|
||||
|
||||
/// The sweep path as the reference records it: a 3D polyline as a wire
|
||||
/// body, anything else as its embedded entity.
|
||||
fn embedded_sweep_path(path: &EntityType) -> Option<codec::entities::EmbeddedEntity> {
|
||||
let EntityType::Polyline3D(value) = path else {
|
||||
return embedded_path(path);
|
||||
};
|
||||
let points = value.vertices.iter()
|
||||
.map(|vertex| [vertex.position.x, vertex.position.y, vertex.position.z])
|
||||
.collect::<Vec<_>>();
|
||||
let mut document = codec::entities::acis::SatDocument::new();
|
||||
kernel::acis::append_polyline_wire(&points, value.is_closed(), &mut document).ok()?;
|
||||
Some(codec::entities::EmbeddedEntity::Body {
|
||||
// The 3D polyline object type.
|
||||
type_code: 16,
|
||||
acis_data: codec::entities::AcisData::from_sat(&document.to_sat_string()),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn is_sweep_profile(entity: &EntityType) -> bool {
|
||||
embedded_sweep_profile(entity).is_some_and(|(profile, transform)| {
|
||||
kernel::acis::sweep_profile_geometry(&profile, transform).is_ok()
|
||||
@@ -64,10 +82,11 @@ pub fn sweep_record(profile: &EntityType, path: &EntityType, options: SweepOptio
|
||||
base,
|
||||
operation_major: 1,
|
||||
sweep_entity: Some(sweep_entity),
|
||||
path_entity: Some(embedded_path(path)?),
|
||||
path_entity: Some(embedded_sweep_path(path)?),
|
||||
scale_factor: options.scale,
|
||||
twist_angle: options.twist_angle,
|
||||
align_option: u8::from(options.align),
|
||||
// 1 aligns the profile to the path; 2 only moves it to the path start.
|
||||
align_option: if options.align { 1 } else { 2 },
|
||||
has_align_start: true,
|
||||
bank: options.bank,
|
||||
sweep_entity_transform,
|
||||
@@ -100,12 +119,32 @@ fn placed_sweep_record(profile: &EntityType, mut record: SolidHistorySweep) -> O
|
||||
[0.0, 0.0, 0.0, 1.0],
|
||||
],
|
||||
});
|
||||
// The record's matrices are the source profile frame (at the base point,
|
||||
// in the profile plane) and the frame it is placed in at the path start;
|
||||
// the reference re-places the profile from them when it re-evaluates.
|
||||
let (plane, _, _) = kernel::acis::sweep_profile_geometry(
|
||||
record.sweep_entity.as_ref()?,
|
||||
record.sweep_entity_transform,
|
||||
).ok()?;
|
||||
let x_axis = glam::DVec3::from_array(plane.x_axis).try_normalize()?;
|
||||
let normal = glam::DVec3::from_array(plane.normal()?);
|
||||
let base = glam::DVec3::new(record.reference_point.x, record.reference_point.y, record.reference_point.z);
|
||||
let source_frame = glam::DMat4::from_cols(
|
||||
x_axis.extend(0.0),
|
||||
normal.cross(x_axis).extend(0.0),
|
||||
normal.extend(0.0),
|
||||
base.extend(1.0),
|
||||
);
|
||||
let mut moved = profile.clone();
|
||||
crate::scene::view::dispatch::apply_transform(&mut moved, &crate::command::EntityTransform::Affine(transform));
|
||||
let (sweep_entity, sweep_entity_transform) = embedded_sweep_profile(&moved)?;
|
||||
let (sweep_entity, _) = embedded_sweep_profile(&moved)?;
|
||||
record.sweep_entity = Some(sweep_entity);
|
||||
record.sweep_entity_transform = sweep_entity_transform;
|
||||
record.flags_294_296 = [false, true, true];
|
||||
record.sweep_entity_transform = source_frame.to_cols_array();
|
||||
record.path_entity_transform = (map * source_frame).to_cols_array();
|
||||
// Group 294 marks a profile only moved to the path, not turned onto it.
|
||||
record.flags_294_296 = [record.align_option != 1, true, true];
|
||||
// The reference records its default mitred joint.
|
||||
record.miter_option = 2;
|
||||
record.reference_point = Vector3::new(0.0, 0.0, 0.0);
|
||||
Some(record)
|
||||
}
|
||||
@@ -135,7 +174,7 @@ pub fn swept_surface_entity(record: &SolidHistorySweep) -> EntityType {
|
||||
sweep_entity_transform: record.sweep_entity_transform,
|
||||
path_entity_transform: record.path_entity_transform,
|
||||
sweep_alignment_flags: record.align_option as i16,
|
||||
align_start: record.has_align_start,
|
||||
align_start: record.align_start,
|
||||
bank: record.bank,
|
||||
base_point_set: true,
|
||||
reference_vector: record.reference_point,
|
||||
|
||||
Reference in new issue
Block a user