-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainFrm.cpp
285 lines (219 loc) · 6.86 KB
/
MainFrm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/* This file is part of Tomato Analyzer.
Tomato Analyzer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Tomato Analyzer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Tomato Analyzer. If not, see <http://www.gnu.org/licenses/>. */
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "AdvImage.h"
#include "BoundingBoxList.h"
#include "Slice.h"
#include "TomatoAnalyzer.h"
#include "MainFrm.h"
#include "TomatoAnalyzerDoc.h"
#include "SingleSliceView.h"
#include "TomatoAnalyzerView.h"
#include "SliceInfoFormView.h"
#include "MeasureItemList.h"
#include "FruitDataView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CAboutDlg)
ON_WM_CREATE()
ON_WM_SIZE()
ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnSelectZoomLevel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
static UINT nToolBarBtn[]={ID_FILE_OPEN,
ID_EXPORT_DATA,
0,
ID_FILE_PREV,
ID_FILE_NEXT,
0,
ID_ZOOM,
0,
ID_ANALYZE_IMG,
ID_ANALYZE_COLOR,
ID_MANUAL_REVISE
};
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
m_bSplitterWndInitialized=FALSE;
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
void CMainFrame::OnSelectZoomLevel(NMHDR * pNotifyStruct, LRESULT * result)
{
POINT pt;
GetCursorPos(&pt);
CMenu MunualMenu;
MunualMenu.LoadMenu(IDR_ZOOMMENU);
CMenu * pPopup = NULL;
NMTOOLBAR * pNt = (NMTOOLBAR *)pNotifyStruct;
switch(pNt->iItem)
{
case ID_ZOOM:
pPopup = MunualMenu.GetSubMenu(0);
break;
case ID_MANUAL_REVISE:
pPopup = MunualMenu.GetSubMenu(1);
break;
case ID_SAVE_FRUIT:
{
char szFileName[_MAX_PATH];
char szMenuItemString[_MAX_PATH];
CTomatoAnalyzerDoc * pDoc = (CTomatoAnalyzerDoc *)GetActiveDocument();
pDoc->GetArchiveName(szFileName);
lstrcpy(szMenuItemString, "Save to ");
lstrcat(szMenuItemString, szFileName);
pPopup = MunualMenu.GetSubMenu(3);
pPopup->ModifyMenu(ID_FILE_SAVE, MF_BYCOMMAND|MF_STRING, ID_FILE_SAVE, szMenuItemString);
}
break;
}
if(NULL != pPopup)
pPopup->TrackPopupMenu( TPM_LEFTALIGN|TPM_LEFTBUTTON,
pt.x,
pt.y,
this
);
MunualMenu.DestroyMenu();
return;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT|TBSTYLE_TRANSPARENT|TBSTYLE_LIST ) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
CToolBarCtrl& tbCtrl = m_wndToolBar.GetToolBarCtrl();
tbCtrl.SetExtendedStyle( TBSTYLE_EX_DRAWDDARROWS );
m_wndToolBar.SetButtonText (0,"Open Image");
m_wndToolBar.SetButtonStyle(0, TBSTYLE_BUTTON|TBSTYLE_AUTOSIZE);
m_wndToolBar.SetButtonText (1,"Save Fruit");
m_wndToolBar.SetButtonStyle(1, TBSTYLE_DROPDOWN|TBSTYLE_AUTOSIZE);
m_wndToolBar.SetButtonText (3,"Export Data");
m_wndToolBar.SetButtonStyle(3, TBSTYLE_BUTTON|TBSTYLE_AUTOSIZE);
m_wndToolBar.SetButtonText (5,"Fit size");
m_wndToolBar.SetButtonStyle(5, TBSTYLE_DROPDOWN|TBSTYLE_AUTOSIZE);
m_wndToolBar.SetButtonText (7,"Analyze");
m_wndToolBar.SetButtonStyle(7, TBSTYLE_BUTTON|TBSTYLE_AUTOSIZE);
m_wndToolBar.SetButtonText (8,"Color test");
m_wndToolBar.SetButtonStyle(8, TBSTYLE_BUTTON|TBSTYLE_AUTOSIZE);
m_wndToolBar.SetButtonText (9,"Revise");
m_wndToolBar.SetButtonStyle(9, TBSTYLE_DROPDOWN|TBSTYLE_AUTOSIZE);
if (!m_wndReBar.Create(this) ||
!m_wndReBar.AddBar(&m_wndToolBar))
{
TRACE0("Failed to create rebar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Remove this if you don't want tool tips
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY);
HICON theIcon;
theIcon = AfxGetApp()->LoadIcon(IDR_OSU_TOMATO);
SetIcon(theIcon, FALSE);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
| WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE | WS_SYSMENU;
return TRUE;
}
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
if(SIZE_MINIMIZED != nType && m_bSplitterWndInitialized)
{
m_wndSplitWnd.SetColumnInfo(0, cx/2, 100);
m_wndSplitRightHalf.SetRowInfo(0, cy*11/18, 100);
}
// TODO: Add your message handler code here
CFrameWnd::OnSize(nType, cx, cy);
}
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
// CMainFrame message handlers
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
//first split the window vertically into 2 half
m_wndSplitWnd.CreateStatic(this, 1, 2);
//create source code view
m_wndSplitWnd.CreateView(
0, 0,
RUNTIME_CLASS(CTomatoAnalyzerView),
CSize(0, 0),
pContext
);
//split the right half vertically into 2 windows
m_wndSplitRightHalf.CreateStatic(
&m_wndSplitWnd,
2, 1,
WS_CHILD|WS_VISIBLE|WS_BORDER,
m_wndSplitWnd.IdFromRowCol(0,1)
);
//create error view
m_wndSplitRightHalf.CreateView(
0, 0,
RUNTIME_CLASS(CSingleSliceView),
CSize(400, 400),
pContext
);
//create object content view
m_wndSplitRightHalf.CreateView(
1, 0,
//RUNTIME_CLASS(CSliceInfoFormView),
RUNTIME_CLASS(CFruitDataView), //
CSize(400, 100),
pContext
);
m_bSplitterWndInitialized=TRUE;
return TRUE;
}