]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx
Feature #1771 Add licence terms for all files.
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsVtkGUIEditorGraphic / vtkGBlackBoxView.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::vtkGBlackBoxView
59 */
60
61
62 #include "vtkGBlackBoxView.h"
63
64 namespace bbtk
65 {
66
67
68         //=========================================================================
69         vtkGBlackBoxView::vtkGBlackBoxView()
70         {
71         }
72
73         //=========================================================================
74         vtkGBlackBoxView::~vtkGBlackBoxView()
75         {
76         }
77
78         //=========================================================================
79     void vtkGBlackBoxView::update_X_Fin()
80     {
81                 double xInic, yInic,zInic,xFin, yFin,zFin;
82                 _model->getInicPoint(xInic,yInic,zInic);
83         double *bounds = _boxTextActor->GetBounds();
84                 _model->getFinalPoint(xFin, yFin,zFin);
85
86                 double xFin1,xFin2,xFin3;
87                 // position referens from box name
88                 xFin1 = xInic+(bounds[1]-bounds[0])/2 + 20;
89         xFin2=xFin1;
90         xFin3=xFin1;
91         // position referens from input ports
92         GBoxModel* gbm=(GBoxModel*)_model;
93                 if ( gbm->getNumInputPorts()>0 )
94                 {
95             GPortModel* gpm = gbm->getInputPort( gbm->getNumInputPorts()-1 );
96             double xpFin, ypFin, zpFin;
97             gpm->getFinalPoint(xpFin, ypFin, zpFin);
98             xFin2 = xpFin+1;
99         }
100         // position referens from output ports
101                 if ( gbm->getNumOutputPorts()>0 )
102                 {
103             GPortModel* gpm = gbm->getOutputPort( gbm->getNumOutputPorts()-1 );
104             double xpFin, ypFin, zpFin;
105             gpm->getFinalPoint(xpFin, ypFin, zpFin);
106             xFin3 = xpFin+2;
107         }
108         xFin=xFin1;
109         if (xFin2>xFin) xFin=xFin2;
110         if (xFin3>xFin) xFin=xFin3;
111                 _model->setFinalPoint( xFin , yFin , zFin  );
112     }
113
114         //=========================================================================
115         void vtkGBlackBoxView::update(int idController,int command)
116         {
117                 updateColors();
118
119                 double xInic, yInic,zInic,xFin, yFin,zFin;
120                 _model->getInicPoint(xInic,yInic,zInic);
121
122                 updatePositionTextActor(xInic, yInic,zInic);
123         update_X_Fin();
124                 _model->getFinalPoint(xFin, yFin,zFin);
125
126                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
127
128                 _pts->SetPoint(0, xInic, yInic, zInic );
129                 _pts->SetPoint(1, xInic, yFin, zInic );
130                 _pts->SetPoint(2, xFin, yFin, zFin );
131                 _pts->SetPoint(3, xFin, yInic, zFin );
132
133                 updatePorts();
134
135                 _borderPolyMapper->Modified();
136                 _fillPolyMapper->Modified();
137                 //-----------
138
139                 //-----------
140                 setRefreshWaiting();
141         }
142
143         //=========================================================================
144
145         void vtkGBlackBoxView::createVtkObjects() //virtual
146         {
147
148                 //------------
149                 _pts                            = vtkPoints::New();
150                 vtkCellArray *lines = vtkCellArray::New();
151                 vtkPolyData *_pd        = vtkPolyData::New();
152                 _borderPolyMapper       = vtkPolyDataMapper::New();
153                 _borderObjectActor      = vtkActor::New();
154
155                 _pts->SetNumberOfPoints(4);
156
157                 double xInic, yInic,zInic,xFin, yFin,zFin;
158                 _model->getInicPoint(xInic,yInic,zInic);
159                 _model->getFinalPoint(xFin, yFin,zFin);
160
161                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
162
163 //EED           _pts->SetPoint(0, xInic, yInic, zInic );
164 //EED           _pts->SetPoint(1, xInic, yFin, zInic );
165 //EED           _pts->SetPoint(2, xFin, yFin, zFin );
166 //EED           _pts->SetPoint(3, xFin, yInic, zFin );
167
168                 _pts->SetPoint(0, -1000, -1000, -1000 );
169                 _pts->SetPoint(1, xInic, yFin, zInic );
170                 _pts->SetPoint(2, 1000, 1000, 1000 );
171                 _pts->SetPoint(3, xFin, yInic, zFin );
172
173
174
175                 lines->InsertNextCell(5);
176                 lines->InsertCellPoint(0);
177                 lines->InsertCellPoint(1);
178                 lines->InsertCellPoint(2);
179                 lines->InsertCellPoint(3);
180                 lines->InsertCellPoint(0);
181
182                 _pd->SetPoints( _pts );
183                 _pd->SetLines( lines );
184
185                 _borderPolyMapper->SetInput(_pd);
186                 _borderObjectActor->SetMapper(_borderPolyMapper);
187                 _borderPolyMapper->Modified();
188
189
190                 ///************************* FILL *************************
191
192                 vtkCellArray *strip = vtkCellArray::New();
193                 vtkPolyData *pdFill = vtkPolyData::New();
194                 _fillPolyMapper         = vtkPolyDataMapper::New();
195                 _fillObjectActor        = vtkActor::New();
196
197                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
198
199                 strip->InsertNextCell(5);
200                 strip->InsertCellPoint(0);
201                 strip->InsertCellPoint(1);
202                 strip->InsertCellPoint(2);
203                 strip->InsertCellPoint(0);
204                 strip->InsertCellPoint(3);
205
206                 pdFill->SetPoints( _pts );
207                 pdFill->SetStrips( strip );
208
209                 _fillPolyMapper->SetInput(pdFill);
210                 _fillObjectActor->SetMapper(_fillPolyMapper);
211                 _fillPolyMapper->Modified();
212
213                 ///************************* FILL *************************
214
215                 //------------
216
217                 _boxTextActor           = vtkTextActor3D::New();
218                 vtkTextProperty *prop =  vtkTextProperty::New();
219                 prop->BoldOn();
220                 prop->SetFontFamilyToArial();
221                 _boxTextActor->GetTextProperty()->BoldOn();
222                 prop->SetFontSize(80);
223                 _boxTextActor->SetTextProperty(prop);
224         
225         //      _boxTextActor->GetTextProperty()->SetFontSize(80);
226                 
227
228                 //------------
229
230                 updatePositionTextActor( xInic,  yInic,  zInic);
231         }
232
233         //=========================================================================
234
235         void vtkGBlackBoxView::addVtkActors()//virtual
236         {
237                 
238                 _baseView->GetRenderer()->AddActor(_borderObjectActor);
239                 vtkGObjectView::addVtkActors();
240                 _baseView->GetRenderer()->AddActor(_boxTextActor);
241         }
242
243         //=========================================================================
244
245         void vtkGBlackBoxView::removeVtkActors()//virtual
246         {
247                 _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
248                 _baseView->GetRenderer()->RemoveActor(_boxTextActor);
249                 vtkGObjectView::removeVtkActors();
250         }
251
252         //=========================================================================
253
254         void vtkGBlackBoxView::updatePositionTextActor(double xInic, double yInic, double zInic)
255         {
256                 std::string temp        = _model->getBBTKType();
257                 temp+=":";
258                 temp+=_model->getBBTKName();
259                 _boxTextActor->SetInput(temp.c_str());
260                 _boxTextActor->SetPosition(xInic+4,yInic-7,zInic+1);
261                 _boxTextActor->SetScale(0.05,0.05,1);
262         }
263
264         //=========================================================================
265
266         void vtkGBlackBoxView::updateColors()
267         {
268                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
269
270                 if(_state==NOTHING_HAPPENS)
271                 {
272                         _borderObjectActor->GetProperty()->SetLineWidth(1);
273                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
274                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
275                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_NH_R,BOXTEXT_NH_G,BOXTEXT_NH_B);
276
277                         GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
278                         if(bbmodel->isExecutable())
279                         {
280                                 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,0.9,BOXBORDER_HIGHLIGHTED_B);
281                                 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,0.9,BOXFILL_HIGHLIGHTED_B);
282                         }
283
284                 }
285                 else if(_state==HIGHLIGHTED)
286                 {
287                         _borderObjectActor->GetProperty()->SetLineWidth(2);
288
289                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
290                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
291                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_HIGHLIGHTED_R,BOXTEXT_HIGHLIGHTED_G,BOXTEXT_HIGHLIGHTED_B);
292                 }
293                 else if(_state==DRAG)
294                 {
295                         _borderObjectActor->GetProperty()->SetLineWidth(1.2);
296                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
297                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
298                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_DRAG_R,BOXTEXT_DRAG_G,BOXTEXT_DRAG_B);
299                 }
300                 else if(_state==SELECTED)
301                 {
302                         _borderObjectActor->GetProperty()->SetLineWidth(2);
303                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
304                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
305                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_SELECTED_R,BOXTEXT_SELECTED_G,BOXTEXT_SELECTED_B);
306                 }
307         }
308
309         //=========================================================================
310
311
312 }  // EO namespace bbtk
313
314 // EOF
315