fix(dwg): preserve hatch context loops

This commit is contained in:
Hakan Seven committed 2026-09-09 08:23:41 +03:00
1 parent 3fb49c4d3e
commit 56e09cd3f5
7 files changed
+56 -31

No files matched your search

+46 -21
View File
@@ -11,7 +11,7 @@
use acadrust::entities::{EntityCommon, EntityType};
use acadrust::objects::{
Dictionary, DimContext, DimSubtype, EmbeddedMTextContext, HatchScaleContext,
Dictionary, DimContext, DimSubtype, EmbeddedMTextContext, HatchLoopContext, HatchScaleContext,
MTextAttributeContext, MTextContext, ObjectContextData, ObjectContextKind, ObjectType,
};
use acadrust::types::{Vector2, Vector3};
@@ -289,12 +289,15 @@ fn context_kind_for(
pattern_lines: hatch.pattern.lines.clone(),
pattern_scale: hatch.pattern_scale,
pattern_base: Vector3::ZERO,
loop_types: hatch
loops: hatch
.paths
.iter()
.map(|path| path.flags.bits() as i32)
.map(|path| HatchLoopContext {
loop_type: path.flags.bits() as i32,
supports_context: true,
boundary: None,
})
.collect(),
supports_context: true,
}),
)),
_ => None,
@@ -435,10 +438,6 @@ pub fn create_annotation_context(
is_default,
scale: scale_handle,
kind,
raw_dwg_data: None,
raw_dwg_handle_bits: 0,
raw_dwg_version: None,
raw_dwg_snapshot: None,
};
doc.objects
.insert(leaf_h, ObjectType::ObjectContextData(leaf));
@@ -895,9 +894,43 @@ fn apply_hatch_context(hatch: &mut acadrust::entities::Hatch, context: &HatchSca
line.base_point.x += context.pattern_base.x;
line.base_point.y += context.pattern_base.y;
}
for (path, bits) in hatch.paths.iter_mut().zip(&context.loop_types) {
path.flags = acadrust::entities::BoundaryPathFlags::from_bits(*bits as u32);
}
let base_paths = std::mem::take(&mut hatch.paths);
hatch.paths = context
.loops
.iter()
.enumerate()
.map(|(index, loop_data)| {
let flags =
acadrust::entities::BoundaryPathFlags::from_bits(loop_data.loop_type as u32);
let mut path = if loop_data.supports_context {
base_paths.get(index).cloned()
} else {
loop_data.boundary.clone()
}
.unwrap_or_else(|| acadrust::entities::BoundaryPath::with_flags(flags));
path.flags = flags;
path
})
.collect();
}
fn sync_hatch_loops(loops: &mut Vec<HatchLoopContext>, paths: &[acadrust::entities::BoundaryPath]) {
let previous = std::mem::take(loops);
*loops = paths
.iter()
.enumerate()
.map(|(index, path)| {
let supports_context = previous
.get(index)
.map(|loop_data| loop_data.supports_context)
.unwrap_or(true);
HatchLoopContext {
loop_type: path.flags.bits() as i32,
supports_context,
boundary: (!supports_context).then(|| path.clone()),
}
})
.collect();
}
pub fn entity_for_annotation_context<'a>(
@@ -1239,11 +1272,7 @@ pub fn sync_annotation_context_from_entity(
line.base_point.y -= context.pattern_base.y;
}
context.pattern_scale = hatch.pattern_scale;
context.loop_types = hatch
.paths
.iter()
.map(|path| path.flags.bits() as i32)
.collect();
sync_hatch_loops(&mut context.loops, &hatch.paths);
}
(EntityType::Hatch(hatch), ObjectContextKind::HatchView(context)) => {
context.hatch.pattern_lines.clone_from(&hatch.pattern.lines);
@@ -1252,11 +1281,7 @@ pub fn sync_annotation_context_from_entity(
line.base_point.y -= context.hatch.pattern_base.y;
}
context.hatch.pattern_scale = hatch.pattern_scale;
context.hatch.loop_types = hatch
.paths
.iter()
.map(|path| path.flags.bits() as i32)
.collect();
sync_hatch_loops(&mut context.hatch.loops, &hatch.paths);
context.view_normal = hatch.normal;
}
_ => {}