forked from 1b-agent/opencadstudio-upstream
Contextual External Reference ribbon tab
Shown and brought forward while only xrefs are selected: Edit Reference In-Place, Open Reference, Create Clipping Boundary, Remove Clipping and External References. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
857f2f2e58
commit
68721813f4
26 files changed
+278
-22
No files matched your search
@@ -20,9 +20,31 @@ impl OpenCADStudio {
|
||||
out
|
||||
}
|
||||
|
||||
/// Show the tab while only PDF underlays are selected.
|
||||
/// The selected xrefs, or nothing when anything else is selected.
|
||||
pub(in crate::app) fn selected_xrefs(&self, i: usize) -> Vec<codec::Handle> {
|
||||
let doc = &self.tabs[i].scene.document;
|
||||
let mut out = Vec::new();
|
||||
for (handle, entity) in self.tabs[i].scene.selected_entities() {
|
||||
let xref = match entity {
|
||||
codec::EntityType::Insert(ins) => doc
|
||||
.block_records
|
||||
.get(&ins.block_name)
|
||||
.is_some_and(|br| br.flags.is_xref || br.flags.is_xref_overlay),
|
||||
_ => false,
|
||||
};
|
||||
if !xref {
|
||||
return Vec::new();
|
||||
}
|
||||
out.push(handle);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Show the PDF Underlay tab while only PDF underlays are selected, the
|
||||
/// External Reference tab while only xrefs are.
|
||||
pub(in crate::app) fn sync_underlay_tab(&mut self) {
|
||||
let i = self.active_tab;
|
||||
let xref = !self.tabs[i].is_start && !self.selected_xrefs(i).is_empty();
|
||||
let context = if self.tabs[i].is_start {
|
||||
None
|
||||
} else {
|
||||
@@ -36,7 +58,7 @@ impl OpenCADStudio {
|
||||
)
|
||||
})
|
||||
};
|
||||
self.ribbon.set_underlay_context(context);
|
||||
self.ribbon.set_underlay_context(context, xref);
|
||||
}
|
||||
|
||||
/// One undo step that edits every selected PDF underlay.
|
||||
@@ -127,6 +149,41 @@ impl OpenCADStudio {
|
||||
self.tabs[i].scene.reseed_underlays();
|
||||
self.sync_underlay_tab();
|
||||
}
|
||||
// External Reference tab: the selected xrefs.
|
||||
"_XREFEDIT" | "_XREFOPEN" => {
|
||||
let Some(&handle) = self.selected_xrefs(i).first() else {
|
||||
return Some(Task::none());
|
||||
};
|
||||
self.tabs[i].scene.deselect_all();
|
||||
self.tabs[i].scene.select_entity(handle, true);
|
||||
let command = if cmd == "_XREFEDIT" { "REFEDIT" } else { "XOPEN" };
|
||||
return Some(self.dispatch_command(command));
|
||||
}
|
||||
"_XREFCLIP" => {
|
||||
use crate::command::CadCommand;
|
||||
let inserts = self.selected_xrefs(i);
|
||||
if inserts.is_empty() {
|
||||
return Some(Task::none());
|
||||
}
|
||||
let clipped = inserts.iter().any(|h| {
|
||||
crate::scene::pick::xclip::filter_handle(&self.tabs[i].scene.document, *h).is_some()
|
||||
});
|
||||
let (command, first) =
|
||||
crate::modules::insert::xclip::XclipCommand::start_new_boundary(inserts, clipped);
|
||||
if let crate::command::CmdResult::ReportMeasurement(text) = first {
|
||||
for line in text.lines() {
|
||||
self.command_line.push_output(line);
|
||||
}
|
||||
}
|
||||
self.command_line.push_info(&command.prompt());
|
||||
self.tabs[i].active_cmd = Some(Box::new(command));
|
||||
}
|
||||
"_XREFUNCLIP" => {
|
||||
let inserts = self.selected_xrefs(i);
|
||||
if !inserts.is_empty() {
|
||||
self.apply_xclip(i, inserts, crate::modules::insert::xclip::XclipAction::Delete);
|
||||
}
|
||||
}
|
||||
"_PDFULUNCLIP" => {
|
||||
self.edit_selected_underlays(i, "PDFCLIP", |u| {
|
||||
u.clip_boundary_vertices.clear();
|
||||
|
||||
Reference in new issue
Block a user