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