11use std:: f64:: consts:: TAU ;
2+ #[ cfg( not( target_arch = "wasm32" ) ) ]
3+ use std:: path:: { Path , PathBuf } ;
24use std:: sync:: Arc ;
35use std:: time:: Duration ;
46#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -16,6 +18,7 @@ use egui_plot::{
1618
1719mod clipboard_import;
1820mod diagnostics;
21+ mod file_import;
1922mod fit_worker;
2023mod formula;
2124mod i18n;
@@ -35,6 +38,8 @@ use self::formula::formula_plain_text;
3538use self :: formula:: model_formula_info;
3639#[ cfg( not( target_arch = "wasm32" ) ) ]
3740use self :: formula:: { formula_svg_bytes, formula_svg_uri} ;
41+ #[ cfg( not( target_arch = "wasm32" ) ) ]
42+ use self :: i18n:: file_import_icon_image;
3843use self :: i18n:: {
3944 actions_icon_image, center_origin_icon_image, clear_icon_image, clipboard_import_icon_image,
4045 family_label, fit_icon_image, fit_to_content_icon_image, github_mark_image,
@@ -115,6 +120,7 @@ const POINTS_PARSE_DEBOUNCE_MS: u64 = 180;
115120const POINTS_HISTORY_LIMIT : usize = 256 ;
116121const POINTS_PARSE_ERROR_PREFIX : & str = "Points parse error: " ;
117122const CLIPBOARD_IMPORT_ERROR_PREFIX : & str = "Clipboard import error: " ;
123+ const FILE_IMPORT_ERROR_PREFIX : & str = "File import error: " ;
118124#[ cfg( target_arch = "wasm32" ) ]
119125const CLIPBOARD_COPY_ERROR_PREFIX : & str = "Clipboard copy error: " ;
120126#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -176,6 +182,14 @@ fn system_locale_tag() -> Option<String> {
176182 web_sys:: window ( ) . and_then ( |window| window. navigator ( ) . language ( ) )
177183}
178184
185+ #[ cfg( not( target_arch = "wasm32" ) ) ]
186+ fn dialog_directory_from_path ( path : & Path ) -> Option < PathBuf > {
187+ if path. is_dir ( ) {
188+ return Some ( path. to_path_buf ( ) ) ;
189+ }
190+ path. parent ( ) . map ( Path :: to_path_buf)
191+ }
192+
179193fn params_to_input_strings ( params : & CurveParams ) -> Vec < String > {
180194 params
181195 . values ( )
@@ -752,6 +766,10 @@ enum WasmFitJob {
752766pub struct CurveFitApp {
753767 points : PointsEditorState ,
754768 #[ cfg( not( target_arch = "wasm32" ) ) ]
769+ points_file_import_dialog : FileDialog ,
770+ #[ cfg( not( target_arch = "wasm32" ) ) ]
771+ points_file_import_last_directory : Option < PathBuf > ,
772+ #[ cfg( not( target_arch = "wasm32" ) ) ]
755773 clipboard_import_request_pending : bool ,
756774 #[ cfg( not( target_arch = "wasm32" ) ) ]
757775 clipboard_import_requested_at : Option < Instant > ,
@@ -816,6 +834,8 @@ pub struct CurveFitApp {
816834 #[ cfg( not( target_arch = "wasm32" ) ) ]
817835 fit_export_file_dialog : FileDialog ,
818836 #[ cfg( not( target_arch = "wasm32" ) ) ]
837+ fit_export_last_directory : Option < PathBuf > ,
838+ #[ cfg( not( target_arch = "wasm32" ) ) ]
819839 fit_export_pending_json : Option < String > ,
820840 fit_preview_params : Option < CurveParams > ,
821841 fit_preview_iteration : Option < u64 > ,
@@ -1463,6 +1483,15 @@ impl Default for CurveFitApp {
14631483 Self {
14641484 points : PointsEditorState :: default ( ) ,
14651485 #[ cfg( not( target_arch = "wasm32" ) ) ]
1486+ points_file_import_dialog : FileDialog :: new ( )
1487+ . title ( "Import points from file" )
1488+ . add_file_filter_extensions ( "Point files" , vec ! [ "csv" , "CSV" , "xlsx" , "XLSX" ] )
1489+ . add_file_filter_extensions ( "CSV files" , vec ! [ "csv" , "CSV" ] )
1490+ . add_file_filter_extensions ( "Excel files" , vec ! [ "xlsx" , "XLSX" ] )
1491+ . default_file_filter ( "Point files" ) ,
1492+ #[ cfg( not( target_arch = "wasm32" ) ) ]
1493+ points_file_import_last_directory : None ,
1494+ #[ cfg( not( target_arch = "wasm32" ) ) ]
14661495 clipboard_import_request_pending : false ,
14671496 #[ cfg( not( target_arch = "wasm32" ) ) ]
14681497 clipboard_import_requested_at : None ,
@@ -1533,6 +1562,8 @@ impl Default for CurveFitApp {
15331562 . default_save_extension ( "JSON files" )
15341563 . default_file_name ( "fit-result.json" ) ,
15351564 #[ cfg( not( target_arch = "wasm32" ) ) ]
1565+ fit_export_last_directory : None ,
1566+ #[ cfg( not( target_arch = "wasm32" ) ) ]
15361567 fit_export_pending_json : None ,
15371568 fit_preview_params : None ,
15381569 fit_preview_iteration : None ,
@@ -1571,6 +1602,8 @@ impl eframe::App for CurveFitApp {
15711602 self . poll_points_clipboard_import ( ctx) ;
15721603 self . poll_clipboard_copy ( ctx) ;
15731604 #[ cfg( not( target_arch = "wasm32" ) ) ]
1605+ self . poll_points_file_import_dialog ( ctx) ;
1606+ #[ cfg( not( target_arch = "wasm32" ) ) ]
15741607 self . poll_fit_export_save_dialog ( ctx) ;
15751608 self . maybe_refresh_points_cache_after_debounce ( ) ;
15761609
0 commit comments