-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCKPSolid_SolutionsPg1.cpp
2159 lines (1913 loc) · 57.5 KB
/
CKPSolid_SolutionsPg1.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
// CKPSolid_SolutionsPg1.cpp : implementation file
//
// $Id$
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "CKPSolid_SolutionsPg1.h"
#include "DelayUpdate.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CCKPSolid_SolutionsPg1, baseCKPSolid_SolutionsPg1)
IMPLEMENT_DYNCREATE(CCKPSolid_SolutionsPg2, baseCKPSolid_SolutionsPg2)
/////////////////////////////////////////////////////////////////////////////
// CCKPSolid_SolutionsPg1 property page
CCKPSolid_SolutionsPg1::CCKPSolid_SolutionsPg1() : baseCKPSolid_SolutionsPg1(CCKPSolid_SolutionsPg1::IDD)
{
//{{AFX_DATA_INIT(CCKPSolid_SolutionsPg1)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CCKPSolid_SolutionsPg1::~CCKPSolid_SolutionsPg1()
{
}
void CCKPSolid_SolutionsPg1::DoDataExchange(CDataExchange* pDX)
{
baseCKPSolid_SolutionsPg1::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCKPSolid_SolutionsPg1)
DDX_Control(pDX, IDC_MSHFG_SOL_SOLS, m_egSolSols);
//}}AFX_DATA_MAP
DDX_S_S_List(pDX, IDC_MSHFG_SOL_SOLS);
}
void CCKPSolid_SolutionsPg1::DDX_S_S_List(CDataExchange* pDX, int nIDC)
{
ASSERT(nIDC == IDC_MSHFG_SOL_SOLS);
// reduce grid flicker
CDelayUpdate update(this, nIDC);
if (m_bFirstSetActive)
{
// Init edit grid
InitGrid();
}
if (pDX->m_bSaveAndValidate)
{
PrepareEditGridCtrl(pDX, nIDC);
std::list<CS_S> listS_S;
for (long nRow = m_egSolSols.GetFixedRows(); nRow < m_egSolSols.GetRows(); nRow = GetLastCompRow(nRow) + 1)
{
ASSERT(m_egSolSols.GetCellEnabled(nRow, 0));
CString strName;
DDX_GridText(pDX, nIDC, nRow, 0, strName);
if (strName.IsEmpty())
{
continue;
}
//
// solid-solution name
//
CS_S S_S;
S_S.m_strName = strName;
// get components
long nLastComp = GetLastCompRow(nRow);
for (long nCompRow = nRow + 1; nCompRow <= nLastComp; ++nCompRow)
{
CS_S_Comp S_S_Comp;
//
// phase name
//
DDX_GridText(pDX, nIDC, nCompRow, 1, S_S_Comp.m_strName);
if (S_S_Comp.m_strName.IsEmpty()) continue;
//
// moles
//
CString strTemp;
DDX_GridText(pDX, nIDC, nCompRow, 2, strTemp);
if (strTemp.IsEmpty())
{
DDX_GridFail(pDX, _T("You must define the number of moles for this component."),
_T("No moles defined"));
}
double dMoles;
DDX_GridText(pDX, nIDC, nCompRow, 2, dMoles);
S_S_Comp.m_ldMoles = dMoles;
S_S.m_listComp.push_back(S_S_Comp);
}
if (S_S.m_listComp.size() < 2)
{
DDX_GridText(pDX, nIDC, nRow, 0, S_S.m_strName);
DDX_GridFail(pDX, _T("You must define at least two components for each solid-solution."),
_T("Not enough components"));
}
// OK
listS_S.push_back(S_S);
}
// All OK
m_listS_S.assign(listS_S.begin(), listS_S.end());
}
else
{
// for now only exchange on first activation
if (!m_bFirstSetActive) return;
std::list<CS_S>::iterator iter = m_listS_S.begin();
for (long nRow = 1; iter != m_listS_S.end(); ++iter, nRow = GetLastCompRow(nRow) + 1)
{
// solid-solution name
DDX_GridText(pDX, nIDC, nRow, 0, (*iter).m_strName);
m_egSolSols.SetRow(nRow); // needed for OnBtnAddComp
// add rows if nec
int nNewRows = (*iter).m_listComp.size() - 2;
for (int i = 0; i < nNewRows; ++i)
{
OnBtnAddComp();
}
std::list<CS_S_Comp>::iterator iterComp = (*iter).m_listComp.begin();
for (long nCompRow = nRow + 1; iterComp != (*iter).m_listComp.end(); ++iterComp, ++nCompRow)
{
// phase name
DDX_GridText(pDX, nIDC, nCompRow, 1, (*iterComp).m_strName);
// moles
DDX_GridText(pDX, nIDC, nCompRow, 2, (*iterComp).m_ldMoles);
}
}
// reset starting grid position
m_egSolSols.SetRow(1); m_egSolSols.SetCol(0);
}
}
void CCKPSolid_SolutionsPg1::InitGrid()
{
// set rows
m_egSolSols.SetRows(max(m_egSolSols.GetRows(), (long)(m_listS_S.size() + 1) * 3 + 1));
// set titles
m_egSolSols.SetTextMatrix(0, 0, _T("Solid-solution name"));
m_egSolSols.SetTextMatrix(0, 1, _T("Phase name"));
m_egSolSols.SetTextMatrix(0, 2, _T("Moles"));
// bold and centered
for (long nCol = 0; nCol < m_egSolSols.GetCols(0); ++nCol)
{
m_egSolSols.SetRow(0); m_egSolSols.SetCol(nCol);
m_egSolSols.SetCellFontBold(TRUE);
m_egSolSols.SetCellAlignment(flexAlignCenterCenter);
}
// set col widths
const long col0 = 1849;
const long col1 = 1207;
const long col2 = 902;
m_egSolSols.SetColWidth(0, 0, col0);
m_egSolSols.SetColWidth(1, 0, col1);
m_egSolSols.SetColWidth(2, 0, col2);
switch ((m_egSolSols.GetRows() - 1) % 3)
{
case 1 :
m_egSolSols.SetRows(m_egSolSols.GetRows() + 2);
break;
case 2 :
m_egSolSols.SetRows(m_egSolSols.GetRows() + 1);
break;
}
ASSERT( (m_egSolSols.GetRows() - 1) % 3 == 0 );
for (long nRow = 1; nRow < m_egSolSols.GetRows(); ++nRow)
{
switch (nRow % 3)
{
case 0 :
m_egSolSols.SetTextMatrix(nRow, 0, _T("comp2"));
m_egSolSols.SetHeaderCell(nRow, 0);
m_egSolSols.SetRow(nRow); m_egSolSols.SetCol(0);
m_egSolSols.SetCellAlignment(flexAlignRightCenter);
break;
case 1 :
m_egSolSols.DisableCell(nRow, 1);
m_egSolSols.DisableCell(nRow, 2);
break;
case 2 :
m_egSolSols.SetTextMatrix(nRow, 0, _T("comp1"));
m_egSolSols.SetHeaderCell(nRow, 0);
m_egSolSols.SetRow(nRow); m_egSolSols.SetCol(0);
m_egSolSols.SetCellAlignment(flexAlignRightCenter);
break;
}
}
// set initial position
m_egSolSols.SetRow(1); m_egSolSols.SetCol(0);
}
BEGIN_MESSAGE_MAP(CCKPSolid_SolutionsPg1, baseCKPSolid_SolutionsPg1)
//{{AFX_MSG_MAP(CCKPSolid_SolutionsPg1)
ON_BN_CLICKED(IDC_BTN_ADD_COMP, OnBtnAddComp)
ON_BN_CLICKED(IDC_BTN_REM_COMP, OnBtnRemComp)
ON_WM_HELPINFO()
//}}AFX_MSG_MAP
// custom set focus notifications
ON_BN_SETFOCUS(IDC_BTN_ADD_COMP, OnSetfocusBtnAddComp)
ON_BN_SETFOCUS(IDC_BTN_REM_COMP, OnSetfocusBtnRemComp)
// custom edit grid notifications
ON_MESSAGE(EGN_BEGINCELLEDIT, OnBeginCellEdit)
ON_MESSAGE(EGN_ENDCELLEDIT, OnEndCellEdit)
ON_MESSAGE(EGN_SETFOCUS, OnSetfocusEG)
END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(CCKPSolid_SolutionsPg2, baseCKPSolid_SolutionsPg2)
//{{AFX_MSG_MAP(CCKPSolid_SolutionsPg2)
ON_WM_HELPINFO()
//}}AFX_MSG_MAP
ON_MESSAGE(EGN_SETFOCUS, OnSetfocusEG)
ON_MESSAGE(EGN_BEGINCELLEDIT, OnBeginCellEdit)
ON_MESSAGE(EGN_ENDCELLEDIT, OnEndCellEdit)
END_MESSAGE_MAP()
void CCKPSolid_SolutionsPg1::OnSetfocusBtnAddComp()
{
// in order for a button to recieve this notification
// it must have the notify style set
CString strRes;
strRes.LoadString(IDS_STRING479);
m_eInputDesc.SetWindowText(strRes);
}
void CCKPSolid_SolutionsPg1::OnSetfocusBtnRemComp()
{
// in order for a button to recieve this notification
// it must have the notify style set
CString strRes;
strRes.LoadString(IDS_STRING480);
m_eInputDesc.SetWindowText(strRes);
}
/////////////////////////////////////////////////////////////////////////////
// CCKPSolid_SolutionsPg2 property page
CCKPSolid_SolutionsPg2::CCKPSolid_SolutionsPg2() : baseCKPSolid_SolutionsPg2(CCKPSolid_SolutionsPg2::IDD)
{
//{{AFX_DATA_INIT(CCKPSolid_SolutionsPg2)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Fill options list
m_mapIC2String[CS_S::IC_GUGG_NONDIMENSIONAL] = _T("-Gugg_nondim");
m_mapIC2String[CS_S::IC_GUGG_KJ] = _T("-Gugg_kj");
m_mapIC2String[CS_S::IC_ACTIVITY_COEFFICIENTS] = _T("-activity_coefficients");
m_mapIC2String[CS_S::IC_DISTRIBUTION_COEFFICIENTS] = _T("-distribution_coefficients");
m_mapIC2String[CS_S::IC_MISCIBILITY_GAP] = _T("-miscibility_gap");
m_mapIC2String[CS_S::IC_SPINODAL_GAP] = _T("-spinodal_gap");
m_mapIC2String[CS_S::IC_CRITICAL_POINT] = _T("-critical_point");
m_mapIC2String[CS_S::IC_ALYOTROPIC_POINT] = _T("-alyotropic_point");
m_mapIC2String[CS_S::IC_THOMPSON] = _T("-Thompson");
m_mapIC2String[CS_S::IC_MARGULES] = _T("-Margules");
std::map<enum CS_S::InputCase, CString>::const_iterator iter =
m_mapIC2String.begin();
for (; iter != m_mapIC2String.end(); ++iter)
{
m_mapString2IC[(*iter).second] = (*iter).first;
}
}
CCKPSolid_SolutionsPg2::~CCKPSolid_SolutionsPg2()
{
}
void CCKPSolid_SolutionsPg2::DoDataExchange(CDataExchange* pDX)
{
baseCKPSolid_SolutionsPg2::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCKPSolid_SolutionsPg2)
DDX_Control(pDX, IDC_MSHFG_SOL_SOLS, m_egSolSols);
//}}AFX_DATA_MAP
DDX_S_S_List(pDX, IDC_MSHFG_SOL_SOLS);
}
void CCKPSolid_SolutionsPg2::DDX_S_S_List(CDataExchange* pDX, int nIDC)
{
ASSERT(nIDC == IDC_MSHFG_SOL_SOLS);
ASSERT(nIDC == m_egSolSols.GetDlgCtrlID());
// reduce grid flicker
CDelayUpdate update(this, nIDC);
if (m_bFirstSetActive)
{
// Init edit grid
InitGrid();
}
if (pDX->m_bSaveAndValidate)
{
// VALIDATE
//// ValidateEGSolSols();
PrepareEditGridCtrl(pDX, nIDC);
std::list<CS_S> listS_S;
for (long nRow = m_egSolSols.GetFixedRows(); nRow < m_egSolSols.GetRows(); nRow = GetLastCompRow(nRow) + 1)
{
ASSERT(m_egSolSols.GetCellEnabled(nRow, 0));
CString strDummy;
DDX_GridText(pDX, nIDC, nRow, 0, strDummy);
if (strDummy.IsEmpty())
{
continue;
}
//
// solid-solution name
//
CS_S S_S;
S_S.m_strName = strDummy;
//
// excess free energy option
//
DDX_GridText(pDX, nIDC, nRow, 3, strDummy);
if (strDummy.IsEmpty())
{
DDX_GridFail(pDX, _T("You must define the excess free energy option for this solid-solution."),
_T("No free energy option"));
}
std::map<CString, enum CS_S::InputCase>::const_iterator item = m_mapString2IC.find(strDummy);
if (item == m_mapString2IC.end())
{
DDX_GridFail(pDX, _T("Please select an excess free energy option from the list."),
_T("Unknown free energy option"));
}
S_S.m_nInputCase = (*item).second;
//
// temperature in Kelvin
//
DDX_GridText(pDX, nIDC, nRow, 5, strDummy);
if ( strDummy.CompareNoCase(_T("deg C")) == 0 )
{
S_S.m_dTk = 273.15;
}
else if ( strDummy.CompareNoCase(_T("deg K")) == 0 )
{
S_S.m_dTk = 0;
}
else
{
DDX_GridFail(pDX, _T("Please select the appropriate temperature units from the list."),
_T("Unknown temperature units"));
}
DDX_GridText(pDX, nIDC, nRow, 4, strDummy);
if ( strDummy.IsEmpty() )
{
DDX_GridFail(pDX, _T("You must define the temperature for this solid-solution."),
_T("No temperature defined"));
}
double dTemp;
DDX_GridText(pDX, nIDC, nRow, 4, dTemp);
S_S.m_dTk += dTemp;
if ( S_S.m_dTk < 0.0 )
{
DDX_GridFail(pDX, _T("Temperature must be greater than zero."),
_T("Invalid temperature"));
}
//
// param 1-4
//
int nParams = 2;
switch (S_S.m_nInputCase)
{
case CS_S::IC_GUGG_NONDIMENSIONAL :
case CS_S::IC_MISCIBILITY_GAP :
case CS_S::IC_SPINODAL_GAP :
case CS_S::IC_CRITICAL_POINT :
case CS_S::IC_ALYOTROPIC_POINT :
case CS_S::IC_GUGG_KJ :
case CS_S::IC_THOMPSON :
case CS_S::IC_MARGULES :
ASSERT( m_egSolSols.GetCellEnabled(nRow, 8) == FALSE );
ASSERT( m_egSolSols.GetCellEnabled(nRow, 9) == FALSE );
nParams = 2;
break;
case CS_S::IC_ACTIVITY_COEFFICIENTS :
case CS_S::IC_DISTRIBUTION_COEFFICIENTS :
ASSERT( m_egSolSols.GetCellEnabled(nRow, 8) == TRUE );
ASSERT( m_egSolSols.GetCellEnabled(nRow, 9) == TRUE );
nParams = 4;
break;
}
for (int i = 0; i < nParams; ++i)
{
DDX_GridText(pDX, nIDC, nRow, i + 6, strDummy);
if ( strDummy.IsEmpty() )
{
DDX_GridFail(pDX, _T("You must define this parameter for this solid-solution."),
_T("Missing parameter"));
}
DDX_GridText(pDX, nIDC, nRow, i + 6, S_S.m_arrldP[i]);
}
// get components
long nLastComp = GetLastCompRow(nRow);
for (long nCompRow = nRow + 1; nCompRow <= nLastComp; ++nCompRow)
{
CS_S_Comp S_S_Comp;
//
// phase name
//
DDX_GridText(pDX, nIDC, nCompRow, 1, S_S_Comp.m_strName);
if (S_S_Comp.m_strName.IsEmpty()) continue;
//
// moles
//
CString strTemp;
DDX_GridText(pDX, nIDC, nCompRow, 2, strTemp);
if (strTemp.IsEmpty())
{
DDX_GridFail(pDX, _T("You must define the number of moles for this component."),
_T("No moles defined"));
}
double dMoles;
DDX_GridText(pDX, nIDC, nCompRow, 2, dMoles);
S_S_Comp.m_ldMoles = dMoles;
S_S.m_listComp.push_back(S_S_Comp);
}
if (S_S.m_listComp.size() < 2)
{
DDX_GridText(pDX, nIDC, nRow, 0, S_S.m_strName);
DDX_GridFail(pDX, _T("You must define two components for each solid-solution."),
_T("Not enough components"));
}
// OK
listS_S.push_back(S_S);
}
// All OK
m_listS_S.assign(listS_S.begin(), listS_S.end());
}
else
{
// for now only exchange on first activation
if (!m_bFirstSetActive) return;
std::list<CS_S>::iterator iter = m_listS_S.begin();
for (long nRow = 1; iter != m_listS_S.end(); ++iter, nRow = GetLastCompRow(nRow) + 1)
{
//
// solid-solution name
//
DDX_GridText(pDX, nIDC, nRow, 0, (*iter).m_strName);
//
// excess free energy option
//
std::map<enum CS_S::InputCase, CString>::iterator item = m_mapIC2String.find((*iter).m_nInputCase);
ASSERT( item != m_mapIC2String.end() );
DDX_GridText(pDX, nIDC, nRow, 3, (*item).second);
long i;
switch ((*iter).m_nInputCase)
{
case CS_S::IC_GUGG_NONDIMENSIONAL :
case CS_S::IC_MISCIBILITY_GAP :
case CS_S::IC_SPINODAL_GAP :
case CS_S::IC_CRITICAL_POINT :
case CS_S::IC_ALYOTROPIC_POINT :
case CS_S::IC_GUGG_KJ :
case CS_S::IC_THOMPSON :
case CS_S::IC_MARGULES :
ASSERT( m_egSolSols.GetCellEnabled(nRow, 8) == FALSE );
ASSERT( m_egSolSols.GetCellEnabled(nRow, 9) == FALSE );
//
// param 1-2
//
for (i = 0; i < 2; ++i)
{
DDX_GridText(pDX, nIDC, nRow, i + 6, (*iter).m_arrldP[i]);
}
break;
case CS_S::IC_ACTIVITY_COEFFICIENTS :
case CS_S::IC_DISTRIBUTION_COEFFICIENTS :
m_egSolSols.EnableCell(nRow, 8);
m_egSolSols.EnableCell(nRow, 9);
//
// param 1-4
//
for (i = 0; i < 4; ++i)
{
DDX_GridText(pDX, nIDC, nRow, i + 6, (*iter).m_arrldP[i]);
}
break;
default :
ASSERT( FALSE ); // invalid input case
break;
}
//
// temperature in Kelvin
//
DDX_GridText(pDX, nIDC, nRow, 4, (*iter).m_dTk);
CString strDummy(_T("deg K"));
DDX_GridText(pDX, nIDC, nRow, 5, strDummy);
// set components
std::list<CS_S_Comp>::iterator iterComp = (*iter).m_listComp.begin();
for (long nCompRow = nRow + 1; iterComp != (*iter).m_listComp.end(); ++iterComp, ++nCompRow)
{
//
// phase name
//
DDX_GridText(pDX, nIDC, nCompRow, 1, (*iterComp).m_strName);
//
// moles
//
DDX_GridText(pDX, nIDC, nCompRow, 2, (*iterComp).m_ldMoles);
}
}
}
}
BOOL CCKPSolid_SolutionsPg2::OnInitDialog()
{
baseCKPSolid_SolutionsPg2::OnInitDialog();
CreateRoot(VERTICAL, 5, 6)
<< (pane(HORIZONTAL, ABSOLUTE_VERT)
<< item(IDC_MSHFG_NUM_DESC, ABSOLUTE_VERT)
)
<< item(IDC_MSHFG_SOL_SOLS, GREEDY)
<< (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
}
BEGIN_EVENTSINK_MAP(CCKPSolid_SolutionsPg2, baseCKPSolid_SolutionsPg2)
//{{AFX_EVENTSINK_MAP(CCKPSolid_SolutionsPg2)
ON_EVENT(CCKPSolid_SolutionsPg2, IDC_MSHFG_SOL_SOLS, -602 /* KeyDown */, OnKeyDownMshfgSolSols, VTS_PI2 VTS_I2)
ON_EVENT(CCKPSolid_SolutionsPg2, IDC_MSHFG_NUM_DESC, 71 /* EnterCell */, OnEnterCellMshfgNumDesc, VTS_NONE)
ON_EVENT(CCKPSolid_SolutionsPg2, IDC_MSHFG_SOL_SOLS, 71 /* EnterCell */, OnEnterCellMshfgSolSols, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
LRESULT CCKPSolid_SolutionsPg1::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;
switch ( nID )
{
case IDC_MSHFG_SOL_SOLS :
if (pInfo->item.iCol == 0 && (GetLastCompRow() + 1 == m_egSolSols.GetRows()))
{
// add more rows if nec
m_egSolSols.SetRows(m_egSolSols.GetRows() + 3);
for (long nRow = m_egSolSols.GetRows() - 3; nRow < m_egSolSols.GetRows(); ++nRow)
{
switch (nRow % 3)
{
case 0 :
m_egSolSols.SetTextMatrix(nRow, 0, _T("comp2"));
m_egSolSols.SetHeaderCell(nRow, 0);
m_egSolSols.SetRow(nRow); m_egSolSols.SetCol(0);
m_egSolSols.SetCellAlignment(flexAlignRightCenter);
break;
case 1 :
m_egSolSols.DisableCell(nRow, 1);
m_egSolSols.DisableCell(nRow, 2);
break;
case 2 :
m_egSolSols.SetTextMatrix(nRow, 0, _T("comp1"));
m_egSolSols.SetHeaderCell(nRow, 0);
m_egSolSols.SetRow(nRow); m_egSolSols.SetCol(0);
m_egSolSols.SetCellAlignment(flexAlignRightCenter);
break;
}
}
// reset position
m_egSolSols.SetRow(pInfo->item.iRow); m_egSolSols.SetCol(0);
}
break;
}
return bMakeChange;
}
LRESULT CCKPSolid_SolutionsPg1::OnBeginCellEdit(WPARAM wParam, LPARAM lParam)
{
NMEGINFO* pInfo = (NMEGINFO*)lParam;
UINT nID = wParam;
BOOL bDenyEdit = FALSE; // allow edit
if ( nID == IDC_MSHFG_SOL_SOLS )
{
switch ( pInfo->item.iCol )
{
case 1 :
// set to phase list
pInfo->item.bUseCombo = (CUtil::InsertPhases(pInfo->item.hWndCombo, GetDatabase()) > 0);
break;
default :
break;
}
}
return bDenyEdit;
}
void CCKPSolid_SolutionsPg1::OnBtnAddComp()
{
long nSaveRow = m_egSolSols.GetRow();
long nSaveCol = m_egSolSols.GetCol();
long nRow = GetLastCompRow(nSaveRow);
CString strComp = m_egSolSols.GetTextMatrix(nRow, 0);
ASSERT(strComp.GetLength() > 4);
CString strVal = strComp.Mid(4);
ASSERT(::_istdigit(strVal[0]));
int nVal = _ttoi(strVal);
m_egSolSols.SetRows(m_egSolSols.GetRows() + 1);
strComp.Format(_T("comp%d"), nVal + 1);
m_egSolSols.SetTextMatrix(m_egSolSols.GetRows() - 1, 0, strComp);
m_egSolSols.SetHeaderCell(m_egSolSols.GetRows() - 1, 0);
m_egSolSols.SetRow(m_egSolSols.GetRows() - 1); m_egSolSols.SetCol(0);
m_egSolSols.SetCellAlignment(flexAlignRightCenter);
m_egSolSols.SetRowPosition(m_egSolSols.GetRows() - 1, nRow + 1);
m_egSolSols.SetRow(nSaveRow); m_egSolSols.SetCol(nSaveCol);
}
long CCKPSolid_SolutionsPg1::GetLastCompRow(long nRow /* -1 */)
{
CDelayUpdate delay(&m_egSolSols);
if (nRow == -1)
{
nRow = m_egSolSols.GetRow();
}
if (m_egSolSols.GetCellEnabled(nRow, 0))
{
nRow += 2;
}
CString strComp = m_egSolSols.GetTextMatrix(nRow, 0);
ASSERT( strComp.Left(4).Compare(_T("comp")) == 0 );
while (m_egSolSols.GetRows() > nRow + 1)
{
TRACE("In while nRow = %d\n", nRow);
ASSERT( m_egSolSols.GetRows() > nRow + 1 );
if (m_egSolSols.GetCellEnabled(nRow + 1, 0))
{
break;
}
nRow++;
};
strComp = m_egSolSols.GetTextMatrix(nRow, 0);
ASSERT( strComp.Left(4).Compare(_T("comp")) == 0 );
return nRow;
}
long CCKPSolid_SolutionsPg2::GetLastCompRow(long nRow /* -1 */)
{
// avoid flashing grid
CDelayUpdate delay(&m_egSolSols);
if (nRow == -1)
{
nRow = m_egSolSols.GetRow();
}
if (m_egSolSols.GetCellEnabled(nRow, 0))
{
nRow += 2;
}
CString strComp = m_egSolSols.GetTextMatrix(nRow, 0);
ASSERT( strComp.Left(4).Compare(_T("comp")) == 0 );
while (m_egSolSols.GetRows() > nRow + 1)
{
ASSERT( m_egSolSols.GetRows() > nRow + 1 );
if (m_egSolSols.GetCellEnabled(nRow + 1, 0))
{
break;
}
nRow++;
};
strComp = m_egSolSols.GetTextMatrix(nRow, 0);
ASSERT( strComp.Left(4).Compare(_T("comp")) == 0 );
return nRow;
}
BEGIN_EVENTSINK_MAP(CCKPSolid_SolutionsPg1, baseCKPSolid_SolutionsPg1)
//{{AFX_EVENTSINK_MAP(CCKPSolid_SolutionsPg1)
ON_EVENT(CCKPSolid_SolutionsPg1, IDC_MSHFG_SOL_SOLS, -602 /* KeyDown */, OnKeyDownMshfgSolSols, VTS_PI2 VTS_I2)
ON_EVENT(CCKPSolid_SolutionsPg1, IDC_MSHFG_SOL_SOLS, 71 /* EnterCell */, OnEnterCellMshfgSolSols, VTS_NONE)
ON_EVENT(CCKPSolid_SolutionsPg1, IDC_MSHFG_NUM_DESC, 71 /* EnterCell */, OnEnterCellMshfgNumDesc, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CCKPSolid_SolutionsPg1::OnKeyDownMshfgSolSols(short FAR* KeyCode, short Shift)
{
UNUSED(Shift);
CString strComp, strLastComp, strSolSol, strFormat;
long nRow, nLastRow, nDeleteRow;
long nCol;
switch (*KeyCode)
{
case VK_DELETE :
nCol = m_egSolSols.GetCol();
nRow = m_egSolSols.GetRow();
if (nCol == 0)
{
if (m_egSolSols.GetCellEnabled(nRow, nCol) == TRUE) // delete solid
{
strSolSol = m_egSolSols.GetTextMatrix(nRow, 0);
if (strSolSol.IsEmpty())
{
MessageBeep(0);
break;
}
strFormat.Format(_T("Are you sure you want to delete %s?"), strSolSol);
if (MessageBox(strFormat, _T("Confirm deletion"), MB_YESNO) == IDYES)
{
nLastRow = GetLastCompRow();
m_egSolSols.SetRedraw(FALSE);
int nCount = nLastRow - nRow + 1;
for (int n = 0; n < nCount; ++n)
{
m_egSolSols.EnableCell(nRow, 0);
m_egSolSols.EnableCell(nRow, 1);
m_egSolSols.EnableCell(nRow, 2);
m_egSolSols.DeleteRow(nRow);
}
// delete extra rows
m_egSolSols.SetRows(m_egSolSols.GetRows() - nCount + 3);
// add headers
m_egSolSols.DisableCell(m_egSolSols.GetRows() - 3, 1); // phase name
m_egSolSols.DisableCell(m_egSolSols.GetRows() - 3, 2); // moles
m_egSolSols.SetTextMatrix(m_egSolSols.GetRows() - 2, 0, _T("comp1"));
m_egSolSols.DisableCell(m_egSolSols.GetRows() - 2, 0);
m_egSolSols.SetRow(m_egSolSols.GetRows() - 2); m_egSolSols.SetCol(0);
m_egSolSols.SetCellAlignment(flexAlignRightCenter);
m_egSolSols.SetTextMatrix(m_egSolSols.GetRows() - 1, 0, _T("comp2"));
m_egSolSols.DisableCell(m_egSolSols.GetRows() - 1, 0);
m_egSolSols.SetRow(m_egSolSols.GetRows() - 1); m_egSolSols.SetCol(0);
m_egSolSols.SetCellAlignment(flexAlignRightCenter);
// reset selection
m_egSolSols.SetRow(nRow); m_egSolSols.SetCol(0);
m_egSolSols.SetRowSel(nRow); m_egSolSols.SetColSel(0);
m_egSolSols.SetRedraw(TRUE);
}
}
else // delete component
{
nDeleteRow = m_egSolSols.GetRow();
nLastRow = GetLastCompRow(nDeleteRow);
strLastComp = m_egSolSols.GetTextMatrix(nLastRow, 0);
if (strLastComp.Compare(_T("comp2")) == 0)
{
MessageBox(_T("Each solid solution requires at least two components."), _T("Error"));
break;
}
// confirm deletion
strComp = m_egSolSols.GetTextMatrix(nDeleteRow, 0);
strFormat.Format(_T("Are you sure you want to delete %s?"), strComp);
if (MessageBox(strFormat, _T("Confirm deletion"), MB_YESNO) == IDYES)
{
if (nDeleteRow == nLastRow)
{
// delete row
m_egSolSols.DeleteRow(nDeleteRow);
m_egSolSols.SetRows(m_egSolSols.GetRows() - 1);
// reset selection
m_egSolSols.SetRow(nDeleteRow); m_egSolSols.SetCol(0);
m_egSolSols.SetRowSel(nDeleteRow); m_egSolSols.SetColSel(0);
}
else
{
// set clipping region
m_egSolSols.SetRow(nDeleteRow + 1); m_egSolSols.SetCol(1);
m_egSolSols.SetRowSel(nLastRow); m_egSolSols.SetColSel(2);
CString strClip = m_egSolSols.GetClip();
// set new clipping region
m_egSolSols.SetRow(nDeleteRow); m_egSolSols.SetCol(1);
m_egSolSols.SetRowSel(nLastRow - 1); m_egSolSols.SetColSel(2);
m_egSolSols.SetClip(strClip);
// delete row
m_egSolSols.DeleteRow(nLastRow);
m_egSolSols.SetRows(m_egSolSols.GetRows() - 1);
// reset selection
m_egSolSols.SetRow(nDeleteRow); m_egSolSols.SetCol(0);
m_egSolSols.SetRowSel(nDeleteRow); m_egSolSols.SetColSel(0);
}
}
}
}
else
{
long nFirstRow = min(m_egSolSols.GetRow(), m_egSolSols.GetRowSel());
long nLastRow = max(m_egSolSols.GetRow(), m_egSolSols.GetRowSel());
for (long nRow = nFirstRow; nRow <= nLastRow; ++nRow)
{
long nFirstCol = min(m_egSolSols.GetCol(), m_egSolSols.GetColSel());
long nLastCol = max(m_egSolSols.GetCol(), m_egSolSols.GetColSel());
for (long nCol = nFirstCol; nCol <= nLastCol; ++nCol)
{
if (m_egSolSols.GetCellEnabled(nRow, nCol))
{
m_egSolSols.SetTextMatrix(nRow, nCol, _T(""));
}
}
}
}
break;
}
}
void CCKPSolid_SolutionsPg2::OnKeyDownMshfgSolSols(short FAR* KeyCode, short Shift)
{
UNUSED(Shift);
CString strComp, strLastComp, strSolSol, strFormat;
long nRow, nLastRow /*, nDeleteRow */;
long nCol;
switch (*KeyCode)
{
case VK_DELETE :
nCol = m_egSolSols.GetCol();
nRow = m_egSolSols.GetRow();
if (m_egSolSols.GetCellEnabled(nRow, nCol) == FALSE)
{
MessageBeep(0);
break;
}
if (nCol == 0)
{
if (m_egSolSols.GetCellEnabled(nRow, nCol) == TRUE) // delete solid
{
strSolSol = m_egSolSols.GetTextMatrix(nRow, 0);
if (strSolSol.IsEmpty())
{
MessageBeep(0);
break;
}
strFormat.Format(_T("Are you sure you want to delete %s?"), strSolSol);
if (MessageBox(strFormat, _T("Confirm deletion"), MB_YESNO) == IDYES)
{
nLastRow = GetLastCompRow(nRow);
m_egSolSols.SetRedraw(FALSE);
int nCount = nLastRow - nRow + 1;
for (int n = 0; n < nCount; ++n)
{
m_egSolSols.EnableCell(nRow, 0);
m_egSolSols.EnableCell(nRow, 1);
m_egSolSols.EnableCell(nRow, 2);
m_egSolSols.DeleteRow(nRow);
}
// delete extra rows
m_egSolSols.SetRows(m_egSolSols.GetRows() - nCount + 3);
// add headers
m_egSolSols.DisableCell(m_egSolSols.GetRows() - 3, 1); // phase name
m_egSolSols.DisableCell(m_egSolSols.GetRows() - 3, 2); // moles
//{{
m_egSolSols.SetTextMatrix(m_egSolSols.GetRows() - 3, 3, _T("-Gugg_nondim"));
m_egSolSols.SetTextMatrix(m_egSolSols.GetRows() - 3, 5, _T("deg C"));
//}}
m_egSolSols.SetTextMatrix(m_egSolSols.GetRows() - 2, 0, _T("comp1"));
m_egSolSols.DisableCell(m_egSolSols.GetRows() - 2, 0);
m_egSolSols.SetRow(m_egSolSols.GetRows() - 2); m_egSolSols.SetCol(0);
m_egSolSols.SetCellAlignment(flexAlignRightCenter);
m_egSolSols.SetTextMatrix(m_egSolSols.GetRows() - 1, 0, _T("comp2"));
m_egSolSols.DisableCell(m_egSolSols.GetRows() - 1, 0);
m_egSolSols.SetRow(m_egSolSols.GetRows() - 1); m_egSolSols.SetCol(0);
m_egSolSols.SetCellAlignment(flexAlignRightCenter);
// reset selection
m_egSolSols.SetRow(nRow); m_egSolSols.SetCol(0);
m_egSolSols.SetRowSel(nRow); m_egSolSols.SetColSel(0);
m_egSolSols.SetRedraw(TRUE);
}
}
}
else
{
m_egSolSols.SetTextMatrix(nRow, nCol, _T(""));
}
break;
}
}
void CCKPSolid_SolutionsPg1::OnEnterCellMshfgSolSols()
{
CString strRes;
if ( m_egSolSols.GetCellEnabled(m_egSolSols.GetRow(), m_egSolSols.GetCol()) == TRUE )
{
switch (m_egSolSols.GetCol())
{
case 0 :
strRes.LoadString(IDS_S_S_COL_0_207);
break;
case 1 :
strRes.LoadString(IDS_S_S_COL_1_208);
break;
case 2 :
strRes.LoadString(IDS_S_S_COL_2_209);
break;
default :
ASSERT(FALSE);
break;
}
}
m_eInputDesc.SetWindowText(strRes);
}
void CCKPSolid_SolutionsPg2::OnEnterCellMshfgSolSols()
{
CString strLoad;
CString strExcessFreeEnergy;
if ( m_egSolSols.GetCellEnabled(m_egSolSols.GetRow(), m_egSolSols.GetCol()) == TRUE )
{
switch (m_egSolSols.GetCol())
{
case 0 :
strLoad.LoadString(IDS_S_S_COL_0_207);
break;
case 1 :
if (m_egSolSols.GetRow() % 2 == 0)
{
AfxFormatString1(strLoad, IDS_S_S_COL_1A_210, _T("1"));
}