]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxLayoutTab.cxx
MeshManager
[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       printf("EED TabWidget::OnTabChange   page=%d \n", mwxNotebook->GetSelection());
99         mBox->bbSetOutputSelection( mwxNotebook->GetSelection() );
100     mBox->bbSignalOutputModification();
101   }
102
103 wxNotebook*     TabWidget::GetmwxNotebook()
104 {
105         return mwxNotebook;
106 }
107
108
109
110   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx , LayoutTab);
111   BBTK_BLACK_BOX_IMPLEMENTATION(LayoutTab,bbtk::WxBlackBox);
112   
113         //-----------------------------------------------------------------     
114         void LayoutTab::bbUserSetDefaultValues()
115         {
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 );
127         }
128         
129         //-----------------------------------------------------------------     
130         void LayoutTab::bbUserInitializeProcessing()
131         {
132         }
133         
134         //-----------------------------------------------------------------     
135         void LayoutTab::bbUserFinalizeProcessing()
136         {
137         }
138         
139         //-----------------------------------------------------------------     
140   void LayoutTab::TryInsertWindow(wxNotebook *book, const std::string& input )
141   {
142     wxWindow* w = bbCreateWidgetOfInput(input,book); 
143     if (w!=NULL)
144     {
145                 book->AddPage(w,w->GetName());
146     } // if w
147   }
148
149
150 void LayoutTab::SetTitleTabs()
151 {
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++)
165         {
166                 bbtk::BlackBoxInputConnector* c = bbGetInputConnectorMap().find( vecInputNameWidget[iWidget] )->second ;
167         if ( c->IsConnected() )
168         {
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() );
173                 } // if c
174         } // for iWidget
175
176 //EED2020-04-06
177 //      wxNotebook* w = (wxNotebook*)bbGetOutputWidget();
178         TabWidget *tabwidget=(TabWidget*)bbGetOutputWidget();
179         if (tabwidget!=NULL)
180         {
181                 wxNotebook *w = tabwidget->GetmwxNotebook();
182                 if (w!=NULL) 
183                 {
184                         int i,size=vecTitle.size();
185                         for (i=0; i<size; i++)
186                         {
187                                 w->SetPageText(i, wxString( vecTitle[i].c_str(),wxConvUTF8 ) ); 
188                         } // for i
189                 } //w
190         } // if tabwidget
191   }
192
193   void LayoutTab::Process() 
194   { 
195         PutWinTitle();
196         SetTitleTabs();
197   }
198     
199   void LayoutTab::CreateWidget(wxWindow* parent) 
200   { 
201     long style = wxNB_TOP;
202     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"0|T|TOP")==true) 
203       { style=wxNB_TOP; }
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)
209       { style=wxNB_LEFT; }
210
211 //EED2020-04-06
212 //   wxNotebook *w = new wxNotebook(parent, //bbGetWxParent(),
213 //                                 -1, 
214 //                                 wxDefaultPosition,
215 //                                 wxDefaultSize,
216 //                                 style );
217 //
218         TabWidget *tabwidget = new TabWidget (this, parent, style );
219     tabwidget->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );    
220         wxNotebook *w = tabwidget->GetmwxNotebook();
221
222 //EED2020-04-06
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");
233
234 //EED2020-04-06
235 //    bbSetOutputWidget( w );
236     bbSetOutputWidget( tabwidget );
237   }
238   
239   
240  // This callback is necessary to get actual processing of the view 
241 // when window is shown
242 void  LayoutTab::OnShowWidget()
243 {
244 //EED2020-04-06
245 //      wxNotebook* w = (wxNotebook*)bbGetOutputWidget();
246         wxNotebook* w = ((TabWidget*)bbGetOutputWidget())->GetmwxNotebook();
247         if (w) 
248         {
249                 if (w->GetPageCount()>0)
250                 {
251                         w->SetSelection(0);
252                         for (unsigned int i=0; i<w->GetPageCount(); ++i) 
253                         { 
254                                 w->AdvanceSelection(); 
255                         } // for
256                 } // if PageCount
257         } // if w    
258 }
259
260
261 }//namespace bbwx
262
263 #endif
264