]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx
It works !! Basic D&D and creation of VTK rectangle... Good work
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / wxVtkSceneManager.cxx
1 /*=========================================================================                                                                               
2 Program:   bbtk
3 Module:    $RCSfile$
4 Language:  C++
5 Date:      $Date$
6 Version:   $Revision$
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32 *  \file 
33 *  \brief Class bbtk::wxVtkSceneManager . 
34 */
35
36
37 #include "wxVtkSceneManager.h"
38
39 namespace bbtk
40 {
41
42
43         //=========================================================================
44         wxVtkSceneManager::wxVtkSceneManager(wxDropTarget *parent, wxVtk3DBaseView *baseView,int id)
45         {
46                 _id=id;
47                 _baseView=baseView;
48                 if( _baseView!=NULL )
49                 {
50                         
51                         _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(parent);
52                         registerController(this);
53
54                         configureBaseView();
55
56                         vtkConeSource *cone = vtkConeSource::New();
57         
58                    cone->SetResolution(10);
59                         
60                    vtkPolyDataMapper *map = vtkPolyDataMapper::New();
61                    map->SetInput(cone->GetOutput());
62                         
63                    vtkActor *act = vtkActor::New();
64                         
65                    act->SetMapper(map);
66                         
67                         /////////////////////
68
69
70                    vtkPoints *_pts = vtkPoints::New();
71                         _pts->SetNumberOfPoints(4);
72
73                         _pts->SetPoint(0, -1    , -1    , 0 );
74                         _pts->SetPoint(1,  1    , -1    , 0 );
75                         _pts->SetPoint(2,  1    ,  1    , 0 );
76                         _pts->SetPoint(3, -1    ,  1    , 0 );
77         
78                         vtkCellArray *lines = vtkCellArray::New();
79                         lines->InsertNextCell(5);
80                         lines->InsertCellPoint(0);
81                         lines->InsertCellPoint(1);
82                         lines->InsertCellPoint(2);
83                         lines->InsertCellPoint(3);
84                         lines->InsertCellPoint(0);
85
86                         vtkPolyData *_pd = vtkPolyData::New();
87                         _pd->SetPoints( _pts );
88                         _pd->SetLines( lines );
89
90                         vtkActor *_pointVtkActor        =       vtkActor::New();
91                         vtkPolyDataMapper* _bboxMapper          =       vtkPolyDataMapper::New();
92
93                         _bboxMapper->SetInput(_pd);
94                         _pointVtkActor->SetMapper(_bboxMapper);
95
96                         getRenderer()->AddActor(_pointVtkActor);
97
98
99
100                         /////////////////////
101
102                    //getRenderer()->AddActor(act);
103                 
104                    //getRenderer()->Render();
105
106
107                 }
108         }
109
110         //=========================================================================
111         void wxVtkSceneManager::disconnectDrop()
112         {
113                 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
114         }
115         //=========================================================================
116         wxVtkSceneManager::~wxVtkSceneManager()
117         {
118         }
119         //=========================================================================
120
121         void wxVtkSceneManager::configureBaseView()
122         {
123                 vtkInteractorStyleImage *temp = vtkInteractorStyleImage::New();
124                 _baseView->GetWxVTKRenderWindowInteractor()->SetInteractorStyle(temp);
125                 _baseView->GetRenderer()->SetActiveCamera(_baseView->GetCamera());
126             _baseView->GetRenderer()->ResetCamera ();
127                 _baseView->GetCamera()->SetParallelProjection(true);
128                 _baseView->Refresh();
129
130         }
131
132         //=========================================================================
133
134         void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
135         {
136                 int type = GBLACKBOX;
137
138                 //Create the MVC Objects
139                 GObjectModel *model = GObjectsMVCFactory::getInstance()->createGObjectModel(type);
140                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
141                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
142                 
143                 //Prepares the initial model
144                 double xx = x;
145                 double yy = y;
146                 double zz = 900;
147
148                 _baseView->TransCoordScreenToWorld(xx,yy,zz);
149
150                 //Associates the view with the correspondent renderer and the  model.
151                 //(NOTE: Refresh is only made by the view)
152                 model->setInicPoint(xx,yy,zz);
153                 view->setModel(model);
154                 view->setRenderer(_baseView->GetRenderer());
155                 view->initVtkObjects();
156                 
157                 //Refresh renderwindow with new objects
158                 refreshRenderWindow();
159
160                 //Associates the controller with the correspondent model and view
161                 controller->setModelAndView(model,view);
162                 
163                 registerController((InteractorStyleMaracas*) controller);
164         }
165
166         //=========================================================================
167
168         void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
169         {
170                 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
171                 baseViewControlManager->AddInteractorStyleMaracas( param );
172         }
173
174         //=========================================================================
175
176         vtkRenderer* wxVtkSceneManager::getRenderer()
177         {
178                 return _baseView->GetRenderer();
179         }
180
181         //=========================================================================
182
183         vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
184         {
185                 return _baseView->GetRenWin();
186         }
187         //=========================================================================
188         
189         void wxVtkSceneManager::refreshRenderWindow()
190         {
191                 _baseView->GetRenWin()->Render();
192         }
193         //=========================================================================
194
195         //=========================================================================
196 }  // EO namespace bbtk
197
198 // EOF
199