]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxLayoutTab.cxx
#3385 BBTK Bug New Normal - box FilesFromDirectory CreateImage InvertCrop ComboBox...
[bbtk.git] / packages / wx / src / bbwxLayoutTab.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
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
9  #
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.
16  #
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
21  #  liability.
22  #
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  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbwxLayoutTab.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:52:14 $
33   Version:   $Revision: 1.12 $
34 =========================================================================*/
35
36 /**
37  *  \file 
38  *  \brief 
39  */
40
41
42 #ifdef _USE_WXWIDGETS_
43
44
45 #include "bbwxLayoutTab.h"
46 #include "bbwxPackage.h"
47 #include "bbtkUtilities.h"
48 #include "bbtkBlackBoxInputConnector.h"
49
50
51
52 namespace bbwx
53 {
54
55
56    //--------------------------------------------------------------------------
57   class TabWidget : public wxPanel
58   {
59   public:
60     TabWidget(LayoutTab* box, wxWindow *parent, long style);
61     ~TabWidget();
62     void OnTabChange( wxEvent& );
63         wxNotebook*     GetmwxNotebook();       
64   private:
65     LayoutTab   *mBox;
66     wxNotebook  *mwxNotebook;
67   }; 
68
69
70   TabWidget::TabWidget(LayoutTab* box,
71                                            wxWindow *parent,long style )
72     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
73       mBox(box)
74   { 
75     wxPanel *panel      = this;
76     mwxNotebook         = new wxNotebook(panel, //bbGetWxParent(),
77                                    -1, 
78                                    wxDefaultPosition,
79                                    wxDefaultSize,
80                                    style );
81     Connect( mwxNotebook->GetId(),   wxEVT_NOTEBOOK_PAGE_CHANGED , 
82              (wxObjectEventFunction) 
83              (void (wxPanel::*)(wxEvent&))
84              &TabWidget::OnTabChange ); 
85     wxBoxSizer *sizer   = new wxBoxSizer(wxHORIZONTAL);
86     sizer -> Add( mwxNotebook,1,wxGROW,0 ); 
87     panel       -> SetSizer(sizer);
88     panel       -> SetAutoLayout(true);
89     panel       -> Layout();
90   }
91   
92   TabWidget::~TabWidget()
93   {
94   }
95   
96   void TabWidget::OnTabChange( wxEvent& )
97   {
98         mBox->bbSetOutputSelection( mwxNotebook->GetSelection() );
99     mBox->bbSignalOutputModification();
100   }
101
102 wxNotebook*     TabWidget::GetmwxNotebook()
103 {
104         return mwxNotebook;
105 }
106
107
108
109   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx , LayoutTab);
110   BBTK_BLACK_BOX_IMPLEMENTATION(LayoutTab,bbtk::WxBlackBox);
111   
112         //-----------------------------------------------------------------     
113         void LayoutTab::bbUserSetDefaultValues()
114         {
115                 bbSetInputOrientation("TOP");
116                 bbSetInputWidget1(NULL);
117                 bbSetInputWidget2(NULL);
118                 bbSetInputWidget3(NULL);
119                 bbSetInputWidget4(NULL);
120                 bbSetInputWidget5(NULL);
121                 bbSetInputWidget6(NULL);
122                 bbSetInputWidget7(NULL);
123                 bbSetInputWidget8(NULL);
124                 bbSetInputWidget9(NULL);
125         }
126         
127         //-----------------------------------------------------------------     
128         void LayoutTab::bbUserInitializeProcessing()
129         {
130         }
131         
132         //-----------------------------------------------------------------     
133         void LayoutTab::bbUserFinalizeProcessing()
134         {
135         }
136         
137         //-----------------------------------------------------------------     
138   void LayoutTab::TryInsertWindow(wxNotebook *book, const std::string& input )
139   {
140     wxWindow* w = bbCreateWidgetOfInput(input,book); 
141     if (w!=NULL)
142     {
143                 book->AddPage(w,w->GetName());
144     } // if w
145   }
146
147
148 void LayoutTab::SetTitleTabs()
149 {
150         std::vector<std::string> vecTitle;
151         std::vector<std::string> vecInputNameWidget;
152         vecInputNameWidget.push_back("Widget1");        
153         vecInputNameWidget.push_back("Widget2");        
154         vecInputNameWidget.push_back("Widget3");        
155         vecInputNameWidget.push_back("Widget4");        
156         vecInputNameWidget.push_back("Widget5");        
157         vecInputNameWidget.push_back("Widget6");        
158         vecInputNameWidget.push_back("Widget7");        
159         vecInputNameWidget.push_back("Widget8");        
160         vecInputNameWidget.push_back("Widget9");        
161         int iWidget,sizeVecInputNameWidget= vecInputNameWidget.size();
162         for (iWidget=0; iWidget<sizeVecInputNameWidget; iWidget++)
163         {
164                 bbtk::BlackBoxInputConnector* c = bbGetInputConnectorMap().find( vecInputNameWidget[iWidget] )->second ;
165         if ( c->IsConnected() )
166         {
167                         // Get black box from 
168                         BlackBox::Pointer from = c->GetConnection()->GetBlackBoxFrom();
169                         bbtk::WidgetBlackBox<wxWindow>::Pointer wfrom = boost::dynamic_pointer_cast<bbtk::WidgetBlackBox<wxWindow> >(from);
170                         vecTitle.push_back( wfrom->bbGetInputWinTitle() );
171                 } // if c
172         } // for iWidget
173
174 //EED2020-04-06
175 //      wxNotebook* w = (wxNotebook*)bbGetOutputWidget();
176         TabWidget *tabwidget=(TabWidget*)bbGetOutputWidget();
177         if (tabwidget!=NULL)
178         {
179                 wxNotebook *w = tabwidget->GetmwxNotebook();
180                 if (w!=NULL) 
181                 {
182                         int i,size=vecTitle.size();
183                         for (i=0; i<size; i++)
184                         {
185                                 w->SetPageText(i, wxString( vecTitle[i].c_str(),wxConvUTF8 ) ); 
186                         } // for i
187                 } //w
188         } // if tabwidget
189   }
190
191   void LayoutTab::Process() 
192   { 
193         PutWinTitle();
194         SetTitleTabs();
195   }
196     
197   void LayoutTab::CreateWidget(wxWindow* parent) 
198   { 
199     long style = wxNB_TOP;
200     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"0|T|TOP")==true) 
201       { style=wxNB_TOP; }
202     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|R|RIGHT")==true)
203       { style=wxNB_RIGHT; }
204     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"2|B|BOTTOM")==true)
205       { style=wxNB_BOTTOM; }
206     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"3|L|LEFT")==true)
207       { style=wxNB_LEFT; }
208
209 //EED2020-04-06
210 //   wxNotebook *w = new wxNotebook(parent, //bbGetWxParent(),
211 //                                 -1, 
212 //                                 wxDefaultPosition,
213 //                                 wxDefaultSize,
214 //                                 style );
215 //
216         TabWidget *tabwidget = new TabWidget (this, parent, style );
217     tabwidget->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );    
218         wxNotebook *w = tabwidget->GetmwxNotebook();
219
220 //EED2020-04-06
221 //    w->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );    
222     TryInsertWindow(w,"Widget1");
223     TryInsertWindow(w,"Widget2");
224     TryInsertWindow(w,"Widget3");
225     TryInsertWindow(w,"Widget4");
226     TryInsertWindow(w,"Widget5");
227     TryInsertWindow(w,"Widget6");
228     TryInsertWindow(w,"Widget7");
229     TryInsertWindow(w,"Widget8");
230     TryInsertWindow(w,"Widget9");
231
232 //EED2020-04-06
233 //    bbSetOutputWidget( w );
234     bbSetOutputWidget( tabwidget );
235   }
236   
237   
238  // This callback is necessary to get actual processing of the view 
239 // when window is shown
240 void  LayoutTab::OnShowWidget()
241 {
242 //EED2020-04-06
243 //      wxNotebook* w = (wxNotebook*)bbGetOutputWidget();
244         wxNotebook* w = ((TabWidget*)bbGetOutputWidget())->GetmwxNotebook();
245         if (w) 
246         {
247                 if (w->GetPageCount()>0)
248                 {
249                         w->SetSelection(0);
250                         for (unsigned int i=0; i<w->GetPageCount(); ++i) 
251                         { 
252                                 w->AdvanceSelection(); 
253                         } // for
254                 } // if PageCount
255         } // if w    
256 }
257
258
259 }//namespace bbwx
260
261 #endif
262