]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx
#3084 bbGEditor Bug New Normal - Color refresh for inputs and outputs
[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 //EED 2017-03)02
118                 update_X_Fin();
119                 vtkGBoxView::update(idController,command);
120                 double xInic, yInic,zInic,xFin, yFin,zFin;
121                 _model->getInicPoint(xInic,yInic,zInic);
122                 updatePositionTextActor(xInic, yInic,zInic);
123                 setRefreshWaiting();
124         }
125
126         //=========================================================================
127
128         void vtkGBlackBoxView::createVtkObjects() //virtual
129         {
130
131                 //------------
132                 _pts                            = vtkPoints::New();
133 //              vtkCellArray *lines = vtkCellArray::New();
134 //              vtkPolyData *_pd        = vtkPolyData::New();
135 //              _borderPolyMapper       = vtkPolyDataMapper::New();
136 //              _borderObjectActor      = vtkActor::New();
137
138                 _pts->SetNumberOfPoints(4);
139
140                 double xInic, yInic,zInic,xFin, yFin,zFin;
141                 _model->getInicPoint(xInic,yInic,zInic);
142                 _model->getFinalPoint(xFin, yFin,zFin);
143
144                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
145
146 //EED           _pts->SetPoint(0, xInic, yInic, zInic );
147 //EED           _pts->SetPoint(1, xInic, yFin, zInic );
148 //EED           _pts->SetPoint(2, xFin, yFin, zFin );
149 //EED           _pts->SetPoint(3, xFin, yInic, zFin );
150
151 //EED 2017-03-02
152 //              _pts->SetPoint(0, -1000, -1000, -1000 );
153 //              _pts->SetPoint(1, xInic, yFin, zInic );
154 //              _pts->SetPoint(2, 1000, 1000, 1000 );
155 //              _pts->SetPoint(3, xFin, yInic, zFin );
156
157
158 //              lines->InsertNextCell(5);
159 //              lines->InsertCellPoint(0);
160 //              lines->InsertCellPoint(1);
161 //              lines->InsertCellPoint(2);
162 //              lines->InsertCellPoint(3);
163 //              lines->InsertCellPoint(0);
164
165 //              _pd->SetPoints( _pts );
166 //              _pd->SetLines( lines );
167 //              _borderPolyMapper->SetInput(_pd);
168 //              _borderObjectActor->SetMapper(_borderPolyMapper);
169 //              _borderPolyMapper->Modified();
170
171
172                 ///************************* FILL *************************
173                 vtkCellArray *strip = vtkCellArray::New();
174                 vtkPolyData *pdFill = vtkPolyData::New();
175                 _fillPolyMapper         = vtkPolyDataMapper::New();
176                 _fillObjectActor        = vtkActor::New();
177                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
178                 strip->InsertNextCell(5);
179                 strip->InsertCellPoint(0);
180                 strip->InsertCellPoint(1);
181                 strip->InsertCellPoint(2);
182                 strip->InsertCellPoint(0);
183                 strip->InsertCellPoint(3);
184                 pdFill->SetPoints( _pts );
185                 pdFill->SetStrips( strip );
186                 _fillPolyMapper->SetInput(pdFill);
187                 _fillObjectActor->SetMapper(_fillPolyMapper);
188                 _fillPolyMapper->Modified();
189                 ///************************* FILL *************************
190
191
192
193                 createVtkInputOutputPorts();
194
195
196
197                 //------------
198
199                 _boxTextActor                   = vtkTextActor3D::New();
200                 vtkTextProperty *prop   =  vtkTextProperty::New();
201                 prop->BoldOn();
202                 prop->SetFontFamilyToArial();
203                 _boxTextActor->GetTextProperty()->BoldOn();
204                 prop->SetFontSize(80);
205                 _boxTextActor->SetTextProperty(prop);
206         
207         //      _boxTextActor->GetTextProperty()->SetFontSize(80);
208                 
209
210                 //------------
211
212                 updatePositionTextActor( xInic,  yInic,  zInic);
213         }
214
215         //===============BoundaryEdgesOn==========================================================
216
217         void vtkGBlackBoxView::addVtkActors()//virtual
218         {
219                 
220 //              _baseView->GetRenderer()->AddActor(_borderObjectActor);
221                 vtkGBoxView::addVtkActors();
222                 _baseView->GetRenderer()->AddActor(_boxTextActor);
223
224         }
225
226         //=========================================================================
227
228         void vtkGBlackBoxView::removeVtkActors()//virtual
229         {
230                 _baseView->GetRenderer()->RemoveActor(_boxTextActor);
231 //              _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
232                 vtkGBoxView::removeVtkActors();
233         }
234
235         //=========================================================================
236
237         void vtkGBlackBoxView::updatePositionTextActor(double xInic, double yInic, double zInic)
238         {
239                 std::string temp        = _model->getBBTKType();
240                 temp+=":";
241                 temp+=_model->getBBTKName();
242                 _boxTextActor->SetInput(temp.c_str());
243                 _boxTextActor->SetPosition(xInic+4,yInic-7,zInic+1);
244                 _boxTextActor->SetScale(0.05,0.05,1);
245         }
246
247         //=========================================================================
248
249         void vtkGBlackBoxView::updateColors()
250         {
251                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
252
253                 if(_state==NOTHING_HAPPENS)
254                 {
255 //                      _borderObjectActor->GetProperty()->SetLineWidth(1);
256 ///                     _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
257                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
258                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_NH_R,BOXTEXT_NH_G,BOXTEXT_NH_B);
259
260                         GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
261                         if(bbmodel->isExecutable())
262                         {
263 //                              _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,0.9,BOXBORDER_HIGHLIGHTED_B);
264                                 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,0.9,BOXFILL_HIGHLIGHTED_B);
265                         }
266
267                 }
268                 else if(_state==HIGHLIGHTED)
269                 {
270 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);
271 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
272                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
273                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_HIGHLIGHTED_R,BOXTEXT_HIGHLIGHTED_G,BOXTEXT_HIGHLIGHTED_B);
274                 }
275                 else if(_state==DRAG)
276                 {
277 //                      _borderObjectActor->GetProperty()->SetLineWidth(1.2);
278 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
279                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
280                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_DRAG_R,BOXTEXT_DRAG_G,BOXTEXT_DRAG_B);
281                 }
282                 else if(_state==SELECTED)
283                 {
284 //                      _borderObjectActor->GetProperty()->SetLineWidth(2);
285 //                      _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
286                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
287                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_SELECTED_R,BOXTEXT_SELECTED_G,BOXTEXT_SELECTED_B);
288                 }
289
290                 updateColorsPorts();
291
292         }
293
294         //=========================================================================
295
296
297 }  // EO namespace bbtk
298
299 // EOF
300