]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGPortView.cxx
#3084 bbGEditor Bug New Normal - Color refresh for inputs and outputs
[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 //EED 2017-03-02
119 //        _pts->SetPoint( 0 , -1000 , -1000 , -1000 ) ;
120 //        _pts->SetPoint( 1 , mid , yFin , zInic ) ;
121 //        _pts->SetPoint( 2 , 1000 , 1000 , 1000 ) ;
122
123
124         ///************************* FILL *************************
125
126         vtkCellArray    *strip          = vtkCellArray::New( ) ;
127         vtkPolyData     *pdFill         = vtkPolyData::New( ) ;
128                         _fillPolyMapper         = vtkPolyDataMapper::New( ) ;
129                         _fillObjectActor        = vtkActor::New( ) ;
130
131         // RaC In the actual version, zInic=zFin=GPOSITION_Z
132
133         strip->InsertNextCell( 3 ) ;
134         strip->InsertCellPoint( 0 ) ;
135         strip->InsertCellPoint( 1 ) ;
136         strip->InsertCellPoint( 2 ) ;
137
138         pdFill->SetPoints( _pts ) ;
139         pdFill->SetStrips( strip ) ;
140
141         _fillPolyMapper->SetInput( pdFill ) ;
142         _fillObjectActor->SetMapper( _fillPolyMapper ) ;
143         _fillPolyMapper->Modified( ) ;
144
145         ///************************* FILL *************************
146
147         updateColors( ) ;
148
149
150     }
151
152     //=========================================================================
153
154     void vtkGPortView::updateColors( ) 
155         {
156 //EED2017-04-08
157                 float rgb[3];
158                 getColors(rgb);
159         _fillObjectActor->GetProperty( )->SetColor( rgb[0] , rgb[1] , rgb[2] ) ;
160     }
161
162     //=========================================================================
163 //EED2017-04-08
164         void vtkGPortView::getColors(float* rgb)
165         {
166                 rgb[0]=0.45; rgb[1]=0.45; rgb[2]=0.45;
167
168         if ( _state == POSSIBLE_CONNECTION ) {
169                         rgb[0]=1; rgb[1]=1; rgb[2]=0;
170         } else if ( _state == SELECTED_POSSIBLE_CONNECTION ) {
171                         rgb[0]=0; rgb[1]=1; rgb[2]=0;
172         } else if ( _state == HIGHLIGHTED ) {
173                         rgb[0]=0; rgb[1]=0; rgb[2]=1;
174         } else {
175             GPortModel* portm = ( GPortModel* ) _model ;
176             if ( portm->isConnected( ) ) {
177                                 rgb[0]=0.15; rgb[1]=0.15; rgb[2]=0.15;
178             } else if ( portm->isValueSet( ) ) {
179                                 rgb[0]=0.55; rgb[1]=0.25; rgb[2]=0.25;
180             } else {
181                                 rgb[0]=0.45; rgb[1]=0.45; rgb[2]=0.45;
182             } // if portm
183         } // if  _state
184         }
185
186 } // EO namespace bbtk
187
188 // EOF
189