SDC C-Project CF Review 프로그램
LYW
2021-07-01 4acd943c6f0beecd3ee573f77d8d6c7524fd5045
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
#pragma once
#include <vector>
 
enum    ResultType        { ResultConstant = 0, ResultCenter, ResultFirst, ResultSecond, ResultLength, ResultAngle, ResultTypeCount };
enum    OperatorType    { OperatorNone = 0, OperatorPlus, OperatorMinus, OperatorMulti, OperatorDiv, OperatorTypeCount };
 
class AFX_EXT_CLASS CFormulaItem
{
public:
 
    CFormulaItem()    { Reset(); }
 
    void Reset()
    {
        nType        = ResultConstant;
        nOperator    = OperatorNone;
        dValue        = 0.0;
        nIndex        = -1;
    }
 
    int                nType;
    int                nOperator;
    double            dValue;
    int                nIndex;
};
typedef std::vector<CFormulaItem>                VectorFormulaItem;
typedef std::vector<CFormulaItem>::iterator        VectorFormulaItemIt;
 
class AFX_EXT_CLASS CRecipeFormula
{
public:
    CRecipeFormula(void);
    ~CRecipeFormula(void);
    void Reset()
    {
        m_strResultName = _T("");
        m_strFormulation = _T("");
        m_vectorFormulaItem.clear();
    }
 
    int        GetItemCount() const;
    void     SetItemCount(int nCount);
    const CFormulaItem* GetItem(int nIndex) const;
    void    SetItem(int nIndex, const CFormulaItem& formulaItem);
    void    AddItem(const CFormulaItem& formulaItem);
 
    double    CalculateFormula() const ;
 
    static BOOL GetRecipeFormula(const CString& strString, CRecipeFormula& recipeFormula);
    static CString SetFormulaString(const CRecipeFormula& formula);
 
    CString m_strResultName;
    CString m_strFormulation;
 
protected:
    VectorFormulaItem    m_vectorFormulaItem;
};
typedef std::vector<CRecipeFormula>                VectorRecipeFormula;
typedef std::vector<CRecipeFormula>::iterator    VectorRecipeFormulaIt;
 
class AFX_EXT_CLASS CResultFormula
{
public:
    CResultFormula(void);
    ~CResultFormula(void);
    void Reset()
    {
        m_nResultCode    = 0;
        m_strResultName = _T("");
        m_dResultValue    = 0.0;
    }
 
    int            m_nResultCode;
    CString        m_strResultName;
    double        m_dResultValue;
};
typedef std::vector<CResultFormula>                VectorResultFormula;
typedef std::vector<CResultFormula>::iterator    VectorResultFormulaIt;
 
static void SetFormulaString(const CRecipeFormula& formula, CString& strString)
{
    strString = _T("");
 
    CString strTemp = _T("");
 
    for (UINT i=0; i<(UINT)formula.GetItemCount(); i++)
    {
        const CFormulaItem* pItem = formula.GetItem(i);
 
        if (pItem==NULL) continue;
 
        if (pItem->nIndex>=0 && pItem->nType!=ResultConstant)
        {
            strTemp.Format(_T("[%c%d"), '%', pItem->nIndex);
            strString += strTemp;
        }
        else
        {
            strTemp.Format(_T("["));
            strString += strTemp;
        }
 
        switch(pItem->nType)
        {
        case ResultConstant:
            strTemp.Format(_T("%.3lf]"), pItem->dValue);
            break;
 
        case ResultCenter:
            strTemp.Format(_T("_C]"));
            break;
 
        case ResultFirst:
            strTemp.Format(_T("_F]"));
            break;
 
        case ResultSecond:
            strTemp.Format(_T("_S]"));
            break;
 
        case ResultLength:
            strTemp.Format(_T("_L]"));
            break;
 
        case ResultAngle:
            strTemp.Format(_T("_A]"));
            break;
        }
        strString += strTemp;
 
        switch(pItem->nOperator)
        {
        case OperatorNone:
            strTemp = _T("");
            break;
 
        case OperatorPlus:
            strTemp = _T("+");
            break;
 
        case OperatorMinus:
            strTemp = _T("-");
            break;
 
        case OperatorMulti:
            strTemp = _T("*");
            break;
 
        case OperatorDiv:
            strTemp = _T("/");
            break;
        }
        strString += strTemp;
    }
}
 
static BOOL GetFormulaString(const CString& strString, CRecipeFormula& recipeFomula)
{
    recipeFomula.Reset();
 
    int nFirst = 0; 
    int nSecond = 0;
 
    BOOL bReturn = FALSE;
 
//    VectorFormulaItem vectorItem;
 
    while(TRUE)
    {
        nFirst = strString.Find(_T('['), nSecond);
 
        if (nFirst<0) break;
 
        nSecond = strString.Find(_T(']'), nFirst+1);
 
        if (nSecond<0) break;
 
        CString strValue = strString.Mid(nFirst+1, nSecond-nFirst-1);
 
        CFormulaItem item;
        item.nOperator = OperatorNone;
 
        if (nSecond+1 < strString.GetLength())
        {
            TCHAR operation = strString.GetAt(nSecond+1);
 
            switch(operation)
            {
            case _T('+'):
                item.nOperator = OperatorPlus;
                break;
            case _T('-'):
                item.nOperator = OperatorMinus;
                break;
            case _T('*'):
                item.nOperator = OperatorMulti;
                break;
            case _T('/'):
                item.nOperator = OperatorDiv;
                break;
            }
        }
 
        // formula
        int nPos1 = strValue.Find(_T('_'));
        if (nPos1<0)
        {
            item.nType    = ResultConstant;
            item.dValue    = _tcstod(strValue, NULL);
        }
        else
        {
            // operation
            CString strType = strValue.Mid(nPos1+1, strValue.GetLength()-nPos1);
 
            if (strType.CompareNoCase(_T("C"))==0)
            {
                item.nType = ResultCenter;
            }
            if (strType.CompareNoCase(_T("F"))==0)
            {
                item.nType = ResultFirst;
            }
            if (strType.CompareNoCase(_T("S"))==0)
            {
                item.nType = ResultSecond;
            }
            if (strType.CompareNoCase(_T("L"))==0)
            {
                item.nType = ResultLength;
            }
            if (strType.CompareNoCase(_T("A"))==0)
            {
                item.nType = ResultAngle;    
            }
            else
            {
                bReturn = FALSE;
            }
 
            // index
            int nPos2 = strValue.Find(_T('%'));
            if (nPos2<0)
            {
                bReturn = FALSE;
            }
            else
            {
                CString strTemp = strValue.Mid(nPos2+1, nPos1-nPos2-1);
                item.nIndex = _ttoi(strTemp);
            }
        }
 
        recipeFomula.AddItem(item);
 
        bReturn = TRUE;
    }
 
    return bReturn;
 
}