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