]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBoxView.cxx
*** empty log message ***
[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=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                 //-----------
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=900
98
99                 _pts->SetPoint(0, xInic, yInic, zInic );
100                 _pts->SetPoint(1, xInic, yFin, zInic );
101                 _pts->SetPoint(2, xFin, yFin, zFin );
102                 _pts->SetPoint(3, xFin, yInic, zFin );
103                                 
104                 lines->InsertNextCell(5);
105                 lines->InsertCellPoint(0);
106                 lines->InsertCellPoint(1);
107                 lines->InsertCellPoint(2);
108                 lines->InsertCellPoint(3);
109                 lines->InsertCellPoint(0);
110                         
111                 _pd->SetPoints( _pts );
112                 _pd->SetLines( lines );
113
114                 _borderPolyMapper->SetInput(_pd);
115                 _borderObjectActor->SetMapper(_borderPolyMapper);
116                 _borderPolyMapper->Modified();
117
118                 
119                 ///************************* FILL *************************
120
121                 vtkCellArray *strip             = vtkCellArray::New();
122                 vtkPolyData *pdFill             = vtkPolyData::New();
123                 _fillPolyMapper                 = vtkPolyDataMapper::New();
124                 _fillObjectActor                = vtkActor::New();
125
126                 // RaC In the actual version, zInic=zFin=900
127
128                 strip->InsertNextCell(5);
129                 strip->InsertCellPoint(0);
130                 strip->InsertCellPoint(1);
131                 strip->InsertCellPoint(2);
132                 strip->InsertCellPoint(0);
133                 strip->InsertCellPoint(3);
134                         
135                 pdFill->SetPoints( _pts );
136                 pdFill->SetStrips( strip );
137
138                 _fillPolyMapper->SetInput(pdFill);
139                 _fillObjectActor->SetMapper(_fillPolyMapper);
140                 _fillPolyMapper->Modified();
141
142                 ///************************* FILL *************************
143
144         }
145
146         //=========================================================================
147
148         void vtkGBoxView::addVtkActors()//virtual
149         {
150                 _baseView->GetRenderer()->AddActor(_borderObjectActor);
151                 vtkGObjectView::addVtkActors();
152         }
153
154         //=========================================================================
155
156         void vtkGBoxView::removeVtkActors()//virtual
157         {
158                 _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
159                 vtkGObjectView::removeVtkActors();
160         }
161
162         //=========================================================================
163
164         void vtkGBoxView::updateColors()
165         {
166                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
167
168                 if(_state==NOTHING_HAPPENS)
169                 {
170                         _borderObjectActor->GetProperty()->SetLineWidth(1);
171                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
172                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
173                         
174                 }
175                 else if(_state==HIGHLIGHTED)
176                 {
177                         _borderObjectActor->GetProperty()->SetLineWidth(2);
178                         
179                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
180                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
181                 }
182                 else if(_state==DRAG)
183                 {
184                         _borderObjectActor->GetProperty()->SetLineWidth(1.2);
185                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
186                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
187                 }
188                 else if(_state==SELECTED)
189                 {
190                         _borderObjectActor->GetProperty()->SetLineWidth(2);
191                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
192                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
193                 }
194         }
195
196         //=========================================================================
197
198         void vtkGBoxView::updatePorts()
199         {
200                 GBoxModel* bmod =(GBoxModel*)_model;
201                 bmod->updatePorts();
202         }
203
204         //=========================================================================
205
206 }  // EO namespace bbtk
207
208 // EOF
209