forked from 1b-agent/opencadstudio-upstream
fix(io): prevent lossy Save As
Use the verified acadifc round-trip fixes and warn for every unsupported object or entity the selected format would drop.
This commit is contained in:
1 parent
bca65600cd
commit
a22681e751
3 files changed
+64
-16
No files matched your search
+61
-14
@@ -477,26 +477,73 @@ pub fn dropped_on_save_count(
|
||||
target_version: acadrust::DxfVersion,
|
||||
is_dxf: bool,
|
||||
) -> usize {
|
||||
if !is_dxf && target_version == doc.version {
|
||||
return 0;
|
||||
}
|
||||
let mut n = doc
|
||||
.objects
|
||||
.values()
|
||||
.filter(|o| {
|
||||
matches!(
|
||||
o,
|
||||
acadrust::objects::ObjectType::Unknown { raw_dwg_data: Some(_), .. }
|
||||
)
|
||||
.filter(|object| match object {
|
||||
acadrust::objects::ObjectType::Unknown {
|
||||
raw_dxf_codes,
|
||||
raw_dwg_data,
|
||||
raw_dwg_version,
|
||||
..
|
||||
} => {
|
||||
if is_dxf {
|
||||
raw_dxf_codes.is_none()
|
||||
} else {
|
||||
raw_dwg_data.is_none()
|
||||
|| raw_dwg_version.is_some_and(|source| source != target_version)
|
||||
}
|
||||
}
|
||||
acadrust::objects::ObjectType::GeoData(_)
|
||||
| acadrust::objects::ObjectType::VisualStyle(_)
|
||||
| acadrust::objects::ObjectType::Material(_)
|
||||
| acadrust::objects::ObjectType::TableStyle(_) => !is_dxf,
|
||||
_ => false,
|
||||
})
|
||||
.count();
|
||||
for e in doc.entities() {
|
||||
if matches!(
|
||||
e,
|
||||
acadrust::EntityType::Unknown(_)
|
||||
| acadrust::EntityType::SectionSymbol(_)
|
||||
| acadrust::EntityType::ViewBorder(_)
|
||||
) {
|
||||
let dropped = match e {
|
||||
acadrust::EntityType::Unknown(entity) => {
|
||||
if is_dxf {
|
||||
entity.raw_dxf_codes.is_none()
|
||||
} else {
|
||||
entity.raw_dwg_data.is_none()
|
||||
|| entity
|
||||
.dwg_source_version
|
||||
.is_some_and(|source| source != target_version)
|
||||
}
|
||||
}
|
||||
acadrust::EntityType::Surface(entity) => {
|
||||
is_dxf
|
||||
|| entity.raw_dwg_data.is_none()
|
||||
|| entity
|
||||
.dwg_source_version
|
||||
.is_some_and(|source| source != target_version)
|
||||
}
|
||||
acadrust::EntityType::Light(entity) => {
|
||||
is_dxf
|
||||
|| entity.raw_dwg_data.is_none()
|
||||
|| entity
|
||||
.dwg_source_version
|
||||
.is_some_and(|source| source != target_version)
|
||||
}
|
||||
acadrust::EntityType::SectionSymbol(entity) => {
|
||||
is_dxf
|
||||
|| entity.raw_dwg_data.is_none()
|
||||
|| entity
|
||||
.dwg_source_version
|
||||
.is_some_and(|source| source != target_version)
|
||||
}
|
||||
acadrust::EntityType::ViewBorder(entity) => {
|
||||
is_dxf
|
||||
|| entity.raw_dwg_data.is_none()
|
||||
|| entity
|
||||
.dwg_source_version
|
||||
.is_some_and(|source| source != target_version)
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
if dropped {
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user