/*========================================================================= Program: bbtk Module: $RCSfile: bbtkWxBlackBox.cxx,v $ Language: C++ Date: $Date: 2008/07/23 11:46:11 $ Version: $Revision: 1.24 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifdef _USE_WXWIDGETS_ /** * \file * \brief */ #include "bbtkWxBlackBox.h" //#include "bbtkWxContainerBlackBox.h" #include //#include "bbtkData.h" //#include "bbtkFactory.h" namespace bbtk { //========================================================================= // WxBlackBoxWindow //========================================================================= //========================================================================= WxBlackBoxWindow::WxBlackBoxWindow(WxBlackBox::Pointer box) : mBox(box), mShown(false) { bbtkDebugMessage("wx",9,"WxBlackBoxWindow::WxBlackBoxWindow("<< mBox.lock()->bbGetFullName()<<")"<bbSetWindow(this); Wx::IncNbWindowsAlive(); } //========================================================================= //========================================================================= WxBlackBoxWindow::~WxBlackBoxWindow() { bbtkDebugMessage("wx",9,"WxBlackBoxWindow::~WxBlackBoxWindow() " <bbSetWindow(0); } } //========================================================================= //========================================================================= void WxBlackBoxWindow::bbShow() { if (bbIsShown()) return; bbtkDebugMessage("wx",9,"WxBlackBoxWindow::bbShow()"<bbGetFullName()<<","<bbGetOutputWidget(); widget->Reparent(this); sizer->Add( widget, 1, wxALL|wxEXPAND, 2); //SetAutoLayout(true); SetSizer(sizer); Layout(); } //========================================================================= //========================================================================= void WxBlackBoxDialog::bbShow() { bbtkDebugMessage("wx",5,"WxBlackBoxDialog::bbShow() [" <bbGetFullName()<<"]"<bbGetFullName()<<","<bbGetOutputWidget(); wxFrame* frame = (wxFrame*)this; widget->Reparent(frame); sizer->Add( widget, 1, wxALL|wxGROW, 2); // frame->SetAutoLayout(true); frame->SetSizer(sizer); //frame->Fit(); frame->Layout(); } //========================================================================= //========================================================================= WxBlackBoxFrame::~WxBlackBoxFrame() { } //========================================================================= //========================================================================= void WxBlackBoxFrame::bbShow() { bbtkDebugMessage("wx",5,"WxBlackBoxFrame::bbShow(" <bbGetFullName()<<")"<bbUserOnShow(); } //========================================================================= //========================================================================= void WxBlackBoxFrame::bbHide() { bbtkDebugMessage("wx",9,"WxBlackBoxFrame::bbHide()"<bbUserOnHide(); } //========================================================================= //========================================================================= void WxBlackBoxFrame::bbClose() { wxFrame::Close(); } //========================================================================= //========================================================================= // WxBlackBoxWidgetEventHandler //========================================================================= //========================================================================= WxBlackBoxWidgetEventHandler:: WxBlackBoxWidgetEventHandler( WxBlackBox::Pointer box, wxWindow *widget ) : mBox(box), mWindow(widget) { bbtkDebugMessage("wx",9,"WxBlackBoxWidgetEventHandler::WxBlackBoxWidgetEventHandler("<bbGetFullName()<<")"<bbSetWidgetEventHandler(this); Connect ( mWindow->GetId(), wxEVT_DESTROY, (wxObjectEventFunction) (void (wxEvtHandler::*)(wxWindowDestroyEvent& c)) &WxBlackBoxWidgetEventHandler::OnWindowDestroy ); mWindow->PushEventHandler(this); } //========================================================================= //========================================================================= WxBlackBoxWidgetEventHandler::~WxBlackBoxWidgetEventHandler() { if (mBox.expired()) return; bbtkDebugMessage("wx",9, "WxBlackBoxWidgetEventHandler::~WxBlackBoxWidgetEventHandler() [" <bbGetFullName()<<"]"<bbSetWidgetEventHandler(0); } //========================================================================= //========================================================================= void WxBlackBoxWidgetEventHandler::OnWindowDestroy(wxWindowDestroyEvent&) { if (mBox.expired()) return; bbtkDebugMessage("wx",9,"WxBlackBoxWidgetEventHandler::OnWindowDestroy() [" <bbGetFullName()<<"]"<bbSetOutputWidget(0); mBox.lock()->bbSetModifiedStatus(); } //========================================================================= //========================================================================= // WxBlackBox //========================================================================= //========================================================================= //========================================================================= //========================================================================= //========================================================================= BBTK_BLACK_BOX_IMPLEMENTATION(WxBlackBox,AtomicBlackBox); //========================================================================= //========================================================================= void WxBlackBox::bbUserConstructor() { bbtkDebugMessage("Kernel",9,"WxBlackBox::bbUserConstructor()"< WxBlackBox::bbUserDestructor() ["<IsDead()) { bbtkDebugMessage("wx",9,"WxBlackBox::bbGetWidget() ["<< bbGetFullName()<<"] : Widget is dead : deleting it" < WxBlackBox::bbExecute() [" <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, "<= WxBlackBox::bbExecute() [" < WxBlackBox::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->bbGetStatus()!=UPDATING)) { 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, "<= WxBlackBox::bbBackwardUpdate() [" <bbUserCreateWidget(); this->bbUserProcess(); bbShowWindow(); // this->bbUserOnShow(); } //========================================================================= //================================================================== /// Specific methods for window creation during pipeline execution /// Shows the window associated to the box /// (called after bbProcess during bbExecute) void WxBlackBox::bbShowWindow() { bbtkDebugMessageInc("wx",1,"=> WxBlackBox::bbShowWindow() [" < No widget event handler : creating one" <(), bbGetOutputWidget()); } else if ( ! bbGetWidgetEventHandler()->IsHandlerOf ( bbGetOutputWidget() ) ) { bbtkDebugMessage("wx",3, "-> Obsolete widget event handler : re-creating one" <(), bbGetOutputWidget()); } // Sets the name of the wxWindow to the input WinTitle bbGetOutputWidget()->SetName(bbtk::std2wx(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("wx",2, "-> Output 'Widget' connected : nothing to do" < Window already exists" < Widget exists : creating the window" <(), bbGetWxParent(), std2wx( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN"), wxSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) ); } // Input WinDialog set to false : creating a Frame else { bbtkDebugMessage("process",2, " Input WinDialog set to false : creating a Frame" <(), bbGetWxParent(), std2wx( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN"), wxSize( bbGetInputWinWidth() , bbGetInputWinHeight() ) ); } } // No window nor widget : error else { bbtkError("WxBlackBox::bbShowWindow() [" <IsShown()) { show->bbShow(); } else { bbtkDebugMessage("wx",2,"-> Already shown : nothing to do"< WxBlackBox::bbHideWindow() [" <bbHide(); bbtkDebugMessageDec("wx",1,"<= WxBlackBox::bbHideWindow() [" < WxBlackBox::bbCloseWindow() [" <bbClose(); bbtkDebugMessageDec("wx",1,"<= WxBlackBox::bbCloseWindow() [" <second->GetConnectionVector().size() != 0 ) { return boost::static_pointer_cast (i->second->GetConnectionVector().front() //.lock() ->GetBlackBoxTo())->bbGetContainingWindow(); } return 0; } //================================================================== //================================================================== wxWindow* WxBlackBox::bbGetWxParent() { return Wx::GetTopWindow(); } //================================================================== //================================================================== bool WxBlackBox::bbIsShown() { if (bbGetContainingWindow()!=0) return bbGetContainingWindow()->bbIsShown(); return false; } //================================================================== }//namespace bbtk #endif