-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCKSReaction.cpp
156 lines (134 loc) · 3.35 KB
/
CKSReaction.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
// CKSReaction.cpp : implementation file
//
// $Id$
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "CKSReaction.h"
#include "Util.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCKSReaction
IMPLEMENT_DYNAMIC(CCKSReaction, baseCKSReaction)
CCKSReaction::CCKSReaction(CWnd* pWndParent)
: baseCKSReaction(IDS_PROPSHT_CAPTION8, pWndParent)
{
// Add all of the property pages here. Note that
// the order that they appear in here will be
// the order they appear in on screen. By default,
// the first page of the set is the active one.
// One way to make a different property page the
// active one is to call SetActivePage().
AddPage(&m_Page1);
AddPage(&m_Page2);
}
CCKSReaction::~CCKSReaction()
{
}
BEGIN_MESSAGE_MAP(CCKSReaction, baseCKSReaction)
//{{AFX_MSG_MAP(CCKSReaction)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCKSReaction message handlers
CString CCKSReaction::GetString()
{
/*
Line 0: REACTION 5 Add sodium chloride and calcite to solution.
Line 1a: NaCl 2.0
Line 1b: Calcite 0.001
Line 2: 0.25 0.5 0.75 1.0 moles
*/
CString strLines;
CString strFormat;
// Line 0
strLines = GetLineZero(CKeyword::K_REACTION);
// Line 1
std::list<CNameCoef>::const_iterator const_iter = m_Page1.m_listNameCoef.begin();
for ( ; const_iter != m_Page1.m_listNameCoef.end(); ++const_iter)
{
strFormat.Format(_T("%s%4c%-10s %g"),
(LPCTSTR)s_strNewLine,
_T(' '),
(LPCTSTR)(*const_iter).m_strName,
(*const_iter).m_dCoef
);
strFormat.TrimRight();
strLines += strFormat;
}
// Line 2
CString strUnits;
switch (m_Page2.m_nUnits)
{
case CCKPReactionPg2::UNITS_MICROMOLES :
strUnits = _T("micromoles");
break;
case CCKPReactionPg2::UNITS_MILLIMOLES :
strUnits = _T("millimoles");
break;
case CCKPReactionPg2::UNITS_MOLES :
strUnits = _T("moles");
break;
}
if (m_Page2.m_nType == CCKPReactionPg2::TYPE_LINEAR)
{
strFormat.Format(_T("%s%4c%.*g %s in %d steps"),
(LPCTSTR)s_strNewLine,
_T(' '),
DBL_DIG,
m_Page2.m_dLinearAmt,
(LPCTSTR)strUnits,
m_Page2.m_nLinearSteps
);
strFormat.TrimRight();
strLines += strFormat;
}
else
{
ASSERT(m_Page2.m_nType == CCKPReactionPg2::TYPE_LIST);
CString strNum;
std::list<double>::const_iterator iter = m_Page2.m_listSteps.begin();
strFormat.Format(_T("%s%4c"),
(LPCTSTR)s_strNewLine,
_T(' ')
);
for (int i = 1; iter != m_Page2.m_listSteps.end(); ++iter, ++i)
{
if (i % 8 == 0)
{
strLines += strFormat;
strFormat.Format(_T("%s%4c"),
(LPCTSTR)s_strNewLine,
_T(' ')
);
}
strNum.Format(_T("%.*g "),
DBL_DIG,
(*iter)
);
strFormat += strNum;
}
strFormat.TrimRight();
strFormat += CString(_T(" ")) + strUnits;
strLines += strFormat;
}
return strLines + s_strNewLine;
}
void CCKSReaction::Edit(CString& rStr)
{
try
{
PhreeqcI p(rStr);
p.GetData(this);
}
catch (...)
{
CString strResource;
strResource.LoadString(IDS_EXCEPTION_ACCESS_VIOLATION);
::MessageBox(NULL, strResource, _T("Unhandled Exception"), MB_OK|MB_ICONERROR);
}
}