]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGPortView.cxx
b0ef338bd65eda4de2ab9c4294462e530adc1cc0
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsVtkGUIEditorGraphic / vtkGPortView.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------  
24 */
25
26
27 /*=========================================================================                                                                               
28 Program:   bbtk
29 Module:    $RCSfile$
30 Language:  C++
31 Date:      $Date$
32 Version:   $Revision$
33 =========================================================================*/
34
35 /* ---------------------------------------------------------------------
36
37  * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
38  * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
39  *
40  *  This software is governed by the CeCILL-B license under French law and 
41  *  abiding by the rules of distribution of free software. You can  use, 
42  *  modify and/ or redistribute the software under the terms of the CeCILL-B 
43  *  license as circulated by CEA, CNRS and INRIA at the following URL 
44  *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
45  *  or in the file LICENSE.txt.
46  *
47  *  As a counterpart to the access to the source code and  rights to copy,
48  *  modify and redistribute granted by the license, users are provided only
49  *  with a limited warranty  and the software's author,  the holder of the
50  *  economic rights,  and the successive licensors  have only  limited
51  *  liability. 
52  *
53  *  The fact that you are presently reading this means that you have had
54  *  knowledge of the CeCILL-B license and that you accept its terms.
55  * ------------------------------------------------------------------------ */
56
57 /**
58  *  \file 
59  *  \brief Class bbtk::vtkGPortView 
60  */
61
62
63 #include "vtkGPortView.h"
64
65 namespace bbtk {
66
67
68     //=========================================================================
69
70     vtkGPortView::vtkGPortView( ) {
71     }
72
73     //=========================================================================
74
75     vtkGPortView::~vtkGPortView( ) {
76     }
77
78     //=========================================================================
79
80     void vtkGPortView::update( int idController , int command ) 
81 {
82         updateColors( ) ;
83
84         double xInic , yInic , zInic , xFin , yFin , zFin ;
85         _model->getInicPoint( xInic , yInic , zInic ) ;
86         _model->getFinalPoint( xFin , yFin , zFin ) ;
87         // RaC In the actual version, zInic=zFin=GPOSITION_Z
88         double mid = ( xInic + xFin ) / 2 ;
89         _pts->SetPoint( 0 , xInic , yInic , zInic ) ;
90         _pts->SetPoint( 1 , mid , yFin , zInic ) ;
91         _pts->SetPoint( 2 , xFin , yInic , zFin ) ;
92         _fillPolyMapper->Modified( ) ;
93         //-----------
94         setRefreshWaiting( ) ;
95     }
96
97     //=========================================================================
98
99     void vtkGPortView::createVtkObjects( ) //virtual
100     {
101
102         double xInic , yInic , zInic , xFin , yFin , zFin ;
103
104         _model->getInicPoint( xInic , yInic , zInic ) ;
105         _model->getFinalPoint( xFin , yFin , zFin ) ;
106
107         // RaC In the actual version, zInic=zFin=GPOSITION_Z
108
109         double mid = ( xInic + xFin ) / 2 ;
110
111         //EED           _pts->SetPoint(0, xInic, yInic, zInic );
112         //EED           _pts->SetPoint(1, mid, yFin, zInic );
113         //EED           _pts->SetPoint(2, xFin, yInic, zFin );                          
114
115         _pts = vtkPoints::New( ) ;
116         _pts->SetNumberOfPoints( 3 ) ;
117
118         _pts->SetPoint( 0 , -1000 , -1000 , -1000 ) ;
119         _pts->SetPoint( 1 , mid , yFin , zInic ) ;
120         _pts->SetPoint( 2 , 1000 , 1000 , 1000 ) ;
121
122
123         ///************************* FILL *************************
124
125         vtkCellArray *strip = vtkCellArray::New( ) ;
126         vtkPolyData *pdFill = vtkPolyData::New( ) ;
127         _fillPolyMapper = vtkPolyDataMapper::New( ) ;
128         _fillObjectActor = vtkActor::New( ) ;
129
130         // RaC In the actual version, zInic=zFin=GPOSITION_Z
131
132         strip->InsertNextCell( 3 ) ;
133         strip->InsertCellPoint( 0 ) ;
134         strip->InsertCellPoint( 1 ) ;
135         strip->InsertCellPoint( 2 ) ;
136
137         pdFill->SetPoints( _pts ) ;
138         pdFill->SetStrips( strip ) ;
139
140         _fillPolyMapper->SetInput( pdFill ) ;
141         _fillObjectActor->SetMapper( _fillPolyMapper ) ;
142         _fillPolyMapper->Modified( ) ;
143
144         ///************************* FILL *************************
145
146         updateColors( ) ;
147
148
149     }
150
151     //=========================================================================
152
153     void vtkGPortView::updateColors( ) {
154         _fillObjectActor->GetProperty( )->SetColor( 0.45 , 0.45 , 0.45 ) ;
155
156         if ( _state == POSSIBLE_CONNECTION ) {
157             _fillObjectActor->GetProperty( )->SetColor( 1 , 1 , 0 ) ;
158         } else if ( _state == SELECTED_POSSIBLE_CONNECTION ) {
159             _fillObjectActor->GetProperty( )->SetColor( 0 , 1 , 0 ) ;
160         } else if ( _state == HIGHLIGHTED ) {
161             _fillObjectActor->GetProperty( )->SetColor( 0 , 0 , 1 ) ;
162         } else {
163             GPortModel* portm = ( GPortModel* ) _model ;
164             if ( portm->isConnected( ) ) {
165                 _fillObjectActor->GetProperty( )->SetColor( 0.15 , 0.15 , 0.15 ) ;
166             } else if ( portm->isValueSet( ) ) {
167                 _fillObjectActor->GetProperty( )->SetColor( 0.55 , 0.25 , 0.25 ) ;
168             } else {
169                 _fillObjectActor->GetProperty( )->SetColor( 0.45 , 0.45 , 0.45 ) ;
170             }
171         }
172     }
173
174     //=========================================================================
175
176
177 } // EO namespace bbtk
178
179 // EOF
180