MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/vtk/text2d.h
Go to the documentation of this file.
00001 /************************************************************************
00002  * MechSys - Open Library for Mechanical Systems                        *
00003  * Copyright (C) 2005 Dorival M. Pedroso, Raúl D. D. Farfan             *
00004  *                                                                      *
00005  * This program is free software: you can redistribute it and/or modify *
00006  * it under the terms of the GNU General Public License as published by *
00007  * the Free Software Foundation, either version 3 of the License, or    *
00008  * any later version.                                                   *
00009  *                                                                      *
00010  * This program is distributed in the hope that it will be useful,      *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         *
00013  * GNU General Public License for more details.                         *
00014  *                                                                      *
00015  * You should have received a copy of the GNU General Public License    *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>  *
00017  ************************************************************************/
00018 
00019 #ifndef MECHSYS_TEXT2D_H
00020 #define MECHSYS_TEXT2D_H
00021 
00022 // VTK
00023 #include <vtkTextActor.h>
00024 #include <vtkTextProperty.h>
00025 
00026 // MechSys
00027 #include <mechsys/vtk/win.h>
00028 #include <mechsys/util/colors.h>
00029 
00030 namespace VTK
00031 {
00032 
00033 class Text2D
00034 {
00035 public:
00036     // Constructor & Destructor
00037      Text2D () { _create(); }
00038     ~Text2D ();
00039 
00040     // Alternative constructor
00041     Text2D (int x, int y, char const * Txt) { _create();  SetPos(x,y);  SetText(Txt); }
00042 
00043     // Set methods
00044     Text2D & SetText  (char const * Txt)                 { _text_actor->SetInput    (Txt);  return (*this); }
00045     Text2D & SetPos   (int x, int y)                     { _text_actor->SetPosition2(x,y);  return (*this); }
00046     Text2D & SetProps (int SizePt=18, bool Shadow=false);
00047     Text2D & SetColor (char const * Name="black");
00048 
00049     // Methods
00050     void AddTo (VTK::Win & win) { win.AddActor(reinterpret_cast<vtkActor*>(_text_actor)); }
00051 
00052 private:
00053     vtkTextActor    * _text_actor;
00054     vtkTextProperty * _text_prop;
00055     void _create ();
00056 };
00057 
00058 
00060 
00061 
00062 inline Text2D::~Text2D ()
00063 {
00064     _text_actor -> Delete();
00065     _text_prop  -> Delete();
00066 }
00067 
00068 inline Text2D & Text2D::SetProps (int SizePt, bool Shadow)
00069 {
00070     _text_prop -> SetFontSize (SizePt);
00071     _text_prop -> SetShadow   (Shadow);
00072     return (*this);
00073 }
00074 
00075 inline Text2D & Text2D::SetColor (char const * Name)
00076 {
00077     Vec3_t c(Colors::Get(Name));
00078     _text_prop->SetColor (c.data());
00079     return (*this);
00080 }
00081 
00082 inline void Text2D::_create ()
00083 {
00084     _text_prop  = vtkTextProperty ::New();
00085     _text_actor = vtkTextActor    ::New();
00086     _text_actor -> SetTextProperty (_text_prop);
00087     SetProps ();
00088     SetColor ();
00089 }
00090 
00091 }; // namespace VTK
00092 
00093 #endif // MECHSYS_TEXT2D_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines