⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cameramanager.cpp

📁 BCAM 1394 Driver
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  pChild->CreateEx(m_MainFrame.m_hWndMDIClient,
    NULL, 
    m_pCurrentDevice->Info.ModelName() + CString(" (") + m_pCurrentDevice->Info.NodeId() + CString(")"));

  m_pCurrentDevice->SetMDIChild(pChild);
  m_Device2ChildFrame[m_pCurrentDevice] = pChild;

  // try to restore the window layout
  if ( m_MainFrame.m_fRestoreWindowLayout )
    pChild->m_View.RestoreLayout();

  BOOL bMaximized = FALSE;
  m_MainFrame.MDIGetActive(&bMaximized);
  if ( bMaximized )
    pChild->ShowWindow(SW_MAXIMIZE);

}

//------------------------------------------------------------------------------
// CChildFrame* CCameraManager::GetCurrentChild()
// Author: 
//------------------------------------------------------------------------------
/**
 * Retrieve a pointer to the window associated with the current device
 *
 */
//------------------------------------------------------------------------------
CChildFrame* CCameraManager::GetCurrentChild()
{
  if ( m_pCurrentDevice == NULL )
    return NULL;
  Device2ChildFrame_t::iterator it = m_Device2ChildFrame.find(m_pCurrentDevice);
  if ( it != m_Device2ChildFrame.end() ) 
    return it->second;
  else 
    return NULL;
}

//------------------------------------------------------------------------------
// bool CCameraManager::ExistMDIChild()
//------------------------------------------------------------------------------
/**
 * Is there already a MDI window associated with the current device
 *
 */
//------------------------------------------------------------------------------
bool CCameraManager::ExistMDIChild()
{
  assert ( m_pCurrentDevice != NULL );
  return ( m_Device2ChildFrame.find(m_pCurrentDevice) != m_Device2ChildFrame.end() );
}


//------------------------------------------------------------------------------
// bool CCameraManager::IsDeviceValid()
//------------------------------------------------------------------------------
/**
 * Is a given device valid, i.e. do we still know the device? 
 *
 */
//------------------------------------------------------------------------------
bool CCameraManager::IsDeviceValid(CCamera* pCamera)
{
  if ( pCamera == NULL ) 
    return false;
  DevName2Camera_t::iterator it = m_DevName2Camera.begin();
  while ( it != m_DevName2Camera.end() )
  {
    if ( it->second == pCamera )
      return true;
    it++;
  }
  return false;
}



//------------------------------------------------------------------------------
// bool CCameraManager::IsGrabActive()
// Author: 
//------------------------------------------------------------------------------
/**
 * Is the current device grabbing?
 *
 */
//------------------------------------------------------------------------------
bool CCameraManager::IsGrabActive()
{
  assert ( m_pCurrentDevice != NULL );
  if ( m_pCurrentDevice != NULL )
    return ( m_pCurrentDevice->IsGrabActive() );
  else
    return false;
}

//------------------------------------------------------------------------------
// void CCameraManager::GrabSingle()
// Author: 
// Date: 20.09.2002
//------------------------------------------------------------------------------
/**
 * Let the current device grab a single image
 *
 */
//------------------------------------------------------------------------------
void CCameraManager::GrabSingle()
{
  assert ( m_pCurrentDevice != NULL );
  if ( m_pCurrentDevice == NULL )
    return;
  assert ( ! m_pCurrentDevice->IsGrabActive() );
  if ( m_pCurrentDevice->IsGrabActive() )
    return;
  if ( ! ExistMDIChild() )
    AddMDIChild();
  m_pCurrentDevice->GrabSingle();

}

//------------------------------------------------------------------------------
// void CCameraManager::GrabContinuous()
// Author: 
//------------------------------------------------------------------------------
/**
 * Let the current device continously grabbing images
 *
 */
//------------------------------------------------------------------------------
void CCameraManager::GrabContinuous()
{
  assert ( m_pCurrentDevice != NULL );
  if ( m_pCurrentDevice == NULL )
    return;
  assert ( ! m_pCurrentDevice->IsGrabActive() );
  if ( m_pCurrentDevice->IsGrabActive() )
    return;
  if ( ! ExistMDIChild() )
    AddMDIChild();
  m_pCurrentDevice->GrabContinuous();
}


//------------------------------------------------------------------------------
// void CCameraManager::PerformWhiteBalance()
// Author: 
//------------------------------------------------------------------------------
/**
 * Let the current device perform a auto white balance
 *
 */
//------------------------------------------------------------------------------
void CCameraManager::PerformWhiteBalance()
{
  assert ( m_pCurrentDevice != NULL );
  if ( m_pCurrentDevice == NULL )
    return;
  assert ( ! m_pCurrentDevice->IsAutoWhiteBalanceActive() );
  if ( m_pCurrentDevice->IsAutoWhiteBalanceActive() )
    return;
  if ( ! ExistMDIChild() )
    AddMDIChild();
  m_pCurrentDevice->PerformWhiteBalance();
}

//------------------------------------------------------------------------------
// void CCameraManager::GrabCancel()
// Author: 
//------------------------------------------------------------------------------
/**
 * Let the current device cancel image acquisition
 *
 */
//------------------------------------------------------------------------------
void CCameraManager::GrabCancel()
{
  assert ( m_pCurrentDevice != NULL );
  if ( m_pCurrentDevice == NULL )
    return;
  assert ( m_pCurrentDevice->IsGrabActive() );
  m_pCurrentDevice->GrabCancel();
}

//------------------------------------------------------------------------------
// void CCameraManager::GrabFromFile(CString FileName)
// Author: 
//------------------------------------------------------------------------------
/**
 * Load an image from file and show it in the MDI child window associated with the current device
 *
 */
//------------------------------------------------------------------------------
void CCameraManager::GrabFromFile(CString FileName)
{
  assert ( m_pCurrentDevice != NULL );
  if ( m_pCurrentDevice == NULL )
    return;
  if ( ! ExistMDIChild() )
    AddMDIChild();
  m_pCurrentDevice->GrabFromFile( FileName);
}


//------------------------------------------------------------------------------
// void CCameraManager::CreateShadingCorrectionTable()
// Author: 
//------------------------------------------------------------------------------
/**
 * Create a shading correction table for the current device 
 *
 * \return    
 */
//------------------------------------------------------------------------------
void CCameraManager::CreateShadingCorrectionTable()
{
  assert ( m_pCurrentDevice != NULL );
  if ( m_pCurrentDevice == NULL )
    return;
  if ( ! ExistMDIChild() )
    AddMDIChild();
  m_pCurrentDevice->CreateShadingCorrectionTable();
}


//------------------------------------------------------------------------------
// void CCameraManager::ShowPixelValue()
// Author: 
//------------------------------------------------------------------------------
/**
 * Show the pixel value under the cursor in the main frame's status bar. 
 * The z-ordering of the windows is considered.
 *
 */
//------------------------------------------------------------------------------
void CCameraManager::ShowPixelValue()
{

  // Iterate through the MDI child windows in descending z-order until the window is found which
  // is under the cursor

  // retrieve handle to first MDI child
  HWND hWndChild = GetWindow(m_MainFrame.m_hWndMDIClient, GW_CHILD);

  CPoint pt;
  GetCursorPos(&pt);

  bool eraseValuePane = true;
  bool erasePosPane = true;

  while ( hWndChild != NULL )
  {
    CRect rect;
    GetWindowRect(hWndChild, &rect);
    if ( rect.PtInRect(pt) )
    {
      // window found 
      // search the object which represents the child window
      Device2ChildFrame_t::iterator it;
	  for (it = m_Device2ChildFrame.begin(); it != m_Device2ChildFrame.end(); ++ it)
      {
        if ( it->second->m_hWnd == hWndChild )
        {
          eraseValuePane = ! it->second->m_View.ShowPixelValue() ; 
          break;
        }
      }
      for ( it = m_Device2ChildFrame.begin(); it != m_Device2ChildFrame.end(); ++it )
      {
        if ( it->second->m_hWnd == hWndChild )
        {
          erasePosPane = ! it->second->m_View.ShowCursorPos();
          break;
        }
      }
      break;
    }
    hWndChild = GetWindow(hWndChild, GW_HWNDNEXT);
  }
  if ( eraseValuePane )
  {
    m_MainFrame.m_Sbar.SetPaneText(ID_VALUE_PANE, CString("") );
  }
  if ( erasePosPane )
  {
    m_MainFrame.m_Sbar.SetPaneText(ID_POS_PANE, CString("") );
  }
}


//------------------------------------------------------------------------------
// void CCameraManager::GetFrameRate(double& fps_acquired, double& fps_displayed)
// Author: 
//------------------------------------------------------------------------------
/**
 * Get the frame rate for the device associated with the child window having the focus.
 *
 * \param     fps_acquired
 * \param     fps_displayed
 */
//------------------------------------------------------------------------------
void CCameraManager::GetFrameRate(double& fps_acquired, double& fps_displayed)
{

   CPoint pt;
   GetCursorPos(&pt);
   fps_acquired = -1;
   fps_displayed = -1;

   HWND hWndChild = m_MainFrame.MDIGetActive();
   if ( hWndChild != NULL )
   {
     for ( Device2ChildFrame_t::iterator it = m_Device2ChildFrame.begin(); it != m_Device2ChildFrame.end(); ++ it)
     {
       if ( it->second->m_hWnd == hWndChild && it->first->IsContinuousGrabActive() )
       {
         it->first->GetFrameRate(fps_acquired, fps_displayed);
         break;
       }
     }
   }

}

//------------------------------------------------------------------------------
// void CCameraManager::AppExit()
// Author: 
//------------------------------------------------------------------------------
/**
 * The main frame informs us that the application is to be closed. 
 * Store the settings of the camera objects and do the cleanup
 *
 * \return    
 *
 */
//------------------------------------------------------------------------------
void CCameraManager::AppExit()
{

  m_pCurrentDevice = NULL;

  for ( DevName2Camera_t::iterator it = m_DevName2Camera.begin(); it != m_DevName2Camera.end(); ++ it )
  {

    CCamera* pCamera = it->second;
    if ( pCamera != NULL )
    {

      // try to save the current configuration and to the registry
      try
      {
        if ( pCamera->IsGrabActive() )
        {
          pCamera->GrabCancel();
        }
        if ( ! pCamera->IsOpen() )
        {
          pCamera->Activate();
        }
        CPropertyBagPtr cameraBag = CRegistryPropertyBag::Create(APPLICATION_KEY + pCamera->Info.NodeId() + "\\Device");
        pCamera->SaveConfiguration(cameraBag);

      }
      catch ( BcamException & e ) 
      {
        e = e;
        ATLTRACE("Exception occured when saving device's configuration: %d (%s)\n", e.Error(), e.Description());
      }
      // Save window Layout  
      Device2ChildFrame_t::iterator wnd = m_Device2ChildFrame.find(pCamera);
      if ( wnd != m_Device2ChildFrame.end() )
        wnd->second->m_View.SaveLayout();
		// delete device
	  delete pCamera;
    }     
  }
  m_DevName2Camera.clear();
}


//------------------------------------------------------------------------------
// void CCameraManager::ReportError(BcamException& e)
// Author: 
// Date: 06.09.2002
//------------------------------------------------------------------------------
/**
 * Convenience function to show an error message
 *
 */
//------------------------------------------------------------------------------
void CCameraManager::ReportError(BcamException& e)
{
  m_MainFrame.ReportError(e);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -