forked from 1b-agent/opencadstudio-upstream
fix(dwg): preserve hatch context loops
This commit is contained in:
1 parent
3fb49c4d3e
commit
56e09cd3f5
7 files changed
+56
-31
No files matched your search
Generated
+2
-2
@@ -79,7 +79,7 @@ checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618"
|
||||
[[package]]
|
||||
name = "acadrust"
|
||||
version = "0.5.4"
|
||||
source = "git+https://github.com/HakanSeven12/cadcodec.git?rev=f438e7312a98c936c0de1e3404893cf095369a26#f438e7312a98c936c0de1e3404893cf095369a26"
|
||||
source = "git+https://github.com/HakanSeven12/cadcodec.git?rev=f1ef57eddb6ffba91bc529e16b5dc39e2aef975c#f1ef57eddb6ffba91bc529e16b5dc39e2aef975c"
|
||||
dependencies = [
|
||||
"ahash 0.8.12",
|
||||
"anyhow",
|
||||
@@ -885,7 +885,7 @@ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
|
||||
[[package]]
|
||||
name = "cadkernel"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/HakanSeven12/cadkernel.git?rev=922ce39e248f610696ebabf97a76a85ee2e11e20#922ce39e248f610696ebabf97a76a85ee2e11e20"
|
||||
source = "git+https://github.com/HakanSeven12/cadkernel.git?rev=98b273c384a3b9ec706f7e53436dbb9ac7c6ec82#98b273c384a3b9ec706f7e53436dbb9ac7c6ec82"
|
||||
dependencies = [
|
||||
"acadrust",
|
||||
"cavalier_contours",
|
||||
|
||||
+2
-2
@@ -31,8 +31,8 @@ glam = { version = "0.33", features = ["bytemuck"] }
|
||||
rfd = "0.17"
|
||||
clap = { version = "4", features = ["derive", "string"] }
|
||||
env_logger = "0.11"
|
||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "f438e7312a98c936c0de1e3404893cf095369a26", features = ["serde"] }
|
||||
cadkernel = { git = "https://github.com/HakanSeven12/cadkernel.git", rev = "922ce39e248f610696ebabf97a76a85ee2e11e20", features = ["acis", "offset"] }
|
||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "f1ef57eddb6ffba91bc529e16b5dc39e2aef975c", features = ["serde"] }
|
||||
cadkernel = { git = "https://github.com/HakanSeven12/cadkernel.git", rev = "98b273c384a3b9ec706f7e53436dbb9ac7c6ec82", features = ["acis", "offset"] }
|
||||
dwg-thumbnailer = { path = "crates/dwg-thumbnailer" }
|
||||
flate2 = "1"
|
||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "bmp", "tiff"] }
|
||||
|
||||
@@ -14,8 +14,8 @@ bincode = "1.3"
|
||||
thiserror = "1"
|
||||
|
||||
# Host adapters convert ObjectId to acadrust handles; kernel handles stay local.
|
||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "f438e7312a98c936c0de1e3404893cf095369a26", features = ["serde"], optional = true }
|
||||
cadkernel = { git = "https://github.com/HakanSeven12/cadkernel.git", rev = "922ce39e248f610696ebabf97a76a85ee2e11e20", features = ["acis", "offset"], optional = true }
|
||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "f1ef57eddb6ffba91bc529e16b5dc39e2aef975c", features = ["serde"], optional = true }
|
||||
cadkernel = { git = "https://github.com/HakanSeven12/cadkernel.git", rev = "98b273c384a3b9ec706f7e53436dbb9ac7c6ec82", features = ["acis", "offset"], optional = true }
|
||||
ocs_plugin_api = { path = "../ocs_plugin_api", optional = true, features = ["host"] }
|
||||
|
||||
[build-dependencies]
|
||||
|
||||
@@ -14,7 +14,7 @@ serde = { version = "1", features = ["derive"] }
|
||||
# Pulled in only by the `host` feature, which adds the `acadrust`-typed
|
||||
# `HostApi` runtime surface. The default crate stays dependency-free so engine
|
||||
# crates and external tooling can depend on the manifest/ribbon contract cheaply.
|
||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "f438e7312a98c936c0de1e3404893cf095369a26", optional = true, features = ["serde"] }
|
||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "f1ef57eddb6ffba91bc529e16b5dc39e2aef975c", optional = true, features = ["serde"] }
|
||||
|
||||
# Runtime IPC and serialization (host feature only).
|
||||
interprocess = { version = "2", optional = true }
|
||||
@@ -38,7 +38,7 @@ serde_json = "1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
cargo-lock = "11"
|
||||
# acadrust is scanned at build time to generate the embedded type registry.
|
||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "f438e7312a98c936c0de1e3404893cf095369a26", features = ["serde"] }
|
||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "f1ef57eddb6ffba91bc529e16b5dc39e2aef975c", features = ["serde"] }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1"
|
||||
@@ -8,7 +8,7 @@ publish = false
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "f438e7312a98c936c0de1e3404893cf095369a26", features = ["serde"] }
|
||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "f1ef57eddb6ffba91bc529e16b5dc39e2aef975c", features = ["serde"] }
|
||||
bincode = "1.3"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
console_error_panic_hook = "0.1"
|
||||
|
||||
@@ -10,4 +10,4 @@ crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
ocs_plugin_api = { path = "../ocs_plugin_api", features = ["host"] }
|
||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "f438e7312a98c936c0de1e3404893cf095369a26", features = ["serde"] }
|
||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "f1ef57eddb6ffba91bc529e16b5dc39e2aef975c", features = ["serde"] }
|
||||
+46
-21
@@ -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;
|
||||
}
|
||||
_ => {}
|
||||
|
||||
Reference in new issue
Block a user