X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkKWBlackBox.cxx;h=6a7ae09abc7783f91d21e651068dc4dd5b0bb8bb;hb=3dcc408acd2264664ca6431a501378ea64233dd6;hp=f1de79ed6ed67b9afb44fc9e9d49bc009e511cb8;hpb=26a8c332dda10ace9e3e088b2ca8544d188c9743;p=bbtk.git diff --git a/kernel/src/bbtkKWBlackBox.cxx b/kernel/src/bbtkKWBlackBox.cxx index f1de79e..6a7ae09 100644 --- a/kernel/src/bbtkKWBlackBox.cxx +++ b/kernel/src/bbtkKWBlackBox.cxx @@ -1,32 +1,39 @@ -/*========================================================================= +/* + # --------------------------------------------------------------------- + # + # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image + # pour la SantÈ) + # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton + # Previous Authors : Laurent Guigues, Jean-Pierre Roux + # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil + # + # This software is governed by the CeCILL-B license under French law and + # abiding by the rules of distribution of free software. You can use, + # modify and/ or redistribute the software under the terms of the CeCILL-B + # license as circulated by CEA, CNRS and INRIA at the following URL + # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + # or in the file LICENSE.txt. + # + # As a counterpart to the access to the source code and rights to copy, + # modify and redistribute granted by the license, users are provided only + # with a limited warranty and the software's author, the holder of the + # economic rights, and the successive licensors have only limited + # liability. + # + # The fact that you are presently reading this means that you have had + # knowledge of the CeCILL-B license and that you accept its terms. + # ------------------------------------------------------------------------ */ + + +/*========================================================================= Program: bbtk Module: $RCSfile: bbtkKWBlackBox.cxx,v $ Language: C++ - Date: $Date: 2008/11/29 21:41:33 $ - Version: $Revision: 1.1 $ + Date: $Date: 2012/11/16 08:49:01 $ + Version: $Revision: 1.11 $ =========================================================================*/ -/* --------------------------------------------------------------------- -* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale) -* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux -* -* This software is governed by the CeCILL-B license under French law and -* abiding by the rules of distribution of free software. You can use, -* modify and/ or redistribute the software under the terms of the CeCILL-B -* license as circulated by CEA, CNRS and INRIA at the following URL -* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -* or in the file LICENSE.txt. -* -* As a counterpart to the access to the source code and rights to copy, -* modify and redistribute granted by the license, users are provided only -* with a limited warranty and the software's author, the holder of the -* economic rights, and the successive licensors have only limited -* liability. -* -* The fact that you are presently reading this means that you have had -* knowledge of the CeCILL-B license and that you accept its terms. -* ------------------------------------------------------------------------ */ /** * \file * \brief @@ -34,608 +41,62 @@ #ifdef USE_KWWIDGETS - - - - #include "bbtkKWBlackBox.h" -#include "vtkObjectFactory.h" - +#include "bbtkBlackBoxOutputConnector.h" +#include "vtkKWBlackBoxDialog.h" namespace bbtk { - - - //========================================================================= - // vtkKWBlackBoxWindow - //========================================================================= - - - - //========================================================================= - vtkKWBlackBoxWindow::vtkKWBlackBoxWindow() - : mShown(false) - { - bbtkDebugMessage("kw",9,"vtkKWBlackBoxWindow::vtkKWBlackBoxWindow()" - <bbSetWindow(0); - } - } - //========================================================================= - - //========================================================================= - void vtkKWBlackBoxWindow::bbShow() - { - if (bbIsShown()) return; - bbtkDebugMessage("kw",9,"vtkKWBlackBoxWindow::bbShow()"<); //========================================================================= - //========================================================================= - void vtkKWBlackBoxDialog::bbShow() - { - if (bbIsShown()) return; - bbtkDebugMessage("kw",5,"vtkKWBlackBoxDialog::bbShow() [" - <bbGetFullName()<<"]"<Display(); - bbClose(); - } - //========================================================================= - - //========================================================================= - void vtkKWBlackBoxDialog::bbHide() - { - bbtkDebugMessage("kw",9,"vtkKWBlackBoxDialog::bbHide()"<Withdraw(); - } - //========================================================================= - - //========================================================================= - void vtkKWBlackBoxDialog::bbClose() - { - bbtkDebugMessage("kw",9,"vtkKWBlackBoxDialog::bbClose()"<Done = vtkKWDialog::StatusCanceled; - // this->Delete(); - } - //========================================================================= - - //========================================================================= - void vtkKWBlackBoxDialog::Cancel() - { - bbtkDebugMessage("kw",9,"vtkKWBlackBoxDialog::Cancel()"<Delete(); - } - //========================================================================= - //========================================================================= - vtkKWBlackBoxDialog::~vtkKWBlackBoxDialog() - { - } - //========================================================================= - - - - - - //========================================================================= - // vtkKWBlackBoxFrame - //========================================================================= - - //------------------------------------------------------------------------- - vtkStandardNewMacro( vtkKWBlackBoxFrame ); - vtkCxxRevisionMacro(vtkKWBlackBoxFrame, "$Revision: 1.1 $"); - //------------------------------------------------------------------------- - //========================================================================= - vtkKWBlackBoxFrame::vtkKWBlackBoxFrame() - { - bbtkDebugMessage("kw",9,"vtkKWBlackBoxFrame::vtkKWBlackBoxFrame()"<bbGetFullName()<<")"<Display(); - // This Update is ** MANDATORY ** - // to synchronize kwvtkRenderWindowInteractor objects - // (force kw objects creation **NOW**) + //================================================================== + /// Callback for creating a Dialog window (modal) + void WxBlackBox::bbCreateDialogWindow() + { + KW::GetApplication(); + vtkKWBlackBoxDialog* win = vtkKWBlackBoxDialog::New(); + show = (Window*) win; + win->bbSetBlackBox( GetThisPointer()); + KW::GetApplication()->AddWindow((vtkKWWindowBase*)win); + win->Create(); + win->SetResizable(0,0); + + bbUserCreateWidget(win->GetFrame()); /* - -#if defined(_WIN32) - kwFrame::Refresh(); -#endif - - kwFrame::Update(); - kwFrame::SetFocus(); + KW::GetApplication()->Script + ("pack %s -expand yes -fill both", + bbGetOutputWidget()->GetWidgetName()); */ - if (bbGetBlackBox()) bbGetBlackBox()->bbUserOnShow(); - } - //========================================================================= - - //========================================================================= - void vtkKWBlackBoxFrame::bbHide() - { - bbtkDebugMessage("kw",9,"vtkKWBlackBoxFrame::bbHide()"<Withdraw(); - if (bbGetBlackBox()) bbGetBlackBox()->bbUserOnHide(); - } - //========================================================================= - - //========================================================================= - void vtkKWBlackBoxFrame::bbClose() - { - bbtkDebugMessage("kw",9,"vtkKWBlackBoxFrame::bbClose()"<Delete(); - } - //========================================================================= - - - /* - //========================================================================= - // KWBlackBoxWidgetEventHandler - //========================================================================= - - //========================================================================= - KWBlackBoxWidgetEventHandler:: - KWBlackBoxWidgetEventHandler( KWBlackBox::Pointer box, - vtkKWWidget *widget ) - : - mBox(box), - mWindow(widget) - { - bbtkDebugMessage("kw",9,"KWBlackBoxWidgetEventHandler::KWBlackBoxWidgetEventHandler("<bbGetFullName()<<")"<bbSetWidgetEventHandler(this); - - Connect ( mWindow->GetId(), - kwEVT_DESTROY, - (kwObjectEventFunction) - (void (kwEvtHandler::*)(kwWindowDestroyEvent& c)) - &KWBlackBoxWidgetEventHandler::OnWindowDestroy ); - - mWindow->PushEventHandler(this); + KW::GetApplication()->Script("place %s -x 0 -y 0 -width %d -height %d", + bbGetOutputWidget()->GetWidgetName(), + bbGetInputWinWidth(), + bbGetInputWinHeight()); } - //========================================================================= - - //========================================================================= - KWBlackBoxWidgetEventHandler::~KWBlackBoxWidgetEventHandler() - { - if (mBox.expired()) return; - bbtkDebugMessage("kw",9, - "KWBlackBoxWidgetEventHandler::~KWBlackBoxWidgetEventHandler() [" - <bbGetFullName()<<"]"<bbSetWidgetEventHandler(0); - } - //========================================================================= - - //========================================================================= - void KWBlackBoxWidgetEventHandler::OnWindowDestroy(kwWindowDestroyEvent&) - { - if (mBox.expired()) return; - bbtkDebugMessage("kw",9,"KWBlackBoxWidgetEventHandler::OnWindowDestroy() [" - <bbGetFullName()<<"]"<bbSetOutputWidget(0); - mBox.lock()->bbSetModifiedStatus(); - } - //========================================================================= - - - */ - - - - - //========================================================================= - // KWBlackBox - //========================================================================= - - //========================================================================= - //========================================================================= - //========================================================================= - //========================================================================= - BBTK_BLACK_BOX_IMPLEMENTATION(KWBlackBox,AtomicBlackBox); - //========================================================================= - - //========================================================================= - void KWBlackBox::bbUserConstructor() - { - bbtkDebugMessage("Kernel",9,"KWBlackBox::bbUserConstructor()"< KWBlackBox::bbUserDestructor() ["<bbClose(); - bbSetWindow(0); - } - bbtkDebugMessage("kw",9,"<== KWBlackBox::bbUserDestructor() ["< KWBlackBox::bbExecute("<<(int)force<<") [" - <second->GetConnectionVector().size() != 0 ) - { - bbtkDebugMessage("process",3, - "-> Output 'Widget' connected : transfering execution to parent" - <second->GetConnectionVector().front() //.lock() - ->GetBlackBoxTo()->bbExecute(force); - - } - // else call 'standard' BlackBox execution method - else - { - BlackBox::bbExecute(force); - } - // - - bbtkDebugMessageDec("process",2, - "<= KWBlackBox::bbExecute() [" - < KWBlackBox::bbBackwardUpdate(" - <<(caller?caller->GetFullName():"0")<<") [" - <GetFullName():"0")<<") [" - <second->GetConnectionVector().size() != 0 ) - - { - BlackBox::Pointer to = - i->second->GetConnectionVector()[0]->GetBlackBoxTo(); - - if (caller) - { - bbtkDebugMessage("process",3, - "-> Output 'Widget' connected to '" - <bbGetFullName()<<"' - caller->to = '" - <GetBlackBoxTo()->bbGetFullName() - <<"'" - < Output 'Widget' connected to '" - <bbGetFullName()<<"'" - <GetBlackBoxTo() != to)&& - (!bbGetUpdateTransferedToParent())&& - (!to->bbGetExecuting()) - ) - ) - { - bbtkDebugMessage("process",3, - " ... Transfering update order to parent" - <second->GetConnectionVector().front() //.lock() - ->GetBlackBoxTo()->bbExecute(false); - } - else - { - bbSetUpdateTransferedToParent(false); - bbtkDebugMessage("process",3, - " ... No need to transfer to parent" - <GetBlackBoxFromOutput()!="Widget")) - ) - { - } - */ - // call 'standard' BlackBox execution method - if (!bbGetUpdateTransferedToParent()) - { - AtomicBlackBox::bbBackwardUpdate(caller); - } - - bbtkDebugMessageDec("process",3, - "<= KWBlackBox::bbBackwardUpdate() [" - <bbUserCreateWidget(); - this->bbUserProcess(); - bbShowWindow(); - // this->bbUserOnShow(); -*/ - this->bbUserProcess(); - // If output widget not connected create the window - if ( (*bbGetOutputConnectorMap().find("Widget")).second - ->GetConnectionVector().size() == 0 ) - { - Window* show = 0; - // If the window already exists : no need creating it - if (bbGetWindow()!=0) - { - bbtkDebugMessage("kw",2, - "-> Window already exists" - < Creating the window" - <bbSetBlackBox( GetThisPointer()); - //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='"<GetTclName()<<"'"<Script("pack %s -side left -anchor c -expand y", - bbGetOutputWidget()->GetWidgetName()); - /* - bbGetOutputWidget()->SetParent(win); - bbGetOutputWidget()->Create(); - KW::GetApplication()->Script("pack %s -side left -anchor c -expand y", - - //"pack %s -side top -anchor nw -expand y -fill none -padx 2 -pady 2", - bbGetOutputWidget()->GetWidgetName()); - */ - /* - } - - // Input WinDialog set to false : creating a Frame - else - { - bbtkDebugMessage("process",2, - " Input WinDialog set to false : creating a Frame" - <bbSetBlackBox( GetThisPointer()); - // win->SetName( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN" ); - // win->SetWidth( bbGetInputWinWidth() ); - // win->SetHeight( bbGetInputWinHeight() ); - KW::GetApplication()->AddWindow((vtkKWWindowBase*)win); - win->Create(); - - bbGetOutputWidget()->SetParent(win); - bbGetOutputWidget()->Create(); - KW::GetApplication()->Script("pack %s -side top -anchor nw -expand y -fill none -padx 2 -pady 2", - bbGetOutputWidget()->GetWidgetName()); } - */ - - // win->Invoke(); - } - - // Show the window - - show->bbShow(); - KW::GetApplication()->Start(); - - } - // - - } - //========================================================================= - - - /* - // 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" - <(), - bbGetOutputWidget()); - } - else if ( ! bbGetWidgetEventHandler()->IsHandlerOf - ( bbGetOutputWidget() ) ) - { - bbtkDebugMessage("kw",3, - "-> Obsolete widget event handler : re-creating one" - <(), - 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,192 +115,23 @@ 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() [" - < No widget event handler : creating one" - <(), - bbGetOutputWidget()); - } - else if ( ! bbGetWidgetEventHandler()->IsHandlerOf - ( bbGetOutputWidget() ) ) - { - bbtkDebugMessage("kw",3, - "-> Obsolete widget event handler : re-creating one" - <(), - 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" - < Window already exists" - < Widget exists : creating the window" - <(), - // 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" - <(), - // 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() [" - <IsShown()) - { - show->bbShow(); - } - else - { - bbtkDebugMessage("kw",2,"-> Already shown : nothing to do"< KWBlackBox::bbHideWindow() [" - <bbHide(); - - bbtkDebugMessageDec("kw",2,"<= KWBlackBox::bbHideWindow() [" - < KWBlackBox::bbCloseWindow() [" - <bbClose(); - - bbtkDebugMessageDec("kw",2,"<= KWBlackBox::bbCloseWindow() [" - <second->GetConnectionVector().size() != 0 ) - { - return boost::static_pointer_cast - (i->second->GetConnectionVector().front() //.lock() - ->GetBlackBoxTo())->bbGetContainingWindow(); - } - return 0; - } - //================================================================== - - - //================================================================== - // LG 24/11/08 : New widget pipeline - // vtkKWWidget* KWBlackBox::bbGetKWParent() { return KW::GetTopWindow(); } //================================================================== + // void KWBlackBox::InitWindowManagerIfNeeded() { KW:: + void KWBlackBox::IncNbWindowsAlive() { KW::IncNbWindowsAlive(); } + void KWBlackBox::DecNbWindowsAlive() { KW::DecNbWindowsAlive(); } + int KWBlackBox::GetNbWindowsAlive() { return KW::GetNbWindowsAlive(); } + bool KWBlackBox::IsSomeWindowAlive() { return KW::IsSomeWindowAlive(); } - - //================================================================== - bool KWBlackBox::bbIsShown() - { - if (bbGetContainingWindow()!=0) - return bbGetContainingWindow()->bbIsShown(); - return false; - } + void KWBlackBox::IncNbWindowsShown() { KW::IncNbWindowsShown(); } + void KWBlackBox::DecNbWindowsShown() { KW::DecNbWindowsShown(); } + int KWBlackBox::GetNbWindowsShown() { return KW::GetNbWindowsShown(); } + bool KWBlackBox::IsSomeWindowShown() { return KW::GetNbWindowsShown(); } //================================================================== - - + }//namespace bbtk - #endif