]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx
The buttons and the objects to create input and output complex box ports were added...
[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(int idController,int command)
55         {
56                 updateColors();
57                 
58                 double xInic, yInic,zInic,xFin, yFin,zFin;
59                 _model->getInicPoint(xInic,yInic,zInic);
60                 _model->getFinalPoint(xFin, yFin,zFin);
61
62                 // RaC In the actual version, zInic=zFin=900
63
64                 _pts->SetPoint(0, xInic, yInic, zInic );
65                 _pts->SetPoint(1, xInic, yFin, zInic );
66                 _pts->SetPoint(2, xFin, yFin, zFin );
67                 _pts->SetPoint(3, xFin, yInic, zFin );
68
69                 updatePorts();
70
71                 _borderPolyMapper->Modified();
72                 _fillPolyMapper->Modified();
73                 //-----------
74
75                 updatePositionTextActor(xInic, yInic,zInic);
76
77                 //-----------
78                 setRefreshWaiting();
79         }
80
81         //=========================================================================
82
83         void vtkGBlackBoxView::createVtkObjects() //virtual
84         {
85
86                 //------------
87                 _pts = vtkPoints::New();        
88                 vtkCellArray *lines = vtkCellArray::New();
89                 vtkPolyData *_pd = vtkPolyData::New();
90                 _borderPolyMapper=vtkPolyDataMapper::New();
91                 _borderObjectActor=vtkActor::New();
92                                 
93                 _pts->SetNumberOfPoints(4);
94
95                 double xInic, yInic,zInic,xFin, yFin,zFin;
96                 _model->getInicPoint(xInic,yInic,zInic);
97                 _model->getFinalPoint(xFin, yFin,zFin);
98
99                 // RaC In the actual version, zInic=zFin=900
100
101                 _pts->SetPoint(0, xInic, yInic, zInic );
102                 _pts->SetPoint(1, xInic, yFin, zInic );
103                 _pts->SetPoint(2, xFin, yFin, zFin );
104                 _pts->SetPoint(3, xFin, yInic, zFin );
105                                 
106                 lines->InsertNextCell(5);
107                 lines->InsertCellPoint(0);
108                 lines->InsertCellPoint(1);
109                 lines->InsertCellPoint(2);
110                 lines->InsertCellPoint(3);
111                 lines->InsertCellPoint(0);
112                         
113                 _pd->SetPoints( _pts );
114                 _pd->SetLines( lines );
115
116                 _borderPolyMapper->SetInput(_pd);
117                 _borderObjectActor->SetMapper(_borderPolyMapper);
118                 _borderPolyMapper->Modified();
119
120                 
121                 ///************************* FILL *************************
122
123                 vtkCellArray *strip = vtkCellArray::New();
124                 vtkPolyData *pdFill = vtkPolyData::New();
125                 _fillPolyMapper=vtkPolyDataMapper::New();
126                 _fillObjectActor=vtkActor::New();
127
128                 // RaC In the actual version, zInic=zFin=900
129
130                 strip->InsertNextCell(5);
131                 strip->InsertCellPoint(0);
132                 strip->InsertCellPoint(1);
133                 strip->InsertCellPoint(2);
134                 strip->InsertCellPoint(0);
135                 strip->InsertCellPoint(3);
136                         
137                 pdFill->SetPoints( _pts );
138                 pdFill->SetStrips( strip );
139
140                 _fillPolyMapper->SetInput(pdFill);
141                 _fillObjectActor->SetMapper(_fillPolyMapper);
142                 _fillPolyMapper->Modified();
143
144                 ///************************* FILL *************************
145
146                 //------------
147
148                 _boxTextActor = vtkTextActor3D::New();
149                 std::string temp = _model->getBBTKType();
150                 temp+=":";
151                 temp+=_model->getBBTKName();
152                 _boxTextActor->GetTextProperty()->SetFontSize(80);
153                 _boxTextActor->GetTextProperty()->BoldOn();
154                 _boxTextActor->SetInput(temp.c_str());
155
156                 //------------
157
158                 updatePositionTextActor( xInic,  yInic,  zInic);
159         }
160
161         //=========================================================================
162
163         void vtkGBlackBoxView::addVtkActors()//virtual
164         {
165                 _baseView->GetRenderer()->AddActor(_borderObjectActor);
166                 _baseView->GetRenderer()->AddActor(_boxTextActor);
167                 vtkGObjectView::addVtkActors();
168         }
169
170         //=========================================================================
171
172         void vtkGBlackBoxView::removeVtkActors()//virtual
173         {
174                 _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
175                 _baseView->GetRenderer()->RemoveActor(_boxTextActor);
176                 vtkGObjectView::removeVtkActors();
177         }
178
179         //=========================================================================
180
181         void vtkGBlackBoxView::updatePositionTextActor(double xInic, double yInic, double zInic)
182         {
183                 _boxTextActor->SetPosition(xInic+4,yInic-7,zInic);
184                 _boxTextActor->SetScale(0.05,0.05,1);
185         }
186
187         //=========================================================================
188
189         void vtkGBlackBoxView::updateColors()
190         {
191                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
192
193                 if(_state==NOTHING_HAPPENS)
194                 {
195                         _borderObjectActor->GetProperty()->SetLineWidth(1);
196                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
197                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
198                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_NH_R,BOXTEXT_NH_G,BOXTEXT_NH_B);
199
200                         GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
201                         if(bbmodel->isExecutable())
202                         {
203                                 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,0.9,BOXBORDER_HIGHLIGHTED_B);
204                                 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,0.9,BOXFILL_HIGHLIGHTED_B);
205                         }
206                         
207                 }
208                 else if(_state==HIGHLIGHTED)
209                 {
210                         _borderObjectActor->GetProperty()->SetLineWidth(2);
211                         
212                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
213                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
214                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_HIGHLIGHTED_R,BOXTEXT_HIGHLIGHTED_G,BOXTEXT_HIGHLIGHTED_B);
215                 }
216                 else if(_state==DRAG)
217                 {
218                         _borderObjectActor->GetProperty()->SetLineWidth(1.2);
219                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
220                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
221                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_DRAG_R,BOXTEXT_DRAG_G,BOXTEXT_DRAG_B);
222                 }
223                 else if(_state==SELECTED)
224                 {
225                         _borderObjectActor->GetProperty()->SetLineWidth(2);
226                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
227                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
228                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_SELECTED_R,BOXTEXT_SELECTED_G,BOXTEXT_SELECTED_B);
229                 }
230         }
231
232         //=========================================================================
233
234
235 }  // EO namespace bbtk
236
237 // EOF
238