forked from 1b-agent/opencadstudio-upstream
feat(ucs): central WCS↔UCS converter; adopt file UCS, drive readout + icon
Introduce one bridge between WCS (how geometry and the file are stored) and the active UCS (the coordinate system the user works in), so every UCS-aware system routes through it instead of re-deriving axis math. - UcsXform (app/helpers.rs): the converter — to_wcs/to_ucs (points), vec_to_wcs/vec_to_ucs (directions), axes(), is_identity(). Orthonormal axes, so the inverse is the transpose. The old ucs_to_wcs / ucs_rotate_vec free fns now delegate to it (one implementation). - DocumentTab::ucs_xform() builds it from the tab's active_ucs (None = WCS). - DocumentTab::adopt_active_ucs_from_header() loads the document's saved current UCS (header model-space UCS) into active_ucs on open, so the file's coordinate system is live immediately; called from both load paths. - Status-bar coordinate readout reports the cursor in the active UCS. - UCS icon tripod projects the active UCS axes, so it rotates to the UCS instead of always showing world X/Y/Z. First slice of routing the app's coordinate systems through the converter; input/picking, grid, ViewCube, and the remaining readouts follow. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
44d2df9361
commit
4aa1e90dcf
6 files changed
+135
-44
No files matched your search
@@ -165,6 +165,29 @@ pub(super) struct DocumentTab {
|
||||
}
|
||||
|
||||
impl DocumentTab {
|
||||
/// The active WCS↔UCS converter for this tab — identity when no UCS is set.
|
||||
/// Every consumer that needs UCS-relative coordinates goes through this.
|
||||
pub(super) fn ucs_xform(&self) -> super::helpers::UcsXform {
|
||||
super::helpers::UcsXform::from_active(self.active_ucs.as_ref())
|
||||
}
|
||||
|
||||
/// Adopt the document's saved current UCS (the header's model-space UCS) as
|
||||
/// the active UCS, so the coordinate readout / icon / input follow the
|
||||
/// file's coordinate system the moment it opens. An identity UCS clears it
|
||||
/// back to plain WCS. Call wherever a document is loaded into the tab.
|
||||
pub(super) fn adopt_active_ucs_from_header(&mut self) {
|
||||
let h = &self.scene.document.header;
|
||||
let mut u = Ucs::new(h.model_space_ucs_name.clone());
|
||||
u.origin = h.model_space_ucs_origin;
|
||||
u.x_axis = h.model_space_ucs_x_axis;
|
||||
u.y_axis = h.model_space_ucs_y_axis;
|
||||
self.active_ucs = if super::helpers::UcsXform::from_ucs(&u).is_identity() {
|
||||
None
|
||||
} else {
|
||||
Some(u)
|
||||
};
|
||||
}
|
||||
|
||||
pub(super) fn new_drawing(n: usize) -> Self {
|
||||
let mut scene = Scene::new();
|
||||
linetypes::populate_document(&mut scene.document);
|
||||
|
||||
Reference in new issue
Block a user