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 <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;
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 protected:
00376 void BuildSymbolGeometry (double width, double height, double ascent);
00377
00378 private:
00379 void UpdateAvailablePositions ();
00380
00381 private:
00382 gcu::Element *m_Element;
00383 int m_nH;
00384 int m_Valence;
00385 int m_ValenceOrbitals;
00386 int m_nlp;
00387 int m_nlu;
00388 double m_width, m_height;
00389 double m_length, m_text_height;
00390 HPos m_HPos;
00391 bool m_ChargeAuto;
00392 int m_Changed;
00393 int m_ascent;
00394 double m_lbearing;
00395 unsigned char m_AvailPos;
00396 unsigned char m_OccupiedPos;
00397 bool m_AvailPosCached;
00398 unsigned char m_ChargePos;
00399 bool m_ChargeAutoPos;
00400 double m_ChargeAngle;
00401 double m_ChargeDist;
00402 double m_ChargeWidth, m_ChargeTWidth, m_ChargeXOffset, m_ChargeYOffset;
00403 std::list<double> m_AngleList;
00404 std::map<double, double> m_InterBonds;
00405
00406 PangoLayout *m_Layout, *m_ChargeLayout, *m_HLayout;
00407 double m_xHOffs, m_yHOffs;
00408 bool m_DrawCircle;
00409 std::string m_FontName;
00410 double m_SWidth, m_SHeightH, m_SHeightL, m_SAngleH, m_SAngleL;
00411
00412 double m_xROffs, m_yROffs;
00413
00414 protected:
00418 double m_CHeight;
00419
00431 GCU_PROP (bool, ShowSymbol)
00432
00433
00444 GCU_PROP (HPos, HPosStyle)
00445 };
00446
00447 }
00448
00449 #endif // GCHEMPAINT_ATOM_H