Skip to content

Commit 4444133

Browse files
seto77claude
andcommitted
Move bulk generated data to embedded resources; add F1 help system
Shrinks Crystallography.dll and makes the large data tables editable, while keeping runtime values bit-exact. Data -> embedded resources: - NIST elastic PCHIP: 96 generated PCHIP*.cs + Registry.cs collapsed into one Brotli-compressed NistElasticPchip.bin, decoded per element at runtime by NistElasticPchipResource (lazy, cached). Energy grid extended 101 -> 111 points (50 eV - 36.4 keV) by continuing from NIST DCS. - SymmetryStatic: large integer/string tables moved to human-readable CSV embedded resources with RFC4180 loaders; position generators reworked from Func[] to a new AffineGen struct (WyckoffPosition.cs). - AtomStaticSub: MassAbsorptionCoefficient flattened to a double[] plus offset tables and rebuilt at static init. FormBase F1 online help: - F1 opens the per-form help URL; title bar shows a right-aligned "(F1: Help)" / "(F1: ヘルプ)" hint sized to the caption. - All forms now derive from FormBase (base declaration moved out of the Designer.cs partials); CommonDialog opts out via ShowHelpSuffix. Physics/core refactors: - EBSD: parallel plane bake with incremental disk release. - EbsdMonteCarloDistribution: parallel bins, fit split into Stage1/Stage2 to drop duplicate work, QuickSelect instead of full sorts. - MonteCarlo: ref readonly transport params, divide -> multiply in the range loop, energy-count linked to the NIST elastic grid. - NativeWrapper: SuppressGCTransition threshold dispatch + one-time ABI check. - EOS: per-material lazy spline init, dropping the dev-only clipboard side effect. - ShouldSerialize* on Atoms/Crystal/EOS to trim serialized XML. Packaging/docs: - Stop bundling CrystalInformationManual(ja).pdf in the Controls output. - Add symmetry-information and scattering-factor appendix pages with auto-captured screenshots. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a11b84d commit 4444133

162 files changed

Lines changed: 14517 additions & 87053 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Crystallography.Controls/CommonDialog.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ public string Author
147147

148148
#region コンストラクタ、ロード、クローズ
149149

150+
//260604Cl 追加: スプラッシュ/履歴/ライセンス/ヒント表示用のダイアログには F1 ヘルプ案内 ("(F1: ヘルプ)") を出さない。
151+
protected override bool ShowHelpSuffix => false;
152+
150153
public CommonDialog()
151154
{
152155
InitializeComponent();

Crystallography.Controls/Crystallography.Controls.csproj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@
3838
<None Remove="doc\CrystalInformationManual(ja).pdf" />
3939
</ItemGroup>
4040

41-
<ItemGroup>
42-
<Content Include="doc\CrystalInformationManual%28ja%29.pdf">
43-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
44-
</Content>
45-
</ItemGroup>
41+
<!-- 260604Cl: CrystalInformationManual(ja).pdf の出力同梱を廃止 (全ホスト: ReciPro/PDIndexer/CSManager)。
42+
ReciPro 側の Crystal Information の説明は GitHub Pages (0-main-window.md) へ移行済み。EOS/弾性定数など
43+
ReciPro で非表示のタブの説明は本 PDF に残るが、当面はオンライン化せず PDF を doc\ に据え置く (配布のみ停止)。
44+
旧:
45+
<ItemGroup>
46+
<Content Include="doc\CrystalInformationManual%28ja%29.pdf">
47+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
48+
</Content>
49+
</ItemGroup> -->
4650

4751
<ItemGroup>
4852
<PackageReference Include="IronPython" Version="3.4.2" />

Crystallography.Controls/FormBase.cs

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Diagnostics;
3+
using System.Drawing; //260604Cl 追加: タイトルバー右寄せのテキスト計測用
4+
using System.Runtime.InteropServices; //260604Cl 追加: WM_GETTITLEBARINFOEX 取得用
35
using System.Windows.Forms;
46

57
namespace Crystallography.Controls;
@@ -27,12 +29,150 @@ public partial class FormBase : Form
2729
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
2830
public string HelpPage { get; set; } = ""; //260529Cl 追加
2931

32+
//260604Cl 追加: F1 でヘルプを開けるフォームのタイトル右端に出す案内文字列 (UI 言語で切替)。
33+
private const string HelpCoreEn = "(F1: Help)"; //260604Cl 追加
34+
private const string HelpCoreJa = "(F1: ヘルプ)"; //260604Cl 追加
35+
private const int HelpFallbackSpaces = 10; //260604Cl 追加: 右寄せ量を計算できない時に挟む固定スペース数
36+
private const int HelpMinSpaces = 4; //260604Cl 追加: タイトルと案内が接触しないための最小スペース数
37+
private bool isUpdatingHelpSuffix = false; //260604Cl 追加: 自分の Text 書換で再入する TextChanged を弾くフラグ
38+
39+
//260604Cl 追加: タイトルに F1 ヘルプ案内を付けるか。出したくない派生フォーム (CommonDialog 等) は override で false にする。
40+
protected virtual bool ShowHelpSuffix => true;
41+
3042
protected FormBase()
3143
{
3244
InitializeComponent();
3345
HelpRequested += FormBase_HelpRequested; //260529Cl 追加: F1 キー (HelpRequested) を購読
46+
47+
//260604Cl 追加: F1 でヘルプが開けるフォームは、タイトル右端に案内 ("(F1: Help)" / 日本語 UI なら "(F1: ヘルプ)") を出して存在を知らせる。
48+
//表示時点では HelpPage / HelpUrlResolver が確定しているので Shown で初回付与し、
49+
//タイトル変更 (TextChanged) や幅変更 (Resize, 右寄せ位置が変わる) でも付け直す。
50+
Shown += (s, e) => AppendHelpSuffix();
51+
TextChanged += (s, e) => AppendHelpSuffix();
52+
Resize += (s, e) => AppendHelpSuffix();
53+
}
54+
55+
//260604Cl 追加: タイトル(Text)の右端に現在の UI 言語の案内文字列を配置する。
56+
//案内はキャプション右端 (最小化ボタンの手前) に来るよう、本文との間にスペースを動的に詰める。
57+
//HelpUrlResolver が未登録/空 URL を返すフォーム (他ホストアプリや設計時) には付けない。
58+
private void AppendHelpSuffix()
59+
{
60+
if (isUpdatingHelpSuffix)
61+
return; //自分が起こした TextChanged の再入を弾く (無限ループ回避)
62+
if (!ShowHelpSuffix)
63+
return; //この派生フォームは案内を出さない (CommonDialog 等)
64+
if (string.IsNullOrEmpty(HelpUrlResolver?.Invoke(this)))
65+
return; //F1 で開くヘルプが無ければ付けない
66+
67+
var core = System.Globalization.CultureInfo.CurrentUICulture.Name == "ja" ? HelpCoreJa : HelpCoreEn;
68+
var baseText = StripHelpSuffix(Text); //既存の案内を一旦取り除いた素のタイトル
69+
70+
int spaces = ComputeRightAlignSpaces(baseText, core); //キャプション右端に寄せるためのスペース数
71+
if (spaces < 0)
72+
spaces = HelpFallbackSpaces; //計測できない時 (ハンドル未生成・枠無し等) は固定スペースでフォールバック
73+
74+
var desired = baseText + new string(' ', spaces) + core;
75+
if (Text == desired)
76+
return; //既に正しい状態 (再表示・連続更新・同幅 Resize 時のちらつき防止)
77+
78+
isUpdatingHelpSuffix = true;
79+
try { Text = desired; }
80+
finally { isUpdatingHelpSuffix = false; }
81+
}
82+
83+
//260604Cl 追加: 既存の案内 (両言語) と直前のスペースを取り除いた素のタイトルを返す。
84+
//言語切替で逆言語の案内が残っていても二重化しないよう、core 一致で末尾を剥がす。
85+
private static string StripHelpSuffix(string text)
86+
{
87+
if (text.EndsWith(HelpCoreEn, StringComparison.Ordinal))
88+
return text.Substring(0, text.Length - HelpCoreEn.Length).TrimEnd(' ');
89+
if (text.EndsWith(HelpCoreJa, StringComparison.Ordinal))
90+
return text.Substring(0, text.Length - HelpCoreJa.Length).TrimEnd(' ');
91+
return text;
92+
}
93+
94+
//260604Cl 追加: baseText の後ろに何個スペースを入れれば core がキャプション右端 (ボタン手前) に来るかを算出する。
95+
//計測不能 (ハンドル未生成・枠無し・最小化・キャプション無し等) なら -1 を返し、呼び出し側で固定スペースにフォールバックする。
96+
private int ComputeRightAlignSpaces(string baseText, string core)
97+
{
98+
try
99+
{
100+
if (!IsHandleCreated || FormBorderStyle == FormBorderStyle.None || WindowState == FormWindowState.Minimized)
101+
return -1;
102+
103+
//タイトルバーと各ボタンの矩形 (スクリーン座標, 物理px) を取得
104+
var info = new TITLEBARINFOEX { cbSize = Marshal.SizeOf<TITLEBARINFOEX>(), rgstate = new int[6], rgrect = new RECT[6] };
105+
SendMessage(Handle, WM_GETTITLEBARINFOEX, IntPtr.Zero, ref info);
106+
107+
int titleLeft = info.rcTitleBar.Left, titleRight = info.rcTitleBar.Right;
108+
if (titleRight <= titleLeft)
109+
return -1; //キャプション無し
110+
111+
//可視ボタン (index 2..5 = 最小化/最大化/ヘルプ/閉じる) のうち最も左の Left を、本文を置ける右端境界にする
112+
int rightBoundary = titleRight;
113+
for (int i = 2; i <= 5; i++)
114+
{
115+
if ((info.rgstate[i] & STATE_SYSTEM_INVISIBLE) != 0) continue;
116+
var r = info.rgrect[i];
117+
if (r.Right > r.Left && r.Left < rightBoundary)
118+
rightBoundary = r.Left;
119+
}
120+
121+
float scale = DeviceDpi / 96f;
122+
bool toolWindow = FormBorderStyle is FormBorderStyle.FixedToolWindow or FormBorderStyle.SizableToolWindow;
123+
bool hasIcon = ShowIcon && ControlBox && !toolWindow;
124+
int margin = (int)(12 * scale); //ボタンとの間に確保する余白
125+
int iconOffset = hasIcon ? (int)(SystemInformation.SmallIconSize.Width + 12 * scale) : (int)(6 * scale);
126+
int textStart = titleLeft + iconOffset; //本文の左端 (アイコン分のおおよその推定)
127+
int availRight = rightBoundary - margin;
128+
if (availRight <= textStart)
129+
return -1; //幅が無い
130+
131+
using var font = toolWindow ? SystemFonts.SmallCaptionFont : SystemFonts.CaptionFont;
132+
if (font == null)
133+
return -1;
134+
135+
//重要: タイトルバー (DWM) の文字描画は GDI の TextRenderer よりやや広く、TextRenderer 基準だと
136+
//スペース数を過大評価して案内が右端に食い込み隠れる。GenericTypographic の MeasureString が
137+
//実描画とよく一致する (実測: 96dpi でスペース 3.287px ≒ 実描画)。計測単位はフォームの DPI なので
138+
//スクリーン座標 (物理px) の右端境界と整合する。
139+
using var g = CreateGraphics();
140+
float Measure(string s) => g.MeasureString(s, font, int.MaxValue, StringFormat.GenericTypographic).Width;
141+
142+
float spaceW = (Measure("x" + new string(' ', 100) + "x") - Measure("xx")) / 100f; //連続スペースの平均で空白1個の幅 (サブピクセル精度)
143+
if (spaceW <= 0.1f)
144+
return -1;
145+
spaceW *= 1.03f; //安全側: DPI 差等の残差があっても右にはみ出す (隠れる) より、わずかに左に余らせる
146+
147+
float baseW = baseText.Length == 0 ? 0 : Measure(baseText);
148+
float coreW = Measure(core);
149+
float gapPx = availRight - (textStart + baseW) - coreW; //本文と案内の間に詰めたい余白px
150+
int spaces = (int)(gapPx / spaceW);
151+
return spaces < HelpMinSpaces ? HelpMinSpaces : spaces;
152+
}
153+
catch { return -1; }
154+
}
155+
156+
#region 260604Cl 追加: タイトルバー右寄せ用の WM_GETTITLEBARINFOEX 取得
157+
private const int WM_GETTITLEBARINFOEX = 0x033F;
158+
private const int STATE_SYSTEM_INVISIBLE = 0x00008000;
159+
160+
[StructLayout(LayoutKind.Sequential)]
161+
private struct RECT { public int Left, Top, Right, Bottom; }
162+
163+
[StructLayout(LayoutKind.Sequential)]
164+
private struct TITLEBARINFOEX
165+
{
166+
public int cbSize;
167+
public RECT rcTitleBar;
168+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public int[] rgstate;
169+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public RECT[] rgrect;
34170
}
35171

172+
[DllImport("user32.dll")]
173+
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref TITLEBARINFOEX lParam);
174+
#endregion
175+
36176
//260529Cl 追加: F1 押下時に HelpUrlResolver が返す URL を既定ブラウザで開く
37177
private void FormBase_HelpRequested(object sender, HelpEventArgs hlpevent)
38178
{

0 commit comments

Comments
 (0)