]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBoxModel.cxx
#3084 bbGEditor Bug New Normal - Color refresh for inputs and outputs
[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         GBoxModel::GBoxModel()
68         {               
69         }
70
71         //=========================================================================
72         GBoxModel::~GBoxModel()
73         {
74         }
75
76         //=========================================================================
77         void GBoxModel::setInicPoint(double& x, double& y, double& z)
78         {
79                 GObjectModel::setInicPoint(x,y,z);
80                 double xFin=x+BOX_WIDTH,yFin=y-BOX_HEIGHT;
81                 setFinalPoint(xFin,yFin,z);
82         }
83
84         //=========================================================================
85         void GBoxModel::addInputPort(GPortModel *inputport)
86         {
87                 _inputs.push_back(inputport);
88         }
89
90         //=========================================================================
91         void GBoxModel::addOutputPort(GPortModel *outputport)
92         {
93                 _outputs.push_back(outputport);
94         }
95
96         //=========================================================================
97         int GBoxModel::getNumInputPorts()
98         {
99                 return _inputs.size();
100         }
101
102         //=========================================================================
103         int GBoxModel::getNumOutputPorts()
104         {
105                 return _outputs.size();
106         }
107
108         //=========================================================================
109         void GBoxModel::move(double xx,double yy,double zz)
110         {
111                 setInicPoint(xx,yy,zz);
112                 //Refresh inputs position
113                 int i;
114                 for(i=0;i<(int)_inputs.size();i++)
115                 {
116                         _inputs[i]->updatePortPosition();
117                 }
118                 //Refresh outputs position
119                 for(i=0;i<(int)_outputs.size();i++)
120                 {
121                         _outputs[i]->updatePortPosition();
122                 }
123         }
124         
125         //=========================================================================
126         std::string GBoxModel::getStatusText()
127         {
128                 std::string temp = "";
129                 
130                 return temp;
131         }
132
133         //=========================================================================
134         std::vector<GPortModel*> GBoxModel::getInputPorts()
135         {
136                 return _inputs;
137         }
138
139         //=========================================================================
140         std::vector<GPortModel*> GBoxModel::getOutputPorts()
141         {
142                 return _outputs;
143         }
144
145         //=========================================================================     
146         void GBoxModel::save(std::string &content)
147         {
148                 content+="\n";
149         }
150         
151
152         //=========================================================================
153         GPortModel* GBoxModel::getInputPort(std::string name)
154         {
155                 for(int i = 0; i<(int)_inputs.size();i++)
156                 {
157                         if(_inputs[i]->getBBTKName()==name)
158                         {
159                                 return _inputs[i];
160                         }
161                 }
162                 return NULL;
163         }
164
165         //=========================================================================
166         GPortModel* GBoxModel::getOutputPort(std::string name)
167         {
168                 for(int i = 0; i<(int)_outputs.size();i++)
169                 {
170                         if(_outputs[i]->getBBTKName()==name)
171                         {
172                                 return _outputs[i];
173                         }
174                 }
175                 return NULL;
176         }
177
178         //=========================================================================
179         GPortModel* GBoxModel::getInputPort(int pos)
180         {
181                 return _inputs[pos];
182         }
183         //=========================================================================
184         
185         GPortModel* GBoxModel::getOutputPort(int pos)
186         {
187                 return _outputs[pos];
188         }
189
190         //=========================================================================
191
192         void GBoxModel::updatePorts()
193         {
194                 for(int i = 0; i<(int)_inputs.size();i++)
195                 {       
196                         _inputs[i]->updatePortPosition();
197                         _inputs[i]->notifyObservers(_objectId);
198                 }
199
200                 for(int i = 0; i<_outputs.size();i++)
201                 {
202                         _outputs[i]->updatePortPosition();
203                         _outputs[i]->notifyObservers(_objectId);
204                 }
205         }
206
207         
208         //=========================================================================
209         //JPR
210         void GBoxModel::addColons(std::string &text)
211         {
212                 std::string character("&&2P&&");                                
213                 size_t pos;
214                 pos = text.find(character);
215                 while(pos != std::string::npos)
216                 {
217                 //We replace the character "&&2P&&" with ":" for all the string
218                         text.replace(pos, character.length(),":");
219                         pos = text.find(character, pos);
220                 }
221         }
222
223         //=========================================================================
224         //JPR
225         void GBoxModel::removeColons(std::string &text)
226         {
227                 std::string character(":");                             
228                 size_t pos;
229                 pos = text.find(character);
230                 while(pos != std::string::npos)
231                 {
232                         //We replace the character ":" with "&&2P&&" for all the string
233                         text.replace(pos, character.length(),"&&2P&&");
234                         pos = text.find(character, pos);
235                         }
236         }
237
238         //=========================================================================
239
240
241 }  // EO namespace bbtk
242
243 // EOF
244