-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCsetParSUB.cpp
More file actions
402 lines (320 loc) · 10.4 KB
/
Copy pathCsetParSUB.cpp
File metadata and controls
402 lines (320 loc) · 10.4 KB
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
// CsetParSUB.cpp : 实现文件
//
#include "stdafx.h"
#include "SoperCheck.h"
#include "CsetParSUB.h"
#include "afxdialogex.h"
CsetParSUB *pCsetParSUB;
// CsetParSUB 对话框
IMPLEMENT_DYNAMIC(CsetParSUB, CDialogEx)
CsetParSUB::CsetParSUB(CWnd* pParent /*=NULL*/)
: CDialogEx(CsetParSUB::IDD, pParent)
{
m_font.CreateFont(22, 0, 0, 0, FW_HEAVY, 0, 0, 0,
DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("微软雅黑"));
m_pSliderMAXCnt = 0;
//m_CamIdex = -1;
}
CsetParSUB::~CsetParSUB()
{
}
void CsetParSUB::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TREE1, m_TreeCtl);
}
BEGIN_MESSAGE_MAP(CsetParSUB, CDialogEx)
ON_BN_CLICKED(IDC_BUTTON1, &CsetParSUB::OnBnClickedButton1)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, &CsetParSUB::OnTvnSelchangedTree1)
//ON_MESSAGE(WM_MYMSG_RegetParaV, &CsetParSUB::OnTvnSelchangedTree1)
ON_WM_HSCROLL()
END_MESSAGE_MAP()
// CsetParSUB 消息处理程序
void CsetParSUB::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
CString str;
str.Format(_T("测试[%d]"), m_CamInfoindex);
AfxMessageBox(str);
return;
//CWnd * pCWnd;
//HWND Handle;
//Handle = pCWnd->GetSafeHwnd();
//pCWnd = FromHandle(Handle);
//
// // hWnd;
// CWnd* pchWnd = GetActiveWindow();//
// HWND hWnd = pchWnd->GetSafeHwnd();
// hWnd = GetDlgItem(IDD_DIALOG_PARASUB)->GetSafeHwnd();
// hWnd = pCsetParSUB->m_hWnd;
// // hWnd = pchWnd->GetSafeHandle();
//
//
// //int m = PostMessageW(TVN_SELCHANGED, NULL, NULL);
//
// //PostMessage(hWnd, TVN_SELCHANGED, NULL, NULL);
// ////SendMessage(m_hWnd, DM_SETDEFID, nID, 0);
// //SendMessage(hWnd, TVN_SELCHANGED, NULL, NULL);
//
// //int ret = SendMessageW(TVN_SELCHANGED);
// //int ret = ::SendMessageW(hWnd, TVN_SELCHANGED, NULL, NULL);
// //int k = GetLastError();
// //int u = 99;
//
// NMTREEVIEW tv;
// memset((void*)&tv, 0, sizeof(tv));
// tv.hdr.hwndFrom = m_TreeCtl.m_hWnd;
// tv.hdr.idFrom = ::GetClassLong(m_TreeCtl.m_hWnd, GWL_ID);
// tv.hdr.code = TVN_SELCHANGED;
// tv.action = TVN_SELCHANGED;
//
////HANDLE ffhandle= m_TreeCtl.GetParentItem()
// //::SendMessage(m_TreeCtl.m_hWnd, WM_NOTIFY, (WPARAM)tv.hdr.idFrom, (LPARAM)&tv);
// ::SendMessage(hWnd, WM_NOTIFY, (WPARAM)tv.hdr.idFrom, (LPARAM)&tv);
//
//
// int k = GetLastError();
// int u = 99;
}
BOOL CsetParSUB::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在此添加额外的初始化
m_TreeCtl.SetFont(&m_font);
m_TreeCtl.SetLineColor(RGB(0, 150, 220));// 设置TreeCtrl线条颜色
m_TreeCtl.SetTextColor(RGB(40, 101, 181));//设置tree的背景色
m_TreeCtl.SetBkColor(RGB(240, 240, 240));//设置tree的背景色
MySEQ* pC = p_MyCamPara;
HTREEITEM rootItem = NULL;
for (int i = 0; i < pC->m_DeFectParaStrArr.size(); i++)
{
string defectName = pC->m_DeFectParaStrArr[i].defectName;
rootItem = m_TreeCtl.InsertItem(C2W(defectName.c_str()), 0, 0, NULL);
}
//getDeFectPara();
//rootItem = m_TreeCtl.InsertItem(TEXT("相机参数"), 0, 0, NULL);
//m_TreeCtl.SelectItem(rootItem);
pCsetParSUB = this;
return TRUE; // return TRUE unless you set the focus to a control
}
void CsetParSUB::getDeFectPara()
{
vector<DeFectPara>* pDeFectPara = (vector<DeFectPara>*)(void*)&p_MyCamPara->m_DeFectParaStrArr;
for (int i = 0; i < pDeFectPara->size(); i++)
{
//int i = m_CamIdex;
DeFectPara* _DeFectPara = &p_MyCamPara->m_DeFectParaStrArr[i];
oneDeFectPara _oneDeFectPara;
for (int oneindex = 0; oneindex < _DeFectPara->defectParaCnt; oneindex++)
{
_oneDeFectPara.camIndex = m_CamInfoindex;
_oneDeFectPara.paraIndex = i;
_oneDeFectPara.parentName = _DeFectPara->defectName;
string sTmp = _DeFectPara->defectParaArrStr[oneindex];
int begain = sTmp.find("'");
int pos1 = sTmp.find(",");
_oneDeFectPara.name = sTmp.substr(begain + 1, pos1 - begain - 1);
int pos2 = sTmp.find(",", pos1 + 1);
_oneDeFectPara.paraMax = atoi(sTmp.substr(pos1 + 1, pos2 - pos1 - 1).c_str());
int end = sTmp.find("'", pos2 + 1);
_oneDeFectPara.paraVal = atoi(sTmp.substr(pos2 + 1, end - pos2 - 1).c_str());
if (p_MapParaKey != NULL)
{
ParaKey parkey(m_CamInfoindex, _oneDeFectPara.parentName, _oneDeFectPara.name);
auto m = p_MapParaKey->find(parkey);
if (m == p_MapParaKey->end())
{
p_MapParaKey->insert(make_pair(parkey, _oneDeFectPara.paraVal));
}
else
{
m->second = _oneDeFectPara.paraVal;
}
}
m_oneDeFectPara.push_back(_oneDeFectPara);
}
}
initCamExpGain();
}
void CsetParSUB::OnTvnSelchangedTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
m_oneDeFectPara.clear();
getDeFectPara();
// TODO: 在此添加控件通知处理程序代码
CRect tabRect;
m_TreeCtl.GetClientRect(tabRect);
CRect CRectq(tabRect);
CRectq.top = tabRect.bottom;
CRectq.left = tabRect.left + 80;
CRectq.right = tabRect.right + 5;
CRectq.bottom = CRectq.top + 60;
CString strText; // 树节点的标签文本字符串
// 获取当前选中节点的句柄
HTREEITEM hItem = m_TreeCtl.GetSelectedItem();
// 获取选中节点的标签文本字符串
strText = m_TreeCtl.GetItemText(hItem);
string strNm = CW2A(strText.GetString());
m_sliderParentName = strNm;
for (int i = 0; i < m_pSliderMAXCnt + 1; i++)
{
if (m_pSlider[i] != NULL){ m_pSlider[i]->ShowWindow(SW_HIDE); delete m_pSlider[i]; m_pSlider[i] = NULL; }
if (m_pSLabel[i] != NULL){ m_pSLabel[i]->ShowWindow(SW_HIDE); delete m_pSLabel[i]; m_pSLabel[i] = NULL; }
if (m_pSValue[i] != NULL){ m_pSValue[i]->ShowWindow(SW_HIDE); delete m_pSValue[i]; m_pSValue[i] = NULL; }
}
int slidercnt = 0;
char tmpC[50] = { 0 };
for (int oneindex = 0; oneindex < m_oneDeFectPara.size(); oneindex++)
{
if (m_oneDeFectPara[oneindex].parentName == m_sliderParentName)
{
if (m_pSliderMAXCnt < slidercnt)m_pSliderMAXCnt = slidercnt;
CRectq.top = CRectq.bottom + 20;
CRectq.bottom = CRectq.top + 20;
m_pSlider[slidercnt] = new CSliderCtrl;
m_pSlider[slidercnt]->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH,
CRectq, this, IDC_SLIDER1_PARA1);
m_pSlider[slidercnt]->ShowWindow(SW_SHOW);
string deFn = m_oneDeFectPara[oneindex].name;
int maxRange = m_oneDeFectPara[oneindex].paraMax;
int pos = m_oneDeFectPara[oneindex].paraVal;
itoa(pos, tmpC, 10);
if (pos > maxRange) pos = maxRange;
m_pSlider[slidercnt]->SetRange(0, maxRange);
m_pSlider[slidercnt]->SetPos(pos);
m_pSLabel[slidercnt] = new CStatic;
m_pSValue[slidercnt] = new CStatic;
CRect CRectLable(CRectq), CRectLValue(CRectq);
CRectLable.left = CRectq.left - 80; CRectLable.right = CRectLable.left + 75;
CRectLValue.left = CRectq.right; CRectLValue.right = CRectLValue.left + 200;
m_pSLabel[slidercnt]->Create(C2W(deFn.c_str()), WS_CHILD | WS_VISIBLE, CRectLable, this);
m_pSValue[slidercnt]->Create(C2W(tmpC), WS_CHILD | WS_VISIBLE, CRectLValue, this);
slidercnt++;
}
}
// 将字符串显示到编辑框中
SetDlgItemText(IDC_STATIC, strText);
//AfxMessageBox(strText);
*pResult = 0;
}
wchar_t* CsetParSUB::C2W(const char* str)
{
int len = MultiByteToWideChar(CP_OEMCP, 0, str, -1/*null terminated*/, NULL, 0);
wchar_t* wstr = new wchar_t[len + 1];
MultiByteToWideChar(CP_OEMCP, 0, str, -1/*null terminated*/, wstr, len);
return wstr;
}
char* CsetParSUB::W2C(const wchar_t *pwstr)
{
int nlength = wcslen(pwstr);
//获取转换后的长度
int nbytes = WideCharToMultiByte(0, 0, pwstr, nlength, NULL, 0, NULL, NULL);
char* pcstr = new char[nbytes + 1];
// 通过以上得到的结果,转换unicode 字符为ascii 字符
WideCharToMultiByte(0, 0, pwstr, nlength, pcstr, nbytes, NULL, NULL);
pcstr[nbytes] = '\0';
return pcstr;
}
bool CsetParSUB::getMapValue(ParaKey parkey, double& value)
{
auto m = p_MapParaKey->find(parkey);
if (m != p_MapParaKey->end())
{
value = m->second;
return true;
}
value = 0;
return false;
}
void CsetParSUB::initCamExpGain()
{
sub2Fun _sub2Fun;
_sub2Fun.fparent = "相机参数";
_sub2Fun.fpara = "exp";
_sub2Fun.cam_Index = m_CamInfoindex;
m_onMessage(this, MSG_SetOneGainExp, (void*)&_sub2Fun, m_CamInfoindex);
_sub2Fun.fpara = "gain";
m_onMessage(this, MSG_SetOneGainExp, (void*)&_sub2Fun, m_CamInfoindex);
m_onMessage(this, MSG_SubsubClose, NULL, NULL);
//double value = 0.0;
//ParaKey parkeyExp(m_CamInfoindex, "相机参数", "exp");
//getMapValue(parkeyExp, value);
//
//ParaKey parkeyGain(m_CamInfoindex, "相机参数", "gain");
//getMapValue(parkeyGain, value);
}
void CsetParSUB::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
char tmpC[20] = { 0 };
CString strLable;
string paraName;
int value = 0;
for (int i = 0; i < m_pSliderMAXCnt + 1; i++)
{
if (m_pSlider[i] == NULL || m_pSValue[i] == NULL) continue;
if (pScrollBar->m_hWnd == m_pSlider[i]->m_hWnd)
{
value = m_pSlider[i]->GetPos();
itoa(value, tmpC, 10);
m_pSValue[i]->SetWindowText(C2W(tmpC));
m_pSLabel[i]->GetWindowText(strLable);
paraName = CT2A(strLable.GetBuffer());
break;
}
}
paraMerge2Config(m_CamInfoindex, m_sliderParentName, paraName, value);
CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CsetParSUB::paraMerge2Config(int camInfoId, string sliderParentName, string paraName, int value)
{
//make map better
char valueC[20] = { 0 };
itoa(value, valueC, 10);
ParaKey parkey(camInfoId, sliderParentName, paraName);
auto m = p_MapParaKey->find(parkey);
if (m == p_MapParaKey->end())
{
p_MapParaKey->insert(make_pair(parkey, value));
}
else
{
m->second = value;
}
sub2Fun _sub2Fun;//没有将max传入
_sub2Fun.fparent = sliderParentName;
_sub2Fun.fpara = paraName;
_sub2Fun.val = value;
_sub2Fun.cam_Index = camInfoId;
if (paraName == "gain" || paraName == "exp")
{
m_onMessage(this, MSG_SetOneGainExp, (void*)&_sub2Fun, m_CamInfoindex);
}
else
{
m_onMessage(this, MSG_NULL, (void*)&_sub2Fun, m_CamInfoindex);
}
*m_paraChange = true;
for (int i = 0; i < p_MyCamPara->m_DeFectParaStrArr.size(); i++)
{
DeFectPara* _DeFectPara = &p_MyCamPara->m_DeFectParaStrArr[i];
if (sliderParentName == _DeFectPara->defectName)
{
for (int j = 0; j < _DeFectPara->defectParaArrStr.size(); j++)
{
string sTmp = _DeFectPara->defectParaArrStr[j];
int pos1 = sTmp.find(",", 1);
string name = sTmp.substr(1, pos1 - 1);
int pos2 = sTmp.find(",", pos1 + 1);
string paraMax = sTmp.substr(pos1 + 1, pos2 - pos1 - 1);
if (name == paraName)
{
string paraStr = "'" + name + "," + paraMax + "," + valueC + "'";
_DeFectPara->defectParaArrStr[j] = paraStr;
break;
}
}
}
}
}