This repository was archived by the owner on Jun 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtomTypesDialog.cpp
More file actions
181 lines (146 loc) · 5.61 KB
/
Copy pathAtomTypesDialog.cpp
File metadata and controls
181 lines (146 loc) · 5.61 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
// AtomTypesDialog.cpp : implementation file
//
#include "stdafx.h"
#include "LatticeRelaxation.h"
#include "AtomTypesDialog.h"
#include <fstream>
#include "RelaxPtPotentialBuilder.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// AtomTypesDialog dialog
AtomTypesDialog::AtomTypesDialog(CWnd* pParent /*=NULL*/)
: CDialog(AtomTypesDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(AtomTypesDialog)
m_elementName = _T("");
m_atomMass = 0.0;
//}}AFX_DATA_INIT
}
void AtomTypesDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(AtomTypesDialog)
DDX_Control(pDX, IDC_ATOMTYPE_COLOR_STATIC, m_atomTypeColorStatic);
DDX_Control(pDX, IDC_EDIT2, m_atomMassControl);
DDX_Control(pDX, IDC_EDIT1, m_elementNameControl);
DDX_Control(pDX, IDC_LIST1, m_atomTypesListBox);
DDX_Text(pDX, IDC_EDIT1, m_elementName);
DDV_MaxChars(pDX, m_elementName, 2);
DDX_Text(pDX, IDC_EDIT2, m_atomMass);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(AtomTypesDialog, CDialog)
//{{AFX_MSG_MAP(AtomTypesDialog)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
ON_EN_CHANGE(IDC_EDIT2, OnChangeAtomMass)
ON_EN_CHANGE(IDC_EDIT1, OnChangeElementName)
ON_BN_CLICKED(IDC_ADD_ATOM_TYPE_BUTTON, OnAddAtomTypeButton)
ON_BN_CLICKED(IDC_CHANGE_ATOM_TYPE_COLOR_BUTTON, OnChangeAtomTypeColorButton)
ON_BN_CLICKED(IDC_EMBEDDING_ENERGY_BUTTON, OnEmbeddingEnergyButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// AtomTypesDialog message handlers
BOOL AtomTypesDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
std::set<AtomType*>::iterator atomTypesIterator;
for (atomTypesIterator = atomTypes.begin(); atomTypesIterator != atomTypes.end(); atomTypesIterator++) {
AtomType* atomType = *atomTypesIterator;
m_atomTypesListBox.AddString(atomType->name);
m_atomTypesListBox.SetItemDataPtr(m_atomTypesListBox.GetCount() - 1, atomType);
}
if (m_atomTypesListBox.GetCount()) {
m_atomTypesListBox.SetCurSel(0);
m_atomMassControl.EnableWindow();
//m_elementNameControl.EnableWindow();
OnSelchangeList1();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void AtomTypesDialog::OnSelchangeList1()
{
// TODO: Add your control notification handler code here
int selectedItem = m_atomTypesListBox.GetCurSel();
AtomType* atomType = (AtomType*)m_atomTypesListBox.GetItemDataPtr(selectedItem);
CString elementName;
m_atomTypesListBox.GetText(selectedItem, elementName);
m_atomMass = atomType->mass;
m_elementName = elementName;
m_atomTypeColorStatic.m_ctrlText = atomType->color;
m_atomTypeColorStatic.RedrawWindow();
//DoDataExchange(new CDataExchange(this,false));
UpdateData(FALSE);
}
void AtomTypesDialog::OnChangeAtomMass()
{
DoDataExchange(new CDataExchange(this,true));
int selectedItem = m_atomTypesListBox.GetCurSel();
//double atomMass = m_atomMass;
AtomType* atomType = (AtomType*)m_atomTypesListBox.GetItemDataPtr(selectedItem);
atomType->mass = m_atomMass;
}
void AtomTypesDialog::OnChangeElementName()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
DoDataExchange(new CDataExchange(this,true));
int selectedItem = m_atomTypesListBox.GetCurSel();
AtomType* atomType = (AtomType*)m_atomTypesListBox.GetItemDataPtr(selectedItem);
const char* newElementName = (LPCTSTR) m_elementName;
strcpy(atomType->name, newElementName);
m_atomTypesListBox.ResetContent();
std::set<AtomType*>::iterator atomTypesIterator;
for (atomTypesIterator = atomTypes.begin(); atomTypesIterator != atomTypes.end(); atomTypesIterator++) {
AtomType* atomType = *atomTypesIterator;
m_atomTypesListBox.AddString(atomType->name);
m_atomTypesListBox.SetItemDataPtr(m_atomTypesListBox.GetCount() - 1, atomType);
}
m_atomTypesListBox.SetCurSel(selectedItem);
OnSelchangeList1();
}
void AtomTypesDialog::OnAddAtomTypeButton()
{
// TODO: Add your control notification handler code here
AtomType* newAtomType = new AtomType("",0);
atomTypes.insert(newAtomType);
int before = m_atomTypesListBox.GetCount();
m_atomTypesListBox.AddString(newAtomType->name);
int after = m_atomTypesListBox.GetCount();
m_atomTypesListBox.SetItemDataPtr(after - 1, newAtomType);
m_atomTypesListBox.SetCurSel(after - 1);
OnSelchangeList1();
}
void AtomTypesDialog::OnChangeAtomTypeColorButton()
{
// TODO: Add your control notification handler code here
CColorDialog colorDialog;
if (IDOK == colorDialog.DoModal()) {
m_atomTypeColorStatic.m_ctrlText = colorDialog.GetColor();
m_atomTypeColorStatic.RedrawWindow();
int selectedItem = m_atomTypesListBox.GetCurSel();
AtomType* atomType = (AtomType*)m_atomTypesListBox.GetItemDataPtr(selectedItem);
atomType->color = colorDialog.GetColor();
}
}
void AtomTypesDialog::OnEmbeddingEnergyButton()
{
RelaxPtPotentialBuilder potBuilder(2.86);
CFileDialog fileDialog(TRUE);
fileDialog.DoModal();
LPSTR fileName = fileDialog.m_ofn.lpstrFile;
std::ifstream potfile(fileName,std::ios::in);
TableSetFunction* embeddingEnergy = potBuilder.loadTableSetFunction(&potfile);
int selectedItem = m_atomTypesListBox.GetCurSel();
AtomType* atomType = (AtomType*)m_atomTypesListBox.GetItemDataPtr(selectedItem);
atomType->embeddingEnergy = *embeddingEnergy;
}