]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUIPackageBrowser.cxx
6ed481da5dcd5c63b43a403ebe2942f3f87c11a6
[bbtk.git] / kernel / src / bbtkWxGUIPackageBrowser.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxGUIPackageBrowser.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:15 $
6   Version:   $Revision: 1.7 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31
32 /**
33  * \brief Short description in one line
34  * 
35  * Long description which 
36  * can span multiple lines
37  */
38 /**
39  * \file 
40  * \brief 
41  */
42 /**
43  * \class bbtk::
44  * \brief 
45  */
46
47 /*
48 #ifdef _USE_WXWIDGETS_
49
50 #define CHECKBOXVIEW 1
51
52 #include "bbtkWxGUIPackageBrowser.h"
53 #include "ThirdParty/wx/treemultictrl/wxTreeMultiCtrl.h"
54 #include "bbtkInterpreter.h"
55 #include "bbtkBlackBoxInputDescriptor.h"
56 #include "bbtkBlackBoxOutputDescriptor.h"
57 #include "bbtkWxBlackBox.h"
58 #include "wx/grid.h"
59 #include <wx/statline.h>
60
61
62 namespace bbtk
63 {
64   //================================================================
65   WxGUIPackageBrowserBlackBox::
66   WxGUIPackageBrowserBlackBox(wxWindow* parent,
67                               WxGUIPackageBrowser* browser,
68                               BlackBoxDescriptor::Pointer descr) :
69     wxPanel(parent, -1),
70     mBrowser(browser),
71     mDescriptor(descr)
72   {
73     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
74     
75     wxStaticText* s = new wxStaticText(this,-1,
76                                        std2wx(descr->GetDescription()));
77     sizer->Add(s,0,wxGROW);
78     s = new wxStaticText(this,-1,
79                          std2wx(descr->GetAuthor()));
80     sizer->Add(s,0,wxGROW);
81     s = new wxStaticText(this,-1,
82                          std2wx(descr->GetCategory()));
83     sizer->Add(s,0,wxGROW);
84
85     std::vector<std::vector<std::string> > user_defined;
86     std::vector<std::vector<std::string> > ubb_defined;
87     std::vector<std::vector<std::string> > wxbb_defined;
88     
89     std::string titlecol("#BBBBFF");
90     std::string usercol("#FFFFFF");
91     std::string ubbcol("#DDFFFF");
92     std::string wxbbcol("#EEFFFF");
93
94    const BlackBoxDescriptor::InputDescriptorMapType& imap = 
95       descr->GetInputDescriptorMap();
96     BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
97     for ( in = imap.begin();  in != imap.end(); ++in ) 
98     {
99       // Skips system-defined inputs
100       std::string col(usercol);
101       int iotype = 0;
102       if (in->second->GetCreatorTypeInfo() == 
103           typeid(AtomicBlackBoxDescriptor))
104         {
105           col = ubbcol; 
106           iotype = 1;
107         }
108       else if (in->second->GetCreatorTypeInfo() == 
109                typeid(WxBlackBoxDescriptor))
110         {
111           col = wxbbcol; 
112           iotype = 2;
113         }
114
115       std::string name(in->second->GetName());
116       //Utilities::html_format(name);
117       
118       std::string type("<");
119       type += in->second->GetTypeName();    
120       type += ">";
121       //Utilities::html_format(type);
122       
123       std::string descr(in->second->GetDescription());
124       //Utilities::html_format(descr);
125       
126       std::vector<std::string> out;
127       out.push_back(name);
128       out.push_back(type);
129       out.push_back(descr);
130
131       if (iotype==0) user_defined.push_back(out);
132       else if (iotype==1) ubb_defined.push_back(out);
133       else if (iotype==2) wxbb_defined.push_back(out);
134       
135     }
136
137  
138     wxBoxSizer *inputs = 
139       new wxStaticBoxSizer
140       ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );    
141     wxFlexGridSizer* grid = new wxFlexGridSizer(3);
142
143     wxTextAttr ionameattr(*wxRED,*wxBLACK);
144     wxTextAttr iotypeattr(*wxBLACK,*wxRED);
145
146     int n = 0;
147     std::vector<std::vector<std::string> >::iterator hi;
148     for (hi=user_defined.begin();hi!=user_defined.end();++hi) 
149       {
150         
151         grid->Add( new wxStaticText(this,-1,std2wx((*hi)[0])));
152         grid->Add( new wxStaticText(this,-1,std2wx((*hi)[1])));
153         grid->Add( new wxStaticText(this,-1,std2wx((*hi)[2])));
154         //      grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
155         //      grid->SetReadOnly( n, 0 );
156      }
157     // grid->Add( new wxStaticLine(this,-1));
158    for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) 
159       {
160         grid->Add( new wxStaticText(this,-1,
161                                     std2wx((*hi)[0])));
162         grid->Add( new wxStaticText(this,-1,
163                                     std2wx((*hi)[1])));
164         grid->Add( new wxStaticText(this,-1,
165                                     std2wx((*hi)[2])));
166       }
167     for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) 
168       {
169         grid->Add( new wxStaticText(this,-1,
170                                     std2wx((*hi)[0])));
171         grid->Add( new wxStaticText(this,-1,
172                                     std2wx((*hi)[1])));
173         grid->Add( new wxStaticText(this,-1,
174                                     std2wx((*hi)[2])));
175       }
176
177     inputs->Add(grid,0,wxGROW);
178     sizer->Add(inputs,0,wxGROW);
179
180     // Outputs
181     user_defined.clear();
182     ubb_defined.clear();
183     wxbb_defined.clear();
184     const BlackBoxDescriptor::OutputDescriptorMapType& omap = 
185       descr->GetOutputDescriptorMap();
186     BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
187     for ( out = omap.begin();  out != omap.end(); ++out ) 
188     {
189       // Skips system-defined inputs
190       std::string col(usercol);
191       int iotype = 0;
192       if (out->second->GetCreatorTypeInfo() == 
193           typeid(AtomicBlackBoxDescriptor))
194         {
195           col = ubbcol; 
196           iotype = 1;
197         }
198       else if (out->second->GetCreatorTypeInfo() == 
199                typeid(WxBlackBoxDescriptor))
200         {
201           col = wxbbcol; 
202           iotype = 2;
203         }
204
205       std::string name(out->second->GetName());
206       //Utilities::html_format(name);
207       
208       std::string type("<");
209       type += out->second->GetTypeName();    
210       type += ">";
211       //Utilities::html_format(type);
212       
213       std::string descr(out->second->GetDescription());
214       //Utilities::html_format(descr);
215       
216       std::vector<std::string> out;
217       out.push_back(name);
218       out.push_back(type);
219       out.push_back(descr);
220
221       if (iotype==0) user_defined.push_back(out);
222       else if (iotype==1) ubb_defined.push_back(out);
223       else if (iotype==2) wxbb_defined.push_back(out);
224       
225     }
226
227     wxBoxSizer *outputs = 
228       new wxStaticBoxSizer
229       ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );    
230     wxFlexGridSizer* ogrid = new wxFlexGridSizer(3);
231
232
233     n = 0;
234     for (hi=user_defined.begin();hi!=user_defined.end();++hi) 
235       {
236         ogrid->Add( new wxStaticText(this,-1,
237                                     std2wx((*hi)[0])));
238         ogrid->Add( new wxStaticText(this,-1,
239                                     std2wx((*hi)[1])));
240         ogrid->Add( new wxStaticText(this,-1,
241                                     std2wx((*hi)[2])));
242         //      grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
243         //      grid->SetReadOnly( n, 0 );
244      }
245     for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) 
246       {
247         ogrid->Add( new wxStaticText(this,-1,
248                                     std2wx((*hi)[0])));
249         ogrid->Add( new wxStaticText(this,-1,
250                                     std2wx((*hi)[1])));
251         ogrid->Add( new wxStaticText(this,-1,
252                                     std2wx((*hi)[2])));
253       }
254     for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) 
255       {
256         ogrid->Add( new wxStaticText(this,-1,
257                                     std2wx((*hi)[0])));
258         ogrid->Add( new wxStaticText(this,-1,
259                                     std2wx((*hi)[1])));
260         ogrid->Add( new wxStaticText(this,-1,
261                                     std2wx((*hi)[2])));
262       }
263
264     outputs->Add(ogrid,0,wxGROW);
265     sizer->Add(outputs,0,wxGROW);
266
267   
268     SetSizer(sizer);
269     SetAutoLayout(true);
270     Layout();
271   }
272   //================================================================
273
274
275   //================================================================
276   WxGUIPackageBrowserBlackBox::~WxGUIPackageBrowserBlackBox()
277   {
278   }
279   //================================================================
280
281
282   //================================================================
283   WxGUIPackageBrowser::WxGUIPackageBrowser( wxWindow *parent,
284                                     WxGUIPackageBrowserUser* user )
285     : wxPanel(parent, -1),
286       mUser(user),
287       mInterpreter()
288   {
289
290     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
291     mTree = new wxTreeMultiCtrl(this, -1);
292     
293     mTree->SetBackgroundColour(*wxWHITE);
294     sizer->Add(mTree,1,wxGROW);
295
296 #ifndef LINUX
297     wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
298 #else
299     wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
300 #endif
301     
302     // make it a bit bigger
303     wxFont somefont;
304     somefont = mTree->GetCaptionFont();
305     somefont.SetFamily(wxMODERN);
306     somefont.SetWeight(wxBOLD);
307     somefont.SetPointSize(somefont.GetPointSize()+1);
308     mTree->SetCaptionFont(somefont);
309
310     mTree->SetSpacingY(1);
311     // mTree->SetCheckboxView(true);
312
313     SetSizer(sizer);
314     SetAutoLayout(true);
315     Layout();
316     
317   }
318   //================================================================
319
320   //================================================================
321   WxGUIPackageBrowser::~WxGUIPackageBrowser()
322   {
323     // std::cout << "del interpreter" << std::endl;
324     //   if (mInterpreter) delete mInterpreter;
325     //    std::cout << "ok" << std::endl;
326   }
327   //================================================================
328
329   //================================================================
330   void WxGUIPackageBrowser::IncludeAll()
331   {
332     if (!mInterpreter) mInterpreter = bbtk::Interpreter::New();
333     mInterpreter->SetCommandLine(true);
334     mInterpreter->InterpretLine("include *");
335
336     Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
337     BuildFromFactory(F);
338   }
339   //================================================================
340   //================================================================
341   
342   void WxGUIPackageBrowser::BuildFromFactory(Factory::Pointer F)
343   {
344 #ifndef LINUX
345     wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
346 #else
347     wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
348 #endif
349     mTree->DeleteAllItems();    
350     const Factory::PackageMapType& M = F->GetPackageMap();
351     Factory::PackageMapType::const_iterator i;
352     for (i=M.begin();i!=M.end();++i)
353       {
354         Package::Pointer P = i->second;
355         wxString packname = std2wx(P->GetName());
356         if (packname==_T("user")) continue;
357         wxTreeMultiItem pack = mTree->AddRoot(packname,packname);
358
359         wxString packinfo = std2wx(P->GetDescription());
360         packinfo += _T(" - by ")+ std2wx(P->GetAuthor());
361         packinfo += _T(" - v. ")+ std2wx(P->GetVersion());
362         mTree->AppendWindow(pack, 
363                             new wxStaticText(mTree,
364                                              -1,packinfo));
365         Package::BlackBoxMapType::iterator j;
366         for (j=P->GetBlackBoxMap().begin();
367              j!=P->GetBlackBoxMap().end();
368              ++j)
369           {
370             wxString boxname = std2wx(j->second->GetTypeName());
371             wxTreeMultiItem box = mTree->AppendNode(pack,boxname,boxname);
372             WxGUIPackageBrowserBlackBox* boxdescr 
373               = new WxGUIPackageBrowserBlackBox(mTree,this,j->second);
374             mTree->AppendWindow(box, boxdescr, _T(""), 
375                                 wndinfo, wxTMC_SPAN_WIDTH);
376
377           }
378       }
379     mTree->CollapseNodes(true);
380
381     // Test exclude 
382     wxTreeMultiItem item = mTree->FindItem(_T("Add"));
383     if(item.IsOk()) mTree->Exclude(item);
384   }
385   //================================================================
386
387   //================================================================
388   WxGUIPackageBrowserWindow::WxGUIPackageBrowserWindow( wxWindow *parent, 
389                                                     wxString title, 
390                                                     wxSize size)
391     : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
392   {     
393     
394     
395     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
396
397     mBrowser = new WxGUIPackageBrowser(this);
398     mBrowser->IncludeAll();
399     sizer->Add(mBrowser,1,wxGROW);
400     
401     //    WxGUICommand* com = new WxGUICommand(this,this);
402     //    sizer->Add(com);
403     
404     SetSizer(sizer); 
405
406
407     // Creates the parent window of all bbtk windows as a child of this
408     Wx::CreateTopWindow(this);
409     //    bbtkAddWxObserver(WxGUIConsole::OnWxSignal);
410
411
412     SetAutoLayout(true);
413     Layout();
414   }
415   //================================================================
416
417   //================================================================
418   WxGUIPackageBrowserWindow::~WxGUIPackageBrowserWindow()
419   {
420   }
421   //================================================================
422
423 } // namespace bbtk
424
425
426 #endif //_USE_WXWIDGETS_
427 */