1 /*M///////////////////////////////////////////////////////////////////////////////////////
\r
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
\r
5 // By downloading, copying, installing or using the software you agree to this license.
\r
6 // If you do not agree to this license, do not download, install,
\r
7 // copy or use the software.
\r
10 // Intel License Agreement
\r
11 // For Open Source Computer Vision Library
\r
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
\r
14 // Third party copyrights are property of their respective owners.
\r
16 // Redistribution and use in source and binary forms, with or without modification,
\r
17 // are permitted provided that the following conditions are met:
\r
19 // * Redistribution's of source code must retain the above copyright notice,
\r
20 // this list of conditions and the following disclaimer.
\r
22 // * Redistribution's in binary form must reproduce the above copyright notice,
\r
23 // this list of conditions and the following disclaimer in the documentation
\r
24 // and/or other materials provided with the distribution.
\r
26 // * The name of Intel Corporation may not be used to endorse or promote products
\r
27 // derived from this software without specific prior written permission.
\r
29 // This software is provided by the copyright holders and contributors "as is" and
\r
30 // any express or implied warranties, including, but not limited to, the implied
\r
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
\r
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
\r
33 // indirect, incidental, special, exemplary, or consequential damages
\r
34 // (including, but not limited to, procurement of substitute goods or services;
\r
35 // loss of use, data, or profits; or business interruption) however caused
\r
36 // and on any theory of liability, whether in contract, strict liability,
\r
37 // or tort (including negligence or otherwise) arising in any way out of
\r
38 // the use of this software, even if advised of the possibility of such damage.
\r
40 //M*/// MainFrm.cpp : implementation of the CMainFrame class
\r
44 #include "StereoGR.h"
\r
46 #include "MainFrm.h"
\r
47 #include "StereoGRDoc.h"
\r
48 #include "StereoGRView.h"
\r
51 #define new DEBUG_NEW
\r
53 static char THIS_FILE[] = __FILE__;
\r
56 /////////////////////////////////////////////////////////////////////////////
\r
59 IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
\r
61 BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
\r
62 //{{AFX_MSG_MAP(CMainFrame)
\r
65 ON_COMMAND(ID_DGRECOG, OnDgRecog)
\r
66 ON_UPDATE_COMMAND_UI(ID_DGRECOG, OnUpdateDgrecog)
\r
71 static UINT indicators[] =
\r
73 ID_SEPARATOR, // status line indicator
\r
80 /////////////////////////////////////////////////////////////////////////////
\r
81 // CMainFrame construction/destruction
\r
83 CMainFrame::CMainFrame()
\r
85 m_isTimerStarted = FALSE;
\r
89 CMainFrame::~CMainFrame()
\r
93 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
\r
95 if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
\r
98 if (!m_wndToolBar.CreateEx(this) ||
\r
99 !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
\r
101 TRACE0("Failed to create toolbar\n");
\r
102 return -1; // fail to create
\r
104 if (!m_wndDlgBar.Create(this, IDR_MAINFRAME,
\r
105 CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
\r
107 TRACE0("Failed to create dialogbar\n");
\r
108 return -1; // fail to create
\r
111 if (!m_wndReBar.Create(this) ||
\r
112 !m_wndReBar.AddBar(&m_wndToolBar) ||
\r
113 !m_wndReBar.AddBar(&m_wndDlgBar))
\r
115 TRACE0("Failed to create rebar\n");
\r
116 return -1; // fail to create
\r
119 if (!m_wndStatusBar.Create(this) ||
\r
120 !m_wndStatusBar.SetIndicators(indicators,
\r
121 sizeof(indicators)/sizeof(UINT)))
\r
123 TRACE0("Failed to create status bar\n");
\r
124 return -1; // fail to create
\r
127 // TODO: Remove this if you don't want tool tips
\r
128 m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
\r
129 CBRS_TOOLTIPS | CBRS_FLYBY);
\r
131 ShowControlBar(&m_wndToolBar, SW_SHOW, FALSE);
\r
132 ShowControlBar(&m_wndDlgBar, SW_HIDE, FALSE);
\r
134 m_menu.LoadMenu(IDR_STEREOTYPE);
\r
139 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
\r
141 if( !CMDIFrameWnd::PreCreateWindow(cs) )
\r
143 // TODO: Modify the Window class or styles here by modifying
\r
144 // the CREATESTRUCT cs
\r
149 /////////////////////////////////////////////////////////////////////////////
\r
150 // CMainFrame diagnostics
\r
153 void CMainFrame::AssertValid() const
\r
155 CMDIFrameWnd::AssertValid();
\r
158 void CMainFrame::Dump(CDumpContext& dc) const
\r
160 CMDIFrameWnd::Dump(dc);
\r
165 /////////////////////////////////////////////////////////////////////////////
\r
166 // CMainFrame message handlers
\r
169 CStatusBar* CMainFrame::GetStatusBar()
\r
171 return &m_wndStatusBar;
\r
174 void CMainFrame::AddView(CStereoGRView *pView)
\r
176 int id = pView->GetDocument()->GetDocType();
\r
178 app->SetView(id, pView);
\r
179 if(!m_isTimerStarted)
\r
182 m_isTimerStarted = TRUE;
\r
188 void CMainFrame::OnTimer(UINT nIDEvent)
\r
191 CMDIFrameWnd::OnTimer(nIDEvent);
\r
194 void CMainFrame::Update()
\r
196 /* Count the frame rate */
\r
197 float fps = CountRate();
\r
199 str.Format("%.1f frames per second", fps);
\r
200 // This feature is disabled in the current release
\r
201 // m_wndStatusBar.SetPaneText(0, LPCTSTR(str));
\r
207 void CMainFrame::RemoveView(CStereoGRView *pView)
\r
209 int id = pView->GetDocument()->GetDocType();
\r
211 app->SetView(id, 0);
\r
212 int* viewIds = app->GetViewIDs();
\r
218 void CMainFrame::InitializeMenu()
\r
220 CMenu* pMenu = GetMenu();
\r
221 pMenu = pMenu->GetSubMenu(1);
\r
222 // pMenu->InsertMenu(0, MF_BYPOSITION | MF_STRING, 1100, "Test");
\r
226 BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
\r
228 CStereoGRApp* app = (CStereoGRApp*)AfxGetApp();
\r
229 int* viewIds = app->GetViewIDs();
\r
230 if(pHandlerInfo == 0)
\r
232 if(nID >= ID_VIEW1 && nID <= ID_VIEW12)
\r
234 int id = nID - ID_VIEW1;
\r
235 if(nCode == CN_COMMAND)
\r
237 viewIds[id] = !viewIds[id];
\r
238 CStereoGRApp* app = (CStereoGRApp*)AfxGetApp();
\r
245 app->CloseView(id);
\r
249 else if(nCode == CN_UPDATE_COMMAND_UI)
\r
251 CCmdUI* pCmdUI = (CCmdUI*)pExtra;
\r
252 if((nID >= ID_VIEW1 && nID <= ID_VIEW6) || nID == ID_VIEW8 || (nID >= ID_VIEW10 && nID <= ID_VIEW12))
\r
255 pCmdUI->SetCheck(viewIds[id]);
\r
259 pCmdUI->Enable(FALSE);
\r
267 return CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
\r
271 float CMainFrame::CountRate()
\r
275 m_time = GetTickCount();
\r
280 long time = GetTickCount();
\r
286 float fps = 1000.0f*m_drawCount/(GetTickCount() - m_time);
\r
292 void CMainFrame::OnDgRecog()
\r
294 CStereoGRApp* app = ((CStereoGRApp*)AfxGetApp());
\r
296 app->m_doRecog = !app->m_doRecog;
\r
298 //CButton* pbut = (CButton*)GetDlgItem( ID_DGRECOG );
\r
299 //pbut->SetCheck( app->m_doRecog );
\r
301 // TODO: Add your command handler code here
\r
304 void CMainFrame::OnUpdateDgrecog(CCmdUI* pCmdUI)
\r
306 CStereoGRApp* app = ((CStereoGRApp*)AfxGetApp());
\r
308 //CButton* pbut = (CButton*)pCmdUI;
\r
309 pCmdUI->SetCheck( app->m_doRecog );
\r
311 // TODO: Add your command update UI handler code here
\r
315 void CMainFrame::OnClose()
\r
319 for(int i = 0; i < VIEWS_COUNT; i++)
\r
321 if(app->GetView(i) == 0)
\r
325 str.Format("Settings\\StereoGR\\View%d", i);
\r
329 GetClRect(&clientRect);
\r
330 ClientToScreen(&clientRect);
\r
331 app->GetView(i)->GetParent()->GetWindowRect(&viewRect);
\r
332 x = viewRect.left - clientRect.left;
\r
333 y = viewRect.top - clientRect.top;
\r
334 app->WriteProfileInt(LPCTSTR(str), "left", x);
\r
335 app->WriteProfileInt(LPCTSTR(str), "top", y);
\r
338 app->SaveSettings();
\r
339 CMDIFrameWnd::OnClose();
\r
342 BOOL CMainFrame::DestroyWindow()
\r
346 return CMDIFrameWnd::DestroyWindow();
\r
349 void CMainFrame::GetClRect( LPRECT lpRect ) const
\r
351 CWnd::GetWindowRect(lpRect);
\r
353 m_wndToolBar.GetWindowRect(&toolbarRect);
\r
354 lpRect->top += toolbarRect.Size().cy;
\r