forked from 1b-agent/opencadstudio-upstream
web: enable STL/STEP export and OBJ import, drag-and-drop open
STLOUT/STEPOUT wrote via std::fs and IMPORTOBJ read via std::fs, all
of which fail on wasm32. The export pickers now mirror the PDF path
(pick_*_owned returns a name-only PathBuf; the browser download names
the file) and the write tail swaps fs::write for sys::download_bytes.
OBJ import reads the picked file's bytes directly, like the web open
picker.
Opening by drag-and-drop was dead on the web build: winit never emits
FileDropped there. A wasm-gated io::web_drop module installs DOM
dragover/drop listeners, filters .dwg/.dxf, reads the File bytes
async, and queues them; the existing 50 ms PollWebControl tick drains
the queue into the same open path the picker uses (progress overlay,
recovery, OPFS recent cache).
Also floors the model-space plot sheet: extents smaller than 10 mm
(or the 0x0 paper a fresh unsaved drawing carries) now fall back to
the standard sheet instead of producing a ~3 pt page.
(cherry picked from commit ad60be11ed)
This commit is contained in:
1 parent
112060e370
commit
6cb8c00fa0
8 files changed
+332
-36
No files matched your search
+22
-8
@@ -4395,19 +4395,33 @@ impl OpenCADStudio {
|
||||
}
|
||||
|
||||
// Model space keeps its established extents + 5% margin behaviour.
|
||||
// A sheet edge below this floor (drawing with tiny extents, or the
|
||||
// 0×0 paper a fresh unsaved drawing carries) cannot be previewed,
|
||||
// printed, or measured meaningfully; the standard-sheet fallback
|
||||
// keeps the output a real page instead of a speck.
|
||||
const MIN_MODEL_SHEET_MM: f64 = 10.0;
|
||||
let standard_sheet = {
|
||||
let (w, h) = selected_sheet;
|
||||
(w.min(h) >= MIN_MODEL_SHEET_MM).then_some((w, h))
|
||||
};
|
||||
let (page_w, page_h, offset_x, offset_y) =
|
||||
if let Some((min, max)) = scene.model_space_extents() {
|
||||
let margin = 1.05_f64;
|
||||
let width = ((max.x - min.x) as f64 * margin).max(1.0);
|
||||
let height = ((max.y - min.y) as f64 * margin).max(1.0);
|
||||
let pad_x = (width - (max.x - min.x) as f64) * 0.5;
|
||||
let pad_y = (height - (max.y - min.y) as f64) * 0.5;
|
||||
(
|
||||
width,
|
||||
height,
|
||||
-(min.x as f64) + pad_x,
|
||||
-(min.y as f64) + pad_y,
|
||||
)
|
||||
if width < MIN_MODEL_SHEET_MM || height < MIN_MODEL_SHEET_MM {
|
||||
let (w, h) = standard_sheet.unwrap_or((297.0, 210.0));
|
||||
(w, h, -min.x as f64, -min.y as f64)
|
||||
} else {
|
||||
let pad_x = (width - (max.x - min.x) as f64) * 0.5;
|
||||
let pad_y = (height - (max.y - min.y) as f64) * 0.5;
|
||||
(
|
||||
width,
|
||||
height,
|
||||
-(min.x as f64) + pad_x,
|
||||
-(min.y as f64) + pad_y,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
(297.0, 210.0, 0.0, 0.0)
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user