]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGComplexBoxPortView.cxx
The buttons and the objects to create input and output complex box ports were added...
[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                 _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 vtkGComplexBoxPortView::addVtkActors()//virtual
149         {
150                 _baseView->GetRenderer()->AddActor(_borderObjectActor);
151                 vtkGObjectView::addVtkActors();
152         }
153
154         //=========================================================================
155
156         void vtkGComplexBoxPortView::removeVtkActors()//virtual
157         {
158                 _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
159                 vtkGObjectView::removeVtkActors();
160         }
161
162         //=========================================================================
163
164         void vtkGComplexBoxPortView::updateColors()
165         {
166                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
167
168                 if(_state==NOTHING_HAPPENS)
169                 {
170                         _borderObjectActor->GetProperty()->SetLineWidth(1);
171                         
172
173                         GComplexBoxPortModel *portModel = (GComplexBoxPortModel*)_model;
174                         if(portModel->getComplexPortType() == GCOMPLEXINPUTPORT)
175                         {
176                                 _fillObjectActor->GetProperty()->SetColor(COMPLEXINPUTPORTFILL_NH_R,COMPLEXINPUTPORTFILL_NH_G,COMPLEXINPUTPORTFILL_NH_B);
177                                 _borderObjectActor->GetProperty()->SetColor(COMPLEXINPUTPORTBORDER_NH_R,COMPLEXINPUTPORTBORDER_NH_G,COMPLEXINPUTPORTBORDER_NH_B);
178                         }
179                         else if (portModel->getComplexPortType() == GCOMPLEXOUTPUTPORT)
180                         {
181                                 _fillObjectActor->GetProperty()->SetColor(COMPLEXOUTPUTPORTFILL_NH_R,COMPLEXOUTPUTPORTFILL_NH_G,COMPLEXOUTPUTPORTFILL_NH_B);
182                                 _borderObjectActor->GetProperty()->SetColor(COMPLEXOUTPUTPORTBORDER_NH_R,COMPLEXOUTPUTPORTBORDER_NH_G,COMPLEXOUTPUTPORTBORDER_NH_B);
183                         }
184                         
185                 }
186                 else if(_state==HIGHLIGHTED)
187                 {
188                         _borderObjectActor->GetProperty()->SetLineWidth(2);
189                         
190                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
191                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
192                 }
193                 else if(_state==DRAG)
194                 {
195                         _borderObjectActor->GetProperty()->SetLineWidth(1.2);
196                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
197                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
198                 }
199                 else if(_state==SELECTED)
200                 {
201                         _borderObjectActor->GetProperty()->SetLineWidth(2);
202                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
203                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
204                 }
205         }
206
207         //=========================================================================
208
209
210 }  // EO namespace bbtk
211
212 // EOF
213