The Gnome Chemistry Utils  0.15.1
gcp/atom.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  * GChemPaint library
5  * atom.h
6  *
7  * Copyright (C) 2001-2012 Jean Bréfort <jean.brefort@normalesup.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 3 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #ifndef GCHEMPAINT_ATOM_H
26 #define GCHEMPAINT_ATOM_H
27 
28 #include <map>
29 #include <string>
30 #include <glib.h>
31 #include <gccv/item-client.h>
32 #include <gccv/structs.h>
33 #include <gcu/atom.h>
34 #include <gcu/dialog-owner.h>
35 #include <gcu/element.h>
36 #include <gcu/macros.h>
37 
40 namespace gcu {
41 class UIManager;
42 }
43 
44 namespace gcp {
45 
46 class Bond;
47 class Molecule;
48 
52 #define POSITION_NE 1
53 
56 #define POSITION_NW 2
57 
60 #define POSITION_N 4
61 
64 #define POSITION_SE 8
65 
68 #define POSITION_SW 16
69 
72 #define POSITION_S 32
73 
76 #define POSITION_E 64
77 
80 #define POSITION_W 128
81 
86 typedef enum {
107 } HPos;
108 
109 class Electron;
110 
114 class Atom: public gcu::Atom, public gcu::DialogOwner, public gccv::ItemClient
115 {
116 public:
120  Atom ();
129  Atom (int Z, double x, double y, double z);
133  virtual ~Atom ();
134 
135 public :
141  virtual void SetZ (int Z);
147  void AddBond (gcu::Bond* pBond);
153  void RemoveBond (gcu::Bond* pBond);
157  virtual void Update ();
161  int GetTotalBondsNumber () const; //take bond order into account
165  int GetAttachedHydrogens () const {return m_nH;}
170  HPos GetBestSide ();
183  virtual gccv::Anchor GetChargePosition (unsigned char& Pos, double Angle, double& x, double& y);
193  virtual int GetAvailablePosition (double& x, double& y);
203  virtual bool GetRelativePosition (double angle, double& x, double& y);
213  virtual bool GetPosition (double angle, double& x, double& y);
220  virtual xmlNodePtr Save (xmlDocPtr xml) const;
227  virtual bool Load (xmlNodePtr node);
233  virtual bool LoadNode (xmlNodePtr node);
237  void AddItem ();
245  void SetSelected (int state);
251  virtual bool AcceptNewBonds (int nb = 1);
257  virtual bool AcceptCharge (int charge);
261  virtual double GetYAlign ();
269  virtual void Move (double x, double y, double z = 0.);
277  virtual void Transform2D (gcu::Matrix2D& m, double x, double y);
286  bool BuildContextualMenu (gcu::UIManager *UIManager, Object *object, double x, double y);
292  virtual void AddToMolecule (Molecule* Mol);
296  bool HasImplicitElectronPairs ();
306  void AddElectron (Electron* electron);
312  void RemoveElectron (Electron* electron);
319  void NotifyPositionOccupation (unsigned char pos, bool occupied);
328  void SetChargePosition (unsigned char Pos, bool def, double angle = 0., double distance = 0.);
335  char GetChargePosition (double *Angle, double *Dist) const;
341  void SetCharge (int charge);
345  int GetCharge () const {return m_Charge;}
349  void ForceChanged () {m_Changed = true;}
360  bool Match (gcu::Atom *atom, gcu::AtomMatchState &state);
361 
374  void GetSymbolGeometry (double &width, double &height, double &angle, bool up) const;
375 
380  bool HasAvailableElectrons (bool paired);
381 
387  Bond *GetBondAtAngle (double angle);
388 
393  bool UpdateStereoBonds ();
397  bool HasStereoBond () const;
402  Bond *GetNewmanBond () const;
403 
404 protected:
412  void BuildSymbolGeometry (double width, double height, double ascent);
413 
421  bool SetProperty (unsigned property, char const *value);
422 
423 private:
424  void UpdateAvailablePositions ();
425 
426 private:
427  gcu::Element *m_Element;
428  int m_nH;
429  int m_Valence; //valence
430  int m_ValenceOrbitals;
431  int m_nlp; //lone electron pairs number
432  int m_nlu; //single electrons number
433  double m_width, m_height; //size of the atomic symbol in the canvas
434  double m_length, m_text_height; // size of the text buffer
435  HPos m_HPos; //0 = left, 1 = right, 2 = top, 3 = bottom, 4 = auto
436  bool m_ChargeAuto;
437  int m_Changed; //update needs regenerate the buffer
438  int m_ascent;
439  double m_lbearing;
440  unsigned char m_AvailPos; //available standard positions for charge and electrons representations
441  unsigned char m_OccupiedPos;
442  bool m_AvailPosCached;
443  unsigned char m_ChargePos;
444  bool m_ChargeAutoPos;
445  double m_ChargeAngle;
446  double m_ChargeDist;
447  double m_ChargeWidth, m_ChargeTWidth, m_ChargeXOffset, m_ChargeYOffset;
448  std::list<double> m_AngleList;
449  std::map<double, double> m_InterBonds; /* positions betwen bonds. First value is the
450  angle between the two bonds and second value is the direction */
451  PangoLayout *m_Layout, *m_ChargeLayout, *m_HLayout;
452  double m_xHOffs, m_yHOffs;
453  bool m_DrawCircle;
454  std::string m_FontName;
455  double m_SWidth, m_SHeightH, m_SHeightL, m_SAngleH, m_SAngleL;
456  // special offset for underlying rectangle; will be removed in next version
457  double m_xROffs, m_yROffs;
458 
459  // atom parity stuff
460  Atom *m_Bonded[4]; // always using positive parity
461 
462 protected:
466  double m_CHeight;
467 
479 GCU_PROP (bool, ShowSymbol)
480 
481 
492 GCU_PROP (HPos, HPosStyle) //0=force left, 1=force right, 2=force top, 3=force bottom, 4=auto.
504 GCU_POINTER_PROP (gccv::Item, ChargeItem)
516 GCU_PROP (bool, ShowCharge)
517 GCU_PROP (std::string, Index)
518 };
519 
520 } // namespace gcp
521 
522 #endif // GCHEMPAINT_ATOM_H
the base class for objects associated with a canvas item.
Definition: item-client.h:44
virtual void SetZ(int Z)
void SetChargePosition(unsigned char Pos, bool def, double angle=0., double distance=0.)
virtual void Update()
int GetCharge() const
Definition: gcp/atom.h:345
void RemoveElectron(Electron *electron)
bool HasAvailableElectrons(bool paired)
void AddBond(gcu::Bond *pBond)
HPos
Definition: gcp/atom.h:86
virtual bool AcceptNewBonds(int nb=1)
virtual bool GetRelativePosition(double angle, double &x, double &y)
virtual bool GetPosition(double angle, double &x, double &y)
bool SetProperty(unsigned property, char const *value)
Bond * GetBondAtAngle(double angle)
virtual bool AcceptCharge(int charge)
GChemPaint molecule class.
Definition: gcp/molecule.h:45
bool HasImplicitElectronPairs()
Bond * GetNewmanBond() const
void SetSelected(int state)
Object(TypeId Id=OtherType)
virtual int GetAvailablePosition(double &x, double &y)
void NotifyPositionOccupation(unsigned char pos, bool occupied)
base class for a user interface manager
Definition: ui-manager.h:33
void AddElectron(Electron *electron)
virtual bool LoadNode(xmlNodePtr node)
double z() const
Definition: gcu/atom.h:159
bool UpdateStereoBonds()
void GetSymbolGeometry(double &width, double &height, double &angle, bool up) const
bool MayHaveImplicitUnpairedElectrons()
#define GCU_POINTER_PROP(type, member)
Definition: macros.h:121
void SetCharge(int charge)
void AddItem()
double m_CHeight
Definition: gcp/atom.h:466
void BuildSymbolGeometry(double width, double height, double ascent)
HPos GetBestSide()
virtual void Move(double x, double y, double z=0.)
virtual ~Atom()
bool HasStereoBond() const
virtual double GetYAlign()
bool Match(gcu::Atom *atom, gcu::AtomMatchState &state)
virtual gccv::Anchor GetChargePosition(unsigned char &Pos, double Angle, double &x, double &y)
virtual void Transform2D(gcu::Matrix2D &m, double x, double y)
virtual xmlNodePtr Save(xmlDocPtr xml) const
int GetAttachedHydrogens() const
Definition: gcp/atom.h:165
#define GCU_PROP(type, member)
Definition: macros.h:51
void RemoveBond(gcu::Bond *pBond)
Chemical element.
Definition: element.h:60
int GetTotalBondsNumber() const
double x() const
Definition: gcu/atom.h:149
double y() const
Definition: gcu/atom.h:154
virtual bool Load(xmlNodePtr node)
bool BuildContextualMenu(gcu::UIManager *UIManager, Object *object, double x, double y)
void ForceChanged()
Definition: gcp/atom.h:349
char m_Charge
Definition: gcu/atom.h:323
virtual void AddToMolecule(Molecule *Mol)