1 /* Copyright (c) 2015  Gerald Knizia
2  *
3  * This file is part of the IboView program (see: http://www.iboview.org)
4  *
5  * IboView 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, version 3.
8  *
9  * IboView is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with bfint (LICENSE). If not, see http://www.gnu.org/licenses/
16  *
17  * Please see IboView documentation in README.txt for:
18  * -- A list of included external software and their licenses. The included
19  *    external software's copyright is not touched by this agreement.
20  * -- Notes on re-distribution and contributions to/further development of
21  *    the IboView software
22  */
23 
24 #ifndef _3D_VIEW_WIDGET_H
25 #define _3D_VIEW_WIDGET_H
26 
27 #include "Iv.h"
28 #include <QAbstractTableModel>
29 #include <QGLWidget>
30 #include <QTimer>
31 // #include "IvScript.h"
32 
33 class FDocument;
34 class FViewImpl;
35 
36 
37 // class FView3d : public QGLWidget, public IView3d {
38 // class FView3d : public IView3d {
39 class FView3d : public QGLWidget {
40 
41    Q_OBJECT // must include this if you use Qt signals/slots
42 
43 public:
44 #include "prop_FView3d.h.inl"
45 
46 public:
47    typedef QGLWidget
48       FBase;
49    FView3d(QWidget *parent, FDocument *document);
50    ~FView3d();
51 
52 public:
53    // return a script setting up the current view.
54    QString GetViewDesc();
55 
56    bool RenderAnyLabels() const;
57 public slots:
58    void updateData(const QModelIndex &topleft,const QModelIndex &bottomright);
59 
60    void UpdateBondMesh();
61 //    void executeUpdate();
62    void ResetFrameBuffers();
63 
64    void PrepareDataLayoutChange();
65    void FinishDataLayoutChange();
66    void RehashShaders();
67 protected:
68    void initializeGL();
69    void resizeGL(int w, int h);
70    void paintGL();
71    void mousePressEvent(QMouseEvent *event);
72    void mouseReleaseEvent(QMouseEvent *event);
73    void mouseMoveEvent(QMouseEvent *event);
74    void wheelEvent(QWheelEvent *event);
75    void keyPressEvent(QKeyEvent *event);
76 
77 //    QTimer m_UpdateTimer;
78 public:
79    FDocument *d;
80    FViewImpl *v;
81    friend class FViewImpl;
82 
83    QImage grabFrameBuffer1(bool withAlpha);
84    friend class IView3d;
85 };
86 
87 
88 
89 // script interface
90 class IView3d : public FView3d {
91    Q_OBJECT
92 public slots:
93    virtual void set_camera_pos(float x, float y, float z); // = 0;
94    virtual void set_camera_dir(float x, float y, float z); // = 0;
95    virtual void set_camera_vup(float x, float y, float z); // = 0;
96    virtual void set_camera_zoom(float z); // = 0;
97    virtual void save_png(QString const &FileName); // = 0;
98    virtual void set_option(QString const &OptionName, QVariant f); // = 0;
99 //    virtual void set_option(QString const &OptionName, double f); // = 0;
100 //    virtual double get_option(QString const &OptionName); // = 0;
101    virtual void modify(QString const &How, float f); // = 0;
102 
103 //    virtual void set_option(QString const &OptionName, bool f); // default impl calls set_view_optioni with +1 or -1.
104 //    virtual void set_option(QString const &OptionName, int i); // default impl calls set_view_optionf(double(i)).
105 
106    virtual void set_size(int width, int height);
107 public: // here for technical reasons. Not part of script interface.
108    IView3d(QWidget *parent_, FDocument *document_);
109    ~IView3d(); // does nothing---just to fix the vtable.
110 };
111 
112 // script interface
113 class ICamera : public QObject
114 {
115    Q_OBJECT
116 public slots:
117    virtual void set_pos(float x, float y, float z); // = 0;
118    virtual void set_dir(float x, float y, float z); // = 0;
119    virtual void set_vup(float x, float y, float z); // = 0;
120    virtual void set_zoom(float z); // = 0;
121 public:
122    explicit ICamera(QObject *pView3d);
123 private:
124    IView3d *pView3d();
125 };
126 
127 
128 
129 #endif  /* _3D_VIEW_WIDGET_H */
130