]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGComplexBoxPortView.cxx
37613747b0fc5fa9c26e93f746e167fdc1b5ef57
[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         updateColors( ) ;
56
57         double xInic , yInic , zInic , xFin , yFin , zFin ;
58         _model->getInicPoint( xInic , yInic , zInic ) ;
59         _model->getFinalPoint( xFin , yFin , zFin ) ;
60
61         // RaC In the actual version, zInic=zFin=GPOSITION_Z
62
63         _pts->SetPoint( 0 , xInic , yInic , zInic ) ;
64         _pts->SetPoint( 1 , xInic , yFin , zInic ) ;
65         _pts->SetPoint( 2 , xFin , yFin , zFin ) ;
66         _pts->SetPoint( 3 , xFin , yInic , zFin ) ;
67
68         updatePorts( ) ;
69
70         _borderPolyMapper->Modified( ) ;
71         _fillPolyMapper->Modified( ) ;
72         //-----------
73
74         //-----------
75         setRefreshWaiting( ) ;
76     }
77
78     //=========================================================================
79
80     void vtkGComplexBoxPortView::createVtkObjects( ) //virtual
81     {
82
83         //------------
84         _pts = vtkPoints::New( ) ;
85         vtkCellArray *lines = vtkCellArray::New( ) ;
86         vtkPolyData *_pd = vtkPolyData::New( ) ;
87         _borderPolyMapper = vtkPolyDataMapper::New( ) ;
88         _borderObjectActor = vtkActor::New( ) ;
89
90         _pts->SetNumberOfPoints( 4 ) ;
91
92         double xInic , yInic , zInic , xFin , yFin , zFin ;
93         _model->getInicPoint( xInic , yInic , zInic ) ;
94         _model->getFinalPoint( xFin , yFin , zFin ) ;
95
96         // RaC In the actual version, zInic=zFin=GPOSITION_Z
97
98         //EED           _pts->SetPoint(0, xInic, yInic, zInic );
99         //EED           _pts->SetPoint(1, xInic, yFin, zInic );
100         //EED           _pts->SetPoint(2, xFin, yFin, zFin );
101         //EED           _pts->SetPoint(3, xFin, yInic, zFin );
102
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         lines->InsertNextCell( 5 ) ;
111         lines->InsertCellPoint( 0 ) ;
112         lines->InsertCellPoint( 1 ) ;
113         lines->InsertCellPoint( 2 ) ;
114         lines->InsertCellPoint( 3 ) ;
115         lines->InsertCellPoint( 0 ) ;
116
117         _pd->SetPoints( _pts ) ;
118         _pd->SetLines( lines ) ;
119
120         _borderPolyMapper->SetInput( _pd ) ;
121         _borderObjectActor->SetMapper( _borderPolyMapper ) ;
122         _borderPolyMapper->Modified( ) ;
123
124
125         ///************************* FILL *************************
126
127         vtkCellArray *strip = vtkCellArray::New( ) ;
128         vtkPolyData *pdFill = vtkPolyData::New( ) ;
129         _fillPolyMapper = vtkPolyDataMapper::New( ) ;
130         _fillObjectActor = vtkActor::New( ) ;
131
132         // RaC In the actual version, zInic=zFin=GPOSITION_Z
133
134         strip->InsertNextCell( 5 ) ;
135         strip->InsertCellPoint( 0 ) ;
136         strip->InsertCellPoint( 1 ) ;
137         strip->InsertCellPoint( 2 ) ;
138         strip->InsertCellPoint( 0 ) ;
139         strip->InsertCellPoint( 3 ) ;
140
141         pdFill->SetPoints( _pts ) ;
142         pdFill->SetStrips( strip ) ;
143
144         _fillPolyMapper->SetInput( pdFill ) ;
145         _fillObjectActor->SetMapper( _fillPolyMapper ) ;
146         _fillPolyMapper->Modified( ) ;
147
148         ///************************* FILL *************************
149
150     }
151
152     //=========================================================================
153
154     void vtkGComplexBoxPortView::addVtkActors( )//virtual
155     {
156         _baseView->GetRenderer( )->AddActor( _borderObjectActor ) ;
157         vtkGObjectView::addVtkActors( ) ;
158     }
159
160     //=========================================================================
161
162     void vtkGComplexBoxPortView::removeVtkActors( )//virtual
163     {
164         _baseView->GetRenderer( )->RemoveActor( _borderObjectActor ) ;
165         vtkGObjectView::removeVtkActors( ) ;
166     }
167
168     //=========================================================================
169
170     void vtkGComplexBoxPortView::updateColors( ) {
171         _fillObjectActor->GetProperty( )->SetAmbient( 0.6 ) ;
172
173         if ( _state == NOTHING_HAPPENS ) {
174             _borderObjectActor->GetProperty( )->SetLineWidth( 1 ) ;
175
176
177             GComplexBoxPortModel *portModel = ( GComplexBoxPortModel* ) _model ;
178             if ( portModel->getComplexPortType( ) == GCOMPLEXINPUTPORT ) {
179                 _fillObjectActor->GetProperty( )->SetColor( COMPLEXINPUTPORTFILL_NH_R , COMPLEXINPUTPORTFILL_NH_G , COMPLEXINPUTPORTFILL_NH_B ) ;
180                 _borderObjectActor->GetProperty( )->SetColor( COMPLEXINPUTPORTBORDER_NH_R , COMPLEXINPUTPORTBORDER_NH_G , COMPLEXINPUTPORTBORDER_NH_B ) ;
181             } else if ( portModel->getComplexPortType( ) == GCOMPLEXOUTPUTPORT ) {
182                 _fillObjectActor->GetProperty( )->SetColor( COMPLEXOUTPUTPORTFILL_NH_R , COMPLEXOUTPUTPORTFILL_NH_G , COMPLEXOUTPUTPORTFILL_NH_B ) ;
183                 _borderObjectActor->GetProperty( )->SetColor( COMPLEXOUTPUTPORTBORDER_NH_R , COMPLEXOUTPUTPORTBORDER_NH_G , COMPLEXOUTPUTPORTBORDER_NH_B ) ;
184             }
185
186         } else if ( _state == HIGHLIGHTED ) {
187             _borderObjectActor->GetProperty( )->SetLineWidth( 2 ) ;
188
189             _borderObjectActor->GetProperty( )->SetColor( BOXBORDER_HIGHLIGHTED_R , BOXBORDER_HIGHLIGHTED_G , BOXBORDER_HIGHLIGHTED_B ) ;
190             _fillObjectActor->GetProperty( )->SetColor( BOXFILL_HIGHLIGHTED_R , BOXFILL_HIGHLIGHTED_G , BOXFILL_HIGHLIGHTED_B ) ;
191         } else if ( _state == DRAG ) {
192             _borderObjectActor->GetProperty( )->SetLineWidth( 1.2 ) ;
193             _borderObjectActor->GetProperty( )->SetColor( BOXBORDER_DRAG_R , BOXBORDER_DRAG_G , BOXBORDER_DRAG_B ) ;
194             _fillObjectActor->GetProperty( )->SetColor( BOXFILL_DRAG_R , BOXFILL_DRAG_G , BOXFILL_DRAG_B ) ;
195         } else if ( _state == SELECTED ) {
196             _borderObjectActor->GetProperty( )->SetLineWidth( 2 ) ;
197             _borderObjectActor->GetProperty( )->SetColor( BOXBORDER_SELECTED_R , BOXBORDER_SELECTED_G , BOXBORDER_SELECTED_B ) ;
198             _fillObjectActor->GetProperty( )->SetColor( BOXFILL_SELECTED_R , BOXFILL_SELECTED_G , BOXFILL_SELECTED_B ) ;
199         }
200     }
201
202     //=========================================================================
203
204
205 } // EO namespace bbtk
206
207 // EOF
208