]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx
It saves the diagram and it was added the icon to open a file ..... Now it is necessa...
[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         void GBlackBoxModel::setInicPoint(double& x, double& y, double& z)
57         {
58                 GObjectModel::setInicPoint(x,y,z);
59
60                 double xFin=x+BOX_WIDTH,yFin=y-BOX_HEIGHT;
61                 setFinalPoint(xFin,yFin,z);
62         }
63
64         //=========================================================================
65
66         void GBlackBoxModel::addInputPort(GPortModel *inputport)
67         {
68                 _inputs.push_back(inputport);
69         }
70
71         //=========================================================================
72
73         void GBlackBoxModel::addOutputPort(GPortModel *outputport)
74         {
75                 _outputs.push_back(outputport);
76         }
77
78         //=========================================================================
79
80         int GBlackBoxModel::getNumInputPorts()
81         {
82                 return _inputs.size();
83         }
84
85         //=========================================================================
86
87         int GBlackBoxModel::getNumOutputPorts()
88         {
89                 return _outputs.size();
90         }
91
92         //=========================================================================
93
94         void GBlackBoxModel::move(double xx,double yy,double zz)
95         {
96                 setInicPoint(xx,yy,zz);
97
98                 //Refresh inputs position
99                 int i;
100                 for(i=0;i<_inputs.size();i++)
101                 {
102                         _inputs[i]->updatePortPosition();
103                 }
104                 
105                 //Refresh outputs position
106                 for(i=0;i<_outputs.size();i++)
107                 {
108                         _outputs[i]->updatePortPosition();
109                 }
110
111         }
112         
113         //=========================================================================
114         
115         std::string GBlackBoxModel::getBBTKPackage()
116         {
117                 return _bbtkPackage;
118         }
119
120         //=========================================================================
121
122         void GBlackBoxModel::setBBTKPackage(std::string obpackage)
123         {
124                 _bbtkPackage = obpackage;
125         }
126
127         //=========================================================================
128         
129         bool GBlackBoxModel::isExecutable()
130         {
131                 return _isExecutable;
132         }
133
134         //=========================================================================
135
136         void GBlackBoxModel::setExecutable(bool executable)
137         {
138                 _isExecutable = executable;
139         }
140
141         //=========================================================================
142         
143         std::string GBlackBoxModel::getStatusText()
144         {
145                 std::string temp = "";
146                 temp+=_bbtkPackage;
147                 temp+=":";
148                 temp+=_bbtkType;
149                 temp+=":";
150                 temp+=_bbtkName;
151                 
152                 return temp;
153         }
154
155         //=========================================================================
156
157         std::vector<GPortModel*> GBlackBoxModel::getInputPorts()
158         {
159                 return _inputs;
160         }
161
162         //=========================================================================
163
164         std::vector<GPortModel*> GBlackBoxModel::getOutputPorts()
165         {
166                 return _outputs;
167         }
168
169         //=========================================================================
170
171         void GBlackBoxModel::setValueToInputPort(int pos,std::string value)
172         {
173                 _inputs[pos]->setValue(value);
174         }
175
176         //=========================================================================     
177
178         void GBlackBoxModel::save(std::string &content)
179         {
180                 content+="BOX\n";
181                 // Box info
182                 content+=_bbtkPackage;
183                 content+=":";
184                 content+=_bbtkType;
185                 content+=":";
186                 content+=_bbtkName;
187                 content+="\n";
188
189                 //Box Position
190                 char buffer [50];
191                 sprintf (buffer, "%f", _xInic);
192                 content+=buffer;
193                 content+=":";
194                 sprintf (buffer, "%f", _yInic);
195                 content+=buffer;
196                 content+=":";
197                 sprintf (buffer, "%f", _zInic);
198                 content+=buffer;
199                 content+="\n";
200
201                 sprintf (buffer, "%f", _xFin);
202                 content+=buffer;
203                 content+=":";
204                 sprintf (buffer, "%f", _yFin);
205                 content+=buffer;
206                 content+=":";
207                 sprintf (buffer, "%f", _zFin);
208                 content+=buffer;
209                 content+="\n";
210
211                 //Ports with a value
212                 for(int i = 0; i<_inputs.size();i++)
213                 {
214                         if(_inputs[i]->isValueSet())
215                         {
216                                 _inputs[i]->save(content);
217                         }
218                 }
219
220         }
221         
222         //=========================================================================
223
224
225 }  // EO namespace bbtk
226
227 // EOF
228