Merge remote-tracking branch 'origin/main' into codex/extrude-taper-history

This commit is contained in:
ramox81 committed 2026-10-08 15:01:55 +03:00
commit 5e6452f1b5
53 files changed
+817 -86

No files matched your search

+1 -1
View File
@@ -1801,7 +1801,7 @@ mod tests {
viewport.id = 2;
viewport.width = 100.0;
viewport.height = 50.0;
viewport.status.is_on = true;
viewport.turn_on();
scene.add_entity(codec::EntityType::Viewport(viewport));
for entity in scene.document.entities_mut() {
if let codec::EntityType::Viewport(viewport) = entity {
+14 -2
View File
@@ -489,6 +489,8 @@ impl OpenCADStudio {
.collect::<Vec<_>>();
// Group 294: a base point the user picked.
let picked_base = options.base_point.is_some();
let several = profiles.len() > 1;
let picked = options;
let options = sweep_model::sweep_selection_options(&selection, options);
let pending = if profiles.is_empty() {
None
@@ -532,8 +534,10 @@ impl OpenCADStudio {
continue;
}
};
// An associative surface keeps the profile and path it reads.
let associative = surface && sweep_model::surface_associativity();
let deletes_path =
crate::app::delobj_deletes_auxiliary(delete_objects, surface);
!associative && crate::app::delobj_deletes_auxiliary(delete_objects, surface);
if deletes_path && self.tabs[i].scene.is_layer_locked(path_handle) {
failed += 1;
continue;
@@ -546,6 +550,14 @@ impl OpenCADStudio {
created,
&expressions,
);
if associative {
// A picked base point, or the one several profiles share.
let linked = crate::command::SweepOptions {
base_point: if picked_base || several { options.and_then(|o| o.base_point) } else { None },
..picked
};
sweep_model::link_sweep_sources(&mut self.tabs[i].scene.document, created, handle, path_handle, &linked);
}
created
} else {
self.add_solid_model(
@@ -558,7 +570,7 @@ impl OpenCADStudio {
failed += 1;
} else {
created_handles.push(created);
if delete_profiles {
if delete_profiles && !associative {
consumed.push(handle);
}
if deletes_path {
+11 -8
View File
@@ -935,14 +935,17 @@ mod delobj_tests {
expected,
);
}
assert_eq!(
sweep_source_presence(2, crate::command::ExtrudeMode::Surface),
(false, false),
);
assert_eq!(
sweep_source_presence(3, crate::command::ExtrudeMode::Surface),
(false, true),
);
// A swept surface is associative by default (SURFACEASSOCIATIVITY 1)
// and keeps the profile and path it follows, whatever DELOBJ says;
// DELOBJ reaches surfaces only with associativity off, a profile-wide
// switch this parallel test leaves alone.
assert!(crate::scene::model::sweep_model::surface_associativity());
for value in [2, 3] {
assert_eq!(
sweep_source_presence(value, crate::command::ExtrudeMode::Surface),
(true, true),
);
}
}
}
+1
View File
@@ -697,6 +697,7 @@ inventory::submit!(crate::command::CommandRegistration {
"PDFOSNAP",
"UOSNAP",
"FIELDDISPLAY",
"SURFACEASSOCIATIVITY",
"FIELDEVAL",
"PDFIMPORTMODE",
"PDFIMPORTFILTER",
+68 -19
View File
@@ -279,7 +279,7 @@ impl OpenCADStudio {
if name.is_empty() {
None
} else {
Some(name.clone())
Some(name.to_uppercase())
}
})
.collect();
@@ -310,6 +310,17 @@ impl OpenCADStudio {
.map(|ds| ds.dimtxsty.clone()),
)
.filter(|s| !s.is_empty())
.map(|s| s.to_uppercase())
.collect();
// Complex linetypes reach their text and shape styles by handle.
let linetype_styles: rustc_hash::FxHashSet<codec::Handle> = self.tabs[i]
.scene
.document
.line_types
.iter()
.flat_map(|lt| lt.elements.iter())
.filter_map(|element| element.complex.as_ref())
.map(|complex| complex.style_handle)
.collect();
// Linetypes: entity references plus every layer's own
// linetype — a ByLayer entity reaches it through the layer.
@@ -334,6 +345,7 @@ impl OpenCADStudio {
.map(|l| l.line_type.clone()),
)
.filter(|s| !s.is_empty())
.map(|s| s.to_uppercase())
.collect();
// Live blocks are reachable from layouts and style roots
@@ -403,7 +415,9 @@ impl OpenCADStudio {
.document
.layers
.iter()
.filter(|l| l.name != "0" && !used_layers.contains(&l.name))
.filter(|l| {
l.name != "0" && !used_layers.contains(&l.name.to_uppercase())
})
.map(|l| l.name.clone())
.collect()
} else {
@@ -415,8 +429,14 @@ impl OpenCADStudio {
.document
.text_styles
.iter()
// Unnamed shape-file records serve complex linetypes
// and are never listed for purging.
.filter(|s| {
s.name != "Standard" && !used_text_styles.contains(&s.name)
!s.name.is_empty()
&& !s.is_shape_file
&& !s.name.eq_ignore_ascii_case("Standard")
&& !used_text_styles.contains(&s.name.to_uppercase())
&& !linetype_styles.contains(&s.handle)
})
.map(|s| s.name.clone())
.collect()
@@ -432,7 +452,7 @@ impl OpenCADStudio {
.iter()
.filter(|lt| {
!standard.iter().any(|s| s.eq_ignore_ascii_case(&lt.name))
&& !used_linetypes.contains(&lt.name)
&& !used_linetypes.contains(&lt.name.to_uppercase())
})
.map(|lt| lt.name.clone())
.collect()
@@ -479,16 +499,17 @@ impl OpenCADStudio {
snapshot_pushed = true;
}
// Apply removals (mutable)
for name in &layer_remove {
self.tabs[i].scene.document.layers.remove(name);
}
for name in &style_remove {
self.tabs[i].scene.document.text_styles.remove(name);
}
for name in &lt_remove {
self.tabs[i].scene.document.line_types.remove(name);
}
// Apply removals (mutable). Count what actually went: an
// entry the table cannot remove by name would otherwise be
// listed again on every pass and never let the loop end.
let doc = &mut self.tabs[i].scene.document;
let layers_gone =
layer_remove.iter().filter(|n| doc.layers.remove(n).is_some()).count();
let styles_gone =
style_remove.iter().filter(|n| doc.text_styles.remove(n).is_some()).count();
let lts_gone =
lt_remove.iter().filter(|n| doc.line_types.remove(n).is_some()).count();
let mut blocks_gone = 0usize;
for name in &block_remove {
// Drop the block definition's member entities (and the
// BLOCK/ENDBLK delimiters) before the record so no orphaned
@@ -506,12 +527,17 @@ impl OpenCADStudio {
for h in handles {
self.tabs[i].scene.document.remove_entity(h);
}
self.tabs[i].scene.document.block_records.remove(name);
if self.tabs[i].scene.document.block_records.remove(name).is_some() {
blocks_gone += 1;
}
}
n_layers += layers_gone;
n_styles += styles_gone;
n_lts += lts_gone;
n_blocks += blocks_gone;
if layers_gone + styles_gone + lts_gone + blocks_gone == 0 {
break;
}
n_layers += layer_remove.len();
n_styles += style_remove.len();
n_lts += lt_remove.len();
n_blocks += block_remove.len();
}
// Remove draw-order tables whose owning blocks are gone.
@@ -1093,6 +1119,7 @@ impl OpenCADStudio {
| "DGNOSNAP"
| "UOSNAP"
| "FIELDDISPLAY"
| "SURFACEASSOCIATIVITY"
| "PDFIMPORTMODE"
| "PDFIMPORTFILTER"
| "PDFIMPORTLAYERS"
@@ -1301,6 +1328,28 @@ impl OpenCADStudio {
}
return Some(self.finish_dispatch(cmd));
}
if name == "SURFACEASSOCIATIVITY" {
use crate::scene::model::sweep_model;
let current = i16::from(sweep_model::surface_associativity());
match value.as_deref().map(|v| v.trim().parse::<i16>().ok().filter(|v| (0..=1).contains(v))) {
Some(Some(mode)) => {
if current != mode {
sweep_model::set_surface_associativity(mode == 1);
self.save_config();
}
}
Some(None) => {
self.command_line.push_error(crate::t!("Requires 0 or 1 only.").as_ref());
self.command_line.push_output(&format!("Enter new value for SURFACEASSOCIATIVITY <{current}>:"));
self.pending_setvar = Some(name.clone());
}
None => {
self.command_line.push_output(&format!("Enter new value for SURFACEASSOCIATIVITY <{current}>:"));
self.pending_setvar = Some(name.clone());
}
}
return Some(self.finish_dispatch(cmd));
}
if name == "FIELDDISPLAY" {
let current = i16::from(crate::entities::field::display());
match value.as_deref().map(|v| v.trim().parse::<i16>().ok().filter(|v| (0..=1).contains(v))) {
+1 -1
View File
@@ -719,7 +719,7 @@ impl OpenCADStudio {
vp.view_height,
vp.height,
),
vp.status.is_on,
vp.is_on(),
vp.status.locked,
))
} else {
+15
View File
@@ -62,10 +62,25 @@ impl OpenCADStudio {
let i = self.active_tab;
let doc_layers = self.tabs[i].scene.document.layers.clone();
let vp_info = self.tabs[i].scene.viewport_list();
let names_before: Vec<String> =
self.tabs[i].layers.layers.iter().map(|l| l.name.clone()).collect();
self.tabs[i]
.layers
.sync_with_viewports(&doc_layers, vp_info);
self.sync_ribbon_layers();
// The Properties palette lists layer names it read when it was built;
// a layer added, removed or renamed must reach that list too (#1664).
// Only then: the rebuild is costly for a large selection.
let names_changed = self.tabs[i].layers.layers.len() != names_before.len()
|| self.tabs[i]
.layers
.layers
.iter()
.zip(&names_before)
.any(|(layer, before)| layer.name != *before);
if names_changed {
self.refresh_properties();
}
}
/// Pick up layers an entity edit registered on the fly (`ensure_layer`).
+6
View File
@@ -561,6 +561,8 @@ pub(super) struct OpenCADStudio {
zoom_wheel_reversed: bool,
/// Scroll pans and Ctrl+scroll zooms (touchpads); see `scroll_intent`.
touchpad_pan: bool,
/// Interface scale in percent, applied through the window scale factor.
ui_scale_percent: u16,
/// Mouse-wheel zoom sensitivity (ZOOMFACTOR), held inside
/// `settings::ZOOM_FACTOR_MIN..=settings::ZOOM_FACTOR_MAX`. `SETVAR`
/// only sets the range the system variable itself has; the Options
@@ -2378,6 +2380,8 @@ pub enum Message {
/// Toggle reversing the mouse-wheel zoom direction (ZOOMWHEEL).
ZoomWheelReversedChanged(bool),
TouchpadPanChanged(bool),
/// Interface scale in percent (Options > Display).
UiScaleChanged(u16),
/// Change how far one wheel notch zooms, from the Options slider
/// (ZOOMFACTOR).
ZoomFactorChanged(i32),
@@ -4161,6 +4165,7 @@ impl OpenCADStudio {
polar_increment_deg: 45.0,
zoom_wheel_reversed: false,
touchpad_pan: false,
ui_scale_percent: 100,
zoom_factor: 60,
zoom_factor_input: 60.to_string(),
cursor_size: 5,
@@ -4904,6 +4909,7 @@ pub fn run() -> iced::Result {
..iced::Settings::default()
})
.subscription(OpenCADStudio::subscription)
.scale_factor(|state: &OpenCADStudio, _| f32::from(state.ui_scale_percent) / 100.0)
.title(|state: &OpenCADStudio, window_id: window::Id| {
let _ = window_id; // all dialogs are in-canvas modals now
if let Some(tab) = state.tabs.get(state.active_tab) {
+11
View File
@@ -183,6 +183,11 @@ pub const ZOOM_FACTOR_MAX: i32 = 500;
/// Hold a ZOOMFACTOR inside the range the application can store, wherever it
/// arrives from — the slider, the Options field, or a configuration file
/// written by hand or by an older build.
/// Interface scale in percent, kept to the range the Options slider offers.
pub fn clamp_ui_scale(percent: u16) -> u16 {
percent.clamp(75, 200)
}
pub fn clamp_zoom_factor(v: i32) -> i32 {
v.clamp(ZOOM_FACTOR_MIN, ZOOM_FACTOR_MAX)
}
@@ -391,6 +396,8 @@ pub struct UserSettings {
/// Scrolling pans and Ctrl+scroll (a touchpad pinch) zooms, for a
/// touchpad that reports two-finger drags as wheel scrolls.
pub touchpad_pan: bool,
/// Interface scale in percent, on top of the display's own scale.
pub ui_scale_percent: u16,
pub zoom_factor: i32,
/// CURSORSIZE: normalized crosshair reach; 5 retains the original 60 px arms.
pub cursor_size: i32,
@@ -415,6 +422,8 @@ pub struct UserSettings {
pub attdef_on_screen: bool,
/// FIELDDISPLAY: fields show on a gray background.
pub field_display: bool,
/// SURFACEASSOCIATIVITY: new surfaces stay associative to their sources.
pub surface_associativity: bool,
/// Nested-copy symbol handling: false inserts, true binds.
pub ncopy_bind: bool,
/// Last Options page; unknown saved names fall back without rejecting the config.
@@ -811,6 +820,7 @@ impl Default for UserSettings {
polar_increment_deg: 45.0,
zoom_wheel_reversed: false,
touchpad_pan: false,
ui_scale_percent: 100,
zoom_factor: 60,
cursor_size: 5,
pick_box: 3,
@@ -827,6 +837,7 @@ impl Default for UserSettings {
image_frame: 1,
attdef_on_screen: true,
field_display: true,
surface_associativity: true,
ncopy_bind: false,
cursor_type: CursorType::Crosshair,
crosshair_color: None,
+4
View File
@@ -663,6 +663,7 @@ impl OpenCADStudio {
polar_increment_deg: self.polar_increment_deg,
zoom_wheel_reversed: self.zoom_wheel_reversed,
touchpad_pan: self.touchpad_pan,
ui_scale_percent: self.ui_scale_percent,
zoom_factor: self.zoom_factor,
cursor_size: self.cursor_size,
pick_box: self.pick_box,
@@ -679,6 +680,7 @@ impl OpenCADStudio {
image_frame: crate::scene::frame::profile_image_mode(),
attdef_on_screen: crate::modules::draw::draw::attdef::session().on_screen,
field_display: crate::entities::field::display(),
surface_associativity: crate::scene::model::sweep_model::surface_associativity(),
ncopy_bind: self.ncopy_bind,
cursor_type: self.cursor_type,
crosshair_color: self.crosshair_color,
@@ -764,6 +766,7 @@ impl OpenCADStudio {
self.polar_increment_deg = s.polar_increment_deg;
self.zoom_wheel_reversed = s.zoom_wheel_reversed;
self.touchpad_pan = s.touchpad_pan;
self.ui_scale_percent = crate::app::settings::clamp_ui_scale(s.ui_scale_percent);
self.zoom_factor = crate::app::settings::clamp_zoom_factor(s.zoom_factor);
// Like the drafting-rotation field below, the Options field edits a
// buffer rather than the value, so it is reseeded whenever the value
@@ -789,6 +792,7 @@ impl OpenCADStudio {
crate::scene::frame::set_profile_image_mode(s.image_frame);
crate::modules::draw::draw::attdef::session().on_screen = s.attdef_on_screen;
crate::entities::field::set_display(s.field_display);
crate::scene::model::sweep_model::set_surface_associativity(s.surface_associativity);
self.ncopy_bind = s.ncopy_bind;
self.cursor_type = s.cursor_type;
self.crosshair_color = s.crosshair_color;
+6
View File
@@ -8391,6 +8391,12 @@ impl OpenCADStudio {
Task::none()
}
Message::UiScaleChanged(percent) => {
self.ui_scale_percent = crate::app::settings::clamp_ui_scale(percent);
self.persist_settings_if_changed();
Task::none()
}
Message::ZoomFactorChanged(factor) => {
self.zoom_factor = crate::app::settings::clamp_zoom_factor(factor);
// The field beside the slider reads the same value, so the
+8 -5
View File
@@ -927,11 +927,14 @@ bg={bg_ms:.1}ms n={view_count}"
snap_angle_deg: self.snap_angle_deg,
pick_pending: self.pending_pick_label().is_some(),
// An infinite-line preview runs along the arms; drop them
// so the preview stays visible (#1437).
hide_arms: tab
.active_cmd
.as_ref()
.is_some_and(|c| matches!(c.name(), "XLINE" | "RAY")),
// so the preview stays visible (#1437). A command asking
// for objects shows the pickbox alone, so picking reads
// apart from both idle and point input (#1661).
hide_arms: tab.active_cmd.as_ref().is_some_and(|c| {
matches!(c.name(), "XLINE" | "RAY")
|| c.needs_entity_pick()
|| c.is_selection_gathering()
}),
snap_color: self.snap_marker_color,
},
crate::ui::overlay::SelectionVisualOptions {
+1
View File
@@ -317,6 +317,7 @@ impl OpenCADStudio {
commandline_fade_ms: self.commandline_fade_ms,
zoom_wheel_reversed: self.zoom_wheel_reversed,
touchpad_pan: self.touchpad_pan,
ui_scale_percent: self.ui_scale_percent,
zoom_factor: self.zoom_factor,
texteditmode: self.texteditmode,
dimension_continue_mode: self.dimension_continue_mode,
+2 -2
View File
@@ -27,7 +27,7 @@ fn fixture() -> (OpenCADStudio, Handle, ViewportFrame) {
viewport.view_height = 1000.0;
viewport.custom_scale = 0.1;
viewport.view_direction = Vector3::UNIT_Z;
viewport.status.is_on = true;
viewport.turn_on();
let viewport = scene.add_entity(EntityType::Viewport(viewport));
let frame = scene.viewport_frame(viewport).unwrap();
scene.document.header.dimension_associativity = 2;
@@ -484,7 +484,7 @@ fn viewport_dimension_eligibility_is_shared_and_uses_clipping() {
first.viewport
);
if let Some(EntityType::Viewport(vp)) = scene.document.get_entity_mut(first.viewport) {
vp.status.is_on = false;
vp.turn_off();
}
assert!(scene.viewport_frames_at_paper_point(paper).is_empty());
assert!(scene.dimension_pick_through_viewport(paper, 0.2).is_none());
+8 -5
View File
@@ -113,7 +113,7 @@ fn properties(vp: &Viewport) -> Vec<PropSection> {
field: "vp_on",
value: PropValue::BoolToggle {
field: "vp_on",
value: vp.status.is_on,
value: vp.is_on(),
},
},
ro(
@@ -193,11 +193,14 @@ fn apply_geom_prop(vp: &mut Viewport, field: &str, value: &str) {
return;
}
"vp_on" => {
vp.status.is_on = if value == "toggle" {
!vp.status.is_on
// turn_on/turn_off keep the explicit-off bit in step, so a
// viewport the file marked off can be turned back on.
let on = if value == "toggle" { !vp.is_on() } else { value == "true" };
if on {
vp.turn_on();
} else {
value == "true"
};
vp.turn_off();
}
return;
}
"vp_perspective" => {
+1 -1
View File
@@ -2539,7 +2539,7 @@ fn fix_viewport_status_flags(doc: &mut CadDocument) {
// If bit 0 is not set but bit 15 is, this is an external-format viewport:
// treat bit 15 as "on" and bit 14 as "locked".
if (bits & 0x0001) == 0 && (bits & 0x8000) != 0 {
vp.status.is_on = true;
vp.turn_on();
vp.status.locked = (bits & 0x4000) != 0;
}
}
+1
View File
@@ -4798,6 +4798,7 @@ pub(super) fn message_attribute(source: &str) -> Option<(&'static str, &'static
"Zoom" => Some(("common", "zoom")),
"Reverse mouse wheel zoom (ZOOMWHEEL)" => Some(("common", "reverse-mouse-wheel-zoom-zoomwheel")),
"Touchpad: scroll pans, Ctrl+scroll or pinch zooms" => Some(("common", "touchpad-scroll-pans-ctrl-scroll-or-pinch-zooms")),
"Interface scale" => Some(("common", "interface-scale")),
"Zoom factor" => Some(("common", "zoom-factor")),
"How far one wheel notch zooms (ZOOMFACTOR)." => Some(("common", "how-far-one-wheel-notch-zooms-zoomfactor")),
"Text and Dimensions" => Some(("common", "text-and-dimensions")),
+299 -2
View File
@@ -2482,6 +2482,9 @@ fn detach_preserved_scope(
Some(ObjectType::Associative(object)) => match &object.data {
AssociativeData::ConstraintGroup(_) | AssociativeData::Network(_) => false,
AssociativeData::Variable(variable) => variable.name.trim().is_empty(),
// A surface action whose surface was erased goes with it.
AssociativeData::Action(_) => action_surface(document, *handle)
.is_none_or(|surface| document.get_entity(surface).is_some()),
_ => true,
},
_ => false,
@@ -2489,6 +2492,35 @@ fn detach_preserved_scope(
.collect(),
_ => Vec::new(),
};
// Unnamed variables stay only while a kept action reads them.
let read_variables: Vec<Handle> = foreign_actions
.iter()
.filter_map(|handle| match document.objects.get(handle) {
Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::Action(action),
..
})) => Some(action),
_ => None,
})
.flat_map(|action| action.values.iter().flat_map(|value| value.variables.iter().map(|variable| variable.handle)))
.filter_map(|handle| match document.objects.get(&handle) {
Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::ValueDependency(value),
..
})) => Some(value.dependency.dependent_on),
_ => None,
})
.collect();
let foreign_actions: Vec<Handle> = foreign_actions
.into_iter()
.filter(|handle| match document.objects.get(handle) {
Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::Variable(_),
..
})) => read_variables.contains(handle),
_ => true,
})
.collect();
let preserved_groups: Vec<_> = native_group_handles(document, owner)
.into_iter()
.filter(|handle| {
@@ -2574,6 +2606,265 @@ fn detach_preserved_scope(
(variables, preserved_groups, foreign_actions)
}
/// The surface an associative surface action writes.
fn action_surface(document: &CadDocument, action: Handle) -> Option<Handle> {
let Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::Action(action),
..
})) = document.objects.get(&action)
else {
return None;
};
let Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::SurfaceActionBody(body),
..
})) = document.objects.get(&action.action_body)
else {
return None;
};
match document.objects.get(&body.surface_body.dependency) {
Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::Dependency(dependency),
..
})) => Some(dependency.dependent_on),
_ => None,
}
}
/// Associative swept surfaces made here that the drawing's network does
/// not carry yet: (surface, profile, path).
fn pending_swept_surfaces(document: &CadDocument) -> Vec<(Handle, Handle, Handle)> {
use crate::scene::model::sweep_model;
let carried: Vec<Handle> = document
.objects
.keys()
.filter_map(|handle| action_surface(document, *handle))
.collect();
let mut pending = document
.entities()
.filter(|entity| matches!(entity, codec::EntityType::Surface(surface)
if matches!(surface.surface_data, codec::entities::SurfaceData::Swept { .. })))
.filter_map(|entity| {
let (profile, path) = sweep_model::sweep_sources(entity)?;
let surface = entity.common().handle;
(!carried.contains(&surface)
&& document.get_entity(profile).is_some_and(|e| sweep_model::assoc_edge_curve(e).is_some())
&& document.get_entity(path).is_some_and(|e| sweep_model::assoc_edge_curve(e).is_some()))
.then_some((surface, profile, path))
})
.collect::<Vec<_>>();
pending.sort_by_key(|(surface, _, _)| surface.value());
pending
}
/// The names an expression reads.
fn expression_names(expression: &str) -> Vec<String> {
let mut names = Vec::new();
let mut current = String::new();
for character in expression.chars().chain(std::iter::once(' ')) {
if character.is_alphanumeric() || character == '_' {
current.push(character);
} else if !current.is_empty() {
if current.chars().next().is_some_and(|c| c.is_alphabetic()) && !names.contains(&current) {
names.push(current.clone());
}
current.clear();
}
}
names
}
/// The reference's associative network for each pending swept surface: an
/// action with a swept-surface body that writes the surface and reads its
/// profile and path, with the rotation, scale and twist as value
/// parameters; a scale or twist expression is an unnamed variable reading
/// the named ones. Returns the network's new actions in order.
fn materialize_swept_surface_actions(
allocator: &mut Allocator,
network: Handle,
parameters: &ParameterTable,
pending: &[(Handle, Handle, Handle)],
first_index: i32,
) -> Vec<Handle> {
use crate::scene::model::sweep_model;
use codec::objects::*;
let mut added = Vec::new();
for (surface, profile, path) in pending.iter().copied() {
let document = &*allocator.document;
let Some(surface_entity) = document.get_entity(surface) else { continue };
let codec::EntityType::Surface(surface_value) = surface_entity else { continue };
let codec::entities::SurfaceData::Swept { options, .. } = &surface_value.surface_data else { continue };
let (rotation, scale, twist) = (options.align_angle, options.scale_factor, options.twist_angle);
let expressions = sweep_model::sweep_expressions(surface_entity).unwrap_or([None, None]);
let (Some(profile_curve), Some(path_curve)) = (
document.get_entity(profile).and_then(sweep_model::assoc_edge_curve),
document.get_entity(path).and_then(sweep_model::assoc_edge_curve),
) else { continue };
let evaluate = |expression: &str| {
let mut table = parameters.clone();
table.set("sweepExpression", expression).ok()?;
table.resolve("sweepExpression").ok().filter(|value| value.is_finite())
};
let document = &mut *allocator.document;
let mut next = || document.allocate_handle();
let (action, body, written, profile_param, profile_edge, profile_read, path_param, path_edge, path_read) =
(next(), next(), next(), next(), next(), next(), next(), next(), next());
let dependency = |dependent_on: Handle, read: bool, id: i32, order: i32| AssocDependency {
class_version: 2,
status: 0,
is_read_dependency: read,
is_write_dependency: !read,
is_attached_to_object: true,
is_delegating_to_owning_action: true,
order,
dependent_on,
name: None,
read_dependency: Handle::NULL,
node: Handle::NULL,
dependency_body: Handle::NULL,
dependency_body_id: id,
};
let mut objects: Vec<(Handle, Handle, &str, &str, AssociativeData)> = Vec::new();
let mut reactors: Vec<(Handle, Handle)> = vec![(surface, written), (profile, profile_read), (path, path_read)];
let mut dependencies = vec![written, profile_read, path_read];
let mut value_handles = [Handle::NULL, Handle::NULL];
let mut network_actions = vec![action];
// Scale (slot 0) and twist (slot 1) expressions.
for (slot, expression) in expressions.iter().enumerate() {
let Some(expression) = expression else { continue };
let Some(value) = evaluate(expression) else { continue };
let (variable, read_by_action) = (document.allocate_handle(), document.allocate_handle());
let mut variable_dependencies = Vec::new();
for (index, name) in expression_names(expression).iter().enumerate() {
let Some(named) = allocator.variables.get(name).copied() else { continue };
let reads = document.allocate_handle();
let named_value = parameters.resolve(name).unwrap_or(0.0);
objects.push((reads, variable, "ACDBASSOCVALUEDEPENDENCY", "AcDbAssocValueDependency",
AssociativeData::ValueDependency(AssocValueDependency {
dependency: dependency(named, true, index as i32 + 1, 0),
class_version: 0,
name: String::new(),
value: Allocator::numeric_eval(named_value),
})));
reactors.push((named, reads));
variable_dependencies.push(AssocVariableDependency { dependency: reads, flags: 0 });
}
objects.push((variable, network, "ACDBASSOCVARIABLE", "AcDbAssocVariable", AssociativeData::Variable(AssocVariable {
action: AssocAction {
class_version: 2,
owning_network: network,
max_dependency_index: variable_dependencies.len() as i32,
..Default::default()
},
class_version: 2,
name: String::new(),
expression: expression.clone(),
evaluator: "AcDbCalc:1.0".to_string(),
description: String::new(),
value: Allocator::numeric_eval(value),
has_cached_value: false,
cached_value: String::new(),
flag: false,
dependencies: variable_dependencies,
})));
objects.push((read_by_action, action, "ACDBASSOCVALUEDEPENDENCY", "AcDbAssocValueDependency",
AssociativeData::ValueDependency(AssocValueDependency {
dependency: dependency(variable, true, dependencies.len() as i32 + 1, 0),
class_version: 0,
name: String::new(),
value: Allocator::numeric_eval(value),
})));
reactors.push((variable, read_by_action));
dependencies.push(read_by_action);
value_handles[slot] = read_by_action;
network_actions.push(variable);
}
let real = |value: f64| AssocEvalVariant { code: 40, value: AssocEvalValue::Real(value) };
let value = |name: &str, unit_type: i32, amount: f64, handle: Handle| AssocValueParam {
class_version: 0,
name: name.to_string(),
unit_type,
variables: vec![AssocValueParamVariable { value: real(amount), handle }],
controlled_object_dependency: written,
};
objects.push((action, network, "ACDBASSOCACTION", "AcDbAssocAction", AssociativeData::Action(AssocAction {
class_version: 2,
geometry_status: 0,
owning_network: network,
action_body: body,
action_index: 0,
max_dependency_index: dependencies.len() as i32,
dependencies: dependencies.iter().map(|handle| AssocActionDependency { is_owned: true, dependency: *handle }).collect(),
owned_parameters: vec![profile_param, path_param],
values: vec![
value("RotationAngle", 2, rotation, Handle::NULL),
value("ScaleFactor", 0, scale, value_handles[0]),
value("TwistAngle", 2, twist, value_handles[1]),
],
})));
objects.push((body, action, "ACDBASSOCSWEPTSURFACEACTIONBODY", "AcDbAssocSweptSurfaceActionBody",
AssociativeData::SurfaceActionBody(AssocSurfaceActionBody {
kind: AssocSurfaceActionKind::Swept,
action_body: AssocActionBody { version: 2 },
surface_body: AssocSurfaceBody { version: 0, dependency: written, is_semi_associative: false, marker: 1, is_semi_override: false, grip_status: 0 },
..Default::default()
})));
objects.push((written, action, "ACDBASSOCDEPENDENCY", "AcDbAssocDependency", AssociativeData::Dependency(dependency(surface, false, 1, i32::MIN))));
let edge_param = |read: Handle, (kind, subcurve, curve): (i32, AssocSubcurveKind, Vec<AssocCurveValue>)| AssociativeData::EdgeActionParam(AssocEdgeActionParam {
single_dependency: AssocSingleDependencyActionParam {
action_param: AssocActionParam { is_r2013: 1, version: 0, name: String::new() },
dependency_class_version: 0,
dependency: read,
class_version: 0,
},
parameter: Handle::NULL,
has_action: true,
action_type: kind,
subcurve_kind: subcurve,
curve,
});
let path_parameter = |name: &str, child: Handle| AssociativeData::PathActionParam(AssocPathActionParam {
compound: AssocCompoundActionParam {
action_param: AssocActionParam { is_r2013: 1, version: 0, name: name.to_string() },
class_version: 0,
status: 0,
parameters: vec![child],
child_parameter: None,
},
version: 0,
});
objects.push((profile_param, action, "ACDBASSOCPATHACTIONPARAM", "AcDbAssocPathActionParam", path_parameter("SweepProfile", profile_edge)));
objects.push((profile_edge, profile_param, "ACDBASSOCEDGEACTIONPARAM", "AcDbAssocEdgeActionParam", edge_param(profile_read, profile_curve)));
objects.push((profile_read, action, "ACDBASSOCDEPENDENCY", "AcDbAssocDependency", AssociativeData::Dependency(dependency(profile, true, 2, 0))));
objects.push((path_param, action, "ACDBASSOCPATHACTIONPARAM", "AcDbAssocPathActionParam", path_parameter("SweepPath", path_edge)));
objects.push((path_edge, path_param, "ACDBASSOCEDGEACTIONPARAM", "AcDbAssocEdgeActionParam", edge_param(path_read, path_curve)));
objects.push((path_read, action, "ACDBASSOCDEPENDENCY", "AcDbAssocDependency", AssociativeData::Dependency(dependency(path, true, 3, 0))));
for (handle, owner, dxf, class, data) in objects {
allocator.insert_associative_at(handle, owner, dxf, class, data);
}
for (target, reactor) in reactors {
let document = &mut *allocator.document;
if let Some(entity) = document.get_entity_mut(target) {
entity.common_mut().reactors.push(reactor);
} else if let Some(ObjectType::Associative(object)) = document.objects.get_mut(&target) {
object.reactors.push(reactor);
}
}
added.extend(network_actions);
}
for (offset, handle) in added.iter().copied().enumerate() {
if let Some(ObjectType::Associative(object)) = allocator.document.objects.get_mut(&handle) {
let action = match &mut object.data {
AssociativeData::Action(action) => action,
AssociativeData::Variable(variable) => &mut variable.action,
_ => continue,
};
action.action_index = first_index + offset as i32 + 1;
}
}
added
}
/// Re-evaluates the unnamed variables of kept actions (a swept surface's
/// scale or twist expression) and the values their actions cache, so the
/// file carries the values the named parameters give.
@@ -2714,6 +3005,7 @@ fn materialize_scope(
&& existing_variables.is_empty()
&& preserved_groups.is_empty()
&& foreign_actions.is_empty()
&& !(materialize_all_parameters && !pending_swept_surfaces(document).is_empty())
{
return None;
}
@@ -2898,6 +3190,9 @@ fn materialize_scope(
}
}
refresh_foreign_values(allocator.document, &foreign_actions, parameters);
let pending = if materialize_all_parameters { pending_swept_surfaces(allocator.document) } else { Vec::new() };
let surface_actions = materialize_swept_surface_actions(
&mut allocator, network_handle, parameters, &pending, first_foreign + foreign_actions.len() as i32);
let network = AssocNetwork {
action: AssocAction {
@@ -2907,7 +3202,7 @@ fn materialize_scope(
..Default::default()
},
network_version: 0,
network_action_index: first_foreign + foreign_actions.len() as i32,
network_action_index: first_foreign + (foreign_actions.len() + surface_actions.len()) as i32,
actions: allocator
.variable_actions
.iter()
@@ -2915,6 +3210,7 @@ fn materialize_scope(
.chain(group_handle)
.chain(preserved_groups)
.chain(foreign_actions)
.chain(surface_actions)
.map(|dependency| AssocActionDependency {
is_owned: true,
dependency,
@@ -3055,7 +3351,8 @@ impl Scene {
};
if set.is_none()
&& !existing
&& (owner != model_owner || self.named_parameters.is_empty())
&& (owner != model_owner
|| (self.named_parameters.is_empty() && pending_swept_surfaces(&self.document).is_empty()))
{
continue;
}
+6 -1
View File
@@ -3696,6 +3696,11 @@ impl Scene {
changes.push(change);
}
}
for change in self.refresh_associative_sweeps(&changes) {
if !changes.iter().any(|(handle, _)| *handle == change.0) {
changes.push(change);
}
}
if solve_parametric && !self.parametric_constraints.is_empty() {
for change in self.refresh_parametric_constraints_with_initial_policy(
&changes,
@@ -7499,7 +7504,7 @@ impl Scene {
let Some(EntityType::Viewport(viewport)) = self.document.get_entity(handle) else {
continue;
};
if viewport.common.owner_handle != paper_block || !viewport.status.is_on {
if viewport.common.owner_handle != paper_block || !viewport.is_on() {
continue;
}
let mode = render_mode_override.unwrap_or(viewport.render_mode);
+218 -20
View File
@@ -167,7 +167,11 @@ pub fn sweep_selection_options(profiles: &[EntityType], mut options: SweepOption
}
// Spatial profiles keep their own anchor.
let profiles = profiles.iter().filter(|profile| spatial_profile(profile).is_none()).collect::<Vec<_>>();
if profiles.is_empty() {
// A single profile takes its base from the path it is swept along
// (`sweep_record`).
// ponytail: several profiles share the group anchor even when the path
// starts inside one of them; the reference rule for that case is unmeasured.
if profiles.len() < 2 {
return Some(options);
}
let geometry = profiles.iter().map(|profile| {
@@ -184,23 +188,7 @@ pub fn sweep_selection_options(profiles: &[EntityType], mut options: SweepOption
/// The path traversed the other way when it was picked nearer its end
/// (measured in plan, as the reference measures the pick), else `None`.
fn reversed_toward_pick(path: &EntityType, pick: glam::DVec3) -> Option<EntityType> {
let (start, end) = match path {
EntityType::Polyline3D(value) if !value.is_closed() => {
let p = |v: &codec::entities::Vertex3DPolyline| glam::DVec3::new(v.position.x, v.position.y, v.position.z);
(p(value.vertices.first()?), p(value.vertices.last()?))
}
EntityType::Spline(value) if !value.flags.closed => {
let points = if value.control_points.is_empty() { &value.fit_points } else { &value.control_points };
let p = |v: &codec::types::Vector3| glam::DVec3::new(v.x, v.y, v.z);
(p(points.first()?), p(points.last()?))
}
_ => {
let planar = crate::entities::curve::entity_curve(path)?;
if planar.curve.is_closed() { return None; }
let at = |t: f64| glam::DVec3::from_array(planar.plane.point_at(planar.curve.point_at(t)));
(at(0.0), at(1.0))
}
};
let (start, end) = path_ends(path)?;
let flat = |p: glam::DVec3| p.truncate().distance(pick.truncate());
if flat(end) >= flat(start) { return None; }
match path {
@@ -220,6 +208,27 @@ fn reversed_toward_pick(path: &EntityType, pick: glam::DVec3) -> Option<EntityTy
}
}
/// The start and end of an open path.
fn path_ends(path: &EntityType) -> Option<(glam::DVec3, glam::DVec3)> {
Some(match path {
EntityType::Polyline3D(value) if !value.is_closed() => {
let p = |v: &codec::entities::Vertex3DPolyline| glam::DVec3::new(v.position.x, v.position.y, v.position.z);
(p(value.vertices.first()?), p(value.vertices.last()?))
}
EntityType::Spline(value) if !value.flags.closed => {
let points = if value.control_points.is_empty() { &value.fit_points } else { &value.control_points };
let p = |v: &codec::types::Vector3| glam::DVec3::new(v.x, v.y, v.z);
(p(points.first()?), p(points.last()?))
}
_ => {
let planar = crate::entities::curve::entity_curve(path)?;
if planar.curve.is_closed() { return None; }
let at = |t: f64| glam::DVec3::from_array(planar.plane.point_at(planar.curve.point_at(t)));
(at(0.0), at(1.0))
}
})
}
pub fn sweep_record(profile: &EntityType, path: &EntityType, options: SweepOptions) -> Option<SolidHistorySweep> {
// Placed from the picked end; the record keeps the original path, and
// the placed frame tells which end the sweep starts from.
@@ -229,10 +238,10 @@ pub fn sweep_record(profile: &EntityType, path: &EntityType, options: SweepOptio
return Some(record);
}
let (sweep_entity, sweep_entity_transform) = embedded_sweep_profile(profile)?;
let (plane, wires, _) = kernel::acis::sweep_profile_geometry(&sweep_entity, sweep_entity_transform).ok()?;
kernel::acis::sweep_profile_geometry(&sweep_entity, sweep_entity_transform).ok()?;
let base_point = match options.base_point {
Some(point) => point.to_array(),
None => kernel::brep::sweep_profile_base(plane, &wires)?,
None => kernel::acis::sweep_default_base(&sweep_entity, sweep_entity_transform, &embedded_sweep_path(path)?).ok()?,
};
let mut base = SolidHistoryNodeBase::new(1);
base.transform = glam::DMat4::IDENTITY.to_cols_array();
@@ -337,6 +346,195 @@ pub fn link_sweep_expressions(
crate::scene::view::dispatch::set_entity_xdata(document, handle, SWEEP_EXPRESSION_APP, Some(values));
}
/// SURFACEASSOCIATIVITY: whether new surfaces stay associative to the
/// objects they were made from. A profile setting, so one value for every
/// drawing.
static SURFACE_ASSOCIATIVITY: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(true);
pub fn surface_associativity() -> bool {
SURFACE_ASSOCIATIVITY.load(std::sync::atomic::Ordering::Relaxed)
}
pub fn set_surface_associativity(on: bool) {
SURFACE_ASSOCIATIVITY.store(on, std::sync::atomic::Ordering::Relaxed);
}
/// The application name under which an associative swept surface keeps
/// the profile and path it was swept from.
pub const SWEEP_SOURCES_APP: &str = "OCS_SWEEP_SOURCES";
/// Marks a swept surface associative to the profile and path it was swept
/// from, with the options it is swept again with when they change; the
/// drawing's associative network for it is written on save.
pub fn link_sweep_sources(
document: &mut codec::CadDocument,
surface: codec::Handle,
profile: codec::Handle,
path: codec::Handle,
options: &SweepOptions,
) {
use codec::xdata::XDataValue;
if surface.is_null() { return; }
let point = |p: glam::DVec3| XDataValue::Point3D(Vector3::new(p.x, p.y, p.z));
// The path keeps the direction it was swept in when it is edited.
let reversed = options.path_pick
.zip(document.get_entity(path))
.is_some_and(|(pick, path)| reversed_toward_pick(path, pick).is_some());
let mut values = vec![
XDataValue::Handle(profile),
XDataValue::Handle(path),
XDataValue::Integer16(i16::from(options.align) | (i16::from(options.bank) << 1) | (i16::from(reversed) << 2)),
];
if let Some(base) = options.base_point {
values.push(XDataValue::String("BASE".to_string()));
values.push(point(base));
}
crate::scene::view::dispatch::set_entity_xdata(document, surface, SWEEP_SOURCES_APP, Some(values));
}
/// The profile and path an associative swept surface was swept from.
pub fn sweep_sources(entity: &EntityType) -> Option<(codec::Handle, codec::Handle)> {
let record = entity.common().extended_data.records().iter()
.find(|record| record.application_name == SWEEP_SOURCES_APP)?;
let mut handles = record.values.iter().filter_map(|value| match value {
codec::xdata::XDataValue::Handle(handle) => Some(*handle),
_ => None,
});
Some((handles.next()?, handles.next()?))
}
/// The surface swept again from its current profile and path, with the
/// options it was made with: (surface record, body).
pub fn resweep_from_sources(
surface: &EntityType,
profile: &EntityType,
path: &EntityType,
) -> Option<(SolidHistorySweep, Body)> {
use codec::xdata::XDataValue;
let record = surface.common().extended_data.records().iter()
.find(|record| record.application_name == SWEEP_SOURCES_APP)?;
let EntityType::Surface(value) = surface else { return None };
let SurfaceData::Swept { options: stored, .. } = &value.surface_data else { return None };
let mut options = SweepOptions {
scale: stored.scale_factor,
twist_angle: stored.twist_angle,
..SweepOptions::default()
};
let mut values = record.values.iter();
while let Some(value) = values.next() {
match value {
XDataValue::Integer16(flags) => {
options.align = flags & 1 != 0;
options.bank = flags & 2 != 0;
// Swept from the end: picked there.
if flags & 4 != 0 {
options.path_pick = path_ends(path).map(|(_, end)| end);
}
}
XDataValue::String(key) if key == "BASE" => {
if let Some(XDataValue::Point3D(p)) = values.next() {
options.base_point = Some(glam::DVec3::new(p.x, p.y, p.z));
}
}
_ => {}
}
}
let record = if spatial_profile(profile).is_some() {
spatial_sweep_record(profile, path, options).ok()?
} else {
sweep_record(profile, path, options)?
};
let body = kernel::acis::rebuild_sweep_with_mode(&record, true).ok()?;
Some((record, body))
}
/// An entity's curve as the reference stores it in an edge action
/// parameter: line segment (23: start, vector to the end), arc (11:
/// centre, normal, reference axis, radius, start and end angle, 0) or a
/// composite of those (47: count, then each part's type and values).
pub fn assoc_edge_curve(entity: &EntityType) -> Option<(i32, codec::objects::AssocSubcurveKind, Vec<codec::objects::AssocCurveValue>)> {
use codec::objects::{AssocCurveValue as V, AssocSubcurveKind as K};
use codec::types::Vector3 as P;
let point = |p: glam::DVec3| V::Point(P::new(p.x, p.y, p.z));
let segment = |a: glam::DVec3, b: glam::DVec3| vec![point(a), point(b - a)];
// An arc about `normal` from `start` through `sweep` (signed, about the
// normal) on a circle of `radius`; measured from the reference axis.
let arc = |centre: glam::DVec3, normal: glam::DVec3, axis: glam::DVec3, radius: f64, start: f64, end: f64| vec![
point(centre), point(normal), point(axis), V::Real(radius), V::Real(start), V::Real(end), V::Real(0.0),
];
match entity {
EntityType::Line(line) => {
let (a, b) = (glam::DVec3::new(line.start.x, line.start.y, line.start.z), glam::DVec3::new(line.end.x, line.end.y, line.end.z));
Some((23, K::LineSegment3d, segment(a, b)))
}
EntityType::Circle(circle) => {
let normal = glam::DVec3::new(circle.normal.x, circle.normal.y, circle.normal.z).try_normalize()?;
let axis = arbitrary_x(normal);
Some((11, K::Arc, arc(glam::DVec3::new(circle.center.x, circle.center.y, circle.center.z), normal, axis, circle.radius, 0.0, std::f64::consts::TAU)))
}
EntityType::Arc(value) => {
let normal = glam::DVec3::new(value.normal.x, value.normal.y, value.normal.z).try_normalize()?;
let axis = arbitrary_x(normal);
// The end past the start by the arc's sweep; an equal pair is a
// full turn. (A loop adding TAU never ends on a huge angle.)
let sweep = (value.end_angle - value.start_angle).rem_euclid(std::f64::consts::TAU);
let end = value.start_angle + if sweep > 0.0 { sweep } else { std::f64::consts::TAU };
Some((11, K::Arc, arc(glam::DVec3::new(value.center.x, value.center.y, value.center.z), normal, axis, value.radius, value.start_angle, end)))
}
EntityType::LwPolyline(polyline) => {
let normal = glam::DVec3::new(polyline.normal.x, polyline.normal.y, polyline.normal.z).try_normalize()?;
let axis_x = arbitrary_x(normal);
let axis_y = normal.cross(axis_x);
let at = |v: &codec::entities::LwVertex| axis_x * v.location.x + axis_y * v.location.y + normal * polyline.elevation;
let count = polyline.vertices.len();
let spans = if polyline.is_closed { count } else { count.saturating_sub(1) };
if spans == 0 { return None; }
let mut values = vec![V::Int(spans as i32)];
for index in 0..spans {
let (from, to) = (&polyline.vertices[index], &polyline.vertices[(index + 1) % count]);
let (a, b) = (at(from), at(to));
if from.bulge.abs() <= 1e-12 {
values.push(V::Int(23));
values.extend(segment(a, b));
} else {
// The arc in the polyline's plane; a clockwise one turns about
// the opposite normal, from the same reference axis.
let bulge = from.bulge;
let chord = b - a;
let centre = a + chord * 0.5 + normal.cross(chord) * ((1.0 - bulge * bulge) / (4.0 * bulge));
let radius = chord.length() * (1.0 + bulge * bulge) / (4.0 * bulge.abs());
let turn = normal * bulge.signum();
let across = turn.cross(axis_x);
let angle = |p: glam::DVec3| (p - centre).dot(across).atan2((p - centre).dot(axis_x));
let start = angle(a);
let end = start + 4.0 * bulge.atan().abs();
values.push(V::Int(11));
values.extend(arc(centre, turn, axis_x, radius, start, end));
}
}
Some((47, K::None, values))
}
EntityType::Polyline3D(polyline) => {
let points = polyline.vertices.iter().map(|v| glam::DVec3::new(v.position.x, v.position.y, v.position.z)).collect::<Vec<_>>();
let spans = if polyline.is_closed() { points.len() } else { points.len().saturating_sub(1) };
if spans == 0 { return None; }
let mut values = vec![V::Int(spans as i32)];
for index in 0..spans {
values.push(V::Int(23));
values.extend(segment(points[index], points[(index + 1) % points.len()]));
}
Some((47, K::None, values))
}
_ => None,
}
}
/// The arbitrary-axis X direction of an entity normal.
fn arbitrary_x(normal: glam::DVec3) -> glam::DVec3 {
let world = if normal.x.abs() < 1.0 / 64.0 && normal.y.abs() < 1.0 / 64.0 { glam::DVec3::Y } else { glam::DVec3::Z };
world.cross(normal).normalize()
}
/// The scale and twist expressions a swept surface is linked to.
pub fn sweep_expressions(entity: &EntityType) -> Option<[Option<String>; 2]> {
let record = entity.common().extended_data.records().iter()
+1 -1
View File
@@ -13,7 +13,7 @@ use codec::EntityType;
use crate::entities::curve::entity_curve;
pub use super::sweep_command_model::{
is_sweep_path, is_sweep_profile, scaled_sweep_path_refusal, spatial_profile, spatial_sweep_record, surface_sweep_record, sweep_expressions, link_sweep_expressions, sweep_record, sweep_refusal_code, sweep_selection_options, swept_surface_entity, swept_with_options,
is_sweep_path, is_sweep_profile, scaled_sweep_path_refusal, spatial_profile, spatial_sweep_record, surface_sweep_record, sweep_expressions, link_sweep_expressions, link_sweep_sources, sweep_sources, SWEEP_SOURCES_APP, resweep_from_sources, surface_associativity, set_surface_associativity, assoc_edge_curve, sweep_record, sweep_refusal_code, sweep_selection_options, swept_surface_entity, swept_with_options,
};
/// A drawn profile, as the kernel wants it: the plane it lies in and the
+75
View File
@@ -1130,6 +1130,54 @@ impl Scene {
rebuilt
}
/// Associative swept surfaces follow edits of their profile or path:
/// swept again from them with the options they were made with. A
/// surface edited along with its sources keeps its own edit. Returns the
/// surfaces rebuilt.
pub(crate) fn refresh_associative_sweeps(&mut self, changes: &[(Handle, crate::scene::ChangeKind)]) -> Vec<(Handle, crate::scene::ChangeKind)> {
use crate::scene::model::sweep_model;
let changed = changes.iter()
.filter(|(_, kind)| !matches!(kind, crate::scene::ChangeKind::Removed))
.map(|(handle, _)| *handle)
.collect::<rustc_hash::FxHashSet<_>>();
// Every edit passes through here: a drawing with no associative
// swept surface (no application registered for them) skips the scan.
if changed.is_empty() || !self.document.app_ids.contains(sweep_model::SWEEP_SOURCES_APP) {
return Vec::new();
}
let linked = self.document.entities()
.filter(|entity| matches!(entity, EntityType::Surface(_)))
.filter_map(|entity| {
let handle = entity.common().handle;
let (profile, path) = sweep_model::sweep_sources(entity)?;
(!changed.contains(&handle) && (changed.contains(&profile) || changed.contains(&path)))
.then_some((handle, profile, path))
})
.collect::<Vec<_>>();
let mut rebuilt = Vec::new();
for (handle, profile, path) in linked {
let (Some(surface), Some(profile), Some(path)) = (
self.document.get_entity(handle),
self.document.get_entity(profile),
self.document.get_entity(path),
) else { continue };
let Some((record, body)) = sweep_model::resweep_from_sources(surface, profile, path) else { continue };
let EntityType::Surface(fresh) = sweep_model::swept_surface_entity(&record) else { continue };
let Some(document) = crate::scene::convert::acis_export::solid_to_sat(&body) else { continue };
let Some(display) = self.prepare_solid_model_display(handle, &body) else { continue };
let before = self.document.get_entity(handle).cloned().map(std::sync::Arc::new);
self.record_undo_before(handle, before);
if let Some(EntityType::Surface(surface)) = self.document.get_entity_mut(handle) {
surface.acis_data = codec::entities::AcisData::from_sat(&document.to_sat_string());
surface.surface_data = fresh.surface_data;
surface.point_of_reference = fresh.point_of_reference;
}
self.register_prepared_solid_model(handle, body, display);
rebuilt.push((handle, crate::scene::ChangeKind::Modified));
}
rebuilt
}
/// Swept surfaces the reference keeps associative to a scale or twist
/// expression (an associative swept surface action whose value parameter
/// depends on an expression variable) are linked the same way here.
@@ -1140,6 +1188,7 @@ impl Scene {
_ => None,
};
let mut links = Vec::new();
let mut sources = Vec::new();
for item in self.document.objects.values() {
let ObjectType::Associative(action) = item else { continue };
let AssociativeData::Action(action) = &action.data else { continue };
@@ -1160,6 +1209,32 @@ impl Scene {
if expressions.iter().any(Option::is_some) {
links.push((written.dependent_on, expressions));
}
// The profile and path the action reads.
let source = |name: &str| {
action.owned_parameters.iter().find_map(|parameter| {
let Some(AssociativeData::PathActionParam(path)) = object(*parameter) else { return None };
if path.compound.action_param.name != name { return None; }
let Some(AssociativeData::EdgeActionParam(edge)) = object(*path.compound.parameters.first()?) else { return None };
match object(edge.single_dependency.dependency) {
Some(AssociativeData::Dependency(dependency)) => Some(dependency.dependent_on),
_ => None,
}
})
};
if let (Some(profile), Some(path)) = (source("SweepProfile"), source("SweepPath")) {
sources.push((written.dependent_on, profile, path));
}
}
for (surface, profile, path) in sources {
let Some(entity @ EntityType::Surface(value)) = self.document.get_entity(surface) else { continue };
if crate::scene::model::sweep_model::sweep_sources(entity).is_some() { continue; }
let codec::entities::SurfaceData::Swept { options, .. } = &value.surface_data else { continue };
let linked = crate::command::SweepOptions {
align: options.sweep_alignment_flags == 1,
bank: options.bank,
..crate::command::SweepOptions::default()
};
crate::scene::model::sweep_model::link_sweep_sources(&mut self.document, surface, profile, path, &linked);
}
for (handle, expressions) in links {
let Some(entity) = self.document.get_entity(handle) else { continue };
+3 -3
View File
@@ -801,7 +801,7 @@ impl Scene {
let Some(EntityType::Viewport(vp)) = self.document.get_entity(*handle) else {
return None;
};
if !vp.status.is_on {
if !vp.is_on() {
return None;
}
let rect = self.viewport_screen_rect(vp.common.handle, canvas)?;
@@ -838,7 +838,7 @@ impl Scene {
pub fn viewport_displays_content(&self, vp_handle: Handle) -> bool {
matches!(
self.document.get_entity(vp_handle),
Some(EntityType::Viewport(vp)) if vp.status.is_on
Some(EntityType::Viewport(vp)) if vp.is_on()
)
}
@@ -850,7 +850,7 @@ impl Scene {
let Some(EntityType::Viewport(vp)) = self.document.get_entity(*handle) else {
return None;
};
if vp.status.is_on {
if vp.is_on() {
Some(vp.common.handle)
} else {
None
+1 -1
View File
@@ -194,7 +194,7 @@ impl Scene {
let Some(EntityType::Viewport(vp)) = self.document.get_entity(handle) else {
continue;
};
if !vp.status.is_on
if !vp.is_on()
|| self.entity_temporarily_hidden(handle)
{
continue;
+2 -2
View File
@@ -21,7 +21,7 @@ impl Scene {
})
.filter(|vp| {
vp.common.owner_handle == paper_block
&& vp.status.is_on
&& vp.is_on()
&& only_vp.map_or(true, |h| vp.common.handle == h)
&& exclude_vp.map_or(true, |h| vp.common.handle != h)
})
@@ -439,7 +439,7 @@ impl Scene {
.iter()
.filter_map(|handle| match self.document.get_entity(*handle) {
Some(EntityType::Viewport(viewport))
if viewport.common.owner_handle == paper_block && viewport.status.is_on =>
if viewport.common.owner_handle == paper_block && viewport.is_on() =>
{
Some(viewport)
}
+19
View File
@@ -61,6 +61,8 @@ pub struct AppPrefs {
pub zoom_wheel_reversed: bool,
/// Scroll pans and Ctrl+scroll zooms (touchpads).
pub touchpad_pan: bool,
/// Interface scale in percent.
pub ui_scale_percent: u16,
/// ZOOMFACTOR. The slider sets the range the system variable has; the
/// field beside it reaches `settings::ZOOM_FACTOR_MAX`.
pub zoom_factor: i32,
@@ -679,6 +681,23 @@ pub fn view_window<'a>(
.width(sizing.width),
Space::new().height(12),
color_controls,
Space::new().height(16),
// A list, not a slider: the dialog rescales under the cursor as the
// value changes, which would drag a slider along with it.
row![
text(crate::t!("Interface scale")).size(12).width(150),
iced::widget::pick_list(
Some(format!("{}%", prefs.ui_scale_percent)),
[75u16, 100, 125, 150, 175, 200].map(|p| format!("{p}%")).to_vec(),
|label: &String| label.clone(),
)
.on_select(|label: String| {
Message::UiScaleChanged(label.trim_end_matches('%').parse().unwrap_or(100))
})
.width(sizing.width),
]
.spacing(12)
.align_y(iced::Center),
Space::new().height(24),
row![
text(crate::t!("Model Space Appearance")).size(15),