www.pudn.com > DalsaNetlink.rar > CyPropertySheet.cpp


// CyPropertySheet.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include  
#include "resource.h" 
#include "CyPropertySheet.h" 
#include "CyApp.h" 
#include "CyAcquisitionPage.h" 
#include  
#include  
using namespace std; 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CyPropertySheet 
 
CyPropertySheet::CyPropertySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage) 
	:CPropertySheet(pszCaption, pParentWnd, iSelectPage), 
     mInitialized( false ), 
     mConfigEnabled( false ) 
{ 
} 
 
CyPropertySheet::~CyPropertySheet() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CyPropertySheet, CPropertySheet) 
	//{{AFX_MSG_MAP(CyPropertySheet) 
	ON_WM_CREATE() 
	ON_COMMAND(ID_APP_EXIT, OnAppExit) 
	//}}AFX_MSG_MAP 
 
    ON_BN_CLICKED(IDC_DEVICE_CONFIGURE, OnDeviceConfigure) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CyPropertySheet message handlers 
 
int CyPropertySheet::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
    if (CPropertySheet::OnCreate(lpCreateStruct) == -1) 
		return -1; 
 
	mMenu.LoadMenu( IDR_MAINFRAME ); 
    SetMenu( &mMenu ); 
    SetIcon( AfxGetApp()->LoadIcon( IDR_MAINFRAME ), FALSE ); 
    SetIcon( AfxGetApp()->LoadIcon( IDR_MAINFRAME ), TRUE ); 
 
    return 0; 
} 
 
void CyPropertySheet::OnAppExit()  
{ 
    EndDialog( IDCANCEL ); 
} 
 
BOOL CyPropertySheet::OnInitDialog()  
{ 
	BOOL bResult = CPropertySheet::OnInitDialog(); 
 
    // Enable the minimize function 
    if ( CMenu* pSysMenu = GetSystemMenu(FALSE) ) 
    { 
        pSysMenu->InsertMenu(1, MF_BYPOSITION | MF_STRING, SC_MAXIMIZE, "Ma&ximize"); 
        pSysMenu->InsertMenu(1, MF_BYPOSITION | MF_STRING, SC_MINIMIZE, "Mi&nimize"); 
        pSysMenu->InsertMenu(0, MF_BYPOSITION | MF_STRING, SC_RESTORE, "&Restore"); 
    } 
    ::SetWindowLong(m_hWnd, GWL_STYLE, GetStyle() | WS_MINIMIZEBOX); 
 
    // Adjust the height of the prop sheet for the menu 
    CRect lRect; 
    GetWindowRect( lRect ); 
    lRect.bottom += 19; 
    SetWindowPos( &wndTop, lRect.top, lRect.left, lRect.Width(), lRect.Height(), 0 ); 
 
    // Remove the OK button    
    CWnd* pOK = GetDlgItem( IDOK ); 
    CyAssert( pOK != 0 ); 
    pOK->ShowWindow( SW_HIDE ); 
    pOK->EnableWindow( FALSE ); 
 
    // Remove the cancel button and gets its position, so  
    // we get its real estate 
    CRect lButtonRect; 
    CWnd* pCancel = GetDlgItem( IDCANCEL ); 
    CyAssert( pCancel != 0 ); 
    pCancel->ShowWindow( SW_HIDE ); 
    pCancel->EnableWindow( FALSE ); 
    pCancel->GetWindowRect( lButtonRect ); 
    ScreenToClient( lButtonRect ); 
 
    // Make the button a little wider 
    lButtonRect.left -= 8; 
 
    mConfigure.Create( "&Configure...", 
                       WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 
                       lButtonRect, 
                       this, 
                       IDC_DEVICE_CONFIGURE ); 
    mConfigure.SetFont( GetFont() ); 
    mConfigure.SetWindowPos( pCancel, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE ); 
    mConfigure.EnableWindow( mConfigEnabled ); 
         
    // Change "&Apply" to "A&pply", because we already have "&Add" (and d is taken) 
    SetDlgItemText( ID_APPLY_NOW, "A&pply" ); 
 
    mInitialized = true; 
 
	return bResult; 
} 
 
void CyPropertySheet::OnDeviceConfigure()  
{ 
    CyApp* lApp = reinterpret_cast( AfxGetApp() ); 
    if ( lApp->HasCamera() ) 
    { 
        CyCameraInterface& lCamera = lApp->GetCamera(); 
        CyGrabber& lGrabber = lApp->GetGrabber(); 
        CyDevice& lDevice = lApp->GetDevice(); 
        unsigned int lID; 
 
        if ( lCamera.ShowDialog( GetSafeHwnd() ) == CY_RESULT_OK ) 
        { 
            BeginWaitCursor(); 
            lApp->mConfigChanged = true; 
 
            // State of grabbing and displaying for channels 
            std::map< CyChannelID, bool > 
                lDisplaying; 
            std::map< CyChannelID, bool > 
                lGrabbing; 
 
            // check the state of the displays and grabbing for all channels 
            for ( lID = 0; lID < lDevice.GetChannelCount(); ++lID ) 
            { 
                // Get the channel from the config 
                const CyChannel lChannel( lDevice.GetChannel( lID ) ); 
 
                // Check the display and stop it for the current channel 
                lDisplaying[ lID ] = lApp->GetDisplay().IsDisplaying( lID ); 
                if ( lDisplaying[ lID ] ) 
                    lApp->GetDisplay().StopDisplaying( lID ); 
 
                // Check the grabbing and stop it for the current channel 
                lGrabbing[ lID ] = lGrabber.IsStarted( lChannel ); 
                if ( lGrabbing[ lID ] ) 
                    lGrabber.StopGrabbing( lChannel ); 
            } 
 
            // Update the camera 
            CyResult lResult = lCamera.UpdateToCamera(); 
            if ( lResult != CY_RESULT_OK ) 
            { 
                CyErrorInfo lError; 
                lApp->GetCamera().GetErrorInfo( &lError ); 
 
                ostringstream lMessage; 
                lMessage << "Could not update camera because " << lError.mMessage; 
                AfxMessageBox( lMessage.str().c_str() ); 
                EndWaitCursor(); 
                return; 
            } 
 
            // Update the buffer 
            for ( lID = 0; lID < lDevice.GetChannelCount(); ++lID ) 
            { 
                // Get the channel from the config 
                const CyChannel lChannel( lDevice.GetChannel( lID ) ); 
 
                // adjust the buffer for this channel 
                CyImageBuffer& lBuffer = lApp->GetBuffer( lChannel ); 
                unsigned short lSizeX, lSizeY, lOffsetX, lOffsetY, lDecimationX, lDecimationY, lDecimationBlockX, lDecimationBlockY; 
                unsigned short lBinningX, lBinningY; 
                CyPixelTypeID lPixelType; 
                lCamera.GetSizeX( lSizeX ); 
                lCamera.GetSizeY( lSizeY ); 
                lCamera.GetOffsetX( lOffsetX ); 
                lCamera.GetOffsetY( lOffsetY ); 
                lCamera.GetDecimationX( lDecimationX ); 
                lCamera.GetDecimationY( lDecimationY ); 
                lCamera.GetDecimationBlockX( lDecimationBlockX ); 
                lCamera.GetDecimationBlockY( lDecimationBlockY ); 
                lCamera.GetBinningX( lBinningX ); 
                lCamera.GetBinningY( lBinningY ); 
                lCamera.GetEffectivePixelType( lPixelType ); 
 
	            if ( ( lDecimationX != 0 ) && ( lDecimationY != 0 ) ) 
	            { 
                    lSizeX = ( ( lSizeX / lBinningX ) + ( ( lSizeX % lBinningX ) ? 1 : 0)); 
                    lSizeX = ( ( lSizeX / lDecimationBlockX / lDecimationX ) + ( ( ( lSizeX / lDecimationBlockX ) % lDecimationX ) ? 1 : 0) ); 
                    lSizeX *= lDecimationBlockX; 
                    lSizeY = ( ( lSizeY / lBinningY ) + ( ( lSizeY % lBinningY ) ? 1 : 0)); 
                    lSizeY = ( ( lSizeY / lDecimationBlockY / lDecimationY ) + ( ( ( lSizeY / lDecimationBlockY ) % lDecimationY ) ? 1 : 0) ); 
                    lSizeY *= lDecimationBlockY; 
		            lBuffer.SetCapacity( lSizeX, lSizeY, lPixelType ); 
	            } 
            } 
 
 
            // Restart the displays and grabbing for the channels 
            // check the state of the displays and grabbing for all channels 
            for ( lID = 0; lID < lDevice.GetChannelCount(); ++lID ) 
            { 
                // Get the channel from the config 
                const CyChannel lChannel( lDevice.GetChannel( lID ) ); 
 
                // restart the grabbing 
                if ( lGrabbing[ lID ] ) 
                    lGrabber.StartGrabbing( lChannel, lApp->GetBuffer( lChannel ) ); 
 
                // restart the display 
                if ( lDisplaying[ lID ] ) 
                { 
                    // TODO: lFlags 
 
                    lApp->GetDisplay().StartDisplaying( lApp->GetBuffer( lChannel ), lID, lApp->mBayerFlag ); 
                } 
            } 
 
            EndWaitCursor(); 
        } 
    } 
} 
 
void CyPropertySheet::EnableConfigure( bool aEnable ) 
{ 
    if ( mInitialized ) 
        mConfigure.EnableWindow( aEnable ); 
    mConfigEnabled = aEnable; 
} 
 
void CyPropertySheet::WinHelp(DWORD dwData, UINT nCmd)  
{ 
    GetActivePage()->WinHelp( dwData, nCmd ); 
}