1use schemars::JsonSchema;
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10use std::collections::BTreeMap;
11
12#[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 Tube,
26 #[serde(rename = "cage_plate")]
28 CagePlate,
29 Mount,
31 Rod,
33 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 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
91pub 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
127pub 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#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
138pub struct Overlay {
139 #[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}