gcp/atom.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /* 
00004  * GChemPaint library
00005  * atom.h 
00006  *
00007  * Copyright (C) 2001-2008 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 <gccv/item-client.h>
00031 #include <gcu/atom.h>
00032 #include <gcu/dialog-owner.h>
00033 #include <gcu/element.h>
00034 #include <gcu/macros.h>
00035 
00036 namespace OpenBabel
00037 {
00038         class OBAtom;
00039 }
00040 
00042 namespace gcp {
00043 
00044 class Bond;
00045 class Molecule;
00046 
00050 #define POSITION_NE 1
00051 
00054 #define POSITION_NW 2
00055 
00058 #define POSITION_N 4
00059 
00062 #define POSITION_SE 8
00063 
00066 #define POSITION_SW 16
00067 
00070 #define POSITION_S 32
00071 
00074 #define POSITION_E 64
00075 
00078 #define POSITION_W 128
00079 
00084 typedef enum {
00088         LEFT_HPOS,
00092         RIGHT_HPOS,
00096         TOP_HPOS,
00100         BOTTOM_HPOS,
00104         AUTO_HPOS,
00105 } HPos;
00106 
00107 class Electron;
00108 
00112 class Atom: public gcu::Atom, public gcu::DialogOwner, public gccv::ItemClient
00113 {
00114 public:
00118         Atom ();
00127         Atom (int Z, double x, double y, double z);
00134         Atom (OpenBabel::OBAtom* atom);
00138         virtual ~Atom ();
00139 
00140 public :
00146         virtual void SetZ (int Z);
00152         void AddBond (gcu::Bond* pBond);
00158         void RemoveBond (gcu::Bond* pBond);
00162         virtual void Update ();
00166         int GetTotalBondsNumber () const; //take bond order into account
00170         int GetAttachedHydrogens () const {return m_nH;}
00175         HPos GetBestSide ();
00193         virtual int GetChargePosition (unsigned char& Pos, double Angle, double& x, double& y);
00203         virtual int GetAvailablePosition (double& x, double& y);
00213         virtual bool GetPosition (double angle, double& x, double& y);
00220         virtual xmlNodePtr Save (xmlDocPtr xml) const;
00227         virtual bool Load (xmlNodePtr node);
00233         virtual bool LoadNode (xmlNodePtr node);
00237         void AddItem ();
00245         void SetSelected (int state);
00251         virtual bool AcceptNewBonds (int nb = 1);
00257         virtual bool AcceptCharge (int charge);
00261         virtual double GetYAlign ();
00269         virtual void Transform2D (gcu::Matrix2D& m, double x, double y);
00278         bool BuildContextualMenu (GtkUIManager *UIManager, Object *object, double x, double y);
00284         virtual void AddToMolecule (Molecule* Mol);
00288         bool HasImplicitElectronPairs ();
00292         bool MayHaveImplicitUnpairedElectrons ();
00298         void AddElectron (Electron* electron);
00304         void RemoveElectron (Electron* electron);
00311         void NotifyPositionOccupation (unsigned char pos, bool occupied);
00320         void SetChargePosition (unsigned char Pos, bool def, double angle = 0., double distance = 0.);
00327         char GetChargePosition (double *Angle, double *Dist) const;
00333         void SetCharge (int charge);
00337         int GetCharge () const {return m_Charge;}
00341         void ForceChanged () {m_Changed = true;}
00352         bool Match (gcu::Atom *atom, gcu::AtomMatchState &state);
00353 
00366         void GetSymbolGeometry (double &width, double &height, double &angle, bool up) const;
00367 
00368         bool HasAvailableElectrons (bool paired);
00369 
00370 protected:
00378         void BuildSymbolGeometry (double width, double height, double ascent);
00379 
00380 private:
00381         void UpdateAvailablePositions ();
00382 
00383 private:
00384         gcu::Element *m_Element;
00385         int m_nH;
00386         int m_Valence; //valence
00387         int m_ValenceOrbitals;
00388         int m_nlp; //lone electron pairs number
00389         int m_nlu; //single electrons number
00390         double m_width, m_height; //size of the atomic symbol in the canvas
00391         double m_length, m_text_height; // size of the text buffer
00392         HPos m_HPos; //0 = left, 1 = right, 2 = top, 3 = bottom, 4 = auto
00393         bool m_ChargeAuto;
00394         int m_Changed; //update needs regenerate the buffer
00395         int m_ascent;
00396         double m_lbearing;
00397         unsigned char m_AvailPos; //available standard positions for charge and electrons representations
00398         unsigned char m_OccupiedPos;
00399         bool m_AvailPosCached;
00400         unsigned char m_ChargePos;
00401         bool m_ChargeAutoPos;
00402         double m_ChargeAngle;
00403         double m_ChargeDist;
00404         double m_ChargeWidth, m_ChargeTWidth, m_ChargeXOffset, m_ChargeYOffset;
00405         std::list<double> m_AngleList;
00406         std::map<double, double> m_InterBonds; /* positions betwen bonds. First  value is the
00407         angle between the two bonds and second value is the direction */
00408         PangoLayout *m_Layout, *m_ChargeLayout, *m_HLayout;
00409         double m_xHOffs, m_yHOffs;
00410         bool m_DrawCircle;
00411         std::string m_FontName;
00412         double m_SWidth, m_SHeightH, m_SHeightL, m_SAngleH, m_SAngleL;
00413         // special offset for underlying rectangle; will be removed in next version
00414         double m_xROffs, m_yROffs;
00415 
00416 protected:
00420         double m_CHeight;
00421 
00433 GCU_PROP (bool, ShowSymbol)
00434 
00435 
00446 GCU_PROP (HPos, HPosStyle) //0=force left, 1=force right, 2=force top, 3=force bottom, 4=auto.
00447 };
00448 
00449 }       //      namespace gcp
00450 
00451 #endif // GCHEMPAINT_ATOM_H

Generated on Thu Jun 25 13:24:19 2009 for The Gnome Chemistry Utils by  doxygen 1.5.9