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