-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPlotOrderDlg.cpp
More file actions
239 lines (199 loc) · 5.8 KB
/
PlotOrderDlg.cpp
File metadata and controls
239 lines (199 loc) · 5.8 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
/* Aerofoil
Aerofoil plotting and CNC cutter driver
Copyright(C) 1995-2019 R Bruce Porteous
This program 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.
This program 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 this program.If not, see <http://www.gnu.org/licenses/>.
*/
// PlotOrderDlg.cpp : implementation file
//
#include "stdafx.h"
#include <assert.h>
#include "aerofoil.h"
#include "PlotOrderDlg.h"
#include "AerofoilDoc.h"
#include "kernel/Plot.h"
#include "kernel/PlotStructure.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
using namespace std;
/////////////////////////////////////////////////////////////////////////////
// CPlotOrderDlg dialog
CPlotOrderDlg::CPlotOrderDlg(CAerofoilDoc* pd, CWnd* pParent /*=NULL*/)
: CDialog(CPlotOrderDlg::IDD, pParent)
, pDoc(pd)
{
Create(CPlotOrderDlg::IDD, pParent);
//{{AFX_DATA_INIT(CPlotOrderDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CPlotOrderDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPlotOrderDlg)
DDX_Control(pDX, IDC_LST_STRUCTURES, m_lstPlots);
DDX_Control(pDX, IDC_CMD_UP, m_cmdUp);
DDX_Control(pDX, IDC_CMD_TOP, m_cmdTop);
DDX_Control(pDX, IDC_CMD_DOWN, m_cmdDown);
DDX_Control(pDX, IDC_CMD_BOTTOM, m_cmdBottom);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPlotOrderDlg, CDialog)
//{{AFX_MSG_MAP(CPlotOrderDlg)
ON_LBN_SELCHANGE(IDC_LST_STRUCTURES, OnSelchangeLstStructures)
ON_BN_CLICKED(IDC_CMD_BOTTOM, OnCmdBottom)
ON_BN_CLICKED(IDC_CMD_DOWN, OnCmdDown)
ON_BN_CLICKED(IDC_CMD_TOP, OnCmdTop)
ON_BN_CLICKED(IDC_CMD_UP, OnCmdUp)
ON_LBN_SELCANCEL(IDC_LST_STRUCTURES, OnSelcancelLstStructures)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CPlotOrderDlg::setSelection(CPlotStructure* ps)
{
int nItems = m_lstPlots.GetCount();
for(int i=0; i<nItems; ++i)
{
if(m_lstPlots.GetItemDataPtr(i) == ps)
{
m_lstPlots.SetCurSel(i);
OnSelchangeLstStructures();
break;
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CPlotOrderDlg message handlers
BOOL CPlotOrderDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CPlot& plot = pDoc->getPlot();
for( CPlot::PlotStructureIterator iter = plot.getPlotStructures();
iter != plot.endPlotStructures();
++iter)
{
CPlotStructure* pps = *iter;
string text = pps->getDescriptiveText();
int idx = m_lstPlots.AddString(text.c_str());
if(idx != LB_ERR)
m_lstPlots.SetItemDataPtr(idx,pps);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPlotOrderDlg::PostNcDestroy()
{
delete this;
}
void CPlotOrderDlg::OnCancel()
{
pDoc->closePlotOrderDialog();
}
void CPlotOrderDlg::OnOK()
{
CPlot& plot = pDoc->getPlot();
int nItems = m_lstPlots.GetCount();
for(int i=0; i<nItems; ++i)
{
CPlotStructure* ps = static_cast<CPlotStructure*>(m_lstPlots.GetItemDataPtr(i));
plot.moveToEnd(ps);
}
pDoc->closePlotOrderDialog();
}
void CPlotOrderDlg::OnSelchangeLstStructures()
{
int idx = m_lstPlots.GetCurSel();
if(idx != LB_ERR)
{
CPlotStructure* selected = static_cast<CPlotStructure*>(m_lstPlots.GetItemDataPtr(idx));
int maxIdx = m_lstPlots.GetCount()-1;
m_cmdTop.EnableWindow( idx != 0);
m_cmdUp.EnableWindow( idx != 0);
m_cmdDown.EnableWindow( idx != maxIdx);
m_cmdBottom.EnableWindow(idx != maxIdx);
pDoc->setSelection(selected);
}
}
void CPlotOrderDlg::OnCmdBottom()
{
int idx = m_lstPlots.GetCurSel();
if(idx != LB_ERR)
{
CPlotStructure* selected = static_cast<CPlotStructure*>(m_lstPlots.GetItemDataPtr(idx));
m_lstPlots.DeleteString(idx);
string text = selected->getDescriptiveText();
int idx = m_lstPlots.AddString(text.c_str());
if(idx != LB_ERR)
{
m_lstPlots.SetItemDataPtr(idx,selected);
m_lstPlots.SetCurSel(idx);
}
}
}
void CPlotOrderDlg::OnCmdDown()
{
int idx = m_lstPlots.GetCurSel();
assert(idx != m_lstPlots.GetCount()-1);
if((idx != LB_ERR) && (idx != m_lstPlots.GetCount()-1))
{
CPlotStructure* selected = static_cast<CPlotStructure*>(m_lstPlots.GetItemDataPtr(idx));
m_lstPlots.DeleteString(idx);
string text = selected->getDescriptiveText();
int ip = m_lstPlots.InsertString(idx+1,text.c_str());
if(ip != LB_ERR)
{
m_lstPlots.SetItemDataPtr(idx+1,selected);
m_lstPlots.SetCurSel(idx+1);
}
}
}
void CPlotOrderDlg::OnCmdTop()
{
int idx = m_lstPlots.GetCurSel();
if(idx != LB_ERR)
{
CPlotStructure* selected = static_cast<CPlotStructure*>(m_lstPlots.GetItemDataPtr(idx));
m_lstPlots.DeleteString(idx);
string text = selected->getDescriptiveText();
int idx = m_lstPlots.InsertString(0,text.c_str());
if(idx != LB_ERR)
{
m_lstPlots.SetItemDataPtr(0,selected);
m_lstPlots.SetCurSel(0);
}
}
}
void CPlotOrderDlg::OnCmdUp()
{
int idx = m_lstPlots.GetCurSel();
assert(idx != 0);
if((idx != LB_ERR) && (idx != 0))
{
CPlotStructure* selected = static_cast<CPlotStructure*>(m_lstPlots.GetItemDataPtr(idx));
m_lstPlots.DeleteString(idx);
string text = selected->getDescriptiveText();
int ip = m_lstPlots.InsertString(idx-1,text.c_str());
if(ip != LB_ERR)
{
m_lstPlots.SetItemDataPtr(idx-1,selected);
m_lstPlots.SetCurSel(idx-1);
}
}
}
void CPlotOrderDlg::OnSelcancelLstStructures()
{
m_cmdTop.EnableWindow(FALSE);
m_cmdUp.EnableWindow(FALSE);
m_cmdDown.EnableWindow(FALSE);
m_cmdBottom.EnableWindow(FALSE);
}