]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx
4549df8ce9160387a7bd42e3d34cc4b459de332f
[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
136 // update position for one Actor that represents all OutputPorts
137
138
139 //              _borderPolyMapper->Modified();
140                 _fillPolyMapper->Modified();
141                 //-----------
142
143                 //-----------
144                 setRefreshWaiting();
145         }
146
147         //=========================================================================
148
149         void vtkGBlackBoxView::createVtkObjects() //virtual
150         {
151
152                 //------------
153                 _pts                            = vtkPoints::New();
154 //              vtkCellArray *lines = vtkCellArray::New();
155 //              vtkPolyData *_pd        = vtkPolyData::New();
156 //              _borderPolyMapper       = vtkPolyDataMapper::New();
157 //              _borderObjectActor      = vtkActor::New();
158
159                 _pts->SetNumberOfPoints(4);
160
161                 double xInic, yInic,zInic,xFin, yFin,zFin;
162                 _model->getInicPoint(xInic,yInic,zInic);
163                 _model->getFinalPoint(xFin, yFin,zFin);
164
165                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
166
167 //EED           _pts->SetPoint(0, xInic, yInic, zInic );
168 //EED           _pts->SetPoint(1, xInic, yFin, zInic );
169 //EED           _pts->SetPoint(2, xFin, yFin, zFin );
170 //EED           _pts->SetPoint(3, xFin, yInic, zFin );
171                 _pts->SetPoint(0, -1000, -1000, -1000 );
172                 _pts->SetPoint(1, xInic, yFin, zInic );
173                 _pts->SetPoint(2, 1000, 1000, 1000 );
174                 _pts->SetPoint(3, xFin, yInic, zFin );
175
176 //              lines->InsertNextCell(5);
177 //              lines->InsertCellPoint(0);
178 //              lines->InsertCellPoint(1);
179 //              lines->InsertCellPoint(2);
180 //              lines->InsertCellPoint(3);
181 //              lines->InsertCellPoint(0);
182
183 //              _pd->SetPoints( _pts );
184 //              _pd->SetLines( lines );
185 //              _borderPolyMapper->SetInput(_pd);
186 //              _borderObjectActor->SetMapper(_borderPolyMapper);
187 //              _borderPolyMapper->Modified();
188
189
190                 ///************************* FILL *************************
191                 vtkCellArray *strip = vtkCellArray::New();
192                 vtkPolyData *pdFill = vtkPolyData::New();
193                 _fillPolyMapper         = vtkPolyDataMapper::New();
194                 _fillObjectActor        = vtkActor::New();
195                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
196                 strip->InsertNextCell(5);
197                 strip->InsertCellPoint(0);
198                 strip->InsertCellPoint(1);
199                 strip->InsertCellPoint(2);
200                 strip->InsertCellPoint(0);
201                 strip->InsertCellPoint(3);
202                 pdFill->SetPoints( _pts );
203                 pdFill->SetStrips( strip );
204                 _fillPolyMapper->SetInput(pdFill);
205                 _fillObjectActor->SetMapper(_fillPolyMapper);
206                 _fillPolyMapper->Modified();
207                 ///************************* FILL *************************
208
209
210
211                 createVtkInputOutputPorts();
212
213
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                 vtkGBoxView::addVtkActors();
240                 _baseView->GetRenderer()->AddActor(_boxTextActor);
241
242         }
243
244         //=========================================================================
245
246         void vtkGBlackBoxView::removeVtkActors()//virtual
247         {
248                 _baseView->GetRenderer()->RemoveActor(_boxTextActor);
249 //              _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
250                 vtkGBoxView::removeVtkActors();
251         }
252
253         //=========================================================================
254
255         void vtkGBlackBoxView::updatePositionTextActor(double xInic, double yInic, double zInic)
256         {
257                 std::string temp        = _model->getBBTKType();
258                 temp+=":";
259                 temp+=_model->getBBTKName();
260                 _boxTextActor->SetInput(temp.c_str());
261                 _boxTextActor->SetPosition(xInic+4,yInic-7,zInic+1);
262                 _boxTextActor->SetScale(0.05,0.05,1);
263         }
264
265         //=========================================================================
266
267         void vtkGBlackBoxView::updateColors()
268         {
269                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
270
271                 if(_state==NOTHING_HAPPENS)
272                 {
273 //                      _borderObjectActor->GetProperty()->SetLineWidth(1);
274 ///                     _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
275                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
276                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_NH_R,BOXTEXT_NH_G,BOXTEXT_NH_B);
277
278                         GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
279                         if(bbmodel->isExecutable())
280                         {
281 //                              _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,0.9,BOXBORDER_HIGHLIGHTED_B);
282                                 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,0.9,BOXFILL_HIGHLIGHTED_B);
283                         }
284
285                 }
286                 else if(_state==HIGHLIGHTED)
287                 {
288 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);
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