-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCKPKineticsPg1.cpp
2546 lines (2196 loc) · 66.1 KB
/
CKPKineticsPg1.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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// CKPKineticsPg1.cpp : implementation file
//
// $Id$
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "CKPKineticsPg1.h"
#include "Util.h"
#include "DelayUpdate.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CCKPKineticsPg1, baseCKPKineticsPg1)
IMPLEMENT_DYNCREATE(CCKPKineticsPg2, baseCKPKineticsPg2)
/////////////////////////////////////////////////////////////////////////////
// CCKPKineticsPg1 property page
CCKPKineticsPg1::CCKPKineticsPg1() : baseCKPKineticsPg1(CCKPKineticsPg1::IDD)
, m_gltDoc(&m_egNames, &m_clRates, &m_tcNames, 1), m_nextMapInt(1)
{
m_bIgnoreCheckChange = FALSE;
//{{AFX_DATA_INIT(CCKPKineticsPg1)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CCKPKineticsPg1::~CCKPKineticsPg1()
{
}
void CCKPKineticsPg1::DoDataExchange(CDataExchange* pDX)
{
baseCKPKineticsPg1::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCKPKineticsPg1)
DDX_Control(pDX, IDC_CL_RATES, m_clRates);
DDX_Control(pDX, IDC_TC_NAMES, m_tcNames);
DDX_Control(pDX, IDC_MSHFG_NAMES, m_egNames);
DDX_Control(pDX, IDC_MSHFG_GENERAL, m_egGeneral);
DDX_Control(pDX, IDC_MSHFG_FORMULA, m_egFormula);
DDX_Control(pDX, IDC_MSHFG_USER, m_egUser);
//}}AFX_DATA_MAP
DDX_CompList(pDX);
}
void CCKPKineticsPg1::DDX_CompList(CDataExchange *pDX)
{
// validate state
ASSERT_VALID(this);
if (m_bFirstSetActive)
{
// Init grid controls
InitGrids();
// Init rate checklist
CUtil::InsertRates(&m_clRates, GetDatabase());
}
// avoid flashing grid
CDelayUpdate update1(this, IDC_MSHFG_GENERAL);
CDelayUpdate update2(this, IDC_MSHFG_USER);
CDelayUpdate update3(this, IDC_MSHFG_FORMULA);
if (pDX->m_bSaveAndValidate)
{
// check if this tab has a CKineticComp associated with it
int nTab = m_tcNames.GetCurSel();
if (nTab == -1)
{
// no CKineticComps defined
ASSERT(m_tcNames.GetItemCount() == 0);
// remove any current CKineticComps
m_listComps.clear();
}
else
{
// CKineticComps have been defined
ASSERT(m_tcNames.GetItemCount() != 0);
TCITEM tcItem;
TCHAR buffer[121];
tcItem.pszText = buffer;
tcItem.cchTextMax = 120;
tcItem.mask = TCIF_PARAM | TCIF_TEXT;
VERIFY(m_tcNames.GetItem(nTab, &tcItem));
if (!tcItem.lParam)
{
// this is a new tab with no associated CKineticComp
tcItem.lParam = m_nextMapInt++;
m_tcNames.SetItem(nTab, &tcItem);
ASSERT(m_mapComps.find(tcItem.lParam) == m_mapComps.end());
}
CKineticComp kineticCompNew;
// Rate name
// m_strRateName already validated by OnEndCellEdit
kineticCompNew.m_strRateName = tcItem.pszText;
//
// General parameters
//
// Initial moles (m0)
DDX_GridText(pDX, IDC_MSHFG_GENERAL, 0, 1, kineticCompNew.m_dM0);
// Moles (m)
DDX_GridText(pDX, IDC_MSHFG_GENERAL, 1, 1, kineticCompNew.m_dM);
// Tolerance (tol)
DDX_GridText(pDX, IDC_MSHFG_GENERAL, 2, 1, kineticCompNew.m_dTol);
//
// User parameters
//
// Parm(1..N)
CString strUserVal;
double dUserVal;
for (long nRow = 0; nRow < m_egUser.GetRows(); ++nRow)
{
DDX_GridText(pDX, IDC_MSHFG_USER, nRow, 1, strUserVal);
if (strUserVal.IsEmpty()) continue;
DDX_GridText(pDX, IDC_MSHFG_USER, nRow, 1, dUserVal);
kineticCompNew.m_listDParams.push_back(dUserVal);
}
//
// Formula
//
// Formula or phase name
CNameCoef nameCoef;
for (long nRow = 1; nRow < m_egFormula.GetRows(); ++nRow)
{
DDX_GridText(pDX, IDC_MSHFG_FORMULA, nRow, 1, strUserVal);
if (strUserVal.IsEmpty()) continue;
nameCoef.m_strName = strUserVal;
DDX_GridText(pDX, IDC_MSHFG_FORMULA, nRow, 2, strUserVal);
if (strUserVal.IsEmpty())
{
nameCoef.m_dCoef = 1.0;
}
else
{
DDX_GridText(pDX, IDC_MSHFG_FORMULA, nRow, 2, nameCoef.m_dCoef);
}
kineticCompNew.m_listNameCoef.push_back(nameCoef);
}
// update map
m_mapComps[tcItem.lParam] = kineticCompNew;
// copy CKineticComps in map to list in tab order
//TCITEM tcItem;
tcItem.mask = TCIF_PARAM | TCIF_TEXT;
m_listComps.clear();
for (int i = 0; i < m_tcNames.GetItemCount(); ++i)
{
m_tcNames.GetItem(i, &tcItem);
CKineticComp kineticComp = m_mapComps[tcItem.lParam];
if (tcItem.lParam == 0)
{
ASSERT(kineticComp.m_strRateName.IsEmpty());
ASSERT(tcItem.pszText != NULL);
kineticComp.m_strRateName = tcItem.pszText;
}
else
{
ASSERT(!kineticComp.m_strRateName.IsEmpty());
}
// add CNameCoef if this rate name is a phase
if (kineticComp.m_listNameCoef.size() == 0)
{
CDBPhase phase;
phase.m_strName = kineticComp.m_strRateName;
std::set<CDBPhase>::const_iterator phaseIter = GetDatabase().m_phaseSet.find(phase);
if (phaseIter != GetDatabase().m_phaseSet.end())
{
CNameCoef nameCoef;
nameCoef.m_strName = phaseIter->m_strFormula;
nameCoef.m_dCoef = 1.0;
kineticComp.m_listNameCoef.push_back(nameCoef);
}
}
m_listComps.push_back(kineticComp);
#ifdef _DEBUG
afxDump << "Item " << i << "\n";
afxDump << "\tName = " << kineticComp.m_strRateName << "\n";
afxDump << "\tInitial moles (m0) = " << kineticComp.m_dM0 << "\n";
afxDump << "\tMoles (m) = " << kineticComp.m_dM << "\n";
afxDump << "\tTolerance (tol) = " << kineticComp.m_dTol << "\n";
afxDump << "\tPARM\n";
std::list<double>::const_iterator iterDouble = kineticComp.m_listDParams.begin();
for (; iterDouble != kineticComp.m_listDParams.end(); ++iterDouble)
{
afxDump << "\t\t" << *iterDouble << "\n";
}
afxDump << "\tFormula\n";
std::list<CNameCoef>::const_iterator iterNameCoef = kineticComp.m_listNameCoef.begin();
for (; iterNameCoef != kineticComp.m_listNameCoef.end(); ++iterNameCoef)
{
afxDump << "\t\t" << (*iterNameCoef).m_strName << ", " << (*iterNameCoef).m_dCoef << "\n";
}
#endif
}
}
}
else
{
if (m_bFirstSetActive)
{
std::list<CKineticComp>::iterator compIter = m_listComps.begin();
TCITEM tcItem;
tcItem.mask = TCIF_PARAM;
for (; compIter != m_listComps.end(); ++compIter)
{
CGridListItem glItem = m_gltDoc.AddItem(compIter->m_strRateName);
tcItem.lParam = m_nextMapInt++;
m_tcNames.SetItem(glItem.m_nTab, &tcItem);
m_mapComps[tcItem.lParam] = (*compIter);
}
if (m_listComps.size() == 0)
{
DisplayTab(-1);
}
else
{
DisplayTab(0);
}
}
}
// validate state
ASSERT_VALID(this);
}
BEGIN_MESSAGE_MAP(CCKPKineticsPg1, baseCKPKineticsPg1)
//{{AFX_MSG_MAP(CCKPKineticsPg1)
ON_NOTIFY(TCN_SELCHANGE, IDC_TC_NAMES, OnSelchangeTcNames)
ON_NOTIFY(TCN_SELCHANGING, IDC_TC_NAMES, OnSelchangingTcNames)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_CL_RATES, OnItemchangedClRates)
ON_NOTIFY(NM_SETFOCUS, IDC_CL_RATES, OnSetfocusClRates)
ON_WM_HELPINFO()
//}}AFX_MSG_MAP
// ON_WM_CONTEXTMENU()
// custom edit grid notifications
ON_MESSAGE(EGN_BEGINCELLEDIT, OnBeginCellEdit)
ON_MESSAGE(EGN_ENDCELLEDIT, OnEndCellEdit)
ON_MESSAGE(EGN_SETFOCUS, OnSetfocusGrid)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCKPKineticsPg2 property page
CCKPKineticsPg2::CCKPKineticsPg2() : baseCKPKineticsPg2(CCKPKineticsPg2::IDD)
{
//{{AFX_DATA_INIT(CCKPKineticsPg2)
//}}AFX_DATA_INIT
m_nLinearSteps = 1;
m_nAmountType = TYPE_LINEAR;
m_dLinearAmt = 1.0;
}
CCKPKineticsPg2::~CCKPKineticsPg2()
{
}
void CCKPKineticsPg2::DoDataExchange(CDataExchange* pDX)
{
baseCKPKineticsPg2::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCKPKineticsPg2)
DDX_Control(pDX, IDC_SPIN_STEPS, m_spinSteps);
DDX_Control(pDX, IDC_E_STEPS, m_eSteps);
DDX_Control(pDX, IDC_E_TOTAL_TIME, m_eTotalTime);
DDX_Control(pDX, IDC_MSHFG_LIST, m_ctrlStepEditGrid);
//}}AFX_DATA_MAP
DDX_Steps(pDX, IDC_MSHFG_LIST);
}
BEGIN_MESSAGE_MAP(CCKPKineticsPg2, baseCKPKineticsPg2)
//{{AFX_MSG_MAP(CCKPKineticsPg2)
ON_BN_CLICKED(IDC_RADIO_LINEAR, OnRadioLinear)
ON_BN_CLICKED(IDC_RADIO_LIST, OnRadioList)
ON_EN_SETFOCUS(IDC_E_TOTAL_TIME, OnSetfocusETotalTime)
ON_EN_SETFOCUS(IDC_E_STEPS, OnSetfocusESteps)
ON_CBN_SETFOCUS(IDC_CB_RK, OnSetfocusCbRk)
ON_EN_SETFOCUS(IDC_E_STEP_DIVIDE, OnSetfocusEStepDivide)
ON_WM_HELPINFO()
//}}AFX_MSG_MAP
// custom radio button set focus notifications
ON_BN_SETFOCUS(IDC_RADIO_LINEAR, OnSetfocusRadioLinear)
ON_BN_SETFOCUS(IDC_RADIO_LIST, OnSetfocusRadioList)
// custom edit grid notifications
ON_MESSAGE(EGN_BEGINCELLEDIT, OnBeginCellEdit)
ON_MESSAGE(EGN_ENDCELLEDIT, OnEndCellEdit)
ON_MESSAGE(EGN_SETFOCUS, OnSetfocusGrid)
END_MESSAGE_MAP()
BOOL CCKPKineticsPg1::OnInitDialog()
{
baseCKPKineticsPg1::OnInitDialog();
// Set Layout
CreateRoot(VERTICAL, 5, 6)
<< (pane(HORIZONTAL, ABSOLUTE_VERT)
<< item(IDC_MSHFG_NUM_DESC, ABSOLUTE_VERT)
)
<< (pane(HORIZONTAL, ABSOLUTE_VERT)
<< item(IDC_S_DEF_RATES, ABSOLUTE_VERT)
)
<< (pane(HORIZONTAL, GREEDY)
<< item(IDC_CL_RATES, GREEDY) // RELATIVE_VERT, 0, 33)
<< item(IDC_MSHFG_NAMES, ABSOLUTE_HORZ)
)
<< (paneTab(&m_tcNames, VERTICAL, GREEDY, nDefaultBorder, 4, 15)
<< (pane(HORIZONTAL, GREEDY)
<< (pane(HORIZONTAL, GREEDY)
<< (pane(VERTICAL, GREEDY)
<< item(IDC_S_GENERAL, ABSOLUTE_VERT | ALIGN_BOTTOM)
<< item(IDC_MSHFG_GENERAL, NORESIZE)
<< item(IDC_S_USER, ABSOLUTE_VERT | ALIGN_BOTTOM)
<< item(IDC_MSHFG_USER, GREEDY)
)
)
<< (pane(HORIZONTAL, GREEDY)
<< (pane(VERTICAL, GREEDY)
<< item(IDC_S_FORMULA, ABSOLUTE_VERT | ALIGN_BOTTOM)
<< item(IDC_MSHFG_FORMULA, GREEDY) // RELATIVE_VERT, 0, 67)
)
)
)
)
<< (paneCtrl(IDC_S_DESC_INPUT, HORIZONTAL, GREEDY, nDefaultBorder, 10, 10)
<< item(IDC_E_DESC_INPUT, ABSOLUTE_VERT)
)
;
UpdateLayout();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCKPKineticsPg1::OnContextMenu(CWnd* pWnd, CPoint point)
{
//{{
ASSERT(FALSE); // message map commented out
//}}
// Add your message handler code here
if (pWnd == &m_egFormula)
{
CMenu menu;
VERIFY(menu.LoadMenu(IDR_POPUP_RICH_IN));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup);
if (pPopup)
{
if (point.x == -1 && point.y == -1)
{
// keystroke invocation
point.x = point.y = 0;
ClientToScreen(&point);
}
// Note: All commands except copy are grayed by default
// disable copy item if there's no selection
// COMMENT: {7/26/2000 3:28:57 PM} if (GetCurSel() == LB_ERR)
// COMMENT: {7/26/2000 3:28:57 PM} {
// COMMENT: {7/26/2000 3:28:57 PM} pPopup->EnableMenuItem((UINT)ID_COPY, MF_BYCOMMAND | MF_GRAYED);
// COMMENT: {7/26/2000 3:28:57 PM} }
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
//{{COPY TO CLIPBOARD
if (::OpenClipboard(m_egFormula.m_hWnd))
{
// Retrieve string from ListBox
CString strText = m_egFormula.GetClip();
// Allocate global memory
HGLOBAL hglbCopy = ::GlobalAlloc(GMEM_DDESHARE, (strText.GetLength() + 1) * sizeof(TCHAR));
if (hglbCopy)
{
// Lock it and get a pointer to it
LPTSTR lptstrCopy = (LPTSTR)::GlobalLock(hglbCopy);
if (lptstrCopy)
{
// Empty existing clipboard contents
VERIFY(::EmptyClipboard());
// Copy string into memory
VERIFY(::lstrcpy(lptstrCopy, (LPCTSTR)strText));
// Unlock memory
VERIFY(::GlobalUnlock(hglbCopy));
// Send memory to clipboard
#ifdef UNICODE
VERIFY(::SetClipboardData(CF_UNICODETEXT, hglbCopy));
#else
VERIFY(::SetClipboardData(CF_TEXT, hglbCopy));
#endif
}
else
{
// Free memory if it couldn't be locked
::GlobalFree(hglbCopy);
}
}
// Close the clipboard.
VERIFY(::CloseClipboard());
}
//}}COPY TO CLIPBOARD
}
}
}
/**
Fills the grids within the tab control with the CKineticComp associated with nTabIndex
nTabIndex == -1 signifies that no CKineticComps have been defined yet
*/
void CCKPKineticsPg1::DisplayTab(int nTabIndex)
{
ASSERT_VALID(this);
CKineticComp kineticComp;
TCITEM tcItem;
tcItem.pszText = NULL;
if (nTabIndex >= 0)
{
TCHAR buffer[181];
tcItem.pszText = buffer;
tcItem.cchTextMax = 180;
tcItem.mask = TCIF_PARAM | TCIF_TEXT;
VERIFY(m_tcNames.GetItem(nTabIndex, &tcItem));
// lookup CKineticComp by lParam
kineticComp = m_mapComps[tcItem.lParam];
}
// General parameters:
{
// avoid flashing grid
CDelayUpdate update(&m_egGeneral);
m_egGeneral.SetFillStyle(flexFillRepeat);
m_egGeneral.SetRow(0);
m_egGeneral.SetCol(1);
m_egGeneral.SetRowSel(m_egGeneral.GetRows() - 1);
m_egGeneral.SetText(_T(""));
m_egGeneral.SetFillStyle(flexFillSingle);
CString str;
str.Format(_T("%.*g"), DBL_DIG, kineticComp.m_dM0);
m_egGeneral.SetTextMatrix(0, 1, str);
str.Format(_T("%.*g"), DBL_DIG, kineticComp.m_dM);
m_egGeneral.SetTextMatrix(1, 1, str);
str.Format(_T("%.*g"), DBL_DIG, kineticComp.m_dTol);
m_egGeneral.SetTextMatrix(2, 1, str);
m_egGeneral.SetRow(0);
m_egGeneral.SetCol(1);
}
// Formula:
{
// avoid flashing grid
CDelayUpdate update(&m_egFormula);
m_egFormula.SetFillStyle(flexFillRepeat);
m_egFormula.SetRow(1);
m_egFormula.SetCol(1);
m_egFormula.SetRowSel(m_egFormula.GetRows() - 1);
m_egFormula.SetColSel(m_egFormula.GetCols(0) - 1);
m_egFormula.SetText(_T(""));
m_egFormula.SetFillStyle(flexFillSingle);
// add CNameCoef if this rate name is a predefined phase
if (kineticComp.m_listNameCoef.size() == 0)
{
CDBPhase phase;
phase.m_strName = tcItem.pszText ? tcItem.pszText : "";
std::set<CDBPhase>::const_iterator phaseIter = GetDatabase().m_phaseSet.find(phase);
if (phaseIter != GetDatabase().m_phaseSet.end())
{
CNameCoef nameCoef;
nameCoef.m_strName = phaseIter->m_strFormula;
nameCoef.m_dCoef = 1.0;
kineticComp.m_listNameCoef.push_back(nameCoef);
}
}
std::list<CNameCoef>::const_iterator iterNameCoef = kineticComp.m_listNameCoef.begin();
for (long nRow = 1; iterNameCoef != kineticComp.m_listNameCoef.end(); ++iterNameCoef, ++nRow)
{
CString str;
m_egFormula.SetTextMatrix(nRow, 1, iterNameCoef->m_strName);
str.Format(_T("%.*g"), DBL_DIG, iterNameCoef->m_dCoef);
m_egFormula.SetTextMatrix(nRow, 2, str);
}
m_egFormula.SetTopRow(1);
m_egFormula.SetRow(1);
m_egFormula.SetCol(1);
}
// User parameters:
{
// avoid flashing grid
CDelayUpdate update(&m_egUser);
m_egUser.SetFillStyle(flexFillRepeat);
m_egUser.SetRow(0);
m_egUser.SetCol(1);
m_egUser.SetRowSel(m_egUser.GetRows() - 1);
m_egUser.SetText(_T(""));
m_egUser.SetFillStyle(flexFillSingle);
std::list<double>::const_iterator iter = kineticComp.m_listDParams.begin();
for (long nRow = 0; iter != kineticComp.m_listDParams.end(); ++iter, ++nRow)
{
CString str;
str.Format(_T("%.*g"), DBL_DIG, *iter);
m_egUser.SetTextMatrix(nRow, 1, str);
}
m_egUser.SetTopRow(0);
m_egUser.SetRow(0);
m_egUser.SetCol(1);
}
UpdateTabs();
ASSERT_VALID(this);
}
void CCKPKineticsPg1::OnSelchangeTcNames(NMHDR* pNMHDR, LRESULT* pResult)
{
// Note: OnSelchangingTcNames updates the rate
// UNREFERENCED_PARAMETER(pNMHDR);
DBG_UNREFERENCED_PARAMETER(pNMHDR);
int nCurSel = m_tcNames.GetCurSel();
ASSERT(nCurSel != -1 || m_tcNames.GetItemCount() == 0);
DisplayTab(nCurSel);
*pResult = 0;
}
void CCKPKineticsPg1::OnSelchangingTcNames(NMHDR* pNMHDR, LRESULT* pResult)
{
UNREFERENCED_PARAMETER(pNMHDR);
ASSERT(m_tcNames.GetCurSel() != -1);
// validate CKineticComp and disallow tab change if (UpdateData != TRUE)
*pResult = !(UpdateData(TRUE));
}
// COMMENT: {12/12/2000 4:04:31 PM}BOOL CCKPKineticsPg1::GetComp(long nRowIndex, CKineticComp* pComp)const
// COMMENT: {12/12/2000 4:04:31 PM}{
// COMMENT: {12/12/2000 4:04:31 PM} ASSERT(pComp != NULL);
// COMMENT: {12/12/2000 4:04:31 PM} ASSERT_VALID(this);
// COMMENT: {12/12/2000 4:04:31 PM} BOOL bItemFound = FALSE;
// COMMENT: {12/12/2000 4:04:31 PM} std::list<XGridTabItem>::const_iterator itemIter = m_listItems.begin();
// COMMENT: {12/12/2000 4:04:31 PM} for (; itemIter != m_listItems.end(); ++itemIter)
// COMMENT: {12/12/2000 4:04:31 PM} {
// COMMENT: {12/12/2000 4:04:31 PM} if (itemIter->nRowIndex == nRowIndex)
// COMMENT: {12/12/2000 4:04:31 PM} {
// COMMENT: {12/12/2000 4:04:31 PM} // item found
// COMMENT: {12/12/2000 4:04:31 PM} bItemFound = TRUE;
// COMMENT: {12/12/2000 4:04:31 PM}
// COMMENT: {12/12/2000 4:04:31 PM} // private members
// COMMENT: {12/12/2000 4:04:31 PM} // pComp->m_dInitialMoles = itemIter->kineticComp.m_dInitialMoles;
// COMMENT: {12/12/2000 4:04:31 PM} // pComp->m_dMoles = itemIter->kineticComp.m_dMoles;
// COMMENT: {12/12/2000 4:04:31 PM} // pComp->m_listCParams.assign(itemIter->kineticComp.m_listCParams.begin(), itemIter->kineticComp.m_listCParams.end());
// COMMENT: {12/12/2000 4:04:31 PM}
// COMMENT: {12/12/2000 4:04:31 PM} pComp->m_dM = itemIter->kineticComp.m_dM;
// COMMENT: {12/12/2000 4:04:31 PM} pComp->m_dM0 = itemIter->kineticComp.m_dM0;
// COMMENT: {12/12/2000 4:04:31 PM} pComp->m_dTol = itemIter->kineticComp.m_dTol;
// COMMENT: {12/12/2000 4:04:31 PM} pComp->m_listDParams.assign(itemIter->kineticComp.m_listDParams.begin(), itemIter->kineticComp.m_listDParams.end());
// COMMENT: {12/12/2000 4:04:31 PM} pComp->m_listNameCoef.assign(itemIter->kineticComp.m_listNameCoef.begin(), itemIter->kineticComp.m_listNameCoef.end());
// COMMENT: {12/12/2000 4:04:31 PM} pComp->m_strRateName = itemIter->kineticComp.m_strRateName;
// COMMENT: {12/12/2000 4:04:31 PM} break;
// COMMENT: {12/12/2000 4:04:31 PM} }
// COMMENT: {12/12/2000 4:04:31 PM} }
// COMMENT: {12/12/2000 4:04:31 PM} ASSERT_VALID(this);
// COMMENT: {12/12/2000 4:04:31 PM} return bItemFound;
// COMMENT: {12/12/2000 4:04:31 PM}}
// COMMENT: {12/12/2000 4:04:55 PM}CString CCKPKineticsPg1::GetRateName(long nRowIndex)const
// COMMENT: {12/12/2000 4:04:55 PM}{
// COMMENT: {12/12/2000 4:04:55 PM} ASSERT_VALID(this);
// COMMENT: {12/12/2000 4:04:55 PM} CString strName;
// COMMENT: {12/12/2000 4:04:55 PM} std::list<XGridTabItem>::const_iterator itemIter = m_listItems.begin();
// COMMENT: {12/12/2000 4:04:55 PM} for (; itemIter != m_listItems.end(); ++itemIter)
// COMMENT: {12/12/2000 4:04:55 PM} {
// COMMENT: {12/12/2000 4:04:55 PM} if (itemIter->nRowIndex == nRowIndex)
// COMMENT: {12/12/2000 4:04:55 PM} {
// COMMENT: {12/12/2000 4:04:55 PM} strName = itemIter->kineticComp.m_strRateName;
// COMMENT: {12/12/2000 4:04:55 PM} // item found
// COMMENT: {12/12/2000 4:04:55 PM} break;
// COMMENT: {12/12/2000 4:04:55 PM} }
// COMMENT: {12/12/2000 4:04:55 PM} }
// COMMENT: {12/12/2000 4:04:55 PM} ASSERT_VALID(this);
// COMMENT: {12/12/2000 4:04:55 PM} return strName;
// COMMENT: {12/12/2000 4:04:55 PM}}
// COMMENT: {12/11/2000 5:32:21 PM}BOOL CCKPKineticsPg1::SetCompName(long nRowIndex, LPCTSTR lpszName)
// COMMENT: {12/11/2000 5:32:21 PM}{
// COMMENT: {12/11/2000 5:32:21 PM} ASSERT_VALID(this);
// COMMENT: {12/11/2000 5:32:21 PM} ASSERT(lpszName && lstrlen(lpszName));
// COMMENT: {12/11/2000 5:32:21 PM} BOOL bItemFound = FALSE;
// COMMENT: {12/11/2000 5:32:21 PM} std::list<XGridTabItem>::iterator itemIter = m_listItems.begin();
// COMMENT: {12/11/2000 5:32:21 PM} for (; itemIter != m_listItems.end(); ++itemIter)
// COMMENT: {12/11/2000 5:32:21 PM} {
// COMMENT: {12/11/2000 5:32:21 PM} if (itemIter->nRowIndex == nRowIndex)
// COMMENT: {12/11/2000 5:32:21 PM} {
// COMMENT: {12/11/2000 5:32:21 PM} // item found
// COMMENT: {12/11/2000 5:32:21 PM} bItemFound = TRUE;
// COMMENT: {12/11/2000 5:32:21 PM}
// COMMENT: {12/11/2000 5:32:21 PM} // update list
// COMMENT: {12/11/2000 5:32:21 PM} itemIter->kineticComp.m_strRateName = lpszName;
// COMMENT: {12/11/2000 5:32:21 PM}
// COMMENT: {12/11/2000 5:32:21 PM} // update grid
// COMMENT: {12/11/2000 5:32:21 PM} m_egNames.SetTextMatrix(itemIter->nRowIndex, 0, lpszName);
// COMMENT: {12/11/2000 5:32:21 PM}
// COMMENT: {12/11/2000 5:32:21 PM} // update tab
// COMMENT: {12/11/2000 5:32:21 PM} TCITEM item;
// COMMENT: {12/11/2000 5:32:21 PM} item.mask = TCIF_TEXT;
// COMMENT: {12/11/2000 5:32:21 PM} item.pszText = (LPTSTR)lpszName;
// COMMENT: {12/11/2000 5:32:21 PM} m_tcNames.SetItem(itemIter->nTabIndex, &item);
// COMMENT: {12/11/2000 5:32:21 PM}
// COMMENT: {12/11/2000 5:32:21 PM} break;
// COMMENT: {12/11/2000 5:32:21 PM} }
// COMMENT: {12/11/2000 5:32:21 PM} }
// COMMENT: {12/11/2000 5:32:21 PM} ASSERT_VALID(this);
// COMMENT: {12/11/2000 5:32:21 PM} return bItemFound;
// COMMENT: {12/11/2000 5:32:21 PM}}
BOOL CCKPKineticsPg2::OnInitDialog()
{
baseCKPKineticsPg2::OnInitDialog();
// set layout
CreateRoot(VERTICAL, 5, 6)
<< (pane(HORIZONTAL, ABSOLUTE_VERT)
<< item(IDC_MSHFG_NUM_DESC, ABSOLUTE_VERT)
)
<< (pane(HORIZONTAL, GREEDY)
<< (paneCtrl(IDC_GB_TYPE_OF_INPUT, VERTICAL, ABSOLUTE_HORZ, nDefaultBorder, 10, 10)
<< item(IDC_RADIO_LINEAR, NORESIZE)
<< itemFixed(VERTICAL, 40)
<< item(IDC_RADIO_LIST, NORESIZE)
)
<< (pane(VERTICAL, GREEDY)
<< (paneCtrl(IDC_GB_LINEAR, HORIZONTAL, ABSOLUTE_VERT, nDefaultBorder, 10, 10)
<< itemFixed(HORIZONTAL, 10)
<< (pane(VERTICAL, NORESIZE)
<< item(IDC_STATIC_LINEAR1, NORESIZE)
<< item(IDC_E_TOTAL_TIME, NORESIZE)
)
<< itemFixed(HORIZONTAL, 50)
<< (pane(VERTICAL, NORESIZE)
<< item(IDC_STATIC_LINEAR3, NORESIZE)
<< (pane(HORIZONTAL, NORESIZE, 0, 0, 0)
<< item(IDC_E_STEPS, NORESIZE)
<< item(IDC_SPIN_STEPS, NORESIZE)
)
)
<< itemGrowing(HORIZONTAL)
)
<< (paneCtrl(IDC_GB_STEPS, HORIZONTAL, GREEDY, nDefaultBorder, 10, 10)
<< itemFixed(HORIZONTAL, 10)
<< item(IDC_MSHFG_LIST, ABSOLUTE_HORZ)
<< itemGrowing(HORIZONTAL)
)
)
)
<< (paneCtrl(IDC_S_DESC_INPUT, HORIZONTAL, GREEDY, nDefaultBorder, 10, 10)
<< item(IDC_E_DESC_INPUT, ABSOLUTE_VERT)
)
;
UpdateLayout();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
LRESULT CCKPKineticsPg1::OnBeginCellEdit(WPARAM wParam, LPARAM lParam)
{
NMEGINFO* pInfo = (NMEGINFO*)lParam;
UINT nID = wParam;
BOOL bDenyEdit = FALSE; // allow edit
if (nID == IDC_MSHFG_NAMES)
{
switch ( pInfo->item.iCol )
{
case 1 :
// set to rate list
pInfo->item.bUseCombo = (CUtil::InsertRates(pInfo->item.hWndCombo, GetDatabase()) > 0);
break;
default :
break;
}
}
return bDenyEdit;
}
void CCKPKineticsPg1::OnItemchangedClRates(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLISTVIEW* pNMListView = (NMLISTVIEW*)pNMHDR;
if ((pNMListView->uNewState ^ pNMListView->uOldState) & LVIS_STATEIMAGEMASK)
{
// do nothing if ignoring
if (m_bIgnoreCheckChange) return;
int cTabsBefore = m_tcNames.GetItemCount();
m_gltDoc.OnItemChanged(pNMHDR, pResult);
if (cTabsBefore > 0 && m_tcNames.GetItemCount() == 0)
{
// no tabs; previously one or more tabs
DisplayTab(-1);
}
else if (cTabsBefore > 1 && m_tcNames.GetCurSel() == -1)
{
// current tab has been deleted
m_tcNames.SetCurSel(0);
DisplayTab(m_tcNames.GetCurSel());
}
else if (cTabsBefore == 0 && m_tcNames.GetItemCount() > 0)
{
// new tab added; previously no tabs
m_tcNames.SetCurSel(0);
DisplayTab(m_tcNames.GetCurSel());
}
else if (m_tcNames.GetCurSel() != -1)
{
if (m_tcNames.GetItemCount() == cTabsBefore)
{
// this should not occur
ASSERT(FALSE);
}
else
{
// a tab was added or removed but the current selection has not changed
// do nothing
}
}
else
{
// unknown state
ASSERT(FALSE);
}
}
}
BEGIN_EVENTSINK_MAP(CCKPKineticsPg1, baseCKPKineticsPg1)
//{{AFX_EVENTSINK_MAP(CCKPKineticsPg1)
ON_EVENT(CCKPKineticsPg1, IDC_MSHFG_NAMES, -602 /* KeyDown */, OnKeyDownMshfgNames, VTS_PI2 VTS_I2)
ON_EVENT(CCKPKineticsPg1, IDC_MSHFG_GENERAL, -602 /* KeyDown */, OnKeyDownMshfgGeneral, VTS_PI2 VTS_I2)
ON_EVENT(CCKPKineticsPg1, IDC_MSHFG_GENERAL, 71 /* EnterCell */, OnEnterCellMshfgGeneral, VTS_NONE)
ON_EVENT(CCKPKineticsPg1, IDC_MSHFG_USER, 71 /* EnterCell */, OnEnterCellMshfgUser, VTS_NONE)
ON_EVENT(CCKPKineticsPg1, IDC_MSHFG_USER, -602 /* KeyDown */, OnKeyDownMshfgUser, VTS_PI2 VTS_I2)
ON_EVENT(CCKPKineticsPg1, IDC_MSHFG_FORMULA, -602 /* KeyDown */, OnKeyDownMshfgFormula, VTS_PI2 VTS_I2)
ON_EVENT(CCKPKineticsPg1, IDC_MSHFG_FORMULA, 71 /* EnterCell */, OnEnterCellMshfgFormula, VTS_NONE)
ON_EVENT(CCKPKineticsPg1, IDC_MSHFG_NUM_DESC, 71 /* EnterCell */, OnEnterCellMshfgNumDesc, VTS_NONE)
ON_EVENT(CCKPKineticsPg1, IDC_MSHFG_NAMES, 71 /* EnterCell */, OnEnterCellMshfgNames, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CCKPKineticsPg1::OnKeyDownMshfgFormula(short FAR* KeyCode, short Shift)
{
UNREFERENCED_PARAMETER(Shift);
switch (*KeyCode)
{
case VK_DELETE:
// just fill with empty strings
m_egFormula.SetFillStyle(flexFillRepeat);
m_egFormula.SetText(_T(""));
m_egFormula.SetFillStyle(flexFillSingle);
break;
}
}
void CCKPKineticsPg1::OnKeyDownMshfgGeneral(short FAR* KeyCode, short Shift)
{
UNREFERENCED_PARAMETER(Shift);
switch (*KeyCode)
{
case VK_DELETE:
// just fill with empty strings
m_egGeneral.SetFillStyle(flexFillRepeat);
m_egGeneral.SetText(_T(""));
m_egGeneral.SetFillStyle(flexFillSingle);
break;
}
}
void CCKPKineticsPg1::OnKeyDownMshfgNames(short FAR* KeyCode, short Shift)
{
UNREFERENCED_PARAMETER(Shift);
switch (*KeyCode)
{
case VK_DELETE :
{
long nCol = m_egNames.GetCol();
long nColSel = m_egNames.GetColSel();
// check if associated col is included (m_nCol)
if ((min(nCol, nColSel) <= 1) && (1 <= max(nCol, nColSel)))
{
long nRow = m_egNames.GetRow();
long nRowSel = m_egNames.GetRowSel();
// determine how many rows to delete
long cSelectedRows = abs(nRow - nRowSel) + 1;
// determine first row to delete
long iStartRow = min(nRow, nRowSel);
// delete each row
for (long i = 0; i < cSelectedRows; ++i)
{
CString strRateName = m_egNames.GetTextMatrix(iStartRow, 1);
if (!strRateName.IsEmpty())
{
CString strMsg;
::AfxFormatString1(strMsg, IDS_REMOVE_COMP_346, strRateName);
CGridListItem item;
switch (AfxMessageBox(strMsg, MB_YESNOCANCEL))
{
case IDYES :
{
int nCurSelTab = m_tcNames.GetCurSel();
// don't allow OnItemChanged to handle
ASSERT(m_bIgnoreCheckChange == FALSE);
m_bIgnoreCheckChange = TRUE;
item = m_gltDoc.DeleteRow(iStartRow);
ASSERT(m_bIgnoreCheckChange == TRUE);
m_bIgnoreCheckChange = FALSE;
if (nCurSelTab == item.m_nTab)
{
// update tabs only if current tab is removed
m_tcNames.SetCurSel(0);
DisplayTab(m_tcNames.GetCurSel());
}
}
break;
case IDNO :
iStartRow++;
break;
case IDCANCEL :
i = cSelectedRows; // break for loop
break;
}
}
}
}
}
break;
}
}
void CCKPKineticsPg1::OnKeyDownMshfgUser(short FAR* KeyCode, short Shift)
{
UNREFERENCED_PARAMETER(Shift);
switch (*KeyCode)
{
case VK_DELETE:
// just fill with empty strings
m_egUser.SetFillStyle(flexFillRepeat);
m_egUser.SetText(_T(""));
m_egUser.SetFillStyle(flexFillSingle);
break;
}
}
LRESULT CCKPKineticsPg1::OnEndCellEdit(WPARAM wParam, LPARAM lParam)
{
NMEGINFO* pInfo = (NMEGINFO*)lParam;
UINT nID = wParam;
BOOL bMakeChange = TRUE;
// ignore if edit is cancelled
if ( pInfo->item.pszText == NULL ) return bMakeChange;
CString strRateName;
switch ( nID )
{
case IDC_MSHFG_NAMES :
{
// replace spaces with underscores
strRateName = pInfo->item.pszText;
if (strRateName.Replace(_T(" "), _T("_")))
{
// see CEditGrid::EndEdit
free(pInfo->item.pszText);
pInfo->item.pszText = _tcsdup(strRateName);
}
int cTabsBefore = m_tcNames.GetItemCount();
ASSERT(m_bIgnoreCheckChange == FALSE);
m_bIgnoreCheckChange = TRUE;
bMakeChange = m_gltDoc.OnEndCellEdit(wParam, lParam);
ASSERT(m_bIgnoreCheckChange == TRUE);
m_bIgnoreCheckChange = FALSE;
if (cTabsBefore > 0 && m_tcNames.GetItemCount() == 0)
{
// no tabs; previously one or more tabs
DisplayTab(-1);
}
else if (cTabsBefore > 1 && m_tcNames.GetCurSel() == -1)
{
// current tab has been deleted
m_tcNames.SetCurSel(0);
DisplayTab(m_tcNames.GetCurSel());
}
else if (cTabsBefore == 0 && m_tcNames.GetItemCount() > 0)
{
// new tab added; previously no tabs
m_tcNames.SetCurSel(0);
DisplayTab(m_tcNames.GetCurSel());
}
else if (m_tcNames.GetCurSel() != -1)
{
ASSERT(m_tcNames.GetItemCount() > 0);
}
else
{
// no tabs before or after
ASSERT(cTabsBefore == 0 && m_tcNames.GetItemCount() == 0);
}
}
break;
case IDC_MSHFG_GENERAL :
// nothing to do
break;
case IDC_MSHFG_USER :