The Gnome Chemistry Utils 0.13.3
gcp/bond.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /* 
00004  * GChemPaint library
00005  * bond.h 
00006  *
00007  * Copyright (C) 2001-2011 Jean Bréfort <jean.brefort@normalesup.org>
00008  *
00009  * This program is free software; you can redistribute it and/or 
00010  * modify it under the terms of the GNU General Public License as 
00011  * published by the Free Software Foundation; either version 2 of the
00012  * License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00022  * USA
00023  */
00024 
00025 #ifndef GCHEMPAINT_BOND_H
00026 #define GCHEMPAINT_BOND_H
00027 
00030 #include <gccv/item-client.h>
00031 #include <gcu/bond.h>
00032 #include <list>
00033 
00034 namespace gcu {
00035 class UIManager;
00036 }
00037 
00038 namespace gcp {
00039 
00048 typedef enum
00049 {
00050         NormalBondType,
00051         UpBondType,
00052         DownBondType,
00053         ForeBondType,
00054         UndeterminedBondType
00055 } BondType;
00056 
00061 typedef struct {
00065         double a;
00069         bool is_before;
00070 } BondCrossing;
00071 
00072 class Atom;
00073 class WidgetData;
00074 
00079 class Bond: public gcu::Bond, public gccv::ItemClient
00080 {
00081 public:
00085         Bond ();
00093         Bond (Atom* first, Atom* last, unsigned char order);
00097         virtual ~Bond ();
00098 
00107         Object* GetAtomAt (double x, double y, double z = 0.);
00111         BondType GetType() const {return m_type;}
00117         void SetType (BondType type);
00124         double GetAngle2D (Atom* pAtom);
00130         void AddCycle (gcu::Cycle* pCycle);
00136         void RemoveCycle (gcu::Cycle* pCycle);
00140         void RemoveAllCycles ();
00152         bool GetLine2DCoords (unsigned Num, double* x1, double* y1, double* x2, double* y2);
00160         virtual bool SaveNode (xmlDocPtr xml, xmlNodePtr node) const;
00166         bool LoadNode (xmlNodePtr node);
00175         void Move (double x, double y, double z = 0);
00185         void Transform2D (gcu::Matrix2D& m, double x, double y);
00195         double GetDist (double x, double y);
00200         void SetDirty ();
00204         void Revert ();
00211         void IncOrder (int n = 1);
00215         void AddItem ();
00219         void UpdateItem ();
00227         void SetSelected (int state);
00232         double GetYAlign ();
00240         bool IsCrossing (Bond *pBond);
00249         bool BuildContextualMenu (gcu::UIManager *UIManager, Object *object, double x, double y);
00253         void MoveToBack ();
00257         void BringToFront ();
00264         std::string GetProperty (unsigned property) const;
00273         bool SetProperty (unsigned property, char const *value);
00274 
00283         void AdjustPosition (double &x, double &y);
00284 
00288         void OnLoaded ();
00289 
00290 private:
00291 //      GnomeCanvasPathDef* BuildPathDef (WidgetData* pData);
00292 //      GnomeCanvasPathDef* BuildCrossingPathDef (WidgetData* pData);
00293         BondType m_type;
00294         double m_coords[16];//coordinates of the lines used to represent the bond in the canvas
00295         bool m_CoordsCalc; //true if m_coords have been calculated, false else
00296         std::map<Bond*, BondCrossing> m_Crossing;
00297         int m_level; // to know which bond should be considered front
00298 };
00299 
00300 }       //      namespace gcp
00301 
00302 #endif // GCHEMPAINT_BOND_H