00001 /*========================================================================= 00002 Program: bbtk 00003 Module: $RCSfile: GObjectsMVCFactory.cxx,v $ 00004 Language: C++ 00005 Date: $Date: 2012/05/29 09:25:15 $ 00006 Version: $Revision: 1.3 $ 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 "GObjectsMVCFactory.h" 00038 00039 namespace bbtk 00040 { 00041 00042 00043 //========================================================================= 00044 00045 GObjectsMVCFactory* GObjectsMVCFactory:: instance = NULL; 00046 GObjectsMVCFactory::GObjectsMVCFactory() 00047 { 00048 _interpreter =Interpreter::New(); 00049 _interpreter->SetCommandLine(true); 00050 std::stringstream* buf = new std::stringstream; 00051 *buf << "exec freeze_no_error" << std::endl; 00052 *buf << "message max 0" << std::endl; 00053 *buf << "include *" << std::endl; 00054 _interpreter->InterpretBuffer(buf); 00055 } 00056 00057 //========================================================================= 00058 GObjectsMVCFactory::~GObjectsMVCFactory() 00059 { 00060 GObjectsMVCFactory::destroyInstance(); 00061 } 00062 //========================================================================= 00063 00064 BlackBoxDescriptor::Pointer GObjectsMVCFactory::getBlackBoxDescriptor(std::string packageName, std::string boxName) 00065 { 00066 Factory::Pointer factory; 00067 Package::Pointer k; 00068 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc; 00069 try{ 00070 factory = _interpreter->GetExecuter()->GetFactory(); 00071 k = factory->GetPackage(packageName); 00072 mapDesc = k->GetDescriptorMap(); 00073 }catch(Exception e){ 00074 printf("SCP: Exception in BlackBoxDescriptor::Pointer GObjectsMVCFactory::getBlackBoxDescriptor for package %s\n", packageName.c_str()); 00075 printf("SCP: ERROR package %s probably does not exist\n", packageName.c_str()); 00076 } 00077 00078 00079 return mapDesc[boxName]; 00080 } 00081 00082 //========================================================================= 00083 GObjectsMVCFactory* GObjectsMVCFactory :: getInstance() 00084 { 00085 if(instance == NULL){ 00086 instance = new GObjectsMVCFactory(); 00087 } 00088 return instance; 00089 } 00090 00091 //========================================================================= 00092 00093 void GObjectsMVCFactory :: destroyInstance() 00094 { 00095 //FCY memory leaks 00096 delete instance; 00097 instance=NULL; 00098 } 00099 00100 //========================================================================= 00101 00102 vtkGObjectView* GObjectsMVCFactory :: createGObjectView(int type) 00103 { 00104 vtkGObjectView* view = NULL; 00105 if (type == GBLACKBOX) 00106 { 00107 view = new vtkGBlackBoxView(); 00108 } 00109 else if(type == GPORT) 00110 { 00111 view = new vtkGPortView(); 00112 } 00113 else if(type == GCOMPLEXINPUTPORT || type == GCOMPLEXOUTPUTPORT) 00114 { 00115 view = new vtkGComplexBoxPortView(); 00116 } 00117 return view; 00118 } 00119 00120 //========================================================================= 00121 00122 GObjectController* GObjectsMVCFactory :: createGObjectController(int type) 00123 { 00124 GObjectController *controller = NULL; 00125 if (type == GBLACKBOX) 00126 { 00127 controller = new GBlackBoxController(); 00128 } 00129 else if(type == GPORT) 00130 { 00131 controller = new GPortController(); 00132 } 00133 else if(type == GCOMPLEXINPUTPORT || type == GCOMPLEXOUTPUTPORT) 00134 { 00135 controller = new GBoxController(); 00136 } 00137 return controller; 00138 } 00139 00140 //========================================================================= 00141 00142 GObjectModel* GObjectsMVCFactory :: createGObjectModel(int type) 00143 { 00144 GObjectModel *model = NULL; 00145 if (type == GBLACKBOX) 00146 { 00147 model = new GBlackBoxModel(); 00148 } 00149 else if(type == GPORT) 00150 { 00151 model = new GPortModel(); 00152 } 00153 else if(type == GCOMPLEXINPUTPORT || type == GCOMPLEXOUTPUTPORT) 00154 { 00155 model = new GComplexBoxPortModel(); 00156 } 00157 00158 model->setGObjectType(type); 00159 00160 return model; 00161 } 00162 00163 //========================================================================= 00164 00165 00166 } // EO namespace bbtk 00167 00168 // EOF 00169