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