# 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 <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
    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
    00114 {
    00115 public:
    00119         Atom ();
    00128         Atom (int Z, double x, double y, double z);
    00135         Atom (OpenBabel::OBAtom* atom);
    00139         virtual ~Atom ();
    00140
    00141 public :
    00147         virtual void SetZ (int Z);
    00153         void AddBond (gcu::Bond* pBond);
    00159         void RemoveBond (gcu::Bond* pBond);
    00163         virtual void Update ();
    00169         virtual void Add (GtkWidget* w) const;
    00175         virtual void Update (GtkWidget* w) const;
    00179         int GetTotalBondsNumber () const; //take bond order into account
    00183         int GetAttachedHydrogens () const {return m_nH;}
    00188         HPos GetBestSide ();
    00206         virtual int GetChargePosition (unsigned char& Pos, double Angle, double& x, double& y);
    00216         virtual int GetAvailablePosition (double& x, double& y);
    00226         virtual bool GetPosition (double angle, double& x, double& y);
    00233         virtual xmlNodePtr Save (xmlDocPtr xml) const;
    00240         virtual bool Load (xmlNodePtr node);
    00246         virtual bool LoadNode (xmlNodePtr node);
    00255         virtual void SetSelected (GtkWidget* w, int state);
    00261         virtual bool AcceptNewBonds (int nb = 1);
    00267         virtual bool AcceptCharge (int charge);
    00271         virtual double GetYAlign ();
    00279         virtual void Transform2D (gcu::Matrix2D& m, double x, double y);
    00288         bool BuildContextualMenu (GtkUIManager *UIManager, Object *object, double x, double y);
    00294         virtual void AddToMolecule (Molecule* Mol);
    00298         bool HasImplicitElectronPairs ();
    00302         bool MayHaveImplicitUnpairedElectrons ();
    00308         void AddElectron (Electron* electron);
    00314         void RemoveElectron (Electron* electron);
    00321         void NotifyPositionOccupation (unsigned char pos, bool occupied);
    00330         void SetChargePosition (unsigned char Pos, bool def, double angle = 0., double distance = 0.);
    00337         char GetChargePosition (double *Angle, double *Dist) const;
    00343         void SetCharge (int charge);
    00347         int GetCharge () const {return m_Charge;}
    00351         void ForceChanged () {m_Changed = true;}
    00362         bool Match (gcu::Atom *atom, gcu::AtomMatchState &state);
    00363
    00376         void GetSymbolGeometry (double &width, double &height, double &angle, bool up) const;
    00377
    00378 protected:
    00386         void BuildSymbolGeometry (double width, double height, double ascent);
    00387
    00388 private:
    00389         void BuildItems (WidgetData* pData);
    00390         void UpdateAvailablePositions ();
    00391
    00392 private:
    00393         gcu::Element *m_Element;
    00394         int m_nH;
    00395         int m_Valence; //valence
    00396         int m_ValenceOrbitals;
    00397         int m_nlp; //lone electron pairs number
    00398         int m_nlu; //single electrons number
    00399         double m_width, m_height; //size of the atomic symbol in the canvas
    00400         double m_length, m_text_height; // size of the text buffer
    00401         HPos m_HPos; //0 = left, 1 = right, 2 = top, 3 = bottom, 4 = auto
    00402         bool m_ChargeAuto;
    00403         int m_Changed; //update needs regenerate the buffer
    00404         int m_ascent;
    00405         double m_lbearing;
    00406         unsigned char m_AvailPos; //available standard positions for charge and electrons representations
    00407         unsigned char m_OccupiedPos;
    00408         bool m_AvailPosCached;
    00409         unsigned char m_ChargePos;
    00410         bool m_ChargeAutoPos;
    00411         double m_ChargeAngle;
    00412         double m_ChargeDist;
    00413         double m_ChargeWidth, m_ChargeTWidth, m_ChargeXOffset, m_ChargeYOffset;
    00414         std::list<double> m_AngleList;
    00415         std::map<double, double> m_InterBonds; /* positions betwen bonds. First  value is the
    00416         angle between the two bonds and second value is the direction */
    00417         PangoLayout *m_Layout, *m_ChargeLayout, *m_HLayout;
    00418         double m_xHOffs, m_yHOffs;
    00419         bool m_DrawCircle;
    00420         std::string m_FontName;
    00421         double m_SWidth, m_SHeightH, m_SHeightL, m_SAngleH, m_SAngleL;
    00422         // special offset for underlying rectangle; will be removed in next version
    00423         double m_xROffs, m_yROffs;
    00424
    00425 protected:
    00429         double m_CHeight;
    00430
    00442 GCU_PROP (bool, ShowSymbol)
    00443
    00444
    00455 GCU_PROP (HPos, HPosStyle) //0=force left, 1=force right, 2=force top, 3=force bottom, 4=auto.
    00456 };
    00457
    00458 }       //      namespace gcp
    00459
    00460 #endif // GCHEMPAINT_ATOM_H