forked from 1b-agent/opencadstudio-upstream
feat(block-editor): wire Visibility parameter placement
Milestone 1: enable Parameters > Visibility and add interactive BPARAMETER VISIBILITY placement using the existing native visibility parameter, grip and state engine. Bare BPARAMETER currently offers only Visibility; other parameter, action and set entries remain unavailable. Show the placed parameter in the editor and support cancel, local undo/ redo, save/discard and saved-edit undo. Bind placement to its document and definition, reject duplicates and invalid points, and protect existing authoring graphs from replacement. Keep visibility parameters and their grips aligned with geometry when a BEDIT UCS change reframes the definition, including parameter-only blocks. Validation: 9 targeted tests, 272 block checks and 58 dock checks passed (overlapping groups). All 17 local DWG fixtures passed in-memory DWG/DXF placement roundtrips and graph-preservation checks; originals unchanged.
This commit is contained in:
1 parent
c8750db7c9
commit
308990e672
14 files changed
+778
-7
No files matched your search
@@ -5,6 +5,8 @@
|
||||
use crate::modules::parametric::ParametricModule;
|
||||
use crate::modules::{CadModule, IconKind, ModuleEvent, RibbonGroup, RibbonItem, ToolDef};
|
||||
|
||||
pub mod visibility_parameter;
|
||||
|
||||
pub struct BlockEditorModule;
|
||||
|
||||
impl CadModule for BlockEditorModule {
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
//! Interactive placement of the supported Visibility action parameter.
|
||||
|
||||
use crate::command::{CadCommand, CmdOption, CmdResult};
|
||||
use codec::Handle;
|
||||
use glam::DVec3;
|
||||
|
||||
pub struct VisibilityParameterCommand {
|
||||
document_id: u64,
|
||||
definition: Handle,
|
||||
choosing_type: bool,
|
||||
}
|
||||
|
||||
impl VisibilityParameterCommand {
|
||||
pub fn new(document_id: u64, definition: Handle, choosing_type: bool) -> Self {
|
||||
Self {
|
||||
document_id,
|
||||
definition,
|
||||
choosing_type,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CadCommand for VisibilityParameterCommand {
|
||||
fn name(&self) -> &'static str {
|
||||
"BPARAMETER"
|
||||
}
|
||||
|
||||
fn prompt(&self) -> String {
|
||||
if self.choosing_type {
|
||||
crate::t!("BPARAMETER Enter parameter type [Visibility] <Visibility>:").into_owned()
|
||||
} else {
|
||||
crate::t!("BPARAMETER Specify visibility parameter location:").into_owned()
|
||||
}
|
||||
}
|
||||
|
||||
fn options(&self) -> Vec<CmdOption> {
|
||||
if self.choosing_type {
|
||||
vec![CmdOption::new(crate::t!("Visibility").as_ref(), "V")]
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
fn wants_text_input(&self) -> bool {
|
||||
self.choosing_type
|
||||
}
|
||||
|
||||
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
|
||||
if !self.choosing_type {
|
||||
return None;
|
||||
}
|
||||
Some(
|
||||
match text
|
||||
.trim()
|
||||
.trim_start_matches('_')
|
||||
.to_ascii_uppercase()
|
||||
.as_str()
|
||||
{
|
||||
"" | "V" | "VISIBILITY" => {
|
||||
self.choosing_type = false;
|
||||
CmdResult::NeedPoint
|
||||
}
|
||||
_ => CmdResult::ReportError(
|
||||
crate::t!("Only Visibility parameter placement is currently supported.")
|
||||
.into_owned(),
|
||||
),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn on_point(&mut self, location: DVec3) -> CmdResult {
|
||||
if self.choosing_type {
|
||||
return CmdResult::NeedPoint;
|
||||
}
|
||||
if !location.is_finite() {
|
||||
return CmdResult::ReportError(
|
||||
crate::t!("Specify a finite parameter location.").into_owned(),
|
||||
);
|
||||
}
|
||||
CmdResult::PlaceBlockVisibilityParameter {
|
||||
document_id: self.document_id,
|
||||
definition: self.definition,
|
||||
location,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_enter(&mut self) -> CmdResult {
|
||||
if self.choosing_type {
|
||||
self.on_text_input("").unwrap()
|
||||
} else {
|
||||
CmdResult::Cancel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inventory::submit!(crate::command::CommandRegistration {
|
||||
names: &["BPARAMETER"]
|
||||
});
|
||||
Reference in new issue
Block a user