FOX/ObjCryst++  1.10.X (development)
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
87  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);
95  int GetCrystalGLDisplayList(const bool atomName=false)const;
97  void OnMenuCrystalGL(wxCommandEvent & WXUNUSED(event));
99  void NotifyCrystalGLDelete();
101  WXGLCrystalCanvas * GetCrystalGL();
102  #endif
103  void OnMenuSaveCIF(wxCommandEvent & WXUNUSED(event));
104  void OnMenuSaveText(wxCommandEvent & WXUNUSED(event));
105  void OnMenuAddScattPowAtom(wxCommandEvent & WXUNUSED(event));
106  void OnMenuAddScattPowSphere(wxCommandEvent & WXUNUSED(event));
107  void OnMenuRemoveScattPow(wxCommandEvent & WXUNUSED(event));
108  void OnMenuAddScatterer(wxCommandEvent & event);
109  void OnMenuRemoveScatterer(wxCommandEvent & WXUNUSED(event));
110  void OnMenuDuplicateScatterer(wxCommandEvent & WXUNUSED(event));
111  void OnMenuImportMoleculeFromFenskeHallZMatrix(wxCommandEvent &event);
112  void OnMenuAtoms2Molecule(wxCommandEvent &event);
113  void OnMenuSetRelativeXYZLimits(wxCommandEvent & WXUNUSED(event));
114  void OnMenuTestRandomMoves(wxCommandEvent &event);
115  bool OnChangeName(const int id);
116  void UpdateUI(const bool mutexlock=false);
117  Crystal& GetCrystal();
118  const Crystal& GetCrystal()const;
119  void OnMenuShowScattPowWindow(wxCommandEvent &event);
120  void OnEditGridScattPow(wxGridEvent &e);
121  void OnEditGridScattPowAntiBump(wxGridEvent &e);
122  void OnEditGridScattPowBondValence(wxGridEvent &e);
123  void NotifyDeleteListWin(WXCrystalScrolledGridWindow *win);
124  //void OnMenuPDF(wxCommandEvent &event);
125  virtual bool Enable(bool enable=true);
126  private:
127  Crystal* mpCrystal;
134 
136  struct RowScattPow
137  {
138  RowScattPow();
139  std::string mName;
141  REAL mBiso,mFormalCharge,mR,mG,mB,mMaximumLikelihoodError,mNbGhostAtoms;
143  std::vector<REAL> mvAntiBumpDistance;
145  std::vector<REAL> mvBondValenceRo;
149  int mIdx;
150  };
151 
152  WXCrystalScrolledGridWindow* mpScattPowWin;
153  WXCrystalScrolledGridWindow* mpAntiBumpWin;
154  WXCrystalScrolledGridWindow* mpBondValenceWin;
155 
156  std::map<ScatteringPowerAtom*,RowScattPow> mvpRowScattPow;
157 
161 
162  #ifdef OBJCRYST_GL
163  //OpenGl
165  unsigned int mCrystalGLDisplayList;
168  unsigned int mCrystalGLNameDisplayList;
170  WXGLCrystalCanvas* mpCrystalGL;
171  #endif
172  wxMutex mMutexGLUpdate;
175  wxCondition *mpConditionGLUpdate;
176 
178  //PDF *mpPDF;
179  DECLARE_EVENT_TABLE()
180 };
181 
182 #ifdef OBJCRYST_GL
183 class UnitCellMap
186 {
187  public:
192  UnitCellMap(const Crystal&crystal);
193  ~UnitCellMap();
197  void GLInitDisplayList(const float contourValue,
198  WXGLCrystalCanvas * parentCrystal) const;
200  void POVRayDescription(ostream &os,const float contourValue,
201  const CrystalPOVRayOptions &options)const;
206  int ImportGRD(const string&filename);
211  int ImportDSN6(const string&filename);
212  #ifdef HAVE_FFTW
213 
219  int CalcFourierMap(const ScatteringData& data, unsigned int type=0, const bool normalized_sf=false);
220  #endif
221  const string & GetName()const;
224  REAL GetValue(const REAL x,const REAL y,const REAL z)const;
226  REAL Max()const;
228  REAL Min()const;
230  REAL Mean()const;
232  REAL StandardDeviation()const;
234  int GetType()const;
236  const Crystal &GetCrystal()const;
238  const ScatteringData *GetData()const;
239 
240  private:
242  const Crystal *mpCrystal;
244  const ScatteringData *mpData;
246  CrystArray3D_REAL mPoints;
248  string mName;
250  REAL mMin,mMax;
252  REAL mMean;
254  REAL mStandardDeviation;
256  int mType;
257 };
258 
261 struct UnitCellMapGLList
262 {
263  public:
264  UnitCellMapGLList(const UnitCellMap &ucmap,WXGLCrystalCanvas * parent,
265  const bool showWire=true,float contour=1.0,
266  const float r=1.0,const float g=0.0,const float b=0.0,const float t=0.5);
267  ~UnitCellMapGLList();
269  void GenList();
271  void SetName(const string &name);
273  const string &GetName()const;
275  void SetColour(const float r=1.0,const float g=0.0,const float b=0.0,
276  const float t=1.0);
278  const float* GetColour()const;
280  void ToggleShowWire();
282  bool ShowWire()const;
284  void Draw()const;
286  void SetShow(bool show);
288  bool Show()const;
290  void SetContour(float contour);
292  float GetContour()const;
294  const UnitCellMap & GetMap()const;
295  private:
297  unsigned int mGLDisplayList;
299  float mColour[4];
301  bool mShowWire;
303  string mName;
305  bool mShow;
307  float mContour;
309  const UnitCellMap *mpUCMap;
311  WXGLCrystalCanvas *mpParent;
312 };
313 
315 class WXGLCrystalCanvas : public wxGLCanvas
316 {
317  public:
318  WXGLCrystalCanvas(WXCrystal *wxcryst,
319  wxFrame *parent, wxWindowID id=-1,
320  const wxPoint &pos=wxDefaultPosition,
321  const wxSize &size=wxDefaultSize);
322  ~WXGLCrystalCanvas();
323  void OnExit(wxCommandEvent &event);
324  void OnPaint(wxPaintEvent &event);
325  //void OnSize(wxSizeEvent& event);
326  void OnEraseBackground(wxEraseEvent& event);
327  void OnKeyDown(wxKeyEvent& event);
328  void OnKeyUp(wxKeyEvent& event);
329  void OnEnterWindow( wxMouseEvent& event );
330  void OnMouse( wxMouseEvent& event );
332  void OnUpdate(wxCommandEvent & WXUNUSED(event));
334  void CrystUpdate();
335  void OnChangeLimits(wxCommandEvent &event);
337  void OnUpdateUI(wxUpdateUIEvent& WXUNUSED(event));
338  void OnShowCrystal(wxCommandEvent & WXUNUSED(event));
339  void OnShowAtomLabel(wxCommandEvent & WXUNUSED(event));
340  void OnShowHydrogens(wxCommandEvent & WXUNUSED(event));
342  bool GetShowHydrogens()const;
343  void OnShowCursor(wxCommandEvent & WXUNUSED(event));
344  void OnSetCursor(wxCommandEvent & WXUNUSED(event));
346  void OnFourier(wxCommandEvent &event);
347 
348  void OnLoadFourierGRD(wxCommandEvent & WXUNUSED(event));
349  void OnLoadFourierDSN6(wxCommandEvent & WXUNUSED(event));
350  void AddFourier(UnitCellMap*);
351  void OnAddContour(wxCommandEvent & WXUNUSED(event));
352  void OnChangeContour(wxCommandEvent & WXUNUSED(event));
353  void OnShowFourier(wxCommandEvent & WXUNUSED(event));
354  void OnFourierChangeColour(wxColourPickerEvent & event);
355  void OnUnloadFourier(wxCommandEvent & WXUNUSED(event));
356  void OnShowWire(wxCommandEvent & WXUNUSED(event));
357  void OnFourierChangeBbox(wxCommandEvent & WXUNUSED(event));
359  void OnPOVRay(wxCommandEvent & WXUNUSED(event));
361  void POVRayOutput(const std::string &filename);
362  // get bounding box for atoms display
363  BBox GetCellBBox();
364  // get bounding box for display of Fourier map
365  BBox GetMapBBox();
366  virtual void SetCurrent();
367  void NotifyDeleteFourierWin();
368  private:
369  void InitGL();
372  int UserSelectUnitCellMapGLList()const;
375  int UserSelectUnitCellMap()const;
388  void UnProject(REAL &x, REAL &y, REAL &z);
390  void BuildGLFont();
392  void DeleteGLFont()const;
394  wxFrame* mpParentFrame;
396  WXCrystal* mpWXCrystal;
398  wxGLContext *mpwxGLContext;
400  bool mIsGLInit;
402  float mQuat [4];
404  float mTrackBallLastX,mTrackBallLastY;
406  float mDist;
407  REAL mX0, mY0,mZ0;
409  float mViewAngle;
411  wxMenu* mpPopUpMenu;
412 
414  bool mShowFourier, mShowCrystal, mShowAtomName, mShowHydrogens, mShowCursor,mSharpenMap;
416  BBox mcellbbox;
418  BBox mmapbbox;
420  Triple mViewCntr;
421 
427  vector<boost::shared_ptr<UnitCellMap> > mvpUnitCellMap;
431  vector<boost::shared_ptr<UnitCellMapGLList> > mvpUnitCellMapGLList;
432 
434  mutable bool mIsGLFontBuilt;
435  mutable int mGLFontDisplayListBase;
437  class WXFourierMapList:public wxWindow
438  {
439  public:
440  WXFourierMapList(WXGLCrystalCanvas *pGLCrystalCanvas,wxWindow *parent);
441  ~WXFourierMapList();
442  wxCheckBox *mpWireFrame;
443  wxCheckBox *mpShowFourier;
444  wxCheckBox *mpSharpenMap;
445  wxListBox *mpAvailableMapList;
446  wxListBox *mpDisplayedMapList;
447  wxStaticText *mpMapInfo;
448  wxTextCtrl *mpNewContourValue;
449  wxTextCtrl *mpContourValue;
450  wxColourPickerCtrl *mpColourPicker;
451  WXGLCrystalCanvas *mpGLCrystalCanvas;
452  wxMutex mMutex;
453  bool mIsUpdating;
454  };
455  WXFourierMapList *mpFourierMapListWin;
456  DECLARE_EVENT_TABLE()
457 };
458 #endif
459 
460 
461 } //namespace
462 
463 #endif //_VFN_WX_CRYSTAL_H_
WXCrystal * mpWXCrystal
The WXCrystal window which created this window, and who should be told if it is destroyed.
Definition: wxCrystal.h:75
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:160
int mIdx
Current position in the list of rows or columns.
Definition: wxCrystal.h:149
std::vector< REAL > mvAntiBumpDistance
Last displayed values for antibump.
Definition: wxCrystal.h:143
bool mNeedUpdateUI
True if we need to update the displayed values.
Definition: wxCrystal.h:147
bool OnChangeName(const int id)
When a WXFieldName has been changed by the user, it is handled here.
Definition: wxCrystal.cpp:1591
Structure to store the scattering power parameters.
Definition: wxCrystal.h:136
REAL mBiso
Last displayed values.
Definition: wxCrystal.h:141
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:652
A field with the name of a WXCrystObj.
Definition: wxCryst.h:371
wxMutex mMutexGLUpdate
Mutex used when updating the OpenGL display List, between background and main thread.
Definition: wxCrystal.h:173
This displays all components of a ObjCryst++ Registry.
Class to compute structure factors for a set of reflections and a Crystal.
WXRegistry< Scatterer > * mpWXScattererRegistry
Scatterers.
Definition: wxCrystal.h:131
Class to store POV-Ray output options.
Definition: General.h:175
wxCryst class for Crystals
Definition: wxCrystal.h:80
WXFieldName * mpFieldSpacegroup
SpaceGroup.
Definition: wxCrystal.h:129
The base wxCryst class for all RefinableObj objects.
WXRegistry< ScatteringPower > * mpWXScatteringPowerRegistry
Scattering Powers.
Definition: wxCrystal.h:133
std::vector< REAL > mvBondValenceRo
Last displayed values for bond valence.
Definition: wxCrystal.h:145
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: Atom.cpp:47
wxCondition * mpConditionGLUpdate
wxCondition used when updating the OpenGL display List, between background and main thread ...
Definition: wxCrystal.h:175
Crystal class: Unit cell, spacegroup, scatterers.
Definition: Crystal.h:97
void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.
Definition: wxCrystal.cpp:1613