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