The Gnome Chemistry Utils 0.13.3
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-2011 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 <gccv/structs.h>
00032 #include <gcu/atom.h>
00033 #include <gcu/dialog-owner.h>
00034 #include <gcu/element.h>
00035 #include <gcu/macros.h>
00036 
00039 namespace gcu {
00040 class UIManager;
00041 }
00042 
00043 namespace gcp {
00044 
00045 class Bond;
00046 class Molecule;
00047 
00051 #define POSITION_NE 1
00052 
00055 #define POSITION_NW 2
00056 
00059 #define POSITION_N 4
00060 
00063 #define POSITION_SE 8
00064 
00067 #define POSITION_SW 16
00068 
00071 #define POSITION_S 32
00072 
00075 #define POSITION_E 64
00076 
00079 #define POSITION_W 128
00080 
00085 typedef enum {
00089         LEFT_HPOS,
00093         RIGHT_HPOS,
00097         TOP_HPOS,
00101         BOTTOM_HPOS,
00105         AUTO_HPOS,
00106 } HPos;
00107 
00108 class Electron;
00109 
00113 class Atom: public gcu::Atom, public gcu::DialogOwner, public gccv::ItemClient
00114 {
00115 public:
00119         Atom ();
00128         Atom (int Z, double x, double y, double z);
00132         virtual ~Atom ();
00133 
00134 public :
00140         virtual void SetZ (int Z);
00146         void AddBond (gcu::Bond* pBond);
00152         void RemoveBond (gcu::Bond* pBond);
00156         virtual void Update ();
00160         int GetTotalBondsNumber () const; //take bond order into account
00164         int GetAttachedHydrogens () const {return m_nH;}
00169         HPos GetBestSide ();
00182         virtual gccv::Anchor GetChargePosition (unsigned char& Pos, double Angle, double& x, double& y);
00192         virtual int GetAvailablePosition (double& x, double& y);
00202         virtual bool GetRelativePosition (double angle, double& x, double& y);
00212         virtual bool GetPosition (double angle, double& x, double& y);
00219         virtual xmlNodePtr Save (xmlDocPtr xml) const;
00226         virtual bool Load (xmlNodePtr node);
00232         virtual bool LoadNode (xmlNodePtr node);
00236         void AddItem ();
00244         void SetSelected (int state);
00250         virtual bool AcceptNewBonds (int nb = 1);
00256         virtual bool AcceptCharge (int charge);
00260         virtual double GetYAlign ();
00268         virtual void Move (double x, double y, double z = 0.);
00276         virtual void Transform2D (gcu::Matrix2D& m, double x, double y);
00285         bool BuildContextualMenu (gcu::UIManager *UIManager, Object *object, double x, double y);
00291         virtual void AddToMolecule (Molecule* Mol);
00295         bool HasImplicitElectronPairs ();
00299         bool MayHaveImplicitUnpairedElectrons ();
00305         void AddElectron (Electron* electron);
00311         void RemoveElectron (Electron* electron);
00318         void NotifyPositionOccupation (unsigned char pos, bool occupied);
00327         void SetChargePosition (unsigned char Pos, bool def, double angle = 0., double distance = 0.);
00334         char GetChargePosition (double *Angle, double *Dist) const;
00340         void SetCharge (int charge);
00344         int GetCharge () const {return m_Charge;}
00348         void ForceChanged () {m_Changed = true;}
00359         bool Match (gcu::Atom *atom, gcu::AtomMatchState &state);
00360 
00373         void GetSymbolGeometry (double &width, double &height, double &angle, bool up) const;
00374 
00379         bool HasAvailableElectrons (bool paired);
00380 
00386         Bond *GetBondAtAngle (double angle);
00387 
00388         bool UpdateStereoBonds ();
00389         bool HasStereoBond () const;
00390 
00391 protected:
00399         void BuildSymbolGeometry (double width, double height, double ascent);
00400 
00408         bool SetProperty (unsigned property, char const *value);
00409 
00410 private:
00411         void UpdateAvailablePositions ();
00412 
00413 private:
00414         gcu::Element *m_Element;
00415         int m_nH;
00416         int m_Valence; //valence
00417         int m_ValenceOrbitals;
00418         int m_nlp; //lone electron pairs number
00419         int m_nlu; //single electrons number
00420         double m_width, m_height; //size of the atomic symbol in the canvas
00421         double m_length, m_text_height; // size of the text buffer
00422         HPos m_HPos; //0 = left, 1 = right, 2 = top, 3 = bottom, 4 = auto
00423         bool m_ChargeAuto;
00424         int m_Changed; //update needs regenerate the buffer
00425         int m_ascent;
00426         double m_lbearing;
00427         unsigned char m_AvailPos; //available standard positions for charge and electrons representations
00428         unsigned char m_OccupiedPos;
00429         bool m_AvailPosCached;
00430         unsigned char m_ChargePos;
00431         bool m_ChargeAutoPos;
00432         double m_ChargeAngle;
00433         double m_ChargeDist;
00434         double m_ChargeWidth, m_ChargeTWidth, m_ChargeXOffset, m_ChargeYOffset;
00435         std::list<double> m_AngleList;
00436         std::map<double, double> m_InterBonds; /* positions betwen bonds. First  value is the
00437         angle between the two bonds and second value is the direction */
00438         PangoLayout *m_Layout, *m_ChargeLayout, *m_HLayout;
00439         double m_xHOffs, m_yHOffs;
00440         bool m_DrawCircle;
00441         std::string m_FontName;
00442         double m_SWidth, m_SHeightH, m_SHeightL, m_SAngleH, m_SAngleL;
00443         // special offset for underlying rectangle; will be removed in next version
00444         double m_xROffs, m_yROffs;
00445 
00446         // atom parity stuff
00447         Atom *m_Bonded[4]; // always using positive parity
00448 
00449 protected:
00453         double m_CHeight;
00454 
00466 GCU_PROP (bool, ShowSymbol)
00467 
00468 
00479 GCU_PROP (HPos, HPosStyle) //0=force left, 1=force right, 2=force top, 3=force bottom, 4=auto.
00491 GCU_POINTER_PROP (gccv::Item, ChargeItem)
00503 GCU_PROP (bool, ShowCharge);
00504 };
00505 
00506 }       //      namespace gcp
00507 
00508 #endif // GCHEMPAINT_ATOM_H