Debian Codegraph @

avogadro/qtplugins/aligntool/aligntool.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_QTPLUGINS_ALIGNTOOL_H
7 #define AVOGADRO_QTPLUGINS_ALIGNTOOL_H
8
9 #include <avogadro/qtgui/toolplugin.h>
10
11 #include <avogadro/qtgui/molecule.h>
12 #include <avogadro/rendering/primitive.h>
13
14 namespace Avogadro::QtPlugins {
15
16 /**
17 * @class AlignTool aligntool.h
18 * <avogadro/qtplugins/aligntool/aligntool.h>
19 * @brief The Align Tool class aligns molecules to a frame of reference.
20 * @author Geoffrey Hutchison
21 */
22 class AlignTool : public QtGui::ToolPlugin
23 {
24 Q_OBJECT
25 public:
26 explicit AlignTool(QObject* parent_ = nullptr);
27 ~AlignTool() override;
28
29 QString name() const override { return tr("Align tool"); }
30 QString description() const override
31 {
32 return tr("Align molecules to a Cartesian axis");
33 }
34 unsigned char priority() const override { return 90; }
35 QAction* activateAction() const override { return m_activateAction; }
36 QWidget* toolWidget() const override;
37
38 void setIcon(bool darkTheme = false) override;
39
40 void setMolecule(QtGui::Molecule* mol) override
41 {
42 if (mol)
43 m_molecule = mol->undoMolecule();
44
45 m_atoms.clear();
46 }
47
48 void setEditMolecule(QtGui::RWMolecule* mol) override { m_molecule = mol; }
49
50 void setGLRenderer(Rendering::GLRenderer* renderer) override
51 {
52 m_renderer = renderer;
53 }
54
55 QUndoCommand* mousePressEvent(QMouseEvent* e) override;
56 QUndoCommand* mouseDoubleClickEvent(QMouseEvent* e) override;
57
58 void draw(Rendering::GroupNode& node) override;
59
60 void shiftAtomToOrigin(Index atomIndex);
61 void alignAtomToAxis(Index atomIndex, int axis);
62
63 bool toggleAtom(const Rendering::Identifier& atom);
64
65 bool handleCommand(const QString& command,
66 const QVariantMap& options) override;
67
68 /**
69 * Called by the app to tell the tool to register commands.
70 * If the tool has commands, it should emit the registerCommand signals.
71 */
72 void registerCommands() override;
73
74 public Q_SLOTS:
75 void axisChanged(int axis);
76 void alignChanged(int align);
77 void align();
78
79 private:
80 QAction* m_activateAction;
81 QtGui::RWMolecule* m_molecule;
82 Rendering::GLRenderer* m_renderer;
83 QVector<Rendering::Identifier> m_atoms;
84
85 int m_axis;
86 int m_alignType;
87
88 mutable QWidget* m_toolWidget;
89
90 private Q_SLOTS:
91 void toolWidgetDestroyed();
92 };
93
94 } // namespace Avogadro::QtPlugins
95
96 #endif // AVOGADRO_QTOPENGL_ALIGNTOOL_H