2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbwxLayoutTab.cxx,v $
32 Date: $Date: 2012/11/16 08:52:14 $
33 Version: $Revision: 1.12 $
34 =========================================================================*/
42 #ifdef _USE_WXWIDGETS_
45 #include "bbwxLayoutTab.h"
46 #include "bbwxPackage.h"
47 #include "bbtkUtilities.h"
48 #include "bbtkBlackBoxInputConnector.h"
56 //--------------------------------------------------------------------------
57 class TabWidget : public wxPanel
60 TabWidget(LayoutTab* box, wxWindow *parent, long style);
62 void OnTabChange( wxEvent& );
63 wxNotebook* GetmwxNotebook();
66 wxNotebook *mwxNotebook;
70 TabWidget::TabWidget(LayoutTab* box,
71 wxWindow *parent,long style )
72 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
75 wxPanel *panel = this;
76 mwxNotebook = new wxNotebook(panel, //bbGetWxParent(),
82 Connect( mwxNotebook->GetId(), wxEVT_NOTEBOOK_PAGE_CHANGED ,
83 (wxObjectEventFunction)
84 (void (wxPanel::*)(wxEvent&))
85 &TabWidget::OnTabChange );
86 wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
87 sizer -> Add( mwxNotebook,1,wxGROW,0 );
88 panel -> SetSizer(sizer);
89 panel -> SetAutoLayout(true);
93 TabWidget::~TabWidget()
97 void TabWidget::OnTabChange( wxEvent& )
99 mBox->bbSetOutputSelection( mwxNotebook->GetSelection() );
100 mBox->bbSignalOutputModification();
103 wxNotebook* TabWidget::GetmwxNotebook()
110 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx , LayoutTab);
111 BBTK_BLACK_BOX_IMPLEMENTATION(LayoutTab,bbtk::WxBlackBox);
113 //-----------------------------------------------------------------
114 void LayoutTab::bbUserSetDefaultValues()
116 bbSetInputOrientation("TOP");
117 bbSetInputWidget1(NULL);
118 bbSetInputWidget2(NULL);
119 bbSetInputWidget3(NULL);
120 bbSetInputWidget4(NULL);
121 bbSetInputWidget5(NULL);
122 bbSetInputWidget6(NULL);
123 bbSetInputWidget7(NULL);
124 bbSetInputWidget8(NULL);
125 bbSetInputWidget9(NULL);
126 bbSetOutputSelection( 0 );
129 //-----------------------------------------------------------------
130 void LayoutTab::bbUserInitializeProcessing()
134 //-----------------------------------------------------------------
135 void LayoutTab::bbUserFinalizeProcessing()
139 //-----------------------------------------------------------------
140 void LayoutTab::TryInsertWindow(wxNotebook *book, const std::string& input )
142 wxWindow* w = bbCreateWidgetOfInput(input,book);
145 book->AddPage(w,w->GetName());
150 void LayoutTab::SetTitleTabs()
152 std::vector<std::string> vecTitle;
153 std::vector<std::string> vecInputNameWidget;
154 vecInputNameWidget.push_back("Widget1");
155 vecInputNameWidget.push_back("Widget2");
156 vecInputNameWidget.push_back("Widget3");
157 vecInputNameWidget.push_back("Widget4");
158 vecInputNameWidget.push_back("Widget5");
159 vecInputNameWidget.push_back("Widget6");
160 vecInputNameWidget.push_back("Widget7");
161 vecInputNameWidget.push_back("Widget8");
162 vecInputNameWidget.push_back("Widget9");
163 int iWidget,sizeVecInputNameWidget= vecInputNameWidget.size();
164 for (iWidget=0; iWidget<sizeVecInputNameWidget; iWidget++)
166 bbtk::BlackBoxInputConnector* c = bbGetInputConnectorMap().find( vecInputNameWidget[iWidget] )->second ;
167 if ( c->IsConnected() )
169 // Get black box from
170 BlackBox::Pointer from = c->GetConnection()->GetBlackBoxFrom();
171 bbtk::WidgetBlackBox<wxWindow>::Pointer wfrom = boost::dynamic_pointer_cast<bbtk::WidgetBlackBox<wxWindow> >(from);
172 vecTitle.push_back( wfrom->bbGetInputWinTitle() );
177 // wxNotebook* w = (wxNotebook*)bbGetOutputWidget();
178 TabWidget *tabwidget=(TabWidget*)bbGetOutputWidget();
181 wxNotebook *w = tabwidget->GetmwxNotebook();
184 int i,size=vecTitle.size();
185 for (i=0; i<size; i++)
187 w->SetPageText(i, wxString( vecTitle[i].c_str(),wxConvUTF8 ) );
193 void LayoutTab::Process()
199 void LayoutTab::CreateWidget(wxWindow* parent)
201 long style = wxNB_TOP;
202 if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"0|T|TOP")==true)
204 if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|R|RIGHT")==true)
205 { style=wxNB_RIGHT; }
206 if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"2|B|BOTTOM")==true)
207 { style=wxNB_BOTTOM; }
208 if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"3|L|LEFT")==true)
212 // wxNotebook *w = new wxNotebook(parent, //bbGetWxParent(),
214 // wxDefaultPosition,
218 TabWidget *tabwidget = new TabWidget (this, parent, style );
219 tabwidget->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );
220 wxNotebook *w = tabwidget->GetmwxNotebook();
223 // w->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );
224 TryInsertWindow(w,"Widget1");
225 TryInsertWindow(w,"Widget2");
226 TryInsertWindow(w,"Widget3");
227 TryInsertWindow(w,"Widget4");
228 TryInsertWindow(w,"Widget5");
229 TryInsertWindow(w,"Widget6");
230 TryInsertWindow(w,"Widget7");
231 TryInsertWindow(w,"Widget8");
232 TryInsertWindow(w,"Widget9");
235 // bbSetOutputWidget( w );
236 bbSetOutputWidget( tabwidget );
240 // This callback is necessary to get actual processing of the view
241 // when window is shown
242 void LayoutTab::OnShowWidget()
245 // wxNotebook* w = (wxNotebook*)bbGetOutputWidget();
246 wxNotebook* w = ((TabWidget*)bbGetOutputWidget())->GetmwxNotebook();
249 if (w->GetPageCount()>0)
252 for (unsigned int i=0; i<w->GetPageCount(); ++i)
254 w->AdvanceSelection();