FOX/ObjCryst++  1.10.X (development)
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  if(wxID_OK!=dialog.ShowModal())
106  {
107  VFN_DEBUG_EXIT("WXScatteringPowerAtom::OnChangeColour():Cancelled",6)
108  return;
109  }
110  dialog.GetValue().ToDouble(&r);
111  }
112  //green
113  {
114  wxString str;
115  str<<g;
116  wxTextEntryDialog dialog(this,_T("Green"),
117  _T("Enter Green component (0.<g<1.)"),str,wxOK | wxCANCEL);
118  if(wxID_OK!=dialog.ShowModal())
119  {
120  VFN_DEBUG_EXIT("WXScatteringPowerAtom::OnChangeColour():Cancelled",6)
121  return;
122  }
123  dialog.GetValue().ToDouble(&g);
124  }
125  //Blue
126  {
127  wxString str;
128  str<<b;
129  wxTextEntryDialog dialog(this,_T("Blue"),
130  _T("Enter Blue component (0.<b<1.)"),str,wxOK | wxCANCEL);
131  if(wxID_OK!=dialog.ShowModal())
132  {
133  VFN_DEBUG_EXIT("WXScatteringPowerAtom::OnChangeColour():Cancelled",6)
134  return;
135  }
136  dialog.GetValue().ToDouble(&b);
137  }
138  mpScatteringPowerAtom->SetColour(r,g,b);
139  VFN_DEBUG_EXIT("WXScatteringPowerAtom::OnChangeColour()",6)
140 }
141 void WXScatteringPowerAtom::UpdateUI(const bool lock)
142 {
143  VFN_DEBUG_ENTRY("WXScatteringPowerAtom::UpdateUI()",3)
144  if(lock) mMutex.Lock();
145  mpFieldSymbol->SetValue(mpScatteringPowerAtom->GetSymbol());
146  this->WXRefinableObj::UpdateUI(false);
147  if(lock) mMutex.Unlock();
148  VFN_DEBUG_EXIT("WXScatteringPowerAtom::UpdateUI()",3)
149 }
150 
151 }// namespace
152 
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:467
CrystMutex mMutex
Mutex used to lock data when preparing to update the UI in non-main thread.
Definition: wxCryst.h:189
virtual void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.
virtual const string & GetSymbol() const
Returns the symbol ('Ta', 'O2-',...) of the atom.
virtual void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.
wxCryst class for ScatteringPowerAtom
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: Atom.cpp:47
virtual bool OnChangeName(const int id)
When a WXFieldName has been changed by the user, it is handled here.