]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxBlackBox.cxx
New widget pipeline : progressing ...
[bbtk.git] / kernel / src / bbtkWxBlackBox.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxBlackBox.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/11/25 11:17:13 $
6   Version:   $Revision: 1.31 $
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
32 #ifdef _USE_WXWIDGETS_
33
34
35
36 /**
37  *  \file 
38  *  \brief 
39  */
40  
41 #include "bbtkWxBlackBox.h"
42 //#include "bbtkWxContainerBlackBox.h"
43 #include <wx/dialog.h>
44
45 //#include "bbtkData.h"
46 //#include "bbtkFactory.h"
47
48
49
50
51 namespace bbtk
52 {
53
54
55
56
57   //=========================================================================
58   // WxBlackBoxWindow
59   //=========================================================================
60
61
62
63   //=========================================================================
64   WxBlackBoxWindow::WxBlackBoxWindow(WxBlackBox::Pointer box)
65     : mBox(box), mShown(false)
66   {
67     bbtkDebugMessage("wx",9,"WxBlackBoxWindow::WxBlackBoxWindow("<<
68                      mBox.lock()->bbGetFullName()<<")"<<std::endl);
69     mBox.lock()->bbSetWindow(this);
70     Wx::IncNbWindowsAlive();
71   }
72   //=========================================================================
73
74   //=========================================================================
75   WxBlackBoxWindow::~WxBlackBoxWindow()
76   {
77     bbtkDebugMessage("wx",9,"WxBlackBoxWindow::~WxBlackBoxWindow() "
78                      <<this<<std::endl);
79     bbHide();
80     Wx::DecNbWindowsAlive();
81     if (!mBox.expired())
82       {
83         mBox.lock()->bbSetWindow(0);
84       }
85   }
86   //========================================================================= 
87
88
89   //=========================================================================
90   void WxBlackBoxWindow::bbShow()
91   {
92     if (bbIsShown()) return;
93     bbtkDebugMessage("wx",9,"WxBlackBoxWindow::bbShow()"<<std::endl);
94     Wx::IncNbWindowsShown();
95     mShown = true;
96   }
97   //=========================================================================
98
99   //=========================================================================
100   void WxBlackBoxWindow::bbHide()
101   {
102     if (!bbIsShown()) return;
103     bbtkDebugMessage("wx",9,"WxBlackBoxWindow::bbHide()"<<std::endl);
104     Wx::DecNbWindowsShown();
105     mShown = false;
106   }
107   //=========================================================================
108
109   //=========================================================================
110   void WxBlackBoxWindow::bbClose()
111   {
112   }
113   //=========================================================================
114
115
116   //=========================================================================
117   // WxBlackBoxDialog
118   //=========================================================================
119
120   //=========================================================================
121   WxBlackBoxDialog::WxBlackBoxDialog(WxBlackBox::Pointer box,
122                                      wxWindow *parent,
123                                      wxString title,
124                                      wxSize size)
125     :
126     wxDialog( parent, 
127                 -1, 
128                 title,
129                 wxDefaultPosition,
130                 size,
131                 wxRESIZE_BORDER | 
132                 wxSYSTEM_MENU  |
133                 wxCLOSE_BOX |
134                 wxMAXIMIZE_BOX | 
135                 wxMINIMIZE_BOX | 
136                 wxCAPTION  
137               ),
138     WxBlackBoxWindow(box)
139   {
140     bbtkDebugMessage("wx",9,"WxBlackBoxDialog::WxBlackBoxDialog("<<
141                      bbGetBlackBox()->bbGetFullName()<<","<<parent<<","
142                      <<title<<",size)"<<std::endl);
143     // Insert the widget into the window
144     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
145           // LG 22/11/08 : new widget pipeline
146           bbGetBlackBox()->bbCreateWidgetAndEventHandler(this);
147     wxWindow* widget = bbGetBlackBox()->bbGetOutputWidget();
148 // old :    widget->Reparent(this);
149     sizer->Add( widget, 1, wxALL|wxEXPAND, 2);
150     //SetAutoLayout(true);
151     SetSizer(sizer);
152     Layout();
153   }
154   //=========================================================================
155   
156   //=========================================================================
157   void WxBlackBoxDialog::bbShow()
158   { 
159     if (bbIsShown()) return;
160     bbtkDebugMessage("wx",5,"WxBlackBoxDialog::bbShow() ["
161                      <<bbGetBlackBox()->bbGetFullName()<<"]"<<std::endl);
162     WxBlackBoxWindow::bbShow();
163     SetReturnCode( wxDialog::ShowModal() ); 
164     bbClose();
165   }
166   //=========================================================================
167
168   //=========================================================================
169   void WxBlackBoxDialog::bbHide()
170   {
171     bbtkDebugMessage("wx",9,"WxBlackBoxDialog::bbHide()"<<std::endl);
172     WxBlackBoxWindow::bbHide();
173     Hide();
174   }
175   //=========================================================================
176
177   //=========================================================================
178   void WxBlackBoxDialog::bbClose()
179   {
180     bbtkDebugMessage("wx",9,"WxBlackBoxDialog::bbClose()"<<std::endl);
181     wxDialog::Destroy();
182   }
183   //=========================================================================
184
185   //=========================================================================
186   WxBlackBoxDialog::~WxBlackBoxDialog()
187   {
188   }
189   //=========================================================================
190
191
192
193
194
195   //=========================================================================
196   // WxBlackBoxFrame
197   //=========================================================================
198
199   //=========================================================================
200   WxBlackBoxFrame::WxBlackBoxFrame(WxBlackBox::Pointer box,
201                                    wxWindow *parent,
202                                    wxString title,
203                                    wxSize size)
204     :  wxFrame( parent, 
205                -1, 
206                title,
207                wxDefaultPosition,
208                size,
209                wxRESIZE_BORDER | 
210                wxSYSTEM_MENU  |
211                wxCLOSE_BOX |
212                wxMAXIMIZE_BOX | 
213                wxMINIMIZE_BOX | 
214                wxCAPTION  
215                 ),
216        WxBlackBoxWindow(box)
217   {
218     bbtkDebugMessage("wx",9,"WxBlackBoxFrame::WxBlackBoxFrame("<<
219                      bbGetBlackBox()->bbGetFullName()<<","<<parent<<","
220                      <<title<<",size)"<<std::endl);
221     // Insert the widget into the window
222     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
223           // LG 22/11/08 : new widget pipeline
224           bbGetBlackBox()->bbCreateWidgetAndEventHandler(this);
225     wxWindow* widget = bbGetBlackBox()->bbGetOutputWidget();
226     wxFrame* frame = (wxFrame*)this;
227 // old :    widget->Reparent(frame);
228     sizer->Add( widget, 1, wxALL|wxGROW, 2);
229     //  frame->SetAutoLayout(true);
230     frame->SetSizer(sizer);
231     //frame->Fit();
232     frame->Layout();
233   }
234   //=========================================================================
235   
236   //=========================================================================
237   WxBlackBoxFrame::~WxBlackBoxFrame()
238   {
239   }
240   //=========================================================================
241
242   //=========================================================================
243   void WxBlackBoxFrame::bbShow() 
244   { 
245     if (bbIsShown()) return;
246     bbtkDebugMessage("wx",5,"WxBlackBoxFrame::bbShow("
247                      <<bbGetBlackBox()->bbGetFullName()<<")"<<std::endl);
248     WxBlackBoxWindow::bbShow();
249   wxFrame::Show();
250     // This Update is ** MANDATORY ** 
251     // to synchronize wxvtkRenderWindowInteractor objects
252     // (force wx objects creation **NOW**)
253
254
255 #if defined(_WIN32)
256       wxFrame::Refresh();
257 #endif
258
259       wxFrame::Update();
260       wxFrame::SetFocus();
261     if (bbGetBlackBox()) bbGetBlackBox()->bbUserOnShow();
262   }
263   //=========================================================================
264
265   //=========================================================================
266   void WxBlackBoxFrame::bbHide()
267   {
268     bbtkDebugMessage("wx",9,"WxBlackBoxFrame::bbHide()"<<std::endl);
269     WxBlackBoxWindow::bbHide();
270     wxFrame::Hide();
271     if (bbGetBlackBox()) bbGetBlackBox()->bbUserOnHide();
272   }
273   //=========================================================================
274
275   //=========================================================================
276   void WxBlackBoxFrame::bbClose()
277   {
278     bbtkDebugMessage("wx",9,"WxBlackBoxFrame::bbClose()"<<std::endl);
279     wxFrame::Close();
280   }
281   //=========================================================================
282
283
284
285   //=========================================================================
286   // WxBlackBoxWidgetEventHandler
287   //=========================================================================
288
289   //=========================================================================
290   WxBlackBoxWidgetEventHandler::
291   WxBlackBoxWidgetEventHandler( WxBlackBox::Pointer box, 
292                                 wxWindow *widget )
293     :
294     mBox(box),
295     mWindow(widget)
296   { 
297     bbtkDebugMessage("wx",9,"WxBlackBoxWidgetEventHandler::WxBlackBoxWidgetEventHandler("<<mBox.lock()->bbGetFullName()<<")"<<std::endl);
298
299     mBox.lock()->bbSetWidgetEventHandler(this);
300
301     Connect (  mWindow->GetId(),
302                wxEVT_DESTROY,
303                (wxObjectEventFunction) 
304                (void (wxEvtHandler::*)(wxWindowDestroyEvent& c))
305                 &WxBlackBoxWidgetEventHandler::OnWindowDestroy );
306     
307     mWindow->PushEventHandler(this);
308     
309   }
310   //=========================================================================
311
312   //=========================================================================
313   WxBlackBoxWidgetEventHandler::~WxBlackBoxWidgetEventHandler()
314   {
315     if (mBox.expired()) return;
316     bbtkDebugMessage("wx",9,
317                      "WxBlackBoxWidgetEventHandler::~WxBlackBoxWidgetEventHandler() ["
318                      <<mBox.lock()->bbGetFullName()<<"]"<<std::endl);
319      mBox.lock()->bbSetWidgetEventHandler(0);   
320   }
321   //=========================================================================
322
323   //=========================================================================
324   void WxBlackBoxWidgetEventHandler::OnWindowDestroy(wxWindowDestroyEvent&)
325   {
326     if (mBox.expired()) return;
327     bbtkDebugMessage("wx",9,"WxBlackBoxWidgetEventHandler::OnWindowDestroy() ["
328                      <<mBox.lock()->bbGetFullName()<<"]"<<std::endl);
329     mBox.lock()->bbSetOutputWidget(0);
330     mBox.lock()->bbSetModifiedStatus();
331   }
332   //=========================================================================
333
334
335
336
337
338
339
340   //=========================================================================
341   // WxBlackBox
342   //=========================================================================
343
344   //=========================================================================
345   //=========================================================================
346   //=========================================================================
347   //=========================================================================
348   BBTK_BLACK_BOX_IMPLEMENTATION(WxBlackBox,AtomicBlackBox);
349   //=========================================================================
350   
351   //=========================================================================
352   void WxBlackBox::bbUserConstructor()
353   {
354     bbtkDebugMessage("Kernel",9,"WxBlackBox::bbUserConstructor()"<<std::endl);
355     bbInitAttributes();
356   }
357   //=========================================================================
358
359   //=========================================================================
360   void WxBlackBox::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
361   {
362     bbtkDebugMessage("Kernel",9,"WxBlackBox::bbUserCopyConstructor()"
363                      <<std::endl);
364     bbInitAttributes();
365   }
366   //=========================================================================
367
368
369   //=========================================================================
370   void WxBlackBox::bbUserDestructor()
371   {
372     bbtkDebugMessage("wx",9,"==> WxBlackBox::bbUserDestructor() ["<<bbGetFullName()<<"]"<<std::endl);
373     if (bbGetWindow()) {
374       delete bbGetWindow();
375       bbSetWindow(0);
376     }
377     bbtkDebugMessage("wx",9,"<== WxBlackBox::bbUserDestructor() ["<<bbGetFullName()<<"]"<<std::endl);
378   }
379   //=========================================================================
380   
381
382   /*
383   //=========================================================================
384   WxBlackBox::Widget*  WxBlackBox::bbGetWidget()
385   { 
386     if (bbGetOutputWidget() && bbGetOutputWidget()->IsDead()) 
387       {
388         bbtkDebugMessage("wx",9,"WxBlackBox::bbGetWidget() ["<<
389                          bbGetFullName()<<"] : Widget is dead : deleting it"
390                          <<std::endl);
391         delete bbGetOutputWidget();
392         bbSetOutputWidget(0);
393       }
394     return bbGetOutputWidget();
395   }
396   //=========================================================================
397   */
398
399
400   //=========================================================================
401   /**
402    * \brief Initialize the attributes of the class
403    *
404    */
405   void WxBlackBox::bbInitAttributes()
406   {
407     bbmWindow = 0;
408     //    bbmWidget = 0;
409     //    bbSetInputWinParent(0);
410     bbSetInputWinTitle(bbGetName());
411     bbSetInputWinWidth(800);
412     bbSetInputWinHeight(800);
413     bbSetInputWinDialog(false);
414     bbSetOutputWidget(0);
415
416     bbSetWidgetEventHandler(0);
417     bbSetUpdateTransferedToParent(false);
418   }
419   //=========================================================================
420
421   //=========================================================================
422   /// Main processing method of the box.
423   void WxBlackBox::bbExecute(bool force)
424   {
425     bbtkDebugMessageInc("process",2,
426                         "=> WxBlackBox::bbExecute("<<(int)force<<") ["
427                         <<bbGetFullName()<<"]"<<std::endl);
428
429     // If the output 'Widget' is connected then 
430     // we must execute the parent box
431     BlackBox::OutputConnectorMapType::const_iterator i 
432       = bbGetOutputConnectorMap().find("Widget");
433
434     if ( i->second->GetConnectionVector().size() != 0 ) 
435       {
436         bbtkDebugMessage("process",3,
437                          "-> Output 'Widget' connected : transfering execution to parent"
438                          <<std::endl);
439         
440         i->second->GetConnectionVector().front() //.lock()
441           ->GetBlackBoxTo()->bbExecute(force);
442
443       }
444     // else call 'standard' BlackBox execution method
445     else 
446       {
447         BlackBox::bbExecute(force);
448       }
449     //
450
451     bbtkDebugMessageDec("process",2,
452                         "<= WxBlackBox::bbExecute() ["
453                         <<bbGetFullName()<<"]"<<std::endl);
454   }
455   //=========================================================================
456
457
458   //=========================================================================
459   /// Main processing method of the box.
460   IOStatus WxBlackBox::bbBackwardUpdate( Connection::Pointer caller )
461   {
462     bbtkDebugMessage("process",3,
463                      "=> WxBlackBox::bbBackwardUpdate("
464                      <<(caller?caller->GetFullName():"0")<<") ["
465                      <<bbGetFullName()<<"]"<<std::endl);
466
467     if ( ! (( bbGetStatus() == MODIFIED ) ||
468             ( bbBoxProcessModeIsAlways() )) )
469       {
470         bbtkDebugMessage("process",3,"Up-to-date : nothing to do"<<std::endl);
471         bbtkDebugMessage("process",3,
472                          "<= WxBlackBox::bbBackwardUpdate("
473                          <<(caller?caller->GetFullName():"0")<<") ["
474                          <<bbGetFullName()<<"]"<<std::endl);
475         return bbGetStatus();
476       }
477  
478     // If the caller's box to is not the box to connected to the 
479     // output 'Widget'
480
481     BlackBox::OutputConnectorMapType::const_iterator i 
482       = bbGetOutputConnectorMap().find("Widget") ;
483     if ( i->second->GetConnectionVector().size() != 0 )
484       
485       {
486         BlackBox::Pointer to = 
487           i->second->GetConnectionVector()[0]->GetBlackBoxTo();
488                 
489         if (caller) 
490           {
491             bbtkDebugMessage("process",3,
492                              "-> Output 'Widget' connected to '"
493                              <<to->bbGetFullName()<<"' - caller->to = '"
494                              <<caller->GetBlackBoxTo()->bbGetFullName()
495                              <<"'"
496                              <<std::endl);
497           }
498         else
499           {
500             bbtkDebugMessage("process",3,
501                              "-> Output 'Widget' connected to '"
502                              <<to->bbGetFullName()<<"'"
503                              <<std::endl);
504           }
505         if ((caller==0) ||
506             ( (caller!=0) && 
507               (caller->GetBlackBoxTo() != to)&&
508               (!bbGetUpdateTransferedToParent())&&
509               (!to->bbGetExecuting()) 
510               )
511             )
512           {
513             bbtkDebugMessage("process",3,
514                              "   ... Transfering update order to parent"
515                              <<std::endl);
516             
517             bbSetUpdateTransferedToParent(true);
518             i->second->GetConnectionVector().front() //.lock()
519               ->GetBlackBoxTo()->bbExecute(false);
520           }
521         else
522           {
523             bbSetUpdateTransferedToParent(false);
524             bbtkDebugMessage("process",3,
525                              "   ... No need to transfer to parent"
526                              <<std::endl);
527           }
528       }
529     /*    
530
531     // If the caller is not the connection to the output widget
532     // and the output 'Widget' is connected then 
533     // we must execute the parent box 
534     // but only one time 
535     // (this is the role of the flag UpdateTransferedToParent)
536     if ( (caller==0) ||
537          ((caller!=0)&&(caller->GetBlackBoxFromOutput()!="Widget"))
538          )
539       {
540       }
541     */
542     // call 'standard' BlackBox execution method
543     if (!bbGetUpdateTransferedToParent()) 
544       { 
545           AtomicBlackBox::bbBackwardUpdate(caller);
546       }
547     
548     bbtkDebugMessageDec("process",3,
549                         "<= WxBlackBox::bbBackwardUpdate() ["
550                         <<bbGetFullName()<<"]"<<std::endl);
551     
552    return bbGetStatus();
553      
554
555   }
556
557   //=========================================================================
558   void WxBlackBox::bbProcess()
559   { 
560 /*
561           if (bbGetOutputWidget()==0) this->bbUserCreateWidget();
562     this->bbUserProcess(); 
563     bbShowWindow();
564     //    this->bbUserOnShow();
565 */
566           // LG 22/11/08 : new widget pipeline
567           // If output widget not connected : 
568           if ( (*bbGetOutputConnectorMap().find("Widget")).second
569                   ->GetConnectionVector().size() == 0 ) 
570       {
571                   Window* show = 0;
572                   // If the window already exists : no need creating it
573                   if (bbGetWindow()!=0)
574                   {
575                           bbtkDebugMessage("wx",2,
576                                                            "-> Window already exists"
577                                                            <<std::endl);
578                           show = bbGetWindow();
579                   }
580                   // Else create window 
581                   else 
582                   {
583                           bbtkDebugMessage("wx",2,
584                                                            "-> Creating the window"
585                                                            <<std::endl);
586                           
587                           
588                           // Input WinDialog set to true : creating a Dialog
589                           if (bbGetInputWinDialog()) 
590                           {
591                                   bbtkDebugMessage("wx",2,
592                                                                    "   Input WinDialog set to true : creating a Dialog"
593                                                                    <<std::endl);
594                                   show = (Window*) new WxBlackBoxDialog( GetThisPointer<WxBlackBox>(),
595                                                                                                                 // bbGetWxParent(), 
596                                                                                                                 // LG 24/11/08 : New widget pipeline
597                                                                                                                 Wx::GetTopWindow(),
598                                                                                                                 std2wx( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN"),
599                                                                                                                 wxSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) );
600                           }
601                           // Input WinDialog set to false : creating a Frame
602                           else 
603                           {
604                                   bbtkDebugMessage("process",2,
605                                                                    "   Input WinDialog set to false : creating a Frame"
606                                                                    <<std::endl);
607                                   show = (Window*) new WxBlackBoxFrame( GetThisPointer<WxBlackBox>(),
608                                                                                                            // bbGetWxParent(), 
609                                                                                                            // LG 24/11/08 : New widget pipeline
610                                                                                                            Wx::GetTopWindow(),
611                                                                                                            std2wx( bbGetInputWinTitle()  + " - bbtk (c) CREATIS LRMN"),
612                                                                                                            wxSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) );
613                           }
614                                                   
615                   }
616                 
617                   // Show the window
618                   show->bbShow(); 
619                   
620                   
621           }               
622           this->bbUserProcess(); 
623           
624   }
625   //=========================================================================
626  
627         
628         
629         // LG 24/11/08 : New widget pipeline
630         void WxBlackBox::bbCreateWidgetAndEventHandler(wxWindow* parent)
631         {
632                 if (bbGetOutputWidget()==0)
633                 {
634                         this->bbUserCreateWidget(parent);
635                 }               
636                 // If Event Handler for the widget does not exist or is obsolete : create it 
637                 if (bbGetOutputWidget()!=0)
638                 {
639                         if (bbGetWidgetEventHandler()==0)
640                         {
641                                 bbtkDebugMessage("wx",3,
642                                                                  "-> No widget event handler : creating one"
643                                                                  <<std::endl);
644                                 new WxBlackBoxWidgetEventHandler(GetThisPointer<WxBlackBox>(),
645                                                                                                  bbGetOutputWidget());
646                         }
647                         else if ( ! bbGetWidgetEventHandler()->IsHandlerOf 
648                                          ( bbGetOutputWidget() ) )
649                         {
650                                 bbtkDebugMessage("wx",3,
651                                                                  "-> Obsolete widget event handler : re-creating one"
652                                                                  <<std::endl);
653                                 delete bbGetWidgetEventHandler();
654                                 new WxBlackBoxWidgetEventHandler(GetThisPointer<WxBlackBox>(),
655                                                                                                  bbGetOutputWidget());
656                         }
657                         // Sets the name of the wxWindow to the input WinTitle
658                         bbGetOutputWidget()->SetName(bbtk::std2wx(bbGetInputWinTitle()));
659                 }
660                 
661                 
662         }
663
664
665         
666         wxWindow*  WxBlackBox::bbCreateWidgetOfInput(const std::string& in, wxWindow* parent)
667         {
668                 wxWindow* w = 0;
669                 // If input is connected 
670                 BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
671                 if ( c->IsConnected() )                 
672                 {
673                         // Get black box from 
674                         BlackBox::Pointer from = 
675                         c->GetConnection()->GetBlackBoxFrom();
676                         // Cast it into a WxBlackBox
677                         WxBlackBox::Pointer wfrom = boost::dynamic_pointer_cast<WxBlackBox>(from);
678                         // Call bbCreateWidgetAndEventHandler
679                         wfrom->bbCreateWidgetAndEventHandler(parent);
680                         // Get the widget created
681                         w = wfrom->bbGetOutputWidget();
682                 }
683                 return w;
684         }
685
686         /*
687   //==================================================================
688   /// Specific methods for window creation during pipeline execution
689   /// Shows the window associated to the box 
690   /// (called after bbProcess during bbExecute)
691   void WxBlackBox::bbShowWindow()
692   {
693     bbtkDebugMessageInc("wx",1,"=> WxBlackBox::bbShowWindow() ["
694                         <<bbGetFullName()<<"]"<<std::endl);
695  
696     // If Event Handler for the widget does not exist or is obsolete : create it 
697     if (bbGetOutputWidget()!=0)
698       {
699         if (bbGetWidgetEventHandler()==0)
700           {
701             bbtkDebugMessage("wx",3,
702                              "-> No widget event handler : creating one"
703                              <<std::endl);
704             new WxBlackBoxWidgetEventHandler(GetThisPointer<WxBlackBox>(),
705                                              bbGetOutputWidget());
706           }
707         else if ( ! bbGetWidgetEventHandler()->IsHandlerOf 
708                   ( bbGetOutputWidget() ) )
709           {
710             bbtkDebugMessage("wx",3,
711                              "-> Obsolete widget event handler : re-creating one"
712                              <<std::endl);
713             delete bbGetWidgetEventHandler();
714             new WxBlackBoxWidgetEventHandler(GetThisPointer<WxBlackBox>(),
715                                              bbGetOutputWidget());
716           }
717         // Sets the name of the wxWindow to the input WinTitle
718         bbGetOutputWidget()->SetName(bbtk::std2wx(bbGetInputWinTitle()));
719       }
720
721     // If the output 'Widget' is connected then it's gonna 
722     // be captured by its parent window : nothing to do 
723     if ( (*bbGetOutputConnectorMap().find("Widget")).second
724          ->GetConnectionVector().size() != 0 ) 
725       {
726         
727         bbtkDebugMessage("wx",2,
728                          "-> Output 'Widget' connected : nothing to do"
729                          <<std::endl);
730         return;
731       }
732
733
734     Window* show = 0;
735     // If the window already exists : no need creating it
736     if (bbGetWindow()!=0)
737       {
738         bbtkDebugMessage("wx",2,
739                          "-> Window already exists"
740                          <<std::endl);
741         show = bbGetWindow();
742       }
743     // Else if the widget exists : create window 
744     else if (bbGetOutputWidget()!=0) 
745       {
746         bbtkDebugMessage("wx",2,
747                          "-> Widget exists : creating the window"
748                          <<std::endl);
749
750
751         // Input WinDialog set to true : creating a Dialog
752         if (bbGetInputWinDialog()) 
753           {
754             bbtkDebugMessage("wx",2,
755                              "   Input WinDialog set to true : creating a Dialog"
756                              <<std::endl);
757             show = (Window*) new WxBlackBoxDialog( GetThisPointer<WxBlackBox>(),
758                                                   // bbGetWxParent(), 
759                                                                                           // LG 24/11/08 : New widget pipeline
760                                                                                           Wx::GetTopWindow(),
761                                                    std2wx( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN"),
762                                                    wxSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) );
763           }
764         // Input WinDialog set to false : creating a Frame
765         else 
766           {
767             bbtkDebugMessage("process",2,
768                              "   Input WinDialog set to false : creating a Frame"
769                              <<std::endl);
770             show = (Window*) new WxBlackBoxFrame( GetThisPointer<WxBlackBox>(),
771                                                   // bbGetWxParent(), 
772                                                                                          // LG 24/11/08 : New widget pipeline
773                                                                                          Wx::GetTopWindow(),
774                                                   std2wx( bbGetInputWinTitle()  + " - bbtk (c) CREATIS LRMN"),
775                                                   wxSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) );
776           }
777
778       }
779     // No window nor widget : error
780     else
781       {
782         bbtkError("WxBlackBox::bbShowWindow() ["
783                   <<bbGetFullName()
784                   <<"] : No widget. Did you set the box output 'Widget' in the processing method of the box ?");
785       }
786  
787     
788     // Show the window
789     if (true) //!show->IsShown())
790       {
791         show->bbShow(); 
792       }
793     else 
794       {
795         bbtkDebugMessage("wx",2,"-> Already shown : nothing to do"<<std::endl);
796       }
797   
798
799     bbtkDebugMessage("wx",2,"<= WxBlackBox::bbShowWindow() ["
800                         <<bbGetFullName()<<"]"<<std::endl);
801
802   }
803   //==================================================================
804 */
805
806
807
808   //==================================================================
809    void WxBlackBox::bbHideWindow()
810   {
811     bbtkDebugMessageInc("wx",1,"=> WxBlackBox::bbHideWindow() ["
812                         <<bbGetFullName()<<"]"<<std::endl);
813
814     if (bbGetWindow()!=0) bbGetWindow()->bbHide();
815
816     bbtkDebugMessageDec("wx",2,"<= WxBlackBox::bbHideWindow() ["
817                         <<bbGetFullName()<<"]"<<std::endl);
818   }
819   //==================================================================
820
821
822   //==================================================================
823    void WxBlackBox::bbCloseWindow()
824   {
825     bbtkDebugMessageInc("wx",1,"=> WxBlackBox::bbCloseWindow() ["
826                         <<bbGetFullName()<<"]"<<std::endl);
827
828     if (bbGetWindow()!=0) bbGetWindow()->bbClose();
829
830     bbtkDebugMessageDec("wx",2,"<= WxBlackBox::bbCloseWindow() ["
831                         <<bbGetFullName()<<"]"<<std::endl);
832   }
833   //==================================================================
834
835   //==================================================================
836   WxBlackBox::Window* WxBlackBox::bbGetContainingWindow()
837   {
838     if (bbGetWindow()!=0) return bbGetWindow();
839     BlackBox::OutputConnectorMapType::const_iterator i 
840       = bbGetOutputConnectorMap().find("Widget");
841     if ( i->second->GetConnectionVector().size() != 0 ) 
842       {
843         return boost::static_pointer_cast<WxBlackBox>
844           (i->second->GetConnectionVector().front() //.lock()
845            ->GetBlackBoxTo())->bbGetContainingWindow();
846       }
847     return 0;
848   }
849   //==================================================================
850
851
852   //==================================================================
853         // LG 24/11/08 : New widget pipeline
854         //  wxWindow* WxBlackBox::bbGetWxParent() { return Wx::GetTopWindow(); }
855   //==================================================================
856   
857   
858   //==================================================================
859   bool WxBlackBox::bbIsShown()
860   {
861     if (bbGetContainingWindow()!=0)
862       return bbGetContainingWindow()->bbIsShown();
863     return false;
864   }
865   //==================================================================
866
867
868 }//namespace bbtk
869
870
871 #endif
872