kalzium
bondcentrictool.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef BONDCENTRICTOOL_H
00030 #define BONDCENTRICTOOL_H
00031
00032 #include "skeletontree.h"
00033
00034 #include <avogadro/glwidget.h>
00035 #include <avogadro/tool.h>
00036
00037 #include <openbabel/mol.h>
00038
00039 #include <QGLWidget>
00040 #include <QObject>
00041 #include <QStringList>
00042 #include <QImage>
00043 #include <QAction>
00044 #include <QUndoCommand>
00045
00046 #include <QLabel>
00047 #include <QSpinBox>
00048 #include <QCheckBox>
00049 #include <QGridLayout>
00050
00051
00052 namespace Avogadro {
00053
00063 class BondCentricTool : public Tool
00064 {
00065 Q_OBJECT
00066
00067 public:
00069 BondCentricTool(QObject *parent = 0);
00071 virtual ~BondCentricTool();
00072
00074
00075
00076 virtual QString name() const { return(tr("Bond Centric Manipulate")); }
00078 virtual QString description() const { return(tr("Bond Centric Manipulation Tool")); }
00080
00082
00083
00084 virtual QUndoCommand* mousePress(GLWidget *widget, const QMouseEvent *event);
00085 virtual QUndoCommand* mouseRelease(GLWidget *widget, const QMouseEvent *event);
00086 virtual QUndoCommand* mouseMove(GLWidget *widget, const QMouseEvent *event);
00087 virtual QUndoCommand* wheel(GLWidget *widget, const QWheelEvent *event);
00089
00090 virtual int usefulness() const;
00091
00092 virtual bool paint(GLWidget *widget);
00093
00094 virtual QWidget *settingsWidget();
00098 virtual void writeSettings(QSettings &settings) const;
00099
00103 virtual void readSettings(QSettings &settings);
00104
00111 void setMolecule(Molecule* molecule);
00112
00113 public Q_SLOTS:
00119 void snapToAngleChanged(int newAngle);
00120
00130 void snapToCheckBoxChanged(int state);
00131
00141 void showAnglesChanged(int state);
00142
00143 protected:
00144 Molecule * m_molecule;
00145 QWidget * m_settingsWidget;
00146
00147
00148 Atom * m_clickedAtom;
00149 Bond * m_clickedBond;
00150 Bond * m_selectedBond;
00151
00152 SkeletonTree * m_skeleton;
00153
00154 Eigen::Vector3d * m_referencePoint;
00155 Eigen::Vector3d * m_currentReference;
00156 Eigen::Vector3d * m_directionVector;
00157
00158 bool m_snapped;
00159 ToolGroup * m_toolGroup;
00160
00161 QUndoCommand * m_undo;
00162
00163 bool m_leftButtonPressed;
00164 bool m_midButtonPressed;
00165 bool m_rightButtonPressed;
00166 bool m_movedSinceButtonPressed;
00167
00168 bool m_showAngles;
00169 bool m_snapToEnabled;
00170
00171 int m_snapToAngle;
00172
00173 QPoint m_lastDraggingPosition;
00174
00175 QLabel * m_snapToAngleLabel;
00176 QLabel * m_spacer;
00177 QCheckBox * m_showAnglesBox;
00178 QCheckBox * m_snapToCheckBox;
00179 QSpinBox * m_snapToAngleBox;
00180 QGridLayout * m_layout;
00181
00183
00184
00185
00196 bool isAtomInBond(Atom *atom, Bond *bond);
00197
00208 void drawAngleSector(GLWidget *widget, Eigen::Vector3d origin,
00209 Eigen::Vector3d direction1, Eigen::Vector3d direction2,
00210 bool alternateAngle = false);
00211
00219 void drawAtomAngles(GLWidget *widget, Atom *atom);
00220
00232 void drawAngles(GLWidget *widget, Atom *atom, Bond *bond);
00233
00242 void drawSkeletonAngles(GLWidget *widget, SkeletonTree *skeleton);
00243
00244 void drawDihedralAngle(GLWidget *widget, Atom *A, Atom *D, Bond *BC,
00245 bool alternateAngle = false);
00246
00247 void drawDihedralAngles(GLWidget *widget, Atom *A, Bond *BC);
00248
00249 void drawSingleDihedralAngles(GLWidget *widget, Atom *A, Bond *BC);
00250
00272 Eigen::Vector3d* calculateSnapTo(Bond *bond, Eigen::Vector3d *referencePoint,
00273 double maximumAngle);
00274
00286 void drawManipulationRectangle(GLWidget *widget, Bond *bond,
00287 Eigen::Vector3d *referencePoint, double rgb[3]);
00288
00289 void drawDihedralRectangle(GLWidget *widget, Bond *bond, Atom *atom, double rgb[3]);
00290
00291 void drawDihedralRectanglesOfAtom(GLWidget *widget, Bond *bond, Atom *atom,
00292 double rgb[3]);
00293
00302 void drawSphere(GLWidget *widget, const Eigen::Vector3d ¢er, double radius,
00303 float alpha);
00305
00311 void clearData();
00312
00325 Eigen::Vector3d performRotation(double angle, Eigen::Vector3d rotationVector,
00326 Eigen::Vector3d centerVector,
00327 Eigen::Vector3d positionVector);
00328
00329 private Q_SLOTS:
00335 void toolChanged(bool checked);
00336
00342 void primitiveRemoved(Primitive* primitive);
00343
00347 void settingsWidgetDestroyed();
00348
00349 };
00350
00362 class BondCentricMoveCommand : public QUndoCommand
00363 {
00364 public:
00366
00372 explicit BondCentricMoveCommand(Molecule *molecule, QUndoCommand *parent = 0);
00373
00375
00383 BondCentricMoveCommand(Molecule *molecule, Atom *atom,
00384 Eigen::Vector3d pos, QUndoCommand *parent = 0);
00385
00389 void redo();
00390
00394 void undo();
00395
00403 bool mergeWith(const QUndoCommand * command);
00404
00410 int id() const;
00411
00412 private:
00413 Molecule m_moleculeCopy;
00414 Molecule *m_molecule;
00415 int m_atomIndex;
00416 Eigen::Vector3d m_pos;
00417 bool undone;
00418 };
00419
00420
00421 class BondCentricToolFactory : public QObject, public ToolFactory
00422 {
00423 Q_OBJECT
00424 Q_INTERFACES(Avogadro::ToolFactory)
00425
00426 public:
00427 Tool *createInstance(QObject *parent = 0) { return new BondCentricTool(parent); }
00428 };
00429
00430 }
00431
00432 #endif