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 <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
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, public gccv::ItemClient
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 ();
00167 int GetTotalBondsNumber () const;
00171 int GetAttachedHydrogens () const {return m_nH;}
00176 HPos GetBestSide ();
00189 virtual gccv::Anchor GetChargePosition (unsigned char& Pos, double Angle, double& x, double& y);
00199 virtual int GetAvailablePosition (double& x, double& y);
00209 virtual bool GetRelativePosition (double angle, double& x, double& y);
00219 virtual bool GetPosition (double angle, double& x, double& y);
00226 virtual xmlNodePtr Save (xmlDocPtr xml) const;
00233 virtual bool Load (xmlNodePtr node);
00239 virtual bool LoadNode (xmlNodePtr node);
00243 void AddItem ();
00251 void SetSelected (int state);
00257 virtual bool AcceptNewBonds (int nb = 1);
00263 virtual bool AcceptCharge (int charge);
00267 virtual double GetYAlign ();
00275 virtual void Move (double x, double y, double z = 0.);
00283 virtual void Transform2D (gcu::Matrix2D& m, double x, double y);
00292 bool BuildContextualMenu (GtkUIManager *UIManager, Object *object, double x, double y);
00298 virtual void AddToMolecule (Molecule* Mol);
00302 bool HasImplicitElectronPairs ();
00306 bool MayHaveImplicitUnpairedElectrons ();
00312 void AddElectron (Electron* electron);
00318 void RemoveElectron (Electron* electron);
00325 void NotifyPositionOccupation (unsigned char pos, bool occupied);
00334 void SetChargePosition (unsigned char Pos, bool def, double angle = 0., double distance = 0.);
00341 char GetChargePosition (double *Angle, double *Dist) const;
00347 void SetCharge (int charge);
00351 int GetCharge () const {return m_Charge;}
00355 void ForceChanged () {m_Changed = true;}
00366 bool Match (gcu::Atom *atom, gcu::AtomMatchState &state);
00367
00380 void GetSymbolGeometry (double &width, double &height, double &angle, bool up) const;
00381
00386 bool HasAvailableElectrons (bool paired);
00387
00393 Bond *GetBondAtAngle (double angle);
00394
00395 protected:
00403 void BuildSymbolGeometry (double width, double height, double ascent);
00404
00405 private:
00406 void UpdateAvailablePositions ();
00407
00408 private:
00409 gcu::Element *m_Element;
00410 int m_nH;
00411 int m_Valence;
00412 int m_ValenceOrbitals;
00413 int m_nlp;
00414 int m_nlu;
00415 double m_width, m_height;
00416 double m_length, m_text_height;
00417 HPos m_HPos;
00418 bool m_ChargeAuto;
00419 int m_Changed;
00420 int m_ascent;
00421 double m_lbearing;
00422 unsigned char m_AvailPos;
00423 unsigned char m_OccupiedPos;
00424 bool m_AvailPosCached;
00425 unsigned char m_ChargePos;
00426 bool m_ChargeAutoPos;
00427 double m_ChargeAngle;
00428 double m_ChargeDist;
00429 double m_ChargeWidth, m_ChargeTWidth, m_ChargeXOffset, m_ChargeYOffset;
00430 std::list<double> m_AngleList;
00431 std::map<double, double> m_InterBonds;
00432
00433 PangoLayout *m_Layout, *m_ChargeLayout, *m_HLayout;
00434 double m_xHOffs, m_yHOffs;
00435 bool m_DrawCircle;
00436 std::string m_FontName;
00437 double m_SWidth, m_SHeightH, m_SHeightL, m_SAngleH, m_SAngleL;
00438
00439 double m_xROffs, m_yROffs;
00440
00441 protected:
00445 double m_CHeight;
00446
00458 GCU_PROP (bool, ShowSymbol)
00459
00460
00471 GCU_PROP (HPos, HPosStyle)
00483 GCU_POINTER_PROP (gccv::Item, ChargeItem)
00495 GCU_PROP (bool, ShowCharge);
00496 };
00497
00498 }
00499
00500 #endif // GCHEMPAINT_ATOM_H