]> Creatis software - bbtk.git/blob - kernel/src/bbtkWidgetBlackBox.txx
*** MAJOR CHANGE *** NOT WORKING YET !!!
[bbtk.git] / kernel / src / bbtkWidgetBlackBox.txx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWidgetBlackBox.txx,v $
4   Language:  C++
5   Date:      $Date: 2009/05/14 14:43:34 $
6   Version:   $Revision: 1.3 $
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  *  \file 
32  *  \brief 
33  */
34
35
36  
37 #include "bbtkWidgetBlackBoxWindow.h"
38 #include "bbtkBlackBoxOutputConnector.h"
39
40
41 namespace bbtk
42 {
43
44   //=========================================================================
45   // WidgetBlackBox
46   //=========================================================================
47
48   //=========================================================================
49   //=========================================================================
50   //=========================================================================
51   //=========================================================================
52   BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(WidgetBlackBox,AtomicBlackBox);
53   //=========================================================================
54   
55 //=========================================================================
56   template <class T>  
57   void WidgetBlackBox<T>::bbUserSetDefaultValues()
58   {
59     bbtkDebugMessage("widget",9,"WidgetBlackBox::bbUserSetDefaultValues()"<<std::endl);
60     bbmWindow = 0;
61     bbSetInputWinTitle(bbGetName());
62     bbSetInputWinWidth(800);
63     bbSetInputWinHeight(800);
64     bbSetInputWinDialog(false);
65     bbSetOutputWidget(0);
66   }
67   //=========================================================================
68
69  
70   //=========================================================================
71   template <class T>  
72   void WidgetBlackBox<T>::bbUserInitializeProcessing()
73   {
74   }
75   //=========================================================================
76
77   //=========================================================================
78   template <class T>  
79   void WidgetBlackBox<T>::bbUserFinalizeProcessing()
80   {
81     bbtkDebugMessage("widget",9,"==> WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
82     if (bbGetWindow()) {
83       bbGetWindow()->bbClose();
84       bbSetWindow(0);
85     }
86     bbtkDebugMessage("widget",9,"<== WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
87   }
88   //=========================================================================
89   
90
91
92  
93
94   //=========================================================================
95   template <class T>  
96   void WidgetBlackBox<T>::bbProcess()
97   { 
98     // TODO : update the window size and title 
99     this->bbUserProcess(); 
100   }
101   //=========================================================================
102
103   //=========================================================================
104   template <class T>  
105   void WidgetBlackBox<T>::bbCreateWindow()
106   { 
107
108
109     // If output 'Widget' not connected then
110     // it is a top level Widget have to create and show the Window
111     if ( ! bbIsOutputWidgetConnected() )
112       {
113         // create the Window if does not exist
114         if ( bbGetWindow() == 0)
115           {
116             bbtkDebugMessage("widget",2,
117                              "-> Creating the window"
118                              <<std::endl);
119             //      this->InitWindowManagerIfNeeded();
120             // If is a Dialog requested
121             if ( bbGetInputWinDialog() )
122               {
123                 bbtkDebugMessage("process",2,
124                                  "   Input WinDialog set to true : creating a Dialog"
125                                  <<std::endl);
126                 this->bbCreateDialogWindow();
127               }
128             // Input WinDialog set to false : creating a Frame
129             else 
130               {
131                 bbtkDebugMessage("process",2,
132                                  "   Input WinDialog set to false : creating a Frame"
133                                  <<std::endl);
134                 this->bbCreateFrameWindow();
135               }
136           }
137         // Show the window
138         if ( !bbGetWindow() )
139           {
140             bbtkInternalError("Need to show the Window of widget "<<bbGetName()
141                               <<" however was not created by apropriate cb");
142           }
143         bbtkDebugMessage("widget",2,
144                          "-> Showing the window"
145                          <<std::endl);
146         bbGetWindow()->bbShow(); 
147       }           
148     //   
149   }
150   //=========================================================================
151   
152
153   //==================================================================
154   template <class T>  
155   typename WidgetBlackBox<T>::WidgetPointer  
156   WidgetBlackBox<T>::bbCreateWidgetOfInput
157   (const std::string& in, typename WidgetBlackBox<T>::WidgetPointer parent)
158   {
159     Widget* w = 0;
160     // If input is connected 
161     BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
162     if ( c->IsConnected() )                     
163       {
164         // Get black box from 
165         BlackBox::Pointer from = 
166           c->GetConnection()->GetBlackBoxFrom();
167         // Cast it into a WidgetBlackBox
168         typename WidgetBlackBox<T>::Pointer wfrom 
169           = boost::dynamic_pointer_cast<WidgetBlackBox<T> >(from);
170         // If the black box from construction is not done yet : do it
171          // If not constructed do it 
172         wfrom->bbInitializeProcessing();
173         // Call bbUserCreateWidget
174         wfrom->bbUserCreateWidget(parent);
175         // Get the widget created
176         w = wfrom->bbGetOutputWidget();
177       }
178     return w;
179   }
180   //==================================================================
181
182   //=========================================================================
183   template <class T>  
184   bool WidgetBlackBox<T>::bbIsOutputWidgetConnected()
185   {
186     return ((*bbGetOutputConnectorMap().find("Widget")).second->GetConnectionVector().size() != 0 );
187   }
188   //==================================================================
189
190  //==================================================================
191   template <class T>  
192    void WidgetBlackBox<T>::bbShowWindow()
193   {
194     bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbShowWindow() ["
195                         <<bbGetFullName()<<"]"<<std::endl);
196
197     if (bbGetWindow()!=0) bbGetWindow()->bbShow();
198
199     bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbShowWindow() ["
200                         <<bbGetFullName()<<"]"<<std::endl);
201   }
202   //==================================================================
203
204   //==================================================================
205   template <class T>  
206    void WidgetBlackBox<T>::bbHideWindow()
207   {
208     bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbHideWindow() ["
209                         <<bbGetFullName()<<"]"<<std::endl);
210
211     if (bbGetWindow()!=0) bbGetWindow()->bbHide();
212
213     bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbHideWindow() ["
214                         <<bbGetFullName()<<"]"<<std::endl);
215   }
216   //==================================================================
217
218
219   //==================================================================
220   template <class T>  
221   void WidgetBlackBox<T>::bbCloseWindow()
222   {
223     bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbCloseWindow() ["
224                         <<bbGetFullName()<<"]"<<std::endl);
225
226     if (bbGetWindow()!=0) bbGetWindow()->bbClose();
227
228     bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbCloseWindow() ["
229                         <<bbGetFullName()<<"]"<<std::endl);
230   }
231   //==================================================================
232
233   //==================================================================
234   template <class T>  
235   typename WidgetBlackBox<T>::Window* 
236   WidgetBlackBox<T>::bbGetContainingWindow()
237   {
238     if (bbGetWindow()!=0) return bbGetWindow();
239     BlackBox::OutputConnectorMapType::const_iterator i 
240       = bbGetOutputConnectorMap().find("Widget");
241     if ( i->second->GetConnectionVector().size() != 0 ) 
242       {
243         return boost::static_pointer_cast<WidgetBlackBox>
244           (i->second->GetConnectionVector().front() //.lock()
245            ->GetBlackBoxTo())->bbGetContainingWindow();
246       }
247     return 0;
248   }
249   //==================================================================
250
251
252   //==================================================================
253   template <class T>  
254   bool WidgetBlackBox<T>::bbIsShown()
255   {
256     if (bbGetContainingWindow()!=0)
257       return bbGetContainingWindow()->bbIsShown();
258     return false;
259   }
260   //==================================================================
261
262
263 }//namespace bbtk
264
265
266
267