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