FOX/ObjCryst++  2022
wxCrystal.h
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000-2009 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 /*
20 * header file for the RefinablePar and RefinableObj classes
21 *
22 * This is still in early development stages !! Not secure !
23 *
24 */
25 
26 #ifndef _VFN_WX_CRYSTAL_H_
27 #define _VFN_WX_CRYSTAL_H_
28 
29 #include <list>
30 #include <boost/shared_ptr.hpp>
31 
32 #include "ObjCryst/wxCryst/wxRefinableObj.h"
33 
34 #include "wx/glcanvas.h"
35 #include "wx/grid.h"
36 #include "wx/clrpicker.h"
37 
38 #include "ObjCryst/ObjCryst/Crystal.h"
39 //#include "ObjCryst/ObjCryst/PDF.h"
40 
41 #include "ObjCryst/wxCryst/MC.h"
42 
43 namespace ObjCryst
44 {
45 typedef struct
46  {
47  float xMin;
48  float xMax;
49  float yMin;
50  float yMax;
51  float zMin;
52  float zMax;
53  }
54  BBox;
55 
56 typedef struct
57  {
58  float x;
59  float y;
60  float z;
61  }
62  Triple;
63 
64 class WXGLCrystalCanvas;
65 class WXCrystal;
66 
67 class WXCrystalScrolledGridWindow:public wxGrid
68 {
69  public:
70  WXCrystalScrolledGridWindow(wxWindow* parent, WXCrystal* pWXMol,long id=-1);
71  virtual ~WXCrystalScrolledGridWindow();
72  private:
76 };
77 
78 
81 {
82  public:
83  WXCrystal(wxWindow *parent, Crystal*);
84  ~WXCrystal();
85  virtual void CrystUpdate(const bool updateUI=false,const bool mutexlock=false);
86  #ifdef OBJCRYST_GL
88  void UpdateGL(const bool onlyIndependentAtoms=false,
89  const REAL xMin=-.1,const REAL xMax=1.1,
90  const REAL yMin=-.1,const REAL yMax=1.1,
91  const REAL zMin=-.1,const REAL zMax=1.1,
92  const REAL fadeDistance=0,
93  const bool fullMoleculeInLimits=false);
97  int GetCrystalGLDisplayList(const bool atomName=false)const;
99  void OnMenuCrystalGL(wxCommandEvent & WXUNUSED(event));
101  void NotifyCrystalGLDelete();
103  WXGLCrystalCanvas * GetCrystalGL();
104  #endif
105  void OnMenuSaveCIF(wxCommandEvent & WXUNUSED(event));
106  void OnMenuSaveText(wxCommandEvent & WXUNUSED(event));
107  void OnMenuAddScattPowAtom(wxCommandEvent & WXUNUSED(event));
108  void OnMenuAddScattPowSphere(wxCommandEvent & WXUNUSED(event));
109  void OnMenuRemoveScattPow(wxCommandEvent & WXUNUSED(event));
110  void OnMenuAddScatterer(wxCommandEvent & event);
111  void OnMenuAddIntermolecularDistRestr(wxCommandEvent & event);
112  void OnMenuRemoveIntermolecularDistRestr(wxCommandEvent & event);
113  void OnMenuRemoveScatterer(wxCommandEvent & WXUNUSED(event));
114  void OnMenuDuplicateScatterer(wxCommandEvent & WXUNUSED(event));
115  void OnMenuImportMoleculeFromFenskeHallZMatrix(wxCommandEvent &event);
116  void OnMenuAtoms2Molecule(wxCommandEvent &event);
117  void OnMenuSetRelativeXYZLimits(wxCommandEvent & WXUNUSED(event));
118  void OnMenuTestRandomMoves(wxCommandEvent &event);
119  bool OnChangeName(const int id);
120  void UpdateUI(const bool mutexlock=false);
121  Crystal& GetCrystal();
122  const Crystal& GetCrystal()const;
123  void OnMenuShowScattPowWindow(wxCommandEvent &event);
124  void OnMenuShowIntermoDistWindow(wxCommandEvent &event);
125  void OnEditGridIntermolDistWindow(wxGridEvent &e);
126  void OnEditGridScattPow(wxGridEvent &e);
127  void OnEditGridScattPowAntiBump(wxGridEvent &e);
128  void OnEditGridScattPowBondValence(wxGridEvent &e);
129  void NotifyDeleteListWin(WXCrystalScrolledGridWindow *win);
130  //void OnMenuPDF(wxCommandEvent &event);
131  virtual bool Enable(bool enable=true);
132  private:
133  Crystal* mpCrystal;
140 
142  struct RowScattPow
143  {
144  RowScattPow();
145  std::string mName;
147  REAL mBiso,mFormalCharge,mR,mG,mB,mMaximumLikelihoodError,mNbGhostAtoms;
149  std::vector<REAL> mvAntiBumpDistance;
151  std::vector<REAL> mvBondValenceRo;
155  int mIdx;
156  };
157 
158  WXCrystalScrolledGridWindow* mpScattPowWin;
159  WXCrystalScrolledGridWindow* mpAntiBumpWin;
160  WXCrystalScrolledGridWindow* mpBondValenceWin;
161  WXCrystalScrolledGridWindow* mpIntermolDistWin;
162 
163  std::map<ScatteringPowerAtom*,RowScattPow> mvpRowScattPow;
164 
168 
169  #ifdef OBJCRYST_GL
170  //OpenGl
172  unsigned int mCrystalGLDisplayList;
175  unsigned int mCrystalGLNameDisplayList;
177  WXGLCrystalCanvas* mpCrystalGL;
178  #endif
180  wxMutex mMutexGLUpdate;
182  wxCondition *mpConditionGLUpdate;
183 
185  //PDF *mpPDF;
186  DECLARE_EVENT_TABLE()
187 };
188 
189 #ifdef OBJCRYST_GL
192 class UnitCellMap
193 {
194  public:
199  UnitCellMap(const Crystal&crystal);
200  ~UnitCellMap();
204  void GLInitDisplayList(const float contourValue,
205  WXGLCrystalCanvas * parentCrystal) const;
207  void POVRayDescription(ostream &os,const float contourValue,
208  const CrystalPOVRayOptions &options)const;
213  int ImportGRD(const string&filename);
218  int ImportDSN6(const string&filename);
219  #ifdef HAVE_FFTW
226  int CalcFourierMap(const ScatteringData& data, unsigned int type=0, const bool normalized_sf=false);
227  #endif
229  const string & GetName()const;
231  REAL GetValue(const REAL x,const REAL y,const REAL z)const;
233  REAL Max()const;
235  REAL Min()const;
237  REAL Mean()const;
239  REAL StandardDeviation()const;
241  int GetType()const;
243  const Crystal &GetCrystal()const;
245  const ScatteringData *GetData()const;
246 
247  private:
249  const Crystal *mpCrystal;
251  const ScatteringData *mpData;
253  CrystArray3D_REAL mPoints;
255  string mName;
257  REAL mMin,mMax;
259  REAL mMean;
261  REAL mStandardDeviation;
263  int mType;
264 };
265 
268 struct UnitCellMapGLList
269 {
270  public:
271  UnitCellMapGLList(const UnitCellMap &ucmap,WXGLCrystalCanvas * parent,
272  const bool showWire=true,float contour=1.0,
273  const float r=1.0,const float g=0.0,const float b=0.0,const float t=0.5);
274  ~UnitCellMapGLList();
276  void GenList();
278  void SetName(const string &name);
280  const string &GetName()const;
282  void SetColour(const float r=1.0,const float g=0.0,const float b=0.0,
283  const float t=1.0);
285  const float* GetColour()const;
287  void ToggleShowWire();
289  bool ShowWire()const;
291  void Draw()const;
293  void SetShow(bool show);
295  bool Show()const;
297  void SetContour(float contour);
299  float GetContour()const;
301  const UnitCellMap & GetMap()const;
302  private:
304  unsigned int mGLDisplayList;
306  float mColour[4];
308  bool mShowWire;
310  string mName;
312  bool mShow;
314  float mContour;
316  const UnitCellMap *mpUCMap;
318  WXGLCrystalCanvas *mpParent;
319 };
320 
322 class WXGLCrystalCanvas : public wxGLCanvas
323 {
324  public:
325  WXGLCrystalCanvas(WXCrystal *wxcryst,
326  wxFrame *parent, wxWindowID id=-1,
327  const wxPoint &pos=wxDefaultPosition,
328  const wxSize &size=wxDefaultSize);
329  ~WXGLCrystalCanvas();
330  void OnExit(wxCommandEvent &event);
331  void OnPaint(wxPaintEvent &event);
332  //void OnSize(wxSizeEvent& event);
333  void OnEraseBackground(wxEraseEvent& event);
334  void OnKeyDown(wxKeyEvent& event);
335  void OnKeyUp(wxKeyEvent& event);
336  void OnEnterWindow( wxMouseEvent& event );
337  void OnMouse( wxMouseEvent& event );
339  void OnUpdate(wxCommandEvent & WXUNUSED(event));
341  void CrystUpdate();
342  void OnChangeLimits(wxCommandEvent &event);
344  void OnUpdateUI(wxUpdateUIEvent& WXUNUSED(event));
345  void OnShowCrystal(wxCommandEvent & WXUNUSED(event));
346  void OnShowAtomLabel(wxCommandEvent & WXUNUSED(event));
347  void OnShowHydrogens(wxCommandEvent & WXUNUSED(event));
349  bool GetShowHydrogens()const;
350  void OnShowCursor(wxCommandEvent & WXUNUSED(event));
351  void OnSetCursor(wxCommandEvent & WXUNUSED(event));
353  void OnShowHelp(wxCommandEvent & WXUNUSED(event));
355  void OnFourier(wxCommandEvent &event);
356 
357  void OnLoadFourierGRD(wxCommandEvent & WXUNUSED(event));
358  void OnLoadFourierDSN6(wxCommandEvent & WXUNUSED(event));
359  void AddFourier(UnitCellMap*);
360  void OnAddContour(wxCommandEvent & WXUNUSED(event));
361  void OnChangeContour(wxCommandEvent & WXUNUSED(event));
362  void OnShowFourier(wxCommandEvent & WXUNUSED(event));
363  void OnFourierChangeColour(wxColourPickerEvent & event);
364  void OnUnloadFourier(wxCommandEvent & WXUNUSED(event));
365  void OnShowWire(wxCommandEvent & WXUNUSED(event));
366  void OnFourierChangeBbox(wxCommandEvent & WXUNUSED(event));
368  void OnPOVRay(wxCommandEvent & WXUNUSED(event));
370  void POVRayOutput(const std::string &filename);
372  BBox GetCellBBox();
374  BBox GetMapBBox();
376  REAL GetFadeDistance();
377  virtual void SetCurrent();
378  void NotifyDeleteFourierWin();
379  private:
380  void InitGL();
383  int UserSelectUnitCellMapGLList()const;
386  int UserSelectUnitCellMap()const;
399  void UnProject(REAL &x, REAL &y, REAL &z);
401  void BuildGLFont();
403  void DeleteGLFont()const;
405  wxFrame* mpParentFrame;
407  WXCrystal* mpWXCrystal;
409  wxGLContext *mpwxGLContext;
411  bool mIsGLInit;
413  float mQuat [4];
415  float mTrackBallLastX,mTrackBallLastY;
417  float mDist;
418  REAL mX0, mY0,mZ0;
420  float mViewAngle;
422  wxMenu* mpPopUpMenu;
423 
425  bool mShowFourier, mShowCrystal, mShowAtomName, mShowHydrogens, mShowCursor, mSharpenMap, mShowHelp, mShowFullMolecule, mWhiteBackground;
427  BBox mcellbbox;
429  BBox mmapbbox;
431  Triple mViewCntr;
432 
438  vector<boost::shared_ptr<UnitCellMap> > mvpUnitCellMap;
442  vector<boost::shared_ptr<UnitCellMapGLList> > mvpUnitCellMapGLList;
443 
445  mutable bool mIsGLFontBuilt;
446  mutable int mGLFontDisplayListBase;
448  class WXFourierMapList:public wxWindow
449  {
450  public:
451  WXFourierMapList(WXGLCrystalCanvas *pGLCrystalCanvas,wxWindow *parent);
452  ~WXFourierMapList();
453  wxCheckBox *mpWireFrame;
454  wxCheckBox *mpShowFourier;
455  wxCheckBox *mpSharpenMap;
456  wxListBox *mpAvailableMapList;
457  wxListBox *mpDisplayedMapList;
458  wxStaticText *mpMapInfo;
459  wxTextCtrl *mpNewContourValue;
460  wxTextCtrl *mpContourValue;
461  wxColourPickerCtrl *mpColourPicker;
462  WXGLCrystalCanvas *mpGLCrystalCanvas;
463  wxMutex mMutex;
464  bool mIsUpdating;
465  };
466  WXFourierMapList *mpFourierMapListWin;
468  REAL mFadeDistance;
469  DECLARE_EVENT_TABLE()
470 };
471 #endif
472 
473 
474 } //namespace
475 
476 #endif //_VFN_WX_CRYSTAL_H_
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: doc-main.h:25
Crystal class: Unit cell, spacegroup, scatterers.
Definition: Crystal.h:98
Class to store POV-Ray output options.
Definition: General.h:178
Class to compute structure factors for a set of reflections and a Crystal.
A field with the name of a WXCrystObj.
Definition: wxCryst.h:372
WXCrystal * mpWXCrystal
The WXCrystal window which created this window, and who should be told if it is destroyed.
Definition: wxCrystal.h:75
wxCryst class for Crystals
Definition: wxCrystal.h:81
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...
Definition: wxCrystal.cpp:690
void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.
Definition: wxCrystal.cpp:1773
wxCondition * mpConditionGLUpdate
wxCondition used when updating the OpenGL display List, between background and main thread
Definition: wxCrystal.h:182
WXRegistry< ScatteringPower > * mpWXScatteringPowerRegistry
Scattering Powers.
Definition: wxCrystal.h:139
bool OnChangeName(const int id)
When a WXFieldName has been changed by the user, it is handled here.
Definition: wxCrystal.cpp:1751
bool mIsSelfUpdating
Flag to indicate that we are updating values in the wxGrid data, and that it is not the user inputing...
Definition: wxCrystal.h:167
WXRegistry< Scatterer > * mpWXScattererRegistry
Scatterers.
Definition: wxCrystal.h:137
wxMutex mMutexGLUpdate
Mutex used when updating the OpenGL display List, between background and main thread.
Definition: wxCrystal.h:180
WXFieldName * mpFieldSpacegroup
SpaceGroup.
Definition: wxCrystal.h:135
Structure to store the scattering power parameters.
Definition: wxCrystal.h:143
REAL mBiso
Last displayed values.
Definition: wxCrystal.h:147
int mIdx
Current position in the list of rows or columns.
Definition: wxCrystal.h:155
std::vector< REAL > mvAntiBumpDistance
Last displayed values for antibump.
Definition: wxCrystal.h:149
bool mNeedUpdateUI
True if we need to update the displayed values.
Definition: wxCrystal.h:153
std::vector< REAL > mvBondValenceRo
Last displayed values for bond valence.
Definition: wxCrystal.h:151
This displays all components of a ObjCryst++ Registry.
The base wxCryst class for all RefinableObj objects.