GConnectorModel.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002 Program:   bbtk
00003 Module:    $RCSfile: GConnectorModel.cxx,v $
00004 Language:  C++
00005 Date:      $Date: 2010/10/04 05:14:21 $
00006 Version:   $Revision: 1.11 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030 
00037 #include "GConnectorModel.h"
00038 
00039 namespace bbtk
00040 {
00041 
00042         //=========================================================================
00043 
00044         GConnectorModel::GConnectorModel()
00045         {               
00046                 _startPort = NULL;
00047                 _endPort = NULL;
00048         }
00049 
00050         //=========================================================================
00051 
00052         GConnectorModel::~GConnectorModel()
00053         {
00054         }
00055 
00056         //=========================================================================
00057 
00058         void GConnectorModel::setStartPort(GPortModel* startPort)
00059         {
00060                 _startPort = startPort;
00061                 startPort->setConnected(true);
00062                 
00063                 double xCenter,yCenter,zCenter;
00064                 startPort->getCenter(xCenter,yCenter,zCenter);
00065                 double xFport,yFport,zFport;
00066                 startPort->getFinalPoint(xFport,yFport,zFport);
00067 
00068                 setInicPoint(xCenter,yFport,zCenter);
00069         }
00070 
00071         //=========================================================================
00072         
00073         void GConnectorModel::setEndPort(GPortModel* endPort)
00074         {
00075                 _endPort = endPort;
00076                 endPort->setConnected(true);
00077 
00078                 double xCenter,yCenter,zCenter;         
00079                 endPort->getCenter(xCenter,yCenter,zCenter);
00080                 double xIport,yIport,zIport;
00081                 endPort->getInicPoint(xIport,yIport,zIport);
00082 
00083                 setFinalPoint(xCenter,yIport,zCenter);
00084 
00085                 // Sets the last point of the contour model in the position of the end input port
00086                 manualPoint* point = _model->GetManualPoint(_model->GetSizeLstPoints()-1);
00087                 point->SetPoint(xCenter,yIport,zCenter);
00088         }
00089 
00090         //=========================================================================
00091         
00092         GPortModel* GConnectorModel::getStartPort()
00093         {
00094                 return _startPort;
00095         }
00096 
00097         //=========================================================================
00098         
00099         GPortModel* GConnectorModel::getEndPort()
00100         {
00101                 return _endPort;
00102         }
00103         
00104         //=========================================================================
00105 
00106         manualContourModel* GConnectorModel::getManualContourModel()
00107         {
00108                 return _model;
00109         }
00110 
00111         //=========================================================================
00112         
00113         void GConnectorModel::setManualContourModel(manualContourModel* model)
00114         {
00115                 _model = model;
00116         }
00117 
00118         //=========================================================================
00119 
00120         void GConnectorModel::updateStartEndPoints()
00121         {
00122                 //Start Point
00123                 double xCenter,yCenter,zCenter;         
00124                 _startPort->getCenter(xCenter,yCenter,zCenter);
00125                 double xport,yport,zport;
00126                 _startPort->getFinalPoint(xport,yport,zport);
00127 
00128                 // Refresh the position of the contourModel first point with the data of the connector model
00129                 manualPoint* point = _model->GetManualPoint(0);
00130                 point->SetPoint(xCenter,yport,zCenter);
00131 
00132                 //End Point     
00133                 _endPort->getCenter(xCenter,yCenter,zCenter);
00134                 _endPort->getInicPoint(xport,yport,zport);
00135 
00136                 // Refresh the position of the contourModel last point with the data of the connector model
00137                 point = _model->GetManualPoint(_model->GetSizeLstPoints()-1);
00138                 point->SetPoint(xCenter,yport,zCenter);
00139         }
00140 
00141         //=========================================================================
00142 
00143         void GConnectorModel::disconnectConnection()
00144         {
00145                 if(_startPort!=NULL)
00146                 {
00147                         _startPort->setConnected(false);                        
00148                 }
00149 
00150                 if(_endPort!=NULL)
00151                 {
00152                         _endPort->setConnected(false);
00153                 }
00154         }
00155 
00156         //=========================================================================
00157 
00158         void GConnectorModel::save(std::string &content)
00159         {
00160                 char buffer[50];
00161 
00162                 content+="CONNECTION\n";
00163 
00164                 // Connection info
00165                 content+=_startPort->getParentBox()->getBBTKName();
00166                 content+=":";
00167                 content+=_startPort->getBBTKName();
00168                 content+=":";
00169                 content+=_endPort->getParentBox()->getBBTKName();
00170                 content+=":";
00171                 content+=_endPort->getBBTKName();
00172                 content+="\n";
00173                 
00174                 int i,sizeLstPoints = _model->GetSizeLstPoints()-2;
00175                 content+="NumberOfControlPoints:";
00176                 sprintf (buffer, "%d", sizeLstPoints );
00177                 content+=buffer;
00178                 content+="\n";
00179                 
00180                 for (i=0;i<sizeLstPoints;i++)
00181                 {
00182                         manualPoint *mp = _model->GetManualPoint(i+1);
00183                         sprintf (buffer, "%f:%f:%f\n", (float)mp->GetX(),(float)mp->GetY(),(float)mp->GetZ() );
00184                         content+=buffer;
00185                 }               
00186         }
00187 
00188         //=========================================================================
00189 
00190 }  // EO namespace bbtk
00191 
00192 // EOF
00193 

Generated on Thu May 31 15:12:19 2012 for bbtkGEditor by  doxygen 1.5.7.1