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