📄 camerafeatureview.cpp
字号:
//-----------------------------------------------------------------------------
// (c) 2002 by Basler Vision Technologies
// Section: Vision Components
// Project: BCAM
// $Header: CameraFeatureView.cpp, 15, 18.06.2004 14:42:38, Happe, A.$
//-----------------------------------------------------------------------------
/**
\file CameraFeatureView.cpp
*
* \brief Implementation of the CCameraFeature class.
*
*/
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "MainFrm.h"
#include "CameraFeatureView.h"
#include "utility.h"
//////////////////////////////////////////////////////////////////////
//
// class CCameraFeatureViewBase
//
//
CCameraFeatureViewBase::CCameraFeatureViewBase(BcamFeatureID id, CMainFrame& MainFrame )
: m_FeatureId(id),
m_MainFrame(MainFrame),
m_pCamera(NULL)
{
}
void CCameraFeatureViewBase::CurrentDeviceChanged(CCamera* pCamera)
{
try
{
m_Format = (DCSVideoFormat) -1;
m_Mode = (DCSVideoMode) -1;
m_Framerate = (DCSVideoFrameRate) -1;
m_Code = (DCSColorCode) -1;
m_pCamera = pCamera;
if ( pCamera == NULL )
{
EnableWindow(hWnd(), FALSE);
return;
}
// Initiate refresh of control (i.e get bounds and read current value )
DCSVideoFormat format;
DCSVideoMode mode;
DCSVideoFrameRate rate;
DCSColorCode code;
m_pCamera->GetVideoMode(&format, &mode, &rate);
if ( format == DCS_Format7 )
{
code = pCamera->FormatSeven[mode].ColorCoding();
}
else
{
code = BcamUtility::ColorCode(format, mode);
}
ConfigurationChanged(format, mode, rate, code);
}
catch ( BcamException& e )
{
EnableWindow(hWnd(), FALSE);
throw e;
}
}
void CCameraFeatureViewBase::ConfigurationChanged(DCSVideoFormat format, DCSVideoMode mode, DCSVideoFrameRate rate, DCSColorCode code)
{
try
{
OnConfigurationChanged(format, mode, rate, code);
}
catch ( BcamException& e )
{
EnableWindow(hWnd(), FALSE);
throw e;
}
m_Format = format;
m_Mode = mode;
m_Framerate = rate;
m_Code = code;
}
//////////////////////////////////////////////////////////////////////
//
// class CScalarFeatureView
//
//
//////////////////////////////////////////////////////////////////////
// Message Handlers
//////////////////////////////////////////////////////////////////////
LRESULT CScalarFeatureView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
::SetWindowText(GetDlgItem(IDC_STATICNAME), BcamUtility::FeatureName(m_FeatureId) );
InitControl();
return 0;
}
LRESULT CScalarFeatureView::OnEnable(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
BOOL enable = false;
if ( wParam ) // Window has been enabled
{
if ( m_pCamera != NULL && Feature().IsSupported() )
enable = true;
}
if ( m_pCamera == NULL )
{
::EnableWindow(GetDlgItem(IDC_EDITVALUE), enable);
::EnableWindow(GetDlgItem(IDC_SLIDER), enable);
}
else
{
/* if ( AbsControl() )
m_EditCtrlDbl.EnableWindow(enable);
else */
m_EditCtrlInt.EnableWindow(enable);
}
::EnableWindow(GetDlgItem(IDC_STATICNAME), enable);
::EnableWindow(GetDlgItem(IDC_STATICMIN), enable);
::EnableWindow(GetDlgItem(IDC_STATICMAX), enable);
return 0;
}
LRESULT CScalarFeatureView::OnValueChanged(WPARAM uNotifyCode, WPARAM wID, HWND hWndCtrl, BOOL& bHandled)
{
if ( m_pCamera == NULL )
return 0;
try
{
CBcam::CScalarProperty& feat = Feature();
if ( ! m_fAbsControl )
{
int newVal = m_EditCtrlInt.GetValue();
feat.Raw.SetAsync(newVal);
}
else
{
double newVal = m_EditCtrlDbl.GetValue();
feat.Abs.SetAsync(newVal);
}
}
catch ( BcamException& e)
{
m_MainFrame.ReportError(e);
}
return 0;
}
//////////////////////////////////////////////////////////////////////
// Public member functions
//////////////////////////////////////////////////////////////////////
bool CScalarFeatureView::AbsoluteControl(bool on)
{
m_fAbsControl = on;
if ( on )
{
m_EditCtrlInt.Detach();
m_EditCtrlDbl.Attach(this, IDC_EDITVALUE, IDC_SLIDER);
m_EditCtrlDbl.WantReturn(true);
m_EditCtrlDbl.AttachTextCtrls(IDC_STATICMIN, IDC_STATICMAX);
}
else
{
m_EditCtrlDbl.Detach();
m_EditCtrlInt.Attach(this, IDC_EDITVALUE, IDC_SLIDER);
m_EditCtrlInt.WantReturn(true);
m_EditCtrlInt.AttachTextCtrls(IDC_STATICMIN, IDC_STATICMAX);
}
return true;
}
void CScalarFeatureView::OnConfigurationChanged(DCSVideoFormat format, DCSVideoMode mode, DCSVideoFrameRate rate, DCSColorCode code)
{
if ( m_pCamera != NULL )
{
CBcam::CScalarProperty& feature = Feature();
if ( feature.IsSupported() && feature.IsSupported(inqManual) )
{
EnableWindow(TRUE);
if ( feature.AutoMode() )
feature.AutoMode = false;
RefreshControl();
}
else
{
EnableWindow(FALSE);
}
}
}
//////////////////////////////////////////////////////////////////////
// Protected/ private member functions
//////////////////////////////////////////////////////////////////////
void CScalarFeatureView::InitControl()
{
AbsoluteControl(m_fAbsControl);
m_EditCtrlDbl.WantReturn(true);
m_EditCtrlInt.WantReturn(true);
m_EditCtrlDbl.PostMsgEnable(true);
m_EditCtrlInt.PostMsgEnable(true);
m_EditCtrlInt.LiveUpdateEnable(true);
m_EditCtrlDbl.LiveUpdateEnable(true);
m_EditCtrlInt.SetKillFocus(TRUE);
m_EditCtrlDbl.SetKillFocus(TRUE);
}
CBcam::CScalarProperty& CScalarFeatureView::Feature()
{
assert ( m_pCamera != NULL );
switch ( m_FeatureId )
{
case FeatureID_Brightness:
return m_pCamera->Brightness;
case FeatureID_Hue:
return m_pCamera->Hue;
case FeatureID_Saturation:
return m_pCamera->Saturation;
case FeatureID_Gamma:
return m_pCamera->Gamma;
case FeatureID_Shutter:
return m_pCamera->Shutter;
case FeatureID_Gain:
return m_pCamera->Gain;
}
assert(false);
return *(CBcam::CScalarProperty*) NULL;
}
void CScalarFeatureView::RefreshControl()
{
assert ( m_pCamera != NULL );
CBcam::CScalarProperty& feat = Feature();
if ( ! m_fAbsControl )
{
m_EditCtrlInt.PostMsgEnable(false);
long min = feat.Raw.Min();
long max = feat.Raw.Max();
long val = feat.Raw();
if ( val < min ) {
val = min;
feat.Raw = min;
}
if ( val > max ) {
val = max;
feat.Raw = max;
}
m_EditCtrlInt.SetRange(min, max);
m_EditCtrlInt.SetValue(val);
m_EditCtrlInt.PostMsgEnable(true);
}
else
{
double min = feat.Abs.Min();
double max = feat.Abs.Max();
double val = feat.Abs();
if ( val < min ) {
val = min;
feat.Abs = min;
}
if ( val > max ) {
val = max;
feat.Abs = max;
}
m_EditCtrlDbl.PostMsgEnable(false);
m_EditCtrlDbl.SetRange(min, max);
m_EditCtrlDbl.SetValue(val);
m_EditCtrlDbl.PostMsgEnable(true);
}
}
//////////////////////////////////////////////////////////////////////
//
// class CWhiteBalanceView
//
//
//////////////////////////////////////////////////////////////////////
// Message Handlers
//////////////////////////////////////////////////////////////////////
LRESULT CWhiteBalanceView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
::SetWindowText(GetDlgItem(IDC_STATICNAME), "White Balance" );
InitControl();
return 0;
}
LRESULT CWhiteBalanceView::OnEnable(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
BOOL enable = false;
if ( wParam ) // Window has been enabled
{
if ( m_pCamera != NULL && ( m_pCamera->IsWhiteBalanceSupported() || m_pCamera->IsBayerConversionEnabled() ) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -