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 Cycle;
00046 class Molecule;
00047
00048 #define CHARGE_NE 1
00049 #define CHARGE_NW 2
00050 #define CHARGE_N 4
00051 #define CHARGE_SE 8
00052 #define CHARGE_SW 16
00053 #define CHARGE_S 32
00054 #define CHARGE_E 64
00055 #define CHARGE_W 128
00056
00057 #define POSITION_NE 1
00058 #define POSITION_NW 2
00059 #define POSITION_N 4
00060 #define POSITION_SE 8
00061 #define POSITION_SW 16
00062 #define POSITION_S 32
00063 #define POSITION_E 64
00064 #define POSITION_W 128
00065
00066 enum {
00067 LEFT_HPOS,
00068 RIGHT_HPOS,
00069 AUTO_HPOS,
00070 };
00071
00072 class Electron;
00073
00074 class Atom: public gcu::Atom, public gcu::DialogOwner
00075 {
00076 public:
00077 Atom ();
00078 Atom (int Z, double x, double y, double z);
00079 Atom (OpenBabel::OBAtom* atom);
00080 virtual ~Atom ();
00081
00082 public :
00083 virtual void SetZ (int Z);
00084 void AddBond (gcu::Bond* pBond);
00085 void RemoveBond (gcu::Bond* pBond);
00086 virtual void Update ();
00087 virtual void Add (GtkWidget* w);
00088 virtual void Update (GtkWidget* w);
00089 int GetTotalBondsNumber ();
00090 int GetAttachedHydrogens () {return m_nH;}
00091 bool GetBestSide ();
00092 bool IsInCycle (Cycle* pCycle);
00093 virtual int GetChargePosition (unsigned char& Pos, double Angle, double& x, double& y);
00094 virtual int GetAvailablePosition (double& x, double& y);
00095 virtual bool GetPosition (double angle, double& x, double& y);
00096 virtual xmlNodePtr Save (xmlDocPtr xml);
00097 virtual bool Load (xmlNodePtr);
00098 virtual bool LoadNode (xmlNodePtr);
00099 virtual void SetSelected (GtkWidget* w, int state);
00100 virtual bool AcceptNewBonds (int nb = 1);
00101 virtual bool AcceptCharge (int charge);
00102 virtual double GetYAlign ();
00103 virtual void Transform2D (gcu::Matrix2D& m, double x, double y);
00104 bool BuildContextualMenu (GtkUIManager *UIManager, Object *object, double x, double y);
00110 virtual void AddToMolecule (Molecule* Mol);
00111 bool HasImplicitElectronPairs ();
00112 bool MayHaveImplicitUnpairedElectrons ();
00118 void AddElectron (Electron* electron);
00124 void RemoveElectron (Electron* electron);
00125 void NotifyPositionOccupation (unsigned char pos, bool occupied);
00126 void SetChargePosition (unsigned char Pos, bool def, double angle = 0., double distance = 0.);
00127 char GetChargePosition (double *Angle, double *Dist);
00128 void SetCharge (int charge);
00129 int GetCharge () {return m_Charge;}
00130 void ForceChanged () {m_Changed = true;}
00131 cairo_rectangle_t &GetInkRect () {return m_InkRect;}
00132 cairo_rectangle_t &GetHInkRect () {return m_HInkRect;}
00133
00134 private:
00135 void BuildItems (WidgetData* pData);
00136 void UpdateAvailablePositions ();
00137
00138 private:
00139 gcu::Element *m_Element;
00140 int m_nH;
00141 int m_Valence;
00142 int m_ValenceOrbitals;
00143 int m_nlp;
00144 int m_nlu;
00145 double m_width, m_height;
00146 double m_length, m_text_height;
00147 int m_HPos;
00148 bool m_ChargeAuto;
00149 int m_Changed;
00150 int m_ascent;
00151 double m_lbearing;
00152 double m_CHeight;
00153 unsigned char m_AvailPos;
00154 unsigned char m_OccupiedPos;
00155 bool m_AvailPosCached;
00156 unsigned char m_ChargePos;
00157 bool m_ChargeAutoPos;
00158 double m_ChargeAngle;
00159 double m_ChargeDist;
00160 double m_ChargeWidth, m_ChargeTWidth, m_ChargeXOffset, m_ChargeYOffset;
00161 std::list<double> m_AngleList;
00162 std::map<double, double> m_InterBonds;
00163
00164 PangoLayout *m_Layout, *m_ChargeLayout;
00165 bool m_DrawCircle;
00166 std::string m_FontName;
00167 cairo_rectangle_t m_InkRect, m_HInkRect;
00168
00169 GCU_PROP (bool, ShowSymbol)
00170 GCU_PROP (unsigned char, HPosStyle)
00171 };
00172
00173 }
00174
00175 #endif // GCHEMPAINT_ATOM_H