1 // AC_STOR_WCL.CPP
2
3 // Copyright (C) 2006 Tommi Hassinen.
4
5 // This package is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9
10 // This package is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14
15 // You should have received a copy of the GNU General Public License
16 // along with this package; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 /*################################################################################################*/
20
21 #include "ac_stor_wcl.h"
22
23 #include "project.h"
24 #include "custom_app.h"
25
26 /*################################################################################################*/
27
ac_stor_wcl(ogl_camera * cam)28 ac_stor_wcl::ac_stor_wcl(ogl_camera * cam) :
29 pangofont_wcl(cam)
30 {
31 }
32
~ac_stor_wcl(void)33 ac_stor_wcl::~ac_stor_wcl(void)
34 {
35 for (int i = 0;i < (int) acv.size();i++)
36 {
37 if (acv[i] != NULL)
38 {
39 delete[] acv[i];
40 acv[i] = NULL;
41 }
42 }
43 }
44
StoreAC(engine * eng)45 int ac_stor_wcl::StoreAC(engine * eng)
46 {
47 if (eng == NULL) return NOT_DEFINED;
48
49 if (!acv.size()) // is this the 1st set???
50 {
51 if (av.size() != 0)
52 {
53 assertion_failed(__FILE__, __LINE__, "av is not empty.");
54 }
55
56 atom ** atmtab = eng->GetSetup()->GetAtoms();
57 for (int i = 0;i < eng->GetSetup()->GetAtomCount();i++)
58 {
59 av.push_back(atmtab[i]);
60 }
61 }
62 else
63 {
64 if (av.size() != eng->GetSetup()->GetAtomCount())
65 {
66 assertion_failed(__FILE__, __LINE__, "av.size() is bad.");
67 }
68 }
69
70 float * newXYZ = new float[av.size() * 3];
71
72 // store the atom coordinates for later viewing...
73 // just assume that the atoms are not re-ordered.
74 // the number of atoms is stored and checked.
75
76 for (int i = 0;i < (int) av.size() * 3;i++)
77 {
78 newXYZ[i] = eng->ReadCRD(i);
79 }
80
81 int retval = (int) acv.size();
82 acv.push_back(newXYZ);
83
84 return retval;
85 }
86
StoreAC(model * mdl,int cset)87 int ac_stor_wcl::StoreAC(model * mdl, int cset)
88 {
89 if (mdl == NULL) return NOT_DEFINED;
90
91 if (!acv.size()) // is this the 1st set???
92 {
93 if (av.size() != 0)
94 {
95 assertion_failed(__FILE__, __LINE__, "av is not empty.");
96 }
97
98 atom ** atmtab = mdl->GetCurrentSetup()->GetAtoms();
99 for (int i = 0;i < mdl->GetCurrentSetup()->GetAtomCount();i++)
100 {
101 av.push_back(atmtab[i]);
102 }
103 }
104 else
105 {
106 if (av.size() != mdl->GetCurrentSetup()->GetAtomCount())
107 {
108 assertion_failed(__FILE__, __LINE__, "av.size() is bad.");
109 }
110 }
111
112 float * newXYZ = new float[av.size() * 3];
113
114 // store the atom coordinates for later viewing...
115 // just assume that the atoms are not re-ordered.
116 // the number of atoms is stored and checked.
117
118 for (int i = 0;i < (int) av.size();i++)
119 {
120 const fGL * xyz = av[i]->GetCRD(cset);
121
122 newXYZ[i * 3 + 0] = xyz[0];
123 newXYZ[i * 3 + 1] = xyz[1];
124 newXYZ[i * 3 + 2] = xyz[2];
125 }
126
127 int retval = (int) acv.size();
128 acv.push_back(newXYZ);
129
130 return retval;
131 }
132
ShowAC(int index)133 void ac_stor_wcl::ShowAC(int index)
134 {
135 if (index < 0 || index >= (int) acv.size()) return;
136
137 project * prj = custom_app::GetAppC()->GetPrj();
138
139 if (acv[index] != NULL && av.size() == prj->GetCurrentSetup()->GetAtomCount())
140 {
141 for (int i = 0;i < (int) av.size();i++)
142 {
143 const float x = acv[index][i * 3 + 0];
144 const float y = acv[index][i * 3 + 1];
145 const float z = acv[index][i * 3 + 2];
146
147 const int cset = 0; // ???
148
149 av[i]->SetCRD(cset, x, y, z);
150 }
151
152 prj->UpdateAllGraphicsViews();
153
154 // also make sure that if user calculates any results, the new structure will be used!
155 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
156
157 prj->GetCurrentSetup()->DiscardCurrentEngine();
158 }
159 }
160
161 /*################################################################################################*/
162
163 // eof
164