]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBoxModel.cxx
#3057 bbGEditor Feature New Normal - optimizing of vtk actors management (input...
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / GBoxModel.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 Program:   bbtk
28 Module:    $RCSfile$
29 Language:  C++
30 Date:      $Date$
31 Version:   $Revision$
32 =========================================================================*/
33
34 /* ---------------------------------------------------------------------
35
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
38 *
39 *  This software is governed by the CeCILL-B license under French law and 
40 *  abiding by the rules of distribution of free software. You can  use, 
41 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
42 *  license as circulated by CEA, CNRS and INRIA at the following URL 
43 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
44 *  or in the file LICENSE.txt.
45 *
46 *  As a counterpart to the access to the source code and  rights to copy,
47 *  modify and redistribute granted by the license, users are provided only
48 *  with a limited warranty  and the software's author,  the holder of the
49 *  economic rights,  and the successive licensors  have only  limited
50 *  liability. 
51 *
52 *  The fact that you are presently reading this means that you have had
53 *  knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */                                                                         
55
56 /**
57 *  \file 
58 *  \brief Class bbtk::GBox 
59 */
60
61
62 #include "GBoxModel.h"
63
64 namespace bbtk
65 {
66         //=========================================================================
67
68         GBoxModel::GBoxModel()
69         {               
70         }
71
72         //=========================================================================
73
74         GBoxModel::~GBoxModel()
75         {
76         }
77
78         //=========================================================================
79
80         void GBoxModel::setInicPoint(double& x, double& y, double& z)
81         {
82                 GObjectModel::setInicPoint(x,y,z);
83                 double xFin=x+BOX_WIDTH,yFin=y-BOX_HEIGHT;
84                 setFinalPoint(xFin,yFin,z);
85         }
86
87         //=========================================================================
88
89         void GBoxModel::addInputPort(GPortModel *inputport)
90         {
91                 _inputs.push_back(inputport);
92         }
93
94         //=========================================================================
95
96         void GBoxModel::addOutputPort(GPortModel *outputport)
97         {
98                 _outputs.push_back(outputport);
99         }
100
101         //=========================================================================
102
103         int GBoxModel::getNumInputPorts()
104         {
105                 return _inputs.size();
106         }
107
108         //=========================================================================
109
110         int GBoxModel::getNumOutputPorts()
111         {
112                 return _outputs.size();
113         }
114
115         //=========================================================================
116
117         void GBoxModel::move(double xx,double yy,double zz)
118         {
119                 setInicPoint(xx,yy,zz);
120
121                 //Refresh inputs position
122                 int i;
123                 for(i=0;i<(int)_inputs.size();i++)
124                 {
125                         _inputs[i]->updatePortPosition();
126                 }
127                 
128                 //Refresh outputs position
129                 for(i=0;i<(int)_outputs.size();i++)
130                 {
131                         _outputs[i]->updatePortPosition();
132                 }
133
134         }
135         
136         //=========================================================================
137         
138         std::string GBoxModel::getStatusText()
139         {
140                 std::string temp = "";
141                 
142                 return temp;
143         }
144
145         //=========================================================================
146
147         std::vector<GPortModel*> GBoxModel::getInputPorts()
148         {
149                 return _inputs;
150         }
151
152         //=========================================================================
153
154         std::vector<GPortModel*> GBoxModel::getOutputPorts()
155         {
156                 return _outputs;
157         }
158
159         //=========================================================================     
160
161         void GBoxModel::save(std::string &content)
162         {
163                 content+="\n";
164         }
165         
166
167         //=========================================================================
168
169         GPortModel* GBoxModel::getInputPort(std::string name)
170         {
171                 for(int i = 0; i<(int)_inputs.size();i++)
172                 {
173                         if(_inputs[i]->getBBTKName()==name)
174                         {
175                                 return _inputs[i];
176                         }
177                 }
178                 return NULL;
179         }
180
181         //=========================================================================
182         
183         GPortModel* GBoxModel::getOutputPort(std::string name)
184         {
185                 for(int i = 0; i<(int)_outputs.size();i++)
186                 {
187                         if(_outputs[i]->getBBTKName()==name)
188                         {
189                                 return _outputs[i];
190                         }
191                 }
192                 return NULL;
193         }
194
195         //=========================================================================
196
197         GPortModel* GBoxModel::getInputPort(int pos)
198         {
199                 return _inputs[pos];
200         }
201
202         //=========================================================================
203         
204         GPortModel* GBoxModel::getOutputPort(int pos)
205         {
206                 return _outputs[pos];
207         }
208
209         //=========================================================================
210
211         void GBoxModel::updatePorts()
212         {
213                 for(int i = 0; i<(int)_inputs.size();i++)
214                 {       
215                         _inputs[i]->updatePortPosition();
216                         _inputs[i]->notifyObservers(_objectId);
217                 }
218
219                 for(int i = 0; i<_outputs.size();i++)
220                 {
221                         _outputs[i]->updatePortPosition();
222                         _outputs[i]->notifyObservers(_objectId);
223                 }
224         }
225
226         
227         //=========================================================================
228         //JPR
229         void GBoxModel::addColons(std::string &text)
230         {
231                 std::string character("&&2P&&");                                
232                 size_t pos;
233                 pos = text.find(character);
234                 while(pos != std::string::npos)
235                 {
236                 //We replace the character "&&2P&&" with ":" for all the string
237                         text.replace(pos, character.length(),":");
238                         pos = text.find(character, pos);
239                 }
240         }
241
242         //=========================================================================
243         //JPR
244         void GBoxModel::removeColons(std::string &text)
245         {
246                 std::string character(":");                             
247                 size_t pos;
248                 pos = text.find(character);
249                 while(pos != std::string::npos)
250                 {
251                         //We replace the character ":" with "&&2P&&" for all the string
252                         text.replace(pos, character.length(),"&&2P&&");
253                         pos = text.find(character, pos);
254                         }
255         }
256
257         //=========================================================================
258
259
260 }  // EO namespace bbtk
261
262 // EOF
263