]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxBlackBox.cxx
No more transfered execution to parent for widget boxes (buggy...)
[bbtk.git] / kernel / src / bbtkWxBlackBox.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxBlackBox.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/12/03 09:38:02 $
6   Version:   $Revision: 1.32 $
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     /*
426     bbtkDebugMessageInc("process",2,
427                         "=> WxBlackBox::bbExecute("<<(int)force<<") ["
428                         <<bbGetFullName()<<"]"<<std::endl);
429     */
430     /*
431     // If the output 'Widget' is connected then 
432     // we must execute the parent box
433     BlackBox::OutputConnectorMapType::const_iterator i 
434       = bbGetOutputConnectorMap().find("Widget");
435
436     if ( i->second->GetConnectionVector().size() != 0 ) 
437       {
438         bbtkDebugMessage("process",3,
439                          "-> Output 'Widget' connected : transfering execution to parent"
440                          <<std::endl);
441         
442         i->second->GetConnectionVector().front() //.lock()
443           ->GetBlackBoxTo()->bbExecute(force);
444
445       }
446     */
447     /*
448     if (false)
449       {
450       }
451     // else call 'standard' BlackBox execution method
452     else 
453       {
454     */
455         return AtomicBlackBox::bbExecute(force);
456         /*
457       }
458     //
459
460     bbtkDebugMessageDec("process",2,
461                         "<= WxBlackBox::bbExecute() ["
462                         <<bbGetFullName()<<"]"<<std::endl);
463         */
464   }
465   //=========================================================================
466
467
468   //=========================================================================
469   /// Main processing method of the box.
470   IOStatus WxBlackBox::bbBackwardUpdate( Connection::Pointer caller )
471   {
472     bbtkDebugMessage("process",3,
473                      "=> WxBlackBox::bbBackwardUpdate("
474                      <<(caller?caller->GetFullName():"0")<<") ["
475                      <<bbGetFullName()<<"]"<<std::endl);
476
477     if ( ! (( bbGetStatus() == MODIFIED ) ||
478             ( bbBoxProcessModeIsAlways() )) )
479       {
480         bbtkDebugMessage("process",3,"Up-to-date : nothing to do"<<std::endl);
481         bbtkDebugMessage("process",3,
482                          "<= WxBlackBox::bbBackwardUpdate("
483                          <<(caller?caller->GetFullName():"0")<<") ["
484                          <<bbGetFullName()<<"]"<<std::endl);
485         return bbGetStatus();
486       }
487  
488     // If the caller's box to is not the box to connected to the 
489     // output 'Widget'
490     /*
491     BlackBox::OutputConnectorMapType::const_iterator i 
492       = bbGetOutputConnectorMap().find("Widget") ;
493     if ( i->second->GetConnectionVector().size() != 0 )
494       
495       {
496         BlackBox::Pointer to = 
497           i->second->GetConnectionVector()[0]->GetBlackBoxTo();
498                 
499         if (caller) 
500           {
501             bbtkDebugMessage("process",3,
502                              "-> Output 'Widget' connected to '"
503                              <<to->bbGetFullName()<<"' - caller->to = '"
504                              <<caller->GetBlackBoxTo()->bbGetFullName()
505                              <<"'"
506                              <<std::endl);
507           }
508         else
509           {
510             bbtkDebugMessage("process",3,
511                              "-> Output 'Widget' connected to '"
512                              <<to->bbGetFullName()<<"'"
513                              <<std::endl);
514           }
515         if ((caller==0) ||
516             ( (caller!=0) && 
517               (caller->GetBlackBoxTo() != to)&&
518               (!bbGetUpdateTransferedToParent())&&
519               (!to->bbGetExecuting()) 
520               )
521             )
522           {
523             bbtkDebugMessage("process",3,
524                              "   ... Transfering update order to parent"
525                              <<std::endl);
526             
527             bbSetUpdateTransferedToParent(true);
528             i->second->GetConnectionVector().front() //.lock()
529               ->GetBlackBoxTo()->bbExecute(false);
530           }
531         else
532           {
533             bbSetUpdateTransferedToParent(false);
534             bbtkDebugMessage("process",3,
535                              "   ... No need to transfer to parent"
536                              <<std::endl);
537           }
538       }
539     */
540     /*    
541
542     // If the caller is not the connection to the output widget
543     // and the output 'Widget' is connected then 
544     // we must execute the parent box 
545     // but only one time 
546     // (this is the role of the flag UpdateTransferedToParent)
547     if ( (caller==0) ||
548          ((caller!=0)&&(caller->GetBlackBoxFromOutput()!="Widget"))
549          )
550       {
551       }
552     */
553     // call 'standard' BlackBox execution method
554     if (!bbGetUpdateTransferedToParent()) 
555       { 
556           AtomicBlackBox::bbBackwardUpdate(caller);
557       }
558     
559     bbtkDebugMessageDec("process",3,
560                         "<= WxBlackBox::bbBackwardUpdate() ["
561                         <<bbGetFullName()<<"]"<<std::endl);
562     
563    return bbGetStatus();
564      
565
566   }
567
568   //=========================================================================
569   void WxBlackBox::bbProcess()
570   { 
571 /*
572           if (bbGetOutputWidget()==0) this->bbUserCreateWidget();
573     this->bbUserProcess(); 
574     bbShowWindow();
575     //    this->bbUserOnShow();
576 */
577           // LG 22/11/08 : new widget pipeline
578           // If output widget not connected : 
579           if ( (*bbGetOutputConnectorMap().find("Widget")).second
580                   ->GetConnectionVector().size() == 0 ) 
581       {
582                   Window* show = 0;
583                   // If the window already exists : no need creating it
584                   if (bbGetWindow()!=0)
585                   {
586                           bbtkDebugMessage("wx",2,
587                                                            "-> Window already exists"
588                                                            <<std::endl);
589                           show = bbGetWindow();
590                   }
591                   // Else create window 
592                   else 
593                   {
594                           bbtkDebugMessage("wx",2,
595                                                            "-> Creating the window"
596                                                            <<std::endl);
597                           
598                           
599                           // Input WinDialog set to true : creating a Dialog
600                           if (bbGetInputWinDialog()) 
601                           {
602                                   bbtkDebugMessage("wx",2,
603                                                                    "   Input WinDialog set to true : creating a Dialog"
604                                                                    <<std::endl);
605                                   show = (Window*) new WxBlackBoxDialog( GetThisPointer<WxBlackBox>(),
606                                                                                                                 // bbGetWxParent(), 
607                                                                                                                 // LG 24/11/08 : New widget pipeline
608                                                                                                                 Wx::GetTopWindow(),
609                                                                                                                 std2wx( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN"),
610                                                                                                                 wxSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) );
611                           }
612                           // Input WinDialog set to false : creating a Frame
613                           else 
614                           {
615                                   bbtkDebugMessage("process",2,
616                                                                    "   Input WinDialog set to false : creating a Frame"
617                                                                    <<std::endl);
618                                   show = (Window*) new WxBlackBoxFrame( GetThisPointer<WxBlackBox>(),
619                                                                                                            // bbGetWxParent(), 
620                                                                                                            // LG 24/11/08 : New widget pipeline
621                                                                                                            Wx::GetTopWindow(),
622                                                                                                            std2wx( bbGetInputWinTitle()  + " - bbtk (c) CREATIS LRMN"),
623                                                                                                            wxSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) );
624                           }
625                                                   
626                   }
627                 
628                   // Show the window
629                   show->bbShow(); 
630                   
631                   
632           }               
633           this->bbUserProcess(); 
634           
635   }
636   //=========================================================================
637  
638         
639         
640         // LG 24/11/08 : New widget pipeline
641         void WxBlackBox::bbCreateWidgetAndEventHandler(wxWindow* parent)
642         {
643                 if (bbGetOutputWidget()==0)
644                 {
645                         this->bbUserCreateWidget(parent);
646                 }               
647                 // If Event Handler for the widget does not exist or is obsolete : create it 
648                 if (bbGetOutputWidget()!=0)
649                 {
650                         if (bbGetWidgetEventHandler()==0)
651                         {
652                                 bbtkDebugMessage("wx",3,
653                                                                  "-> No widget event handler : creating one"
654                                                                  <<std::endl);
655                                 new WxBlackBoxWidgetEventHandler(GetThisPointer<WxBlackBox>(),
656                                                                                                  bbGetOutputWidget());
657                         }
658                         else if ( ! bbGetWidgetEventHandler()->IsHandlerOf 
659                                          ( bbGetOutputWidget() ) )
660                         {
661                                 bbtkDebugMessage("wx",3,
662                                                                  "-> Obsolete widget event handler : re-creating one"
663                                                                  <<std::endl);
664                                 delete bbGetWidgetEventHandler();
665                                 new WxBlackBoxWidgetEventHandler(GetThisPointer<WxBlackBox>(),
666                                                                                                  bbGetOutputWidget());
667                         }
668                         // Sets the name of the wxWindow to the input WinTitle
669                         bbGetOutputWidget()->SetName(bbtk::std2wx(bbGetInputWinTitle()));
670                 }
671                 
672                 
673         }
674
675
676         
677         wxWindow*  WxBlackBox::bbCreateWidgetOfInput(const std::string& in, wxWindow* parent)
678         {
679                 wxWindow* w = 0;
680                 // If input is connected 
681                 BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
682                 if ( c->IsConnected() )                 
683                 {
684                         // Get black box from 
685                         BlackBox::Pointer from = 
686                         c->GetConnection()->GetBlackBoxFrom();
687                         // Cast it into a WxBlackBox
688                         WxBlackBox::Pointer wfrom = boost::dynamic_pointer_cast<WxBlackBox>(from);
689                         // Call bbCreateWidgetAndEventHandler
690                         wfrom->bbCreateWidgetAndEventHandler(parent);
691                         // Get the widget created
692                         w = wfrom->bbGetOutputWidget();
693                 }
694                 return w;
695         }
696
697         /*
698   //==================================================================
699   /// Specific methods for window creation during pipeline execution
700   /// Shows the window associated to the box 
701   /// (called after bbProcess during bbExecute)
702   void WxBlackBox::bbShowWindow()
703   {
704     bbtkDebugMessageInc("wx",1,"=> WxBlackBox::bbShowWindow() ["
705                         <<bbGetFullName()<<"]"<<std::endl);
706  
707     // If Event Handler for the widget does not exist or is obsolete : create it 
708     if (bbGetOutputWidget()!=0)
709       {
710         if (bbGetWidgetEventHandler()==0)
711           {
712             bbtkDebugMessage("wx",3,
713                              "-> No widget event handler : creating one"
714                              <<std::endl);
715             new WxBlackBoxWidgetEventHandler(GetThisPointer<WxBlackBox>(),
716                                              bbGetOutputWidget());
717           }
718         else if ( ! bbGetWidgetEventHandler()->IsHandlerOf 
719                   ( bbGetOutputWidget() ) )
720           {
721             bbtkDebugMessage("wx",3,
722                              "-> Obsolete widget event handler : re-creating one"
723                              <<std::endl);
724             delete bbGetWidgetEventHandler();
725             new WxBlackBoxWidgetEventHandler(GetThisPointer<WxBlackBox>(),
726                                              bbGetOutputWidget());
727           }
728         // Sets the name of the wxWindow to the input WinTitle
729         bbGetOutputWidget()->SetName(bbtk::std2wx(bbGetInputWinTitle()));
730       }
731
732     // If the output 'Widget' is connected then it's gonna 
733     // be captured by its parent window : nothing to do 
734     if ( (*bbGetOutputConnectorMap().find("Widget")).second
735          ->GetConnectionVector().size() != 0 ) 
736       {
737         
738         bbtkDebugMessage("wx",2,
739                          "-> Output 'Widget' connected : nothing to do"
740                          <<std::endl);
741         return;
742       }
743
744
745     Window* show = 0;
746     // If the window already exists : no need creating it
747     if (bbGetWindow()!=0)
748       {
749         bbtkDebugMessage("wx",2,
750                          "-> Window already exists"
751                          <<std::endl);
752         show = bbGetWindow();
753       }
754     // Else if the widget exists : create window 
755     else if (bbGetOutputWidget()!=0) 
756       {
757         bbtkDebugMessage("wx",2,
758                          "-> Widget exists : creating the window"
759                          <<std::endl);
760
761
762         // Input WinDialog set to true : creating a Dialog
763         if (bbGetInputWinDialog()) 
764           {
765             bbtkDebugMessage("wx",2,
766                              "   Input WinDialog set to true : creating a Dialog"
767                              <<std::endl);
768             show = (Window*) new WxBlackBoxDialog( GetThisPointer<WxBlackBox>(),
769                                                   // bbGetWxParent(), 
770                                                                                           // LG 24/11/08 : New widget pipeline
771                                                                                           Wx::GetTopWindow(),
772                                                    std2wx( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN"),
773                                                    wxSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) );
774           }
775         // Input WinDialog set to false : creating a Frame
776         else 
777           {
778             bbtkDebugMessage("process",2,
779                              "   Input WinDialog set to false : creating a Frame"
780                              <<std::endl);
781             show = (Window*) new WxBlackBoxFrame( GetThisPointer<WxBlackBox>(),
782                                                   // bbGetWxParent(), 
783                                                                                          // LG 24/11/08 : New widget pipeline
784                                                                                          Wx::GetTopWindow(),
785                                                   std2wx( bbGetInputWinTitle()  + " - bbtk (c) CREATIS LRMN"),
786                                                   wxSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) );
787           }
788
789       }
790     // No window nor widget : error
791     else
792       {
793         bbtkError("WxBlackBox::bbShowWindow() ["
794                   <<bbGetFullName()
795                   <<"] : No widget. Did you set the box output 'Widget' in the processing method of the box ?");
796       }
797  
798     
799     // Show the window
800     if (true) //!show->IsShown())
801       {
802         show->bbShow(); 
803       }
804     else 
805       {
806         bbtkDebugMessage("wx",2,"-> Already shown : nothing to do"<<std::endl);
807       }
808   
809
810     bbtkDebugMessage("wx",2,"<= WxBlackBox::bbShowWindow() ["
811                         <<bbGetFullName()<<"]"<<std::endl);
812
813   }
814   //==================================================================
815 */
816
817
818
819   //==================================================================
820    void WxBlackBox::bbHideWindow()
821   {
822     bbtkDebugMessageInc("wx",1,"=> WxBlackBox::bbHideWindow() ["
823                         <<bbGetFullName()<<"]"<<std::endl);
824
825     if (bbGetWindow()!=0) bbGetWindow()->bbHide();
826
827     bbtkDebugMessageDec("wx",2,"<= WxBlackBox::bbHideWindow() ["
828                         <<bbGetFullName()<<"]"<<std::endl);
829   }
830   //==================================================================
831
832
833   //==================================================================
834    void WxBlackBox::bbCloseWindow()
835   {
836     bbtkDebugMessageInc("wx",1,"=> WxBlackBox::bbCloseWindow() ["
837                         <<bbGetFullName()<<"]"<<std::endl);
838
839     if (bbGetWindow()!=0) bbGetWindow()->bbClose();
840
841     bbtkDebugMessageDec("wx",2,"<= WxBlackBox::bbCloseWindow() ["
842                         <<bbGetFullName()<<"]"<<std::endl);
843   }
844   //==================================================================
845
846   //==================================================================
847   WxBlackBox::Window* WxBlackBox::bbGetContainingWindow()
848   {
849     if (bbGetWindow()!=0) return bbGetWindow();
850     BlackBox::OutputConnectorMapType::const_iterator i 
851       = bbGetOutputConnectorMap().find("Widget");
852     if ( i->second->GetConnectionVector().size() != 0 ) 
853       {
854         return boost::static_pointer_cast<WxBlackBox>
855           (i->second->GetConnectionVector().front() //.lock()
856            ->GetBlackBoxTo())->bbGetContainingWindow();
857       }
858     return 0;
859   }
860   //==================================================================
861
862
863   //==================================================================
864         // LG 24/11/08 : New widget pipeline
865         //  wxWindow* WxBlackBox::bbGetWxParent() { return Wx::GetTopWindow(); }
866   //==================================================================
867   
868   
869   //==================================================================
870   bool WxBlackBox::bbIsShown()
871   {
872     if (bbGetContainingWindow()!=0)
873       return bbGetContainingWindow()->bbIsShown();
874     return false;
875   }
876   //==================================================================
877
878
879 }//namespace bbtk
880
881
882 #endif
883