# gcp/bond.h

    00001 // -*- C++ -*-
    00002
    00003 /*
    00004  * GChemPaint library
    00005  * bond.h
    00006  *
    00007  * Copyright (C) 2001-2008 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
    00042 typedef enum
    00043 {
    00044         NormalBondType,
    00045         UpBondType,
    00046         DownBondType,
    00047         ForeBondType,
    00048         UndeterminedBondType
    00049 } BondType;
    00050
    00055 typedef struct {
    00059         double a;
    00063         bool is_before;
    00064 } BondCrossing;
    00065
    00066 class Atom;
    00067 class WidgetData;
    00068
    00073 class Bond: public gcu::Bond
    00074 {
    00075 public:
    00079         Bond ();
    00087         Bond (Atom* first, Atom* last, unsigned char order);
    00091         virtual ~Bond ();
    00092
    00101         Object* GetAtomAt (double x, double y, double z = 0.);
    00105         BondType GetType() const {return m_type;}
    00111         void SetType (BondType type);
    00118         double GetAngle2D (Atom* pAtom);
    00124         void AddCycle (gcu::Cycle* pCycle);
    00130         void RemoveCycle (gcu::Cycle* pCycle);
    00134         void RemoveAllCycles ();
    00146         bool GetLine2DCoords (unsigned Num, double* x1, double* y1, double* x2, double* y2);
    00154         virtual bool SaveNode (xmlDocPtr xml, xmlNodePtr node) const;
    00160         bool LoadNode (xmlNodePtr node);
    00166         void Update (GtkWidget* w) const;
    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);
    00220         void SetSelected (GtkWidget* w, int state);
    00226         void Add (GtkWidget* w) const;
    00231         double GetYAlign ();
    00239         bool IsCrossing (Bond *pBond);
    00248         bool BuildContextualMenu (GtkUIManager *UIManager, Object *object, double x, double y);
    00252         void MoveToBack ();
    00256         void BringToFront ();
    00265         bool SetProperty (unsigned property, char const *value);
    00266
    00267 private:
    00268         GnomeCanvasPathDef* BuildPathDef (WidgetData* pData);
    00269         GnomeCanvasPathDef* BuildCrossingPathDef (WidgetData* pData);
    00270         BondType m_type;
    00271         double m_coords[16];//coordinates of the lines used to represent the bond in the canvas
    00272         bool m_CoordsCalc; //true if m_coords have been calculated, false else
    00273         std::map<Bond*, BondCrossing> m_Crossing;
    00274         int m_level; // to know which bond should be considered front
    00275 };
    00276
    00277 }       //      namespace gcp
    00278
    00279 #endif // GCHEMPAINT_BOND_H