Skip to main content

lensbench_project/
catalog_spec.rs

1//! カタログの品の種類・名前の決まった仕様・ほかのカタログへ足す中身(ユーザーカタログの形の一部)。
2//!
3//! ユーザーカタログ([`crate::UserCatalog`])の品は `kind`・`url`・`specs`・`tags`・出典を持てる。
4//! カタログ全体の `url_template` と `overlay` は、同じメーカーのほかのカタログ(ZMF・.zmx の玉など)の品にも
5//! 仕様とリンクを足す(元のファイルは書き換えない)。足し方・仕様での絞り込み・検索は lensbench-catalog。
6
7use schemars::JsonSchema;
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10use std::collections::BTreeMap;
11
12/// 品の種類(一覧での分類。ブロックの種類とは別: ウィンドウ・偏光子も今は玉・面の並びのブロックで書ける)
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
14#[serde(rename_all = "lowercase")]
15pub enum ItemKind {
16    Lens,
17    Mirror,
18    Splitter,
19    Polarizer,
20    Waveplate,
21    Window,
22    Filter,
23    Prism,
24    /// レンズチューブ(機構)
25    Tube,
26    /// ケージ板
27    #[serde(rename = "cage_plate")]
28    CagePlate,
29    /// マウント(素子の保持)
30    Mount,
31    /// ケージのロッド
32    Rod,
33    /// アダプタ・スペーサ・止め輪など
34    Adapter,
35    Other,
36}
37
38impl ItemKind {
39    pub fn as_str(self) -> &'static str {
40        match self {
41            ItemKind::Lens => "lens",
42            ItemKind::Mirror => "mirror",
43            ItemKind::Splitter => "splitter",
44            ItemKind::Polarizer => "polarizer",
45            ItemKind::Waveplate => "waveplate",
46            ItemKind::Window => "window",
47            ItemKind::Filter => "filter",
48            ItemKind::Prism => "prism",
49            ItemKind::Tube => "tube",
50            ItemKind::CagePlate => "cage_plate",
51            ItemKind::Mount => "mount",
52            ItemKind::Rod => "rod",
53            ItemKind::Adapter => "adapter",
54            ItemKind::Other => "other",
55        }
56    }
57    /// 機構部品か(光学の面を持たず、`mech` の寸法を持つ)
58    pub fn is_mech(self) -> bool {
59        matches!(
60            self,
61            ItemKind::Tube
62                | ItemKind::CagePlate
63                | ItemKind::Mount
64                | ItemKind::Rod
65                | ItemKind::Adapter
66        )
67    }
68    pub const ALL: [ItemKind; 14] = [
69        ItemKind::Lens,
70        ItemKind::Mirror,
71        ItemKind::Splitter,
72        ItemKind::Polarizer,
73        ItemKind::Waveplate,
74        ItemKind::Window,
75        ItemKind::Filter,
76        ItemKind::Prism,
77        ItemKind::Tube,
78        ItemKind::CagePlate,
79        ItemKind::Mount,
80        ItemKind::Rod,
81        ItemKind::Adapter,
82        ItemKind::Other,
83    ];
84    pub fn parse(s: &str) -> Option<ItemKind> {
85        ItemKind::ALL
86            .into_iter()
87            .find(|k| k.as_str().eq_ignore_ascii_case(s.trim()))
88    }
89}
90
91/// 名前の決まった仕様: (名前, 単位, 説明)。値は数・[下限, 上限]・文字列。ほかの名前も自由に使える
92pub const SPEC_NAMES: &[(&str, &str, &str)] = &[
93    (
94        "wavelength_nm",
95        "nm",
96        "設計波長域 [下限, 上限](1 つの波長なら数)",
97    ),
98    ("diameter", "mm", "外径(四角い品は一辺か [幅, 高さ])"),
99    ("clear_aperture", "mm", "有効径"),
100    ("thickness", "mm", "厚さ・キューブの一辺"),
101    ("efl", "mm", "焦点距離"),
102    ("material", "", "硝材・基板"),
103    ("coating", "", "膜(AR・反射膜の名前)"),
104    ("reflectance", "%", "反射率(帯域の平均など)"),
105    ("transmittance", "%", "透過率"),
106    ("split_ratio", "", "分岐比 R:T(例 \"50:50\")"),
107    ("extinction_ratio", "", "消光比(例 1000 は 1000:1)"),
108    ("retardance", "波長", "遅延(例 0.25 は λ/4)"),
109    ("order", "", "波長板の次数(zero・multi・achromatic など)"),
110    ("wedge", "arcmin", "くさび角"),
111    (
112        "flatness",
113        "λ",
114        "面精度(λ@633nm の分母でなく λ の値、例 0.1 は λ/10)",
115    ),
116    ("surface_quality", "", "スクラッチ・ディグ(例 \"40-20\")"),
117    ("damage_threshold", "", "損傷しきい値(条件つきの文字列)"),
118    ("aoi_deg", "deg", "入射角"),
119    ("mount", "", "取付け(ねじ・マウントの規格)"),
120    ("thread", "", "機構のねじ(例 \"SM1\")"),
121    ("length", "mm", "機構の長さ(チューブ・ロッド)"),
122    ("inner_diameter", "mm", "機構の内径・保持径"),
123    ("rod_spacing", "mm", "ケージのロッドの間隔"),
124    ("price", "", "価格(通貨つきの文字列)"),
125];
126
127/// 名前の決まった仕様の単位(無い名前は空)
128pub fn spec_unit(name: &str) -> &'static str {
129    SPEC_NAMES
130        .iter()
131        .find(|(n, _, _)| *n == name)
132        .map(|(_, u, _)| *u)
133        .unwrap_or("")
134}
135
136/// ほかのカタログの品へ足す仕様・リンク(`overlay` の値)
137#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
138pub struct Overlay {
139    /// 品の説明が空のときに使う
140    #[serde(default, skip_serializing_if = "String::is_empty")]
141    pub description: String,
142    #[serde(default, skip_serializing_if = "Option::is_none")]
143    pub kind: Option<ItemKind>,
144    #[serde(default, skip_serializing_if = "String::is_empty")]
145    pub url: String,
146    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
147    #[schemars(with = "BTreeMap<String, serde_json::Value>")]
148    pub specs: BTreeMap<String, Value>,
149    #[serde(default, skip_serializing_if = "Vec::is_empty")]
150    pub tags: Vec<String>,
151}