]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBoxView.cxx
4ea328597c09e598c4362cbff7b9a56072dfebd2
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsVtkGUIEditorGraphic / vtkGBoxView.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::vtkGBoxView 
34 */
35
36
37 #include "vtkGBoxView.h"
38
39 namespace bbtk
40 {
41
42
43         //=========================================================================
44         vtkGBoxView::vtkGBoxView()
45         {                       
46         }
47
48         //=========================================================================
49         vtkGBoxView::~vtkGBoxView()
50         {
51         }
52
53         //=========================================================================
54         void vtkGBoxView::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=GPOSITION_Z
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                 //-----------
76                 setRefreshWaiting();
77         }
78
79         //=========================================================================
80
81         void vtkGBoxView::createVtkObjects() //virtual
82         {
83
84                 //------------
85                 _pts                            = vtkPoints::New();     
86                 vtkCellArray *lines = vtkCellArray::New();
87                 vtkPolyData *_pd        = vtkPolyData::New();
88                 _borderPolyMapper       = vtkPolyDataMapper::New();
89                 _borderObjectActor      = vtkActor::New();
90                                 
91                 _pts->SetNumberOfPoints(4);
92
93                 double xInic, yInic,zInic,xFin, yFin,zFin;
94                 _model->getInicPoint(xInic,yInic,zInic);
95                 _model->getFinalPoint(xFin, yFin,zFin);
96
97                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
98
99 //EED           _pts->SetPoint(0, xInic, yInic, zInic );
100 //EED           _pts->SetPoint(1, xInic, yFin, zInic );
101 //EED           _pts->SetPoint(2, xFin, yFin, zFin );
102 //EED           _pts->SetPoint(3, xFin, yInic, zFin );
103
104                 _pts->SetPoint(0, -1000, -1000, -1000 );
105                 _pts->SetPoint(1, xInic, yFin, zInic );
106                 _pts->SetPoint(2, 1000, 1000, 1000 );
107                 _pts->SetPoint(3, xFin, yInic, zFin );
108                 
109                 
110                 
111                 lines->InsertNextCell(5);
112                 lines->InsertCellPoint(0);
113                 lines->InsertCellPoint(1);
114                 lines->InsertCellPoint(2);
115                 lines->InsertCellPoint(3);
116                 lines->InsertCellPoint(0);
117                         
118                 _pd->SetPoints( _pts );
119                 _pd->SetLines( lines );
120
121                 _borderPolyMapper->SetInput(_pd);
122                 _borderObjectActor->SetMapper(_borderPolyMapper);
123                 _borderPolyMapper->Modified();
124
125                 
126                 ///************************* FILL *************************
127
128                 vtkCellArray *strip             = vtkCellArray::New();
129                 vtkPolyData *pdFill             = vtkPolyData::New();
130                 _fillPolyMapper                 = vtkPolyDataMapper::New();
131                 _fillObjectActor                = vtkActor::New();
132
133                 // RaC In the actual version, zInic=zFin=GPOSITION_Z
134
135                 strip->InsertNextCell(5);
136                 strip->InsertCellPoint(0);
137                 strip->InsertCellPoint(1);
138                 strip->InsertCellPoint(2);
139                 strip->InsertCellPoint(0);
140                 strip->InsertCellPoint(3);
141                         
142                 pdFill->SetPoints( _pts );
143                 pdFill->SetStrips( strip );
144
145                 _fillPolyMapper->SetInput(pdFill);
146                 _fillObjectActor->SetMapper(_fillPolyMapper);
147                 _fillPolyMapper->Modified();
148
149                 ///************************* FILL *************************
150
151         }
152
153         //=========================================================================
154
155         void vtkGBoxView::addVtkActors()//virtual
156         {
157                 _baseView->GetRenderer()->AddActor(_borderObjectActor);
158                 vtkGObjectView::addVtkActors();
159         }
160
161         //=========================================================================
162
163         void vtkGBoxView::removeVtkActors()//virtual
164         {
165                 _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
166                 vtkGObjectView::removeVtkActors();
167         }
168
169         //=========================================================================
170
171         void vtkGBoxView::updateColors()
172         {
173                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
174
175                 if(_state==NOTHING_HAPPENS)
176                 {
177                         _borderObjectActor->GetProperty()->SetLineWidth(1);
178                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
179                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
180                         
181                 }
182                 else if(_state==HIGHLIGHTED)
183                 {
184                         _borderObjectActor->GetProperty()->SetLineWidth(2);
185                         
186                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
187                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
188                 }
189                 else if(_state==DRAG)
190                 {
191                         _borderObjectActor->GetProperty()->SetLineWidth(1.2);
192                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
193                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
194                 }
195                 else if(_state==SELECTED)
196                 {
197                         _borderObjectActor->GetProperty()->SetLineWidth(2);
198                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
199                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
200                 }
201         }
202
203         //=========================================================================
204
205         void vtkGBoxView::updatePorts()
206         {
207                 GBoxModel* bmod =(GBoxModel*)_model;
208                 bmod->updatePorts();
209         }
210
211         //=========================================================================
212
213 }  // EO namespace bbtk
214
215 // EOF
216