gcp/atom.h

00001 // -*- C++ -*-
00002 
00003 /* 
00004  * GChemPaint library
00005  * atom.h 
00006  *
00007  * Copyright (C) 2001-2007 Jean Bréfort <jean.brefort@normalesup.org>
00008  *
00009  * This program is free software; you can redistribute it and/or 
00010  * modify it under the terms of the GNU General Public License as 
00011  * published by the Free Software Foundation; either version 2 of the
00012  * License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00022  * USA
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 (); //take bond order into account
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; //valence
00144         int m_ValenceOrbitals;
00145         int m_nlp; //lone electron pairs number
00146         int m_nlu; //single electrons number
00147         double m_width, m_height; //size of the atomic symbol in the canvas
00148         double m_length, m_text_height; // size of the text buffer
00149         bool m_HPos; //false = left, true = right
00150         bool m_ChargeAuto;
00151         int m_Changed; //update needs regenerate the buffer
00152         int m_ascent;
00153         double m_lbearing;
00154         double m_CHeight;
00155         unsigned char m_AvailPos; //available standard positions for charge and electrons representations
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; /* positions betwen bonds. First  value is the
00165         angle between the two bonds and second value is the direction */
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) //0=force left, 1=force right, 2=auto.
00172 };
00173 
00174 }       //      namespace gcp
00175 
00176 #endif // GCHEMPAINT_ATOM_H

Generated on Thu Jun 28 09:02:00 2007 for The Gnome Chemistry Utils by  doxygen 1.5.2