]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBoxView.cxx
b60742e1f4ff459a654d75371eebdeacce7274fc
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsVtkGUIEditorGraphic / vtkGBoxView.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------  
24 */
25
26 /*=========================================================================                                                                               
27 Program:   bbtk
28 Module:    $RCSfile$
29 Language:  C++
30 Date:      $Date$
31 Version:   $Revision$
32 =========================================================================*/
33
34 /* ---------------------------------------------------------------------
35
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
38 *
39 *  This software is governed by the CeCILL-B license under French law and 
40 *  abiding by the rules of distribution of free software. You can  use, 
41 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
42 *  license as circulated by CEA, CNRS and INRIA at the following URL 
43 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
44 *  or in the file LICENSE.txt.
45 *
46 *  As a counterpart to the access to the source code and  rights to copy,
47 *  modify and redistribute granted by the license, users are provided only
48 *  with a limited warranty  and the software's author,  the holder of the
49 *  economic rights,  and the successive licensors  have only  limited
50 *  liability. 
51 *
52 *  The fact that you are presently reading this means that you have had
53 *  knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */                                                                         
55
56 /**
57 *  \file 
58 *  \brief Class bbtk::vtkGBoxView 
59 */
60
61
62 #include "vtkGBoxView.h"
63
64 namespace bbtk
65 {
66
67
68         //=========================================================================
69         vtkGBoxView::vtkGBoxView()
70         {                       
71         }
72
73         //=========================================================================
74         vtkGBoxView::~vtkGBoxView()
75         {
76         }
77
78         //=========================================================================
79         void vtkGBoxView::update(int idController,int command)
80         {
81                 updateColors();
82                 
83                 double xInic, yInic,zInic,xFin, yFin,zFin;
84                 _model->getInicPoint(xInic,yInic,zInic);
85                 _model->getFinalPoint(xFin, yFin,zFin);
86
87                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
88
89                 _pts->SetPoint(0, xInic, yInic, zInic );
90                 _pts->SetPoint(1, xInic, yFin, zInic );
91                 _pts->SetPoint(2, xFin, yFin, zFin );
92                 _pts->SetPoint(3, xFin, yInic, zFin );
93
94                 updatePorts();
95
96                 _borderPolyMapper->Modified();
97                 _fillPolyMapper->Modified();
98                 //-----------
99
100                 //-----------
101                 setRefreshWaiting();
102         }
103
104         //=========================================================================
105
106         void vtkGBoxView::createVtkObjects() //virtual
107         {
108
109                 //------------
110                 _pts                            = vtkPoints::New();     
111                 vtkCellArray *lines = vtkCellArray::New();
112                 vtkPolyData *_pd        = vtkPolyData::New();
113                 _borderPolyMapper       = vtkPolyDataMapper::New();
114                 _borderObjectActor      = vtkActor::New();
115                                 
116                 _pts->SetNumberOfPoints(4);
117
118                 double xInic, yInic,zInic,xFin, yFin,zFin;
119                 _model->getInicPoint(xInic,yInic,zInic);
120                 _model->getFinalPoint(xFin, yFin,zFin);
121
122                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
123
124 //EED           _pts->SetPoint(0, xInic, yInic, zInic );
125 //EED           _pts->SetPoint(1, xInic, yFin, zInic );
126 //EED           _pts->SetPoint(2, xFin, yFin, zFin );
127 //EED           _pts->SetPoint(3, xFin, yInic, zFin );
128
129                 _pts->SetPoint(0, -1000, -1000, -1000 );
130                 _pts->SetPoint(1, xInic, yFin, zInic );
131                 _pts->SetPoint(2, 1000, 1000, 1000 );
132                 _pts->SetPoint(3, xFin, yInic, zFin );
133                 
134                 
135                 
136                 lines->InsertNextCell(5);
137                 lines->InsertCellPoint(0);
138                 lines->InsertCellPoint(1);
139                 lines->InsertCellPoint(2);
140                 lines->InsertCellPoint(3);
141                 lines->InsertCellPoint(0);
142                         
143                 _pd->SetPoints( _pts );
144                 _pd->SetLines( lines );
145
146                 _borderPolyMapper->SetInput(_pd);
147                 _borderObjectActor->SetMapper(_borderPolyMapper);
148                 _borderPolyMapper->Modified();
149
150                 
151                 ///************************* FILL *************************
152
153                 vtkCellArray *strip             = vtkCellArray::New();
154                 vtkPolyData *pdFill             = vtkPolyData::New();
155                 _fillPolyMapper                 = vtkPolyDataMapper::New();
156                 _fillObjectActor                = vtkActor::New();
157
158                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
159
160                 strip->InsertNextCell(5);
161                 strip->InsertCellPoint(0);
162                 strip->InsertCellPoint(1);
163                 strip->InsertCellPoint(2);
164                 strip->InsertCellPoint(0);
165                 strip->InsertCellPoint(3);
166                         
167                 pdFill->SetPoints( _pts );
168                 pdFill->SetStrips( strip );
169
170                 _fillPolyMapper->SetInput(pdFill);
171                 _fillObjectActor->SetMapper(_fillPolyMapper);
172                 _fillPolyMapper->Modified();
173
174                 ///************************* FILL *************************
175
176         }
177
178         //=========================================================================
179
180         void vtkGBoxView::addVtkActors()//virtual
181         {
182                 _baseView->GetRenderer()->AddActor(_borderObjectActor);
183                 vtkGObjectView::addVtkActors();
184         }
185
186         //=========================================================================
187
188         void vtkGBoxView::removeVtkActors()//virtual
189         {
190                 _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
191                 vtkGObjectView::removeVtkActors();
192         }
193
194         //=========================================================================
195
196         void vtkGBoxView::updateColors()
197         {
198                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
199
200                 if(_state==NOTHING_HAPPENS)
201                 {
202                         _borderObjectActor->GetProperty()->SetLineWidth(1);
203                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
204                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
205                         
206                 }
207                 else if(_state==HIGHLIGHTED)
208                 {
209                         _borderObjectActor->GetProperty()->SetLineWidth(2);
210                         
211                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
212                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
213                 }
214                 else if(_state==DRAG)
215                 {
216                         _borderObjectActor->GetProperty()->SetLineWidth(1.2);
217                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
218                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
219                 }
220                 else if(_state==SELECTED)
221                 {
222                         _borderObjectActor->GetProperty()->SetLineWidth(2);
223                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
224                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
225                 }
226         }
227
228         //=========================================================================
229
230         void vtkGBoxView::updatePorts()
231         {
232                 GBoxModel* bmod =(GBoxModel*)_model;
233                 bmod->updatePorts();
234         }
235
236         //=========================================================================
237
238 }  // EO namespace bbtk
239
240 // EOF
241