gcp/bond.h

00001 // -*- C++ -*-
00002 
00003 /* 
00004  * GChemPaint library
00005  * bond.h 
00006  *
00007  * Copyright (C) 2001-2006 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 
00028 #include <gcu/bond.h>
00029 #include <list>
00030 #include <libgnomecanvas/gnome-canvas-path-def.h>
00031         
00032 using namespace gcu;
00033 
00034 namespace gcp {
00035 
00036 typedef enum
00037 {
00038         NormalBondType,
00039         UpBondType,
00040         DownBondType,
00041         ForeBondType,
00042         UndeterminedBondType
00043 } BondType;
00044 
00045 typedef struct {
00046         double a;
00047         bool is_before;
00048 } BondCrossing;
00049 
00050 class Atom;
00051 class Cycle;
00052 class WidgetData;
00053 
00054 class Bond: public gcu::Bond
00055 {
00056 public:
00057         Bond ();
00058         Bond (Atom* first, Atom* last, unsigned char order);
00059         virtual ~Bond ();
00060 
00061         virtual Object* GetAtomAt (double x, double y, double z = 0.);
00062         BondType GetType() {return m_type;}
00063         void SetType (BondType type);
00064         double GetAngle2D (Atom* pAtom);
00065         double GetAngle2DRad (Atom* pAtom);
00066         void AddCycle (Cycle* pCycle);
00067         void RemoveCycle (Cycle* pCycle);
00068         void RemoveAllCycles ();
00069         unsigned IsCyclic () {return m_Cycles.size ();}
00070         Cycle* GetFirstCycle (std::list<Cycle*>::iterator& i, Cycle * pCycle);
00071         Cycle* GetNextCycle (std::list<Cycle*>::iterator& i, Cycle * pCycle);
00072         bool IsInCycle (Cycle* pCycle);
00073         bool GetLine2DCoords (unsigned Num, double* x1, double* y1, double* x2, double* y2);
00074         virtual bool SaveNode (xmlDocPtr xml, xmlNodePtr);
00075         virtual bool LoadNode (xmlNodePtr);
00076         virtual void Update (GtkWidget* w);
00077         virtual void Move (double x, double y, double z = 0);
00078         virtual void Transform2D (Matrix2D& m, double x, double y);
00079         double GetDist (double x, double y);
00080         void SetDirty ();
00081         void Revert ();
00082         double Get2DLength ();
00083         void IncOrder (int n = 1);
00084         virtual void SetSelected (GtkWidget* w, int state);
00085         void Add (GtkWidget* w);
00086         bool ReplaceAtom (Atom* oldAtom, Atom* newAtom);
00087         virtual double GetYAlign ();
00088         bool IsCrossing (Bond *pBond);
00089         bool BuildContextualMenu (GtkUIManager *UIManager, Object *object, double x, double y);
00090         void MoveToBack ();
00091         void BringToFront ();
00092 
00093 private:
00094         GnomeCanvasPathDef* BuildPathDef (WidgetData* pData);
00095         GnomeCanvasPathDef* BuildCrossingPathDef (WidgetData* pData);
00096 
00097 protected:
00098         BondType m_type;
00099         double m_coords[16];//coordinates of the lines used to represent the bond in the canvas
00100         bool m_CoordsCalc; //true if m_coords have been calculated, false else
00101         list<Cycle*> m_Cycles;
00102         map<Bond*, BondCrossing> m_Crossing;
00103         int m_level; // to know which bond shouldbe considered front
00104 };
00105 
00106 }       //      namespace gcp
00107 
00108 #endif // GCHEMPAINT_BOND_H

Generated on Sun Sep 16 14:21:55 2007 for The Gnome Chemistry Utils by  doxygen 1.5.3