1 
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Christian B. Huebschle & George M. Sheldrick
5 ** All rights reserved.
6 ** Contact: chuebsch@moliso.de
7 **
8 ** This file is part of the ShelXle
9 **
10 ** This file may be used under the terms of the GNU Lesser
11 ** General Public License version 2.1 as published by the Free Software
12 ** Foundation and appearing in the file COPYING included in the
13 ** packaging of this file.  Please review the following information to
14 ** ensure the GNU Lesser General Public License version 2.1 requirements
15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 **
18 ****************************************************************************/
19 #ifndef CHGL_H
20 #define CHGL_H
21 
22 #include <QGLWidget>
23 
24 #include "molecule.h"
25 //#include "fourxle.h"
26 #ifndef MAXSELECT
27 #define MAXSELECT 300001
28 #endif
29 
30 #define HIDE_REASON_SELECT          1
31 #define HIDE_REASON_THIS_FRAGMENT   2
32 #define HIDE_REASON_OTHER_FRAGMENT  4
33 #define HIDE_REASON_HYDROGEN        8
34 #define HIDE_REASON_QPEAK          16
35 #define HIDE_REASON_BELO           32
36 /*! \brief ChGL is the QGLWidget of ShelXle
37  */
38 class ChGL : public QGLWidget{
39 Q_OBJECT
40 public:
41     explicit ChGL(QWidget * parent = 0);
42     virtual ~ChGL();
setMainWindow(QWidget * parent)43     void setMainWindow(QWidget * parent){
44     chparent=parent;
45     }
46     QTimer *idl;//! idle rotation timer
47     QTimer *idl_end;//! idle rotation timer
48     bool on;
49     bool habzutun;
50     int ww,//!<Window with
51 	wh,//!<Window height
52 	minus;//!<for streo mode swiches right and left eye view
53     int SDM_Limit; //!< if the number of atoms in the au exceeds this limit shortest distance is not computed automatically default 350
54     int retinafktr;
55     int stereo_mode;//!< intager value of the current stereo mode
56     int objCnt;//!< number of visible atoms + q-peaks
57     int ImeanThisAtom;//!< atom index for context menu.
58     double viewAngle,//!< viewing angele for the perspective view 0 is othogonal
59 	   envirange;//!< range in Angstrom around which environmental atoms should be consedered.
60     QColor labelColor,//!< Color of atom labels.
61         backGroundColor;//!< Base color of the back groud.
62     bool pause,//!< if true no rendering is made
63 	 inRenameMode,//!< if true wee are in rename mode
64 	 noWaitLabel,//!< if true wire mode after list initialization is not used to generate srceen shots.
65          exporting;//!< for exporting bitmaps
66     QVector< QVector< float > > fVertexes;
67     QVector< QVector< float > > fNormals;
68     double lintrans;//!<degree of thansparency for the maps 0-1. 0 is transparent.
69     double linwidth;//!<linewidth of the meshes.
70     double contMin,contMax;
71     QColor fopc;//!< Fo positive color
72     QColor fomc;//!< Fo negative color
73     QColor dipc;//!< Fo-Fc positive color
74     QColor dimc;//!< Fo-Fc negative color
75     struct labz{
76     int x,y;
77     QString l;
78     int an;
79     };//!< struct labels for exporting bitmaps
80     QList<labz> LabelZ;//!< labels for exporting bitmaps
81     bool hiddenThings;//!< We know that there are hidden objects.
82     bool neutrons;//!< true if we have neuton scattering factors (negative Fo map is shown if this is true)
83     int dratpause;//!< when the molecule is rotated for a time of dratpause milliseconds the molecule is drawn as a wire frame draft
84     QFont myFont,//!< there is a Font for Labels of atoms
85 	  nonAtomFont;//!< there is a Font for Labels of Q-Peaks
86     QTimer *moving;//!< timer runs dratpause miliseconds after a rotation or scale
87     GLdouble MM[16];//!< a GL matrix.
88     QAction *addBond,//!< QAction BIND
89 	    *killBond,//!< QAction FREE
90 	    *clearSelection,//!< QAction deselect
91 	    *centerSelection,//!< QAction center selected atoms
92 	    *hideNotSelection,//!< QAction hide non selected atoms
93 	    *unhide,//!< QAction show all previous hidden objects
94 	    *invhide,//!< QAction show all previous hidden and hide visible objects
95 	    *grow,//!< QAction grow
96 	    *fuse,//!< QAction fuse
97 	    *shpm1,//!< QAction show part -N ghost
98 	    *hideh, //!< QAction hide Hydrogen atoms
99 	    *qPeakBonds,//!< QAction Q-Peak binds
100 	    *toggleDockWidgets,//!< QAction hide text windows
101 	    *delSelAt,//!< QAction delete selected atoms
102 	    *highlightParts, //!< QAction highlight atoms in parts != 0
103 	    *centroid, //!< QAction create a centroid dummy
104 	    *enviNoQ,//!< QAction ENVI only for real atoms
105 	    *enviCova,//!< QAction ENVI only for covalent contacts
106 	    *wireButt,//!< QAction show atoms while rotation in wire mode
107 	    *invSelection,//!< QAction invert selection
108         *cntrPlot,
109         *nocntrPlot,
110         *rainbowPlot,
111         *hideBeLo,//!< hide/show  BEDE and LONE objects
112         *useTextureLabels,//!< alternative to Qt renderText render Labels on BillBoard textures
113         *shortLabels,//!< Labels without residue number or symmery flag are considered short
114         *atomLegend;//!< a key legend for atoms used
115     QToolButton *enviButt;//!< Button to clear the envi -ronment.
116     QToolButton *enviSelect;//!< Button to select the envi -ronment.
117     QList<V3>enviPositions;//!<List of atom postions of an envi-ronment.
118     QList<V3> cont;
119     QMap<int,GLfloat> contval;
120     QList<int>enviKat;//!< List of categorie:qs of contacts in an envi-ronment.
121     V3 enviP0;//!< coordinate used for envi.
122     QMenu *sfacMenu;//!< a sub menu to change the element of a specified atom.
123     QStringList labs;//!< Labels for an envi-ronment list.
124     Molecule *mol;//!< pointer to the Molecule object.
125     int	murx;//!< non zero values lead to a rerendering of the display lists.
126 //    static const int bas=1;//!< GL List base for atoms bonds unit cell.
127 //    static const int wirbas=11;//!< GL List base for wireframe bonds and atoms
128     double L;//!< a scale factor.
129     QAction *foact, //!< QAction toggling Fobs maps.
130 	    *fofcact;//!< QAction toggling Fobs-Fcalc maps.
131     int rotze;//!< if not -1 the index of an atom in the rotation center.
132     QToolButton *invertMouseZoom;//!< inverts the mouse direction that zoom on right click.
133     QCheckBox   *lighting;//!< enable lighting on the electron density.
134     QCheckBox   *niceTrans;//!< draw 6 perspectives for each surface to improve transparent visualization.
135     QCheckBox   *fillMap;//!< draw maps in filled style.
136     QToolButton *rCenter;//!< resets the rotation center
137     V3 altemitte;//!<rotation center position
138     V3 altcenter;
139     bool altpivot;
140     QComboBox *pivot1cb;
141     QComboBox *pivot2cb;
142     QDoubleSpinBox *axx;
143     QDoubleSpinBox *axy;
144     QDoubleSpinBox *axz;
145     QCheckBox *manualAx;
146     QLabel *whyNotSplit;
147 //    void initLists();
148     bool canSplitRotate();
149     QSpinBox *angle1;
150     QSpinBox *angle2;
151     void farbverlauf(double wrt, double min, double max);
152     QColor farbverlaufQC(double wrt, double min, double max);
153     void zoom(double speed);
isFO()154     bool isFO(){return drawFO;}//!< if Fo map is visible true is returned.
isDF()155     bool isDF(){return drawDF;}//!< if Fo-Fc map is visible true is returned.
156     //void warFaul(){warfaul=true;}
157     void gZoom(double speed);
158     void rotZ(double speed);
159     void rotY(double speed);
160     void rotX(double speed);
161     void moveX(double speed);
162     void moveY(double speed);
163     void setupTexture();
164     void updateBondActions();
165     QList<int> lastClicked();
glError2String(GLenum err)166     inline QString glError2String(GLenum err){
167         switch (err) {
168         case GL_NO_ERROR: return QString("GL_NO_ERROR: No OpenGL error."); break;
169         case GL_INVALID_ENUM: return QString("GL_INVALID_ENUM: An enumeration parameter is not a legal enumeration for that function."); break;
170         case GL_INVALID_VALUE: return QString("GL_INVALID_VALUE: Given when a value parameter is not a legal value for that function."); break;
171         case GL_INVALID_OPERATION: return QString("GL_INVALID_OPERATION: Given when the set of state for a command is not legal for the parameters given to that command."); break;
172         case GL_STACK_OVERFLOW: return QString("GL_STACK_OVERFLOW: Given when a stack pushing operation cannot be done because it would overflow the limit of that stack's size."); break;
173         case GL_STACK_UNDERFLOW: return QString("GL_STACK_UNDERFLOW: Given when a stack popping operation cannot be done because the stack is already at its lowest point."); break;
174         case GL_OUT_OF_MEMORY: return QString("GL_OUT_OF_MEMORY: Given when performing an operation that can allocate memory, and the memory cannot be allocated."); break;
175         default : return QString("Some other OpenGL error."); break;
176         }
177     }
178     void pairing(QList<int> ima, QList<int> imb);
setLabelSize(double s)179     inline void setLabelSize(double s){
180         labScal=s;
181     }
182 signals:
183     void no_hw_st();//!< we have no hard ware stereo sorry!
184     void message(const QString &);//!< small text messages to the status bar.
185     void bigmessage(const QString &);//!< passes HTML strings to the info window.
186     void jumpit(int index);//!<An atom has ben left clicked: cursor jump on it.
187     void selectionChanged();
188     void movedByUser();
189     void diffscroll(int numsteps,int diff);//!< to change the iso value of the Fo- or Fo-Fc maps
190     void neuemitte(V3 mitte);//!< the rotation center has changet to mitte.
191     void inimibas();//!< tells FourXle to initialize the GL display lists.
192     void qpfoci(double height);//!< when a mouse hovers a Q-Peak the height is emitted to the Q-Peak Legend.
193     void insertDFIX(double value, double esd, QList<MyAtom> selected, QString resiSpec); //!< Insert DFIX restrain to the ins file
194     void bindthem();
195     void splitable(bool ok);
196     void insertDANG(double value, double esd, QList<MyAtom> selected, QString resiSpec); //!< Insert DANG restrain to the ins file
197     void insertFLAT(double esd, QList<MyAtom> selected, QString resiSpec); //!< Insert FLAT restrain to the ins file
198     void insertEXYZ(QList<MyAtom> selected); //!< Insert EXYZ restrain to the ins file
199     void insertEADP(QList<MyAtom> selected); //!< Insert EADP restrain to the ins file
200     void insertSADI(int selected); //!< Insert SADI restrain to the ins file
201     void insertDELU(double esd1, double esd2, QList<MyAtom> selected, QString resiSpec); //!< Insert DELU restrain to the ins file
202     void insertSIMU(double esd1, double st, double dmax, QList<MyAtom> selected, QString resiSpec); //!< Insert SIMU restrain to the ins file
203     void insertISOR(double esd1, double esd2, QList<MyAtom> selected, QString resiSpec); //!< Insert ISOR restrain to the ins file
204     void insertRIGU(double esd1, double esd2, QList<MyAtom> selected, QString resiSpec); //!< Insert DELU restrain to the ins file
205     void insertCHIV(double Vol, double esd1, QList<MyAtom> selected, QString resiSpec); //!< Insert CHIV restrain to the ins file
206     void insertANIS(QList<MyAtom> selected); //!< Insert ANIS instruction for selected atoms
207     void pivot1Changed(int i);
208     void pivot2Changed(int i);
209 public slots:
210     void sdm();
211     void rotateIdle();
212     void along001();
213     void anaglyphRedCyan();
214     void changeBColor();
215     void changeEnviRange();
216     void changeTColor();
changePivot1(int i)217     void changePivot1(int i){pivot=i;splitRotate();emit splitable(canSplitRotate()); }
changePivot2(int i)218     void changePivot2(int i){pivot2=i;splitRotate();emit splitable(canSplitRotate());}
219     void clearEnvi();
220 //    void clearLists();
221     void connectSelection();
222     void crosseye();
223     void decFontSize();
224     void disConnectSelection(int index);
225     void disSelection();
226     void envi();
227     void expand();
fertig()228     void fertig(){habzutun=false;updateGL();printf("map veritces ready!\n");}
229     void hardwareStereo();
230     void hideHydrogens();
231     void hideNonSelected();
232     void hideOtherFragments();
233     void hidePartMinusOne(bool off);
234     void hideQPeaksBelow(double cutoff);
235     void hideSelected();
236     void hideThisFragment();
237     void highliteQPeak(double co);
238     void homeXY();
239     void incFontSize();
240     void invertSelection();
241     void invertHidden();//!< Toggle visibility of atoms etc
242     void Listen();
243     void singleBondDistance();
244     void loadOrientation();
245     void loadOrientation(QString fn);
246     void nostereo();
247     void parallel();
248     void rehide();
249     void rotCenter();
250     void saveOrientation();
251     void saveOrientation(QString fn);
252     void selectEnvi();
253     void selectPair(const QString &s);
254     void selectResiByNr(int nr);
255     void selectThisFragment();
256     void setADP(bool b);
257     void setAtom(bool b);
258     void setBGGradient(bool b);
259     void setBond(bool b);
260     void setDepthCueing(bool b);
261     void setHBond(bool b);
262     void setLabel(bool b);
263     void setMSAA(bool b);
264     void setMatrix();
265     void setMolecule(Molecule *m);
266     void setReNaMo(bool b);
267     void setRotationCenter();
268     void setRotationCenter(int rz);
269     void setRotationCenter(V3 center);
setTube(bool b)270     void setTube(bool b){
271       //!sets tube mode to b
272       tubes=b;
273       updateGL();
274     }
275     void setUnit(bool b);
276     void setViewAngle(double ang);
277     void showHidden();
278     void showMatrix();
279     void splitRotate();
280     void toogleWithSymmetry(bool b);
281     void zoomOut();
unsetTube(bool b)282     void unsetTube(bool b){
283       //!sets tube mode to not b
284       tubes=!b;
285       updateGL();
286     }
287     void updateLabelTextures();
288     void zalman();
289 // Restrain slots
290     void addDFIX();
291     void addDANG();
292     void addFLAT();
293     void addEXYZ();
294     void addEADP();
295     void addSADI();
296     void addDELU();
297     void addSIMU();
298     void addISOR();
299     void addRIGU();
300     void addCHIV();
301     void addANIS();
302     void wuff();
303 
304 protected:
305    void initializeGL();
306    void resizeGL(int width, int height);
307    void paintGL();
308 #if (QT_VERSION >= 0x040600) && (defined (Q_WS_MAC) || defined(Q_OS_MAC))
309    bool event(QEvent *event);
310 #endif
311    void mousePressEvent(QMouseEvent *event);
312    void mouseMoveEvent(QMouseEvent *event);
313    void contextMenuEvent(QContextMenuEvent *event);
314    void wheelEvent(QWheelEvent *event);
315 private:
316   QWidget *chparent;
317   inline void __RotateCS( double c, double s, double& X, double& Y ) ;
318   void glTranslateL( const double dx, const double dy, const double dz );
319   void glRotateL( const double dang, const double x, const double y, const double z );
320   void findPivot();
321   QList<int> seat;//selected atoms indices for splitrotation
322   int pivot,pivot2;
323   int ppp,pp,p;//there is no need this should longer GLuint 26.02.2020
324 #if (QT_VERSION >= 0x040600) && (defined (Q_WS_MAC) || defined(Q_OS_MAC))
325         bool gestureEvent(QGestureEvent *event);
326         void pinchTriggered(QPinchGesture*);
327         void swipeTriggered(QSwipeGesture*);
328 #endif
329         bool mouseOverInteraction,atomsClickable,tubes,bggradient,depthcueing;
330         bool drawAx,drawUc,drawAt,drawADP,drawBo,drawLa,drawHb,drawFO,drawDF, warLabel;
331         int imFokus,afok;
332         void draw();
333         Connection apair;
334         GLint vp[4];
335         int hideReason;
336         double qcutoff,pickradius;
337         int frid;
338         double labScal;
339         QList<QImage> labelTextures;
340         QList<QImage> extraTextures;
341         QList<QImage> enviTextures;
342         int withsymm;
343         QPoint lastPos;
344         QStringList resis();
345 };
346 
347 #endif // CHGL_H
348