]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkKWBlackBox.cxx
BUG MACOS
[bbtk.git] / kernel / src / bbtkKWBlackBox.cxx
index f1de79ed6ed67b9afb44fc9e9d49bc009e511cb8..08679361b1b485a4123fd916b7c12f5ba0e38066 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkKWBlackBox.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/11/29 21:41:33 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2008/12/18 11:54:44 $
+  Version:   $Revision: 1.8 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
 
  
 #include "bbtkKWBlackBox.h"
-#include "vtkObjectFactory.h"
+#include "bbtkBlackBoxOutputConnector.h"
+#include "vtkKWBlackBoxDialog.h"
 
 
 namespace bbtk
 {
 
-
-  //=========================================================================
-  // vtkKWBlackBoxWindow
-  //=========================================================================
-
-
-
-  //=========================================================================
-  vtkKWBlackBoxWindow::vtkKWBlackBoxWindow()
-    : mShown(false)
-  {
-    bbtkDebugMessage("kw",9,"vtkKWBlackBoxWindow::vtkKWBlackBoxWindow()"
-                    <<std::endl);
-    KW::IncNbWindowsAlive();
-  }
-  //=========================================================================
-
-
-
-  //=========================================================================
-  vtkKWBlackBoxWindow::~vtkKWBlackBoxWindow()
-  {
-    bbtkDebugMessage("kw",9,"vtkKWBlackBoxWindow::~vtkKWBlackBoxWindow() "
-                    <<this<<std::endl);
-    bbHide();
-    KW::DecNbWindowsAlive();
-    if (!mBox.expired())
-      {
-       mBox.lock()->bbSetWindow(0);
-      }
-  }
-  //========================================================================= 
-
-
-  //=========================================================================
-  void vtkKWBlackBoxWindow::bbShow()
-  {
-    if (bbIsShown()) return;
-    bbtkDebugMessage("kw",9,"vtkKWBlackBoxWindow::bbShow()"<<std::endl);
-    KW::IncNbWindowsShown();
-    mShown = true;
-  }
-  //=========================================================================
-
-  //=========================================================================
-  void vtkKWBlackBoxWindow::bbHide()
-  {
-    if (!bbIsShown()) return;
-    bbtkDebugMessage("kw",9,"vtkKWBlackBoxWindow::bbHide()"<<std::endl);
-    KW::DecNbWindowsShown();
-    mShown = false;
-  }
-  //=========================================================================
-
-  //=========================================================================
-  void vtkKWBlackBoxWindow::bbClose()
-  {
-  }
-  //=========================================================================
-
-
-  //=========================================================================
-  // vtkKWBlackBoxDialog
-  //=========================================================================
-  
-  //-------------------------------------------------------------------------
-  vtkStandardNewMacro( vtkKWBlackBoxDialog );
-  vtkCxxRevisionMacro(vtkKWBlackBoxDialog, "$Revision: 1.1 $");
-  //-------------------------------------------------------------------------
-
-  //=========================================================================
-  vtkKWBlackBoxDialog::vtkKWBlackBoxDialog()
-  {
-    bbtkDebugMessage("kw",9,"vtkKWBlackBoxDialog::vtkKWBlackBoxDialog()"
-                    <<std::endl);
-  }
-  //=========================================================================
-  
-  //=========================================================================
-  void vtkKWBlackBoxDialog::bbShow()
-  { 
-    if (bbIsShown()) return;
-    bbtkDebugMessage("kw",5,"vtkKWBlackBoxDialog::bbShow() ["
-                    <<bbGetBlackBox()->bbGetFullName()<<"]"<<std::endl);
-    vtkKWBlackBoxWindow::bbShow();
-    //SetReturnCode( kwDialog::ShowModal() ); 
-    this->Display();
-    bbClose();
-  }
-  //=========================================================================
-
-  //=========================================================================
-  void vtkKWBlackBoxDialog::bbHide()
-  {
-    bbtkDebugMessage("kw",9,"vtkKWBlackBoxDialog::bbHide()"<<std::endl);
-    vtkKWBlackBoxWindow::bbHide();
-    //    Hide();
-    this->Withdraw();
-  }
-  //=========================================================================
-
-  //=========================================================================
-  void vtkKWBlackBoxDialog::bbClose()
-  {
-    bbtkDebugMessage("kw",9,"vtkKWBlackBoxDialog::bbClose()"<<std::endl);
-    this->Done = vtkKWDialog::StatusCanceled;
-    //   this->Delete();
-  }
-  //=========================================================================
-
-  //=========================================================================
-  void vtkKWBlackBoxDialog::Cancel()
-  {
-    bbtkDebugMessage("kw",9,"vtkKWBlackBoxDialog::Cancel()"<<std::endl);
-    this->Delete();
-  }
-  //=========================================================================
-  //=========================================================================
-  vtkKWBlackBoxDialog::~vtkKWBlackBoxDialog()
-  {
-  }
-  //=========================================================================
-
-
-
-
-
-  //=========================================================================
-  // vtkKWBlackBoxFrame
-  //=========================================================================
-
-  //-------------------------------------------------------------------------
-  vtkStandardNewMacro( vtkKWBlackBoxFrame );
-  vtkCxxRevisionMacro(vtkKWBlackBoxFrame, "$Revision: 1.1 $");
-  //-------------------------------------------------------------------------
-  //=========================================================================
-  vtkKWBlackBoxFrame::vtkKWBlackBoxFrame()
-  {
-    bbtkDebugMessage("kw",9,"vtkKWBlackBoxFrame::vtkKWBlackBoxFrame()"<<std::endl);
-  }
-  //=========================================================================
-  
-  //=========================================================================
-  vtkKWBlackBoxFrame::~vtkKWBlackBoxFrame()
-  {
-  }
-  //=========================================================================
-
-  //=========================================================================
-  void vtkKWBlackBoxFrame::bbShow() 
-  { 
-    if (bbIsShown()) return;
-    bbtkDebugMessage("kw",5,"vtkKWBlackBoxFrame::bbShow("
-                    <<bbGetBlackBox()->bbGetFullName()<<")"<<std::endl);
-    vtkKWBlackBoxWindow::bbShow();
-    // vtkKWFrame::Show();
-    this->Display();
-    // This Update is ** MANDATORY ** 
-    // to synchronize kwvtkRenderWindowInteractor objects
-    // (force kw objects creation **NOW**)
-    /*
-
-#if defined(_WIN32)
-      kwFrame::Refresh();
-#endif
-
-      kwFrame::Update();
-      kwFrame::SetFocus();
-    */
-    if (bbGetBlackBox()) bbGetBlackBox()->bbUserOnShow();
-  }
-  //=========================================================================
-
-  //=========================================================================
-  void vtkKWBlackBoxFrame::bbHide()
-  {
-    bbtkDebugMessage("kw",9,"vtkKWBlackBoxFrame::bbHide()"<<std::endl);
-    vtkKWBlackBoxWindow::bbHide();
-    //  vtkKWFrame::Hide();
-    this->Withdraw();
-    if (bbGetBlackBox()) bbGetBlackBox()->bbUserOnHide();
-  }
-  //=========================================================================
-
-  //=========================================================================
-  void vtkKWBlackBoxFrame::bbClose()
-  {
-    bbtkDebugMessage("kw",9,"vtkKWBlackBoxFrame::bbClose()"<<std::endl);
-    //    vtkKWFrame::Close();
-    this->Delete();
-  }
-  //=========================================================================
-
-
-  /*
-  //=========================================================================
-  // KWBlackBoxWidgetEventHandler
-  //=========================================================================
-
-  //=========================================================================
-  KWBlackBoxWidgetEventHandler::
-  KWBlackBoxWidgetEventHandler( KWBlackBox::Pointer box, 
-                               vtkKWWidget *widget )
-    :
-    mBox(box),
-    mWindow(widget)
-  { 
-    bbtkDebugMessage("kw",9,"KWBlackBoxWidgetEventHandler::KWBlackBoxWidgetEventHandler("<<mBox.lock()->bbGetFullName()<<")"<<std::endl);
-
-    mBox.lock()->bbSetWidgetEventHandler(this);
-
-    Connect (  mWindow->GetId(),
-              kwEVT_DESTROY,
-              (kwObjectEventFunction) 
-              (void (kwEvtHandler::*)(kwWindowDestroyEvent& c))
-               &KWBlackBoxWidgetEventHandler::OnWindowDestroy );
-    
-    mWindow->PushEventHandler(this);
-    
-  }
-  //=========================================================================
-
-  //=========================================================================
-  KWBlackBoxWidgetEventHandler::~KWBlackBoxWidgetEventHandler()
-  {
-    if (mBox.expired()) return;
-    bbtkDebugMessage("kw",9,
-                    "KWBlackBoxWidgetEventHandler::~KWBlackBoxWidgetEventHandler() ["
-                    <<mBox.lock()->bbGetFullName()<<"]"<<std::endl);
-     mBox.lock()->bbSetWidgetEventHandler(0);   
-  }
-  //=========================================================================
-
-  //=========================================================================
-  void KWBlackBoxWidgetEventHandler::OnWindowDestroy(kwWindowDestroyEvent&)
-  {
-    if (mBox.expired()) return;
-    bbtkDebugMessage("kw",9,"KWBlackBoxWidgetEventHandler::OnWindowDestroy() ["
-                    <<mBox.lock()->bbGetFullName()<<"]"<<std::endl);
-    mBox.lock()->bbSetOutputWidget(0);
-    mBox.lock()->bbSetModifiedStatus();
-  }
-  //=========================================================================
-
-
-  */
-
-
-
-
   //=========================================================================
   // KWBlackBox
   //=========================================================================
@@ -355,155 +106,15 @@ namespace bbtk
     bbSetOutputWidget(0);
 
     //    bbSetWidgetEventHandler(0);
-    bbSetUpdateTransferedToParent(false);
+    //  bbSetUpdateTransferedToParent(false);
   }
   //=========================================================================
 
-  //=========================================================================
-  /// Main processing method of the box.
-  void KWBlackBox::bbExecute(bool force)
-  {
-    bbtkDebugMessageInc("process",2,
-                       "=> KWBlackBox::bbExecute("<<(int)force<<") ["
-                       <<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",3,
-                        "-> Output 'Widget' connected : transfering execution to parent"
-                        <<std::endl);
-       
-       i->second->GetConnectionVector().front() //.lock()
-         ->GetBlackBoxTo()->bbExecute(force);
-
-      }
-    // else call 'standard' BlackBox execution method
-    else 
-      {
-       BlackBox::bbExecute(force);
-      }
-    //
-
-    bbtkDebugMessageDec("process",2,
-                       "<= KWBlackBox::bbExecute() ["
-                       <<bbGetFullName()<<"]"<<std::endl);
-  }
-  //=========================================================================
-
-
-  //=========================================================================
-  /// Main processing method of the box.
-  IOStatus KWBlackBox::bbBackwardUpdate( Connection::Pointer caller )
-  {
-    bbtkDebugMessage("process",3,
-                    "=> KWBlackBox::bbBackwardUpdate("
-                    <<(caller?caller->GetFullName():"0")<<") ["
-                    <<bbGetFullName()<<"]"<<std::endl);
-
-    if ( ! (( bbGetStatus() == MODIFIED ) ||
-           ( bbBoxProcessModeIsAlways() )) )
-      {
-       bbtkDebugMessage("process",3,"Up-to-date : nothing to do"<<std::endl);
-       bbtkDebugMessage("process",3,
-                        "<= KWBlackBox::bbBackwardUpdate("
-                        <<(caller?caller->GetFullName():"0")<<") ["
-                        <<bbGetFullName()<<"]"<<std::endl);
-       return bbGetStatus();
-      }
-    // If the caller's box to is not the box to connected to the 
-    // output 'Widget'
-
-    BlackBox::OutputConnectorMapType::const_iterator i 
-      = bbGetOutputConnectorMap().find("Widget") ;
-    if ( i->second->GetConnectionVector().size() != 0 )
-      
-      {
-       BlackBox::Pointer to = 
-         i->second->GetConnectionVector()[0]->GetBlackBoxTo();
-               
-       if (caller) 
-         {
-           bbtkDebugMessage("process",3,
-                            "-> Output 'Widget' connected to '"
-                            <<to->bbGetFullName()<<"' - caller->to = '"
-                            <<caller->GetBlackBoxTo()->bbGetFullName()
-                            <<"'"
-                            <<std::endl);
-         }
-       else
-         {
-           bbtkDebugMessage("process",3,
-                            "-> Output 'Widget' connected to '"
-                            <<to->bbGetFullName()<<"'"
-                            <<std::endl);
-         }
-       if ((caller==0) ||
-           ( (caller!=0) && 
-             (caller->GetBlackBoxTo() != to)&&
-             (!bbGetUpdateTransferedToParent())&&
-             (!to->bbGetExecuting()) 
-             )
-           )
-         {
-           bbtkDebugMessage("process",3,
-                            "   ... Transfering update order to parent"
-                            <<std::endl);
-           
-           bbSetUpdateTransferedToParent(true);
-           i->second->GetConnectionVector().front() //.lock()
-             ->GetBlackBoxTo()->bbExecute(false);
-         }
-       else
-         {
-           bbSetUpdateTransferedToParent(false);
-           bbtkDebugMessage("process",3,
-                            "   ... No need to transfer to parent"
-                            <<std::endl);
-         }
-      }
-    /*    
-
-    // If the caller is not the connection to the output widget
-    // and the output 'Widget' is connected then 
-    // we must execute the parent box 
-    // but only one time 
-    // (this is the role of the flag UpdateTransferedToParent)
-    if ( (caller==0) ||
-        ((caller!=0)&&(caller->GetBlackBoxFromOutput()!="Widget"))
-        )
-      {
-      }
-    */
-    // call 'standard' BlackBox execution method
-    if (!bbGetUpdateTransferedToParent()) 
-      { 
-         AtomicBlackBox::bbBackwardUpdate(caller);
-      }
-    
-    bbtkDebugMessageDec("process",3,
-                       "<= KWBlackBox::bbBackwardUpdate() ["
-                       <<bbGetFullName()<<"]"<<std::endl);
-    
-   return bbGetStatus();
-     
-
-  }
 
   //=========================================================================
   void KWBlackBox::bbProcess()
   { 
-/*
-         if (bbGetOutputWidget()==0) this->bbUserCreateWidget();
-    this->bbUserProcess(); 
-    bbShowWindow();
-    //    this->bbUserOnShow();
-*/
+
     this->bbUserProcess(); 
 
     // If output widget not connected create the window 
@@ -538,17 +149,26 @@ namespace bbtk
                vtkKWBlackBoxDialog* win = vtkKWBlackBoxDialog::New();
                show = (Window*) win;
                win->bbSetBlackBox( GetThisPointer<KWBlackBox>());
-               //bbGetOutputWidget()->GetWidgetName());
-                            // win->SetName( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN" );
-               //              win->SetWidth( bbGetInputWinWidth() );
-               //              win->SetHeight( bbGetInputWinHeight() );
                KW::GetApplication()->AddWindow((vtkKWWindowBase*)win);
                win->Create();
-               std::cout << "TclName='"<<win->GetTclName()<<"'"<<std::endl;
+               win->SetResizable(0,0);
+
+               bbUserCreateWidget(win->GetFrame());
+               /*
+               KW::GetApplication()->Script
+                 ("pack %s -expand yes -fill both",
+                  bbGetOutputWidget()->GetWidgetName());
+               */
                
-               bbUserCreateWidget(win);
-               KW::GetApplication()->Script("pack %s -side left -anchor c -expand y",
-                                            bbGetOutputWidget()->GetWidgetName());
+               KW::GetApplication()->Script("place %s -x 0 -y 0 -width %d -height %d",
+                                            bbGetOutputWidget()->GetWidgetName(),
+                                            bbGetInputWinWidth(),
+                                            bbGetInputWinHeight());
+               
+               
+
+
+
                /*
                bbGetOutputWidget()->SetParent(win);
                bbGetOutputWidget()->Create();
@@ -587,7 +207,9 @@ namespace bbtk
        // Show the window
 
        show->bbShow(); 
-       KW::GetApplication()->Start();
+       //      std::cout << "KW::GetApplication()->Start();"<<std::endl;
+       //      KW::GetApplication()->Start();
+       //      std::cout << "AFTER KW::GetApplication()->Start();"<<std::endl;
        
       }                  
     //   
@@ -595,47 +217,9 @@ namespace bbtk
   }
   //=========================================================================
   
-  
-  /*
-  // LG 24/11/08 : New widget pipeline
-  void KWBlackBox::bbCreateWidgetAndEventHandler(vtkKWWidget* parent)
-  {
-    if (bbGetOutputWidget()==0)
-      {
-       this->bbUserCreateWidget(parent);
-      }        
-    
-    // If Event Handler for the widget does not exist or is obsolete : create it 
-    
-      if (bbGetOutputWidget()!=0)
-      {
-       if (bbGetWidgetEventHandler()==0)
-         {
-           bbtkDebugMessage("kw",3,
-                            "-> No widget event handler : creating one"
-                            <<std::endl);
-           new KWBlackBoxWidgetEventHandler(GetThisPointer<KWBlackBox>(),
-                                            bbGetOutputWidget());
-         }
-       else if ( ! bbGetWidgetEventHandler()->IsHandlerOf 
-                 ( bbGetOutputWidget() ) )
-         {
-           bbtkDebugMessage("kw",3,
-                            "-> Obsolete widget event handler : re-creating one"
-                            <<std::endl);
-           delete bbGetWidgetEventHandler();
-           new KWBlackBoxWidgetEventHandler(GetThisPointer<KWBlackBox>(),
-                                            bbGetOutputWidget());
-         }
-       // Sets the name of the vtkKWWidget to the input WinTitle
-       bbGetOutputWidget()->SetName(bbtk::std2kw(bbGetInputWinTitle()));
-      }
-   
-  }
-    
-  */
-  
-  vtkKWWidget*  KWBlackBox::bbCreateWidgetOfInput(const std::string& in, vtkKWWidget* parent)
+
+  //==================================================================
+  vtkKWWidget*  KWBlackBox::bbCreateWidgetOfInput(const std::string& in, vtkKWFrame* parent)
   {
     vtkKWWidget* w = 0;
     // If input is connected 
@@ -654,128 +238,7 @@ namespace bbtk
       }
     return w;
   }
-  
-  
-/*
   //==================================================================
-  /// Specific methods for window creation during pipeline execution
-  /// Shows the window associated to the box 
-  /// (called after bbProcess during bbExecute)
-  void KWBlackBox::bbShowWindow()
-  {
-    bbtkDebugMessageInc("kw",1,"=> KWBlackBox::bbShowWindow() ["
-                       <<bbGetFullName()<<"]"<<std::endl);
-    // If Event Handler for the widget does not exist or is obsolete : create it 
-    if (bbGetOutputWidget()!=0)
-      {
-       if (bbGetWidgetEventHandler()==0)
-         {
-           bbtkDebugMessage("kw",3,
-                            "-> No widget event handler : creating one"
-                            <<std::endl);
-           new KWBlackBoxWidgetEventHandler(GetThisPointer<KWBlackBox>(),
-                                            bbGetOutputWidget());
-         }
-       else if ( ! bbGetWidgetEventHandler()->IsHandlerOf 
-                 ( bbGetOutputWidget() ) )
-         {
-           bbtkDebugMessage("kw",3,
-                            "-> Obsolete widget event handler : re-creating one"
-                            <<std::endl);
-           delete bbGetWidgetEventHandler();
-           new KWBlackBoxWidgetEventHandler(GetThisPointer<KWBlackBox>(),
-                                            bbGetOutputWidget());
-         }
-       // Sets the name of the vtkKWWidget to the input WinTitle
-       bbGetOutputWidget()->SetName(bbtk::std2kw(bbGetInputWinTitle()));
-      }
-
-    // If the output 'Widget' is connected then it's gonna 
-    // be captured by its parent window : nothing to do 
-    if ( (*bbGetOutputConnectorMap().find("Widget")).second
-        ->GetConnectionVector().size() != 0 ) 
-      {
-       
-       bbtkDebugMessage("kw",2,
-                        "-> Output 'Widget' connected : nothing to do"
-                        <<std::endl);
-       return;
-      }
-
-
-    Window* show = 0;
-    // If the window already exists : no need creating it
-    if (bbGetWindow()!=0)
-      {
-       bbtkDebugMessage("kw",2,
-                        "-> Window already exists"
-                        <<std::endl);
-       show = bbGetWindow();
-      }
-    // Else if the widget exists : create window 
-    else if (bbGetOutputWidget()!=0) 
-      {
-       bbtkDebugMessage("kw",2,
-                        "-> Widget exists : creating the window"
-                        <<std::endl);
-
-
-       // Input WinDialog set to true : creating a Dialog
-       if (bbGetInputWinDialog()) 
-         {
-           bbtkDebugMessage("kw",2,
-                            "   Input WinDialog set to true : creating a Dialog"
-                            <<std::endl);
-           show = (Window*) new KWBlackBoxDialog( GetThisPointer<KWBlackBox>(),
-                                                 // bbGetKWParent(), 
-                                                                                         // LG 24/11/08 : New widget pipeline
-                                                                                         KW::GetTopWindow(),
-                                                  std2kw( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN"),
-                                                  kwSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) );
-         }
-       // Input WinDialog set to false : creating a Frame
-       else 
-         {
-           bbtkDebugMessage("process",2,
-                            "   Input WinDialog set to false : creating a Frame"
-                            <<std::endl);
-           show = (Window*) new KWBlackBoxFrame( GetThisPointer<KWBlackBox>(),
-                                                 // bbGetKWParent(), 
-                                                                                        // LG 24/11/08 : New widget pipeline
-                                                                                        KW::GetTopWindow(),
-                                                 std2kw( bbGetInputWinTitle()  + " - bbtk (c) CREATIS LRMN"),
-                                                 kwSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) );
-         }
-
-      }
-    // No window nor widget : error
-    else
-      {
-       bbtkError("KWBlackBox::bbShowWindow() ["
-                 <<bbGetFullName()
-                 <<"] : No widget. Did you set the box output 'Widget' in the processing method of the box ?");
-      }
-    
-    // Show the window
-    if (true) //!show->IsShown())
-      {
-       show->bbShow(); 
-      }
-    else 
-      {
-       bbtkDebugMessage("kw",2,"-> Already shown : nothing to do"<<std::endl);
-      }
-  
-
-    bbtkDebugMessage("kw",2,"<= KWBlackBox::bbShowWindow() ["
-                       <<bbGetFullName()<<"]"<<std::endl);
-
-  }
-  //==================================================================
-*/
-
 
 
   //==================================================================
@@ -822,12 +285,6 @@ namespace bbtk
   //==================================================================
 
 
-  //==================================================================
-       // LG 24/11/08 : New widget pipeline
-       //  vtkKWWidget* KWBlackBox::bbGetKWParent() { return KW::GetTopWindow(); }
-  //==================================================================
-  
-  
   //==================================================================
   bool KWBlackBox::bbIsShown()
   {