feat: node graph overlay; move to opencadcodec/opencadkernel/opencadgraph

The codec and kernel repositories and crates are renamed opencadcodec and
opencadkernel. Inside OCS they are depended on under short keys, so code
reads `codec::`, `kernel::` and the new `graph::` (opencadgraph, the node
graph engine). File-format and protocol spellings stay as they were: the
ACIS product id `acadrust`, the ACADRUST_* switches and the plugin
version keys `acadrust_version` / `acadrust_source`.

A button left of MCP on the command line opens a translucent node graph
over the viewport, with a palette of object, input, math, logic, list,
text and geometry nodes added by click or drag. An object node owns
drawing entities and its rows are the Properties panel's own rows for
them: the single-object page is extracted from refresh_properties as
entity_property_sections, values use the control protocol's
property_json, and writes go through set_property_value with a property
target override, so the panel, MCP and the graph share one read/write
path. A list reaching an object row makes one entity per element. Each
graph action is one undo step; the canvas pans and zooms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 5.5 committed 2026-09-25 07:34:23 +03:00
1 parent 56c04408d6
commit f537aff75c
430 files changed
+9925 -8540

No files matched your search

+106 -106
View File
@@ -68,8 +68,8 @@ impl OpenCADStudio {
pub(super) fn handle_replace_many(
&mut self,
replacements: Vec<(Handle, Vec<acadrust::EntityType>)>,
additions: Vec<acadrust::EntityType>,
replacements: Vec<(Handle, Vec<codec::EntityType>)>,
additions: Vec<codec::EntityType>,
) -> Option<Task<Message>> {
let i = self.active_tab;
if let Some((handle, _)) = replacements
@@ -106,7 +106,7 @@ impl OpenCADStudio {
pub(super) fn handle_replace_many_continue(
&mut self,
replacements: Vec<(Handle, Vec<acadrust::EntityType>)>,
replacements: Vec<(Handle, Vec<codec::EntityType>)>,
) -> Option<Task<Message>> {
let i = self.active_tab;
if let Some((handle, _)) = replacements
@@ -141,7 +141,7 @@ impl OpenCADStudio {
pub(super) fn handle_replace_entity(
&mut self,
handle: Handle,
new_entities: Vec<acadrust::EntityType>,
new_entities: Vec<codec::EntityType>,
) -> Option<Task<Message>> {
let i = self.active_tab;
if self.reject_locked_edit(i, handle) {
@@ -149,7 +149,7 @@ impl OpenCADStudio {
}
// Detect SPLINEDIT sentinel: a single XLine with a magic layer name.
if new_entities.len() == 1 {
if let acadrust::EntityType::XLine(ref xl) = new_entities[0] {
if let codec::EntityType::XLine(ref xl) = new_entities[0] {
let op = xl.common.layer.clone();
if op.starts_with("__SPLINEDIT_") {
let label = self.history_label_from_active_cmd(i, "SPLINEDIT");
@@ -171,7 +171,7 @@ impl OpenCADStudio {
let label = self.history_label_from_active_cmd(i, "TRIM");
self.push_undo_snapshot(i, label);
self.tabs[i].scene.erase_entities(&[handle]);
let new_handles: Vec<acadrust::Handle> = new_entities
let new_handles: Vec<codec::Handle> = new_entities
.into_iter()
.map(|e| self.tabs[i].scene.add_entity(e))
.collect();
@@ -179,7 +179,7 @@ impl OpenCADStudio {
for &nh in &new_handles {
if matches!(
self.tabs[i].scene.document.get_entity(nh),
Some(acadrust::EntityType::Dimension(_))
Some(codec::EntityType::Dimension(_))
) {
self.tabs[i].scene.invalidate_dim_block_recorded(nh);
}
@@ -327,7 +327,7 @@ impl OpenCADStudio {
if matches!(
self.tabs[i].scene.document.get_entity(handle),
Some(
acadrust::EntityType::Block(_) | acadrust::EntityType::BlockEnd(_)
codec::EntityType::Block(_) | codec::EntityType::BlockEnd(_)
)
) {
needs_geometry_bump = true;
@@ -358,7 +358,7 @@ impl OpenCADStudio {
for &handle in by_index.iter().filter(|h| !h.is_null()) {
if matches!(
self.tabs[i].scene.document.get_entity(handle),
Some(acadrust::EntityType::Leader(_))
Some(codec::EntityType::Leader(_))
) {
let _ = self.tabs[i]
.scene
@@ -423,15 +423,15 @@ impl OpenCADStudio {
/// `sync_displayed_annotation_context`, undo/dirty/selection/echo/panels).
/// See the per-helper report in `finalize_paste`.
pub(crate) fn paste_entities_kernel(
doc: &mut acadrust::CadDocument,
entities: &[acadrust::EntityType],
doc: &mut codec::CadDocument,
entities: &[codec::EntityType],
deps: &crate::app::ClipboardDeps,
translate: Option<&crate::command::EntityTransform>,
) -> (
Vec<Handle>,
rustc_hash::FxHashMap<Handle, Handle>,
) {
use acadrust::TableEntry;
use codec::TableEntry;
// Port of `merge_dependencies`: recreate missing table records with fresh
// handles from the target document. Pure `&mut CadDocument` work.
for rec in &deps.layers {
@@ -478,7 +478,7 @@ pub(crate) fn paste_entities_kernel(
// Same `*D`-block re-point as `finalize_paste` (#290, #161): the
// baked dimension geometry lives in WCS, so the paste gets its own
// transformed copy of the snapshotted block.
if let acadrust::EntityType::Dimension(d) = &entity {
if let codec::EntityType::Dimension(d) = &entity {
let bn = d.base().block_name.clone();
if !bn.trim().is_empty() {
if let Some(subs) = deps
@@ -491,7 +491,7 @@ pub(crate) fn paste_entities_kernel(
crate::command::EntityTransform::Translate(glam::DVec3::ZERO),
);
if let Some(new_bn) = define_transformed_block_doc(doc, &subs, &bt) {
if let acadrust::EntityType::Dimension(d) = &mut entity {
if let codec::EntityType::Dimension(d) = &mut entity {
d.base_mut().block_name = new_bn;
}
}
@@ -536,7 +536,7 @@ pub(crate) fn paste_entities_kernel(
let leader_links: Vec<(Handle, Handle)> = entities
.iter()
.filter_map(|source| {
let acadrust::EntityType::Leader(leader) = source else {
let codec::EntityType::Leader(leader) = source else {
return None;
};
let copied_leader = handle_map.get(&source.common().handle).copied()?;
@@ -548,7 +548,7 @@ pub(crate) fn paste_entities_kernel(
})
.collect();
for (leader_handle, annotation_handle) in leader_links {
if let Some(acadrust::EntityType::Leader(leader)) = doc.get_entity_mut(leader_handle) {
if let Some(codec::EntityType::Leader(leader)) = doc.get_entity_mut(leader_handle) {
leader.annotation_handle = annotation_handle;
}
}
@@ -561,14 +561,14 @@ pub(crate) fn paste_entities_kernel(
/// two lines are mirrored here), NULL top-level/owner handles, then
/// `doc.add_entity`. The `entity_mode` default (Model vs paper space) and all
/// tessellation/render caching stay caller-side in the Scene shell.
fn add_entity_clone_doc(doc: &mut acadrust::CadDocument, mut entity: acadrust::EntityType) -> Handle {
fn add_entity_clone_doc(doc: &mut codec::CadDocument, mut entity: codec::EntityType) -> Handle {
match &mut entity {
acadrust::EntityType::Insert(ins) => {
codec::EntityType::Insert(ins) => {
for att in ins.attributes.iter_mut() {
att.common.handle = doc.allocate_handle();
}
}
acadrust::EntityType::Polyline3D(p) => {
codec::EntityType::Polyline3D(p) => {
for v in p.vertices.iter_mut() {
v.handle = doc.allocate_handle();
}
@@ -584,10 +584,10 @@ fn add_entity_clone_doc(doc: &mut acadrust::CadDocument, mut entity: acadrust::E
/// half of `Scene::define_block_raw` (no-op when the block exists). The
/// trailing `bump_geometry` stays caller-side.
fn define_block_raw_doc(
doc: &mut acadrust::CadDocument,
doc: &mut codec::CadDocument,
name: &str,
base_point: acadrust::types::Vector3,
entities: &[acadrust::EntityType],
base_point: codec::types::Vector3,
entities: &[codec::EntityType],
) {
if name.is_empty() || doc.block_records.get(name).is_some() {
return;
@@ -596,21 +596,21 @@ fn define_block_raw_doc(
let br_handle = Handle::new(next);
let block_handle = Handle::new(next + 1);
let end_handle = Handle::new(next + 2);
let mut block_record = acadrust::tables::BlockRecord::new(name);
let mut block_record = codec::tables::BlockRecord::new(name);
block_record.handle = br_handle;
block_record.block_entity_handle = block_handle;
block_record.block_end_handle = end_handle;
if doc.block_records.add(block_record).is_err() {
return;
}
let mut block = acadrust::entities::Block::new(name, base_point);
let mut block = codec::entities::Block::new(name, base_point);
block.common.handle = block_handle;
block.common.owner_handle = br_handle;
let _ = doc.add_entity(acadrust::EntityType::Block(block));
let mut block_end = acadrust::entities::BlockEnd::new();
let _ = doc.add_entity(codec::EntityType::Block(block));
let mut block_end = codec::entities::BlockEnd::new();
block_end.common.handle = end_handle;
block_end.common.owner_handle = br_handle;
let _ = doc.add_entity(acadrust::EntityType::BlockEnd(block_end));
let _ = doc.add_entity(codec::EntityType::BlockEnd(block_end));
for mut entity in entities.iter().cloned() {
add_entity_clone_doc_inner(doc, &mut entity, br_handle);
let _ = doc.add_entity(entity);
@@ -619,17 +619,17 @@ fn define_block_raw_doc(
/// Shared sub-handle reset + owner stamp for block-definition members.
fn add_entity_clone_doc_inner(
doc: &mut acadrust::CadDocument,
entity: &mut acadrust::EntityType,
doc: &mut codec::CadDocument,
entity: &mut codec::EntityType,
owner: Handle,
) {
match entity {
acadrust::EntityType::Insert(ins) => {
codec::EntityType::Insert(ins) => {
for att in ins.attributes.iter_mut() {
att.common.handle = doc.allocate_handle();
}
}
acadrust::EntityType::Polyline3D(p) => {
codec::EntityType::Polyline3D(p) => {
for v in p.vertices.iter_mut() {
v.handle = doc.allocate_handle();
}
@@ -645,8 +645,8 @@ fn add_entity_clone_doc_inner(
/// so this is a verbatim port). Returns the new block name, or `None` when
/// `subs` is empty.
fn define_transformed_block_doc(
doc: &mut acadrust::CadDocument,
subs: &[acadrust::EntityType],
doc: &mut codec::CadDocument,
subs: &[codec::EntityType],
t: &crate::command::EntityTransform,
) -> Option<String> {
if subs.is_empty() {
@@ -664,19 +664,19 @@ fn define_transformed_block_doc(
let br_handle = Handle::new(next);
let block_handle = Handle::new(next + 1);
let end_handle = Handle::new(next + 2);
let mut br = acadrust::tables::BlockRecord::new(&new_name);
let mut br = codec::tables::BlockRecord::new(&new_name);
br.handle = br_handle;
br.block_entity_handle = block_handle;
br.block_end_handle = end_handle;
doc.block_records.add(br).ok()?;
let mut block = acadrust::entities::Block::new(&new_name, acadrust::types::Vector3::ZERO);
let mut block = codec::entities::Block::new(&new_name, codec::types::Vector3::ZERO);
block.common.handle = block_handle;
block.common.owner_handle = br_handle;
doc.add_entity(acadrust::EntityType::Block(block)).ok()?;
let mut block_end = acadrust::entities::BlockEnd::new();
doc.add_entity(codec::EntityType::Block(block)).ok()?;
let mut block_end = codec::entities::BlockEnd::new();
block_end.common.handle = end_handle;
block_end.common.owner_handle = br_handle;
doc.add_entity(acadrust::EntityType::BlockEnd(block_end))
doc.add_entity(codec::EntityType::BlockEnd(block_end))
.ok()?;
for sub in subs {
let mut sub = sub.clone();
@@ -693,9 +693,9 @@ fn define_transformed_block_doc(
/// storage (`clipboard`, `clipboard_base`, `clipboard_deps`) and the echo stay
/// caller-side in `copy_entities_to_clipboard` / `handle_copy_to_clipboard`.
pub(crate) fn copy_to_clipboard_kernel(
doc: &acadrust::CadDocument,
doc: &codec::CadDocument,
handles: &[Handle],
) -> (Vec<acadrust::EntityType>, crate::app::ClipboardDeps) {
) -> (Vec<codec::EntityType>, crate::app::ClipboardDeps) {
let entities: Vec<_> = handles
.iter()
.filter_map(|&handle| doc.get_entity(handle).cloned())
@@ -705,7 +705,7 @@ pub(crate) fn copy_to_clipboard_kernel(
}
fn recreate_ext_subtree(
doc: &mut acadrust::CadDocument,
doc: &mut codec::CadDocument,
cap: &crate::app::ClipExtObjects,
entity_handle: Option<Handle>,
) -> Option<Handle> {
@@ -733,12 +733,12 @@ fn recreate_ext_subtree(
/// Replace references to a clipboard entity inside one recreated extension
/// dictionary graph after its final block-owned handle becomes known.
pub(crate) fn remap_ext_subtree_reference(
doc: &mut acadrust::CadDocument,
doc: &mut codec::CadDocument,
root: Handle,
source_entity: Handle,
target_entity: Handle,
) {
use acadrust::objects::ObjectType;
use codec::objects::ObjectType;
use rustc_hash::FxHashSet;
use std::collections::HashMap;
@@ -779,12 +779,12 @@ pub(crate) fn remap_ext_subtree_reference(
/// through `remap` (a handle still in the source space stays unchanged, which is
/// correct for cross-references that point outside the captured subtree).
pub(crate) fn remap_object(
obj: &mut acadrust::objects::ObjectType,
new_handle: acadrust::Handle,
remap: &std::collections::HashMap<acadrust::Handle, acadrust::Handle>,
obj: &mut codec::objects::ObjectType,
new_handle: codec::Handle,
remap: &std::collections::HashMap<codec::Handle, codec::Handle>,
) {
use acadrust::objects::ObjectType;
let map = |h: acadrust::Handle| remap.get(&h).copied().unwrap_or(h);
use codec::objects::ObjectType;
let map = |h: codec::Handle| remap.get(&h).copied().unwrap_or(h);
match obj {
ObjectType::Dictionary(d) => {
d.handle = new_handle;
@@ -819,7 +819,7 @@ pub(crate) fn remap_object(
x.handle = new_handle;
x.owner = map(x.owner);
for entry in &mut x.entries {
if let acadrust::objects::XRecordValue::Handle(handle) = &mut entry.value {
if let codec::objects::XRecordValue::Handle(handle) = &mut entry.value {
*handle = map(*handle);
}
}
@@ -842,13 +842,13 @@ pub(crate) fn remap_object(
}
context.scale = map(context.scale);
match &mut context.kind {
acadrust::objects::ObjectContextKind::Dim(dimension) => {
codec::objects::ObjectContextKind::Dim(dimension) => {
dimension.block = map(dimension.block);
}
acadrust::objects::ObjectContextKind::HatchView(hatch) => {
codec::objects::ObjectContextKind::HatchView(hatch) => {
hatch.view = map(hatch.view);
}
acadrust::objects::ObjectContextKind::MTextAttribute(attribute) => {
codec::objects::ObjectContextKind::MTextAttribute(attribute) => {
if let Some(embedded) = &mut attribute.context {
embedded.owner_handle = map(embedded.owner_handle);
for reactor in &mut embedded.reactors {
@@ -860,7 +860,7 @@ pub(crate) fn remap_object(
embedded.scale = map(embedded.scale);
}
}
acadrust::objects::ObjectContextKind::MLeader(mleader) => {
codec::objects::ObjectContextKind::MLeader(mleader) => {
if let Some(handle) = &mut mleader.text_style_handle {
*handle = map(*handle);
}
@@ -895,29 +895,29 @@ pub(crate) fn remap_object(
mod clipboard_xdict_clone_tests {
use super::recreate_ext_subtree;
use super::remap_object;
use acadrust::Handle;
use codec::Handle;
// Same re-export path `commands/blocks.rs:356` uses — this import proves
// the `mod.rs` re-export still covers external callers.
use super::super::remap_ext_subtree_reference;
use acadrust::objects::{ObjectType, XRecordValue};
use codec::objects::{ObjectType, XRecordValue};
/// A dictionary root pointing at one XRecord leaf that references the
/// source entity — the minimal shape of a captured XCLIP filter graph.
fn xdict_capture_fixture() -> crate::app::ClipExtObjects {
let mut src = acadrust::CadDocument::new();
let mut src = codec::CadDocument::new();
let src_entity = src.allocate_handle();
let src_root = src.allocate_handle();
let src_leaf = src.allocate_handle();
let mut dict = acadrust::objects::Dictionary::new();
let mut dict = codec::objects::Dictionary::new();
dict.handle = src_root;
dict.owner = src_entity;
dict.add_entry("XCLIP", src_leaf);
let mut xrec = acadrust::objects::XRecord::new();
let mut xrec = codec::objects::XRecord::new();
xrec.handle = src_leaf;
xrec.owner = src_root;
xrec.entries.push(acadrust::objects::XRecordEntry::new(
xrec.entries.push(codec::objects::XRecordEntry::new(
340,
XRecordValue::Handle(src_entity),
));
@@ -934,7 +934,7 @@ mod clipboard_xdict_clone_tests {
}
}
fn leaf_of(doc: &acadrust::CadDocument, root: Handle) -> Handle {
fn leaf_of(doc: &codec::CadDocument, root: Handle) -> Handle {
match doc.objects.get(&root) {
Some(ObjectType::Dictionary(d)) => {
assert_eq!(d.entries.len(), 1);
@@ -949,7 +949,7 @@ mod clipboard_xdict_clone_tests {
#[test]
fn cross_drawing_clone_remaps_xdict_handles() {
let cap = xdict_capture_fixture();
let mut dst = acadrust::CadDocument::new();
let mut dst = codec::CadDocument::new();
let before: Vec<Handle> = dst.objects.keys().copied().collect();
let dst_entity = dst.allocate_handle();
@@ -990,7 +990,7 @@ mod clipboard_xdict_clone_tests {
#[test]
fn cross_drawing_clone_two_phase_remap_resolves_reference() {
let cap = xdict_capture_fixture();
let mut dst = acadrust::CadDocument::new();
let mut dst = codec::CadDocument::new();
let before_len = dst.objects.len();
let root =
@@ -1021,7 +1021,7 @@ mod clipboard_xdict_clone_tests {
#[test]
fn remap_object_rewrites_dictionary_handles() {
use std::collections::HashMap;
let mut scratch = acadrust::CadDocument::new();
let mut scratch = codec::CadDocument::new();
let old_self = scratch.allocate_handle();
let old_owner = scratch.allocate_handle();
let old_child = scratch.allocate_handle();
@@ -1029,7 +1029,7 @@ mod clipboard_xdict_clone_tests {
let new_owner = scratch.allocate_handle();
let new_child = scratch.allocate_handle();
let mut dict = acadrust::objects::Dictionary::new();
let mut dict = codec::objects::Dictionary::new();
dict.handle = old_self;
dict.owner = old_owner;
dict.add_entry("K", old_child);
@@ -1051,17 +1051,17 @@ mod clipboard_xdict_clone_tests {
mod copy_to_clipboard_kernel_tests {
use super::copy_to_clipboard_kernel;
fn line_on(layer: &str) -> acadrust::EntityType {
let mut line = acadrust::entities::Line::new();
fn line_on(layer: &str) -> codec::EntityType {
let mut line = codec::entities::Line::new();
line.common.layer = layer.to_string();
acadrust::EntityType::Line(line)
codec::EntityType::Line(line)
}
#[test]
fn clones_entities_and_captures_layer_deps() {
let mut doc = acadrust::CadDocument::new();
let mut doc = codec::CadDocument::new();
doc.layers
.add(acadrust::tables::Layer::new("WALLS"))
.add(codec::tables::Layer::new("WALLS"))
.expect("add layer");
let a = doc.add_entity(line_on("WALLS")).unwrap();
let b = doc.add_entity(line_on("WALLS")).unwrap();
@@ -1078,7 +1078,7 @@ mod copy_to_clipboard_kernel_tests {
#[test]
fn skips_handles_missing_from_the_document() {
let mut doc = acadrust::CadDocument::new();
let mut doc = codec::CadDocument::new();
let kept = doc.add_entity(line_on("0")).unwrap();
let missing = doc.allocate_handle();
@@ -1090,7 +1090,7 @@ mod copy_to_clipboard_kernel_tests {
#[test]
fn empty_selection_yields_empty_payload() {
let doc = acadrust::CadDocument::new();
let doc = codec::CadDocument::new();
let (entities, deps) = copy_to_clipboard_kernel(&doc, &[]);
@@ -1103,32 +1103,32 @@ mod copy_to_clipboard_kernel_tests {
#[cfg(test)]
mod paste_entities_kernel_tests {
use super::{copy_to_clipboard_kernel, paste_entities_kernel};
use acadrust::Handle;
use codec::Handle;
fn line_on(layer: &str) -> acadrust::EntityType {
let mut line = acadrust::entities::Line::new();
fn line_on(layer: &str) -> codec::EntityType {
let mut line = codec::entities::Line::new();
line.common.layer = layer.to_string();
acadrust::EntityType::Line(line)
codec::EntityType::Line(line)
}
#[test]
fn pastes_with_fresh_handles_and_translate() {
let mut seed = acadrust::CadDocument::new();
let mut seed = codec::CadDocument::new();
seed.layers
.add(acadrust::tables::Layer::new("WALLS"))
.add(codec::tables::Layer::new("WALLS"))
.expect("add layer");
// Position the seed line away from the origin so the translate is visible.
let mut seed_line = acadrust::entities::Line::from_points(
acadrust::types::Vector3::new(0.0, 0.0, 0.0),
acadrust::types::Vector3::new(10.0, 0.0, 0.0),
let mut seed_line = codec::entities::Line::from_points(
codec::types::Vector3::new(0.0, 0.0, 0.0),
codec::types::Vector3::new(10.0, 0.0, 0.0),
);
seed_line.common.layer = "WALLS".to_string();
let seed_handle = seed
.add_entity(acadrust::EntityType::Line(seed_line))
.add_entity(codec::EntityType::Line(seed_line))
.unwrap();
let (entities, deps) = copy_to_clipboard_kernel(&seed, &[seed_handle]);
let mut dst = acadrust::CadDocument::new();
let mut dst = codec::CadDocument::new();
let delta = glam::DVec3::new(5.0, 7.0, 0.0);
let translate = crate::command::EntityTransform::Translate(delta);
let (handles, handle_map) =
@@ -1140,7 +1140,7 @@ mod paste_entities_kernel_tests {
assert_ne!(pasted, seed_handle, "paste must use a fresh handle");
assert_eq!(handle_map.get(&seed_handle), Some(&pasted));
let line = match dst.get_entity(pasted) {
Some(acadrust::EntityType::Line(l)) => l,
Some(codec::EntityType::Line(l)) => l,
other => panic!("expected pasted Line, got {other:?}"),
};
assert!((line.start.x - 5.0).abs() < 1e-9, "start.x = {}", line.start.x);
@@ -1153,23 +1153,23 @@ mod paste_entities_kernel_tests {
#[test]
fn remaps_leader_annotation_link_to_pasted_handles() {
let mut seed = acadrust::CadDocument::new();
let mut seed = codec::CadDocument::new();
let note = seed
.add_entity(acadrust::EntityType::MText(acadrust::entities::MText::new()))
.add_entity(codec::EntityType::MText(codec::entities::MText::new()))
.unwrap();
let mut leader = acadrust::entities::Leader::default();
let mut leader = codec::entities::Leader::default();
leader.annotation_handle = note;
let leader_handle = seed
.add_entity(acadrust::EntityType::Leader(leader))
.add_entity(codec::EntityType::Leader(leader))
.unwrap();
let (entities, deps) = copy_to_clipboard_kernel(&seed, &[leader_handle, note]);
let mut dst = acadrust::CadDocument::new();
let mut dst = codec::CadDocument::new();
let (handles, _) = paste_entities_kernel(&mut dst, &entities, &deps, None);
assert_eq!(handles.len(), 2);
let pasted_leader = match dst.get_entity(handles[0]) {
Some(acadrust::EntityType::Leader(l)) => l,
Some(codec::EntityType::Leader(l)) => l,
other => panic!("expected pasted Leader, got {other:?}"),
};
assert_eq!(
@@ -1182,8 +1182,8 @@ mod paste_entities_kernel_tests {
fn recreates_ext_subtree_and_repoints_xdictionary() {
// Minimal XCLIP-shaped capture: a dictionary root over one XRecord leaf
// that references the source entity (mirrors clipboard_xdict_clone_tests).
use acadrust::objects::{Dictionary, ObjectType, XRecord, XRecordEntry, XRecordValue};
let mut seed = acadrust::CadDocument::new();
use codec::objects::{Dictionary, ObjectType, XRecord, XRecordEntry, XRecordValue};
let mut seed = codec::CadDocument::new();
let seed_entity = seed.add_entity(line_on("0")).unwrap();
let src_root = seed.allocate_handle();
let src_leaf = seed.allocate_handle();
@@ -1206,7 +1206,7 @@ mod paste_entities_kernel_tests {
let (entities, deps) = copy_to_clipboard_kernel(&seed, &[seed_entity]);
assert_eq!(deps.ext_objects.len(), 1, "capture must snapshot the xdict");
let mut dst = acadrust::CadDocument::new();
let mut dst = codec::CadDocument::new();
let before: Vec<Handle> = dst.objects.keys().copied().collect();
let (handles, _) = paste_entities_kernel(&mut dst, &entities, &deps, None);
@@ -1243,7 +1243,7 @@ mod paste_entities_kernel_tests {
mod headless_reuse_proof_tests {
// Task 5 reuse proof — headless only. This module constructs NO
// `OpenCADStudio` value and touches no UI/scene state: only
// `acadrust::CadDocument`, entities, and the shared kernels
// `codec::CadDocument`, entities, and the shared kernels
// (`copy_to_clipboard_kernel`, `paste_entities_kernel`,
// `match_layer_kernel`, `match_properties_kernel` + `MatchOpts`).
use super::{copy_to_clipboard_kernel, paste_entities_kernel};
@@ -1252,25 +1252,25 @@ mod headless_reuse_proof_tests {
#[test]
fn headless_copy_paste_then_match_kernels_share_one_path() {
// Phase 1: copy in doc A, paste into doc B with a translate.
let mut doc_a = acadrust::CadDocument::new();
let mut doc_a = codec::CadDocument::new();
doc_a
.layers
.add(acadrust::tables::Layer::new("WALLS"))
.add(codec::tables::Layer::new("WALLS"))
.expect("add layer");
let mut seed_line = acadrust::entities::Line::from_points(
acadrust::types::Vector3::new(0.0, 0.0, 0.0),
acadrust::types::Vector3::new(10.0, 0.0, 0.0),
let mut seed_line = codec::entities::Line::from_points(
codec::types::Vector3::new(0.0, 0.0, 0.0),
codec::types::Vector3::new(10.0, 0.0, 0.0),
);
seed_line.common.layer = "WALLS".to_string();
let seed_handle = doc_a
.add_entity(acadrust::EntityType::Line(seed_line))
.add_entity(codec::EntityType::Line(seed_line))
.unwrap();
let (entities, deps) = copy_to_clipboard_kernel(&doc_a, &[seed_handle]);
assert_eq!(entities.len(), 1);
assert_eq!(entities[0].common().layer, "WALLS");
let mut doc_b = acadrust::CadDocument::new();
let mut doc_b = codec::CadDocument::new();
let translate =
crate::command::EntityTransform::Translate(glam::DVec3::new(5.0, 7.0, 0.0));
let (handles, handle_map) =
@@ -1283,7 +1283,7 @@ mod headless_reuse_proof_tests {
assert_eq!(handle_map.get(&seed_handle), Some(&pasted));
assert!(doc_b.layers.contains("WALLS"), "layer dep must follow");
match doc_b.get_entity(pasted) {
Some(acadrust::EntityType::Line(l)) => {
Some(codec::EntityType::Line(l)) => {
assert_eq!(l.common.layer, "WALLS");
assert!((l.start.x - 5.0).abs() < 1e-9, "start.x = {}", l.start.x);
assert!((l.start.y - 7.0).abs() < 1e-9, "start.y = {}", l.start.y);
@@ -1293,19 +1293,19 @@ mod headless_reuse_proof_tests {
}
// Phase 2: match kernels on a src/dst pair in the same headless doc.
let mut src_line = acadrust::entities::Line::new();
let mut src_line = codec::entities::Line::new();
src_line.common.layer = "WALLS".to_string();
src_line.common.linetype_scale = 2.5;
src_line.thickness = 1.25;
let src = doc_b
.add_entity(acadrust::EntityType::Line(src_line))
.add_entity(codec::EntityType::Line(src_line))
.unwrap();
let mut dst_line = acadrust::entities::Line::new();
let mut dst_line = codec::entities::Line::new();
dst_line.common.layer = "0".to_string();
dst_line.common.linetype_scale = 1.0;
dst_line.thickness = 0.0;
let dst = doc_b
.add_entity(acadrust::EntityType::Line(dst_line))
.add_entity(codec::EntityType::Line(dst_line))
.unwrap();
let count = match_layer_kernel(&mut doc_b, &[dst], src).expect("match layer");
@@ -1322,7 +1322,7 @@ mod headless_reuse_proof_tests {
match_properties_kernel(&src_clone, dst_entity, &MatchOpts::all());
}
match doc_b.get_entity(dst) {
Some(acadrust::EntityType::Line(l)) => {
Some(codec::EntityType::Line(l)) => {
assert_eq!(l.common.layer, "WALLS");
assert!((l.common.linetype_scale - 2.5).abs() < 1e-9);
assert!((l.thickness - 1.25).abs() < 1e-9);
+12 -12
View File
@@ -253,7 +253,7 @@ impl OpenCADStudio {
let resolved = {
let document = &self.tabs[i].scene.document;
let world =
acadrust::types::Vector3::new(pick.point.x, pick.point.y, pick.point.z);
codec::types::Vector3::new(pick.point.x, pick.point.y, pick.point.z);
let reference = match pick.handle {
Some(handle) => {
nearest_parametric_point_on_entity(document, scope, handle, world)
@@ -426,7 +426,7 @@ impl OpenCADStudio {
entity.as_entity_mut().set_layer(
crate::scene::parametric_constraints::DYNAMIC_DIMENSION_LAYER.to_string(),
);
entity.common_mut().color = acadrust::types::Color::Rgb {
entity.common_mut().color = codec::types::Color::Rgb {
r: 103,
g: 109,
b: 118,
@@ -614,7 +614,7 @@ impl OpenCADStudio {
entity.as_entity_mut().set_layer(
crate::scene::parametric_constraints::DYNAMIC_DIMENSION_LAYER.to_string(),
);
entity.common_mut().color = acadrust::types::Color::Rgb {
entity.common_mut().color = codec::types::Color::Rgb {
r: 103,
g: 109,
b: 118,
@@ -795,7 +795,7 @@ impl OpenCADStudio {
entity.as_entity_mut().set_layer(
crate::scene::parametric_constraints::DYNAMIC_DIMENSION_LAYER.to_string(),
);
entity.common_mut().color = acadrust::types::Color::Rgb {
entity.common_mut().color = codec::types::Color::Rgb {
r: 103,
g: 109,
b: 118,
@@ -1000,7 +1000,7 @@ impl OpenCADStudio {
let scope = self.tabs[i].current_parametric_scope();
let document = &self.tabs[i].scene.document;
let world =
acadrust::types::Vector3::new(pick.point.x, pick.point.y, pick.point.z);
codec::types::Vector3::new(pick.point.x, pick.point.y, pick.point.z);
let resolved = match (pick.whole_curve, pick.handle) {
(true, Some(handle)) => {
parametric_curve_ref_for_pick(document, scope, handle, world)
@@ -1059,7 +1059,7 @@ impl OpenCADStudio {
let found = nearest_parametric_point(
&self.tabs[i].scene.document,
scope,
acadrust::types::Vector3::new(pick.point.x, pick.point.y, pick.point.z),
codec::types::Vector3::new(pick.point.x, pick.point.y, pick.point.z),
None,
)
.is_some();
@@ -1097,7 +1097,7 @@ impl OpenCADStudio {
let axis = if vertical { "Vertical" } else { "Horizontal" };
let scope = self.tabs[i].current_parametric_scope();
let to_world = |point: glam::DVec3| {
acadrust::types::Vector3::new(point.x, point.y, point.z)
codec::types::Vector3::new(point.x, point.y, point.z)
};
let (refs, initial_fixed) = match selection {
HorizontalConstraintSelection::Reference(reference) => {
@@ -1175,7 +1175,7 @@ impl OpenCADStudio {
));
return Some(Task::none());
}
let direction = acadrust::types::Vector3::new(
let direction = codec::types::Vector3::new(
direction.x / axis_length,
direction.y / axis_length,
0.0,
@@ -1337,7 +1337,7 @@ impl OpenCADStudio {
let scope = self.tabs[i].current_parametric_scope();
let to_world = |point: glam::DVec3| {
acadrust::types::Vector3::new(point.x, point.y, point.z)
codec::types::Vector3::new(point.x, point.y, point.z)
};
let resolve_point = |pick: crate::command::CoincidentPick| {
if let Some(handle) = pick.handle {
@@ -1692,7 +1692,7 @@ impl OpenCADStudio {
unreachable!("router only routes the matching variant");
};
let scope = self.tabs[i].current_parametric_scope();
let to_world = |p: glam::DVec3| acadrust::types::Vector3::new(p.x, p.y, p.z);
let to_world = |p: glam::DVec3| codec::types::Vector3::new(p.x, p.y, p.z);
let resolve = |pick: crate::command::CoincidentPick,
exclude: Option<Handle>| {
if pick.whole_curve {
@@ -1877,7 +1877,7 @@ impl OpenCADStudio {
unreachable!("router only routes the matching variant");
};
let scope = self.tabs[i].current_parametric_scope();
let to_world = |p: glam::DVec3| acadrust::types::Vector3::new(p.x, p.y, p.z);
let to_world = |p: glam::DVec3| codec::types::Vector3::new(p.x, p.y, p.z);
let resolved = crate::scene::parametric_constraints::nearest_parametric_point(
&self.tabs[i].scene.document,
scope,
@@ -1922,7 +1922,7 @@ impl OpenCADStudio {
) -> Option<Task<Message>> {
let i = self.active_tab;
let scope = self.tabs[i].current_parametric_scope();
let to_world = |p: glam::DVec3| acadrust::types::Vector3::new(p.x, p.y, p.z);
let to_world = |p: glam::DVec3| codec::types::Vector3::new(p.x, p.y, p.z);
let mut refs = Vec::with_capacity(4);
for p in points {
let Some(r) = crate::scene::parametric_constraints::nearest_parametric_point(
+33 -33
View File
@@ -33,9 +33,9 @@ impl OpenCADStudio {
let i = self.active_tab;
let valid = matches!(
self.tabs[i].scene.document.get_entity(dimension),
Some(acadrust::EntityType::Dimension(
acadrust::entities::Dimension::Linear(_)
| acadrust::entities::Dimension::Aligned(_)
Some(codec::EntityType::Dimension(
codec::entities::Dimension::Linear(_)
| codec::entities::Dimension::Aligned(_)
))
);
if !valid {
@@ -45,12 +45,12 @@ impl OpenCADStudio {
} else if !self.reject_locked_edit(i, dimension) {
self.push_undo_snapshot(i, "DIMJOGLINE");
let values = point.map(|point| {
use acadrust::xdata::XDataValue;
use codec::xdata::XDataValue;
vec![
XDataValue::Integer16(387),
XDataValue::Integer16(3),
XDataValue::Integer16(389),
XDataValue::Point3D(acadrust::types::Vector3::new(
XDataValue::Point3D(codec::types::Vector3::new(
point.x, point.y, point.z,
)),
]
@@ -124,7 +124,7 @@ fn segment_intersection_xy(
first: (glam::DVec3, glam::DVec3),
second: (glam::DVec3, glam::DVec3),
) -> Option<(glam::DVec3, glam::DVec3)> {
let gap = cadkernel::space::segment_break_gap_xy(
let gap = kernel::space::segment_break_gap_xy(
[first.0.to_array(), first.1.to_array()],
[second.0.to_array(), second.1.to_array()],
0.25,
@@ -135,25 +135,25 @@ fn segment_intersection_xy(
))
}
fn break_object_handle(document: &acadrust::CadDocument, dimension: Handle) -> Option<Handle> {
fn break_object_handle(document: &codec::CadDocument, dimension: Handle) -> Option<Handle> {
document.objects.iter().find_map(|(handle, object)| {
let acadrust::objects::ObjectType::DataObject(object) = object else {
let codec::objects::ObjectType::DataObject(object) = object else {
return None;
};
let acadrust::objects::DataObjectData::BreakData(data) = &object.data else {
let codec::objects::DataObjectData::BreakData(data) = &object.data else {
return None;
};
(data.dimension_reference == dimension).then_some(*handle)
})
}
fn remove_dimension_break_data(document: &mut acadrust::CadDocument, dimension: Handle) -> bool {
fn remove_dimension_break_data(document: &mut codec::CadDocument, dimension: Handle) -> bool {
let handles: Vec<_> = document
.objects
.iter()
.filter_map(|(handle, object)| match object {
acadrust::objects::ObjectType::DataObject(object) => match &object.data {
acadrust::objects::DataObjectData::BreakData(data)
codec::objects::ObjectType::DataObject(object) => match &object.data {
codec::objects::DataObjectData::BreakData(data)
if data.dimension_reference == dimension =>
{
Some(*handle)
@@ -170,7 +170,7 @@ fn remove_dimension_break_data(document: &mut acadrust::CadDocument, dimension:
document.objects.remove(handle);
}
if let Some(dictionary_handle) = document.extension_dictionary_handle(dimension) {
if let Some(acadrust::objects::ObjectType::Dictionary(dictionary)) =
if let Some(codec::objects::ObjectType::Dictionary(dictionary)) =
document.objects.get_mut(&dictionary_handle)
{
dictionary.entries.retain(|(name, handle)| {
@@ -185,12 +185,12 @@ fn remove_dimension_break_data(document: &mut acadrust::CadDocument, dimension:
}
fn write_dimension_break_data(
document: &mut acadrust::CadDocument,
document: &mut codec::CadDocument,
dimension: Handle,
reserved_reference: Handle,
references: Vec<acadrust::objects::BreakPointReference>,
references: Vec<codec::objects::BreakPointReference>,
) -> bool {
use acadrust::objects::{BreakData, DataObject, DataObjectData, Dictionary, ObjectType};
use codec::objects::{BreakData, DataObject, DataObjectData, Dictionary, ObjectType};
if references.is_empty() {
return remove_dimension_break_data(document, dimension);
@@ -252,15 +252,15 @@ fn break_reference(
reference_type: i32,
first: glam::DVec3,
second: glam::DVec3,
) -> acadrust::objects::BreakPointReference {
acadrust::objects::BreakPointReference {
) -> codec::objects::BreakPointReference {
codec::objects::BreakPointReference {
version: 0,
reserved: 0,
reference_type,
flags: 0,
identifier,
first_point: acadrust::types::Vector3::new(first.x, first.y, first.z),
second_point: acadrust::types::Vector3::new(second.x, second.y, second.z),
first_point: codec::types::Vector3::new(first.x, first.y, first.z),
second_point: codec::types::Vector3::new(second.x, second.y, second.z),
trailing_version: 0,
}
}
@@ -278,7 +278,7 @@ fn apply_dimbreak(
.filter(|handle| {
matches!(
scene.document.get_entity(*handle),
Some(acadrust::EntityType::Dimension(_))
Some(codec::EntityType::Dimension(_))
) && scene.locked_layer_name(*handle).is_none()
})
.collect();
@@ -326,8 +326,8 @@ fn apply_dimbreak(
let existing: Vec<_> = break_object_handle(&scene.document, *dimension)
.and_then(|handle| scene.document.objects.get(&handle))
.and_then(|object| match object {
acadrust::objects::ObjectType::DataObject(object) => match &object.data {
acadrust::objects::DataObjectData::BreakData(data) => {
codec::objects::ObjectType::DataObject(object) => match &object.data {
codec::objects::DataObjectData::BreakData(data) => {
Some(data.point_references.clone())
}
_ => None,
@@ -408,9 +408,9 @@ fn apply_dimspace(
others: &[Handle],
requested_spacing: Option<f64>,
) -> bool {
use acadrust::entities::Dimension;
use codec::entities::Dimension;
let (axis, normal, definition, auto_spacing) = match scene.document.get_entity(base_h) {
Some(acadrust::EntityType::Dimension(dimension @ Dimension::Linear(d))) => {
Some(codec::EntityType::Dimension(dimension @ Dimension::Linear(d))) => {
let spacing = dimension_auto_spacing(
&scene.document,
dimension,
@@ -427,7 +427,7 @@ fn apply_dimspace(
spacing,
)
}
Some(acadrust::EntityType::Dimension(dimension @ Dimension::Aligned(d))) => {
Some(codec::EntityType::Dimension(dimension @ Dimension::Aligned(d))) => {
let spacing = dimension_auto_spacing(
&scene.document,
dimension,
@@ -450,7 +450,7 @@ fn apply_dimspace(
}
_ => return false,
};
let Some(frame) = cadkernel::space::dimension_spacing_frame(axis, normal, definition) else {
let Some(frame) = kernel::space::dimension_spacing_frame(axis, normal, definition) else {
return false;
};
@@ -459,11 +459,11 @@ fn apply_dimspace(
for (idx, &h) in others.iter().enumerate() {
let target = frame.coordinate + effective_spacing * (idx + 1) as f64;
let mut changed = false;
if let Some(acadrust::EntityType::Dimension(dim)) = scene.document.get_entity_mut(h) {
let slide = |p: &mut acadrust::types::Vector3| {
if let Some(codec::EntityType::Dimension(dim)) = scene.document.get_entity_mut(h) {
let slide = |p: &mut codec::types::Vector3| {
let point =
cadkernel::space::move_to_dimension_spacing([p.x, p.y, p.z], frame, target);
*p = acadrust::types::Vector3::new(point[0], point[1], point[2]);
kernel::space::move_to_dimension_spacing([p.x, p.y, p.z], frame, target);
*p = codec::types::Vector3::new(point[0], point[1], point[2]);
};
match dim {
Dimension::Linear(d) => {
@@ -493,8 +493,8 @@ fn apply_dimspace(
}
fn dimension_auto_spacing(
document: &acadrust::CadDocument,
dimension: &acadrust::entities::Dimension,
document: &codec::CadDocument,
dimension: &codec::entities::Dimension,
annotation_multiplier: f64,
) -> f64 {
let style = document
+42 -42
View File
@@ -3,7 +3,7 @@ use super::*;
impl OpenCADStudio {
pub(super) fn handle_commit_entity(
&mut self,
entity: acadrust::EntityType,
entity: codec::EntityType,
preserve_commit_layer: bool,
) -> Option<Task<Message>> {
let i = self.active_tab;
@@ -25,10 +25,10 @@ impl OpenCADStudio {
// leave the anchor untouched. (#327)
if matches!(
entity,
acadrust::EntityType::Line(_)
| acadrust::EntityType::Arc(_)
| acadrust::EntityType::LwPolyline(_)
| acadrust::EntityType::Polyline2D(_)
codec::EntityType::Line(_)
| codec::EntityType::Arc(_)
| codec::EntityType::LwPolyline(_)
| codec::EntityType::Polyline2D(_)
) {
self.update_cont_anchor(&entity);
}
@@ -40,9 +40,9 @@ impl OpenCADStudio {
let pending = self.begin_undo(i, label, 1, delta_safe);
let is_associative_dimension = matches!(
entity,
acadrust::EntityType::Dimension(
acadrust::entities::Dimension::Linear(_)
| acadrust::entities::Dimension::Aligned(_)
codec::EntityType::Dimension(
codec::entities::Dimension::Linear(_)
| codec::entities::Dimension::Aligned(_)
)
);
let association_enabled =
@@ -76,7 +76,7 @@ impl OpenCADStudio {
pub(super) fn handle_commit_entities(
&mut self,
mut entities: Vec<acadrust::EntityType>,
mut entities: Vec<codec::EntityType>,
preserve_commit_style: bool,
preserve_commit_layer: bool,
) -> Option<Task<Message>> {
@@ -137,7 +137,7 @@ impl OpenCADStudio {
pub(super) fn handle_commit_entities_and_exit(
&mut self,
mut entities: Vec<acadrust::EntityType>,
mut entities: Vec<codec::EntityType>,
preserve_commit_style: bool,
preserve_commit_layer: bool,
) {
@@ -185,7 +185,7 @@ impl OpenCADStudio {
pub(super) fn handle_commit_and_exit(
&mut self,
entity: acadrust::EntityType,
entity: codec::EntityType,
) -> Option<Task<Message>> {
let i = self.active_tab;
// XATTACH: the definition and its INSERT are created together
@@ -200,7 +200,7 @@ impl OpenCADStudio {
return Some(Task::none());
}
let insert_block_name = match &entity {
acadrust::EntityType::Insert(ins) => Some(ins.block_name.clone()),
codec::EntityType::Insert(ins) => Some(ins.block_name.clone()),
_ => None,
};
// Record where this draw ended so ARC_CONT can continue from it
@@ -211,9 +211,9 @@ impl OpenCADStudio {
let pending = self.begin_undo(i, label, 1, delta_safe);
let is_associative_dimension = matches!(
entity,
acadrust::EntityType::Dimension(
acadrust::entities::Dimension::Linear(_)
| acadrust::entities::Dimension::Aligned(_)
codec::EntityType::Dimension(
codec::entities::Dimension::Linear(_)
| codec::entities::Dimension::Aligned(_)
)
);
let association_enabled =
@@ -259,7 +259,7 @@ impl OpenCADStudio {
let association_mode = self.tabs[i].scene.document.header.dimension_associativity;
let single_source_dimension = matches!(
&entity,
acadrust::EntityType::Dimension(acadrust::entities::Dimension::Ordinate(_))
codec::EntityType::Dimension(codec::entities::Dimension::Ordinate(_))
);
// A dimension placed on the sheet but measuring model geometry
// through a viewport carries the compensation as a negative
@@ -277,7 +277,7 @@ impl OpenCADStudio {
let association_allowed = self.dimension_association_allowed(i);
let inherited_dimension = if preserve_base_style {
match &entity {
acadrust::EntityType::Dimension(dimension) => Some((
codec::EntityType::Dimension(dimension) => Some((
dimension.base().common.layer.clone(),
dimension.base().style_name.clone(),
)),
@@ -316,7 +316,7 @@ impl OpenCADStudio {
&self.tabs[i].scene.document,
&mut entity,
);
if let (Some((layer, style_name)), acadrust::EntityType::Dimension(dimension)) =
if let (Some((layer, style_name)), codec::EntityType::Dimension(dimension)) =
(inherited_dimension, &mut entity)
{
dimension.base_mut().common.layer = layer;
@@ -399,7 +399,7 @@ impl OpenCADStudio {
pub(super) fn handle_commit_dimensions_and_exit(
&mut self,
dimensions: Vec<(
acadrust::EntityType,
codec::EntityType,
crate::command::DimensionAssociationInput,
)>,
) {
@@ -557,12 +557,12 @@ impl OpenCADStudio {
pub(super) fn handle_commit_and_edit_text(
&mut self,
entity: acadrust::EntityType,
entity: codec::EntityType,
) -> Option<Task<Message>> {
let i = self.active_tab;
let annotative_mleader = matches!(
&entity,
acadrust::EntityType::MultiLeader(ml) if ml.enable_annotation_scale
codec::EntityType::MultiLeader(ml) if ml.enable_annotation_scale
);
let label = self.history_label_from_active_cmd(i, "ENTITY");
let delta_safe = self.delta_add_safe(i, &entity) && !annotative_mleader;
@@ -600,7 +600,7 @@ impl OpenCADStudio {
pub(super) fn handle_commit_many_and_edit_text(
&mut self,
entities: Vec<acadrust::EntityType>,
entities: Vec<codec::EntityType>,
edit_index: usize,
open_editor: bool,
) -> Option<Task<Message>> {
@@ -611,7 +611,7 @@ impl OpenCADStudio {
let mut edit_handle = None;
let mut leader_handle = None;
for (idx, entity) in entities.into_iter().enumerate() {
let is_leader = matches!(entity, acadrust::EntityType::Leader(_));
let is_leader = matches!(entity, codec::EntityType::Leader(_));
let h = self.commit_entity_handle(entity);
if idx == edit_index {
edit_handle = h;
@@ -623,7 +623,7 @@ impl OpenCADStudio {
// Link the leader to its annotation so the pair edits as a unit
// (double-click on the leader resolves to the text entity).
if let (Some(lh), Some(ah)) = (leader_handle, edit_handle) {
let linked = if let Some(acadrust::EntityType::Leader(l)) =
let linked = if let Some(codec::EntityType::Leader(l)) =
self.tabs[i].scene.document.get_entity_mut(lh)
{
l.annotation_handle = ah;
@@ -767,8 +767,8 @@ impl OpenCADStudio {
pub(super) fn handle_commit_styled_hatch(
&mut self,
hatch: crate::scene::HatchModel,
color: acadrust::types::Color,
transparency: acadrust::types::Transparency,
color: codec::types::Color,
transparency: codec::types::Transparency,
) {
let i = self.active_tab;
let label = self.history_label_from_active_cmd(i, "HATCH");
@@ -795,8 +795,8 @@ impl OpenCADStudio {
pub(super) fn handle_commit_hatch_with_boundaries(
&mut self,
mut hatch: crate::scene::HatchModel,
boundaries: Vec<acadrust::EntityType>,
entity_style: Option<(acadrust::types::Color, acadrust::types::Transparency)>,
boundaries: Vec<codec::EntityType>,
entity_style: Option<(codec::types::Color, codec::types::Transparency)>,
) {
let i = self.active_tab;
let label = self.history_label_from_active_cmd(i, "HATCH");
@@ -838,7 +838,7 @@ impl OpenCADStudio {
pub(super) fn handle_commit_hatches(
&mut self,
hatches: Vec<crate::scene::HatchModel>,
entity_style: Option<(acadrust::types::Color, acadrust::types::Transparency)>,
entity_style: Option<(codec::types::Color, codec::types::Transparency)>,
) {
let i = self.active_tab;
let label = self.history_label_from_active_cmd(i, "HATCH");
@@ -867,7 +867,7 @@ impl OpenCADStudio {
pub(super) fn handle_update_entity_and_finish(
&mut self,
handle: Handle,
entity: acadrust::EntityType,
entity: codec::EntityType,
) -> Option<Task<Message>> {
let i = self.active_tab;
if self.reject_locked_edit(i, handle) {
@@ -876,7 +876,7 @@ impl OpenCADStudio {
}
let label = self.history_label_from_active_cmd(i, "EDIT");
self.push_undo_snapshot(i, label);
let is_dimension = matches!(entity, acadrust::EntityType::Dimension(_));
let is_dimension = matches!(entity, codec::EntityType::Dimension(_));
if let Some(current) = self.tabs[i].scene.document.get_entity_mut(handle) {
*current = entity;
if is_dimension {
@@ -934,13 +934,13 @@ impl OpenCADStudio {
let i = self.active_tab;
// Collect the full AttributeDefinitions owned by this block
// record so each created attribute keeps its geometry (#255).
let attdefs: Vec<acadrust::entities::AttributeDefinition> = {
let attdefs: Vec<codec::entities::AttributeDefinition> = {
let doc = &self.tabs[i].scene.document;
if let Some(br) = doc.block_records.get(&block_name) {
br.entity_handles
.iter()
.filter_map(|&h| {
if let Some(acadrust::EntityType::AttributeDefinition(ad)) =
if let Some(codec::EntityType::AttributeDefinition(ad)) =
doc.get_entity(h)
{
Some(ad.clone())
@@ -962,7 +962,7 @@ impl OpenCADStudio {
.and_then(|c| c.attreq_take_insert());
if let Some(entity) = entity {
let insert_name = match &entity {
acadrust::EntityType::Insert(ins) => Some(ins.block_name.clone()),
codec::EntityType::Insert(ins) => Some(ins.block_name.clone()),
_ => None,
};
let label = self.history_label_from_active_cmd(i, "INSERT");
@@ -997,7 +997,7 @@ impl OpenCADStudio {
None
}
pub(super) fn handle_commit_live_entity(&mut self, entity: acadrust::EntityType) {
pub(super) fn handle_commit_live_entity(&mut self, entity: codec::EntityType) {
let i = self.active_tab;
let label = self.history_label_from_active_cmd(i, "ENTITY");
let delta_safe = self.delta_add_safe(i, &entity);
@@ -1026,18 +1026,18 @@ impl OpenCADStudio {
pub(super) fn handle_update_live_entity(
&mut self,
handle: Handle,
entity: acadrust::EntityType,
entity: codec::EntityType,
finish: bool,
) {
let i = self.active_tab;
let tracks_draw_anchor = matches!(
&entity,
acadrust::EntityType::Line(_)
| acadrust::EntityType::Arc(_)
| acadrust::EntityType::LwPolyline(_)
| acadrust::EntityType::Polyline(_)
| acadrust::EntityType::Polyline2D(_)
| acadrust::EntityType::Polyline3D(_)
codec::EntityType::Line(_)
| codec::EntityType::Arc(_)
| codec::EntityType::LwPolyline(_)
| codec::EntityType::Polyline(_)
| codec::EntityType::Polyline2D(_)
| codec::EntityType::Polyline3D(_)
);
// Replace the live entity's geometry in place, preserving its
// handle and layer (the fresh entity from the command carries
+34 -34
View File
@@ -77,7 +77,7 @@
use super::{Message, OpenCADStudio};
use crate::command::{CmdResult, SelectionEntity, StepInput};
use acadrust::Handle;
use codec::Handle;
use iced::Task;
mod utilities;
@@ -149,7 +149,7 @@ impl OpenCADStudio {
if let Some((scale, justification, style_name, style_handle)) = mline_settings {
let tab = &mut self.tabs[self.active_tab];
let header = &mut tab.scene.document.header;
let style_handle = style_handle.unwrap_or(acadrust::Handle::NULL);
let style_handle = style_handle.unwrap_or(codec::Handle::NULL);
let changed = (header.multiline_scale - scale).abs() > f64::EPSILON
|| header.multiline_justification != justification
|| !header.multiline_style.eq_ignore_ascii_case(&style_name)
@@ -220,17 +220,17 @@ impl OpenCADStudio {
pub(crate) fn begin_table_cell_edit(
&mut self,
i: usize,
handle: acadrust::Handle,
handle: codec::Handle,
click: glam::DVec3,
) -> crate::modules::annotate::table_cmd::TableCellEditStart {
use crate::modules::annotate::table_cmd::{table_cell_at, TableCellEditStart};
let target = if handle != acadrust::Handle::NULL {
let target = if handle != codec::Handle::NULL {
self.tabs[i]
.scene
.document
.get_entity(handle)
.and_then(|entity| match entity {
acadrust::EntityType::Table(table) => Some((handle, table.clone())),
codec::EntityType::Table(table) => Some((handle, table.clone())),
_ => None,
})
} else {
@@ -239,7 +239,7 @@ impl OpenCADStudio {
// taking the last match selects the table on top if they overlap.
let mut matched = None;
for entity in self.tabs[i].scene.document.entities() {
if let acadrust::EntityType::Table(table) = entity {
if let codec::EntityType::Table(table) = entity {
let h = table.common.handle;
let style = table.table_style_handle.and_then(|style_handle| {
self.tabs[i]
@@ -248,7 +248,7 @@ impl OpenCADStudio {
.objects
.get(&style_handle)
.and_then(|object| match object {
acadrust::objects::ObjectType::TableStyle(style) => Some(style),
codec::objects::ObjectType::TableStyle(style) => Some(style),
_ => None,
})
});
@@ -269,7 +269,7 @@ impl OpenCADStudio {
.objects
.get(&style_handle)
.and_then(|object| match object {
acadrust::objects::ObjectType::TableStyle(style) => Some(style),
codec::objects::ObjectType::TableStyle(style) => Some(style),
_ => None,
})
});
@@ -353,7 +353,7 @@ impl OpenCADStudio {
&mut self,
tab: usize,
handle: Handle,
mut entities: Vec<acadrust::EntityType>,
mut entities: Vec<codec::EntityType>,
) -> Vec<Handle> {
let same_type = entities.len() == 1
&& self.tabs[tab]
@@ -394,7 +394,7 @@ impl OpenCADStudio {
for &updated in &handles {
if matches!(
self.tabs[tab].scene.document.get_entity(updated),
Some(acadrust::EntityType::Dimension(_))
Some(codec::EntityType::Dimension(_))
) {
self.tabs[tab].scene.invalidate_dim_block_recorded(updated);
}
@@ -1350,10 +1350,10 @@ impl OpenCADStudio {
self.tabs[i].scene.clear_preview_wire();
self.restore_pre_cmd_tangent();
if handle == acadrust::Handle::NULL && self.selection_cycling {
if handle == codec::Handle::NULL && self.selection_cycling {
let mut candidates = Vec::new();
for entity in self.tabs[i].scene.document.entities() {
if let acadrust::EntityType::Table(table) = entity {
if let codec::EntityType::Table(table) = entity {
let h = table.common.handle;
let style = table.table_style_handle.and_then(|style_handle| {
self.tabs[i]
@@ -1362,7 +1362,7 @@ impl OpenCADStudio {
.objects
.get(&style_handle)
.and_then(|object| match object {
acadrust::objects::ObjectType::TableStyle(style) => Some(style),
codec::objects::ObjectType::TableStyle(style) => Some(style),
_ => None,
})
});
@@ -1418,7 +1418,7 @@ impl OpenCADStudio {
!self.tabs[i].scene.is_layer_locked(*handle)
&& matches!(
self.tabs[i].scene.document.get_entity(*handle),
Some(acadrust::EntityType::MultiLeader(_))
Some(codec::EntityType::MultiLeader(_))
)
});
if !handles.is_empty() {
@@ -1473,7 +1473,7 @@ impl OpenCADStudio {
/// handle from the target document so it can't collide with an existing
/// one. No-op for same-document pastes (the records already exist). (#129)
pub(super) fn merge_dependencies(&mut self, i: usize, deps: &crate::app::ClipboardDeps) {
use acadrust::TableEntry;
use codec::TableEntry;
if deps.is_empty() {
return;
}
@@ -1538,7 +1538,7 @@ impl OpenCADStudio {
/// the nearest planar curve of the edited space within a small share of
/// that space's extent, the way a pick box takes the object under a click.
fn entity_at_typed_point(
document: &acadrust::CadDocument,
document: &codec::CadDocument,
owner: Handle,
point: glam::DVec3,
) -> Option<Handle> {
@@ -1559,9 +1559,9 @@ fn entity_at_typed_point(
// inside it picks it.
None if matches!(
entity,
acadrust::EntityType::Text(_)
| acadrust::EntityType::MText(_)
| acadrust::EntityType::Ellipse(_)
codec::EntityType::Text(_)
| codec::EntityType::MText(_)
| codec::EntityType::Ellipse(_)
) =>
{
let dx = (bounds.min.x - point.x).max(point.x - bounds.max.x).max(0.0);
@@ -1586,11 +1586,11 @@ fn entity_at_typed_point(
fn apply_mleader_align(
scene: &mut crate::scene::Scene,
handles: &[acadrust::Handle],
handles: &[codec::Handle],
from: glam::DVec3,
to: glam::DVec3,
) -> bool {
use cadkernel::geom2d::{closest_point, Curve, Vec2, XLine};
use kernel::geom2d::{closest_point, Curve, Vec2, XLine};
let Some(direction) = Vec2::new(to.x - from.x, to.y - from.y).normalize() else {
return false;
@@ -1601,7 +1601,7 @@ fn apply_mleader_align(
});
let mut changed = Vec::new();
for &handle in handles {
if let Some(acadrust::EntityType::MultiLeader(ml)) = scene.document.get_entity_mut(handle) {
if let Some(codec::EntityType::MultiLeader(ml)) = scene.document.get_entity_mut(handle) {
let old = ml.context.content_base_point;
let projected = closest_point(&line, [old.x, old.y]).point;
let new_x = projected[0];
@@ -1632,16 +1632,16 @@ fn apply_mleader_align(
fn compatible_mleader_collect_handles(
scene: &crate::scene::Scene,
handles: &[acadrust::Handle],
) -> Vec<acadrust::Handle> {
handles: &[codec::Handle],
) -> Vec<codec::Handle> {
let Some((base_block, base_style)) = handles.iter().find_map(|handle| {
if scene.is_layer_locked(*handle) {
return None;
}
let acadrust::EntityType::MultiLeader(leader) = scene.document.get_entity(*handle)? else {
let codec::EntityType::MultiLeader(leader) = scene.document.get_entity(*handle)? else {
return None;
};
(leader.content_type == acadrust::entities::LeaderContentType::Block)
(leader.content_type == codec::entities::LeaderContentType::Block)
.then_some((leader.block_content_handle, leader.style_handle))
}) else {
return Vec::new();
@@ -1654,8 +1654,8 @@ fn compatible_mleader_collect_handles(
if !scene.is_layer_locked(handle)
&& matches!(
scene.document.get_entity(handle),
Some(acadrust::EntityType::MultiLeader(leader))
if leader.content_type == acadrust::entities::LeaderContentType::Block
Some(codec::EntityType::MultiLeader(leader))
if leader.content_type == codec::entities::LeaderContentType::Block
&& leader.block_content_handle == base_block
&& leader.style_handle == base_style
)
@@ -1668,7 +1668,7 @@ fn compatible_mleader_collect_handles(
fn apply_mleader_collect(
scene: &mut crate::scene::Scene,
handles: &[acadrust::Handle],
handles: &[codec::Handle],
point: glam::DVec3,
) -> bool {
if handles.len() < 2 {
@@ -1676,18 +1676,18 @@ fn apply_mleader_collect(
}
let px = point.x;
let py = point.y;
let Some(acadrust::EntityType::MultiLeader(base)) = scene.document.get_entity(handles[0])
let Some(codec::EntityType::MultiLeader(base)) = scene.document.get_entity(handles[0])
else {
return false;
};
let base_block = base.block_content_handle;
let base_style = base.style_handle;
let mut extra_roots: Vec<acadrust::entities::LeaderRoot> = Vec::new();
let mut extra_roots: Vec<codec::entities::LeaderRoot> = Vec::new();
let mut merged_handles = Vec::new();
for &h in &handles[1..] {
if let Some(acadrust::EntityType::MultiLeader(ml)) = scene.document.get_entity(h) {
if ml.content_type == acadrust::entities::LeaderContentType::Block
if let Some(codec::EntityType::MultiLeader(ml)) = scene.document.get_entity(h) {
if ml.content_type == codec::entities::LeaderContentType::Block
&& ml.block_content_handle == base_block
&& ml.style_handle == base_style
{
@@ -1706,7 +1706,7 @@ fn apply_mleader_collect(
return false;
}
if let Some(acadrust::EntityType::MultiLeader(ml)) = scene.document.get_entity_mut(handles[0]) {
if let Some(codec::EntityType::MultiLeader(ml)) = scene.document.get_entity_mut(handles[0]) {
let shift_x = px - ml.context.content_base_point.x;
let shift_y = py - ml.context.content_base_point.y;
for root in &mut ml.context.leader_roots {
+14 -14
View File
@@ -300,21 +300,21 @@ impl OpenCADStudio {
}
if !matches!(
self.tabs[i].scene.document.get_entity(handle),
Some(acadrust::EntityType::Hatch(_))
Some(codec::EntityType::Hatch(_))
) {
self.command_line
.push_error(crate::t!("HATCHEDIT: hatch entity not found.").as_ref());
} else {
use crate::command::{CadCommand, HatchEditOperation};
if matches!(&operation, HatchEditOperation::BeginAssociate) {
let associative = matches!(self.tabs[i].scene.document.get_entity(handle),Some(acadrust::EntityType::Hatch(h)) if h.is_associative);
let associative = matches!(self.tabs[i].scene.document.get_entity(handle),Some(codec::EntityType::Hatch(h)) if h.is_associative);
if associative {
self.command_line
.push_info("HATCHEDIT: hatch is already associative.");
self.tabs[i].active_cmd = None;
} else {
let plane = match self.tabs[i].scene.document.get_entity(handle) {
Some(acadrust::EntityType::Hatch(h)) => {
Some(codec::EntityType::Hatch(h)) => {
let storage =
crate::entities::curve::ocs_plane(h.normal, h.elevation);
crate::command::WorkingPlane::new(
@@ -338,7 +338,7 @@ impl OpenCADStudio {
if let HatchEditOperation::DrawOrderBoundary { above } = &operation {
let references: Vec<_> =
match self.tabs[i].scene.document.get_entity(handle) {
Some(acadrust::EntityType::Hatch(h)) => h
Some(codec::EntityType::Hatch(h)) => h
.paths
.iter()
.flat_map(|p| p.boundary_handles.iter())
@@ -436,7 +436,7 @@ impl OpenCADStudio {
}
}
}
if let Some(acadrust::EntityType::Hatch(hatch)) =
if let Some(codec::EntityType::Hatch(hatch)) =
self.tabs[i].scene.document.get_entity_mut(handle)
{
if !name.is_empty() && name != hatch.pattern.name {
@@ -467,7 +467,7 @@ impl OpenCADStudio {
crate::scene::model::hatch_model::HatchPattern::Solid
);
hatch.pattern_type =
acadrust::entities::HatchPatternType::Predefined;
codec::entities::HatchPatternType::Predefined;
hatch.gradient_color.enabled = false;
}
} else {
@@ -483,7 +483,7 @@ impl OpenCADStudio {
hatch.pattern_scale = scale.max(1.0e-6) as f64;
hatch.pattern_angle = (angle as f64).to_radians();
if let Some((x, y)) = origin {
hatch.set_pattern_origin(acadrust::types::Vector2::new(x, y));
hatch.set_pattern_origin(codec::types::Vector2::new(x, y));
}
if disassociate {
for path in &mut hatch.paths {
@@ -551,7 +551,7 @@ impl OpenCADStudio {
}
HatchEditOperation::RecreateBoundary { associate, region } => {
let source = self.tabs[i].scene.document.get_entity(handle).cloned();
if let Some(acadrust::EntityType::Hatch(source)) = source {
if let Some(codec::EntityType::Hatch(source)) = source {
let storage = crate::entities::curve::ocs_plane(
source.normal,
source.elevation,
@@ -592,10 +592,10 @@ impl OpenCADStudio {
.enumerate()
.map(|(outer, boundary)| {
inner != outer
&& cadkernel::geom2d::contains(
&& kernel::geom2d::contains(
boundary,
seed,
cadkernel::geom2d::Tolerance::new(1e-6),
kernel::geom2d::Tolerance::new(1e-6),
)
})
.collect::<Vec<_>>()
@@ -670,7 +670,7 @@ impl OpenCADStudio {
}
}
if associate {
if let Some(acadrust::EntityType::Hatch(hatch)) =
if let Some(codec::EntityType::Hatch(hatch)) =
self.tabs[i].scene.document.get_entity_mut(handle)
{
for (path, boundary) in
@@ -692,12 +692,12 @@ impl OpenCADStudio {
}
HatchEditOperation::Separate => {
let source = self.tabs[i].scene.document.get_entity(handle).cloned();
if let Some(acadrust::EntityType::Hatch(hatch)) = source {
if let Some(codec::EntityType::Hatch(hatch)) = source {
let groups = crate::scene::separated_hatch_path_groups(&hatch);
if groups.len() > 1 {
for paths in groups {
let mut separated = hatch.clone();
separated.common.handle = acadrust::Handle::NULL;
separated.common.handle = codec::Handle::NULL;
separated.paths = paths;
separated.is_associative = separated
.paths
@@ -705,7 +705,7 @@ impl OpenCADStudio {
.any(|path| !path.boundary_handles.is_empty());
self.tabs[i]
.scene
.add_entity(acadrust::EntityType::Hatch(separated));
.add_entity(codec::EntityType::Hatch(separated));
}
self.tabs[i].scene.erase_entities(&[handle]);
}
+4 -4
View File
@@ -725,7 +725,7 @@ impl OpenCADStudio {
};
if annotational {
entity.as_entity_mut().set_layer(active_layer.clone());
entity.common_mut().color = acadrust::types::Color::ByLayer;
entity.common_mut().color = codec::types::Color::ByLayer;
// The dynamic form's screen-size and horizontal-text
// overrides go; the style draws it.
for code in [
@@ -744,7 +744,7 @@ impl OpenCADStudio {
entity
.as_entity_mut()
.set_layer(DYNAMIC_DIMENSION_LAYER.to_string());
entity.common_mut().color = acadrust::types::Color::Rgb {
entity.common_mut().color = codec::types::Color::Rgb {
r: 103,
g: 109,
b: 118,
@@ -899,7 +899,7 @@ impl OpenCADStudio {
Task::none()
}
pub(super) fn apply_continuous_constraints(&mut self, i: usize, new_handles: &[acadrust::Handle]) {
pub(super) fn apply_continuous_constraints(&mut self, i: usize, new_handles: &[codec::Handle]) {
let supported_creation = self.tabs[i]
.active_cmd
.as_ref()
@@ -924,7 +924,7 @@ impl OpenCADStudio {
pub(in crate::app) fn apply_inferred_constraints(
&mut self,
i: usize,
changed_handles: &[acadrust::Handle],
changed_handles: &[codec::Handle],
) {
if !self.constraint_infer || changed_handles.is_empty() {
return;
+8 -8
View File
@@ -58,9 +58,9 @@ impl OpenCADStudio {
// This application record is the hatch background colour.
// Keep the outer Option to distinguish "source is not a
// hatch" from "source hatch has no background".
let hatch_background_xdata: Option<Option<Vec<acadrust::xdata::XDataValue>>> =
let hatch_background_xdata: Option<Option<Vec<codec::xdata::XDataValue>>> =
match src_clone.as_ref() {
Some(acadrust::EntityType::Hatch(h)) => Some(
Some(codec::EntityType::Hatch(h)) => Some(
h.common
.extended_data
.get_record("HATCHBACKGROUNDCOLOR")
@@ -71,12 +71,12 @@ impl OpenCADStudio {
// Dimension-style overrides ride the ACAD record, identified
// by a leading DSTYLE string. Matching replicates that payload
// (or clears the destination when the source has none).
let dstyle_xdata: Option<Vec<(i16, acadrust::xdata::XDataValue)>> = src_clone
let dstyle_xdata: Option<Vec<(i16, codec::xdata::XDataValue)>> = src_clone
.as_ref()
.filter(|e| {
matches!(
e,
acadrust::EntityType::Dimension(_) | acadrust::EntityType::Leader(_)
codec::EntityType::Dimension(_) | codec::EntityType::Leader(_)
)
})
.map(|e| crate::entities::dim_override::pairs(&e.common().extended_data));
@@ -93,8 +93,8 @@ impl OpenCADStudio {
let mut is_hatch = false;
if let Some(se) = &src_clone {
if let Some(e) = app.tabs[i].scene.document.get_entity_mut(handle) {
is_dim = matches!(e, acadrust::EntityType::Dimension(_));
is_hatch = matches!(e, acadrust::EntityType::Hatch(_));
is_dim = matches!(e, codec::EntityType::Dimension(_));
is_hatch = matches!(e, codec::EntityType::Hatch(_));
crate::entities::match_props::match_properties_kernel(se, e, &match_opts);
}
}
@@ -117,11 +117,11 @@ impl OpenCADStudio {
if match_opts.copy_dim_overrides
&& matches!(
app.tabs[i].scene.document.get_entity(handle),
Some(acadrust::EntityType::Dimension(_) | acadrust::EntityType::Leader(_))
Some(codec::EntityType::Dimension(_) | codec::EntityType::Leader(_))
)
&& matches!(
src_clone,
Some(acadrust::EntityType::Dimension(_) | acadrust::EntityType::Leader(_))
Some(codec::EntityType::Dimension(_) | codec::EntityType::Leader(_))
)
{
crate::entities::dim_override::replace(
+15 -15
View File
@@ -115,8 +115,8 @@ impl OpenCADStudio {
.flatten();
let mut surface = empty_extruded_surface(direction, taper_angle);
if let (
Some(acadrust::objects::SolidHistoryOperation::Extrusion(value)),
acadrust::EntityType::Surface(entity),
Some(codec::objects::SolidHistoryOperation::Extrusion(value)),
codec::EntityType::Surface(entity),
) = (&history, &mut surface)
{
if let Some(data) =
@@ -227,14 +227,14 @@ impl OpenCADStudio {
let mut failed = 0usize;
let mut self_intersections = 0usize;
for handle in handles {
let Some(acadrust::EntityType::Surface(surface)) =
let Some(codec::EntityType::Surface(surface)) =
self.tabs[i].scene.document.get_entity(handle)
else {
failed += 1;
continue;
};
let kernel_distance =
if surface.kind == acadrust::entities::SurfaceKind::Revolved {
if surface.kind == codec::entities::SurfaceKind::Revolved {
-distance
} else {
distance
@@ -251,9 +251,9 @@ impl OpenCADStudio {
failed += 1;
continue;
};
let solid = match cadkernel::brep::thicken(&body, kernel_distance) {
let solid = match kernel::brep::thicken(&body, kernel_distance) {
Ok(solid) => solid,
Err(cadkernel::brep::ThickenError::SelfIntersection) => {
Err(kernel::brep::ThickenError::SelfIntersection) => {
failed += 1;
self_intersections += 1;
continue;
@@ -388,7 +388,7 @@ impl OpenCADStudio {
let result =
sweep_model::revolve_history(&entity, from, to, angle, start_angle)
.and_then(|history| {
cadkernel::acis::rebuild_body(&history)
kernel::acis::rebuild_body(&history)
.ok()
.map(|solid| (solid, history))
})
@@ -497,14 +497,14 @@ impl OpenCADStudio {
for (handle, profile) in profiles {
let result = path.as_ref().zip(options).and_then(|(path, options)| {
let record = sweep_model::sweep_record(&profile, path, options)?;
let (_, _, closed) = cadkernel::acis::sweep_profile_geometry(
let (_, _, closed) = kernel::acis::sweep_profile_geometry(
record.sweep_entity.as_ref()?,
record.sweep_entity_transform,
)
.ok()?;
let surface = mode == ExtrudeMode::Surface || !closed;
let body =
cadkernel::acis::rebuild_sweep_with_mode(&record, surface).ok()?;
kernel::acis::rebuild_sweep_with_mode(&record, surface).ok()?;
Some((body, record, surface))
});
let Some((body, record, surface)) = result else {
@@ -523,7 +523,7 @@ impl OpenCADStudio {
self.add_solid_model(
empty_solid3d(),
body,
acadrust::objects::SolidHistoryOperation::Sweep(record),
codec::objects::SolidHistoryOperation::Sweep(record),
)
};
if created.is_null() {
@@ -617,7 +617,7 @@ impl OpenCADStudio {
} else {
loft_command_model::record(&sections, &guides, path, &available, mode, options)
.and_then(|record| {
cadkernel::acis::rebuild_loft_with_options(&record)
kernel::acis::rebuild_loft_with_options(&record)
.map(|body| (body, record))
})
};
@@ -651,7 +651,7 @@ impl OpenCADStudio {
if !handle.is_null() {
self.tabs[i].scene.create_solid_history(
handle,
acadrust::objects::SolidHistoryOperation::Loft(record),
codec::objects::SolidHistoryOperation::Loft(record),
);
}
handle
@@ -659,7 +659,7 @@ impl OpenCADStudio {
self.add_solid_model(
empty_solid3d(),
body,
acadrust::objects::SolidHistoryOperation::Loft(record),
codec::objects::SolidHistoryOperation::Loft(record),
)
};
if created.is_null() {
@@ -751,7 +751,7 @@ impl OpenCADStudio {
task
}
pub(super) fn handle_slice_entities(&mut self, targets: Vec<Handle>, plane: cadkernel::space::Plane, keep_point: Option<glam::DVec3>) -> Task<Message> {
pub(super) fn handle_slice_entities(&mut self, targets: Vec<Handle>, plane: kernel::space::Plane, keep_point: Option<glam::DVec3>) -> Task<Message> {
let i = self.active_tab;
let task = self.solid_slice(&targets, plane, keep_point);
self.tabs[i].active_cmd = None;
@@ -761,7 +761,7 @@ impl OpenCADStudio {
task
}
pub(super) fn handle_slice_surface_entities(&mut self, targets: Vec<Handle>, cutter: Box<cadkernel::brep::Body>, keep_point: Option<glam::DVec3>) -> Task<Message> {
pub(super) fn handle_slice_surface_entities(&mut self, targets: Vec<Handle>, cutter: Box<kernel::brep::Body>, keep_point: Option<glam::DVec3>) -> Task<Message> {
let i = self.active_tab;
let task = self.solid_slice_surface(&targets, *cutter, keep_point);
self.tabs[i].active_cmd = None;
+62 -62
View File
@@ -1,8 +1,8 @@
#[cfg(test)]
mod command_replacement_tests {
use super::super::*;
use acadrust::entities::{Circle, Line};
use acadrust::types::Vector3;
use codec::entities::{Circle, Line};
use codec::types::Vector3;
#[test]
fn one_to_one_edits_keep_identity_but_type_changes_do_not() {
@@ -11,7 +11,7 @@ mod command_replacement_tests {
let tab = app.active_tab;
let handle = app.tabs[tab]
.scene
.add_entity(acadrust::EntityType::Line(Line::from_points(
.add_entity(codec::EntityType::Line(Line::from_points(
Vector3::ZERO,
Vector3::new(1.0, 0.0, 0.0),
)));
@@ -26,7 +26,7 @@ mod command_replacement_tests {
let kept = app.replace_command_entity(
tab,
handle,
vec![acadrust::EntityType::Line(Line::from_points(
vec![codec::EntityType::Line(Line::from_points(
Vector3::ZERO,
Vector3::new(3.0, 0.0, 0.0),
))],
@@ -34,12 +34,12 @@ mod command_replacement_tests {
assert_eq!(kept, vec![handle]);
let edited = app.tabs[tab].scene.document.get_entity(handle).unwrap();
assert_eq!(edited.common().owner_handle, owner);
assert!(matches!(edited, acadrust::EntityType::Line(line) if line.end.x == 3.0));
assert!(matches!(edited, codec::EntityType::Line(line) if line.end.x == 3.0));
let allocated = app.replace_command_entity(
tab,
handle,
vec![acadrust::EntityType::Circle(Circle::from_coords(
vec![codec::EntityType::Circle(Circle::from_coords(
0.0, 0.0, 0.0, 2.0,
))],
);
@@ -55,7 +55,7 @@ mod command_replacement_tests {
let tab = app.active_tab;
let handle = app.tabs[tab]
.scene
.add_entity(acadrust::EntityType::Line(Line::from_points(
.add_entity(codec::EntityType::Line(Line::from_points(
Vector3::ZERO,
Vector3::new(1.0, 0.0, 0.0),
)));
@@ -69,7 +69,7 @@ mod command_replacement_tests {
let _ = app.apply_cmd_result(CmdResult::UpdateLiveEntity {
handle,
entity: acadrust::EntityType::Line(Line::from_points(
entity: codec::EntityType::Line(Line::from_points(
Vector3::ZERO,
Vector3::new(4.0, 0.0, 0.0),
)),
@@ -82,7 +82,7 @@ mod command_replacement_tests {
assert_eq!(updated.common().layer, expected.layer);
assert_eq!(updated.common().invisible, expected.invisible);
assert_eq!(updated.common().linetype_scale, expected.linetype_scale);
assert!(matches!(updated, acadrust::EntityType::Line(line) if line.end.x == 4.0));
assert!(matches!(updated, codec::EntityType::Line(line) if line.end.x == 4.0));
}
}
@@ -94,17 +94,17 @@ mod parametric_constraint_undo_tests {
fn add_line(app: &mut OpenCADStudio, x1: f64, y1: f64, x2: f64, y2: f64) -> Handle {
app.tabs[app.active_tab]
.scene
.add_entity(acadrust::EntityType::Line(
acadrust::entities::Line::from_points(
acadrust::types::Vector3::new(x1, y1, 0.0),
acadrust::types::Vector3::new(x2, y2, 0.0),
.add_entity(codec::EntityType::Line(
codec::entities::Line::from_points(
codec::types::Vector3::new(x1, y1, 0.0),
codec::types::Vector3::new(x2, y2, 0.0),
),
))
}
fn line_angle_deg(app: &OpenCADStudio, handle: Handle) -> f64 {
match app.tabs[app.active_tab].scene.document.get_entity(handle) {
Some(acadrust::EntityType::Line(l)) => (l.end.y - l.start.y)
Some(codec::EntityType::Line(l)) => (l.end.y - l.start.y)
.atan2(l.end.x - l.start.x)
.to_degrees(),
other => panic!("expected a Line, got {other:?}"),
@@ -188,14 +188,14 @@ mod parametric_constraint_undo_tests {
});
let line = |handle| match app.tabs[app.active_tab].scene.document.get_entity(handle) {
Some(acadrust::EntityType::Line(line)) => line.clone(),
Some(codec::EntityType::Line(line)) => line.clone(),
other => panic!("expected a Line, got {other:?}"),
};
let fixed = line(first);
let moving = line(second);
assert_eq!(fixed.start, acadrust::types::Vector3::new(0.0, 0.0, 0.0));
assert_eq!(fixed.end, acadrust::types::Vector3::new(10.0, 0.0, 0.0));
assert!((moving.start - acadrust::types::Vector3::new(20.0, 0.0, 0.0)).length() < 1.0e-9);
assert_eq!(fixed.start, codec::types::Vector3::new(0.0, 0.0, 0.0));
assert_eq!(fixed.end, codec::types::Vector3::new(10.0, 0.0, 0.0));
assert!((moving.start - codec::types::Vector3::new(20.0, 0.0, 0.0)).length() < 1.0e-9);
assert!((moving.length() - 10.0).abs() < 1.0e-7);
assert!(
(fixed.end - fixed.start)
@@ -216,10 +216,10 @@ mod parametric_constraint_undo_tests {
.document
.get_entity(handle)
{
Some(acadrust::EntityType::Line(line)) => (line.start, line.end, line.length()),
Some(codec::EntityType::Line(line)) => (line.start, line.end, line.length()),
other => panic!("expected a Line, got {other:?}"),
};
let direction = acadrust::types::Vector3::new(3.0, 4.0, 0.0).normalize();
let direction = codec::types::Vector3::new(3.0, 4.0, 0.0).normalize();
let _ = app.apply_cmd_result(CmdResult::AddHorizontalConstraint {
kind: crate::scene::parametric_constraints::ConstraintKind::Horizontal,
@@ -231,7 +231,7 @@ mod parametric_constraint_undo_tests {
});
let line = match app.tabs[app.active_tab].scene.document.get_entity(handle) {
Some(acadrust::EntityType::Line(line)) => line,
Some(codec::EntityType::Line(line)) => line,
other => panic!("expected a Line, got {other:?}"),
};
let solved = (line.end - line.start).normalize();
@@ -246,7 +246,7 @@ mod parametric_constraint_undo_tests {
app.undo_steps(1);
let line = match app.tabs[app.active_tab].scene.document.get_entity(handle) {
Some(acadrust::EntityType::Line(line)) => line,
Some(codec::EntityType::Line(line)) => line,
other => panic!("expected a Line after undo, got {other:?}"),
};
assert_eq!((line.start, line.end), (original_start, original_end));
@@ -261,7 +261,7 @@ mod parametric_constraint_undo_tests {
app.redo_steps(1);
let line = match app.tabs[app.active_tab].scene.document.get_entity(handle) {
Some(acadrust::EntityType::Line(line)) => line,
Some(codec::EntityType::Line(line)) => line,
other => panic!("expected a Line after redo, got {other:?}"),
};
assert!((line.end - line.start).normalize().cross(&direction).length() < 1.0e-7);
@@ -285,15 +285,15 @@ mod parametric_constraint_undo_tests {
pick(first, glam::DVec3::ZERO),
pick(second, glam::DVec3::new(8.0, 3.0, 0.0)),
),
direction: acadrust::types::Vector3::UNIT_X,
direction: codec::types::Vector3::UNIT_X,
label: "Horizontal constraint",
});
let line = |handle| match app.tabs[app.active_tab].scene.document.get_entity(handle) {
Some(acadrust::EntityType::Line(line)) => line,
Some(codec::EntityType::Line(line)) => line,
other => panic!("expected a Line, got {other:?}"),
};
assert_eq!(line(first).start, acadrust::types::Vector3::ZERO);
assert_eq!(line(first).start, codec::types::Vector3::ZERO);
assert!(line(second).start.y.abs() < 1.0e-8);
}
@@ -301,28 +301,28 @@ mod parametric_constraint_undo_tests {
fn horizontal_minor_axis_rotates_an_ellipse_around_its_center() {
let mut app = OpenCADStudio::new_for_test();
let _ = app.automation_op(r#"{"op":"new"}"#);
let mut ellipse = acadrust::entities::Ellipse::default();
ellipse.center = acadrust::types::Vector3::new(3.0, 7.0, 0.0);
ellipse.major_axis = acadrust::types::Vector3::new(3.0, 4.0, 0.0);
let mut ellipse = codec::entities::Ellipse::default();
ellipse.center = codec::types::Vector3::new(3.0, 7.0, 0.0);
ellipse.major_axis = codec::types::Vector3::new(3.0, 4.0, 0.0);
ellipse.minor_axis_ratio = 0.4;
let handle = app.tabs[app.active_tab]
.scene
.add_entity(acadrust::EntityType::Ellipse(ellipse));
.add_entity(codec::EntityType::Ellipse(ellipse));
let _ = app.apply_cmd_result(CmdResult::AddHorizontalConstraint {
kind: crate::scene::parametric_constraints::ConstraintKind::Horizontal,
selection: crate::command::HorizontalConstraintSelection::Reference(
ParametricRef::ellipse_minor_axis(handle),
),
direction: acadrust::types::Vector3::UNIT_X,
direction: codec::types::Vector3::UNIT_X,
label: "Horizontal constraint",
});
let ellipse = match app.tabs[app.active_tab].scene.document.get_entity(handle) {
Some(acadrust::EntityType::Ellipse(ellipse)) => ellipse,
Some(codec::EntityType::Ellipse(ellipse)) => ellipse,
other => panic!("expected an Ellipse, got {other:?}"),
};
assert!((ellipse.center - acadrust::types::Vector3::new(3.0, 7.0, 0.0)).length() < 1.0e-9);
assert!((ellipse.center - codec::types::Vector3::new(3.0, 7.0, 0.0)).length() < 1.0e-9);
assert!(ellipse.major_axis.x.abs() < 1.0e-7);
assert!((ellipse.major_axis.length() - 5.0).abs() < 1.0e-7);
assert!((ellipse.minor_axis_ratio - 0.4).abs() < 1.0e-9);
@@ -335,9 +335,9 @@ mod parametric_constraint_undo_tests {
let _ = app.automation_op(r#"{"op":"new"}"#);
let _existing = add_line(&mut app, 0.0, 0.0, 5.0, 0.0);
let new_line = acadrust::EntityType::Line(acadrust::entities::Line::from_points(
acadrust::types::Vector3::new(5.0, 0.0, 0.0), // exactly on `existing`'s end point
acadrust::types::Vector3::new(10.0, 0.0, 0.0),
let new_line = codec::EntityType::Line(codec::entities::Line::from_points(
codec::types::Vector3::new(5.0, 0.0, 0.0), // exactly on `existing`'s end point
codec::types::Vector3::new(10.0, 0.0, 0.0),
));
app.tabs[app.active_tab].active_cmd = Some(Box::new(
crate::modules::draw::draw::line::LineCommand::new(),
@@ -489,7 +489,7 @@ mod parametric_constraint_undo_tests {
Ok(8.0)
);
let (start, end) = match app.tabs[app.active_tab].scene.document.get_entity(line) {
Some(acadrust::EntityType::Line(l)) => (l.start, l.end),
Some(codec::EntityType::Line(l)) => (l.start, l.end),
other => panic!("expected a Line, got {other:?}"),
};
let len = ((end.x - start.x).powi(2) + (end.y - start.y).powi(2)).sqrt();
@@ -502,7 +502,7 @@ mod parametric_constraint_undo_tests {
app.named_parameter_editor_rows[0].formula = "3".to_string();
app.apply_named_parameter_editor_rows();
let (start, end) = match app.tabs[app.active_tab].scene.document.get_entity(line) {
Some(acadrust::EntityType::Line(l)) => (l.start, l.end),
Some(codec::EntityType::Line(l)) => (l.start, l.end),
other => panic!("expected a Line, got {other:?}"),
};
let len = ((end.x - start.x).powi(2) + (end.y - start.y).powi(2)).sqrt();
@@ -520,7 +520,7 @@ mod parametric_constraint_undo_tests {
Ok(8.0)
);
let length_after_undo = match app.tabs[app.active_tab].scene.document.get_entity(line) {
Some(acadrust::EntityType::Line(line)) => line.length(),
Some(codec::EntityType::Line(line)) => line.length(),
other => panic!("expected a Line, got {other:?}"),
};
assert!((length_after_undo - 8.0).abs() < 1e-6);
@@ -650,7 +650,7 @@ mod parametric_constraint_undo_tests {
Ok(8.0)
);
let (start, end) = match app.tabs[app.active_tab].scene.document.get_entity(line) {
Some(acadrust::EntityType::Line(l)) => (l.start, l.end),
Some(codec::EntityType::Line(l)) => (l.start, l.end),
other => panic!("expected a Line, got {other:?}"),
};
let len = ((end.x - start.x).powi(2) + (end.y - start.y).powi(2)).sqrt();
@@ -822,18 +822,18 @@ mod parametric_constraint_undo_tests {
entities.contains(&a) && entities.contains(&b),
"the constraint should reference both lines"
);
let Some(acadrust::EntityType::Line(first)) =
let Some(codec::EntityType::Line(first)) =
app.tabs[app.active_tab].scene.document.get_entity(a)
else {
panic!("expected first line");
};
let Some(acadrust::EntityType::Line(second)) =
let Some(codec::EntityType::Line(second)) =
app.tabs[app.active_tab].scene.document.get_entity(b)
else {
panic!("expected second line");
};
assert!(
(first.end - acadrust::types::Vector3::new(5.0, 0.0, 0.0)).length() < 1.0e-7
(first.end - codec::types::Vector3::new(5.0, 0.0, 0.0)).length() < 1.0e-7
);
assert!((second.start - first.end).length() < 1.0e-7);
assert!((second.length() - 5.0).abs() < 1.0e-7);
@@ -878,21 +878,21 @@ mod parametric_constraint_undo_tests {
#[cfg(all(test, not(target_arch = "wasm32")))]
mod delobj_tests {
use super::super::*;
use acadrust::types::Vector3;
use codec::types::Vector3;
fn sweep_source_presence(value: i16, mode: crate::command::ExtrudeMode) -> (bool, bool) {
let mut app = OpenCADStudio::new_for_test();
app.automation_op(r#"{"op":"new"}"#);
let i = app.active_tab;
let mut circle = acadrust::Circle::new();
let mut circle = codec::Circle::new();
circle.radius = 2.0;
let profile = app.tabs[i]
.scene
.add_entity(acadrust::EntityType::Circle(circle));
.add_entity(codec::EntityType::Circle(circle));
let path =
app.tabs[i]
.scene
.add_entity(acadrust::EntityType::Line(acadrust::Line::from_points(
.add_entity(codec::EntityType::Line(codec::Line::from_points(
Vector3::new(0.0, 0.0, 0.0),
Vector3::new(0.0, 0.0, 5.0),
)));
@@ -912,10 +912,10 @@ mod delobj_tests {
.entities()
.any(|entity| match mode {
crate::command::ExtrudeMode::Solid => {
matches!(entity, acadrust::EntityType::Solid3D(_))
matches!(entity, codec::EntityType::Solid3D(_))
}
crate::command::ExtrudeMode::Surface => {
matches!(entity, acadrust::EntityType::Surface(_))
matches!(entity, codec::EntityType::Surface(_))
}
});
assert!(created, "SWEEP must produce the requested result");
@@ -948,15 +948,15 @@ mod delobj_tests {
#[cfg(all(test, not(target_arch = "wasm32")))]
mod thicken_tests {
use super::super::*;
use acadrust::entities::{Surface, SurfaceKind};
use cadkernel::geom2d::{Circle, Curve, NurbsCurve};
use cadkernel::space::{Parameterization, Plane};
use codec::entities::{Surface, SurfaceKind};
use kernel::geom2d::{Circle, Curve, NurbsCurve};
use kernel::space::{Parameterization, Plane};
#[test]
fn thicken_preserves_sources_and_round_trips_results_with_one_undo() {
let mut app = OpenCADStudio::new_for_test();
app.automation_op(r#"{"op":"new"}"#);
let body = cadkernel::brep::planar_region(
let body = kernel::brep::planar_region(
Plane::XY,
&[vec![Curve::Circle(Circle {
centre: [0.0; 2],
@@ -965,14 +965,14 @@ mod thicken_tests {
)
.unwrap();
let source = app.add_surface_model(
acadrust::EntityType::Surface(Surface::new(SurfaceKind::Plane)),
codec::EntityType::Surface(Surface::new(SurfaceKind::Plane)),
body,
);
assert!(!source.is_null());
let i = app.active_tab;
let invalid = app.tabs[i]
.scene
.add_entity(acadrust::EntityType::Surface(Surface::new(
.add_entity(codec::EntityType::Surface(Surface::new(
SurfaceKind::Generic,
)));
let original =
@@ -993,7 +993,7 @@ mod thicken_tests {
.document
.entities()
.find_map(|entity| {
matches!(entity, acadrust::EntityType::Solid3D(_)).then_some(entity.common().handle)
matches!(entity, codec::EntityType::Solid3D(_)).then_some(entity.common().handle)
})
.unwrap();
assert!(app.tabs[i]
@@ -1006,7 +1006,7 @@ mod thicken_tests {
original
);
let expected =
cadkernel::brep::analytic_mass_properties(&app.tabs[i].scene.solid_models[&result])
kernel::brep::analytic_mass_properties(&app.tabs[i].scene.solid_models[&result])
.unwrap()
.volume;
let bytes = crate::io::save_to_bytes(
@@ -1019,7 +1019,7 @@ mod thicken_tests {
let mut restored = crate::scene::Scene::new();
restored.document = document;
restored.restore_solid_models(&[result]);
let actual = cadkernel::brep::analytic_mass_properties(&restored.solid_models[&result])
let actual = kernel::brep::analytic_mass_properties(&restored.solid_models[&result])
.unwrap()
.volume;
assert!((expected - actual).abs() < 1e-8);
@@ -1057,10 +1057,10 @@ mod thicken_tests {
)
.unwrap();
let body =
cadkernel::brep::extrude_surface(Plane::XY, &[Curve::Nurbs(profile)], [0.0, 0.0, 2.0])
kernel::brep::extrude_surface(Plane::XY, &[Curve::Nurbs(profile)], [0.0, 0.0, 2.0])
.unwrap();
let source = app.add_surface_model(
acadrust::EntityType::Surface(Surface::new(SurfaceKind::Generic)),
codec::EntityType::Surface(Surface::new(SurfaceKind::Generic)),
body,
);
let i = app.active_tab;
@@ -1075,7 +1075,7 @@ mod thicken_tests {
.document
.entities()
.filter_map(|entity| {
matches!(entity, acadrust::EntityType::Solid3D(_)).then_some(entity.common().handle)
matches!(entity, codec::EntityType::Solid3D(_)).then_some(entity.common().handle)
})
.collect::<Vec<_>>();
assert_eq!(solids.len(), 1);
@@ -1095,7 +1095,7 @@ mod thicken_tests {
mod dispatched_command_task_tests {
use super::super::*;
use crate::command::CmdResult;
use acadrust::entities::ViewportRenderMode as Mode;
use codec::entities::ViewportRenderMode as Mode;
/// `CmdResult::Dispatch` and `CmdResult::Relaunch` run the assembled line
/// through `dispatch_command`, and the Task it returns must reach the
+12 -12
View File
@@ -55,7 +55,7 @@ impl OpenCADStudio {
pub(super) fn handle_suspend_for_text_input(
&mut self,
pos: glam::DVec3,
entity: acadrust::entities::Text,
entity: codec::entities::Text,
) {
let i = self.active_tab;
self.tabs[i].suspended_cmd = self.tabs[i].active_cmd.take();
@@ -126,7 +126,7 @@ impl OpenCADStudio {
!self.tabs[i].scene.is_layer_locked(*handle)
&& matches!(
self.tabs[i].scene.document.get_entity(*handle),
Some(acadrust::EntityType::Dimension(_))
Some(codec::EntityType::Dimension(_))
)
});
if handles.is_empty() {
@@ -135,15 +135,15 @@ impl OpenCADStudio {
} else {
self.push_undo_snapshot(i, "DIMEDIT");
for handle in &handles {
if let Some(acadrust::EntityType::Dimension(dimension)) =
if let Some(codec::EntityType::Dimension(dimension)) =
self.tabs[i].scene.document.get_entity_mut(*handle)
{
use crate::command::DimensionEditOperation as Operation;
match &operation {
Operation::Home => {
let base = dimension.base_mut();
base.text_middle_point = acadrust::types::Vector3::ZERO;
base.insertion_point = acadrust::types::Vector3::ZERO;
base.text_middle_point = codec::types::Vector3::ZERO;
base.insertion_point = codec::types::Vector3::ZERO;
base.text_user_positioned = false;
base.text_rotation = 0.0;
}
@@ -156,10 +156,10 @@ impl OpenCADStudio {
dimension.base_mut().text_rotation = degrees.to_radians();
}
Operation::Oblique(degrees) => match dimension {
acadrust::entities::Dimension::Linear(value) => {
codec::entities::Dimension::Linear(value) => {
value.ext_line_rotation = degrees.to_radians();
}
acadrust::entities::Dimension::Aligned(value) => {
codec::entities::Dimension::Aligned(value) => {
value.ext_line_rotation = degrees.to_radians();
}
_ => {}
@@ -196,23 +196,23 @@ impl OpenCADStudio {
let mut is_dim = false;
if let Some(entity) = self.tabs[i].scene.document.get_entity_mut(handle) {
match entity {
acadrust::EntityType::Text(t) => {
codec::EntityType::Text(t) => {
t.value = new_text;
updated = true;
}
acadrust::EntityType::MText(t) => {
codec::EntityType::MText(t) => {
t.value = new_text;
updated = true;
}
acadrust::EntityType::AttributeDefinition(a) => {
codec::EntityType::AttributeDefinition(a) => {
a.default_value = new_text;
updated = true;
}
acadrust::EntityType::AttributeEntity(a) => {
codec::EntityType::AttributeEntity(a) => {
a.set_value(new_text);
updated = true;
}
acadrust::EntityType::Dimension(d) => {
codec::EntityType::Dimension(d) => {
// Empty string resets to auto-measured value; otherwise set override.
let base = d.base_mut();
base.text = new_text;
+21 -21
View File
@@ -259,7 +259,7 @@ impl OpenCADStudio {
let structural = handles.iter().any(|handle| {
matches!(
self.tabs[i].scene.document.get_entity(*handle),
Some(acadrust::EntityType::Dimension(_))
Some(codec::EntityType::Dimension(_))
)
});
let pending = self.begin_undo(i, "STRETCH", handles.len(), !structural);
@@ -281,13 +281,13 @@ impl OpenCADStudio {
// Dimensions whose points moved — their baked *D block is
// stale afterwards and must be dropped (see #398 / #372).
let mut stretched_dims: Vec<acadrust::Handle> = Vec::new();
let mut stretched_dims: Vec<codec::Handle> = Vec::new();
for handle in &handles {
let before = self.tabs[i].scene.document.get_entity_arc(*handle);
if let Some(entity) = before.as_deref() {
use crate::scene::parametric_constraints::ParametricRef;
match entity {
acadrust::EntityType::Line(line) => {
codec::EntityType::Line(line) => {
if in_win(line.start.x, line.start.y) {
driven_refs.push(ParametricRef::point(*handle, 0));
}
@@ -295,7 +295,7 @@ impl OpenCADStudio {
driven_refs.push(ParametricRef::point(*handle, 1));
}
}
acadrust::EntityType::LwPolyline(polyline) => {
codec::EntityType::LwPolyline(polyline) => {
if let Some(world) =
crate::entities::curve::lwpolyline_world_xy(polyline)
{
@@ -309,7 +309,7 @@ impl OpenCADStudio {
}
}
}
acadrust::EntityType::Polyline2D(polyline) => {
codec::EntityType::Polyline2D(polyline) => {
for (index, vertex) in polyline.vertices.iter().enumerate() {
if in_win(vertex.location.x, vertex.location.y) {
driven_refs.push(ParametricRef::point(
@@ -319,12 +319,12 @@ impl OpenCADStudio {
}
}
}
acadrust::EntityType::Circle(circle)
codec::EntityType::Circle(circle)
if in_win(circle.center.x, circle.center.y) =>
{
driven_refs.push(ParametricRef::center(*handle));
}
acadrust::EntityType::Arc(arc)
codec::EntityType::Arc(arc)
if in_win(arc.center.x, arc.center.y) =>
{
driven_refs.push(ParametricRef::center(*handle));
@@ -337,7 +337,7 @@ impl OpenCADStudio {
};
let mut stretched = false;
match entity {
acadrust::EntityType::Line(l) => {
codec::EntityType::Line(l) => {
let s_in = in_win(l.start.x, l.start.y);
let e_in = in_win(l.end.x, l.end.y);
if s_in {
@@ -353,7 +353,7 @@ impl OpenCADStudio {
stretched = true;
}
}
acadrust::EntityType::LwPolyline(p) => {
codec::EntityType::LwPolyline(p) => {
let Some(mut world) = crate::entities::curve::lwpolyline_world_xy(p)
else {
continue;
@@ -369,7 +369,7 @@ impl OpenCADStudio {
*p = world;
}
}
acadrust::EntityType::Polyline2D(p) => {
codec::EntityType::Polyline2D(p) => {
for v in &mut p.vertices {
if in_win(v.location.x, v.location.y) {
v.location.x += dx;
@@ -378,7 +378,7 @@ impl OpenCADStudio {
}
}
}
acadrust::EntityType::Polyline(p) => {
codec::EntityType::Polyline(p) => {
for v in &mut p.vertices {
if in_win(v.location.x, v.location.z) {
v.location.x += dx;
@@ -387,7 +387,7 @@ impl OpenCADStudio {
}
}
}
acadrust::EntityType::Arc(a) => {
codec::EntityType::Arc(a) => {
if in_win(a.center.x, a.center.y) {
a.center.x += dx;
a.center.y += dy;
@@ -395,7 +395,7 @@ impl OpenCADStudio {
stretched = true;
}
}
acadrust::EntityType::Circle(c) => {
codec::EntityType::Circle(c) => {
if in_win(c.center.x, c.center.y) {
c.center.x += dx;
c.center.y += dy;
@@ -403,7 +403,7 @@ impl OpenCADStudio {
stretched = true;
}
}
acadrust::EntityType::Ellipse(e) => {
codec::EntityType::Ellipse(e) => {
if in_win(e.center.x, e.center.y) {
e.center.x += dx;
e.center.y += dy;
@@ -411,7 +411,7 @@ impl OpenCADStudio {
stretched = true;
}
}
acadrust::EntityType::Insert(ins) => {
codec::EntityType::Insert(ins) => {
if in_win(ins.insert_point.x, ins.insert_point.y) {
ins.insert_point.x += dx;
ins.insert_point.y += dy;
@@ -419,7 +419,7 @@ impl OpenCADStudio {
stretched = true;
}
}
acadrust::EntityType::Text(t) => {
codec::EntityType::Text(t) => {
if in_win(t.insertion_point.x, t.insertion_point.y) {
t.insertion_point.x += dx;
t.insertion_point.y += dy;
@@ -427,7 +427,7 @@ impl OpenCADStudio {
stretched = true;
}
}
acadrust::EntityType::MText(t) => {
codec::EntityType::MText(t) => {
if in_win(t.insertion_point.x, t.insertion_point.y) {
t.insertion_point.x += dx;
t.insertion_point.y += dy;
@@ -435,18 +435,18 @@ impl OpenCADStudio {
stretched = true;
}
}
acadrust::EntityType::Viewport(vp) => {
codec::EntityType::Viewport(vp) => {
stretched = windows.iter().any(|(win_min, win_max)| {
crate::entities::viewport::stretch(vp, *win_min, *win_max, delta)
});
}
acadrust::EntityType::Dimension(dim) => {
use acadrust::entities::Dimension;
codec::EntityType::Dimension(dim) => {
use codec::entities::Dimension;
// Move every definition point that falls inside the
// window — the same points the grips expose — then
// refresh the stored measurement so the value tracks
// the stretched geometry.
let mv = |p: &mut acadrust::types::Vector3| {
let mv = |p: &mut codec::types::Vector3| {
if in_win(p.x, p.y) {
p.x += dx;
p.y += dy;
+12 -12
View File
@@ -37,20 +37,20 @@ impl OpenCADStudio {
/// UCS origin (0,0,0 in user coordinates).
fn default_draw_start(&self, i: usize) -> glam::DVec3 {
let tab = &self.tabs[i];
let endpoint = |entity: &acadrust::EntityType| {
let endpoint = |entity: &codec::EntityType| {
let last_grip = match entity {
acadrust::EntityType::Line(line) => {
codec::EntityType::Line(line) => {
return Some(glam::DVec3::new(line.end.x, line.end.y, line.end.z));
}
acadrust::EntityType::Arc(_) => Some(2),
acadrust::EntityType::LwPolyline(polyline) => {
codec::EntityType::Arc(_) => Some(2),
codec::EntityType::LwPolyline(polyline) => {
polyline.vertices.len().checked_sub(1)
}
acadrust::EntityType::Polyline(polyline) => polyline.vertices.len().checked_sub(1),
acadrust::EntityType::Polyline2D(polyline) => {
codec::EntityType::Polyline(polyline) => polyline.vertices.len().checked_sub(1),
codec::EntityType::Polyline2D(polyline) => {
polyline.vertices.len().checked_sub(1)
}
acadrust::EntityType::Polyline3D(polyline) => {
codec::EntityType::Polyline3D(polyline) => {
polyline.vertices.len().checked_sub(1)
}
_ => None,
@@ -472,7 +472,7 @@ impl OpenCADStudio {
let (kept, dropped): (Vec<Handle>, Vec<Handle>) = handles.into_iter().partition(|h| {
matches!(
self.tabs[i].scene.document.get_entity(*h),
Some(acadrust::EntityType::Insert(_))
Some(codec::EntityType::Insert(_))
)
});
for handle in &dropped {
@@ -560,10 +560,10 @@ impl OpenCADStudio {
let solid_pick = matches!(
self.tabs[i].scene.document.get_entity(*handle),
Some(
acadrust::EntityType::Solid3D(_)
| acadrust::EntityType::Surface(_)
| acadrust::EntityType::Region(_)
| acadrust::EntityType::Body(_)
codec::EntityType::Solid3D(_)
| codec::EntityType::Surface(_)
| codec::EntityType::Region(_)
| codec::EntityType::Body(_)
)
);
let direction = if solid_pick {
+16 -16
View File
@@ -1,7 +1,7 @@
use super::*;
impl OpenCADStudio {
pub(super) fn handle_mview_create(&mut self, viewport: acadrust::entities::Viewport, preserve_view: bool) {
pub(super) fn handle_mview_create(&mut self, viewport: codec::entities::Viewport, preserve_view: bool) {
let i = self.active_tab;
let saved_view = preserve_view.then(|| {
(
@@ -17,9 +17,9 @@ impl OpenCADStudio {
});
let label = self.history_label_from_active_cmd(i, "MVIEW");
let pending = self.begin_undo(i, label, 1, true);
let handle = self.commit_entity_handle(acadrust::EntityType::Viewport(viewport));
let handle = self.commit_entity_handle(codec::EntityType::Viewport(viewport));
if let (Some(handle), Some(saved)) = (handle, saved_view) {
if let Some(acadrust::EntityType::Viewport(viewport)) =
if let Some(codec::EntityType::Viewport(viewport)) =
self.tabs[i].scene.document.get_entity_mut(handle)
{
viewport.view_target = saved.0;
@@ -45,7 +45,7 @@ impl OpenCADStudio {
pub(super) fn handle_mview_create_clipped(
&mut self,
boundary: Option<acadrust::EntityType>,
boundary: Option<codec::EntityType>,
boundary_handle: Handle,
) -> Option<Task<Message>> {
let i = self.active_tab;
@@ -56,12 +56,12 @@ impl OpenCADStudio {
.document
.get_entity(boundary_handle)
.is_some_and(|entity| match entity {
acadrust::EntityType::Circle(_) => true,
acadrust::EntityType::Ellipse(ellipse) => ellipse.is_full(),
acadrust::EntityType::LwPolyline(polyline) => polyline.is_closed,
acadrust::EntityType::Polyline(polyline) => polyline.is_closed(),
acadrust::EntityType::Polyline2D(polyline) => polyline.is_closed(),
acadrust::EntityType::Polyline3D(polyline) => polyline.flags.closed,
codec::EntityType::Circle(_) => true,
codec::EntityType::Ellipse(ellipse) => ellipse.is_full(),
codec::EntityType::LwPolyline(polyline) => polyline.is_closed,
codec::EntityType::Polyline(polyline) => polyline.is_closed(),
codec::EntityType::Polyline2D(polyline) => polyline.is_closed(),
codec::EntityType::Polyline3D(polyline) => polyline.flags.closed,
_ => false,
});
if !valid {
@@ -146,14 +146,14 @@ impl OpenCADStudio {
return Some(Task::none());
}
let mut viewport = acadrust::entities::Viewport::new();
let mut viewport = codec::entities::Viewport::new();
viewport.center =
acadrust::types::Vector3::new((min_x + max_x) / 2.0, (min_y + max_y) / 2.0, 0.0);
codec::types::Vector3::new((min_x + max_x) / 2.0, (min_y + max_y) / 2.0, 0.0);
viewport.width = max_x - min_x;
viewport.height = max_y - min_y;
viewport.id = 2;
viewport.clip_boundary_handle = clip_handle;
let viewport_handle = self.commit_entity_handle(acadrust::EntityType::Viewport(viewport));
let viewport_handle = self.commit_entity_handle(codec::EntityType::Viewport(viewport));
if let Some(viewport_handle) = viewport_handle {
if !created_boundary {
let before = self.tabs[i]
@@ -279,7 +279,7 @@ impl OpenCADStudio {
let mut thawed_count = 0usize;
// Collect target viewport handles
let target_handles: Vec<Handle> = if vp_handle == acadrust::Handle::NULL {
let target_handles: Vec<Handle> = if vp_handle == codec::Handle::NULL {
// All viewports in current layout block
let block_handle = self.tabs[i].scene.current_layout_block_handle_pub();
self.tabs[i]
@@ -288,7 +288,7 @@ impl OpenCADStudio {
.entities()
.filter(|e| {
e.common().owner_handle == block_handle
&& matches!(e, acadrust::EntityType::Viewport(_))
&& matches!(e, codec::EntityType::Viewport(_))
})
.map(|e| e.common().handle)
.collect()
@@ -297,7 +297,7 @@ impl OpenCADStudio {
};
for &target_handle in &target_handles {
if let Some(acadrust::EntityType::Viewport(vp)) =
if let Some(codec::EntityType::Viewport(vp)) =
self.tabs[i].scene.document.get_entity_mut(target_handle)
{
for h in &freeze_handles {