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