Newer
Older
TIASShot / TIASshot / UI / Form1.WhiteBoard.cs
#if WHITEBOARD
using System;
using System.Windows.Forms;

namespace TIASshot {
    public partial class Form1 {

        /// <summary>
        /// 白板撮影ボタンの初期化(WHITEBOARD 限定)
        /// InitializeComponent() 完了後にコンストラクタから呼び出す.
        /// </summary>
        private void InitializeWhiteBoardButton() {
            this.btnWhiteBoard = new System.Windows.Forms.Button();
            //
            // btnWhiteBoard [WB]
            //
            this.btnWhiteBoard.BackColor = System.Drawing.Color.LightYellow;
            this.btnWhiteBoard.Font = new System.Drawing.Font("MS UI Gothic", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
            this.btnWhiteBoard.Location = new System.Drawing.Point(15, 225);
            this.btnWhiteBoard.Name = "btnWhiteBoard";
            this.btnWhiteBoard.Size = new System.Drawing.Size(268, 28);
            this.btnWhiteBoard.TabIndex = 25;
            this.btnWhiteBoard.Text = "[WB] 白板撮影(均一性評価用)";
            this.btnWhiteBoard.UseVisualStyleBackColor = false;
            this.btnWhiteBoard.Click += new System.EventHandler(this.btnWhiteBoard_Click);
            this.Controls.Add(this.btnWhiteBoard);
        }

        /// <summary>
        /// [WB] 白板撮影ボタン(照明均一性評価用)
        /// 校正ゲートを通さず IScam の白板撮影パスを呼び出す.
        /// WHITEBOARD シンボルが定義されていない構成(Release 等)には含まれない.
        /// </summary>
        private void btnWhiteBoard_Click(object sender, EventArgs e) {
            int numImages = GetNumMultiShots();
            if (numImages < 1) numImages = 1;

            btnWhiteBoard.Enabled = false;
            ShowMessage($"白板撮影開始({numImages} 枚)...");

            // 撮影は UI スレッドをブロックしないよう別スレッドで実行
            var thread = new System.Threading.Thread(() => {
                try {
                    _camera.ShotWhiteBoard(numImages);
                } catch (Exception ex) {
                    System.Diagnostics.Debug.WriteLine($"[WhiteBoard] 撮影スレッドエラー: {ex.Message}");
                    ShowMessage($"白板撮影エラー: {ex.Message}");
                } finally {
                    if (InvokeRequired) {
                        Invoke((MethodInvoker)delegate {
                            btnWhiteBoard.Enabled = true;
                        });
                    } else {
                        btnWhiteBoard.Enabled = true;
                    }
                }
            });
            thread.Name = "WhiteBoardShotThread";
            thread.Start();
        }

        private System.Windows.Forms.Button btnWhiteBoard;
    }
}
#endif