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

Generated on Thu Dec 20 11:20:45 2007 for The Gnome Chemistry Utils by  doxygen 1.5.4