FOX/ObjCryst++  2022
wxScatteringPower.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/wxScatteringPower.h"
32 
33 //Fixes for Cygwin; where do those stupid macros come from ? Somewhere in wxMSW headers
34 #ifdef max
35 #undef max
36 #endif
37 #ifdef min
38 #undef min
39 #endif
40 #ifdef DrawText
41 #undef DrawText
42 #endif
43 
44 namespace ObjCryst
45 {
47 //
48 // WXScatteringPowerAtom
49 //
51 static const long ID_WXSCATTPOWATOM_SYMBOL =WXCRYST_ID();
52 static const long ID_SCATTPOWATOM_MENU_COLOUR =WXCRYST_ID();
53 static const long ID_SCATTPOWATOM_MENU_COLOUR_SETRGB=WXCRYST_ID();
54 
55 BEGIN_EVENT_TABLE(WXScatteringPowerAtom, wxWindow)
56  EVT_MENU(ID_SCATTPOWATOM_MENU_COLOUR_SETRGB, WXScatteringPowerAtom::OnChangeColour)
57  EVT_UPDATE_UI(ID_CRYST_UPDATEUI, WXRefinableObj::OnUpdateUI)
58 END_EVENT_TABLE()
59 
60 WXScatteringPowerAtom::WXScatteringPowerAtom(wxWindow* parent, ScatteringPowerAtom *obj):
61 WXRefinableObj(parent,(RefinableObj*)obj),mpScatteringPowerAtom(obj)
62 {
63  VFN_DEBUG_MESSAGE("WXScatteringPowerAtom::WXScatteringPowerAtom()",6)
64  mpWXTitle->SetForegroundColour(wxColour(0,200,0));
65  //Lattice
66  mpFieldSymbol=new WXFieldName
67  (this,"Symbol:",this,ID_WXSCATTPOWATOM_SYMBOL);
68 
69  mpTopSizer->Add(mpFieldSymbol ,0,wxALIGN_TOP);
70  mList.Add(mpFieldSymbol);
71  this->Layout();
72  this->BottomLayout(0);
73  this->CrystUpdate(true);
74 }
75 
76 bool WXScatteringPowerAtom::OnChangeName(const int id)
77 {
78  VFN_DEBUG_MESSAGE("WXScatteringPowerAtom::OnChangeName()",6)
79  if(this->WXRefinableObj::OnChangeName(id)==true) return true;
80  if(id==ID_WXSCATTPOWATOM_SYMBOL)
81  {
82  VFN_DEBUG_MESSAGE("WXScatteringPowerAtom::OnChangeName():Changing Symbol",6)
83  mpScatteringPowerAtom->Init(mpScatteringPowerAtom->GetName(),
84  mpFieldSymbol->GetValue(),
85  mpScatteringPowerAtom->GetBiso());
86  return true;
87  }
88  return false;
89 }
90 
91 void WXScatteringPowerAtom::OnChangeColour(wxCommandEvent & event)
92 {
93  VFN_DEBUG_ENTRY("WXScatteringPowerAtom::OnChangeColour()",6)
94  const float* oldColour=mpScatteringPowerAtom->GetColourRGB();
95  double r,g,b;
96  r=oldColour[0];
97  g=oldColour[1];
98  b=oldColour[2];
99  //red
100  {
101  wxString str;
102  str<<r;
103  wxTextEntryDialog dialog(this,_T("Red"),
104  _T("Enter Red component (0.<r<1.)"),str,wxOK | wxCANCEL);
105  dialog.SetTextValidator(wxTextValidator(wxFILTER_NUMERIC));
106  if(wxID_OK!=dialog.ShowModal())
107  {
108  VFN_DEBUG_EXIT("WXScatteringPowerAtom::OnChangeColour():Cancelled",6)
109  return;
110  }
111  dialog.GetValue().ToDouble(&r);
112  }
113  //green
114  {
115  wxString str;
116  str<<g;
117  wxTextEntryDialog dialog(this,_T("Green"),
118  _T("Enter Green component (0.<g<1.)"),str,wxOK | wxCANCEL);
119  dialog.SetTextValidator(wxTextValidator(wxFILTER_NUMERIC));
120  if(wxID_OK!=dialog.ShowModal())
121  {
122  VFN_DEBUG_EXIT("WXScatteringPowerAtom::OnChangeColour():Cancelled",6)
123  return;
124  }
125  dialog.GetValue().ToDouble(&g);
126  }
127  //Blue
128  {
129  wxString str;
130  str<<b;
131  wxTextEntryDialog dialog(this,_T("Blue"),
132  _T("Enter Blue component (0.<b<1.)"),str,wxOK | wxCANCEL);
133  dialog.SetTextValidator(wxTextValidator(wxFILTER_NUMERIC));
134  if(wxID_OK!=dialog.ShowModal())
135  {
136  VFN_DEBUG_EXIT("WXScatteringPowerAtom::OnChangeColour():Cancelled",6)
137  return;
138  }
139  dialog.GetValue().ToDouble(&b);
140  }
141  mpScatteringPowerAtom->SetColour(r,g,b);
142  VFN_DEBUG_EXIT("WXScatteringPowerAtom::OnChangeColour()",6)
143 }
144 void WXScatteringPowerAtom::UpdateUI(const bool lock)
145 {
146  VFN_DEBUG_ENTRY("WXScatteringPowerAtom::UpdateUI()",3)
147  if(lock) mMutex.Lock();
148  mpFieldSymbol->SetValue(mpScatteringPowerAtom->GetSymbol());
149  this->WXRefinableObj::UpdateUI(false);
150  if(lock) mMutex.Unlock();
151  VFN_DEBUG_EXIT("WXScatteringPowerAtom::UpdateUI()",3)
152 }
153 
154 }// namespace
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: doc-main.h:25
virtual const string & GetSymbol() const
Returns the symbol ('Ta', 'O2-',...) of the atom.
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 &)
This actually posts an UpdateUI event, so that it is safe to call it from a non-graphic thread.
Definition: wxCryst.cpp:472
virtual bool OnChangeName(const int id)
When a WXFieldName has been changed by the user, it is handled here.
virtual void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.
wxCryst class for ScatteringPowerAtom
virtual void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.