The Gnome Chemistry Utils  0.14.0
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 <glib.h>
30 #include <gccv/item-client.h>
31 #include <gccv/structs.h>
32 #include <gcu/atom.h>
33 #include <gcu/dialog-owner.h>
34 #include <gcu/element.h>
35 #include <gcu/macros.h>
36 
39 namespace gcu {
40 class UIManager;
41 }
42 
43 namespace gcp {
44 
45 class Bond;
46 class Molecule;
47 
51 #define POSITION_NE 1
52 
55 #define POSITION_NW 2
56 
59 #define POSITION_N 4
60 
63 #define POSITION_SE 8
64 
67 #define POSITION_SW 16
68 
71 #define POSITION_S 32
72 
75 #define POSITION_E 64
76 
79 #define POSITION_W 128
80 
85 typedef enum {
106 } HPos;
107 
108 class Electron;
109 
113 class Atom: public gcu::Atom, public gcu::DialogOwner, public gccv::ItemClient
114 {
115 public:
119  Atom ();
128  Atom (int Z, double x, double y, double z);
132  virtual ~Atom ();
133 
134 public :
140  virtual void SetZ (int Z);
146  void AddBond (gcu::Bond* pBond);
152  void RemoveBond (gcu::Bond* pBond);
156  virtual void Update ();
160  int GetTotalBondsNumber () const; //take bond order into account
164  int GetAttachedHydrogens () const {return m_nH;}
169  HPos GetBestSide ();
182  virtual gccv::Anchor GetChargePosition (unsigned char& Pos, double Angle, double& x, double& y);
192  virtual int GetAvailablePosition (double& x, double& y);
202  virtual bool GetRelativePosition (double angle, double& x, double& y);
212  virtual bool GetPosition (double angle, double& x, double& y);
219  virtual xmlNodePtr Save (xmlDocPtr xml) const;
226  virtual bool Load (xmlNodePtr node);
232  virtual bool LoadNode (xmlNodePtr node);
236  void AddItem ();
244  void SetSelected (int state);
250  virtual bool AcceptNewBonds (int nb = 1);
256  virtual bool AcceptCharge (int charge);
260  virtual double GetYAlign ();
268  virtual void Move (double x, double y, double z = 0.);
276  virtual void Transform2D (gcu::Matrix2D& m, double x, double y);
285  bool BuildContextualMenu (gcu::UIManager *UIManager, Object *object, double x, double y);
291  virtual void AddToMolecule (Molecule* Mol);
295  bool HasImplicitElectronPairs ();
305  void AddElectron (Electron* electron);
311  void RemoveElectron (Electron* electron);
318  void NotifyPositionOccupation (unsigned char pos, bool occupied);
327  void SetChargePosition (unsigned char Pos, bool def, double angle = 0., double distance = 0.);
334  char GetChargePosition (double *Angle, double *Dist) const;
340  void SetCharge (int charge);
344  int GetCharge () const {return m_Charge;}
348  void ForceChanged () {m_Changed = true;}
359  bool Match (gcu::Atom *atom, gcu::AtomMatchState &state);
360 
373  void GetSymbolGeometry (double &width, double &height, double &angle, bool up) const;
374 
379  bool HasAvailableElectrons (bool paired);
380 
386  Bond *GetBondAtAngle (double angle);
387 
392  bool UpdateStereoBonds ();
396  bool HasStereoBond () const;
401  Bond *GetNewmanBond () const;
402 
403 protected:
411  void BuildSymbolGeometry (double width, double height, double ascent);
412 
420  bool SetProperty (unsigned property, char const *value);
421 
422 private:
423  void UpdateAvailablePositions ();
424 
425 private:
426  gcu::Element *m_Element;
427  int m_nH;
428  int m_Valence; //valence
429  int m_ValenceOrbitals;
430  int m_nlp; //lone electron pairs number
431  int m_nlu; //single electrons number
432  double m_width, m_height; //size of the atomic symbol in the canvas
433  double m_length, m_text_height; // size of the text buffer
434  HPos m_HPos; //0 = left, 1 = right, 2 = top, 3 = bottom, 4 = auto
435  bool m_ChargeAuto;
436  int m_Changed; //update needs regenerate the buffer
437  int m_ascent;
438  double m_lbearing;
439  unsigned char m_AvailPos; //available standard positions for charge and electrons representations
440  unsigned char m_OccupiedPos;
441  bool m_AvailPosCached;
442  unsigned char m_ChargePos;
443  bool m_ChargeAutoPos;
444  double m_ChargeAngle;
445  double m_ChargeDist;
446  double m_ChargeWidth, m_ChargeTWidth, m_ChargeXOffset, m_ChargeYOffset;
447  std::list<double> m_AngleList;
448  std::map<double, double> m_InterBonds; /* positions betwen bonds. First value is the
449  angle between the two bonds and second value is the direction */
450  PangoLayout *m_Layout, *m_ChargeLayout, *m_HLayout;
451  double m_xHOffs, m_yHOffs;
452  bool m_DrawCircle;
453  std::string m_FontName;
454  double m_SWidth, m_SHeightH, m_SHeightL, m_SAngleH, m_SAngleL;
455  // special offset for underlying rectangle; will be removed in next version
456  double m_xROffs, m_yROffs;
457 
458  // atom parity stuff
459  Atom *m_Bonded[4]; // always using positive parity
460 
461 protected:
465  double m_CHeight;
466 
478 GCU_PROP (bool, ShowSymbol)
479 
480 
491 GCU_PROP (HPos, HPosStyle) //0=force left, 1=force right, 2=force top, 3=force bottom, 4=auto.
503 GCU_POINTER_PROP (gccv::Item, ChargeItem)
515 GCU_PROP (bool, ShowCharge);
516 };
517 
518 } // namespace gcp
519 
520 #endif // GCHEMPAINT_ATOM_H