forked from 1b-agent/opencadstudio-upstream
Properties: a dynamic block's visibility state as a dropdown
A reference to a block with a visibility parameter gets a Custom row named after the parameter, listing its states with the one shown selected. Picking a state applies it the same way as the reference's visibility grip, one undo step. Refs #1862 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
20fb6a66b0
commit
5f5b64ef70
3 files changed
+49
No files matched your search
@@ -117,6 +117,34 @@ impl OpenCADStudio {
|
||||
})
|
||||
}
|
||||
|
||||
/// The visibility parameter of a dynamic-block reference as a Properties
|
||||
/// row: the parameter's name, its states, and the one shown now.
|
||||
pub(super) fn visibility_property(
|
||||
doc: &codec::CadDocument,
|
||||
handle: Handle,
|
||||
) -> Option<crate::scene::model::object::Property> {
|
||||
let Some(EntityType::Insert(ins)) = doc.get_entity(handle) else {
|
||||
return None;
|
||||
};
|
||||
let (def_block, param) = doc.dynamic_visibility_for_insert(handle)?;
|
||||
let options: Vec<String> = param.states.iter().map(|s| s.name.clone()).collect();
|
||||
let current = Self::current_visibility_state(doc, def_block, &ins.block_name, param);
|
||||
// An unnamed parameter takes the name a new one gets in the file.
|
||||
let label = if param.element_name.trim().is_empty() {
|
||||
"Visibility1".to_string()
|
||||
} else {
|
||||
param.element_name.clone()
|
||||
};
|
||||
Some(crate::scene::model::object::Property {
|
||||
label,
|
||||
field: "dyn_visibility",
|
||||
value: crate::scene::model::object::PropValue::Choice {
|
||||
selected: current.and_then(|c| options.get(c).cloned()).unwrap_or_default(),
|
||||
options,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/// Recompute the visibility grip for the active tab's single selection and
|
||||
/// append it (as a Triangle grip) to `selected_grips`. Clears it when the
|
||||
/// selection is not a dynamic-block reference. `wo` is the world offset
|
||||
|
||||
Reference in new issue
Block a user