Standardize parametric constraints and interoperability

This commit is contained in:
Hakan Seven committed 2026-09-15 03:19:52 +03:00
1 parent 753df67ee4
commit d738ebfcc6
41 files changed
+10038 -7847

No files matched your search

+65 -93
View File
@@ -9,9 +9,7 @@ struct TextOrient {
x_scale: f64,
}
fn inverse_affine(
transform: &acadrust::types::Transform,
) -> Option<acadrust::types::Transform> {
fn inverse_affine(transform: &acadrust::types::Transform) -> Option<acadrust::types::Transform> {
use acadrust::types::{Matrix3, Matrix4, Transform, Vector3};
let matrix = &transform.matrix.m;
let linear = Matrix3::from_rows(
@@ -248,9 +246,7 @@ impl Scene {
let image_bearing = self.document.get_entity(h).is_some_and(|entity| {
matches!(
entity,
EntityType::RasterImage(_)
| EntityType::Ole2Frame(_)
| EntityType::Underlay(_)
EntityType::RasterImage(_) | EntityType::Ole2Frame(_) | EntityType::Underlay(_)
)
});
if image_bearing {
@@ -301,10 +297,7 @@ impl Scene {
/// Entities in anonymous dimension blocks that visually belong to
/// dimensions inside `block_record`. They must follow a block-coordinate
/// reframe and be included in BEDIT's discard snapshot.
pub(crate) fn block_definition_dependent_handles(
&self,
block_record: Handle,
) -> Vec<Handle> {
pub(crate) fn block_definition_dependent_handles(&self, block_record: Handle) -> Vec<Handle> {
let Some(record) = self
.document
.block_records
@@ -367,17 +360,16 @@ impl Scene {
let owned: HashSet<Handle> = handles.iter().copied().collect();
let transform = EntityTransform::Affine(*local_from_old);
let matrix = &local_from_old.matrix.m;
let dependent_transform =
EntityTransform::Affine(acadrust::types::Transform::from_matrix(
acadrust::types::Matrix4 {
m: [
[matrix[0][0], matrix[0][1], matrix[0][2], 0.0],
[matrix[1][0], matrix[1][1], matrix[1][2], 0.0],
[matrix[2][0], matrix[2][1], matrix[2][2], 0.0],
[0.0, 0.0, 0.0, 1.0],
],
},
));
let dependent_transform = EntityTransform::Affine(acadrust::types::Transform::from_matrix(
acadrust::types::Matrix4 {
m: [
[matrix[0][0], matrix[0][1], matrix[0][2], 0.0],
[matrix[1][0], matrix[1][1], matrix[1][2], 0.0],
[matrix[2][0], matrix[2][1], matrix[2][2], 0.0],
[0.0, 0.0, 0.0, 1.0],
],
},
));
let mut changed = Vec::new();
for handle in handles {
@@ -596,10 +588,7 @@ impl Scene {
let entity = self.document.get_entity(h)?.clone();
let annotation_scales = if leader_pair_handles.contains(&h) {
crate::scene::annotative::annotation_scale_handles_for_entity(
&self.document,
h,
)
crate::scene::annotative::annotation_scale_handles_for_entity(&self.document, h)
} else {
Vec::new()
};
@@ -691,8 +680,8 @@ impl Scene {
if let Some(model) = new_model {
self.hatches.insert(h, model);
}
let rebuilt_history = self.copy_solid_history(src_handle, h)
&& self.transform_solid_history(h, t);
let rebuilt_history =
self.copy_solid_history(src_handle, h) && self.transform_solid_history(h, t);
if !rebuilt_history
&& self.document.get_entity(h).is_some_and(|entity| {
matches!(
@@ -717,8 +706,7 @@ impl Scene {
let leader_links: Vec<(Handle, Handle)> = handle_map
.iter()
.filter_map(|(&source_handle, &copied_handle)| {
let EntityType::Leader(source_leader) =
self.document.get_entity(source_handle)?
let EntityType::Leader(source_leader) = self.document.get_entity(source_handle)?
else {
return None;
};
@@ -733,9 +721,7 @@ impl Scene {
.collect();
for (leader_handle, annotation_handle) in leader_links {
if let Some(EntityType::Leader(leader)) =
self.document.get_entity_mut(leader_handle)
{
if let Some(EntityType::Leader(leader)) = self.document.get_entity_mut(leader_handle) {
leader.annotation_handle = annotation_handle;
}
@@ -753,7 +739,7 @@ impl Scene {
.collect();
self.bump_entities(&changes);
// Constraints wholly within the duplicated selection follow it.
self.duplicate_sketch_constraints_for(&handle_map);
self.duplicate_parametric_constraints_for(&handle_map);
self.refresh_meshes_for_handles(&refresh_solid_handles);
new_handles
}
@@ -840,11 +826,7 @@ impl Scene {
let Some(reference) = reference else {
return;
};
let point = acadrust::types::Vector3::new(
reference.x,
reference.y,
reference.z,
);
let point = acadrust::types::Vector3::new(reference.x, reference.y, reference.z);
match self.document.get_entity_mut(handle) {
Some(EntityType::Solid3D(entity)) => entity.point_of_reference = point,
Some(EntityType::Surface(entity)) => entity.point_of_reference = point,
@@ -928,7 +910,9 @@ impl Scene {
(EntityType::Surface(_), SolidHistoryOperation::Loft(value)) => {
let EntityType::Surface(surface) =
crate::scene::model::loft_command_model::surface_entity(value)
else { return None; };
else {
return None;
};
Some(Some(surface.surface_data))
}
(EntityType::Solid3D(_), _) => Some(None),
@@ -953,9 +937,11 @@ impl Scene {
let Some(display) = self.prepare_solid_model_display(handle, &body) else {
return false;
};
if matches!(&operation, acadrust::objects::SolidHistoryOperation::Loft(_)
| acadrust::objects::SolidHistoryOperation::Extrusion(_))
&& !display.0.complete
if matches!(
&operation,
acadrust::objects::SolidHistoryOperation::Loft(_)
| acadrust::objects::SolidHistoryOperation::Extrusion(_)
) && !display.0.complete
{
return false;
}
@@ -970,7 +956,8 @@ impl Scene {
match self.document.get_entity_mut(handle) {
Some(EntityType::Solid3D(entity)) => entity.set_sat_document(&document),
Some(EntityType::Surface(entity)) => {
entity.acis_data = acadrust::entities::AcisData::from_sat(&document.to_sat_string());
entity.acis_data =
acadrust::entities::AcisData::from_sat(&document.to_sat_string());
if let Some(data) = surface_data {
if matches!(&data, acadrust::entities::SurfaceData::Extruded { .. }) {
entity.kind = acadrust::entities::SurfaceKind::Extruded;
@@ -1001,16 +988,19 @@ impl Scene {
let Some(display) = self.prepare_solid_model_display(handle, &body) else {
return false;
};
if matches!(&operation, acadrust::objects::SolidHistoryOperation::Loft(_)
| acadrust::objects::SolidHistoryOperation::Extrusion(_))
&& !display.0.complete
if matches!(
&operation,
acadrust::objects::SolidHistoryOperation::Loft(_)
| acadrust::objects::SolidHistoryOperation::Extrusion(_)
) && !display.0.complete
{
return false;
}
match self.document.get_entity_mut(handle) {
Some(EntityType::Solid3D(entity)) => entity.set_sat_document(&document),
Some(EntityType::Surface(entity)) => {
entity.acis_data = acadrust::entities::AcisData::from_sat(&document.to_sat_string());
entity.acis_data =
acadrust::entities::AcisData::from_sat(&document.to_sat_string());
if let Some(data) = surface_data {
if matches!(&data, acadrust::entities::SurfaceData::Extruded { .. }) {
entity.kind = acadrust::entities::SurfaceKind::Extruded;
@@ -1062,24 +1052,22 @@ impl Scene {
true
}
fn transform_solid_history(
&mut self,
handle: Handle,
transform: &EntityTransform,
) -> bool {
fn transform_solid_history(&mut self, handle: Handle, transform: &EntityTransform) -> bool {
let Some(mut operation) = self.document.solid_history_operation(handle).cloned() else {
return false;
};
if !crate::scene::model::solid_history::transform_operation(
&mut operation,
transform,
) {
if !crate::scene::model::solid_history::transform_operation(&mut operation, transform) {
return false;
}
if let EntityTransform::Translate(delta) = transform {
let surface_data = match (&operation, self.document.get_entity(handle)) {
(acadrust::objects::SolidHistoryOperation::Extrusion(value), Some(EntityType::Surface(_))) => {
let Some(data) = crate::scene::model::solid_history::extrusion_surface_data(value) else {
(
acadrust::objects::SolidHistoryOperation::Extrusion(value),
Some(EntityType::Surface(_)),
) => {
let Some(data) =
crate::scene::model::solid_history::extrusion_surface_data(value)
else {
return false;
};
Some(data)
@@ -1104,12 +1092,7 @@ impl Scene {
self.rebuild_solid_history(handle, operation)
}
pub fn apply_solid_history_choice(
&mut self,
handle: Handle,
field: &str,
value: &str,
) -> bool {
pub fn apply_solid_history_choice(&mut self, handle: Handle, field: &str, value: &str) -> bool {
self.record_solid_history_before(handle);
let mut created = false;
if self.document.solid_history_graph(handle).is_none() {
@@ -1137,7 +1120,10 @@ impl Scene {
_ => return false,
};
if create {
if !matches!(self.document.get_entity(handle), Some(EntityType::Solid3D(_))) {
if !matches!(
self.document.get_entity(handle),
Some(EntityType::Solid3D(_))
) {
return false;
}
self.restore_solid_models(&[handle]);
@@ -1195,13 +1181,9 @@ impl Scene {
return false;
};
self.restore_solid_models(&[handle]);
let Some(definition) = self
.solid_models
.get(&handle)
.and_then(|body| {
crate::scene::model::solid_history::fillet_radius_grip(body, radius)
})
else {
let Some(definition) = self.solid_models.get(&handle).and_then(|body| {
crate::scene::model::solid_history::fillet_radius_grip(body, radius)
}) else {
return false;
};
let Some(axis) = definition.axis else {
@@ -1247,8 +1229,7 @@ impl Scene {
let acadrust::objects::SolidHistoryOperation::Chamfer(value) = &mut operation else {
return false;
};
let distance = if grip_id
== crate::scene::model::solid_history::GRIP_CHAMFER_DISTANCE1
let distance = if grip_id == crate::scene::model::solid_history::GRIP_CHAMFER_DISTANCE1
{
&mut value.base_distance
} else {
@@ -1260,11 +1241,8 @@ impl Scene {
}
return self.preview_solid_history(handle, operation);
}
if !crate::scene::model::solid_history::apply_primitive_grip(
&mut operation,
grip_id,
apply,
) {
if !crate::scene::model::solid_history::apply_primitive_grip(&mut operation, grip_id, apply)
{
return false;
}
self.preview_solid_history(handle, operation)
@@ -1276,12 +1254,10 @@ impl Scene {
field: &str,
value: &str,
) -> bool {
let Some(mut operation) =
crate::scene::model::solid_history::primitive_property_operation(
&self.document,
handle,
)
else {
let Some(mut operation) = crate::scene::model::solid_history::primitive_property_operation(
&self.document,
handle,
) else {
return false;
};
if !crate::scene::model::solid_history::apply_primitive_property(
@@ -1407,7 +1383,8 @@ impl Scene {
};
let n = leader.vertices.len();
if n < 3 || (grip_id != n - 1 && grip_id != n - 2) || leader.annotation_handle.is_null() {
if n < 3 || (grip_id != n - 1 && grip_id != n - 2) || leader.annotation_handle.is_null()
{
return None;
}
@@ -1451,10 +1428,7 @@ impl Scene {
if self.sync_displayed_annotation_context(annotation_handle) {
self.poison_undo_recording();
}
self.bump_entities(&[(
annotation_handle,
crate::scene::ChangeKind::Modified,
)]);
self.bump_entities(&[(annotation_handle, crate::scene::ChangeKind::Modified)]);
}
}
}
@@ -1510,9 +1484,7 @@ impl Scene {
let image_bearing = self.document.get_entity(handle).is_some_and(|entity| {
matches!(
entity,
EntityType::RasterImage(_)
| EntityType::Ole2Frame(_)
| EntityType::Underlay(_)
EntityType::RasterImage(_) | EntityType::Ole2Frame(_) | EntityType::Underlay(_)
)
});