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 ORBVIEW_MAIN_H
25 #define ORBVIEW_MAIN_H
26 
27 #include "Iv.h"
28 #include <QMainWindow>
29 #include <QAction>
30 #include <QSortFilterProxyModel>
31 #include <QScriptEngine>
32 #include <QResizeEvent>
33 #include <QShowEvent>
34 #include <QDragEnterEvent>
35 #include <QDropEvent>
36 #include <QCloseEvent>
37 #include "IvView3D.h"
38 #include "IvDocument.h"
39 // #include "IvScript.h"
40 
41 namespace Ui{
42     class MainWindow;
43     class AboutDialog;
44 }
45 
46 class FDocument;
47 class IApplication;
48 class IView3d;
49 
50 class FShowOnlyCurrentColumnFilter : public QSortFilterProxyModel
51 {
52    Q_OBJECT;
53 public:
54    typedef QSortFilterProxyModel
55       FBase;
56    bool filterAcceptsColumn(int sourceColumn, const QModelIndex &sourceParent) const; // override
57    explicit FShowOnlyCurrentColumnFilter(int ShownColumn_, QObject *parent = 0);
58 
shownColumn()59    int shownColumn() const { return m_ShownColumn; }
60 public slots:
61    void setShownColumn(int NewColumn);
62 private:
63 //    FDocument *m_pDocument;
64    int
65       m_ShownColumn;
66 };
67 
68 
69 // class FMainWindow : public QMainWindow, public IApplication
70 class FMainWindow : public QMainWindow
71 {
72     Q_OBJECT
73 public:
74    typedef QMainWindow
75       FBase;
76    FMainWindow(QWidget *parent = 0, Qt::WindowFlags flags = 0);
77    ~FMainWindow();
78 public:
79    Ui::MainWindow *ui;
80    IView3d *view3d;
81    FDocument *document;
82    FShowOnlyCurrentColumnFilter *dataViewFilter;
83 
84 public:
85    FGeometry *pGetActiveGeometry();
86    FOrbital *pGetOrbital(int iMo);
87 
88    QString MakeStateScript();
89    void WriteStateScript(QString FileName="");
90 
91    // fixme: remove this if we get a saturation control for main color.
92 //    float hc, vc, sc, ac;
93    int iUpdateLocked;
94 
95 public slots:
96    void onDataChanged();
97    void onActiveDatasetChanged();
98    void onFrameIdChanged(int iNewFrame);
99    void onDataRowClicked(QModelIndex const &);
100    void onDataRowDoubleClicked(QModelIndex const &);
101    void onActiveIboCurveChanged();
102 
103 // various more-or-less directly UI-exposed actions.
104    void onOpenFile();
105    void onSaveState();
106    void onSaveStateAs();
107    void onCopyState();
108    void onExecStateFromClipboard();
109    void onSavePicture();
110    void onSavePictureAs();
111    void onCopyPicture();
112    void onExportCurves();
113    void onOpenPreferences();
114 
115    void onTraceIsoSurfacesClicked();
116    void onAboutClicked();
117    void onToggleTrackedOrbitalClicked();
118    void onComputeWaveFunctionTriggered();
119    void ExecPresetScript();
120 
121    void onRebuildIsoSurfacesClicked();
122    void onFlipOrbitalClicked();
123    void toggleShadingControls();
124    void setShaderPath();
125 
126    void onOrbitalColorChanged(int iNewValue);
127    void onDiscreeteTrafoTriggered();
128    void processInputs();
129 
130    void showFrameLog();
131    void onTitleChanged();
132    void UpdateAtomAndBondScalesText();
133    void ShowTablesAndCurves();
134    void ShowEditFramesForm();
135 
136    void dummySignalTest(double o);
137 
138    void StoreApplicationSettings();
139 public:
140    void LoadApplicationSettings();
141    // guess and set a size for the given sub-window in terms of the main window size.
142    void SetDefaultDialogSize(QWidget *pWindow, double fDefaultVerticalScale = -1.);
143 protected:
144    void dragEnterEvent(QDragEnterEvent *event); // override
145    void dropEvent(QDropEvent *event); // override
146 
147    void AddPresetScript(QMenu *pMenu, QString FileName);
148    void closeEvent(QCloseEvent *event);
149 public:
150    friend class IApplication;
151    IApplication *ThisAsIApp();
152 //    void set_iso_surface_type_(QString const &IsoType, float fIsoValue);
153    void load_files_(QStringList const &FileName);
154    void close_files_();
155 };
156 
157 // script interface
158 class IApplication : public FMainWindow {
159     Q_OBJECT
160 public slots:
161    virtual void load_file(QString const &FileName); // = 0;
162 //    virtual void load_files(QString const &FileNames); // = 0;
163    virtual void load_files(QScriptValue const &FileList);
164    virtual void close_files();
165    virtual void set_frame(int iFrame); // = 0;
166    virtual QString get_frame_name(); // = 0;
167    // align molecules in space. 'Mode' denotes the atom weight; can
168    // be "mass", "charge", "unity", or "iso-mass" (most common isotope mass instead of average isotope mass)
169    virtual void orient_frames(QString const &Mode); // = 0;
170 
171    virtual void show_mo(int iMo, int cIsoPlus=-1, int cIsoMinus=-1); // = 0;
172    virtual void hide_mo(int iMo); // = 0;
173    virtual void hide_mos(); // = 0; // hide all MOs.
174 
175    virtual uint num_frames();
176    virtual QObject* frame(int iFrame); // return frame #iFrame. return value is an IFrame* object.
177    virtual QObject* frame(); // return current frame.
178 
179    // add/remove bond lines. Atom indices are 1-based here.
180    // These here apply to all loaded frames.
181    virtual void add_bond(int iAt, int jAt, QString const &Flags); // = 0;
182    virtual void delete_bond(int iAt, int jAt); // = 0;
183    virtual void reset_bonds(); // = 0; // reset all bonds to normal.
184 
185    virtual void set_atom_mode(int iAt, QString const &Mode); // = 0; // 0: hidden
186    virtual void reset_atom_modes(); // = 0; // reset all atom states to normal.
187 
188    // exit the application at next opportunity.
189    virtual void quit(); // = 0;
190 
191 //    virtual FElementOptionsList &element_options();
192 //    virtual QObjectList element_options();
193    virtual QObject* element_options(int iElem);
194    // reset element options to defaults for that element.
195    virtual void reset_element_options(int iElem);
196    // note: this either returns or creates a override pPropertiesOverride object in the corresponding FAtomOptions object.
197    virtual QObject* atom_options(int iAtom);
198    // destroy property override object and make atom behave like other elements of its kind.
199    virtual void reset_atom_options(int iAtom);
200 
201    virtual void update_views();
202 
203 //    virtual void set_iso_surface_type(QString const &IsoType, float fIsoValue); // = 0;
204 
205 public: // here for technical reasons. Not part of script interface.
206    IApplication( QWidget * parent = 0, Qt::WindowFlags flags = 0 )
FMainWindow(parent,flags)207       : FMainWindow(parent, flags)
208    {}
209    ~IApplication(); // does nothing---just to fix the vtable.
210 };
211 
212 
213 #include <QDialog>
214 struct FAboutDialogImpl;
215 
216 class FAboutDialog : public QDialog
217 {
218     Q_OBJECT
219 public:
220     Ui::AboutDialog *ui;
221     FAboutDialogImpl *p;
222 
223     FAboutDialog(QWidget *parent = 0);
224    ~FAboutDialog();
225 // protected:
226 //    void closeEvent(QCloseEvent *event);
227 };
228 
229 
230 // don't ask.
231 // class QFileDialog;
232 // class FSaveFileDirChangeProxy : public QObject
233 // {
234 //    Q_OBJECT
235 // public:
236 //    explicit FSaveFileDirChangeProxy(QFileDialog *pDialog);
237 //    ~FSaveFileDirChangeProxy();
238 // protected:
239 //    QFileDialog *m_pDialog;
240 // protected slots:
241 //    void selectFile(QString const &File);
242 // };
243 
244 #endif // ORBVIEW_MAIN_H
245