]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.cxx
Feature #1771 Add licence terms for all files.
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / GPortModel.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::GPortModel
59  */
60
61 /****
62  * Design and Developpement of BBTK GEditor
63  * Ricardo A Corredor J <ra.corredor67@uniandes.edu.co>
64  * RaC - 2010
65  ****/
66 #include "GPortModel.h"
67
68 namespace bbtk {
69
70
71     //=========================================================================
72
73     GPortModel::GPortModel( ) {
74         _parentBox              = NULL ;
75         _portType               = -1 ;
76         _posInBox               = 0 ;
77         _isConnected    = false ;
78         _value                  = "" ;
79         _isValueSet             = false ;
80
81
82     }
83
84     //=========================================================================
85
86     GPortModel::~GPortModel( ) {
87     }
88     //=========================================================================
89
90     void GPortModel::registerInBox( GBoxModel *blackBox , int portType , int pos ) {
91         _parentBox      = blackBox ;
92         _portType       = portType ;
93         _posInBox       = pos ;
94         updatePortPosition( ) ;
95     }
96
97     //=========================================================================
98
99     void GPortModel::updatePortPosition( ) {
100         double xInic , yInic , zInic , xFin , yFin , zFin ;
101         _parentBox->getInicPoint( xInic , yInic , zInic ) ;
102         _parentBox->getFinalPoint( xFin , yFin , zFin ) ;
103
104         double posX = xInic , posY = yInic , posZ = zInic ;
105         if ( _portType == GOUTPUTPORT ) {
106             posY = yFin ;
107         } else if ( _portType == GINPUTPORT ) {
108             posY = yInic + PORT_HEIGHT ;
109         }
110
111         //Attribute '_posInBox' starts with value 0 and it represents the position of the port in the box from left to right
112         posX = xInic + ( PORT_WIDTH / 2 ) + _posInBox * 1.1 * PORT_WIDTH ;
113
114         setInicPoint( posX , posY , posZ ) ;
115
116         posX = posX + PORT_WIDTH ;
117         posY = posY - PORT_HEIGHT ;
118
119         setFinalPoint( posX , posY , posZ ) ;
120
121     }
122
123     //=========================================================================
124
125     int GPortModel::getPortType( ) {
126         return _portType ;
127     }
128
129     //=========================================================================
130
131     int GPortModel::getPosInBox( ) {
132         return _posInBox ;
133     }
134
135     //=========================================================================
136
137     std::string GPortModel::getStatusText( ) {
138         std::string temp = "" ;
139
140         temp += _bbtkName ;
141         if ( isValueSet( ) ) {
142             temp += "(" ;
143             temp += _value ;
144             temp += ")" ;
145         }
146         temp += " " ;
147         temp += _bbtkType ;
148
149         return temp ;
150     }
151
152     //=========================================================================
153
154     GBoxModel* GPortModel::getParentBox( ) {
155         return _parentBox;
156     }
157
158     //=========================================================================
159
160     bool GPortModel::isConnected( ) {
161         return _isConnected ;
162     }
163
164     //=========================================================================
165
166     void GPortModel::setConnected( bool value ) {
167         _isConnected = value ;
168         notifyObservers( _objectId ) ;
169     }
170
171     //=========================================================================
172
173     void GPortModel::setValue( std::string value ) {
174
175                 //Removing Colons JPRG
176                 _parentBox->removeColons(value);
177                 
178         _value = value ;
179         if ( _value == "" ) {
180             _isValueSet = false ;
181         } else {
182             _isValueSet = true ;
183         }
184         notifyObservers( _objectId ) ;
185     }
186
187     //=========================================================================
188
189     std::string GPortModel::getValue( ) {
190                 //JPRG::Adding Colons
191                 std::string text = _value;
192                 _parentBox->addColons(text);
193                 return text;
194                 
195     }
196
197     //=========================================================================
198
199     bool GPortModel::isValueSet( ) {
200         return _isValueSet ;
201     }
202
203     //=========================================================================
204
205     void GPortModel::save( std::string &content ) {
206         content += "PORT\n" ;
207
208         // Port value info
209         content += _bbtkName ;
210         content += ":" ;
211         content += _value ;
212         content += "\n" ;
213     }
214
215     //=========================================================================
216
217 } // EO namespace bbtk
218
219 // EOF
220