/*========================================================================= Program: bbtk Module: $RCSfile: bbtkWidgetBlackBox.txx,v $ Language: C++ Date: $Date: 2009/04/08 07:56:11 $ Version: $Revision: 1.1 $ =========================================================================*/ /* --------------------------------------------------------------------- * 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 */ #include "bbtkWidgetBlackBoxWindow.h" #include "bbtkBlackBoxOutputConnector.h" namespace bbtk { //========================================================================= // WidgetBlackBox //========================================================================= //========================================================================= //========================================================================= //========================================================================= //========================================================================= BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(WidgetBlackBox,AtomicBlackBox); //========================================================================= //========================================================================= template void WidgetBlackBox::bbUserConstructor() { bbtkDebugMessage("widget",9,"WidgetBlackBox::bbUserConstructor()"< void WidgetBlackBox::bbUserCopyConstructor(bbtk::BlackBox::Pointer) { bbtkDebugMessage("widget",9,"WidgetBlackBox::bbUserCopyConstructor()" < void WidgetBlackBox::bbUserDestructor() { bbtkDebugMessage("widget",9,"==> WidgetBlackBox::bbUserDestructor() ["<bbClose(); bbSetWindow(0); } bbtkDebugMessage("widget",9,"<== WidgetBlackBox::bbUserDestructor() ["< void WidgetBlackBox::bbInitAttributes() { bbmWindow = 0; bbSetInputWinTitle(bbGetName()); bbSetInputWinWidth(800); bbSetInputWinHeight(800); bbSetInputWinDialog(false); bbSetOutputWidget(0); } //========================================================================= //========================================================================= template void WidgetBlackBox::bbProcess() { // TODO : update the window size and title this->bbUserProcess(); } //========================================================================= //========================================================================= template void WidgetBlackBox::bbCreateWindow() { // If output 'Widget' not connected then // it is a top level Widget have to create and show the Window if ( ! bbIsOutputWidgetConnected() ) { // create the Window if does not exist if ( bbGetWindow() == 0) { bbtkDebugMessage("widget",2, "-> Creating the window" <InitWindowManagerIfNeeded(); // If is a Dialog requested if ( bbGetInputWinDialog() ) { bbtkDebugMessage("process",2, " Input WinDialog set to true : creating a Dialog" <bbCreateDialogWindow(); } // Input WinDialog set to false : creating a Frame else { bbtkDebugMessage("process",2, " Input WinDialog set to false : creating a Frame" <bbCreateFrameWindow(); } } // Show the window if ( !bbGetWindow() ) { bbtkInternalError("Need to show the Window of widget "< Showing the window" <bbShow(); } // } //========================================================================= //================================================================== template typename WidgetBlackBox::WidgetPointer WidgetBlackBox::bbCreateWidgetOfInput (const std::string& in, WidgetBlackBox::WidgetPointer parent) { Widget* w = 0; // If input is connected BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ; if ( c->IsConnected() ) { // Get black box from BlackBox::Pointer from = c->GetConnection()->GetBlackBoxFrom(); // Cast it into a WidgetBlackBox typename WidgetBlackBox::Pointer wfrom = boost::dynamic_pointer_cast >(from); // Call bbCreateWidget wfrom->bbUserCreateWidget(parent); // Get the widget created w = wfrom->bbGetOutputWidget(); } return w; } //================================================================== //========================================================================= template bool WidgetBlackBox::bbIsOutputWidgetConnected() { return ((*bbGetOutputConnectorMap().find("Widget")).second->GetConnectionVector().size() != 0 ); } //================================================================== //================================================================== template void WidgetBlackBox::bbShowWindow() { bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbShowWindow() [" <bbShow(); bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbShowWindow() [" < void WidgetBlackBox::bbHideWindow() { bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbHideWindow() [" <bbHide(); bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbHideWindow() [" < void WidgetBlackBox::bbCloseWindow() { bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbCloseWindow() [" <bbClose(); bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbCloseWindow() [" < typename WidgetBlackBox::Window* WidgetBlackBox::bbGetContainingWindow() { if (bbGetWindow()!=0) return bbGetWindow(); BlackBox::OutputConnectorMapType::const_iterator i = bbGetOutputConnectorMap().find("Widget"); if ( i->second->GetConnectionVector().size() != 0 ) { return boost::static_pointer_cast (i->second->GetConnectionVector().front() //.lock() ->GetBlackBoxTo())->bbGetContainingWindow(); } return 0; } //================================================================== //================================================================== template bool WidgetBlackBox::bbIsShown() { if (bbGetContainingWindow()!=0) return bbGetContainingWindow()->bbIsShown(); return false; } //================================================================== }//namespace bbtk