]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.cxx
Feature #1771 Add licence terms for all files.
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / GConnectorModel.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::GConnectorModel 
59 */
60
61
62 #include "GConnectorModel.h"
63
64 namespace bbtk
65 {
66
67         //=========================================================================
68
69         GConnectorModel::GConnectorModel()
70         {               
71                 _startPort = NULL;
72                 _endPort = NULL;
73         }
74
75         //=========================================================================
76
77         GConnectorModel::~GConnectorModel()
78         {
79         }
80
81         //=========================================================================
82
83         void GConnectorModel::setStartPort(GPortModel* startPort)
84         {
85                 _startPort = startPort;
86                 startPort->setConnected(true);
87                 
88                 double xCenter,yCenter,zCenter;
89                 startPort->getCenter(xCenter,yCenter,zCenter);
90                 double xFport,yFport,zFport;
91                 startPort->getFinalPoint(xFport,yFport,zFport);
92
93                 setInicPoint(xCenter,yFport,zCenter);
94         }
95
96         //=========================================================================
97         
98         void GConnectorModel::setEndPort(GPortModel* endPort)
99         {
100                 _endPort = endPort;
101                 endPort->setConnected(true);
102
103                 double xCenter,yCenter,zCenter;         
104                 endPort->getCenter(xCenter,yCenter,zCenter);
105                 double xIport,yIport,zIport;
106                 endPort->getInicPoint(xIport,yIport,zIport);
107
108                 setFinalPoint(xCenter,yIport,zCenter);
109
110                 // Sets the last point of the contour model in the position of the end input port
111                 manualPoint* point = _model->GetManualPoint(_model->GetSizeLstPoints()-1);
112                 point->SetPoint(xCenter,yIport,zCenter);
113         }
114
115         //=========================================================================
116         
117         GPortModel* GConnectorModel::getStartPort()
118         {
119                 return _startPort;
120         }
121
122         //=========================================================================
123         
124         GPortModel* GConnectorModel::getEndPort()
125         {
126                 return _endPort;
127         }
128         
129         //=========================================================================
130
131         manualContourModel* GConnectorModel::getManualContourModel()
132         {
133                 return _model;
134         }
135
136         //=========================================================================
137         
138         void GConnectorModel::setManualContourModel(manualContourModel* model)
139         {
140                 _model = model;
141         }
142
143         //=========================================================================
144
145         void GConnectorModel::updateStartEndPoints()
146         {
147                 
148                 //back point
149                 double bsx,bsy; // back start for x and y
150                 double nsx,nsy;
151                 double bex,bey; // new start for x and y
152                 double nex,ney;
153                 
154                 //Start Point
155                 double xCenter,yCenter,zCenter;         
156                 _startPort->getCenter(xCenter,yCenter,zCenter);
157                 double xport,yport,zport;
158                 _startPort->getFinalPoint(xport,yport,zport);
159
160                 // Refresh the position of the contourModel first point with the data of the connector model
161                 manualPoint* point = _model->GetManualPoint(0);
162                 bsx=point->GetX(); 
163                 bsy=point->GetY(); 
164                 point->SetPoint(xCenter,yport,zCenter);
165                 nsx=xCenter;
166                 nsy=yport;
167                 
168                 //End Point     
169                 _endPort->getCenter(xCenter,yCenter,zCenter);
170                 _endPort->getInicPoint(xport,yport,zport);
171
172                 // Refresh the position of the contourModel last point with the data of the connector model
173                 point = _model->GetManualPoint(_model->GetSizeLstPoints()-1);
174                 bex=point->GetX(); 
175                 bey=point->GetY(); 
176                 point->SetPoint(xCenter,yport,zCenter);
177                 nex=xCenter;
178                 ney=yport;
179
180                 
181                 // moving point of the spline connection
182                 if ( ((bsx!=nsx)&&(bex!=nex)) ||  ((bsy!=nsy)&&(bey!=ney)) )
183                 {
184                         double difx=bsx-nsx; 
185                         double dify=bey-ney;
186                         double tmpX, tmpY, tmpZ;
187                         int i,size=_model->GetSizeLstPoints();
188                         if (size>2)
189                         {
190                                 for (i=1;i<size-1;i++)
191                                 {
192                                         point = _model->GetManualPoint(i);
193                                         tmpX = point->GetX();
194                                         tmpY = point->GetY();
195                                         tmpZ = point->GetZ();
196                                         point->SetPoint(tmpX-difx,tmpY-dify,tmpZ);
197                                 } // for i
198                         }// if size
199                 } // if bsx nsx  bex nex   bsy nsy bey ney 
200         }
201
202         //=========================================================================
203
204         void GConnectorModel::disconnectConnection()
205         {
206                 if(_startPort!=NULL)
207                 {
208                         _startPort->setConnected(false);                        
209                 }
210
211                 if(_endPort!=NULL)
212                 {
213                         _endPort->setConnected(false);
214                 }
215         }
216
217         //=========================================================================
218
219         void GConnectorModel::save(std::string &content)
220         {
221                 char buffer[50];
222
223                 content+="CONNECTION\n";
224
225                 // Connection info
226                 content+=_startPort->getParentBox()->getBBTKName();
227                 content+=":";
228                 content+=_startPort->getBBTKName();
229                 content+=":";
230                 content+=_endPort->getParentBox()->getBBTKName();
231                 content+=":";
232                 content+=_endPort->getBBTKName();
233                 content+="\n";
234                 
235                 int i,sizeLstPoints = _model->GetSizeLstPoints()-2;
236                 content+="NumberOfControlPoints:";
237                 sprintf (buffer, "%d", sizeLstPoints );
238                 content+=buffer;
239                 content+="\n";
240                 
241                 for (i=0;i<sizeLstPoints;i++)
242                 {
243                         manualPoint *mp = _model->GetManualPoint(i+1);
244                         sprintf (buffer, "%f:%f:%f\n", (float)mp->GetX(),(float)mp->GetY(),(float)mp->GetZ() );
245                         content+=buffer;
246                 }               
247         }
248
249         //=========================================================================
250
251 }  // EO namespace bbtk
252
253 // EOF
254