]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGComplexBoxPortView.cxx
35dc1a8bc592320d9c4c31baf9b6dd59ab671ca6
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsVtkGUIEditorGraphic / vtkGComplexBoxPortView.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::vtkGComplexBoxPortView 
34 */
35
36
37 #include "vtkGComplexBoxPortView.h"
38
39 namespace bbtk
40 {
41
42
43         //=========================================================================
44         vtkGComplexBoxPortView::vtkGComplexBoxPortView()
45         {                       
46         }
47
48         //=========================================================================
49         vtkGComplexBoxPortView::~vtkGComplexBoxPortView()
50         {
51         }
52
53         //=========================================================================
54         void vtkGComplexBoxPortView::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 vtkGComplexBoxPortView::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 //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                 
105                 _pts->SetPoint(0, -1000, -1000, -1000 );
106                 _pts->SetPoint(1, xInic, yFin, zInic );
107                 _pts->SetPoint(2, 1000, 1000, 1000 );
108                 _pts->SetPoint(3, xFin, yInic, zFin );
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=900
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 vtkGComplexBoxPortView::addVtkActors()//virtual
156         {
157                 _baseView->GetRenderer()->AddActor(_borderObjectActor);
158                 vtkGObjectView::addVtkActors();
159         }
160
161         //=========================================================================
162
163         void vtkGComplexBoxPortView::removeVtkActors()//virtual
164         {
165                 _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
166                 vtkGObjectView::removeVtkActors();
167         }
168
169         //=========================================================================
170
171         void vtkGComplexBoxPortView::updateColors()
172         {
173                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
174
175                 if(_state==NOTHING_HAPPENS)
176                 {
177                         _borderObjectActor->GetProperty()->SetLineWidth(1);
178                         
179
180                         GComplexBoxPortModel *portModel = (GComplexBoxPortModel*)_model;
181                         if(portModel->getComplexPortType() == GCOMPLEXINPUTPORT)
182                         {
183                                 _fillObjectActor->GetProperty()->SetColor(COMPLEXINPUTPORTFILL_NH_R,COMPLEXINPUTPORTFILL_NH_G,COMPLEXINPUTPORTFILL_NH_B);
184                                 _borderObjectActor->GetProperty()->SetColor(COMPLEXINPUTPORTBORDER_NH_R,COMPLEXINPUTPORTBORDER_NH_G,COMPLEXINPUTPORTBORDER_NH_B);
185                         }
186                         else if (portModel->getComplexPortType() == GCOMPLEXOUTPUTPORT)
187                         {
188                                 _fillObjectActor->GetProperty()->SetColor(COMPLEXOUTPUTPORTFILL_NH_R,COMPLEXOUTPUTPORTFILL_NH_G,COMPLEXOUTPUTPORTFILL_NH_B);
189                                 _borderObjectActor->GetProperty()->SetColor(COMPLEXOUTPUTPORTBORDER_NH_R,COMPLEXOUTPUTPORTBORDER_NH_G,COMPLEXOUTPUTPORTBORDER_NH_B);
190                         }
191                         
192                 }
193                 else if(_state==HIGHLIGHTED)
194                 {
195                         _borderObjectActor->GetProperty()->SetLineWidth(2);
196                         
197                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
198                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
199                 }
200                 else if(_state==DRAG)
201                 {
202                         _borderObjectActor->GetProperty()->SetLineWidth(1.2);
203                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
204                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
205                 }
206                 else if(_state==SELECTED)
207                 {
208                         _borderObjectActor->GetProperty()->SetLineWidth(2);
209                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
210                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
211                 }
212         }
213
214         //=========================================================================
215
216
217 }  // EO namespace bbtk
218
219 // EOF
220