The Gnome Chemistry Utils 0.13.3
fragment.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /* 
00004  * GChemPaint library
00005  * fragment.h 
00006  *
00007  * Copyright (C) 2002-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_FRAGMENT_H
00026 #define GCHEMPAINT_FRAGMENT_H
00027 
00028 #include "text-object.h"
00029 #include <gccv/item-client.h>
00030 #include <gccv/text-tag.h>
00031 
00032 namespace gccv {
00033         class Text;
00034 }
00035 
00037 namespace gcp {
00038 
00039 extern gccv::Tag ChargeTag, StoichiometryTag;
00040 
00047 class ChargeTextTag: public gccv::PositionTextTag
00048 {
00049 public:
00055         ChargeTextTag (double size);
00059         virtual ~ChargeTextTag ();
00060 
00067         TextTag *Restrict (TextTag *tag);
00068 };
00069 
00076 class StoichiometryTextTag: public gccv::PositionTextTag
00077 {
00078 public:
00084         StoichiometryTextTag (double size);
00088         virtual ~StoichiometryTextTag ();
00089 
00096         TextTag *Restrict (TextTag *tag);
00097 };
00098 
00099 class FragmentAtom;
00100 class Atom;
00101 
00109 class Fragment: public TextObject
00110 {
00111 public:
00115         Fragment ();
00123         Fragment (double x, double y);
00127         virtual ~Fragment ();
00128 
00132         void AddItem ();
00136         void UpdateItem ();
00144         void SetSelected (int state);
00151         xmlNodePtr Save (xmlDocPtr xml) const;
00159         xmlNodePtr SaveSelection (xmlDocPtr xml) const;
00166         bool Load (xmlNodePtr node);
00172         bool OnChanged (bool save);
00176         void AnalContent ();
00183         void AnalContent (unsigned start, unsigned &end);
00192         Object* GetAtomAt (double x, double y, double z = 0.);
00200         void Move (double x, double y, double z = 0);
00208         void Transform2D (gcu::Matrix2D& m, double x, double y);
00213         void OnChangeAtom ();
00217         Atom  *GetAtom () {return reinterpret_cast < Atom * > (m_Atom);}
00218         Atom const *GetAtom () const {return reinterpret_cast < Atom const * > (m_Atom);}
00226         int GetElementAtPos (unsigned start, unsigned &end);
00242         gccv::Anchor GetChargePosition (FragmentAtom *pAtom, unsigned char &Pos, double Angle, double &x, double &y);
00252         int GetAvailablePosition (double &x, double &y);
00260         bool GetPosition (double angle, double &x, double &y);
00264         bool Validate ();
00268         double GetYAlign ();
00269 
00279         bool SetProperty (unsigned property, char const *value);
00280 
00285         bool Analyze ();
00286 
00291         void Update ();
00292 
00296         gccv::Item *GetChargeItem ();
00297 
00301         std::string Name ();
00310         bool GetCoords (double *x, double *y, double *z = NULL) const;
00318         typedef enum {
00322                 Invalid,
00326                 Valid,
00330                 Valid2D,
00334                 Valid3D
00335         } Validity;
00336 
00343         typedef enum {
00347                 AutoMode,
00351                 NormalMode,
00355                 SubscriptMode,
00359                 SuperscriptMode,
00363                 ChargeMode,
00367                 StoichiometryMode
00368         } FragmentMode;
00369 
00370 private:
00371         bool SavePortion (xmlDocPtr xml, xmlNodePtr node, unsigned start, unsigned end) const;
00372 
00373 private:
00374         FragmentAtom *m_Atom;
00375         unsigned m_BeginAtom, m_EndAtom;
00376         double m_lbearing;
00377         double m_CHeight;
00378         bool m_Inversable;
00379 
00383 GCU_RO_PROP (Validity, Valid)
00395 GCU_PROP (FragmentMode, Mode)
00396 };
00397 
00398 }       //      namespace gcp
00399 
00400 #endif  //GCHEMPAINT_FRAGMENT_H