forked from paulhoad/gp2trackeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfo.cpp
More file actions
executable file
·405 lines (323 loc) · 11.4 KB
/
Copy pathInfo.cpp
File metadata and controls
executable file
·405 lines (323 loc) · 11.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
403
404
405
// Info.cpp : implementation file
//
#include "stdafx.h"
#include "TrackEditor.h"
#include "Info.h"
#include "TrackEditorDoc.h"
#include "TrackSection.h"
#include "GPTrack.h"
#include "CCLineSection.h"
#include "ImportDataElement.h"
//#include "CLineEditor.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInfo
IMPLEMENT_DYNCREATE(CInfo, CMyTableView)
CInfo::CInfo() { cclinedlg = new CCLineEditor(this); }
CInfo::~CInfo()
{
if (cclinedlg != NULL) delete cclinedlg;
CTrackEditorDoc* pDoc = (CTrackEditorDoc*)GetDocument();
if (pDoc) {
pDoc->ccTable = NULL;
}
}
BEGIN_MESSAGE_MAP(CInfo, CMyTableView)
//{{AFX_MSG_MAP(CInfo)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_SETFOCUS()
ON_WM_LBUTTONUP()
ON_COMMAND(ID_EXPORT_TABLE, OnExportTable)
ON_WM_CREATE()
ON_COMMAND(ID_IMPORT_TABLE, OnImportTable)
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInfo drawing
void CInfo::OnInitialUpdate()
{}
void CInfo::UpdateInfo(BOOL update)
{
CTrackEditorDoc* pDoc = (CTrackEditorDoc*)GetDocument();
pDoc->ccTable = this;
GPTrack* mytrack = pDoc->getTrack();
if (mytrack != NULL) {
if (!update) {
int colidx = 0;
EmptyTable();
addColumn("Index", 50, colidx++);
addColumn("Cmd", 50, colidx++);
addColumn("Length", 50, colidx++);
addColumn("Radius", 50, colidx++);
addColumn("Sign/Scale ?", 50, colidx++);
addColumn("Tight/Wider Offset", 50, colidx++);
addColumn("Angle", 50, colidx++);
addColumn("Arc", 50, colidx++);
addColumn("Arc (Rad)", 50, colidx++);
addColumn("0x70 (only) Sign/Scale for 0x70", 50, colidx++);
addColumn("0x70 (only) Radius for 0x70", 50, colidx++);
addColumn("StAng ", 50, colidx++);
addColumn("StEnd ", 50, colidx++);
}
if (mytrack->TrackSections) {
TrackSection* t1 = (TrackSection*)mytrack->TrackSections->elementAt(0);
double xpos = t1->getStartX();
double ypos = t1->getStartY();
double currentangle =
((360 * mytrack->TrackStartAngle.GetValue()) / 65535);
double currrad = 0.0;
xpos += mytrack->CCLineStartX.GetValue();
ypos += WIDTH_TO_CCWIDTH(mytrack->CCLineStartY.GetValue());
for (int i = 0; i < mytrack->CCLineSections->size(); i++) {
CCLineSection* t =
(CCLineSection*)mytrack->CCLineSections->elementAt(i);
double nextxpos, nextypos;
double direction = (double)t->getArg2();
double ndirection = (double)t->getArg3();
if (direction > 0x8000) direction = -(0x10000 - direction);
if (ndirection > 0x8000) ndirection = -(0x10000 - ndirection);
double rad = t->getRadius();
double length = t->getLength();
double sectorStartAngle = currrad;
double sectorEndAngle = currrad;
double anglelen;
double rad2 = 0;
rad = RadiusTo(mytrack, rad, direction, (double)t->getArg1(), t->getCmd(), t->getArg3(), t->getArg4(), rad2);
if (rad != 0) {
double anglerad = (length / rad);
anglelen = RadToDeg(anglerad);
double sectorRadius = 0;
double inrad = anglerad / 2.0;
double len = 2.0 * (rad * sin(inrad));
nextypos = len * sin((currrad + inrad));
nextxpos = len * cos((currrad + inrad));
sectorEndAngle = currrad + inrad;
currrad += anglerad;
} else {
nextypos = length * sin(currrad);
nextxpos = length * cos(currrad);
anglelen = 0;
}
// t->setStartX(xpos);
// t->setStartY(ypos);
// t->setEndX(nextxpos);
// t->setEndY(nextypos);
// t->setStartAngle(sectorStartAngle);
// t->setEndAngle(sectorEndAngle);
xpos = (xpos + nextxpos);
ypos = (ypos + nextypos);
int tidx = 0;
UpdateTableStringPtr(update, i, tidx++, toString(i), TO_ID(t->getIcon()));
UpdateTableStringPtr(update, i, tidx++, toString(t->getCmd()));
UpdateTableStringPtr(update, i, tidx++, toString((int)length));
UpdateTableStringPtr(update, i, tidx++, toString((int)t->getRadius()));
UpdateTableStringPtr(update, i, tidx++, toString((int)direction));
UpdateTableStringPtr(update, i, tidx++, toString(t->getArg1()));
UpdateTableStringPtr(update, i, tidx++, toString(anglelen));
UpdateTableStringPtr(update, i, tidx++, toString(RadToDeg(currrad)));
UpdateTableStringPtr(update, i, tidx++, toString(currrad));
if (t->getCmd() != 0x50) {
UpdateTableStringPtr(update, i, tidx++, toString((int)ndirection));
UpdateTableStringPtr(update, i, tidx++, toString(t->getArg4()));
} else {
UpdateTableStringPtr(update, i, tidx++, CString("-"));
UpdateTableStringPtr(update, i, tidx++, CString("-"));
}
UpdateTableStringPtr(update, i, tidx++, toString(RadToDeg(sectorStartAngle)));
UpdateTableStringPtr(update, i, tidx++, toString(RadToDeg(sectorEndAngle)));
}
}
}
}
void CInfo::OnDraw(CDC* pDC)
{}
CString
CInfo::toString(int data)
{
static char mess[256];
wsprintf(mess, "%d", data);
return CString(mess);
}
CString
CInfo::toString(double data)
{
static char mess[256];
sprintf(mess, "%2.2f", (float)data);
return CString(mess);
}
/////////////////////////////////////////////////////////////////////////////
// CInfo diagnostics
#ifdef _DEBUG
void CInfo::AssertValid() const
{
CMyTableView::AssertValid();
}
void CInfo::Dump(CDumpContext& dc) const
{
CMyTableView::Dump(dc);
}
#endif//_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CInfo message handlers
BOOL CInfo::OnScrollBy(CSize sizeScroll, BOOL bDoScroll)
{
// TODO: Add your specialized code here and/or call the base class
return CMyTableView::OnScrollBy(sizeScroll, bDoScroll);
}
BOOL CInfo::OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll)
{
// TODO: Add your specialized code here and/or call the base class
return CMyTableView::OnScroll(nScrollCode, nPos, bDoScroll);
}
void CInfo::OnLButtonDown(UINT nFlags, CPoint point)
{
// CPoint offset = GetDeviceScrollPosition();
// TODO: Add your message handler code here and/or call default
CTrackEditorDoc* pDoc = (CTrackEditorDoc*)GetDocument();
GPTrack* mytrack = pDoc->getTrack();
int idx = getTableSectionIndex();
for (int i = 0; i < mytrack->CCLineSections->size(); i++) {
CCLineSection* t = (CCLineSection*)mytrack->CCLineSections->elementAt(i);
t->setSelected(FALSE);
}
if (idx >= 0 && idx < mytrack->CCLineSections->size()) {
CCLineSection* t = (CCLineSection*)mytrack->CCLineSections->elementAt(idx);
t->setSelected(TRUE);
if (t) {
pDoc->getTree()->Expand(pDoc->getTree()->GetParentItem(t->getTreeNode()),
TVE_EXPAND);
pDoc->getTree()->SelectItem(t->getTreeNode());
}
}
CMyTableView::OnLButtonDown(nFlags, point);
}
void CInfo::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int idx = getTableSectionIndex();
CTrackEditorDoc* pDoc = (CTrackEditorDoc*)GetDocument();
GPTrack* mytrack = pDoc->getTrack();
if (idx >= 0) {
CCLineSection* t = (CCLineSection*)mytrack->CCLineSections->elementAt(idx);
int result = cclinedlg->EditCCSections(t);
mytrack->createTrack(pDoc);
UpdateInfo(TRUE);
/*
if (cclinedlg && t)
cclinedlg->setSection(t,idx);
int res = cclinedlg->DoModal();
if (cclinedlg && t && res!=IDCANCEL)
{
cclinedlg->getSection(t);
//mytrack->PutCCSection(t);
mytrack->regenerate=TRUE;
mytrack->createCC();
UpdateInfo(TRUE);
}
*/
}
CMyTableView::OnLButtonDblClk(nFlags, point);
}
void CInfo::OnSetFocus(CWnd* pOldWnd)
{
CMyTableView::OnSetFocus(pOldWnd);
CTrackEditorDoc* pDoc = (CTrackEditorDoc*)GetDocument();
GPTrack* mytrack = pDoc->getTrack();
if (mytrack && mytrack->isValid()) {
// UpdateInfo();
}
}
void CInfo::OnLButtonUp(UINT nFlags, CPoint point)
{
CMyTableView::OnLButtonUp(nFlags, point);
}
void CInfo::OnExportTable()
{
// TODO: Add your command handler code here
ExportTableData();
}
BOOL CInfo::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
BOOL res = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
// SetImageList((((CTrackEditorApp*)AfxGetApp())->getSharedImageList()),LVSIL_SMALL);
return res;
}
int CInfo::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMyTableView::OnCreate(lpCreateStruct) == -1) return -1;
CImageList* pImages = (((CTrackEditorApp*)AfxGetApp())->getSharedImageList());
if (pImages != NULL) {
SetImageList(pImages, LVSIL_SMALL);
useImages = TRUE;
} else {
useImages = FALSE;
AfxMessageBox("Failed to open Images");
}
// TODO: Add your specialized creation code here
UpdateInfo(FALSE);
return 0;
}
void CInfo::OnImportTable()
{
// TODO: Add your command handler code here
Vector* tabledata = ImportTableData();
CTrackEditorDoc* pDoc = (CTrackEditorDoc*)GetDocument();
GPTrack* mytrack = pDoc->getTrack();
BOOL ignoreExtra = 0;
BOOL removeExtra = 0;
if (tabledata != NULL) {
int result = AfxMessageBox(
"About to Import CC Table Data!, are you sure you want to do this",
MB_YESNO);
if (result == IDYES) {
if (tabledata->size() > mytrack->CCLineSections->size()) {
// ignoreExtra = AfxMessageBox("More Table Data Than Track (Ignore Extra
// Table Data)?",MB_YESNO);
AfxMessageBox(
"More Table Data Than CC Data (Ignoring Extra Table Data)?");
ignoreExtra = TRUE;
} else if (tabledata->size() < mytrack->CCLineSections->size()) {
// removeExtra = AfxMessageBox("More Track Data Than Table (Remove Extra
// Track Data)?",MB_YESNO);
AfxMessageBox(
"More CC Data Than Table (leaving end of ccline unaltered!)");
}
int importSize = tabledata->size();
if (ignoreExtra == TRUE) {
importSize = mytrack->CCLineSections->size();
}
for (int i = 0; i < importSize; i++) {
Vector* row = (Vector*)tabledata->elementAt(i);
CCLineSection* t =
(CCLineSection*)mytrack->CCLineSections->elementAt(i);
if (t != NULL) {
ImportDataElement* elm = (ImportDataElement*)row->elementAt(2);
t->setLength(elm->toDouble());
elm = (ImportDataElement*)row->elementAt(3);
t->setRadius(elm->toInt());
elm = (ImportDataElement*)row->elementAt(4);
t->setArg2(elm->toInt());
}
}
}
}
mytrack->createTrack(pDoc);
mytrack->createCC();
UpdateInfo(TRUE);
}
void CInfo::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CPoint pt;
pt.x = 0;
pt.y = 0;
if (nChar == 13) {
OnLButtonDblClk(0, pt);
}
CMyTableView::OnKeyDown(nChar, nRepCnt, nFlags);
}