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