public void EnableReconstruction(bool enabled)
 {
     if (Reconstruct.Enabled != enabled)
     {
         Reconstruct.Enabled = enabled;
         if (enabled)
         {
             Reconstruct.Focus();
         }
         else
         {
             Start.Focus();
         }
     }
 }
        public void SetButtonState(ButtonState state)
        {
            Color RECORD_COLOR = Color.Red;

            // Consolidated logic to restore the color of the Reconstruct button after the scanning has ended.
            if (Reconstruct.BackColor == RECORD_COLOR)
            {
                Reconstruct.BackColor = OriginalReconstructBackColor;
            }

            buttonState = state;
            switch (buttonState)
            {
            case ButtonState.SCe_SSd:     // Streaming stopped (Start Camera enabled, Start Scanning disabled)
                Start.Text    = "Start Camera";
                Start.Enabled = true;
                Start.Focus();
                Reconstruct.Text    = "Start Scanning";
                Reconstruct.Enabled = false;
                break;

            case ButtonState.Cd_SSd:     // Waiting for streaming start (Cancel disabled, Start Scanning disabled)
                Start.Text          = "Cancel";
                Start.Enabled       = false;
                Reconstruct.Text    = "Start Scanning";
                Reconstruct.Enabled = false;
                break;

            case ButtonState.Ce_SSd:     // Start Camera pressed (Cancel enabled, Start Scanning disabled)
                Start.Text    = "Cancel";
                Start.Enabled = true;
                Start.Focus();
                Reconstruct.Text    = "Start Scanning";
                Reconstruct.Enabled = false;
                break;

            case ButtonState.Ce_SSd2:     // Streaming started (Cancel enabled, Start Scanning disabled)
                Start.Text    = "Cancel";
                Start.Enabled = true;
                Start.Focus();
                Reconstruct.Text    = "Start Scanning";
                Reconstruct.Enabled = false;
                break;

            case ButtonState.Ce_SSe:     // Scanning preconditions met (Cancel enabled, Start Scanning enabled)
                Start.Text          = "Cancel";
                Start.Enabled       = true;
                Reconstruct.Text    = "Start Scanning";
                Reconstruct.Enabled = true;
                Reconstruct.Focus();
                break;

            case ButtonState.Ce_ESd:     // Start Scanning pressed (Cancel enabled, End Scanning disabled)
                scan_requested = true;
                Start.Text     = "Cancel";
                Start.Enabled  = true;
                Start.Focus();
                Reconstruct.Text    = "End Scanning";
                Reconstruct.Enabled = false;
                break;

            case ButtonState.Ce_ESe:     // Scanning started (Cancel enabled, End Scanning enabled)
                Start.Text          = "Cancel";
                Start.Enabled       = true;
                Reconstruct.Text    = "End Scanning";
                Reconstruct.Enabled = true;
                Reconstruct.Focus();
                OriginalReconstructBackColor = Reconstruct.BackColor;
                Reconstruct.BackColor        = RECORD_COLOR;
                break;

            case ButtonState.Cd_ESd:     // Scanning ended (Cancel disabled, End Scanning disabled)
                Start.Text          = "Cancel";
                Start.Enabled       = false;
                Reconstruct.Text    = "End Scanning";
                Reconstruct.Enabled = false;
                break;
            }
            Panel_Paint(MainPanel, null);
        }