Merge remote-tracking branch 'origin/main' into plugin/host-model-api

This commit is contained in:
Felix Riestra committed 2026-09-21 22:20:09 +02:00
commit b1e6d2a349
42 files changed
+4134 -356

No files matched your search

+870 -14
View File
@@ -3,6 +3,28 @@ use crate::command::{CmdResult, SelectionEntity, StepInput};
use acadrust::Handle;
use iced::Task;
/// `old` as a whole identifier in `source` becomes `new`.
fn replace_identifier(source: &str, old: &str, new: &str) -> String {
let mut out = String::with_capacity(source.len());
let mut token = String::new();
let flush = |token: &mut String, out: &mut String| {
if !token.is_empty() {
out.push_str(if token == old { new } else { token.as_str() });
token.clear();
}
};
for c in source.chars() {
if c.is_alphanumeric() || c == '_' {
token.push(c);
} else {
flush(&mut token, &mut out);
out.push(c);
}
}
flush(&mut token, &mut out);
out
}
impl OpenCADStudio {
pub(super) fn reject_locked_edit(&mut self, i: usize, handle: Handle) -> bool {
let Some(layer) = self.tabs[i].scene.locked_layer_name(handle) else {
@@ -1103,6 +1125,257 @@ impl OpenCADStudio {
TableCellEditStart::Started
}
/// Reports a refused command-line value and shows the prompt again.
fn reprompt_active_command(&mut self, i: usize, message: &str) {
self.command_line.push_error(message);
if let Some(prompt) = self.tabs[i].active_cmd.as_ref().map(|command| command.prompt()) {
self.command_line.push_info(&prompt);
}
}
/// Drops what removed dimensional constraints leave behind: their dynamic
/// dimensions, and their parameters when no other constraint reads them.
pub(crate) fn purge_dimensional_extras(
&mut self,
i: usize,
dimensions: Vec<Handle>,
parameters: Vec<String>,
) {
if !dimensions.is_empty() {
self.tabs[i].scene.erase_entities(&dimensions);
}
let unused: Vec<String> = parameters
.into_iter()
.filter(|name| {
!self.tabs[i]
.scene
.parametric_constraints
.iter()
.flat_map(|set| set.constraints.iter())
.any(|constraint| {
matches!(
&constraint.driving_param,
Some(crate::scene::named_parameters::DrivingValue::Named(used))
if used == name
)
})
})
.collect();
if !unused.is_empty() {
self.tabs[i].scene.record_undo_named_parameters_before();
for name in &unused {
self.tabs[i].scene.named_parameters_mut().remove(name);
}
}
}
/// `Dynamic` or `Annotational`, the DCFORM setting.
pub(crate) fn constraint_form_name(&self) -> &'static str {
if self.constraint_form_annotational {
"Annotational"
} else {
"Dynamic"
}
}
/// The value prompt a double-clicked constraint dimension opens.
pub(crate) fn dynamic_dimension_value_command(
&self,
i: usize,
handle: Handle,
) -> Option<crate::modules::parametric::DimensionValueCommand> {
use crate::scene::named_parameters::DrivingValue;
let scene = &self.tabs[i].scene;
for set in &scene.parametric_constraints {
let Some((id, _)) = set
.dimensions
.iter()
.find(|(_, dimension)| **dimension == handle)
else {
continue;
};
let constraint = set.get(*id)?;
let Some(DrivingValue::Named(name)) = &constraint.driving_param else {
return None;
};
let table = if set.local_parameters.is_empty() {
scene.named_parameters()
} else {
&set.local_parameters
};
let current = table
.get(name)
.map(|parameter| parameter.source.trim().to_string())
.unwrap_or_default();
return Some(crate::modules::parametric::DimensionValueCommand::new(
name.clone(),
current,
));
}
None
}
/// Applies `expression` or `newname=expression` to parameter `name`:
/// the dimension value prompt and -PARAMETERS Edit.
pub(crate) fn apply_parameter_input(&mut self, i: usize, name: &str, input: &str) {
let input = input.trim();
let (target, expression) = match input.split_once('=') {
Some((new_name, expression)) => {
(new_name.trim().to_string(), expression.trim().to_string())
}
None => (name.to_string(), input.to_string()),
};
if expression.is_empty() {
return;
}
if target != name {
if let Err(error) = self.rename_parameter(i, name, &target) {
self.command_line.push_error(&error);
return;
}
}
let mut table = self.tabs[i].scene.named_parameters().clone();
if let Err(error) = table.set(&target, &expression) {
self.command_line.push_error(&error.to_string());
return;
}
if !table
.resolve(&target)
.is_ok_and(|value| value.is_finite())
{
self.command_line.push_error("Invalid expression.");
return;
}
let pending = self.begin_undo(i, "Edit parameter", 0, true);
self.tabs[i].scene.record_undo_named_parameters_before();
self.tabs[i].scene.named_parameters = table;
self.resolve_named_parameter_edit(i, &target);
self.tabs[i].scene.refresh_dynamic_dimension_texts();
self.tabs[i].dirty = true;
if let Some(pd) = pending {
self.commit_undo_delta(i, pd);
}
}
/// -PARAMETERS New.
pub(crate) fn create_parameter(&mut self, i: usize, name: &str, expression: &str) {
if self.tabs[i].scene.named_parameters().contains(name) {
self.command_line
.push_error(&format!("Parameter {name} already exists."));
return;
}
let mut table = self.tabs[i].scene.named_parameters().clone();
if let Err(error) = table.set(name, expression) {
self.command_line.push_error(&error.to_string());
return;
}
let pending = self.begin_undo(i, "New parameter", 0, true);
self.tabs[i].scene.record_undo_named_parameters_before();
self.tabs[i].scene.named_parameters = table;
self.tabs[i].scene.sync_native_parametric_graph();
self.tabs[i].dirty = true;
if let Some(pd) = pending {
self.commit_undo_delta(i, pd);
}
}
/// Renames a parameter everywhere: the table, the expressions that use
/// it and the constraints it drives.
pub(crate) fn rename_parameter(&mut self, i: usize, old: &str, new: &str) -> Result<(), String> {
use crate::scene::named_parameters::{is_reserved_name, is_valid_name, DrivingValue};
let table = self.tabs[i].scene.named_parameters().clone();
let Some(source) = table.get(old).map(|parameter| parameter.source.clone()) else {
return Err(format!("Parameter {old} not found."));
};
if !is_valid_name(new) || is_reserved_name(new) || table.contains(new) {
return Err(format!("Invalid parameter name {new}."));
}
let mut renamed = table.clone();
renamed.set(new, &source).map_err(|error| error.to_string())?;
for parameter in table.iter() {
if parameter.name == old {
continue;
}
let rewritten = replace_identifier(&parameter.source, old, new);
if rewritten != parameter.source {
renamed
.set(&parameter.name, &rewritten)
.map_err(|error| error.to_string())?;
}
}
renamed.remove(old);
let pending = self.begin_undo(i, "Rename parameter", 0, true);
self.tabs[i].scene.record_undo_named_parameters_before();
self.tabs[i].scene.named_parameters = renamed;
let scopes: Vec<_> = self.tabs[i]
.scene
.parametric_constraints
.iter()
.map(|set| set.scope)
.collect();
for scope in scopes {
let before = self.tabs[i]
.scene
.parametric_constraint_set(scope)
.filter(|set| {
set.constraints.iter().any(|constraint| {
matches!(&constraint.driving_param, Some(DrivingValue::Named(name)) if name == old)
})
})
.cloned();
let Some(before) = before else {
continue;
};
self.tabs[i]
.scene
.record_undo_parametric_constraints_before(scope, before);
let set = self.tabs[i].scene.parametric_constraint_set_mut(scope);
for constraint in &mut set.constraints {
if matches!(&constraint.driving_param, Some(DrivingValue::Named(name)) if name == old) {
constraint.driving_param = Some(DrivingValue::Named(new.to_string()));
}
}
}
self.tabs[i].scene.refresh_dynamic_dimension_texts();
self.tabs[i].scene.sync_native_parametric_graph();
self.tabs[i].dirty = true;
if let Some(pd) = pending {
self.commit_undo_delta(i, pd);
}
Ok(())
}
/// -PARAMETERS Delete: a parameter no constraint drives with.
pub(crate) fn delete_parameter(&mut self, i: usize, name: &str) {
use crate::scene::named_parameters::DrivingValue;
if !self.tabs[i].scene.named_parameters().contains(name) {
self.command_line
.push_error(&format!("Parameter {name} not found."));
return;
}
let in_use = self.tabs[i]
.scene
.parametric_constraints
.iter()
.flat_map(|set| set.constraints.iter())
.any(|constraint| {
matches!(&constraint.driving_param, Some(DrivingValue::Named(used)) if used == name)
});
if in_use {
self.command_line
.push_error(&format!("Parameter {name} is used by a constraint."));
return;
}
let pending = self.begin_undo(i, "Delete parameter", 0, true);
self.tabs[i].scene.record_undo_named_parameters_before();
self.tabs[i].scene.named_parameters_mut().remove(name);
self.tabs[i].scene.sync_native_parametric_graph();
self.tabs[i].dirty = true;
if let Some(pd) = pending {
self.commit_undo_delta(i, pd);
}
}
fn remove_parametric_constraint(
&mut self,
id: crate::scene::parametric_constraints::ConstraintId,
@@ -1117,8 +1390,13 @@ impl OpenCADStudio {
return false;
};
let touched: Vec<Handle> = constraint.refs.iter().map(|r| r.entity).collect();
let dimension = set.dimensions.get(&id).copied();
let parameter = match &constraint.driving_param {
Some(crate::scene::named_parameters::DrivingValue::Named(name)) => Some(name.clone()),
_ => None,
};
let constraints_before = set.clone();
let pending = self.begin_undo(i, label, touched.len(), true);
let pending = self.begin_undo(i, label, touched.len(), dimension.is_none());
self.tabs[i]
.scene
.record_undo_parametric_constraints_before(scope, constraints_before);
@@ -1126,6 +1404,11 @@ impl OpenCADStudio {
.scene
.parametric_constraint_set_mut(scope)
.remove(id);
self.purge_dimensional_extras(
i,
dimension.into_iter().collect(),
parameter.into_iter().collect(),
);
if self.tabs[i].scene.selected_constraint == Some(id) {
self.tabs[i].scene.selected_constraint = None;
}
@@ -1219,6 +1502,23 @@ impl OpenCADStudio {
.flat_map(|c| c.refs.iter().map(|r| r.entity))
.collect();
// A changed value moves a dimensional constraint's second point; its
// first point stays, as in the reference.
let anchors: Vec<crate::scene::parametric_constraints::ParametricRef> = self.tabs[i]
.scene
.parametric_constraints
.iter()
.flat_map(|set| set.constraints.iter())
.filter(|c| {
c.enabled
&& matches!(
c.driving_param,
Some(crate::scene::named_parameters::DrivingValue::Named(_))
)
})
.filter_map(|c| c.refs.first().copied())
.filter(|reference| reference.marker.is_some())
.collect();
let pending = self.begin_undo(i, "Apply named parameters", touched.len(), true);
self.tabs[i].scene.record_undo_named_parameters_before();
self.tabs[i].scene.named_parameters = table;
@@ -1228,10 +1528,15 @@ impl OpenCADStudio {
.into_iter()
.map(|h| (h, crate::scene::ChangeKind::Modified))
.collect();
self.tabs[i].scene.bump_entities(&changes);
self.tabs[i].scene.bump_entities_with_parametric_policy(
&changes,
&anchors,
self.constraint_solve_mode,
);
} else {
self.tabs[i].scene.sync_native_parametric_graph();
}
self.tabs[i].scene.refresh_dynamic_dimension_texts();
if let Some(pd) = pending {
self.commit_undo_delta(i, pd);
}
@@ -1248,7 +1553,8 @@ impl OpenCADStudio {
/// table, so unlike that whole-table Apply this can cheaply scope the
/// re-solve to just the entities that actually reference it.
fn resolve_named_parameter_edit(&mut self, i: usize, name: &str) {
let touched: Vec<Handle> = self.tabs[i]
let readers: Vec<&crate::scene::parametric_constraints::ParametricConstraint> = self
.tabs[i]
.scene
.parametric_constraints
.iter()
@@ -1257,8 +1563,24 @@ impl OpenCADStudio {
c.enabled
&& matches!(&c.driving_param, Some(crate::scene::named_parameters::DrivingValue::Named(n)) if n == name)
})
.collect();
let touched: Vec<Handle> = readers
.iter()
.flat_map(|c| c.refs.iter().map(|r| r.entity))
.collect();
// A changed value moves a dimensional constraint's second point; its
// first point (and the line it measures perpendicular to) stays, as
// in the reference.
let anchors: Vec<crate::scene::parametric_constraints::ParametricRef> = readers
.iter()
.flat_map(|c| {
crate::scene::parametric_constraints::dimensional_anchor_refs(
&self.tabs[i].scene.document,
&c.refs,
)
})
.filter(|reference| reference.marker.is_some())
.collect();
self.tabs[i].dirty = true;
if touched.is_empty() {
self.tabs[i].scene.sync_native_parametric_graph();
@@ -1268,7 +1590,9 @@ impl OpenCADStudio {
.into_iter()
.map(|h| (h, crate::scene::ChangeKind::Modified))
.collect();
self.tabs[i].scene.bump_entities(&changes);
self.tabs[i]
.scene
.bump_entities_with_parametric_policy(&changes, &anchors, false);
}
/// Commits one field of one Parameters-section row (Properties panel) —
@@ -1337,6 +1661,11 @@ impl OpenCADStudio {
current.name.clone(),
),
ParamField::Name => {
let description = self.tabs[i]
.scene
.named_parameters()
.description(&current.name)
.to_string();
self.tabs[i]
.scene
.named_parameters_mut()
@@ -1345,12 +1674,19 @@ impl OpenCADStudio {
.scene
.named_parameters_mut()
.set(&typed, &current.source);
if outcome.is_err() {
let kept = if outcome.is_err() {
let _ = self.tabs[i]
.scene
.named_parameters_mut()
.set(&current.name, &current.source);
}
current.name.as_str()
} else {
typed.as_str()
};
self.tabs[i]
.scene
.named_parameters_mut()
.set_description(kept, &description);
(outcome, typed.clone())
}
};
@@ -1405,6 +1741,190 @@ impl OpenCADStudio {
Task::none()
}
/// The dynamic dimension the Properties panel targets: its handle, scope,
/// constraint id and parameter name.
fn dynamic_dimension_target(
&self,
i: usize,
) -> Option<(
Handle,
crate::scene::parametric_constraints::ParametricScope,
crate::scene::parametric_constraints::ConstraintId,
String,
)> {
use crate::scene::named_parameters::DrivingValue;
use crate::scene::parametric_constraints::dynamic_dimension_constraint;
let handle = *self.property_target_handles(i).first()?;
let (set, constraint) =
dynamic_dimension_constraint(&self.tabs[i].scene.parametric_constraints, handle)?;
let Some(DrivingValue::Named(name)) = &constraint.driving_param else {
return None;
};
Some((handle, set.scope, constraint.id, name.clone()))
}
/// Commits a dynamic dimension's Description row into its parameter.
pub(super) fn on_dynamic_dimension_description_commit(
&mut self,
field: &'static str,
) -> Task<Message> {
use crate::ui::properties::FieldKey;
let i = self.active_tab;
self.tabs[i].properties.active_field = None;
let Some(typed) = self.tabs[i]
.properties
.edit_buf
.remove(&FieldKey::Geom(field))
else {
return Task::none();
};
let Some((_, _, _, name)) = self.dynamic_dimension_target(i) else {
self.refresh_properties();
return Task::none();
};
let pending = self.begin_undo(i, "Constraint description", 0, true);
self.tabs[i].scene.record_undo_named_parameters_before();
self.tabs[i]
.scene
.named_parameters_mut()
.set_description(&name, &typed);
self.tabs[i].dirty = true;
if let Some(pd) = pending {
self.commit_undo_delta(i, pd);
}
self.refresh_properties();
Task::none()
}
/// Applies a dynamic dimension's Constraint Form or Reference choice.
pub(super) fn on_dynamic_dimension_choice(
&mut self,
field: &'static str,
value: &str,
) -> Task<Message> {
use crate::scene::parametric_constraints::DYNAMIC_DIMENSION_LAYER;
let i = self.active_tab;
let Some((handle, scope, id, _)) = self.dynamic_dimension_target(i) else {
return Task::none();
};
match field {
"dyn_constraint_form" => {
// Annotational: an ordinary dimension on the current layer
// that plots; Dynamic: the gray one on the constraints layer.
let annotational = value.eq_ignore_ascii_case("Annotational");
let active_layer = self.tabs[i].active_layer.clone();
if !annotational {
self.tabs[i].scene.ensure_dynamic_dimension_layer();
}
self.apply_property_op(i, "Constraint form", &[handle], |app, handle| {
use crate::entities::dim_override as dov;
let Some(mut entity) = app.tabs[i].scene.document.get_entity(handle).cloned()
else {
return;
};
if annotational {
entity.as_entity_mut().set_layer(active_layer.clone());
entity.common_mut().color = acadrust::types::Color::ByLayer;
// The dynamic form's screen-size and horizontal-text
// overrides go; the style draws it.
for code in [dov::DIMSCALE, dov::DIMTIH, dov::DIMTOH] {
dov::set_on_entity(&mut entity, code, None);
}
} else {
entity
.as_entity_mut()
.set_layer(DYNAMIC_DIMENSION_LAYER.to_string());
entity.common_mut().color = acadrust::types::Color::Rgb {
r: 103,
g: 109,
b: 118,
};
}
app.tabs[i].scene.update_entity(entity);
});
// The dynamic form is rescaled to the screen and shows the
// trimmed value; the annotational one is never hidden.
self.tabs[i].scene.refresh_dynamic_dimension_scales(true);
self.tabs[i].scene.refresh_dynamic_dimension_texts();
self.tabs[i].scene.refresh_hidden_dynamic_dimensions();
}
"dyn_constraint_reference" => {
// A reference constraint reads the geometry instead of
// driving it; its text sits in parentheses.
let reference =
value.eq_ignore_ascii_case("Yes") || value == crate::t!("Yes").as_ref();
let Some(before) = self.tabs[i].scene.parametric_constraint_set(scope).cloned()
else {
return Task::none();
};
let pending = self.begin_undo(i, "Constraint reference", 0, true);
self.tabs[i]
.scene
.record_undo_parametric_constraints_before(scope, before);
self.tabs[i].scene.record_undo_named_parameters_before();
let set = self.tabs[i].scene.parametric_constraint_set_mut(scope);
if let Some(constraint) = set.constraints.iter_mut().find(|c| c.id == id) {
constraint.enabled = !reference;
}
self.tabs[i].scene.refresh_dynamic_dimension_texts();
self.tabs[i].scene.sync_native_parametric_graph();
self.tabs[i].dirty = true;
if let Some(pd) = pending {
self.commit_undo_delta(i, pd);
}
self.refresh_properties();
}
_ => {}
}
Task::none()
}
/// Commits a dynamic dimension's Name or Expression row: the typed text
/// goes to the Parameters-section row of the constraint's parameter.
pub(super) fn on_dynamic_dimension_field_commit(
&mut self,
field: &'static str,
param_field: crate::ui::window::named_parameters::ParamField,
) -> Task<Message> {
use crate::scene::named_parameters::DrivingValue;
use crate::scene::parametric_constraints::dynamic_dimension_constraint;
use crate::ui::properties::FieldKey;
let i = self.active_tab;
self.tabs[i].properties.active_field = None;
let Some(typed) = self.tabs[i]
.properties
.edit_buf
.remove(&FieldKey::Geom(field))
else {
return Task::none();
};
let handles = self.property_target_handles(i);
let name = handles.first().and_then(|handle| {
let (_, constraint) =
dynamic_dimension_constraint(&self.tabs[i].scene.parametric_constraints, *handle)?;
match &constraint.driving_param {
Some(DrivingValue::Named(name)) => Some(name.clone()),
_ => None,
}
});
let index = name.and_then(|name| {
self.tabs[i]
.scene
.named_parameters()
.iter()
.position(|parameter| parameter.name == name)
});
let Some(index) = index else {
self.refresh_properties();
return Task::none();
};
self.tabs[i]
.properties
.edit_buf
.insert(FieldKey::Param(index, param_field), typed);
self.on_prop_param_commit(index, param_field)
}
/// Removes Parameters-section row `index` immediately. Any
/// constraint that referenced it gets the same "undefined reference"
/// resolve-failure treatment a formula's own bad reference already gets
@@ -3357,8 +3877,13 @@ impl OpenCADStudio {
|| equal_size_follower(&self.tabs[i].scene.document, first, other)
.is_none()
{
self.command_line
.push_error(EqualConstraintCommand::INVALID_OBJECT);
// The reference names the kind the first object
// asks for.
let message = match equal_size(&self.tabs[i].scene.document, first) {
Some(EqualSize::Radius(_)) => EqualConstraintCommand::INVALID_RADIUS_OBJECT,
_ => EqualConstraintCommand::INVALID_LENGTH_OBJECT,
};
self.command_line.push_error(message);
continue;
}
let exists = self.tabs[i]
@@ -3378,7 +3903,10 @@ impl OpenCADStudio {
}
followers.push(other);
}
if multiple && !finishing {
// A refused second object is asked for again, as in the
// reference; Multiple keeps asking anyway.
let keep = (multiple && !finishing) || (!multiple && followers.is_empty());
if keep {
if let Some(prompt) =
self.tabs[i].active_cmd.as_ref().map(|command| command.prompt())
{
@@ -3450,6 +3978,322 @@ impl OpenCADStudio {
self.commit_undo_delta(i, pd);
}
}
CmdResult::CheckConstraintPoint(pick) => {
use crate::scene::parametric_constraints::{
nearest_parametric_point, nearest_parametric_point_on_entity, resolve_point,
};
let scope = self.tabs[i].current_parametric_scope();
let resolved = {
let document = &self.tabs[i].scene.document;
let world =
acadrust::types::Vector3::new(pick.point.x, pick.point.y, pick.point.z);
let reference = match pick.handle {
Some(handle) => {
nearest_parametric_point_on_entity(document, scope, handle, world)
}
None => nearest_parametric_point(document, scope, world, None),
};
reference.map(|reference| {
let point = document
.get_entity(reference.entity)
.zip(reference.marker)
.and_then(|(entity, marker)| resolve_point(entity, marker))
.map_or(pick.point, |p| glam::DVec3::new(p.x, p.y, p.z));
(reference, point)
})
};
let Some((reference, point)) = resolved else {
return self.apply_cmd_result(CmdResult::ReportError(
crate::modules::parametric::DimConstraintCommand::NO_POINT.to_string(),
));
};
let result = self.tabs[i]
.active_cmd
.as_mut()
.map(|command| command.accept_constraint_point(reference, point));
return match result {
Some(result) => self.apply_cmd_result(result),
None => Task::none(),
};
}
CmdResult::AddDimensionalConstraint {
kind,
first,
second,
first_point,
second_point,
location,
axis,
direction,
name,
expression,
label,
} => {
use crate::modules::annotate::{aligned_dim, linear_dim};
use crate::scene::named_parameters::{is_valid_name, DrivingValue};
use crate::scene::parametric_constraints::{
distance_direction_type, dynamic_dimension_text, ConstraintKind,
};
let scope = self.tabs[i].current_parametric_scope();
let mut refs = vec![first, second];
refs.extend(direction);
// The same measurement between the same references is
// refused after the value, and the command ends.
let duplicate = self.tabs[i]
.scene
.parametric_constraint_set(scope)
.is_some_and(|set| {
set.constraints.iter().any(|c| {
c.enabled
&& c.kind == kind
&& c.refs.len() == refs.len()
&& c.refs[..2].contains(&first)
&& c.refs[..2].contains(&second)
&& c.refs.get(2) == refs.get(2)
})
});
if duplicate {
self.command_line
.push_output("The constraint already exists on the selected objects.");
self.tabs[i].active_cmd = None;
self.tabs[i].snap_result = None;
return Task::none();
}
// A refused value keeps the prompt open, as the reference's
// editor does. A directed distance validates as the plain
// two-point distance it also is.
let (validate_kind, validate_refs) = if kind == ConstraintKind::DistanceDirected {
(ConstraintKind::Distance, &refs[..2])
} else {
(kind, &refs[..])
};
if let Err(message) = self.tabs[i].scene.validate_parametric_constraint(
validate_kind,
validate_refs,
Some(&DrivingValue::Literal(1.0)),
) {
self.reprompt_active_command(i, message);
return Task::none();
}
let anchors = crate::scene::parametric_constraints::dimensional_anchor_refs(
&self.tabs[i].scene.document,
&refs,
);
let name = name.trim().to_string();
if !is_valid_name(&name) {
self.reprompt_active_command(i, "Invalid parameter name.");
return Task::none();
}
let mut table = self.tabs[i].scene.named_parameters().clone();
if let Err(error) = table.set(&name, &expression) {
self.reprompt_active_command(i, &error.to_string());
return Task::none();
}
let value = match table.resolve(&name) {
Ok(value) if value.is_finite() => value,
_ => {
self.command_line.push_error("Invalid expression.");
self.reprompt_active_command(
i,
"The parameter is used in an expression which results in an invalid value for a dimensional constraint.",
);
return Task::none();
}
};
// DCFORM Annotational: an ordinary plotted dimension on the
// current layer that shows the value at dimension precision.
let annotational = self.constraint_form_annotational;
let text = dynamic_dimension_text(
&name,
value,
self.tabs[i].scene.constraint_name_format,
false,
Some(&expression),
annotational,
);
let mut entity = if kind == ConstraintKind::Distance {
aligned_dim::aligned_dimension_entity(
first_point,
second_point,
location,
Some(text),
)
} else {
linear_dim::linear_dimension_entity(
first_point,
second_point,
location,
axis,
Some(text),
)
};
crate::scene::creation_style::apply_current_creation_styles(
&self.tabs[i].scene.document,
&mut entity,
);
if annotational {
entity
.as_entity_mut()
.set_layer(self.tabs[i].active_layer.clone());
} else {
// A dynamic dimension lives on the reference's constraints
// layer, hidden from the layer lists and never plotted, and
// draws in the constraint gray, not the current color.
self.tabs[i].scene.ensure_dynamic_dimension_layer();
entity.as_entity_mut().set_layer(
crate::scene::parametric_constraints::DYNAMIC_DIMENSION_LAYER.to_string(),
);
entity.common_mut().color = acadrust::types::Color::Rgb {
r: 103,
g: 109,
b: 118,
};
}
let constraints_before = self.tabs[i]
.scene
.parametric_constraint_set(scope)
.cloned()
.unwrap_or_else(|| {
crate::scene::parametric_constraints::ParametricConstraintSet::new(scope)
});
let mut touched = vec![first.entity];
for reference in [Some(second), direction].into_iter().flatten() {
if !touched.contains(&reference.entity) {
touched.push(reference.entity);
}
}
let pending = self.begin_undo(i, label, touched.len() + 1, false);
self.tabs[i]
.scene
.record_undo_parametric_constraints_before(scope, constraints_before);
self.tabs[i].scene.record_undo_named_parameters_before();
self.tabs[i].scene.named_parameters = table;
let dimension = self.tabs[i].scene.add_entity(entity);
let set = self.tabs[i].scene.parametric_constraint_set_mut(scope);
let id = set.add(kind, refs, Some(DrivingValue::Named(name)));
if direction.is_some() {
if let Some(constraint) = set.constraints.iter_mut().find(|c| c.id == id) {
constraint.distance_direction_type =
distance_direction_type::PERPENDICULAR_TO_LINE;
}
}
set.dimensions.insert(id, dimension);
self.tabs[i].scene.note_parametric_constraint_applied(
scope,
id,
self.constraint_bar_display,
);
self.tabs[i].scene.attach_dimension_association(
dimension,
vec![Some(first.entity), Some(second.entity)],
);
let changes: Vec<(Handle, crate::scene::ChangeKind)> = touched
.into_iter()
.map(|handle| (handle, crate::scene::ChangeKind::Modified))
.collect();
// The first point (and a line it belongs to that the distance
// runs perpendicular to) stays; a value other than the
// measured one moves the second, as in the reference. Not
// `retain_size`: the typed value is the new length.
self.tabs[i]
.scene
.bump_entities_with_parametric_policy(&changes, &anchors, false);
// DYNCONSTRAINTDISPLAY 0 also keeps a new dynamic dimension off screen.
self.tabs[i].scene.refresh_hidden_dynamic_dimensions();
self.tabs[i].scene.refresh_dynamic_dimension_scales(true);
self.tabs[i].dirty = true;
self.tabs[i].active_cmd = None;
self.tabs[i].snap_result = None;
self.refresh_properties();
if let Some(pd) = pending {
self.commit_undo_delta(i, pd);
}
}
CmdResult::MakeParallel {
first_line,
first_ends,
second_line,
second_ends,
} => {
use crate::scene::parametric_constraints::{resolve_point, ConstraintKind};
let scope = self.tabs[i].current_parametric_scope();
let refs = [first_line, second_line];
if let Err(message) =
self.tabs[i]
.scene
.validate_parametric_constraint(ConstraintKind::Parallel, &refs, None)
{
return self.apply_cmd_result(CmdResult::ReportError(message.to_string()));
}
let already = self.tabs[i]
.scene
.parametric_constraint_set(scope)
.is_some_and(|set| {
set.constraints.iter().any(|c| {
c.enabled
&& c.kind == ConstraintKind::Parallel
&& c.refs.contains(&first_line)
&& c.refs.contains(&second_line)
})
});
if !already {
let constraints_before = self.tabs[i]
.scene
.parametric_constraint_set(scope)
.cloned()
.unwrap_or_else(|| {
crate::scene::parametric_constraints::ParametricConstraintSet::new(
scope,
)
});
let pending = self.begin_undo(i, "Parallel constraint", 1, true);
self.tabs[i]
.scene
.record_undo_parametric_constraints_before(scope, constraints_before);
let set = self.tabs[i].scene.parametric_constraint_set_mut(scope);
let id = set.add(ConstraintKind::Parallel, refs.to_vec(), None);
self.tabs[i].scene.note_parametric_constraint_applied(
scope,
id,
self.constraint_bar_display,
);
// The first line stays; the second turns parallel the way the
// Parallel constraint itself moves it.
self.tabs[i].scene.bump_entities_with_parametric_policy(
&[(second_line.entity, crate::scene::ChangeKind::Modified)],
&first_ends,
self.constraint_solve_mode,
);
self.tabs[i].dirty = true;
if let Some(pd) = pending {
self.commit_undo_delta(i, pd);
}
}
let ends = {
let document = &self.tabs[i].scene.document;
document.get_entity(second_line.entity).and_then(|entity| {
let world = |reference: crate::scene::parametric_constraints::ParametricRef| {
let point = resolve_point(entity, reference.marker?)?;
Some((reference, glam::DVec3::new(point.x, point.y, point.z)))
};
Some([world(second_ends[0])?, world(second_ends[1])?])
})
};
let Some(ends) = ends else {
return self.apply_cmd_result(CmdResult::ReportError(
crate::modules::parametric::DimConstraintCommand::NO_OBJECT.to_string(),
));
};
let result = self.tabs[i]
.active_cmd
.as_mut()
.map(|command| command.accept_parallel_line(ends));
return match result {
Some(result) => self.apply_cmd_result(result),
None => Task::none(),
};
}
CmdResult::AddFixedConstraint(pick) => {
use crate::modules::parametric::FixConstraintCommand;
use crate::scene::parametric_constraints::{
@@ -3599,7 +4443,7 @@ impl OpenCADStudio {
("No valid constraint point found.", Some(first))
} else {
(
"The object or point is already selected. Select a different object or constraint point.",
"The object or point is already selected. Select a different object or constraint point.",
Some(first),
)
};
@@ -7857,10 +8701,22 @@ fn entity_at_typed_point(
extent = extent
.max((bounds.max.x - bounds.min.x).abs())
.max((bounds.max.y - bounds.min.y).abs());
let Some(distance) =
crate::scene::viewport_dimension_pick::planar_pick_distance(entity, point)
else {
continue;
let distance = match crate::scene::viewport_dimension_pick::planar_pick_distance(entity, point) {
Some(distance) => distance,
// A text or an ellipse answers by its extent, the way a click
// inside it picks it.
None if matches!(
entity,
acadrust::EntityType::Text(_)
| acadrust::EntityType::MText(_)
| acadrust::EntityType::Ellipse(_)
) =>
{
let dx = (bounds.min.x - point.x).max(point.x - bounds.max.x).max(0.0);
let dy = (bounds.min.y - point.y).max(point.y - bounds.max.y).max(0.0);
dx.hypot(dy)
}
None => continue,
};
if nearest.is_none_or(|(best, _)| distance < best) {
nearest = Some((distance, common.handle));
+179 -3
View File
@@ -1131,7 +1131,26 @@ impl OpenCADStudio {
self.command_line.push_output("No constraints found.");
return None;
}
let pending = self.begin_undo(i, "Delete constraints", handles.len(), true);
let dimensions: Vec<acadrust::Handle> = ids
.iter()
.filter_map(|id| before.dimensions.get(id).copied())
.collect();
let parameters: Vec<String> = ids
.iter()
.filter_map(|id| before.get(*id))
.filter_map(|constraint| match &constraint.driving_param {
Some(crate::scene::named_parameters::DrivingValue::Named(name)) => {
Some(name.clone())
}
_ => None,
})
.collect();
let pending = self.begin_undo(
i,
"Delete constraints",
handles.len(),
dimensions.is_empty(),
);
self.tabs[i]
.scene
.record_undo_parametric_constraints_before(scope, before);
@@ -1139,6 +1158,7 @@ impl OpenCADStudio {
for id in &ids {
set.remove(*id);
}
self.purge_dimensional_extras(i, dimensions, parameters);
let changes: Vec<_> = handles
.iter()
.copied()
@@ -1290,6 +1310,7 @@ impl OpenCADStudio {
}
"DCCONVERT" => {
self.dim_constraint_last = "Convert";
let handles = self.tabs[i].scene.selected_handles_in_order();
if handles.is_empty() {
use crate::modules::draw::select::SelectObjectsCommand;
@@ -1486,6 +1507,131 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"DIMCONSTRAINT" => {
use crate::modules::parametric::DimConstraintMenuCommand;
self.command_line.push_output(&format!(
"Current settings: Constraint form = {}",
self.constraint_form_name()
));
let new_cmd = DimConstraintMenuCommand::new(self.dim_constraint_last);
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"DCFORM" => {
use crate::modules::parametric::ConstraintFormCommand;
let new_cmd = ConstraintFormCommand::new(self.constraint_form_annotational);
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
// DCFORM's answer, then on into DIMCONSTRAINT's options as the
// reference does.
cmd if cmd.starts_with("DCFORM_SET ") => {
use crate::modules::parametric::DimConstraintMenuCommand;
self.constraint_form_annotational = cmd
.trim_start_matches("DCFORM_SET ")
.trim()
.eq_ignore_ascii_case("Annotational");
self.command_line.push_output(&format!(
"Current settings: Constraint form = {}",
self.constraint_form_name()
));
let new_cmd = DimConstraintMenuCommand::new(self.dim_constraint_last);
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
// A dynamic dimension's value prompt (double-click).
cmd if cmd.starts_with("DCVALUE ") => {
let rest = cmd.trim_start_matches("DCVALUE ").trim();
if let Some((name, input)) = rest.split_once(' ') {
self.apply_parameter_input(i, name.trim(), input);
}
}
"-PARAMETERS" => {
use crate::modules::parametric::ParametersCliCommand;
let new_cmd = ParametersCliCommand::new();
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
cmd if cmd.starts_with("-PARAMETERS ") => {
let rest = cmd.trim_start_matches("-PARAMETERS ").trim();
let (op, args) = rest.split_once(' ').unwrap_or((rest, ""));
match op {
"LIST" => {
let rule = "-".repeat(74);
let rows: Vec<String> = {
let table = self.tabs[i].scene.named_parameters();
table
.iter()
.map(|parameter| {
let value = table
.resolve(&parameter.name)
.map(|value| format!("{value:.4}"))
.unwrap_or_else(|_| "**".to_string());
format!(
"Parameter: {:<12} Expression: {:<21} Value: {value}",
parameter.name, parameter.source
)
})
.collect()
};
self.command_line.push_output(&rule);
for row in rows {
self.command_line.push_output(&row);
}
self.command_line.push_output(&rule);
}
"NEW" => {
if let Some((name, expression)) = args.split_once(' ') {
self.create_parameter(i, name.trim(), expression.trim());
}
}
"EDIT" => {
use crate::modules::parametric::ParametersCliCommand;
let name = args.trim().to_string();
let old = {
let table = self.tabs[i].scene.named_parameters();
table.get(&name).map(|parameter| {
let value = table
.resolve(&name)
.map(|value| format!("{value:.4}"))
.unwrap_or_else(|_| "**".to_string());
format!("Old Expression = {}, Value = {value}", parameter.source)
})
};
match old {
Some(line) => {
self.command_line.push_output(&line);
let new_cmd = ParametersCliCommand::edit_expression(name);
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
None => self
.command_line
.push_error(&format!("Parameter {name} not found.")),
}
}
"SET" => {
if let Some((name, expression)) = args.split_once(' ') {
self.apply_parameter_input(i, name.trim(), expression.trim());
}
}
"RENAME" => {
if let Some((old, new)) = args.split_once(' ') {
if let Err(error) = self.rename_parameter(i, old.trim(), new.trim()) {
self.command_line.push_error(&error);
}
}
}
"DELETE" => self.delete_parameter(i, args.trim()),
_ => {}
}
}
"EDCONSTRAINT" => {
use crate::modules::parametric::EqualDistanceConstraintCommand;
let new_cmd = EqualDistanceConstraintCommand::new();
@@ -1726,8 +1872,35 @@ impl OpenCADStudio {
}
}
"DCONSTRAINT" | "DCLINEAR" | "DCHORIZONTAL" | "DCVERTICAL" | "DCALIGNED"
| "DCRADIUS" | "DCDIAMETER" => {
"DCLINEAR" | "DCHORIZONTAL" | "DCVERTICAL" | "DCALIGNED" => {
use crate::modules::parametric::{DimConstraintAxis, DimConstraintCommand};
use crate::scene::parametric_constraints::next_dimensional_parameter_name;
let axis = match cmd {
"DCHORIZONTAL" => DimConstraintAxis::Horizontal,
"DCVERTICAL" => DimConstraintAxis::Vertical,
"DCALIGNED" => DimConstraintAxis::Aligned,
_ => DimConstraintAxis::Linear,
};
self.dim_constraint_last = match cmd {
"DCHORIZONTAL" => "Horizontal",
"DCVERTICAL" => "Vertical",
"DCALIGNED" => "Aligned",
_ => "Linear",
};
let name = next_dimensional_parameter_name(self.tabs[i].scene.named_parameters());
// Both constraint points are picked inside the command.
self.tabs[i].scene.deselect_all();
let command = DimConstraintCommand::new(axis, name);
self.command_line.push_info(&command.prompt());
self.tabs[i].active_cmd = Some(Box::new(command));
}
"DCONSTRAINT" | "DCRADIUS" | "DCDIAMETER" => {
if cmd == "DCRADIUS" {
self.dim_constraint_last = "Radius";
} else if cmd == "DCDIAMETER" {
self.dim_constraint_last = "Diameter";
}
let handles = self.tabs[i].scene.selected_handles_in_order();
if handles.is_empty() {
use crate::modules::draw::select::SelectObjectsCommand;
@@ -1767,6 +1940,9 @@ impl OpenCADStudio {
}
"ACONSTRAINT" | "DCANGULAR" => {
if cmd == "DCANGULAR" {
self.dim_constraint_last = "ANgular";
}
let handles = self.tabs[i].scene.selected_handles_in_order();
if handles.is_empty() {
use crate::modules::draw::select::SelectObjectsCommand;
+22 -1
View File
@@ -1052,6 +1052,8 @@ impl OpenCADStudio {
| "CONSTRAINTINFER"
| "CONSTRAINTBARDISPLAY"
| "CONSTRAINTBARMODE"
| "CONSTRAINTNAMEFORMAT"
| "DYNCONSTRAINTDISPLAY"
) =>
{
return self.dispatch_styleprops(&format!("SETVAR {cmd}"), i);
@@ -1075,7 +1077,7 @@ impl OpenCADStudio {
if name.is_empty() || name == "?" {
self.command_line.push_info(&super::plotvars::setvar_listing());
self.command_line.push_info(
crate::t!("SETVAR: CETRANSPARENCY LTSCALE CELTSCALE PDMODE PDSIZE TEXTSIZE ORTHOMODE FILLMODE MIRRTEXT FRAME IMAGEFRAME PDFFRAME WIPEOUTFRAME XCLIPFRAME POINTCLOUDCLIPFRAME ZOOMWHEEL ZOOMFACTOR SHORTCUTMENU SHORTCUTMENUDURATION CURSORSIZE PICKBOX CURSORTYPE SNAPANG TEXTFILL CLIPROMPTLINES COMMANDLINEFADETIME ATTREQ ATTDIA DIMASSOC DIMCONTINUEMODE CONSTRAINTSOLVEMODE CONSTRAINTINFER CONSTRAINTBARDISPLAY CONSTRAINTBARMODE ANGBASE ANGDIR SKETCHINC SKPOLY SKTOLERANCE DONUTID DONUTOD CENTEREXE CENTERLAYER CENTERLTYPE CENTERLTSCALE CENTERLTYPEFILE CENTERCROSSSIZE CENTERCROSSGAP CENTERMARKEXE COLORTHEME SELECTIONAREA SELECTIONAREAOPACITY SELECTIONEFFECT SELECTIONEFFECTCOLOR WINDOWSAREACOLOR CROSSINGAREACOLOR SELECTIONPREVIEW GRIPSIZE GRIPCOLOR GRIPHOT GRIPHOVER GRIPOBJLIMIT | CLAYER CELTYPE TEXTSTYLE (read-only)").as_ref(),
crate::t!("SETVAR: CETRANSPARENCY LTSCALE CELTSCALE PDMODE PDSIZE TEXTSIZE ORTHOMODE FILLMODE MIRRTEXT FRAME IMAGEFRAME PDFFRAME WIPEOUTFRAME XCLIPFRAME POINTCLOUDCLIPFRAME ZOOMWHEEL ZOOMFACTOR SHORTCUTMENU SHORTCUTMENUDURATION CURSORSIZE PICKBOX CURSORTYPE SNAPANG TEXTFILL CLIPROMPTLINES COMMANDLINEFADETIME ATTREQ ATTDIA DIMASSOC DIMCONTINUEMODE CONSTRAINTSOLVEMODE CONSTRAINTINFER CONSTRAINTBARDISPLAY CONSTRAINTBARMODE CONSTRAINTNAMEFORMAT DYNCONSTRAINTDISPLAY ANGBASE ANGDIR SKETCHINC SKPOLY SKTOLERANCE DONUTID DONUTOD CENTEREXE CENTERLAYER CENTERLTYPE CENTERLTSCALE CENTERLTYPEFILE CENTERCROSSSIZE CENTERCROSSGAP CENTERMARKEXE COLORTHEME SELECTIONAREA SELECTIONAREAOPACITY SELECTIONEFFECT SELECTIONEFFECTCOLOR WINDOWSAREACOLOR CROSSINGAREACOLOR SELECTIONPREVIEW GRIPSIZE GRIPCOLOR GRIPHOT GRIPHOVER GRIPOBJLIMIT | CLAYER CELTYPE TEXTSTYLE (read-only)").as_ref(),
);
} else {
if name == "CETRANSPARENCY" {
@@ -1275,17 +1277,26 @@ impl OpenCADStudio {
| "CONSTRAINTINFER"
| "CONSTRAINTBARDISPLAY"
| "CONSTRAINTBARMODE"
| "CONSTRAINTNAMEFORMAT"
| "DYNCONSTRAINTDISPLAY"
) {
let current = match name.as_str() {
"CONSTRAINTSOLVEMODE" => i16::from(self.constraint_solve_mode),
"CONSTRAINTINFER" => i16::from(self.constraint_infer),
"CONSTRAINTBARDISPLAY" => self.constraint_bar_display,
"CONSTRAINTBARMODE" => self.constraint_bar_mode,
"CONSTRAINTNAMEFORMAT" => {
i16::from(self.tabs[i].scene.constraint_name_format)
}
"DYNCONSTRAINTDISPLAY" => {
i16::from(self.tabs[i].scene.dynamic_constraint_display)
}
_ => unreachable!(),
};
let maximum = match name.as_str() {
"CONSTRAINTBARDISPLAY" => 3,
"CONSTRAINTBARMODE" => 4095,
"CONSTRAINTNAMEFORMAT" => 2,
_ => 1,
};
if let Some(value) = &value {
@@ -1304,6 +1315,16 @@ impl OpenCADStudio {
self.constraint_bar_display = mode
}
"CONSTRAINTBARMODE" => self.constraint_bar_mode = mode,
"CONSTRAINTNAMEFORMAT" => {
self.tabs[i].scene.constraint_name_format = mode as u8;
self.tabs[i].scene.refresh_dynamic_dimension_texts();
self.tabs[i].dirty = true;
}
"DYNCONSTRAINTDISPLAY" => {
self.tabs[i].scene.dynamic_constraint_display =
mode != 0;
self.tabs[i].scene.refresh_hidden_dynamic_dimensions();
}
_ => unreachable!(),
}
self.persist_settings_if_changed();
+2
View File
@@ -83,6 +83,8 @@ impl OpenCADStudio {
.layers
.layers
.iter()
// The reference's hidden system layers (`*ADSK_CONSTRAINTS`) stay out.
.filter(|l| !l.name.starts_with('*'))
.map(|l| crate::ui::ribbon::LayerInfo {
name: l.name.clone(),
color: crate::ui::window::layers::iced_color_from_acad(&l.color),
+6
View File
@@ -612,6 +612,10 @@ pub(super) struct OpenCADStudio {
pub constraint_solve_mode: bool,
pub constraint_infer: bool,
pub constraint_bar_display: i16,
/// DCFORM: new dimensional constraints use the annotational form.
pub constraint_form_annotational: bool,
/// The dimensional constraint DIMCONSTRAINT offers by default: the last one used.
pub dim_constraint_last: &'static str,
pub constraint_bar_mode: i16,
/// Minutes between autosaves to a `.sv$` recovery file (SAVETIME command);
/// 0 disables autosave.
@@ -3956,6 +3960,8 @@ impl OpenCADStudio {
constraint_solve_mode: true,
constraint_infer: false,
constraint_bar_display: 3,
constraint_form_annotational: false,
dim_constraint_last: "Aligned",
constraint_bar_mode: 4095,
savetime_min: 10,
script_commands: true,
+144
View File
@@ -79,6 +79,8 @@ impl OpenCADStudio {
.layers
.iter()
.map(|l| l.name.clone())
// The reference's hidden system layers (`*ADSK_CONSTRAINTS`) stay out.
.filter(|name| !name.starts_with('*'))
.collect();
let linetype_items: Vec<ui::properties::LinetypeItem> = self.tabs[i]
.scene
@@ -2292,6 +2294,29 @@ impl OpenCADStudio {
}
_ => entity_type_label(entity),
};
// A dynamic dimension shows only its constraint and text
// rotation, as the reference does.
let title = match crate::scene::parametric_constraints::dynamic_dimension_constraint(
&self.tabs[i].scene.parametric_constraints,
handle,
) {
Some((set, constraint)) => {
sections = dynamic_dimension_sections(
&self.tabs[i].scene,
handle,
set,
constraint,
sections,
);
match entity {
acadrust::EntityType::Dimension(
acadrust::entities::Dimension::Aligned(_),
) => t!("Aligned Dimensional Constraint").into_owned(),
_ => t!("Linear Dimensional Constraint").into_owned(),
}
}
None => title,
};
ui::PropertiesPanel {
choice_combos: sections
.iter()
@@ -2739,6 +2764,26 @@ handles={handles_ms:.1} panel={:.1} ribbon={ribbon_ms:.1} tail={:.1} selected={}
}
}
}
if self.tabs[i].scene.is_dynamic_dimension(handle) {
// A dynamic dimension shows the reference's grips: a
// triangle at each constraint point aimed at the other
// one, and the text square — no dimension line grip.
let points: Vec<glam::DVec3> = entity_grips
.iter()
.filter(|grip| grip.id <= 1)
.map(|grip| grip.world)
.collect();
entity_grips.retain(|grip| grip.id != 2);
for grip in &mut entity_grips {
if grip.id <= 1 {
let other = points.get(1 - grip.id).copied().unwrap_or(grip.world);
let dir = (other - grip.world).normalize_or(glam::DVec3::X);
*grip = crate::entities::common::oriented_triangle_grip(
grip.id, grip.world, dir,
);
}
}
}
entity_grips.extend(crate::scene::model::solid_history::primitive_grips(
&self.tabs[i].scene.document,
handle,
@@ -3572,6 +3617,105 @@ fn set_row(sections: &mut [crate::scene::model::object::PropSection], field: &st
/// Replace a row's value with an arbitrary control (editable field, dropdown,
/// colour picker …) rather than plain read-only text.
/// A dimensional constraint's Properties as the reference shows them: the
/// Constraint rows, then only the text rotation for a dynamic dimension
/// and the full dimension sections for an annotational one.
fn dynamic_dimension_sections(
scene: &crate::scene::Scene,
handle: Handle,
set: &crate::scene::parametric_constraints::ParametricConstraintSet,
constraint: &crate::scene::parametric_constraints::ParametricConstraint,
sections: Vec<crate::scene::model::object::PropSection>,
) -> Vec<crate::scene::model::object::PropSection> {
use crate::scene::model::object::{PropSection, PropValue, Property};
use crate::scene::named_parameters::DrivingValue;
let table = if set.local_parameters.is_empty() {
scene.named_parameters()
} else {
&set.local_parameters
};
let reference = !constraint.enabled;
let annotational = scene.dimension_is_annotational(handle);
let (name, expression, value, description) = match &constraint.driving_param {
Some(DrivingValue::Named(name)) => (
name.clone(),
table
.iter()
.find(|parameter| &parameter.name == name)
.map(|parameter| parameter.source.clone())
.unwrap_or_default(),
table.resolve(name).ok(),
table.description(name).to_string(),
),
Some(DrivingValue::Literal(value)) => {
(String::new(), format!("{value}"), Some(*value), String::new())
}
None => (String::new(), String::new(), None, String::new()),
};
let row = |label: &str, field: &'static str, value: PropValue| Property {
label: label.to_string(),
field,
value,
};
let yes_no = |flag: bool| PropValue::Choice {
selected: if flag { t!("Yes") } else { t!("No") }.into_owned(),
options: vec![t!("Yes").into_owned(), t!("No").into_owned()],
};
let text_rotation = sections
.iter()
.flat_map(|section| section.props.iter())
.find(|property| property.field == "text_rotation")
.cloned();
let mut result = vec![PropSection {
title: t!("Constraint").into_owned(),
props: vec![
row(
t!("Constraint Form").as_ref(),
"dyn_constraint_form",
PropValue::Choice {
selected: if annotational { "Annotational" } else { "Dynamic" }.to_string(),
options: vec!["Dynamic".to_string(), "Annotational".to_string()],
},
),
row(
t!("Reference").as_ref(),
"dyn_constraint_reference",
yes_no(reference),
),
row(t!("Name").as_ref(), "dyn_constraint_name", PropValue::EditText(name)),
row(
t!("Expression").as_ref(),
"dyn_constraint_expression",
// A reference constraint's expression is the measurement.
if reference {
PropValue::ReadOnly(expression)
} else {
PropValue::EditText(expression)
},
),
row(
t!("Value").as_ref(),
"dyn_constraint_value",
PropValue::ReadOnly(value.map(|v| format!("{v:.4}")).unwrap_or_default()),
),
row(
t!("Description").as_ref(),
"dyn_constraint_description",
PropValue::EditText(description),
),
],
}];
if annotational {
result.extend(sections);
} else if let Some(text_rotation) = text_rotation {
result.push(PropSection {
title: t!("Text").into_owned(),
props: vec![text_rotation],
});
}
result
}
fn set_row_value(
sections: &mut [crate::scene::model::object::PropSection],
field: &str,
+16
View File
@@ -2188,6 +2188,9 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
field: &'static str,
value: String,
) -> Task<Message> {
if matches!(field, "dyn_constraint_form" | "dyn_constraint_reference") {
return self.on_dynamic_dimension_choice(field, &value);
}
let i = self.active_tab;
let handles = self.property_target_handles(i);
@@ -3259,6 +3262,19 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
}
pub(super) fn on_prop_geom_commit(&mut self, field: &'static str) -> Task<Message> {
use crate::ui::window::named_parameters::ParamField;
// A dynamic dimension's Name/Expression rows edit its parameter.
let dynamic_field = match field {
"dyn_constraint_name" => Some(ParamField::Name),
"dyn_constraint_expression" => Some(ParamField::Formula),
_ => None,
};
if let Some(param_field) = dynamic_field {
return self.on_dynamic_dimension_field_commit(field, param_field);
}
if field == "dyn_constraint_description" {
return self.on_dynamic_dimension_description_commit(field);
}
let i = self.active_tab;
self.tabs[i].properties.active_field = None;
let handles = self.property_target_handles(i);
+3 -3
View File
@@ -1466,7 +1466,7 @@ impl OpenCADStudio {
self.prepare_native_save(i);
let version = self.tabs[i].scene.document.version;
let snapshot = self.tabs[i].scene.document.clone();
let snapshot = self.tabs[i].scene.document_for_save();
crate::io::save_owned_as_version_atomic(
snapshot,
&path,
@@ -1895,7 +1895,7 @@ impl OpenCADStudio {
path: std::path::PathBuf,
) -> Task<Message> {
let i = self.active_tab;
let document = self.tabs[i].scene.document.clone();
let document = self.tabs[i].scene.document_for_save();
let handles: Vec<_> = self.tabs[i].scene.selected.iter().copied().collect();
let worker_name = block_name.clone();
let worker_path = path.clone();
@@ -2300,7 +2300,7 @@ impl OpenCADStudio {
crate::ui::wrap_bar::dropdown_bounds(crate::app::view::VIEWPORT_CAPTURE_BOUNDS_ID)
});
let clone_started = iced::time::Instant::now();
let mut snapshot = self.tabs[i].scene.document.clone();
let mut snapshot = self.tabs[i].scene.document_for_save();
// Save-As across folders: rebase relative reference paths onto the
// new base dir inside the snapshot only (live strings are untouched).
if purpose == crate::app::SavePurpose::SaveAs {
+11
View File
@@ -785,6 +785,8 @@ impl OpenCADStudio {
pub(super) fn on_tick(&mut self, t: Instant) -> Task<Message> {
let i = self.active_tab;
self.tabs[i].scene.update(t - self.start);
// Dynamic dimensions keep their screen size across zoom bands.
self.tabs[i].scene.refresh_dynamic_dimension_scales(false);
// If the camera moved since we last synced, write it back to
// the document and mark the file dirty.
@@ -5058,6 +5060,15 @@ properties={:.1}ms picked={}",
{
return Task::none();
}
// A constraint dimension edits its parameter from the
// command line, standing in for the reference's in-place
// value editor.
if let Some(prompt) = self.dynamic_dimension_value_command(i, handle) {
use crate::command::CadCommand;
self.command_line.push_info(&prompt.prompt());
self.tabs[i].active_cmd = Some(Box::new(prompt));
return Task::none();
}
// Any text-bearing entity opens its in-place editor
// (plain box or rich MText editor, per type). A
// Leader resolves to the entity it annotates.