]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx
v1.1.0
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / GBlackBoxModel.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
33 /****
34 * Design and Developpement of BBTK GEditor
35 * Ricardo A Corredor J <ra.corredor67@uniandes.edu.co>
36 * RaC - 2010
37 ****/
38
39 #include "GBlackBoxModel.h"
40
41 namespace bbtk
42 {
43         //=========================================================================
44
45         GBlackBoxModel::GBlackBoxModel()
46         {               
47                 _isExecutable = false;
48         }
49
50         //=========================================================================
51
52         GBlackBoxModel::~GBlackBoxModel()
53         {
54         }
55
56         //=========================================================================
57         
58         std::string GBlackBoxModel::getBBTKPackage()
59         {
60                 return _bbtkPackage;
61         }
62
63         //=========================================================================
64
65         void GBlackBoxModel::setBBTKPackage(std::string obpackage)
66         {
67                 _bbtkPackage = obpackage;
68         }
69
70         //=========================================================================
71         
72         bool GBlackBoxModel::isExecutable()
73         {
74                 return _isExecutable;
75         }
76
77         //=========================================================================
78
79         void GBlackBoxModel::setExecutable(bool executable)
80         {
81                 _isExecutable = executable;
82         }
83
84         //=========================================================================
85         
86         std::string GBlackBoxModel::getStatusText()
87         {
88                 std::string temp = "";
89                 temp+=_bbtkPackage;
90                 temp+=":";
91                 temp+=_bbtkType;
92                 temp+=":";
93                 temp+=_bbtkName;
94                 
95                 return temp;
96         }
97
98         //=========================================================================
99
100         void GBlackBoxModel::setValueToInputPort(int pos,std::string value)
101         {
102                 _inputs[pos]->setValue(value);
103         }
104
105         //=========================================================================     
106
107         void GBlackBoxModel::save(std::string &content)
108         {
109                 content+="BOX\n";
110                 // Box info
111                 content+=_bbtkPackage;
112                 content+=":";
113                 content+=_bbtkType;
114                 content+=":";
115                 content+=_bbtkName;
116                 content+="\n";
117                 content+="ISEXEC:";
118                 if(_isExecutable)
119                 {
120                         content+="TRUE";
121                 }
122                 else
123                 {
124                         content+="FALSE";
125                 }
126                 content+="\n";
127
128
129                 //Box Position
130                 char buffer [50];
131                 sprintf (buffer, "%f", _xInic);
132                 content+=buffer;
133                 content+=":";
134                 sprintf (buffer, "%f", _yInic);
135                 content+=buffer;
136                 content+=":";
137                 sprintf (buffer, "%f", _zInic);
138                 content+=buffer;
139                 content+="\n";
140
141                 sprintf (buffer, "%f", _xFin);
142                 content+=buffer;
143                 content+=":";
144                 sprintf (buffer, "%f", _yFin);
145                 content+=buffer;
146                 content+=":";
147                 sprintf (buffer, "%f", _zFin);
148                 content+=buffer;
149                 content+="\n";
150
151                 //Ports with a value
152                 for(int i = 0; i<(int)_inputs.size();i++)
153                 {
154                         if(_inputs[i]->isValueSet())
155                         {
156                                 _inputs[i]->save(content);
157                         }
158                 }
159                 content+="FIN_BOX\n";
160
161         }
162         
163         //=========================================================================
164
165         void GBlackBoxModel::setValueToInput(std::string name,std::string value)
166         {
167                 for(int i = 0; i<(int)_inputs.size();i++)
168                 {
169                         if(_inputs[i]->getBBTKName()==name)
170                         {
171                                 _inputs[i]->setValue(value);
172                         }
173                 }
174         }
175
176         //=========================================================================
177
178         std::string GBlackBoxModel::getValueInputPort(int pos)
179         {
180                 std::string text = _inputs[pos]->getValue();
181                 addColons(text);
182                 return text;
183         }
184
185         //=========================================================================
186
187         std::string GBlackBoxModel::getValueInput(std::string name)
188         {
189                 for(int i = 0; i<(int)_inputs.size();i++)
190                 {
191                         if(_inputs[i]->getBBTKName()==name)
192                         {
193                                 return _inputs[i]->getValue();
194                         }
195                 }
196                 return NULL;
197         }
198
199         //=========================================================================
200
201         std::vector<int> GBlackBoxModel::getConnectedInputs()
202         {
203                 std::vector<int> connected;
204                 for(int i = 0; i<(int)_inputs.size();i++)
205                 {
206                         if(_inputs[i]->isConnected())
207                         {
208                                 connected.push_back(i);
209                         }
210                 }
211                 return connected;
212         }
213
214         //=========================================================================
215
216         std::vector<int> GBlackBoxModel::getConnectedOutputs()
217         {
218                 std::vector<int> connected;
219                 for(int i = 0; i<(int)_outputs.size();i++)
220                 {
221                         if(_outputs[i]->isConnected())
222                         {
223                                 connected.push_back(i);
224                         }
225                 }
226                 return connected;
227         }
228
229         //=========================================================================
230 }   // EO namespace bbtk
231
232 // EOF
233