mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-02 20:22:15 -05:00
Save As and Export: write DXF and DWG at the chosen version (#3213)
EXPORT ignored the version and always wrote the version the drawing was read in, and the Save dialog passed the Default Save Format version only for drawings with no file yet, so an opened 2013 DXF could not be written as 2000. EXPORT now takes SAVEAS's version and binary options for DXF and DWG (other formats refuse them). The Save and Export dialogs share one helper that passes the Default Save Format version for every .dxf or .dwg path, an opened drawing's too. An export leaves the drawing's own version and name alone, and QSAVE still keeps the file's version. The message shown when the version is picked names Save As and Export and goes through the translation system.
This commit is contained in:
1 parent
32ad922df5
commit
50d2fd0c77
12 files changed
+216
-35
No files matched your search
@@ -94,9 +94,9 @@
|
||||
untested, 2018 tested only on synthetic files) open through the open-source acadrust library
|
||||
and save as 2000 through 2018. New drawings default to
|
||||
2018 (AC1032) in both formats. In the app's Save dialog, File ▸ Default Save Format
|
||||
(also Options ▸ Open and Save, `saveVersion`, default 2018) sets the version for untitled
|
||||
drawings; drawings with a file keep their own version, subject to supported-version mapping
|
||||
and the DWG minimum. SAVEAS `version` overrides this choice and is remembered for later
|
||||
(also Options ▸ Open and Save, `saveVersion`, default 2018) sets the version Save As and
|
||||
Export write, for opened drawings too; Save (QSAVE) of an opened file keeps its own version,
|
||||
subject to supported-version mapping and the DWG minimum. SAVEAS `version` overrides this choice and is remembered for later
|
||||
saves. Export to SVG and PNG today.
|
||||
- **Fast and native.** Pure Rust and egui, no Electron, no web view. One binary on macOS
|
||||
(universal), Windows, Linux and FreeBSD, plus a WebAssembly build for the browser.
|
||||
@@ -120,7 +120,7 @@ numbers):
|
||||
| Layers & properties | Layers palette and Layer Properties Manager (on/off, freeze, lock, plot, colour, linetype), layer tools (isolate, freeze, off, lock, match, previous), Properties palette with per-object editing, linetypes, lineweights, colour index and true colour |
|
||||
| Annotation | All DIM* commands with full DIMSTYLE variables, overrides and every arrowhead, associative dimensions that follow geometry, MLEADER, TABLE, TrueType fonts (`.ttf`, `.otf`, `.ttc` collections), MTEXT formatting codes (fonts, heights, colours, stacked fractions), our own single-stroke drafting font |
|
||||
| Hatch & blocks | Pick-point hatch boundaries with islands, pattern, solid and gradient fills from our own pattern library, BLOCK/INSERT, attributes and nested blocks |
|
||||
| Files | DXF read (R12–2018, binary from R13) and write (2000–2018, ASCII and binary), including dimension styles, associativity, tables and constraints; DWG read (via the acadrust library; R13 and R14 untested, 2018 tested only on synthetic files) and write (2000–2018). New drawings save as 2018 (AC1032); opened drawings keep their supported version, except DWG defaults to at least 2004. In the app's Save dialog, File ▸ Default Save Format (also Options ▸ Open and Save, `saveVersion`, default 2018) sets the version for untitled drawings; drawings with a file keep their own version, subject to supported-version mapping and the DWG minimum. SAVEAS `version` overrides this choice and is remembered for later saves. DXF uses R2000 structure with the chosen `$ACADVER`. PDF plotting, SVG and PNG export. Entities CADCraft doesn't model yet are not kept on save: see [file-format parity](docs/file-format-parity.md) for version selection and fidelity |
|
||||
| Files | DXF read (R12–2018, binary from R13) and write (2000–2018, ASCII and binary), including dimension styles, associativity, tables and constraints; DWG read (via the acadrust library; R13 and R14 untested, 2018 tested only on synthetic files) and write (2000–2018). New drawings save as 2018 (AC1032); opened drawings keep their supported version, except DWG defaults to at least 2004. In the app's Save dialog, File ▸ Default Save Format (also Options ▸ Open and Save, `saveVersion`, default 2018) sets the version Save As and Export write, for opened drawings too; Save (QSAVE) of an opened file keeps its own version, subject to supported-version mapping and the DWG minimum. SAVEAS `version` overrides this choice and is remembered for later saves. DXF uses R2000 structure with the chosen `$ACADVER`. PDF plotting, SVG and PNG export. Entities CADCraft doesn't model yet are not kept on save: see [file-format parity](docs/file-format-parity.md) for version selection and fidelity |
|
||||
| Layouts & plotting | Paper-space layouts, viewports (scale, lock, per-viewport layer freeze), MSPACE/PSPACE through viewports, page setups, PLOT and EXPORTPDF |
|
||||
| Parametric | Geometric and dimensional constraints, AUTOCONSTRAIN, PARAMETERS with expressions, conflict detection; constraints re-solve after every edit |
|
||||
| Grips | Hot grips with Space to cycle Stretch, Move, Rotate, Scale and Mirror |
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
CommandSpec::new("export", "Export...", run_export)
|
||||
.menu(&["File", "Export..."])
|
||||
.alias(&["exp"])
|
||||
.params("{path? (else returns base64 `data`), format?: dxf|dwg|svg|png|pdf (default: the path's extension)} → {format, bytes, path? | data, warnings?: what an image draws short of the drawing}")
|
||||
.params("{path? (else returns base64 `data`), format?: dxf|dwg|svg|png|pdf (default: the path's extension), version?: 2000|2004|2007|2010|2013|2018 (DXF and DWG; default: the drawing's own), binary?: false (DXF only)} → {format, bytes, version? (DXF and DWG), path? | data, warnings?: what an image draws short of the drawing}")
|
||||
.noundo(),
|
||||
CommandSpec::new("preview", "Plot Preview", run_preview)
|
||||
.menu(&["File", "Plot Preview"])
|
||||
@@ -123,7 +123,23 @@ fn run_export(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
return Err(bad("export", "`format` must be dxf, dwg, svg, png or pdf (or give a `path` with one of those extensions)"));
|
||||
}
|
||||
let file = format!("export.{format}");
|
||||
let (bytes, notes) = super::file::write_noted(hooks, s.doc()?, &file).map_err(|e| bad("export", e))?;
|
||||
// DXF and DWG take SAVEAS's version and binary options; the drawing keeps its own version and
|
||||
// name (an export is not a save).
|
||||
let opts = super::file::save_options("export", p)?;
|
||||
let drawing_format = matches!(format.as_str(), "dxf" | "dwg");
|
||||
if opts.version.is_some() && !drawing_format {
|
||||
return Err(bad("export", "`version` applies to DXF and DWG files only"));
|
||||
}
|
||||
if opts.binary && format != "dxf" {
|
||||
return Err(bad("export", "`binary` applies to DXF files only"));
|
||||
}
|
||||
let (bytes, notes) = if opts.version.is_some() || opts.binary {
|
||||
let w =
|
||||
super::file::write_as().ok_or_else(|| bad("export", "exporting at a chosen version or as binary DXF is not available in this build"))?;
|
||||
(w(s.doc()?, &file, &opts).map_err(|e| bad("export", e))?, Vec::new())
|
||||
} else {
|
||||
super::file::write_noted(hooks, s.doc()?, &file).map_err(|e| bad("export", e))?
|
||||
};
|
||||
let folder = path.and_then(super::file::new_folder);
|
||||
let mut r = match path {
|
||||
Some(path) => {
|
||||
@@ -132,8 +148,11 @@ fn run_export(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
None => json!({ "data": base64_encode(&bytes), "format": format, "bytes": bytes.len() }),
|
||||
};
|
||||
if let (Some(v), Some(o)) = (opts.version, r.as_object_mut()) {
|
||||
o.insert("version".into(), json!(v.year()));
|
||||
}
|
||||
super::file::report_new_folder(s, &mut r, folder);
|
||||
super::file::report_loss(s, &mut r, &file);
|
||||
super::file::report_loss(s, &mut r, &file, opts.version);
|
||||
super::file::report_notes(s, &mut r, notes);
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ fn version_list() -> String {
|
||||
|
||||
/// The `version` and `binary` parameters of a save: a version is a year (2018 or "2018"), "R2018"
|
||||
/// or an `$ACADVER` code ("AC1032").
|
||||
fn save_options(cmd: &str, p: &Value) -> Result<SaveAs> {
|
||||
pub(super) fn save_options(cmd: &str, p: &Value) -> Result<SaveAs> {
|
||||
let version = match p.get("version") {
|
||||
None | Some(Value::Null) => None,
|
||||
Some(v) => {
|
||||
@@ -1090,10 +1090,10 @@ pub(crate) fn lost_writing(d: &Drawing, path: &str, version: Version) -> std::co
|
||||
}
|
||||
|
||||
/// Report what the file `path`, just written from the active document (what EXPORT writes: the
|
||||
/// block while the Block Editor is open) at its own version, left out.
|
||||
pub(super) fn report_loss(s: &mut Session, r: &mut Value, path: &str) {
|
||||
/// block while the Block Editor is open) at version `asked` (else its own), left out.
|
||||
pub(super) fn report_loss(s: &mut Session, r: &mut Value, path: &str, asked: Option<Version>) {
|
||||
let Ok(d) = s.doc() else { return };
|
||||
let version = own_version(d, path);
|
||||
let version = asked.unwrap_or_else(|| own_version(d, path));
|
||||
let lost = lost_writing(d, path, version);
|
||||
let notes = if drops_unknown(path) { dwg_notes(d) } else { Vec::new() };
|
||||
report_lost(s, r, path, version, &lost);
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
//! #3213, with the real DXF and DWG readers and writers: a drawing read from a 2013 DXF (AC1027)
|
||||
//! exported or saved as a 2000 DXF or DWG says AC1015, and a plain export keeps the drawing's own
|
||||
//! version.
|
||||
//!
|
||||
//! In its own test binary, not `tests/it`, because it installs the real io hooks. The hooks are
|
||||
//! process-wide and set once (`set_io` and `set_write_as` keep the first value), so in `tests/it`
|
||||
//! they would change what the other tests' saves, exports and opens do, by test order. They also
|
||||
//! cannot share a binary with `save_version.rs`, whose stub writer must be the one installed.
|
||||
|
||||
use cadcraft_engine::Session;
|
||||
use cadcraft_engine::cmd::file::{IoHooks, base64_decode, set_io, set_write_as};
|
||||
use cadcraft_engine::doc::EntityKind;
|
||||
use serde_json::json;
|
||||
|
||||
#[path = "support/temp_dir.rs"]
|
||||
mod temp_dir;
|
||||
|
||||
use temp_dir::TempDir;
|
||||
|
||||
fn install() {
|
||||
set_io(IoHooks {
|
||||
read: |b, name| cadcraft_io::read(b, name).map_err(|e| e.to_string()),
|
||||
write: |d, name| cadcraft_io::write(d, name).map_err(|e| e.to_string()),
|
||||
plot: None,
|
||||
});
|
||||
set_write_as(|d, name, o| {
|
||||
cadcraft_io::write_with(d, name, &cadcraft_io::SaveOptions { version: o.version, binary: o.binary }).map_err(|e| e.to_string())
|
||||
});
|
||||
}
|
||||
|
||||
/// The `$ACADVER` an exported DXF declares.
|
||||
fn acadver(r: &serde_json::Value) -> String {
|
||||
header_version(&String::from_utf8(base64_decode(r["data"].as_str().unwrap()).unwrap()).unwrap())
|
||||
}
|
||||
|
||||
/// The version a DWG file's bytes open with ("AC1015" for 2000).
|
||||
fn dwg_version(bytes: &[u8]) -> String {
|
||||
String::from_utf8_lossy(bytes.get(..6).unwrap_or_default()).into_owned()
|
||||
}
|
||||
|
||||
/// The radii of the circles in the active drawing.
|
||||
fn radii(s: &Session) -> Vec<f64> {
|
||||
s.doc().unwrap().model.iter().filter_map(|e| if let EntityKind::Circle(c) = &e.kind { Some(c.radius) } else { None }).collect()
|
||||
}
|
||||
|
||||
/// The `$ACADVER` in the header of the DXF text `text`.
|
||||
fn header_version(text: &str) -> String {
|
||||
let mut lines = text.lines().map(str::trim);
|
||||
while let Some(l) = lines.next() {
|
||||
if l == "$ACADVER" {
|
||||
lines.next();
|
||||
return lines.next().unwrap_or_default().to_string();
|
||||
}
|
||||
}
|
||||
String::new()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_2013_drawing_exports_as_a_2000_dxf() {
|
||||
install();
|
||||
// Removed when the test ends, even when an assertion fails.
|
||||
let dir = TempDir::new("export-version");
|
||||
let file = dir.path_str("plan.dxf");
|
||||
let mut s = Session::new();
|
||||
s.cmdline("circle 0,0 5").unwrap();
|
||||
s.execute("saveas", &json!({ "path": file, "version": "2013" })).unwrap();
|
||||
s.execute("open", &json!({ "path": file })).unwrap();
|
||||
|
||||
assert_eq!(acadver(&s.execute("export", &json!({ "format": "dxf" })).unwrap()), "AC1027");
|
||||
assert_eq!(acadver(&s.execute("export", &json!({ "format": "dxf", "version": "2000" })).unwrap()), "AC1015");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_2013_drawing_saved_as_2000_says_ac1015() {
|
||||
install();
|
||||
let dir = TempDir::new("saveas-version");
|
||||
let (file, copy) = (dir.path_str("plan.dxf"), dir.path_str("plan-2000.dxf"));
|
||||
let mut s = Session::new();
|
||||
s.cmdline("circle 0,0 5").unwrap();
|
||||
s.execute("saveas", &json!({ "path": file, "version": "2013" })).unwrap();
|
||||
s.execute("open", &json!({ "path": file })).unwrap();
|
||||
|
||||
s.execute("saveas", &json!({ "path": copy, "version": "2000" })).unwrap();
|
||||
assert_eq!(header_version(&std::fs::read_to_string(©).unwrap()), "AC1015");
|
||||
}
|
||||
|
||||
/// The DWG writer itself writes the chosen version: the file opens with AC1015, not the 2013
|
||||
/// drawing's AC1027, and reads back with its circle.
|
||||
#[test]
|
||||
fn a_2013_drawing_exports_and_saves_as_a_2000_dwg() {
|
||||
install();
|
||||
// The drawing is the test's own, so the DWG conversion may run in this process.
|
||||
cadcraft_io::dwg_worker::allow_in_process();
|
||||
let dir = TempDir::new("dwg-version");
|
||||
let (file, copy) = (dir.path_str("plan.dxf"), dir.path_str("plan-2000.dwg"));
|
||||
let mut s = Session::new();
|
||||
s.cmdline("circle 0,0 5").unwrap();
|
||||
s.execute("saveas", &json!({ "path": file, "version": "2013" })).unwrap();
|
||||
s.execute("open", &json!({ "path": file })).unwrap();
|
||||
|
||||
let exported = |s: &mut Session, p: serde_json::Value| base64_decode(s.execute("export", &p).unwrap()["data"].as_str().unwrap()).unwrap();
|
||||
assert_eq!(dwg_version(&exported(&mut s, json!({ "format": "dwg" }))), "AC1027");
|
||||
assert_eq!(dwg_version(&exported(&mut s, json!({ "format": "dwg", "version": "2000" }))), "AC1015");
|
||||
|
||||
s.execute("saveas", &json!({ "path": copy, "version": "2000" })).unwrap();
|
||||
assert_eq!(dwg_version(&std::fs::read(©).unwrap()), "AC1015");
|
||||
s.execute("open", &json!({ "path": copy })).unwrap();
|
||||
assert_eq!(radii(&s), [5.0]);
|
||||
}
|
||||
@@ -96,3 +96,32 @@ fn opening_binary_dxf_keeps_it_binary() {
|
||||
assert!(!s.state().unwrap().binary_dxf);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// #3213: EXPORT to DXF or DWG takes the same version and binary options; the drawing keeps its
|
||||
/// own version and name, and other formats refuse a version.
|
||||
#[test]
|
||||
fn export_takes_the_version_and_binary_options() {
|
||||
install();
|
||||
let mut s = Session::new();
|
||||
s.cmdline("circle 0,0 5").unwrap();
|
||||
let data = |r: &serde_json::Value| String::from_utf8(base64_decode(r["data"].as_str().unwrap()).unwrap()).unwrap();
|
||||
|
||||
let r = s.execute("export", &json!({ "format": "dxf", "version": "2000" })).unwrap();
|
||||
assert_eq!(data(&r), "2000|false");
|
||||
assert_eq!(r["version"], json!("2000"));
|
||||
assert_eq!(acadver(&s).as_deref(), Some("AC1032"), "an export leaves the drawing's version alone");
|
||||
let r = s.execute("export", &json!({ "format": "dwg", "version": 2004 })).unwrap();
|
||||
assert_eq!(data(&r), "2004|false");
|
||||
let r = s.execute("export", &json!({ "format": "dxf", "binary": true })).unwrap();
|
||||
assert_eq!(data(&r), "-|true");
|
||||
// Without options: the plain writer, at the drawing's own version.
|
||||
let r = s.execute("export", &json!({ "format": "dxf" })).unwrap();
|
||||
assert_eq!(data(&r), "plain");
|
||||
assert!(r.get("version").is_none());
|
||||
|
||||
let err = |s: &mut Session, p: serde_json::Value| s.execute("export", &p).unwrap_err().to_string();
|
||||
assert!(err(&mut s, json!({ "format": "svg", "version": "2000" })).contains("DXF and DWG"));
|
||||
assert!(err(&mut s, json!({ "format": "dwg", "binary": true })).contains("DXF"));
|
||||
assert!(err(&mut s, json!({ "format": "dxf", "version": "2005" })).contains("unknown version"));
|
||||
assert!(s.state().unwrap().path.is_none(), "the drawing keeps its name");
|
||||
}
|
||||
@@ -52,7 +52,10 @@ pub fn route(app: &mut CadApp, id: &str) -> Result<Value, String> {
|
||||
.pick_then(Pick::Save(format!("{stem}.pdf")), |app, path| app.run("publish", json!({ "path": path })))
|
||||
.unwrap_or_else(|| no_picker(app, "PUBLISH", "publish {}")),
|
||||
_ => app
|
||||
.pick_then(Pick::Save(format!("{stem}.svg")), |app, path| app.run("export", json!({ "path": path })))
|
||||
.pick_then(Pick::Save(format!("{stem}.svg")), |app, path| {
|
||||
let params = version_params(&app.ui, &path);
|
||||
app.run("export", params)
|
||||
})
|
||||
.unwrap_or_else(|| no_picker(app, "EXPORT", r#"export {"format": "svg"}"#)),
|
||||
}
|
||||
}
|
||||
@@ -153,6 +156,17 @@ pub fn pdf_dialog(app: &mut CadApp, ctx: &egui::Context, open: &mut bool) {
|
||||
}
|
||||
}
|
||||
|
||||
/// SAVEAS or EXPORT parameters for a path picked in the Save or Export dialog: a DXF or DWG file is
|
||||
/// written in the version chosen under File ▸ Default Save Format (#3213), whatever version the
|
||||
/// drawing was read in; other formats have no version.
|
||||
pub(crate) fn version_params(ui: &crate::UiState, path: &str) -> Value {
|
||||
let drawing_file = matches!(cadcraft_doc::Format::from_path(path), Some(cadcraft_doc::Format::Dxf | cadcraft_doc::Format::Dwg));
|
||||
match crate::SaveVersion::parse(&ui.save_version) {
|
||||
Some(v) if drawing_file => json!({ "path": path, "version": v.year() }),
|
||||
_ => json!({ "path": path }),
|
||||
}
|
||||
}
|
||||
|
||||
fn no_picker(app: &mut CadApp, name: &str, example: &str) -> Result<Value, String> {
|
||||
let msg = format!("{name}: there is no file dialog here; run it with parameters, e.g. {example}");
|
||||
app.session.echo(msg.clone());
|
||||
@@ -350,6 +364,17 @@ mod tests {
|
||||
(CadApp::new(Session::new(), services), asked, answer)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn export_writes_drawing_files_in_the_default_save_version() {
|
||||
// #3213: File ▸ Default Save Format ▸ 2000 makes Export write an R2000 DXF or DWG.
|
||||
let ui = crate::UiState { save_version: "2000".into(), ..crate::UiState::default() };
|
||||
assert_eq!(super::version_params(&ui, "/tmp/plan.dxf"), json!({ "path": "/tmp/plan.dxf", "version": "2000" }));
|
||||
assert_eq!(super::version_params(&ui, "/tmp/plan.DWG"), json!({ "path": "/tmp/plan.DWG", "version": "2000" }));
|
||||
// Images and PDF have no version.
|
||||
assert_eq!(super::version_params(&ui, "/tmp/plan.svg"), json!({ "path": "/tmp/plan.svg" }));
|
||||
assert_eq!(super::version_params(&ui, "/tmp/plan.pdf"), json!({ "path": "/tmp/plan.pdf" }));
|
||||
}
|
||||
|
||||
fn status(app: &CadApp) -> &str {
|
||||
app.status.as_ref().map(|(s, _)| s.as_str()).unwrap_or_default()
|
||||
}
|
||||
|
||||
@@ -137,8 +137,8 @@ pub struct UiState {
|
||||
pub animations: animation::AnimationPref,
|
||||
/// The format Save As suggests: "dxf" or "dwg", for new drawings and opened files alike.
|
||||
pub save_format: SaveFormat,
|
||||
/// The version Save As writes for a drawing that has no file yet ("2000" … "2018"); a
|
||||
/// drawing opened from a file keeps that file's version.
|
||||
/// The version ("2000" … "2018") Save As and Export write DXF and DWG files in, for every
|
||||
/// drawing, an opened one too. Save (QSAVE) of an opened file keeps that file's version.
|
||||
pub save_version: String,
|
||||
/// Drawings opened from a path, newest first (File ▸ Open Recent and the Start page).
|
||||
pub recent_files: Vec<String>,
|
||||
|
||||
@@ -247,7 +247,7 @@ fn run_preference_command(app: &mut CadApp, id: &str, params: &Value) -> Option<
|
||||
},
|
||||
None => Ok(json!({ "saveFormat": app.ui.save_format.as_str() })),
|
||||
},
|
||||
// `{"version": "2000"…"2018"}` sets the version new drawings are saved in; without it,
|
||||
// `{"version": "2000"…"2018"}` sets the version Save As and Export write; without it,
|
||||
// reports it.
|
||||
id if id.starts_with("ui.saveversion") => {
|
||||
let name = id
|
||||
@@ -258,7 +258,7 @@ fn run_preference_command(app: &mut CadApp, id: &str, params: &Value) -> Option<
|
||||
Some(name) => match crate::SaveVersion::parse(&name) {
|
||||
Some(v) => {
|
||||
app.ui.save_version = v.year().to_string();
|
||||
app.session.echo(format!("New drawings will be saved as version {v}"));
|
||||
app.session.echo(crate::tf!("Save As and Export will write DXF and DWG files as version {version}", version = v));
|
||||
Ok(json!({ "saveVersion": app.ui.save_version }))
|
||||
}
|
||||
None => Err(format!("unknown version \"{}\" (2000, 2004, 2007, 2010, 2013 or 2018)", name.chars().take(40).collect::<String>())),
|
||||
@@ -472,7 +472,7 @@ fn run_ui_command_inner(app: &mut CadApp, id: &str, params: &Value) -> Option<Re
|
||||
let name = format.suggested_name(title.as_deref());
|
||||
// Bound to this drawing: the answer saves it, not whichever drawing is active then.
|
||||
app.pick_then(Pick::Save(name), |app, p| {
|
||||
app.session.execute("saveas", &saveas_params(&app.ui, &app.session, &p)).map_err(|e| e.to_string())
|
||||
app.session.execute("saveas", &crate::exchange::version_params(&app.ui, &p)).map_err(|e| e.to_string())
|
||||
})
|
||||
.unwrap_or(Ok(Value::Null))
|
||||
}
|
||||
@@ -642,16 +642,6 @@ fn suggested_save_format(params: &Value, default: crate::SaveFormat) -> Result<c
|
||||
})
|
||||
}
|
||||
|
||||
/// SAVEAS parameters for a path picked in the Save dialog: a drawing that has no file yet is saved
|
||||
/// in the default save version; one opened from a file keeps that file's version.
|
||||
fn saveas_params(ui: &crate::UiState, session: &cadcraft_engine::Session, path: &str) -> Value {
|
||||
let untitled = session.state().is_ok_and(|s| s.path.is_none());
|
||||
match crate::SaveVersion::parse(&ui.save_version) {
|
||||
Some(v) if untitled => json!({ "path": path, "version": v.year() }),
|
||||
_ => json!({ "path": path }),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_save_format(app: &mut CadApp, format: crate::SaveFormat) -> Value {
|
||||
app.ui.save_format = format;
|
||||
app.session.echo(format!("Save As will suggest {}", format.as_str().to_ascii_uppercase()));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! The default save version (#421): File > Default Save Format > Version …, kept in the
|
||||
//! preferences, applied by the Save dialog to drawings that have no file yet.
|
||||
//! preferences, applied by the Save dialog to every drawing, an opened one too (#3213).
|
||||
|
||||
use cadcraft_engine::Session;
|
||||
use cadcraft_engine::cmd::file::{IoHooks, SaveAs, set_io, set_write_as};
|
||||
@@ -28,8 +28,14 @@ fn default_save_version_applies_to_new_drawings_and_persists() {
|
||||
// The Save dialog saves an untitled drawing in the default version …
|
||||
app.run("ui.saveas", Value::Null).unwrap();
|
||||
assert_eq!(std::fs::read(picked()).unwrap(), b"2010|false");
|
||||
// … and a drawing that has a file in its own.
|
||||
// … and a drawing that has a file too, in the version picked since (#3213) …
|
||||
app.run("ui.saveversion", json!({ "version": 2000 })).unwrap();
|
||||
let said = app.session.log.last().cloned().unwrap_or_default();
|
||||
assert!(said.starts_with("Save As and Export will write DXF and DWG files as version"), "{said}");
|
||||
app.run("ui.saveas", Value::Null).unwrap();
|
||||
assert_eq!(std::fs::read(picked()).unwrap(), b"2000|false");
|
||||
// … while Save keeps the file's version.
|
||||
app.run("qsave", json!({})).unwrap();
|
||||
assert_eq!(std::fs::read(picked()).unwrap(), b"plain");
|
||||
let _ = std::fs::remove_file(picked());
|
||||
|
||||
|
||||
@@ -67,8 +67,9 @@ DXF is the native path: `dxf` parses tags, `io::dxf_read` maps them to the docum
|
||||
`io::dxf_write` uses R2000 DXF structure with the chosen version's `$ACADVER` (2000–2018),
|
||||
version-specific groups and UTF-8 text from 2007. New drawings default to 2018 (AC1032).
|
||||
In the app's Save dialog, File ▸ Default Save Format (also Options ▸ Open and Save,
|
||||
`saveVersion`, default 2018) sets the version for untitled drawings; drawings with a file keep
|
||||
their own version, subject to supported-version mapping and the DWG minimum. SAVEAS `version`
|
||||
`saveVersion`, default 2018) sets the version Save As and Export write, for opened drawings
|
||||
too; Save (QSAVE) of an opened file keeps its own version,
|
||||
subject to supported-version mapping and the DWG minimum. SAVEAS `version`
|
||||
overrides this choice and is remembered for later saves.
|
||||
Without an explicit save version, `io::save_version` uses the drawing's `$ACADVER`, keeping
|
||||
supported versions, mapping older files to 2000 and newer files to 2018 (missing or invalid
|
||||
|
||||
@@ -69,8 +69,9 @@ and DWG. Without an explicit save version, `io::save_version` keeps an opened dr
|
||||
or invalid code defaults to 2018 (`crates/io/src/lib.rs`, `crates/dxf/src/version.rs`). DWG
|
||||
uses the version carried through its DXF read bridge, with the 2004 minimum described above.
|
||||
In the app's Save dialog, File ▸ Default Save Format (also Options ▸ Open and Save,
|
||||
`saveVersion`, default 2018) sets the version for untitled drawings; drawings with a file keep
|
||||
their own version, subject to supported-version mapping and the DWG minimum.
|
||||
`saveVersion`, default 2018) sets the version Save As and Export write, for opened drawings
|
||||
too; Save (QSAVE) of an opened file keeps its own version,
|
||||
subject to supported-version mapping and the DWG minimum.
|
||||
CLI, script and engine SAVEAS/QSAVE JSON saves do not read this UI preference; MCP honours it only when
|
||||
driving the app's Save dialog.
|
||||
SAVEAS `version` overrides this choice and remembers it for later saves. DXF output uses
|
||||
|
||||
@@ -205,8 +205,9 @@ rows for localization, ecosystem, platforms, stability or AI. The weighted figur
|
||||
depth both grew since 2026-10-07 and the weights are now written down; the hours rose because
|
||||
the remaining work is depth and 3D.
|
||||
In the app's Save dialog, File ▸ Default Save Format (also Options ▸ Open and Save,
|
||||
`saveVersion`, default 2018) sets the version for untitled drawings; drawings with a file keep
|
||||
their own version, subject to supported-version mapping and the DWG minimum. SAVEAS `version`
|
||||
`saveVersion`, default 2018) sets the version Save As and Export write, for opened drawings
|
||||
too; Save (QSAVE) of an opened file keeps its own version,
|
||||
subject to supported-version mapping and the DWG minimum. SAVEAS `version`
|
||||
overrides this choice and is remembered for later saves.
|
||||
|
||||
**Parallelism.** About 70% of the work splits across 4–6 agents by area (each feature area,
|
||||
|
||||
Reference in new issue
Block a user