]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx
4dbbbedae0756badc45b963c919ec550c757dc85
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsVtkGUIEditorGraphic / vtkGBlackBoxView.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::vtkGBlackBoxView 
34 */
35
36
37 #include "vtkGBlackBoxView.h"
38
39 namespace bbtk
40 {
41
42
43         //=========================================================================
44         vtkGBlackBoxView::vtkGBlackBoxView()
45         {                       
46         }
47
48         //=========================================================================
49         vtkGBlackBoxView::~vtkGBlackBoxView()
50         {
51         }
52
53         //=========================================================================
54         void vtkGBlackBoxView::update(int idController,int command)
55         {
56                 updateColors();
57                 
58                 double xInic, yInic,zInic,xFin, yFin,zFin;
59                 _model->getInicPoint(xInic,yInic,zInic);
60                 _model->getFinalPoint(xFin, yFin,zFin);
61
62                 // RaC In the actual version, zInic=zFin=900
63
64                 _pts->SetPoint(0, xInic, yInic, zInic );
65                 _pts->SetPoint(1, xInic, yFin, zInic );
66                 _pts->SetPoint(2, xFin, yFin, zFin );
67                 _pts->SetPoint(3, xFin, yInic, zFin );
68
69                 updatePorts();
70
71                 _borderPolyMapper->Modified();
72                 _fillPolyMapper->Modified();
73                 //-----------
74
75                 updatePositionTextActor(xInic, yInic,zInic);
76
77                 //-----------
78                 setRefreshWaiting();
79         }
80
81         //=========================================================================
82
83         void vtkGBlackBoxView::createVtkObjects() //virtual
84         {
85
86                 //------------
87                 _pts                            = vtkPoints::New();     
88                 vtkCellArray *lines = vtkCellArray::New();
89                 vtkPolyData *_pd        = vtkPolyData::New();
90                 _borderPolyMapper       = vtkPolyDataMapper::New();
91                 _borderObjectActor      = vtkActor::New();
92                                 
93                 _pts->SetNumberOfPoints(4);
94
95                 double xInic, yInic,zInic,xFin, yFin,zFin;
96                 _model->getInicPoint(xInic,yInic,zInic);
97                 _model->getFinalPoint(xFin, yFin,zFin);
98
99                 // RaC In the actual version, zInic=zFin=900
100
101 //EED           _pts->SetPoint(0, xInic, yInic, zInic );
102 //EED           _pts->SetPoint(1, xInic, yFin, zInic );
103 //EED           _pts->SetPoint(2, xFin, yFin, zFin );
104 //EED           _pts->SetPoint(3, xFin, yInic, zFin );
105
106                 _pts->SetPoint(0, -1000, -1000, -1000 );
107                 _pts->SetPoint(1, xInic, yFin, zInic );
108                 _pts->SetPoint(2, 1000, 1000, 1000 );
109                 _pts->SetPoint(3, xFin, yInic, zFin );
110                 
111                 
112                 
113                 lines->InsertNextCell(5);
114                 lines->InsertCellPoint(0);
115                 lines->InsertCellPoint(1);
116                 lines->InsertCellPoint(2);
117                 lines->InsertCellPoint(3);
118                 lines->InsertCellPoint(0);
119                         
120                 _pd->SetPoints( _pts );
121                 _pd->SetLines( lines );
122
123                 _borderPolyMapper->SetInput(_pd);
124                 _borderObjectActor->SetMapper(_borderPolyMapper);
125                 _borderPolyMapper->Modified();
126
127                 
128                 ///************************* FILL *************************
129
130                 vtkCellArray *strip = vtkCellArray::New();
131                 vtkPolyData *pdFill = vtkPolyData::New();
132                 _fillPolyMapper         = vtkPolyDataMapper::New();
133                 _fillObjectActor        = vtkActor::New();
134
135                 // RaC In the actual version, zInic=zFin=900
136
137                 strip->InsertNextCell(5);
138                 strip->InsertCellPoint(0);
139                 strip->InsertCellPoint(1);
140                 strip->InsertCellPoint(2);
141                 strip->InsertCellPoint(0);
142                 strip->InsertCellPoint(3);
143                         
144                 pdFill->SetPoints( _pts );
145                 pdFill->SetStrips( strip );
146
147                 _fillPolyMapper->SetInput(pdFill);
148                 _fillObjectActor->SetMapper(_fillPolyMapper);
149                 _fillPolyMapper->Modified();
150
151                 ///************************* FILL *************************
152
153                 //------------
154
155                 _boxTextActor           = vtkTextActor3D::New();
156                 _boxTextActor->GetTextProperty()->SetFontSize(80);
157                 _boxTextActor->GetTextProperty()->BoldOn();
158
159                 //------------
160
161                 updatePositionTextActor( xInic,  yInic,  zInic);
162         }
163
164         //=========================================================================
165
166         void vtkGBlackBoxView::addVtkActors()//virtual
167         {
168                 _baseView->GetRenderer()->AddActor(_borderObjectActor);
169                 _baseView->GetRenderer()->AddActor(_boxTextActor);
170                 vtkGObjectView::addVtkActors();
171         }
172
173         //=========================================================================
174
175         void vtkGBlackBoxView::removeVtkActors()//virtual
176         {
177                 _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
178                 _baseView->GetRenderer()->RemoveActor(_boxTextActor);
179                 vtkGObjectView::removeVtkActors();
180         }
181
182         //=========================================================================
183
184         void vtkGBlackBoxView::updatePositionTextActor(double xInic, double yInic, double zInic)
185         {
186                 std::string temp        = _model->getBBTKType();
187                 temp+=":";
188                 temp+=_model->getBBTKName();
189                 _boxTextActor->SetInput(temp.c_str());
190                 _boxTextActor->SetPosition(xInic+4,yInic-7,zInic);
191                 _boxTextActor->SetScale(0.05,0.05,1);
192         }
193
194         //=========================================================================
195
196         void vtkGBlackBoxView::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                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_NH_R,BOXTEXT_NH_G,BOXTEXT_NH_B);
206
207                         GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
208                         if(bbmodel->isExecutable())
209                         {
210                                 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,0.9,BOXBORDER_HIGHLIGHTED_B);
211                                 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,0.9,BOXFILL_HIGHLIGHTED_B);
212                         }
213                         
214                 }
215                 else if(_state==HIGHLIGHTED)
216                 {
217                         _borderObjectActor->GetProperty()->SetLineWidth(2);
218                         
219                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
220                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
221                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_HIGHLIGHTED_R,BOXTEXT_HIGHLIGHTED_G,BOXTEXT_HIGHLIGHTED_B);
222                 }
223                 else if(_state==DRAG)
224                 {
225                         _borderObjectActor->GetProperty()->SetLineWidth(1.2);
226                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
227                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
228                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_DRAG_R,BOXTEXT_DRAG_G,BOXTEXT_DRAG_B);
229                 }
230                 else if(_state==SELECTED)
231                 {
232                         _borderObjectActor->GetProperty()->SetLineWidth(2);
233                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
234                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
235                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_SELECTED_R,BOXTEXT_SELECTED_G,BOXTEXT_SELECTED_B);
236                 }
237         }
238
239         //=========================================================================
240
241
242 }  // EO namespace bbtk
243
244 // EOF
245