-
Notifications
You must be signed in to change notification settings - Fork 8
/
DlgPhase.cpp
398 lines (331 loc) · 9.33 KB
/
DlgPhase.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
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
// DlgPhase.cpp : 实现文件
//
#include "stdafx.h"
#include "FA2013.h"
#include "DlgPhase.h"
#include "afxdialogex.h"
#include <math.h>
#include "splab_vector.h"
// CDlgPhase 对话框
IMPLEMENT_DYNAMIC(CDlgPhase, CDialog)
CDlgPhase::CDlgPhase(CWnd* pParent /*=NULL*/)
: CDialog(CDlgPhase::IDD, pParent)
, Vps(1.0)
, Ips(1.0)
, m_Mode(0)
{
}
CDlgPhase::~CDlgPhase()
{
}
void CDlgPhase::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_WaitList, WaitList);
DDX_Control(pDX, IDC_CurList, CurList);
DDX_Control(pDX, IDC_Phasemode, ModeButton);
DDX_Control(pDX, IDC_DataList, PhaseList);
}
BEGIN_MESSAGE_MAP(CDlgPhase, CDialog)
ON_BN_CLICKED(IDC_INSERTTOLIST, &CDlgPhase::OnBnClickedInserttolist)
ON_BN_CLICKED(IDC_DELETEONE, &CDlgPhase::OnBnClickedDeleteone)
ON_BN_CLICKED(IDC_DELETEALL, &CDlgPhase::OnBnClickedDeleteall)
// ON_WM_MOUSEACTIVATE()
ON_BN_CLICKED(IDC_Vinc, &CDlgPhase::OnBnClickedVinc)
ON_BN_CLICKED(IDC_Iinc, &CDlgPhase::OnBnClickedIinc)
ON_BN_CLICKED(IDC_Vdec, &CDlgPhase::OnBnClickedVdec)
ON_BN_CLICKED(IDC_Idec, &CDlgPhase::OnBnClickedIdec)
ON_BN_CLICKED(IDC_Vini, &CDlgPhase::OnBnClickedVini)
ON_BN_CLICKED(IDC_Iini, &CDlgPhase::OnBnClickedIini)
ON_BN_CLICKED(IDC_Phasemode, &CDlgPhase::OnBnClickedPhasemode)
ON_WM_CLOSE()
END_MESSAGE_MAP()
// CDlgPhase 消息处理程序
void CDlgPhase::OnBnClickedInserttolist()
{
// TODO: 在此添加控件通知处理程序代码
int N = pDoc->pFile->m_ANumber;
int M = CurList.GetCount();
for(int i=0; i<N;i++)
{
CString tempCS;
tempCS.Format(_T("%d:"),i+1);
tempCS += pDoc->pFile->AVector[i]->name;
if ((0 != WaitList.GetSel(i))&&(0 > CurList.FindString(0,tempCS)))
CurList.InsertString(M++,tempCS);
}
UpdateData(TRUE);
m_pView->Invalidate();
}
BOOL CDlgPhase::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在此添加额外的初始化
for(int i=0; i<pDoc->pFile->m_ANumber;i++)
{
CString tempCS;
tempCS.Format(_T("%d:"),i+1);
tempCS += pDoc->pFile->AVector[i]->name;
WaitList.InsertString(i,tempCS);
}
PhaseList.SetExtendedStyle(LVS_EX_FLATSB
|LVS_EX_FULLROWSELECT
|LVS_EX_HEADERDRAGDROP
|LVS_EX_ONECLICKACTIVATE
|LVS_EX_GRIDLINES);
PhaseList.InsertColumn(0,_T("通道号"),2,70,0);
PhaseList.InsertColumn(1,_T("通道名称"),2,200,1);
PhaseList.InsertColumn(2,_T("幅值"),2,100,2);
PhaseList.InsertColumn(3,_T("相位"),2,100,3);
UpdateData(TRUE);
UINT TargetCtrlID = IDC_PhaseView;
CWnd *pWnd = this->GetDlgItem(TargetCtrlID);
CRect RectTargetCtrl;
pWnd->GetWindowRect(RectTargetCtrl);
this->ScreenToClient(RectTargetCtrl);
m_pView = (CPhaseView*)RUNTIME_CLASS(CPhaseView)->CreateObject();
(m_pView->pDoc)=pDoc;
//在目标位置动态创建视图
if (NULL==m_pView)
{
return FALSE;
}
m_pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, RectTargetCtrl, this, TargetCtrlID);
m_pView->m_pDlg = this;
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CDlgPhase::OnBnClickedDeleteone()
{
// TODO: 在此添加控件通知处理程序代码
int M = CurList.GetCount();
for(int i=M-1; i>=0;i--)
{
if (0 != CurList.GetSel(i))
CurList.DeleteString(i);
}
UpdateData(TRUE);
m_pView->Invalidate();
}
void CDlgPhase::OnBnClickedDeleteall()
{
// TODO: 在此添加控件通知处理程序代码
int M = CurList.GetCount();
for(int i=M-1; i>=0;i--)
CurList.DeleteString(i);
UpdateData(TRUE);
m_pView->Invalidate();
}
// C:\Users\炎侃\Desktop\FA2013F\FA2013\DlgPhase.cpp : 实现文件
//
#include "stdafx.h"
#include "FA2013.h"
#include "DlgPhase.h"
// CPhaseView
IMPLEMENT_DYNCREATE(CPhaseView, CView)
CPhaseView::CPhaseView()
: CursorNum1(0)
{
}
CPhaseView::~CPhaseView()
{
}
BEGIN_MESSAGE_MAP(CPhaseView, CView)
ON_WM_MOUSEACTIVATE()
END_MESSAGE_MAP()
// CPhaseView 绘图
void CPhaseView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: 在此添加绘制代码
DrawPhase(pDC);
}
// CPhaseView 诊断
#ifdef _DEBUG
void CPhaseView::AssertValid() const
{
CView::AssertValid();
}
#ifndef _WIN32_WCE
void CPhaseView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif
#endif //_DEBUG
// CPhaseView 消息处理程序
int CPhaseView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
//return CView::OnMouseActivate(pDesktopWnd, nHitTest, message);
return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
}
int CPhaseView::DrawPhase(CDC* pDC)
{
CRect rect;
using splab::PI;
extern CFA2013App theApp;
GetClientRect(&rect);
pDC->FillSolidRect(&rect,RGB(0,0,0));//背景
//pDC->SetBkColor(RGB(0,0,0));
CFont* def_font = pDC->SelectObject(&theApp.font);
pDC->SetTextColor(White);
pDC->SetBkMode(TRANSPARENT);
m_pDlg->PhaseList.DeleteAllItems();
//坐标线
int Vsp = (int)(rect.Height()*0.05);
int R = (int)(rect.Height()*0.45);
int Hsp = (int)(rect.Width()/2) - R;
CPoint center(rect.Width()/2,rect.Height()/2);
CPen* pOld = pDC->SelectObject(&theApp.PenGrid);
pDC->Arc(Hsp,Vsp,rect.Width()-Hsp,rect.Height()-Vsp,rect.Width()/2,Vsp,rect.Width()/2,Vsp);
pDC->Arc(Hsp+R/2,Vsp+R/2,rect.Width()-Hsp-R/2,rect.Height()-Vsp-R/2,rect.Width()/2,Vsp+R/2,rect.Width()/2,Vsp+R/2);
//pDC->Ellipse(Hsp,Vsp,rect.Width()-Hsp,rect.Height()-Vsp);
for(int i=0;i<12;i++)
{
pDC->MoveTo(center);
pDC->LineTo(center.x+(int)(R*cos(i*PI/6)),center.y-(int)(R*sin(i*PI/6)));
}
//计算
int M = m_pDlg->CurList.GetCount();
int ChanNum;
CursorNum1 =pDoc->CursorNum1;
double firsttheta = 0.0;
for (int i=0; i<M; i++)
{
CString tempCS;
int curPos=0;
m_pDlg->CurList.GetText(i,tempCS);
ChanNum= _wtoi((tempCS.Tokenize(_T(":"), curPos).GetBuffer()));
int Flag = pDoc->pFile->AVector[ChanNum-1]->GetCurrentPhasor(CursorNum1+1,pDoc->pFile->m_SampleRate);
if (Flag==1)
{
pDC->TextOutW(10,10,_T("·该区域无法计算,请将光标后移!"));
return 0;
}
CString ph = pDoc->pFile->AVector[ChanNum-1]->ph;
CString uu = pDoc->pFile->AVector[ChanNum-1]->uu;
double RChan;
double thetaChan;
double RChan0 = pDoc->pFile->AVector[ChanNum-1]->APhasor.Amplitude;
double thetaChan0 = pDoc->pFile->AVector[ChanNum-1]->APhasor.phase;
//表格部分
CString CSNo,CSName,CSRChan,CSthetaChan;
CSNo.Format(_T("%d"),ChanNum);
CSName =pDoc->pFile->AVector[ChanNum-1]->name;
CSRChan.Format(_T("%.3f"),RChan0);
CSRChan += uu;
CSthetaChan.Format(_T("%.3f°"),thetaChan0);
m_pDlg->PhaseList.InsertItem(i,CSNo);
m_pDlg->PhaseList.SetItemText(i,1,CSName);
m_pDlg->PhaseList.SetItemText(i,2,CSRChan);
m_pDlg->PhaseList.SetItemText(i,3,CSthetaChan);
//m_pDlg->UpdateData(true);
//画图部分
if (( uu == _T("V"))||(uu == _T("kV")))
RChan = RChan0 * m_pDlg->Vps;
else if ((uu == _T("A"))||( uu == _T("kA")))
RChan = RChan0 * m_pDlg->Ips;
if (m_pDlg->m_Mode==1)
{
if (i==0)
{
firsttheta = thetaChan0;
thetaChan = 0;
}
else thetaChan = thetaChan0 -firsttheta;
}
else
thetaChan = thetaChan0;
if (ph==_T("A")) {pOld = pDC->SelectObject(&theApp.PenA);pDC->SetTextColor(Yellow);}
else if (ph==_T("B")) {pOld = pDC->SelectObject(&theApp.PenB);pDC->SetTextColor(Green);}
else if (ph==_T("C")) {pOld = pDC->SelectObject(&theApp.PenC);pDC->SetTextColor(Red);}
else if (ph==_T("N")) {pOld = pDC->SelectObject(&theApp.PenN);pDC->SetTextColor(White);}
else if ((ph==_T(" "))||(ph==_T(""))) pOld = pDC->SelectObject(&theApp.PenF);
pDC->MoveTo(center);
pDC->LineTo(center.x+(int)(RChan*cos(thetaChan*PI/180.0)),center.y-(int)(RChan*sin(thetaChan*PI/180.0)));
pDC->LineTo(center.x+(int)(RChan*0.9*cos((thetaChan-3)*PI/180.0)),center.y-(int)(RChan*0.9*sin((thetaChan-3)*PI/180.0)));
pDC->MoveTo(center.x+(int)(RChan*cos(thetaChan*PI/180.0)),center.y-(int)(RChan*sin(thetaChan*PI/180.0)));
pDC->LineTo(center.x+(int)(RChan*0.9*cos((thetaChan+3)*PI/180.0)),center.y-(int)(RChan*0.9*sin((thetaChan+3)*PI/180.0)));
CString OutText;
OutText.Format(_T(" [%d]"),ChanNum);
pDC->TextOutW(center.x+(int)((RChan+15)*cos(thetaChan*PI/180.0)),center.y-(int)((RChan+15)*sin(thetaChan*PI/180.0)),OutText);
pDC->SelectObject(pOld);
}
return 0;
}
void CDlgPhase::OnBnClickedVinc()
{
// TODO: 在此添加控件通知处理程序代码
if (Vps<10)
Vps =Vps *1.2;
m_pView->Invalidate();
}
void CDlgPhase::OnBnClickedIinc()
{
// TODO: 在此添加控件通知处理程序代码
if (Ips<50)
Ips =Ips *2;
m_pView->Invalidate();
}
void CDlgPhase::OnBnClickedVdec()
{
// TODO: 在此添加控件通知处理程序代码
if (Vps>0.2)
Vps =Vps /1.2;
m_pView->Invalidate();
}
void CDlgPhase::OnBnClickedIdec()
{
// TODO: 在此添加控件通知处理程序代码
if (Ips>0.2)
Ips =Ips /1.2;
m_pView->Invalidate();
}
void CDlgPhase::OnBnClickedVini()
{
// TODO: 在此添加控件通知处理程序代码
Vps =1.0;
m_pView->Invalidate();
}
void CDlgPhase::OnBnClickedIini()
{
// TODO: 在此添加控件通知处理程序代码
Ips =1.0;
m_pView->Invalidate();
}
void CDlgPhase::OnBnClickedPhasemode()
{
// TODO: 在此添加控件通知处理程序代码
CWnd* pWnd = GetDlgItem(IDC_Phasemode);
if (m_Mode ==0)
{
m_Mode =1;
pWnd->SetWindowTextW(_T("转变为旋转相量"));
}
else
{
m_Mode =0;
pWnd->SetWindowTextW(_T("转变为相对相量"));
}
m_pView->Invalidate();
}
void CDlgPhase::OnCancel()
{
// TODO: 在此添加专用代码和/或调用基类
DestroyWindow();
//CDialog::OnCancel();
}
void CDlgPhase::PostNcDestroy()
{
// TODO: 在此添加专用代码和/或调用基类
this->pDoc->pDlgPhase = NULL;
delete this;
CDialog::PostNcDestroy();
}
void CDlgPhase::OnClose()
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
DestroyWindow();
//CDialog::OnClose();
}