1 /*******************************************************************************
2 
3   This source file is part of the Avogadro project.
4 
5   Copyright 2018 Kitware, Inc.
6 
7   This source code is released under the New BSD License, (the "License").
8 
9   Unless required by applicable law or agreed to in writing, software
10   distributed under the License is distributed on an "AS IS" BASIS,
11   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   See the License for the specific language governing permissions and
13   limitations under the License.
14 
15 *******************************************************************************/
16 
17 #ifndef AVOGADRO_QTPLUGINS_PLOTPDF_H
18 #define AVOGADRO_QTPLUGINS_PLOTPDF_H
19 
20 #include <avogadro/qtgui/extensionplugin.h>
21 
22 // Forward declarations
23 class QByteArray;
24 class QStringList;
25 
26 namespace VTK {
27 class VtkPlot;
28 }
29 
30 namespace Avogadro {
31 namespace QtPlugins {
32 
33 class PdfOptionsDialog;
34 
35 // First item in the pair is radius. Second is the pdf value.
36 typedef std::vector<std::pair<double, double>> PdfData;
37 
38 /**
39  * @brief Generate and plot a PDF curve
40  */
41 class PlotPdf : public Avogadro::QtGui::ExtensionPlugin
42 {
43   Q_OBJECT
44 public:
45   explicit PlotPdf(QObject* parent_ = 0);
46   ~PlotPdf();
47 
name()48   QString name() const { return tr("PlotPdf"); }
49   QString description() const;
50   QList<QAction*> actions() const;
51   QStringList menuPath(QAction*) const;
52 
53 public slots:
54   void setMolecule(QtGui::Molecule* mol);
55 
56   void moleculeChanged(unsigned int changes);
57 
58 private slots:
59   void updateActions();
60 
61   void displayDialog();
62 
63 private:
64   // Generate Pdf curve from a crystal
65   // Writes the results to @p results, which is a vector of pairs of doubles
66   // (see definition above).
67   // err will be set to an error string if the function fails.
68   // radius is in Angstroms.
69   static bool generatePdfPattern(QtGui::Molecule& mol, PdfData& results,
70                                  QString& err, double maxRadius = 10.0,
71                                  double step = 0.1);
72 
73   QList<QAction*> m_actions;
74   QtGui::Molecule* m_molecule;
75 
76   QScopedPointer<PdfOptionsDialog> m_pdfOptionsDialog;
77   QScopedPointer<QAction> m_displayDialogAction;
78   QScopedPointer<VTK::VtkPlot> m_plot;
79 };
80 
description()81 inline QString PlotPdf::description() const
82 {
83   return tr("Generate and plot a Pair Distribution Function curve.");
84 }
85 
86 } // namespace QtPlugins
87 } // namespace Avogadro
88 
89 #endif // AVOGADRO_QTPLUGINS_PLOTPDF_H
90