gcp/atom.h
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 #ifndef GCHEMPAINT_ATOM_H
00026 #define GCHEMPAINT_ATOM_H
00027
00028 #include <map>
00029 #include <glib.h>
00030 #include <gcu/atom.h>
00031 #include <gcu/dialog-owner.h>
00032 #include <gcu/element.h>
00033 #include <gcu/macros.h>
00034 #include <libgnomecanvas/gnome-canvas.h>
00035 #include "widgetdata.h"
00036
00037 namespace OpenBabel
00038 {
00039 class OBAtom;
00040 }
00041
00042 namespace gcp {
00043
00044 class Bond;
00045 class Molecule;
00046
00047 #define CHARGE_NE 1
00048 #define CHARGE_NW 2
00049 #define CHARGE_N 4
00050 #define CHARGE_SE 8
00051 #define CHARGE_SW 16
00052 #define CHARGE_S 32
00053 #define CHARGE_E 64
00054 #define CHARGE_W 128
00055
00056 #define POSITION_NE 1
00057 #define POSITION_NW 2
00058 #define POSITION_N 4
00059 #define POSITION_SE 8
00060 #define POSITION_SW 16
00061 #define POSITION_S 32
00062 #define POSITION_E 64
00063 #define POSITION_W 128
00064
00065 enum {
00066 LEFT_HPOS,
00067 RIGHT_HPOS,
00068 AUTO_HPOS,
00069 };
00070
00071 class Electron;
00072
00073 class Atom: public gcu::Atom, public gcu::DialogOwner
00074 {
00075 public:
00076 Atom ();
00077 Atom (int Z, double x, double y, double z);
00078 Atom (OpenBabel::OBAtom* atom);
00079 virtual ~Atom ();
00080
00081 public :
00082 virtual void SetZ (int Z);
00083 void AddBond (gcu::Bond* pBond);
00084 void RemoveBond (gcu::Bond* pBond);
00085 virtual void Update ();
00086 virtual void Add (GtkWidget* w) const;
00087 virtual void Update (GtkWidget* w) const;
00088 int GetTotalBondsNumber () const;
00089 int GetAttachedHydrogens () const {return m_nH;}
00090 bool GetBestSide ();
00091 virtual int GetChargePosition (unsigned char& Pos, double Angle, double& x, double& y);
00092 virtual int GetAvailablePosition (double& x, double& y);
00093 virtual bool GetPosition (double angle, double& x, double& y);
00094 virtual xmlNodePtr Save (xmlDocPtr xml) const;
00095 virtual bool Load (xmlNodePtr);
00096 virtual bool LoadNode (xmlNodePtr);
00097 virtual void SetSelected (GtkWidget* w, int state);
00098 virtual bool AcceptNewBonds (int nb = 1);
00099 virtual bool AcceptCharge (int charge);
00100 virtual double GetYAlign ();
00101 virtual void Transform2D (gcu::Matrix2D& m, double x, double y);
00102 bool BuildContextualMenu (GtkUIManager *UIManager, Object *object, double x, double y);
00108 virtual void AddToMolecule (Molecule* Mol);
00109 bool HasImplicitElectronPairs ();
00110 bool MayHaveImplicitUnpairedElectrons ();
00116 void AddElectron (Electron* electron);
00122 void RemoveElectron (Electron* electron);
00123 void NotifyPositionOccupation (unsigned char pos, bool occupied);
00124 void SetChargePosition (unsigned char Pos, bool def, double angle = 0., double distance = 0.);
00125 char GetChargePosition (double *Angle, double *Dist) const;
00126 void SetCharge (int charge);
00127 int GetCharge () const {return m_Charge;}
00128 void ForceChanged () {m_Changed = true;}
00129 bool Match (gcu::Atom *atom, gcu::AtomMatchState &state);
00130
00143 void GetSymbolGeometry (double &width, double &height, double &angle, bool up) const;
00144
00145 protected:
00146 virtual void BuildSymbolGeometry (double width, double height, double ascent);
00147
00148 private:
00149 void BuildItems (WidgetData* pData);
00150 void UpdateAvailablePositions ();
00151
00152 private:
00153 gcu::Element *m_Element;
00154 int m_nH;
00155 int m_Valence;
00156 int m_ValenceOrbitals;
00157 int m_nlp;
00158 int m_nlu;
00159 double m_width, m_height;
00160 double m_length, m_text_height;
00161 int m_HPos;
00162 bool m_ChargeAuto;
00163 int m_Changed;
00164 int m_ascent;
00165 double m_lbearing;
00166 unsigned char m_AvailPos;
00167 unsigned char m_OccupiedPos;
00168 bool m_AvailPosCached;
00169 unsigned char m_ChargePos;
00170 bool m_ChargeAutoPos;
00171 double m_ChargeAngle;
00172 double m_ChargeDist;
00173 double m_ChargeWidth, m_ChargeTWidth, m_ChargeXOffset, m_ChargeYOffset;
00174 std::list<double> m_AngleList;
00175 std::map<double, double> m_InterBonds;
00176
00177 PangoLayout *m_Layout, *m_ChargeLayout;
00178 bool m_DrawCircle;
00179 std::string m_FontName;
00180 double m_SWidth, m_SHeightH, m_SHeightL, m_SAngleH, m_SAngleL;
00181
00182 protected:
00183 double m_CHeight;
00184
00185 GCU_PROP (bool, ShowSymbol)
00186 GCU_PROP (unsigned char, HPosStyle)
00187 };
00188
00189 }
00190
00191 #endif // GCHEMPAINT_ATOM_H