]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkWxBlackBox.cxx
Created a bbs editor : bbed
[bbtk.git] / kernel / src / bbtkWxBlackBox.cxx
index 1cea747459170fe233e9acec99b57b89f49ce3f1..5b8e52f0efb5602342b05dae1757008387228853 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxBlackBox.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/02/08 10:05:38 $
-  Version:   $Revision: 1.7 $
+  Date:      $Date: 2008/03/10 12:28:43 $
+  Version:   $Revision: 1.10 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -55,7 +55,7 @@ namespace bbtk
                     mBox->bbGetFullName()<<")"<<std::endl);
     mBox->bbSetWindow(this);
     Wx::IncNbWindowsAlive();
-    bbtkDebugMessage("Wx",9," -> Number of windows alive = "
+    bbtkDebugMessage("Wx",5," -> Number of windows alive = "
                     <<Wx::GetNbWindowsAlive()<<std::endl);
   }
   //=========================================================================
@@ -68,13 +68,14 @@ namespace bbtk
     bbHide();
     mBox->bbSetWindow(0);
     Wx::DecNbWindowsAlive();
-    bbtkDebugMessage("Wx",9," -> Number of windows alive = "
+    bbtkDebugMessage("Wx",5," -> Number of windows alive = "
                     <<Wx::GetNbWindowsAlive()<<std::endl);
      
 
   }
   //========================================================================= 
 
+
   //=========================================================================
   void WxBlackBoxWindow::bbShow()
   {
@@ -83,7 +84,7 @@ namespace bbtk
                     mBox->bbGetFullName()<<"]"<<std::endl);
     Wx::IncNbWindowsShown();
     mShown = true;
-    bbtkDebugMessage("Wx",9," -> Number of windows shown = "
+    bbtkDebugMessage("Wx",5," -> Number of windows shown = "
                     <<Wx::GetNbWindowsShown()<<std::endl);
   }
   //=========================================================================
@@ -96,7 +97,7 @@ namespace bbtk
                     mBox->bbGetFullName()<<"]"<<std::endl);
     Wx::DecNbWindowsShown();
     mShown = false;
-    bbtkDebugMessage("Wx",9," -> Number of windows shown = "
+    bbtkDebugMessage("Wx",5," -> Number of windows shown = "
                     <<Wx::GetNbWindowsShown()<<std::endl);
   }
   //=========================================================================
@@ -222,7 +223,13 @@ namespace bbtk
     bbtkDebugMessage("Wx",5,"WxBlackBoxFrame::bbShow("
                     <<bbGetBlackBox()->bbGetFullName()<<")"<<std::endl);
     WxBlackBoxWindow::bbShow();
-    wxFrame::Show(); 
+    wxFrame::Show();
+    // This Update is ** MANDATORY ** 
+    // to synchronize wxvtkRenderWindowInteractor objects
+    // (force wx objects creation **NOW**)
+    wxFrame::Update();
+    bbGetBlackBox()->bbUserOnShow();
+    //    wxFrame::SetFocus();
   }
   //=========================================================================
 
@@ -232,7 +239,8 @@ namespace bbtk
     bbtkDebugMessage("Wx",9,"WxBlackBoxFrame::bbHide() ["<<
                     bbGetBlackBox()->bbGetFullName()<<"]"<<std::endl);
     WxBlackBoxWindow::bbHide();
-    Hide();
+    wxFrame::Hide();
+    bbGetBlackBox()->bbUserOnHide();
   }
   //=========================================================================
 
@@ -486,8 +494,52 @@ namespace bbtk
   }
   //=========================================================================
 
+  //=========================================================================
+  /// Main processing method of the box.
+  void WxBlackBox::bbExecute(bool force)
+  {
+    bbtkDebugMessageInc("Process",1,
+                       "=> WxBlackBox::bbExecute() ["
+                       <<bbGetFullName()<<"]"<<std::endl);
 
+    // If the output 'Widget' is connected then 
+    // we must execute the parent box
+    BlackBox::OutputConnectorMapType::const_iterator i 
+      = bbGetOutputConnectorMap().find("Widget");
 
+    if ( i->second->GetConnectionVector().size() != 0 ) 
+      {
+       bbtkDebugMessage("Process",2,
+                        "-> Output 'Widget' connected : transfering execution to parent"
+                        <<std::endl);
+       
+       i->second->GetConnectionVector().front()
+         ->GetBlackBoxTo()->bbExecute(force);
+
+      }
+    // else call 'standard' BlackBox execution method
+    else 
+      {
+       BlackBox::bbExecute(force);
+      }
+    //
+
+    bbtkDebugMessageDec("Process",1,
+                       "<= WxBlackBox::bbExecute() ["
+                       <<bbGetFullName()<<"]"<<std::endl);
+  }
+  //=========================================================================
+
+
+  //=========================================================================
+  void WxBlackBox::bbProcess()
+  { 
+    if (bbGetOutputWidget()==0) this->bbUserCreateWidget();
+    this->bbUserProcess(); 
+    bbShowWindow();
+  }
+  //=========================================================================
+  
   //==================================================================
   /// Specific methods for window creation during pipeline execution
   /// Shows the window associated to the box 
@@ -558,7 +610,7 @@ namespace bbtk
                             "   Input WinDialog set to true : creating a Dialog"
                             <<std::endl);
            show = (Window*) new WxBlackBoxDialog( this,
-                                                  Wx::GetTopWindow(), 
+                                                  bbGetWxParent(), 
                                                   std2wx( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN"),
                                                   wxSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) );
          }
@@ -569,7 +621,7 @@ namespace bbtk
                             "   Input WinDialog set to false : creating a Frame"
                             <<std::endl);
            show = (Window*) new WxBlackBoxFrame( this,
-                                                 Wx::GetTopWindow(), 
+                                                 bbGetWxParent(), 
                                                  std2wx( bbGetInputWinTitle()  + " - bbtk (c) CREATIS LRMN"),
                                                  wxSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) );
          }
@@ -618,6 +670,35 @@ namespace bbtk
   //==================================================================
 
 
+  //==================================================================
+  WxBlackBox::Window* WxBlackBox::bbGetContainingWindow()
+  {
+    if (bbGetWindow()!=0) return bbGetWindow();
+    BlackBox::OutputConnectorMapType::const_iterator i 
+      = bbGetOutputConnectorMap().find("Widget");
+    if ( i->second->GetConnectionVector().size() != 0 ) 
+      {
+       return ((WxBlackBox*)i->second->GetConnectionVector().front()
+               ->GetBlackBoxTo())->bbGetContainingWindow();
+      }
+    return 0;
+  }
+  //==================================================================
+
+
+  //==================================================================
+  wxWindow* WxBlackBox::bbGetWxParent() { return Wx::GetTopWindow(); }
+  //==================================================================
+  
+  
+  //==================================================================
+  bool WxBlackBox::bbIsShown()
+  {
+    if (bbGetContainingWindow()!=0)
+      return bbGetContainingWindow()->bbIsShown();
+    return false;
+  }
+  //==================================================================
 
 
 }//namespace bbtk