📄 mainfrm.cpp
字号:
}
LRESULT CMainFrame::OnViewFeature(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
try
{
BcamFeatureID id = (BcamFeatureID) (wID - ID_VIEW_FIRST_FEATURE);
FeatureMap_t::iterator feature = m_Features.find( id );
if ( feature != m_Features.end() )
{
HWND hWnd = feature->second->hWnd();
if ( hWnd != NULL )
{
BOOL bShow = !::IsWindowVisible(hWnd);
ShowFeatureWindow(id, bShow);
}
}
} CATCH_REPORT();
return 0;
}
BOOL CMainFrame::OnIdle() {
UpdateUI();
return FALSE;
}
void CMainFrame::UpdateUI()
{
// update UI elements
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Must not access the camera in UpdateUI(). Reason:
// If a single grab and a parameterization request are pending,
// additional requests issued by UpdateUI() will not be completed until
// these pending requests are completed ==> The message loop might be blocked
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
UISetCheck(ID_VIEW_BUSVIEW, ::IsWindowVisible(m_BusView) );
bool MDIOpen = false;
bool GrabActive = false;
bool SingleGrabActive = false;
bool WhiteBalanceActive = false;
CCamera* pCamera = m_CameraManager.GetCurrentDevice();
if ( pCamera != 0 )
{
try
{
MDIOpen = m_CameraManager.ExistMDIChild();
GrabActive = m_CameraManager.IsGrabActive();
SingleGrabActive = pCamera->IsSingleGrabActive();
WhiteBalanceActive = pCamera->IsAutoWhiteBalanceActive();
}
catch ( BcamException& e )
{
if ( e.Error() != ERROR_DEVICE_REMOVED )
ReportError(e);
}
}
UIEnable(ID_FILE_SAVE_CONFIGURATION, ( pCamera != NULL ) && ! GrabActive );
UIEnable(ID_FILE_RESTORE_CONFIGURATION, (pCamera != NULL ) && ! GrabActive );
UIEnable(ID_FILE_NEW, (pCamera != NULL ) && ! MDIOpen);
UIEnable(ID_FILE_OPEN, (pCamera != NULL ) && ! GrabActive );
UIEnable(ID_FILE_SAVE, (pCamera != NULL ) && ! GrabActive && pCamera->GetBitmap() != NULL );
UIEnable(ID_EDIT_COPY, (pCamera != NULL ) && ( pCamera->GetBitmap() != NULL )) ;
UIEnable(ID_GRAB_CONTINUOUS, (pCamera != NULL ) && ( ! GrabActive ));
UIEnable(ID_GRAB_SINGLE, (pCamera != NULL ) && ( ! GrabActive ) );
UIEnable(ID_GRAB_CANCEL, (pCamera != NULL ) && GrabActive );
UIEnable(ID_CAMERA_MAXIMIZE, (pCamera != NULL ) && MDIOpen && pCamera->IsScalable() && ! SingleGrabActive );
UIEnable(ID_VIEW_PROPERTIES, (pCamera != NULL) && ! SingleGrabActive );
UIEnable(ID_VIEW_ZOOM_BEST, (pCamera != NULL ) && MDIOpen && ! m_CameraManager.GetCurrentChild()->m_View.IsZoomedToFit());
UIEnable(ID_TOOLS_CALCULATE_CORRECTION_TABLE, ( pCamera != NULL ) && ! GrabActive && m_fCurrentDeviceSupportsShading && m_fMono8 );
UIEnable(ID_VIEW_NO_CONVERSION, m_fBayerColorFilter);
UIEnable(ID_VIEW_CONVERSION_GB, m_fBayerColorFilter);
UIEnable(ID_VIEW_CONVERSION_GR, m_fBayerColorFilter);
UIEnable(ID_VIEW_CONVERSION_BG, m_fBayerColorFilter);
UIEnable(ID_VIEW_CONVERSION_RG, m_fBayerColorFilter);
UIEnable(ID_WHITE_BALANCE, ( ( m_fYuv422 && m_fWhiteBalanceSupported) || (pCamera != NULL && pCamera->GetBayerToRGBConversion() > 0 ) ) && ! WhiteBalanceActive && ! SingleGrabActive ) ;
if ( ! GrabActive )
{
// delete fps panes
m_Sbar.SetPaneText(ID_FPS_ACQUIRED_PANE, CString("") );
m_Sbar.SetPaneText(ID_FPS_DISPLAYED_PANE, CString("") );
}
for ( int i = 0; i < 5; i ++ )
{
UISetCheck( ID_VIEW_NO_CONVERSION + i,
(pCamera != NULL) &&
(pCamera->GetColorCode() == DCSColor_Mono8 || pCamera->GetColorCode() == DCSColor_Raw8) &&
pCamera->GetBayerToRGBConversion() == i );
}
UIUpdateToolBar();
}
LRESULT CMainFrame::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CAboutDlg dlg;
dlg.DoModal();
return 0;
}
LRESULT CMainFrame::OnWindowCascade(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
MDICascade();
return 0;
}
LRESULT CMainFrame::OnWindowTile(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
MDITile();
return 0;
}
LRESULT CMainFrame::OnWindowArrangeIcons(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
MDIIconArrange();
return 0;
}
LRESULT CMainFrame::OnGrabSingle(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if ( m_CameraManager.GetCurrentDevice() != NULL )
{
try
{
m_CameraManager.GrabSingle();
}
CATCH_REPORT();
}
return 0;
}
LRESULT CMainFrame::OnGrabContinuous(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if ( m_CameraManager.GetCurrentDevice() != NULL )
{
try
{
m_CameraManager.GrabContinuous();
}
CATCH_REPORT();
}
return 0;
}
LRESULT CMainFrame::OnWhiteBalance(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if ( m_CameraManager.GetCurrentDevice() != NULL )
{
try
{
m_CameraManager.PerformWhiteBalance();
}
CATCH_REPORT();
}
return 0;
}
LRESULT CMainFrame::OnGrabCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if ( m_CameraManager.GetCurrentDevice() != NULL )
{
try
{
m_CameraManager.GrabCancel();
}
CATCH_REPORT();
}
return 0;
}
LRESULT CMainFrame::OnCameraMaximize(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if ( m_CameraManager.GetCurrentDevice() != NULL )
{
try
{
m_CameraManager.GetCurrentDevice()->MaximizeAOI();
}
CATCH_REPORT();
}
return 0;
}
LRESULT CMainFrame::OnCalculateCorrectionTable(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
try
{
if ( m_CameraManager.GetCurrentDevice() != NULL )
{
m_CameraManager.CreateShadingCorrectionTable();
}
}
CATCH_REPORT();
return 0;
}
LRESULT CMainFrame::OnTimer(UINT, WPARAM wParam, LPARAM, BOOL&)
{
assert(wParam == TIMERID);
// Show FPS
CCamera *pCurrentDevice = m_CameraManager.GetCurrentDevice();
if ( pCurrentDevice != NULL )
{
double fps_acquired = 0;
double fps_displayed = 0;
m_CameraManager.GetFrameRate(fps_acquired, fps_displayed);
CString out;
if ( fps_acquired != -1 )
{
out.Format("FPS - acquired: %3.1f", fps_acquired);
if ( m_fBroadCastFps )
{
::PostMessage(HWND_BROADCAST, m_uFpsBroadCastMessage, 0, (long) ( fps_acquired * 10 + 0.5 ) );
}
}
else
{
out = "";
if ( m_fBroadCastFps )
{
::PostMessage(HWND_BROADCAST, m_uFpsBroadCastMessage, 0, 0 );
}
}
m_Sbar.SetPaneText(ID_FPS_ACQUIRED_PANE, out);
if ( fps_displayed != -1 )
out.Format("FPS - displayed: %3.1f", fps_displayed);
else
out = "";
m_Sbar.SetPaneText(ID_FPS_DISPLAYED_PANE, out);
m_CameraManager.ShowPixelValue();
}
return 0;
}
LRESULT CMainFrame::OnSetCursor(UINT, WPARAM, LPARAM, BOOL& bHandled)
{
bHandled = FALSE;
m_CameraManager.ShowPixelValue();
return 0;
}
LRESULT CMainFrame::OnHelp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
ShowHelp();
return 0;
}
LRESULT CMainFrame::OnHelpCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
ShowHelp();
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// public member functions
//
void CMainFrame::CurrentDeviceChanged(CCamera* pCamera)
{
try
{
// an eventually active camera property page has to be closed
if ( m_fPropertyPageVisible )
{
assert(m_pPropertyDlg != NULL );
if ( m_pPropertyDlg != NULL )
{
m_pPropertyDlg->SendMessage(WM_COMMAND, IDCANCEL, 0);
m_fPropertyPageVisible = false;
}
}
// update cached information about the camera
UpdateCache();
// refresh the feature views
RefreshFeatureViews(pCamera);
// inform the bus viewer
m_BusView.CurrentDeviceChanged(pCamera);
}
CATCH_REPORT()
}
void CMainFrame::RefreshFeatureViews(CCamera* pCamera)
{
if ( m_CameraManager.GetCurrentDevice() != pCamera )
return; // nothing to be done
// handle feature windows
FeatureMap_t::iterator feature;
for (feature = m_Features.begin(); feature != m_Features.end(); ++ feature)
{
feature->second->CurrentDeviceChanged(pCamera);
}
}
// update cached information for the current device
void CMainFrame::UpdateCache()
{
m_fWhiteBalanceSupported = false;
m_fMono8 = false;
m_fBayerColorFilter = false;
m_fYuv422 = false;
m_fCurrentDeviceSupportsShading = false;
m_fCurrentDeviceSupportsOneShot = false;
CCamera* pCamera = m_CameraManager.GetCurrentDevice();
if ( pCamera == NULL )
return;
try
{
m_fWhiteBalanceSupported = pCamera->WhiteBalance.IsSupported() || pCamera->IsBayerConversionEnabled();
const DCSColorCode code = pCamera->GetColorCode();
m_fMono8 = code == DCSColor_Mono8;
m_fYuv422 = code == DCSColor_YUV8_4_2_2;
m_fBayerColorFilter = (code == DCSColor_Mono8 || code == DCSColor_Raw8);
// check if the current device supports the shading feature
m_fCurrentDeviceSupportsShading = pCamera->ShadingCorrection.IsSupported();
m_fCurrentDeviceSupportsOneShot = pCamera->OneShot.IsSupported();
}
CATCH_REPORT();
}
void CMainFrame::ConfigurationChanged(CCamera* pCamera, DCSVideoFormat format, DCSVideoMode mode, DCSVideoFrameRate rate, DCSColorCode code)
{
assert (pCamera != NULL );
try
{
// handle feature windows
if ( m_CameraManager.GetCurrentDevice() == pCamera )
{
// the feature windows are bound to a device -> inform them about changed configuration
FeatureMap_t::iterator feature;
for (feature = m_Features.begin(); feature != m_Features.end(); ++ feature)
{
feature->second->ConfigurationChanged(format, mode, rate, code);
}
UpdateCache();
}
} CATCH_REPORT()
}
// Callback to notify us about the removal of a device
void CMainFrame::DeviceRemoved(CString DevName)
{
// Update UI
UpdateUI();
}
void CMainFrame::ReportError(BcamException& e)
{
if ( ! ::IsWindow(m_ErrorBox) )
{
m_ErrorBox.Create(m_hWnd);
m_ErrorBox.ShowWindow(SW_SHOW);
}
m_ErrorBox.ReportError(e);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// private member functions
//
void CMainFrame::AddScalarFeature(BcamFeatureID id, BOOL newLine, BOOL Show)
{
// Create feature view window
CScalarFeatureView *pFeatureView = new CScalarFeatureView(id, *this);
pFeatureView->Create(m_Dock, rcDefault);
AddSimpleReBarBand(*pFeatureView, 0, newLine);
pFeatureView->CurrentDeviceChanged(NULL);
m_Features[id] = pFeatureView;
if ( Show )
{
UISetCheck(ID_VIEW_FIRST_FEATURE + id, TRUE);
}
else
{
ShowFeatureWindow(id, FALSE);
}
}
void CMainFrame::AddWhiteBalanceFeature(BOOL newLine, BOOL Show)
{
// Create feature view window
CWhiteBalanceView *pFeatureView = new CWhiteBalanceView(*this);
pFeatureView->Create(m_Dock, rcDefault);
AddSimpleReBarBand(*pFeatureView, 0, newLine);
pFeatureView->CurrentDeviceChanged(NULL);
m_Features[FeatureID_WhiteBalance] = pFeatureView;
if ( Show )
{
UISetCheck(ID_VIEW_FIRST_FEATURE + FeatureID_WhiteBalance, TRUE);
}
else
{
ShowFeatureWindow(FeatureID_WhiteBalance, FALSE);
}
}
void CMainFrame::AddBandwidthFeature(BOOL newLine, BOOL Show)
{
CBytePerPacketView *pFeatureView = new CBytePerPacketView(*this);
pFeatureView->Create(m_Dock, rcDefault);
AddSimpleReBarBand(*pFeatureView, 0, newLine);
pFeatureView->CurrentDeviceChanged(NULL);
m_Features[FeatureID_Bandwidth] = pFeatureView;
if ( Show )
{
UISetCheck(ID_VIEW_FIRST_FEATURE + FeatureID_Bandwidth, TRUE);
}
else
{
ShowFeatureWindow(FeatureID_Bandwidth, FALSE);
}
}
void CMainFrame::ShowFeatureWindow(BcamFeatureID id, BOOL show)
{
FeatureMap_t::iterator feature = m_Features.find( id );
if ( feature != m_Features.end() )
{
HWND hWnd = feature->second->hWnd();
if ( hWnd != NULL )
{
CReBarCtrl reb(m_hWndToolBar);
// find band which contains the feature
for ( unsigned int i = 2; i < reb.GetBandCount(); ++i ) // band 0 = command bar, band 1 = Tool Bar, band 2 = first feature
{
REBARBANDINFO rbInfo;
rbInfo.cbSize = sizeof(REBARBANDINFO);
rbInfo.fMask = RBBIM_CHILD | RBBIM_STYLE;
reb.GetBandInfo(i, &rbInfo);
if ( rbInfo.hwndChild == hWnd )
{
reb.ShowBand(i, show );
UISetCheck(id + ID_VIEW_FIRST_FEATURE, show );
break;
}
}
}
UpdateLayout();
}
}
void CMainFrame::ShowHelp()
{
HWND hwnd = HtmlHelp(GetDesktopWindow(), HELP_FILE, HH_DISPLAY_TOPIC, NULL) ;
if (hwnd == NULL)
{
CString msg;
msg.Format("Cannot find help file '%s'", HELP_FILE);
MessageBox(msg, "Error", MB_OK | MB_ICONEXCLAMATION);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -