123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using PaintDotNet.Base.SettingModel;
- using TUCamera;
- using TUCAMAPI;
- namespace PaintDotNet.ImageCollect.CameraComponent
- {
- public partial class AdjustGainControl : UserControl
- {
- private TUCamera.TUCamera m_camera;
- private CameraParamModel m_cameraParamModel;
- private bool m_use;
- private void InitializeLanguageText()
- {
- this.groupBox2.Text = PdnResources.GetString("Menu.Gainvalueadjustment.text");
- }
- public AdjustGainControl(CameraParamModel model, bool use)
- {
- InitializeComponent();
- InitializeLanguageText();
- m_use = use;
- m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
- m_cameraParamModel = model;
- InitializeControlData();
- if (m_cameraParamModel.parame.ATExposure == 1)
- {
- trbGain.Enabled = false;
- txtGain.Enabled = false;
- }
- }
- public void ReLoad(CameraParamModel model, bool use)
- {
- m_cameraParamModel = model;
- m_use = use;
- InitializeControlData();
- if (m_cameraParamModel.parame.ATExposure == 1)
- {
- trbGain.Enabled = false;
- txtGain.Enabled = false;
- }
- }
- private void InitializeControlData()
- {
- if (m_camera.IsOpen())
- {
- // Get gain range
- TUCAM_PROP_ATTR attrProp;
- attrProp = m_camera.GetGlobalGainRange();
- trbGain.SetRange((int)attrProp.dbValMin, (int)attrProp.dbValMax);
- lblGainMin.Text = trbGain.Minimum.ToString();
- lblGainMax.Text = trbGain.Maximum.ToString();
- }
- // gain
- int gainValue = m_cameraParamModel.parame.GlobalGain;
- if (gainValue >= this.trbGain.Minimum && gainValue <= this.trbGain.Maximum)
- {
- this.trbGain.Value = gainValue;
- }
- }
- private void trbGain_ValueChanged(object sender, EventArgs e)
- {
- txtGain.Text = trbGain.Value.ToString();
- m_cameraParamModel.parame.GlobalGain = trbGain.Value;
- // 设置到相机
- if (m_use)
- {
- m_camera.SetGlobalGain(m_cameraParamModel.parame.GlobalGain); //usec
- }
- }
- private void txtGain_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (!char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Enter)) // 非数字键, 放弃该输入
- {
- e.Handled = true;
- return;
- }
- if (e.KeyChar == (char)Keys.Enter)
- {
- try
- {
- int trbGainVal = Convert.ToInt32(txtGain.Text);
- if (trbGainVal < trbGain.Minimum)
- {
- trbGainVal = trbGain.Minimum;
- }
- if (trbGainVal > trbGain.Maximum)
- {
- trbGainVal = trbGain.Maximum;
- }
- trbGain.Value = trbGainVal;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- }
- }
|