00001 /*========================================================================= 00002 Program: bbtk 00003 Module: $RCSfile: bbtkWidgetBlackBox.txx,v $ 00004 Language: C++ 00005 Date: $Date: 2010/01/14 13:17:27 $ 00006 Version: $Revision: 1.6 $ 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 00038 //#include "bbtkWidgetBlackBoxWindow.h" 00039 #include "bbtkBlackBoxOutputConnector.h" 00040 00041 00042 namespace bbtk 00043 { 00044 00045 //========================================================================= 00046 // WidgetBlackBox 00047 //========================================================================= 00048 00049 //========================================================================= 00050 //========================================================================= 00051 //========================================================================= 00052 //========================================================================= 00053 BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(WidgetBlackBox,AtomicBlackBox); 00054 //========================================================================= 00055 00056 //========================================================================= 00057 template <class T> 00058 void WidgetBlackBox<T>::bbUserSetDefaultValues() 00059 { 00060 bbtkBlackBoxDebugMessage("widget",9,"WidgetBlackBox::bbUserSetDefaultValues()"<<std::endl); 00061 // bbmWindow = 0; 00062 bbSetInputWinTitle(bbGetName()); 00063 bbSetInputWinWidth(800); 00064 bbSetInputWinHeight(800); 00065 bbSetInputWinDialog(false); 00066 bbSetOutputWidget(0); 00067 } 00068 //========================================================================= 00069 00070 00071 //========================================================================= 00072 template <class T> 00073 void WidgetBlackBox<T>::bbUserInitializeProcessing() 00074 { 00075 bbmShown = false; 00076 } 00077 //========================================================================= 00078 00079 //========================================================================= 00080 template <class T> 00081 void WidgetBlackBox<T>::bbUserFinalizeProcessing() 00082 { 00083 /* 00084 std::cout << "****** WidgetBlackBox<T>::bbUserFinalizeProcessing()"<<std::endl; 00085 bbtkBlackBoxDebugMessage("widget",9,"==> WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl); 00086 if (bbGetWindow()) 00087 { 00088 bool shown = bbGetWindow()->bbIsShown(); 00089 bbGetWindow()->bbDestroy(); 00090 bbSetWindow(0); 00091 00092 if (GetUseCount()==0) 00093 { 00094 bbtkBlackBoxDebugMessage("widget",9,"**** HERE use count == 0"<<std::endl); 00095 if (shown) DecNbWindowsShown(); 00096 DecNbWindowsAlive(); 00097 } 00098 00099 } 00100 bbtkBlackBoxDebugMessage("widget",9,"<== WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl); 00101 */ 00102 } 00103 //========================================================================= 00104 00105 00106 00107 00108 00109 //========================================================================= 00110 template <class T> 00111 void WidgetBlackBox<T>::bbProcess() 00112 { 00113 // TODO : update the window size and title 00114 this->bbUserProcess(); 00115 } 00116 //========================================================================= 00117 00118 //========================================================================= 00119 template <class T> 00120 void WidgetBlackBox<T>::bbCreateWindow() 00121 { 00122 00123 00124 // If output 'Widget' not connected then 00125 // it is a top level Widget have to create and show the Window 00126 if ( ! bbIsOutputWidgetConnected() ) 00127 { 00128 // create the Window if does not exist 00129 if (!bbWindowIsCreated()) 00130 { 00131 bbtkBlackBoxDebugMessage("widget",2, 00132 "-> Creating the window" 00133 <<std::endl); 00134 // Reinitializing 00135 bbSetShown(false); 00136 bbmNestedWidgetBoxes.clear(); 00137 00138 // this->InitWindowManagerIfNeeded(); 00139 // If is a Dialog requested 00140 if ( bbGetInputWinDialog() ) 00141 { 00142 bbtkBlackBoxDebugMessage("widget",2, 00143 " Input WinDialog set to true : creating a Dialog" 00144 <<std::endl); 00145 this->bbCreateDialogWindow(); 00146 } 00147 // Input WinDialog set to false : creating a Frame 00148 else 00149 { 00150 bbtkBlackBoxDebugMessage("widget",2, 00151 " Input WinDialog set to false : creating a Frame" 00152 <<std::endl); 00153 this->bbCreateFrameWindow(); 00154 } 00155 } 00156 /* 00157 // Show the window 00158 if ( !bbGetWindow() ) 00159 { 00160 bbtkInternalError("Need to show the Window of widget "<<bbGetName() 00161 <<" however was not created by apropriate cb"); 00162 } 00163 */ 00164 00165 /* 00166 bbtkBlackBoxDebugMessage("widget",2, 00167 "-> Showing the window" 00168 <<std::endl); 00169 // bbGetWindow()->bbShow(); 00170 this->bbShowWindow(); 00171 */ 00172 } 00173 // 00174 } 00175 //========================================================================= 00176 00177 00178 //================================================================== 00179 template <class T> 00180 typename WidgetBlackBox<T>::WidgetPointer 00181 WidgetBlackBox<T>::bbCreateWidgetOfInput 00182 (const std::string& in, typename WidgetBlackBox<T>::WidgetPointer parent) 00183 { 00184 bbtkBlackBoxDebugMessage("widget",2,"bbCreateWidgetOfInput(" 00185 <<in<<","<<parent<<")" 00186 <<std::endl); 00187 Widget* w = 0; 00188 // If input is connected 00189 BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ; 00190 if ( c->IsConnected() ) 00191 { 00192 // Get black box from 00193 BlackBox::Pointer from = 00194 c->GetConnection()->GetBlackBoxFrom(); 00195 // Cast it into a WidgetBlackBox 00196 typename WidgetBlackBox<T>::Pointer wfrom 00197 = boost::dynamic_pointer_cast<WidgetBlackBox<T> >(from); 00198 // If the black box from construction is not done yet : do it 00199 // If not constructed do it 00200 wfrom->bbInitializeProcessing(); 00201 // Call bbUserCreateWidget 00202 wfrom->bbUserCreateWidget(parent); 00203 // Get the widget created 00204 w = wfrom->bbGetOutputWidget(); 00205 // Insert the box into the NestedWidgetBoxes list 00206 bbmNestedWidgetBoxes.push_back(from); 00207 } 00208 return w; 00209 } 00210 //================================================================== 00211 00212 //========================================================================= 00213 template <class T> 00214 bool WidgetBlackBox<T>::bbIsOutputWidgetConnected() 00215 { 00216 return ((*bbGetOutputConnectorMap().find("Widget")).second->GetConnectionVector().size() != 0 ); 00217 } 00218 //================================================================== 00219 00220 //================================================================== 00221 template <class T> 00222 void WidgetBlackBox<T>::bbSetShown(bool b) 00223 { 00224 if (b==bbmShown) return; 00225 00226 bbtkBlackBoxDebugMessage("widget",5,"WidgetBlackBox::bbSetShown(" 00227 <<b<<")" 00228 <<std::endl); 00229 00230 bbmShown = b; 00231 if (b) 00232 { 00233 this->bbUserOnShow(); 00234 } 00235 // Have to propagate to nested widgets 00236 std::vector<BlackBox::WeakPointer>::const_iterator i; 00237 for (i =bbmNestedWidgetBoxes.begin(); 00238 i!=bbmNestedWidgetBoxes.end(); 00239 ++i) 00240 { 00241 if (!i->expired()) i->lock()->bbSetShown(b); 00242 } 00243 00244 } 00245 //================================================================== 00246 00247 //================================================================== 00248 template <class T> 00249 bool WidgetBlackBox<T>::bbIsShown() 00250 { 00251 return bbmShown; 00252 } 00253 //================================================================== 00254 00255 /* 00256 //================================================================== 00257 template <class T> 00258 void WidgetBlackBox<T>::bbShowWindow() 00259 { 00260 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbShowWindow() [" 00261 <<bbGetFullName()<<"]"<<std::endl); 00262 00263 if (bbGetWindow()!=0) bbGetWindow()->bbShow(); 00264 00265 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbShowWindow() [" 00266 <<bbGetFullName()<<"]"<<std::endl); 00267 } 00268 //================================================================== 00269 00270 //================================================================== 00271 template <class T> 00272 void WidgetBlackBox<T>::bbHideWindow() 00273 { 00274 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbHideWindow() [" 00275 <<bbGetFullName()<<"]"<<std::endl); 00276 00277 if (bbGetWindow()!=0) bbGetWindow()->bbHide(); 00278 00279 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbHideWindow() [" 00280 <<bbGetFullName()<<"]"<<std::endl); 00281 } 00282 //================================================================== 00283 00284 00285 //================================================================== 00286 template <class T> 00287 void WidgetBlackBox<T>::bbCloseWindow() 00288 { 00289 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbCloseWindow() [" 00290 <<bbGetFullName()<<"]"<<std::endl); 00291 00292 if (bbGetWindow()!=0) bbGetWindow()->bbDestroy(); 00293 00294 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbCloseWindow() [" 00295 <<bbGetFullName()<<"]"<<std::endl); 00296 } 00297 //================================================================== 00298 00299 //================================================================== 00300 template <class T> 00301 typename WidgetBlackBox<T>::Window* 00302 WidgetBlackBox<T>::bbGetContainingWindow() 00303 { 00304 if (bbGetWindow()!=0) return bbGetWindow(); 00305 BlackBox::OutputConnectorMapType::const_iterator i 00306 = bbGetOutputConnectorMap().find("Widget"); 00307 if ( i->second->GetConnectionVector().size() != 0 ) 00308 { 00309 return boost::static_pointer_cast<WidgetBlackBox> 00310 (i->second->GetConnectionVector().front() //.lock() 00311 ->GetBlackBoxTo())->bbGetContainingWindow(); 00312 } 00313 return 0; 00314 } 00315 //================================================================== 00316 00317 00318 //================================================================== 00319 template <class T> 00320 bool WidgetBlackBox<T>::bbIsShown() 00321 { 00322 if (bbGetContainingWindow()!=0) 00323 return bbGetContainingWindow()->bbIsShown(); 00324 return false; 00325 } 00326 //================================================================== 00327 */ 00328 00329 }//namespace bbtk 00330 00331 00332 00333