selectcallback.h

00001 /*************************************************************************************
00002  * MechSys - A C++ library to simulate (Continuum) Mechanical Systems                *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>       *
00004  * Copyright (C) 2005 Raul Dario Durand Farfan  <raul.durand at gmail.com>           *
00005  *                                                                                   *
00006  * This file is part of MechSys.                                                     *
00007  *                                                                                   *
00008  * MechSys is free software; you can redistribute it and/or modify it under the      *
00009  * terms of the GNU General Public License as published by the Free Software         *
00010  * Foundation; either version 2 of the License, or (at your option) any later        *
00011  * version.                                                                          *
00012  *                                                                                   *
00013  * MechSys is distributed in the hope that it will be useful, but WITHOUT ANY        *
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   *
00015  * PARTICULAR PURPOSE. See the GNU General Public License for more details.          *
00016  *                                                                                   *
00017  * You should have received a copy of the GNU General Public License along with      *
00018  * MechSys; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
00019  * Fifth Floor, Boston, MA 02110-1301, USA                                           *
00020  *************************************************************************************/
00021 
00022 #ifndef MECHSYS_SELECTCALLBACK_H
00023 #define MECHSYS_SELECTCALLBACK_H
00024 
00025 // VTK
00026 #include "vtkCommand.h"
00027 #include "vtkRenderer.h"
00028 #include "vtkBorderRepresentation.h"
00029 #include "vtkSelectVisiblePoints.h"
00030 #include "vtkObject.h"
00031 #include "vtkCoordinate.h"
00032 
00033 class SelectCallBack : public vtkCommand
00034 {
00035 public:
00036     // Constructor
00037     SelectCallBack() : _ren(NULL), _bord_repr(NULL), _vis_pts1(NULL), _vis_pts2(NULL) {}
00038 
00039     // Methods
00040     void Setup(vtkRenderer            * Ren    , vtkBorderRepresentation * BordRepr,
00041                vtkSelectVisiblePoints * VisPts1, vtkSelectVisiblePoints  * VisPts2=NULL);
00042     void Execute(vtkObject * Caller, unsigned long eventId, void *);
00043 
00044     // Static
00045     static SelectCallBack * New() { return new SelectCallBack; }
00046 
00047 private:
00048     // Data
00049     vtkRenderer             * _ren;
00050     vtkBorderRepresentation * _bord_repr;
00051     vtkSelectVisiblePoints  * _vis_pts1;
00052     vtkSelectVisiblePoints  * _vis_pts2;
00053     int                     * _C1;
00054     int                     * _C2;
00055 
00056     // Private Methods
00057     void _update_coords();
00058 
00059 }; // class SelectCallBack
00060 
00061 
00063 
00064 
00065 inline void SelectCallBack::Setup(vtkRenderer            * Ren    , vtkBorderRepresentation * BordRepr, // {{{
00066                                   vtkSelectVisiblePoints * VisPts1, vtkSelectVisiblePoints  * VisPts2 )
00067 {
00068     _ren       = Ren;
00069     _bord_repr = BordRepr;
00070     _vis_pts1  = VisPts1;
00071     _vis_pts2  = VisPts2;
00072     _update_coords();
00073     if (_vis_pts1!=NULL) _vis_pts1 -> SetSelection(_C1[0],_C2[0],_C1[1],_C2[1]);
00074     if (_vis_pts2!=NULL) _vis_pts2 -> SetSelection(_C1[0],_C2[0],_C1[1],_C2[1]);
00075 } // }}}
00076 
00077 inline void SelectCallBack::Execute(vtkObject * Caller, unsigned long eventId, void *) // {{{
00078 {
00079     if (_ren!=NULL && _bord_repr!=NULL)
00080     {
00081         _update_coords();
00082         if (_vis_pts1!=NULL) _vis_pts1 -> SetSelection(_C1[0],_C2[0],_C1[1],_C2[1]);
00083         if (_vis_pts2!=NULL) _vis_pts2 -> SetSelection(_C1[0],_C2[0],_C1[1],_C2[1]);
00084     }
00085 } // }}}
00086 
00087 inline void SelectCallBack::_update_coords() // {{{
00088 {
00089     vtkCoordinate * c1 = _bord_repr->GetPositionCoordinate();
00090     vtkCoordinate * c2 = _bord_repr->GetPosition2Coordinate();
00091                    _C1 = c1->GetComputedDisplayValue(_ren);
00092                    _C2 = c2->GetComputedDisplayValue(_ren);
00093     /*
00094     std::cout << "  X1=" << _C1[0] << ", Y1=" << _C1[1];
00095     std::cout << ", X2=" << _C2[0] << ", Y2=" << _C2[1];
00096     std::cout << std::endl;
00097     */
00098 } // }}}
00099 
00100 #endif // MECHSYS_SELECTCALLBACK_H
00101 
00102 // vim:fdm=marker

Generated on Wed Jan 24 15:56:28 2007 for MechSys by  doxygen 1.4.7