Skip to main content

lensbench_core/coating/
remote.rs

1//! フォルダに無い膜のモデルを取る口(拡張の表の欄)
2
3use std::path::{Path, PathBuf};
4
5/// フォルダに無い膜のモデルを取る口(膜ファイルのフォルダ、膜の名前)→ 取ったファイル(`.lbcb` など)
6pub type RemoteLoader = fn(&Path, &str) -> Option<PathBuf>;
7
8/// 拡張の表([`crate::ext::Ext`])の欄: フォルダに無い膜のモデルを取る口
9#[derive(Clone, Copy, Default)]
10pub struct RemoteCoatings(pub Option<RemoteLoader>);
11
12/// [`super::Coatings::load_dir_for`] がフォルダで膜のモデル・実測表を見つけられなかったときに呼ぶ口を、プロセスの既定の
13/// 拡張の表に決める(CLI・GUI の起動時。共有の置き場から取る、lensbench_cad::coat_remote)
14pub fn set_remote_loader(f: RemoteLoader) {
15    crate::ext::update_default(|e| e.slot_mut::<RemoteCoatings>().0 = Some(f));
16}
17
18pub(in crate::coating) fn remote_loader() -> Option<RemoteLoader> {
19    crate::ext::current()
20        .slot::<RemoteCoatings>()
21        .and_then(|r| r.0)
22}
23
24/// 膜ファイルのフォルダから共有の置き場で取れる膜の名前の一覧を返す口(膜の欄の候補。取らずに目録だけ読む)
25pub type RemoteLister = fn(&Path) -> Vec<String>;
26
27/// 拡張の表の欄: 共有の置き場で取れる膜の名前の一覧を返す口
28#[derive(Clone, Copy, Default)]
29pub struct RemoteCoatingNames(pub Option<RemoteLister>);
30
31/// [`super::coat_choices`] が膜ファイルのフォルダの共有の置き場の膜を候補に出す口を、プロセスの既定の拡張の表に
32/// 決める([`set_remote_loader`] と一緒に。lensbench_cad::coat_remote)
33pub fn set_remote_lister(f: RemoteLister) {
34    crate::ext::update_default(|e| e.slot_mut::<RemoteCoatingNames>().0 = Some(f));
35}
36
37pub(in crate::coating) fn remote_lister() -> Option<RemoteLister> {
38    crate::ext::current()
39        .slot::<RemoteCoatingNames>()
40        .and_then(|r| r.0)
41}