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