FOX/ObjCryst++  1.10.X (development)
wxDiffractionSingleCrystal.cpp
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000-2002 Vincent Favre-Nicolin vincefn@users.sourceforge.net
3  2000-2001 University of Geneva (Switzerland)
4 
5  This program 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 program 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 program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 //#include <sstream> //for stringstream
20 #include <fstream>
21 
22 // wx headers, with or without precompilation
23 #include "wx/wxprec.h"
24 #ifdef __BORLANDC__
25  #pragma hdrstop
26 #endif
27 #ifndef WX_PRECOMP
28  #include "wx/wx.h"
29 #endif
30 
31 #include "ObjCryst/wxCryst/wxDiffractionSingleCrystal.h"
32 #include "ObjCryst/wxCryst/wxRadiation.h"
33 
34 //Fixes for Cygwin; where do those stupid macros come from ? Somewhere in wxMSW headers
35 #ifdef max
36 #undef max
37 #endif
38 #ifdef min
39 #undef min
40 #endif
41 #ifdef DrawText
42 #undef DrawText
43 #endif
44 
45 namespace ObjCryst
46 {
48 //
49 // WXDiffractionSingleCrystalGraph
50 //
52 
55 class WXDiffractionSingleCrystalGraph:public WXMultiGraph
56 {
57  public:
58  WXDiffractionSingleCrystalGraph(wxFrame *frame,WXDiffractionSingleCrystal *parent):
59  WXMultiGraph(frame)
60  {
61  mpParent=parent;
62  }
63  virtual ~WXDiffractionSingleCrystalGraph()
64  {
65  mpParent->NotifyDeleteGraph();
66  }
67  private:
68  WXDiffractionSingleCrystal *mpParent;
69 };
71 //
72 // WXDiffractionSingleCrystal
73 //
75 static long ID_DIFFSINGLECRYST_MENU_SAVEHKLIOBSICALC= WXCRYST_ID();
76 static long ID_DIFFSINGLECRYST_MENU_SAVEHKLFCALC= WXCRYST_ID();
77 static long ID_DIFFSINGLECRYST_MENU_SIMULATE= WXCRYST_ID();
78 static long ID_DIFFSINGLECRYST_MENU_IMPORT_HKLIOBS= WXCRYST_ID();
79 static long ID_DIFFSINGLECRYST_MENU_IMPORT_HKLIOBSSIGMA= WXCRYST_ID();
80 static long ID_DIFFSINGLECRYST_MENU_IMPORT_SHELXHKLF4= WXCRYST_ID();
81 static long ID_DIFFSINGLECRYST_MENU_IMPORT_CIF= WXCRYST_ID();
82 static long ID_DIFFSINGLECRYST_MENU_IMPORT_JANAM91= WXCRYST_ID();
83 static long ID_DIFFSINGLECRYST_MENU_IMPORT_HKLIOBSGROUP= WXCRYST_ID();
84 static long ID_DIFFSINGLECRYST_MENU_FITSCALE_R= WXCRYST_ID();
85 static long ID_DIFFSINGLECRYST_MENU_FITSCALE_RW= WXCRYST_ID();
86 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH= WXCRYST_ID();
87 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_XRAY= WXCRYST_ID();
88 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_NEUTRON= WXCRYST_ID();
89 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_ELECTRON= WXCRYST_ID();
90 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET= WXCRYST_ID();
91 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_AG= WXCRYST_ID();
92 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_MO= WXCRYST_ID();
93 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CU= WXCRYST_ID();
94 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_FE= WXCRYST_ID();
95 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CO= WXCRYST_ID();
96 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CR= WXCRYST_ID();
97 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_AGA1= WXCRYST_ID();
98 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_MOA1= WXCRYST_ID();
99 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CUA1= WXCRYST_ID();
100 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_FEA1= WXCRYST_ID();
101 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_COA1= WXCRYST_ID();
102 static long ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CRA1= WXCRYST_ID();
103 static long ID_DIFFSINGLECRYST_CRYSTAL= WXCRYST_ID();
104 static long ID_DIFFSINGLECRYST_MENU_DATA= WXCRYST_ID();
105 static long ID_DIFFSINGLECRYST_MENU_DATA_GRAPH= WXCRYST_ID();
106 
107 BEGIN_EVENT_TABLE(WXDiffractionSingleCrystal, wxWindow)
108  EVT_BUTTON(ID_WXOBJ_COLLAPSE, WXCrystObj::OnToggleCollapse)
109  EVT_MENU(ID_REFOBJ_MENU_OBJ_SAVE, WXRefinableObj::OnMenuSave)
110  EVT_MENU(ID_REFOBJ_MENU_OBJ_LOAD, WXRefinableObj::OnMenuLoad)
111  EVT_MENU(ID_REFOBJ_MENU_PAR_FIXALL, WXRefinableObj::OnMenuFixAllPar)
112  EVT_MENU(ID_REFOBJ_MENU_PAR_UNFIXALL, WXRefinableObj::OnMenuUnFixAllPar)
113  EVT_MENU(ID_DIFFSINGLECRYST_MENU_SAVEHKLIOBSICALC, WXDiffractionSingleCrystal::OnMenuSaveHKLIobsIcalc)
114  EVT_MENU(ID_DIFFSINGLECRYST_MENU_SAVEHKLFCALC, WXDiffractionSingleCrystal::OnMenuSaveHKLFcalc)
115  EVT_MENU(ID_DIFFSINGLECRYST_MENU_SIMULATE, WXDiffractionSingleCrystal::OnMenuSimulate)
116  EVT_MENU(ID_DIFFSINGLECRYST_MENU_IMPORT_HKLIOBS, WXDiffractionSingleCrystal::OnMenuImport)
117  EVT_MENU(ID_DIFFSINGLECRYST_MENU_IMPORT_HKLIOBSSIGMA,WXDiffractionSingleCrystal::OnMenuImport)
118  EVT_MENU(ID_DIFFSINGLECRYST_MENU_IMPORT_SHELXHKLF4, WXDiffractionSingleCrystal::OnMenuImport)
119  EVT_MENU(ID_DIFFSINGLECRYST_MENU_IMPORT_CIF , WXDiffractionSingleCrystal::OnMenuImport)
120  EVT_MENU(ID_DIFFSINGLECRYST_MENU_IMPORT_JANAM91, WXDiffractionSingleCrystal::OnMenuImport)
121  EVT_MENU(ID_DIFFSINGLECRYST_MENU_IMPORT_HKLIOBSGROUP,WXDiffractionSingleCrystal::OnMenuImport)
122  EVT_BUTTON(ID_DIFFSINGLECRYST_CRYSTAL, WXDiffractionSingleCrystal::OnChangeCrystal)
123  //EVT_MENU(ID_DIFFSINGLECRYST_MENU_FITSCALE_R, WXDiffractionSingleCrystal::OnMenuFitScaleForR)
124  //EVT_MENU(ID_DIFFSINGLECRYST_MENU_FITSCALE_RW, WXDiffractionSingleCrystal::OnMenuFitScaleForRw)
125  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET, WXDiffractionSingleCrystal::OnMenuSetWavelength)
126  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_XRAY, WXDiffractionSingleCrystal::OnMenuSetWavelength)
127  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_NEUTRON, WXDiffractionSingleCrystal::OnMenuSetWavelength)
128  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_ELECTRON,WXDiffractionSingleCrystal::OnMenuSetWavelength)
129  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_AG, WXDiffractionSingleCrystal::OnMenuSetWavelength)
130  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_MO, WXDiffractionSingleCrystal::OnMenuSetWavelength)
131  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CU, WXDiffractionSingleCrystal::OnMenuSetWavelength)
132  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_FE, WXDiffractionSingleCrystal::OnMenuSetWavelength)
133  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CO, WXDiffractionSingleCrystal::OnMenuSetWavelength)
134  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CR, WXDiffractionSingleCrystal::OnMenuSetWavelength)
135  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_AGA1,WXDiffractionSingleCrystal::OnMenuSetWavelength)
136  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_MOA1,WXDiffractionSingleCrystal::OnMenuSetWavelength)
137  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CUA1,WXDiffractionSingleCrystal::OnMenuSetWavelength)
138  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_FEA1,WXDiffractionSingleCrystal::OnMenuSetWavelength)
139  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_COA1,WXDiffractionSingleCrystal::OnMenuSetWavelength)
140  EVT_MENU(ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CRA1,WXDiffractionSingleCrystal::OnMenuSetWavelength)
141  EVT_MENU(ID_DIFFSINGLECRYST_MENU_DATA_GRAPH, WXDiffractionSingleCrystal::OnMenuShowGraph)
142  EVT_UPDATE_UI(ID_CRYST_UPDATEUI, WXRefinableObj::OnUpdateUI)
143 END_EVENT_TABLE()
144 
145 WXDiffractionSingleCrystal::WXDiffractionSingleCrystal(wxWindow *parent,
146  DiffractionDataSingleCrystal* data):
147 WXRefinableObj(parent,data),mpData(data),mpGraph(0),mGrapIdObs(0),mGrapIdCalc(0)
148 {
149  VFN_DEBUG_MESSAGE("WXDiffractionSingleCrystal::WXDiffractionSingleCrystal()",6)
150  mpWXTitle->SetForegroundColour(wxColour(255,0,0));
151  mpWXTitle->SetSize(400,-1);
152  // Menu
153  mpMenuBar->AddMenu("File",ID_REFOBJ_MENU_OBJ);
154  //:TODO: reactivate & test those menus
155  //mpMenuBar->AddMenuItem(ID_REFOBJ_MENU_OBJ,ID_REFOBJ_MENU_OBJ_SAVE,"Save");
156  //mpMenuBar->AddMenuItem(ID_REFOBJ_MENU_OBJ,ID_REFOBJ_MENU_OBJ_LOAD,"Load");
157  mpMenuBar->AddMenuItem(ID_REFOBJ_MENU_OBJ,ID_DIFFSINGLECRYST_MENU_SAVEHKLIOBSICALC,
158  "Save HKL Iobs Icalc (text)");
159  mpMenuBar->AddMenuItem(ID_REFOBJ_MENU_OBJ,ID_DIFFSINGLECRYST_MENU_SAVEHKLFCALC,
160  "Save HKL Fcalc (text)");
161  mpMenuBar->GetMenu(ID_REFOBJ_MENU_OBJ).AppendSeparator();
162  mpMenuBar->AddMenuItem(ID_REFOBJ_MENU_OBJ,ID_DIFFSINGLECRYST_MENU_SIMULATE,
163  "Simulation mode (generate HKL list)");
164  mpMenuBar->GetMenu(ID_REFOBJ_MENU_OBJ).AppendSeparator();
165  mpMenuBar->AddMenuItem(ID_REFOBJ_MENU_OBJ,ID_DIFFSINGLECRYST_MENU_IMPORT_HKLIOBS,
166  "Import HKL Iobs");
167  mpMenuBar->AddMenuItem(ID_REFOBJ_MENU_OBJ,ID_DIFFSINGLECRYST_MENU_IMPORT_HKLIOBSSIGMA,
168  "Import HKL Iobs Sigma (space or tab-separated)");
169  mpMenuBar->AddMenuItem(ID_REFOBJ_MENU_OBJ,ID_DIFFSINGLECRYST_MENU_IMPORT_SHELXHKLF4,
170  "Import HKL Iobs Sigma (HKLF 4 Shelx format)");
171  mpMenuBar->AddMenuItem(ID_REFOBJ_MENU_OBJ,ID_DIFFSINGLECRYST_MENU_IMPORT_CIF,
172  "Import CIF single crystal data");
173  //mpMenuBar->AddMenuItem(ID_REFOBJ_MENU_OBJ,ID_DIFFSINGLECRYST_MENU_IMPORT_JANAM91,
174  // "Import Jana M91");
175  mpMenuBar->AddMenuItem(ID_REFOBJ_MENU_OBJ,ID_DIFFSINGLECRYST_MENU_IMPORT_HKLIOBSGROUP,
176  "Import Reflections with group intensity");
177 
178  mpMenuBar->AddMenu("Radiation",ID_DIFFSINGLECRYST_MENU_WAVELENGTH);
179  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
180  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_NEUTRON,
181  "Neutron");
182  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
183  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_XRAY,
184  "X-Ray");
185  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
186  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_ELECTRON,
187  "Electron");
188  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
189  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET,
190  "Monochromatic Wavelength");
191  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
192  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_AG,
193  "X-Ray Tube Ag Ka12");
194  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
195  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_AGA1,
196  "X-Ray Tube Ag Ka1");
197  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
198  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_MO,
199  "X-Ray Tube Mo Ka12");
200  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
201  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_MOA1,
202  "X-Ray Tube Mo Ka1");
203  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
204  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CU,
205  "X-Ray Tube Cu Ka12");
206  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
207  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CUA1,
208  "X-Ray Tube Cu Ka1");
209  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
210  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_FE,
211  "X-Ray Tube Fe Ka12");
212  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
213  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_FEA1,
214  "X-Ray Tube Fe Ka1");
215  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
216  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CO,
217  "X-Ray Tube Co Ka12");
218  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
219  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_COA1,
220  "X-Ray Tube Co Ka1");
221  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
222  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CR,
223  "X-Ray Tube Cr Ka12");
224  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_WAVELENGTH,
225  ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CRA1,
226  "X-Ray Tube Cr Ka1");
227  //mpMenuBar->AddMenu("Compute",ID_CRYSTAL_MENU_DISPLAY);
228  // mpMenuBar->AddMenuItem(ID_CRYSTAL_MENU_DISPLAY,ID_DIFFSINGLECRYST_MENU_FITSCALE_R,
229  // "Fit Scale for R");
230  // mpMenuBar->AddMenuItem(ID_CRYSTAL_MENU_DISPLAY,ID_DIFFSINGLECRYST_MENU_FITSCALE_RW,
231  // "Fit Scale for Rw");
232  mpMenuBar->AddMenu("Data",ID_DIFFSINGLECRYST_MENU_DATA);
233  mpMenuBar->AddMenuItem(ID_DIFFSINGLECRYST_MENU_DATA,ID_DIFFSINGLECRYST_MENU_DATA_GRAPH,
234  "Show Graph");
235  //mpSizer->SetItemMinSize(mpMenuBar,
236  // mpMenuBar->GetSize().GetWidth(),
237  // mpMenuBar->GetSize().GetHeight());
238  //Radiation
239  mpSizer->Add(mpData->mRadiation.WXCreate(this),0);
240  mList.Add(mpData->mRadiation.WXGet());
241  // Crystal
242  mpFieldCrystal=new WXFieldChoice(this,ID_DIFFSINGLECRYST_CRYSTAL,"Crystal:",300);
243  mpSizer->Add(mpFieldCrystal,0,wxALIGN_LEFT);
244  mList.Add(mpFieldCrystal);
245  // Max Sin(theta/Lambda)
246  WXFieldPar<REAL> *maxSiThOvLa=
247  new WXFieldPar<REAL>(this,"Max Sin(theta)/lambda:",-1,&(mpData->mMaxSinThetaOvLambda));
248  mpSizer->Add(maxSiThOvLa,0,wxALIGN_LEFT);
249  mList.Add(maxSiThOvLa);
250  // Statistics
251  wxBoxSizer* pStats=new wxBoxSizer(wxHORIZONTAL);
252 
253  WXFieldPar<REAL> *pWXFieldChi2=new WXFieldPar<REAL>(this,"Chi^2",-1,&mChi2,100);
254  pStats->Add(pWXFieldChi2 ,0,wxALIGN_CENTER);
255  mList.Add(pWXFieldChi2);
256 
257  WXFieldPar<REAL> *pWXFieldGof=new WXFieldPar<REAL>(this,"GoF",-1,&mGoF,70);
258  pStats->Add(pWXFieldGof ,0,wxALIGN_CENTER);
259  mList.Add(pWXFieldGof);
260 
261  WXFieldPar<REAL> *pWXFieldRwp=new WXFieldPar<REAL>(this,"Rwp",-1,&mRwp,70);
262  pStats->Add(pWXFieldRwp ,0,wxALIGN_CENTER);
263  mList.Add(pWXFieldRwp);
264 
265  WXFieldPar<REAL> *pWXFieldRp=new WXFieldPar<REAL>(this,"Rp",-1,&mRp,70);
266  pStats->Add(pWXFieldRp ,0,wxALIGN_CENTER);
267  mList.Add(pWXFieldRp);
268 
269  mpSizer->Add(pStats);
270 
271  this->CrystUpdate(true);
272  VFN_DEBUG_MESSAGE("WXDiffractionSingleCrystal::WXDiffractionSingleCrystal():End",6)
273 }
274 
275 void WXDiffractionSingleCrystal::CrystUpdate(const bool uui,const bool lock)
276 {
277  VFN_DEBUG_ENTRY("WXDiffractionSingleCrystal::CrystUpdate()",6)
278  if(lock) mMutex.Lock();
280 
281  mChi2=mpData->GetChi2();
282  if(0==mpData->GetIobs().numElements()) mGoF=0;
283  else mGoF=mpData->GetChi2()/mpData->GetIobs().numElements();
284  mRwp=mpData->GetRw();
285  mRp=mpData->GetR();
286  if(mpGraph!=0)
287  {
288  const CrystVector_REAL *mpCalc=&(mpData->GetIcalc());
289  const CrystVector_REAL *mpObs =&(mpData->GetIobs());
290  const CrystVector_REAL *mpSinThetaOverLambda=&(mpData->GetSinThetaOverLambda());
291  const unsigned long nb=mpCalc->numElements();
292  mX .resize(nb);
293  mIobs .resize(nb);
294  mIcalc.resize(nb);
295  for(unsigned long i=0;i<nb;i++)
296  {
297  mX[i]=(*mpSinThetaOverLambda)(i)*2;//1/d
298  mIobs[i] =(*mpObs)(i);
299  mIcalc[i]=(*mpCalc)(i);
300  }
301  }
302  if(lock) mMutex.Unlock();
303  this->WXRefinableObj::CrystUpdate(uui,lock);
304  VFN_DEBUG_EXIT("WXDiffractionSingleCrystal::CrystUpdate()",6)
305 }
306 
308 {
309  mpGraph=0;
310 }
311 
312 void WXDiffractionSingleCrystal::OnMenuSimulate(wxCommandEvent & WXUNUSED(event))
313 {
315  double theta;
316  {
317  wxTextEntryDialog dialog(this,_T("Theta Max"),
318  _T("Enter maximum Theta (degrees)"),_T("50"),wxOK | wxCANCEL);
319  if(wxID_OK!=dialog.ShowModal())
320  {
321  VFN_DEBUG_EXIT("WXDiffractionSingleCrystal::OnMenuSimulate():Cancelled",6)
322  return;
323  }
324  dialog.GetValue().ToDouble(&theta);
325  }
326  wxString choices[2];
327  choices[0]=_T("all reflections (keep Friedel&Bijvoet mates)");
328  choices[1]=_T("only unique reflections");
329  wxSingleChoiceDialog dialog(this,_T("Choose method"),
330  _T("Choose method for Reflection generation"),
331  2,choices,(void **)NULL,wxOK | wxCANCEL);
332  if(wxID_OK!=dialog.ShowModal()) return;
333  const int choice=dialog.GetSelection();
334  if(0==choice) mpData->GenHKLFullSpace(theta*DEG2RAD,false);
335  else mpData->GenHKLFullSpace(theta*DEG2RAD,true);
336 }
337 void WXDiffractionSingleCrystal::OnMenuImport(wxCommandEvent & event)
338 {
339  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_IMPORT_HKLIOBS)
340  {
341  wxFileDialog open(this,_T("Choose file to import from"),
342  _T(""),_T(""),_T("*.*"),wxFD_OPEN | wxFD_FILE_MUST_EXIST);
343  if(open.ShowModal() != wxID_OK) return;
344  long nb=0;
345  {
346  wxTextEntryDialog dialog(this,_T("Number of reflections"),
347  _T("Enter The number of reflections to import"),_T("50"),
348  wxOK | wxCANCEL);
349  if(wxID_OK!=dialog.ShowModal())
350  {
351  VFN_DEBUG_EXIT("WXDiffractionSingleCrystal))OnMenuImport())Cancelled",6)
352  return;
353  }
354  dialog.GetValue().ToLong(&nb);
355  }
356  mpData->ImportHklIobs(string(open.GetPath().ToAscii()),nb);
357  mpData->UpdateDisplay();
358  return;
359  }
360  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_IMPORT_HKLIOBSSIGMA)
361  {
362  wxFileDialog open(this,_T("Choose file to import from"),
363  _T(""),_T(""),_T("*.*"),wxFD_OPEN | wxFD_FILE_MUST_EXIST);
364  if(open.ShowModal() != wxID_OK) return;
365  long nb=0;
366  {
367  wxTextEntryDialog dialog(this,_T("Number of reflections"),
368  _T("Enter The number of reflections to import"),_T("50"),
369  wxOK | wxCANCEL);
370  if(wxID_OK!=dialog.ShowModal())
371  {
372  VFN_DEBUG_EXIT("WXDiffractionSingleCrystal))OnMenuImport())Cancelled",6)
373  return;
374  }
375  dialog.GetValue().ToLong(&nb);
376  }
377  mpData->ImportHklIobsSigma(string(open.GetPath().ToAscii()),nb);
378  mpData->UpdateDisplay();
379  return;
380  }
381  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_IMPORT_SHELXHKLF4)
382  {
383  wxFileDialog open(this,_T("Choose Shelx file to import from"),
384  _T(""),_T(""),_T("*.hkl"),wxFD_OPEN | wxFD_FILE_MUST_EXIST);
385  if(open.ShowModal() != wxID_OK) return;
386  mpData->ImportShelxHKLF4(string(open.GetPath().ToAscii()));
387  mpData->UpdateDisplay();
388  return;
389  }
390  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_IMPORT_CIF)
391  {
392  wxFileDialog open(this,_T("Choose CIF file to import from"),
393  _T(""),_T(""),_T("*.cif"),wxFD_OPEN | wxFD_FILE_MUST_EXIST);
394  if(open.ShowModal() != wxID_OK) return;
395  mpData->ImportCIF(string(open.GetPath().ToAscii()));
396  mpData->UpdateDisplay();
397  return;
398  }
399  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_IMPORT_HKLIOBSGROUP)
400  {
401  wxFileDialog open(this,_T("Choose data file"),
402  _T(""),_T(""),_T("*.*"),wxFD_OPEN | wxFD_FILE_MUST_EXIST);
403  if(open.ShowModal() != wxID_OK) return;
404  mpData->ImportHklIobsGroup(string(open.GetPath().ToAscii()));
405  mpData->UpdateDisplay();
406  return;
407  }
408  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_IMPORT_JANAM91)
409  {
410  wxFileDialog open(this,_T("Choose data file"),
411  _T(""),_T(""),_T("*.*"),wxFD_OPEN | wxFD_FILE_MUST_EXIST);
412  if(open.ShowModal() != wxID_OK) return;
413  mpData->ImportHklIobsSigmaJanaM91(string(open.GetPath().ToAscii()));
414  mpData->UpdateDisplay();
415  return;
416  }
417 }
418 void WXDiffractionSingleCrystal::OnMenuSaveHKLIobsIcalc(wxCommandEvent & WXUNUSED(event))
419 {
420  VFN_DEBUG_MESSAGE("WXDiffractionSingleCrystal::OnMenuSaveHKLIobsIcalc()",6)
422  wxFileDialog save(this,_T("Choose a file"),_T(""),_T(""),_T("*.txt"),wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
423  if(save.ShowModal() != wxID_OK) return;
424  mpData->SaveHKLIobsIcalc(string(save.GetPath().ToAscii()));
425 }
426 void WXDiffractionSingleCrystal::OnMenuSaveHKLFcalc(wxCommandEvent & WXUNUSED(event))
427 {
428  VFN_DEBUG_MESSAGE("WXDiffractionSingleCrystal::OnMenuSaveHKLFcalc()",6)
430  wxFileDialog save(this,_T("Choose a file"),_T(""),_T(""),_T("*.txt"),wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
431  if(save.ShowModal() != wxID_OK) return;
432  ofstream os(save.GetPath().ToAscii());
433  mpData->PrintFhklCalcDetail(os);
434  os.close();
435  mpData->GetCrystal().GetScatteringComponentList().Print();
436 }
437 void WXDiffractionSingleCrystal::OnMenuSetWavelength(wxCommandEvent &event)
438 {
440  //:TODO: Use wxRadiation instead
441  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_XRAY)
442  mpData->SetRadiationType(RAD_XRAY);
443  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_NEUTRON)
444  mpData->SetRadiationType(RAD_NEUTRON);
445  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_ELECTRON)
446  mpData->SetRadiationType(RAD_ELECTRON);
447  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET)
448  {
449  double lambda;
450  wxTextEntryDialog dialog(this,_T("new Wavelength)"),
451  _T("Enter new Wavelength (Angstroems)"),_T("1"),wxOK | wxCANCEL);
452  if(wxID_OK!=dialog.ShowModal())
453  {
454  VFN_DEBUG_EXIT("WXDiffractionSingleCrystal))OnMenuSetWavelength())Monochromatic)Cancelled",6)
455  return;
456  }
457  dialog.GetValue().ToDouble(&lambda);
458  mpData->SetWavelength(lambda);
459  }
460  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_AG)
461  mpData->SetWavelength("Ag");
462  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_MO)
463  mpData->SetWavelength("Mo");
464  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CU)
465  mpData->SetWavelength("Cu");
466  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_FE)
467  mpData->SetWavelength("Fe");
468  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CO)
469  mpData->SetWavelength("Co");
470  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CR)
471  mpData->SetWavelength("Cr");
472  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_AGA1)
473  mpData->SetWavelength("AgA1");
474  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_MOA1)
475  mpData->SetWavelength("MoA1");
476  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CUA1)
477  mpData->SetWavelength("CuA1");
478  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_FEA1)
479  mpData->SetWavelength("FeA1");
480  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_COA1)
481  mpData->SetWavelength("CoA1");
482  if(event.GetId()== ID_DIFFSINGLECRYST_MENU_WAVELENGTH_SET_CRA1)
483  mpData->SetWavelength("CrA1");
484  this->CrystUpdate(true,true);
485 }
486 
487 void WXDiffractionSingleCrystal::OnMenuShowGraph(wxCommandEvent &event)
488 {
489  VFN_DEBUG_MESSAGE("WXDiffractionSingleCrystal::OnMenuShowGraph()"<<mpGraph,6)
490  if(mpGraph!=0) return;
491  if(mpData->GetNbRefl()<=0) return;
493  std::string s=mpData->GetName();
494  if(s.size()==0) s=mpData->GetCrystal().GetName();
495  s="Single Crystal data:"+s;
496  wxFrame *frame= new wxFrame(this,-1,wxString::FromAscii(s.c_str()),
497  wxDefaultPosition,wxSize(500,300),wxCLOSE_BOX|wxRESIZE_BORDER|wxCAPTION);//wxFRAME_FLOAT_ON_PARENT
498  frame->CreateStatusBar(1);
499  mpGraph = new WXDiffractionSingleCrystalGraph(frame,this);
500  mpGraph->SetXLabel(_T("1/d (A)"));
501  mpGraph->SetYLabel(_T("Intensity"));
502  mGrapIdObs =mpGraph->AddGraph("Iobs");
503  mGrapIdCalc=mpGraph->AddGraph("Icalc");
504 
505  wxSizer *ps=new wxBoxSizer(wxHORIZONTAL);
506  ps->Add(mpGraph,1,wxEXPAND);
507  frame->SetSizer(ps);
508  frame->SetAutoLayout(true);
509 
510  //frame->CreateStatusBar(2);
511  frame->Show(true);
512  frame->Raise();
513  this->CrystUpdate(true);
514 }
515 
516 void WXDiffractionSingleCrystal::OnChangeCrystal(wxCommandEvent & WXUNUSED(event))
517 {
518  VFN_DEBUG_MESSAGE("WXDiffractionSingleCrystal::OnChangeCrystal()",6)
520  int choice;
521  Crystal *cryst=dynamic_cast<Crystal*>
523  "Choose a Crystal Structure:",choice));
524  if(0==cryst) return;
525  mpData->SetCrystal(*cryst);
526  this->CrystUpdate(true,true);
527 }
528 void WXDiffractionSingleCrystal::UpdateUI(const bool lock)
529 {
530  if(lock) mMutex.Lock();
531  if(mpData->HasCrystal()) mpFieldCrystal->SetValue(mpData->GetCrystal().GetName());
532  if(mpGraph!=0)
533  {
534  mpGraph->SetGraphData(mGrapIdObs,mX,mIobs);
535  mpGraph->SetGraphData(mGrapIdCalc,mX,mIcalc);
536  mpGraph->UpdateDisplay();
537  }
538  this->WXRefinableObj::UpdateUI(false);
539  if(lock) mMutex.Unlock();
540 }
541 
542 }//namespace
T * WXDialogChooseFromRegistry(ObjRegistry< T > &reg, wxWindow *parent, const string &message, int &choice)
This function allows to pick up one object in a registry.
virtual void UpdateDisplay() const
If there is an interface, this should be automatically be called each time there is a 'new...
void ImportHklIobsSigmaJanaM91(const string &fileName)
Import h,k,l,I,Sigma from a Jana98 '*.m91' file.
valarray< float > mIobs
Copy of the data for graph display.
void WXCrystValidateAllUserInput()
This function validates all user input (in a WXField) not yet taken into account, if needs be...
Definition: wxCryst.cpp:257
CrystMutex mMutex
Mutex used to lock data when preparing to update the UI in non-main thread.
Definition: wxCryst.h:189
void SetValue(const string &)
Used by the owner to change the name of the choice.
Definition: wxCryst.cpp:759
bool HasCrystal() const
Has a Crystal structure associated yet ?
ObjRegistry< Crystal > gCrystalRegistry("List of all Crystals")
Global registry for all Crystal objects.
Definition: Crystal.h:525
virtual void SetRadiationType(const RadiationType radiation)
Set : neutron or x-ray experiment ? Wavelength ?
virtual void CrystUpdate(const bool updateUI=false, const bool mutexlock=false)
Get new values to be displayed from the underlying object, and raise flag if an UI update is necessar...
void NotifyDeleteGraph()
For the mpGraph to tell its owner it was deleted.
virtual void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.
const Crystal & GetCrystal() const
Const access to the data's crystal.
WX Class for DiffractionDataSingleCrystal objects.
void ImportShelxHKLF4(const string &fileName)
Import h,k,l,I,Sigma from a file using shelx HKLF 4 format.
void ImportHklIobsGroup(const string &fileName, const unsigned int skipLines=0)
Import h,k,l and grouped intensities from a file.
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: Atom.cpp:47
virtual const string & GetName() const
Name of the object.
virtual void CrystUpdate(const bool updateUI=false, const bool mutexlock=false)
Get new values to be displayed from the underlying object, and raise flag if an UI update is necessar...
void ImportCIF(const string &fileName)
Import diffraction data from a CIF file.
virtual void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.