]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.cxx
Feature #1366 Increased the line width of bbEditor connections.
[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
68         updatePortPosition( ) ;
69
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         _value = value ;
150         if ( _value == "" ) {
151             _isValueSet = false ;
152         } else {
153             _isValueSet = true ;
154         }
155         notifyObservers( _objectId ) ;
156     }
157
158     //=========================================================================
159
160     std::string GPortModel::getValue( ) {
161         return _value ;
162     }
163
164     //=========================================================================
165
166     bool GPortModel::isValueSet( ) {
167         return _isValueSet ;
168     }
169
170     //=========================================================================
171
172     void GPortModel::save( std::string &content ) {
173         content += "PORT\n" ;
174
175         // Port value info
176         content += _bbtkName ;
177         content += ":" ;
178         content += _value ;
179         content += "\n" ;
180     }
181
182     //=========================================================================
183
184 } // EO namespace bbtk
185
186 // EOF
187