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
00038 namespace gcp {
00039
00040 class Bond;
00041 class Molecule;
00042
00046 #define POSITION_NE 1
00047
00050 #define POSITION_NW 2
00051
00054 #define POSITION_N 4
00055
00058 #define POSITION_SE 8
00059
00062 #define POSITION_SW 16
00063
00066 #define POSITION_S 32
00067
00070 #define POSITION_E 64
00071
00074 #define POSITION_W 128
00075
00080 typedef enum {
00084 LEFT_HPOS,
00088 RIGHT_HPOS,
00092 TOP_HPOS,
00096 BOTTOM_HPOS,
00100 AUTO_HPOS,
00101 } HPos;
00102
00103 class Electron;
00104
00108 class Atom: public gcu::Atom, public gcu::DialogOwner, public gccv::ItemClient
00109 {
00110 public:
00114 Atom ();
00123 Atom (int Z, double x, double y, double z);
00127 virtual ~Atom ();
00128
00129 public :
00135 virtual void SetZ (int Z);
00141 void AddBond (gcu::Bond* pBond);
00147 void RemoveBond (gcu::Bond* pBond);
00151 virtual void Update ();
00155 int GetTotalBondsNumber () const;
00159 int GetAttachedHydrogens () const {return m_nH;}
00164 HPos GetBestSide ();
00177 virtual gccv::Anchor GetChargePosition (unsigned char& Pos, double Angle, double& x, double& y);
00187 virtual int GetAvailablePosition (double& x, double& y);
00197 virtual bool GetRelativePosition (double angle, double& x, double& y);
00207 virtual bool GetPosition (double angle, double& x, double& y);
00214 virtual xmlNodePtr Save (xmlDocPtr xml) const;
00221 virtual bool Load (xmlNodePtr node);
00227 virtual bool LoadNode (xmlNodePtr node);
00231 void AddItem ();
00239 void SetSelected (int state);
00245 virtual bool AcceptNewBonds (int nb = 1);
00251 virtual bool AcceptCharge (int charge);
00255 virtual double GetYAlign ();
00263 virtual void Move (double x, double y, double z = 0.);
00271 virtual void Transform2D (gcu::Matrix2D& m, double x, double y);
00280 bool BuildContextualMenu (GtkUIManager *UIManager, Object *object, double x, double y);
00286 virtual void AddToMolecule (Molecule* Mol);
00290 bool HasImplicitElectronPairs ();
00294 bool MayHaveImplicitUnpairedElectrons ();
00300 void AddElectron (Electron* electron);
00306 void RemoveElectron (Electron* electron);
00313 void NotifyPositionOccupation (unsigned char pos, bool occupied);
00322 void SetChargePosition (unsigned char Pos, bool def, double angle = 0., double distance = 0.);
00329 char GetChargePosition (double *Angle, double *Dist) const;
00335 void SetCharge (int charge);
00339 int GetCharge () const {return m_Charge;}
00343 void ForceChanged () {m_Changed = true;}
00354 bool Match (gcu::Atom *atom, gcu::AtomMatchState &state);
00355
00368 void GetSymbolGeometry (double &width, double &height, double &angle, bool up) const;
00369
00374 bool HasAvailableElectrons (bool paired);
00375
00381 Bond *GetBondAtAngle (double angle);
00382
00383 protected:
00391 void BuildSymbolGeometry (double width, double height, double ascent);
00392
00393 private:
00394 void UpdateAvailablePositions ();
00395
00396 private:
00397 gcu::Element *m_Element;
00398 int m_nH;
00399 int m_Valence;
00400 int m_ValenceOrbitals;
00401 int m_nlp;
00402 int m_nlu;
00403 double m_width, m_height;
00404 double m_length, m_text_height;
00405 HPos m_HPos;
00406 bool m_ChargeAuto;
00407 int m_Changed;
00408 int m_ascent;
00409 double m_lbearing;
00410 unsigned char m_AvailPos;
00411 unsigned char m_OccupiedPos;
00412 bool m_AvailPosCached;
00413 unsigned char m_ChargePos;
00414 bool m_ChargeAutoPos;
00415 double m_ChargeAngle;
00416 double m_ChargeDist;
00417 double m_ChargeWidth, m_ChargeTWidth, m_ChargeXOffset, m_ChargeYOffset;
00418 std::list<double> m_AngleList;
00419 std::map<double, double> m_InterBonds;
00420
00421 PangoLayout *m_Layout, *m_ChargeLayout, *m_HLayout;
00422 double m_xHOffs, m_yHOffs;
00423 bool m_DrawCircle;
00424 std::string m_FontName;
00425 double m_SWidth, m_SHeightH, m_SHeightL, m_SAngleH, m_SAngleL;
00426
00427 double m_xROffs, m_yROffs;
00428
00429 protected:
00433 double m_CHeight;
00434
00446 GCU_PROP (bool, ShowSymbol)
00447
00448
00459 GCU_PROP (HPos, HPosStyle)
00471 GCU_POINTER_PROP (gccv::Item, ChargeItem)
00483 GCU_PROP (bool, ShowCharge);
00484 };
00485
00486 }
00487
00488 #endif // GCHEMPAINT_ATOM_H