bbtkWxGUIPackageBrowser.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkWxGUIPackageBrowser.cxx,v $
00004   Language:  C++
00005   Date:      $Date: 2008/10/17 08:18:15 $
00006   Version:   $Revision: 1.7 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030 
00031 
00047 /*
00048 #ifdef _USE_WXWIDGETS_
00049 
00050 #define CHECKBOXVIEW 1
00051 
00052 #include "bbtkWxGUIPackageBrowser.h"
00053 #include "ThirdParty/wx/treemultictrl/wxTreeMultiCtrl.h"
00054 #include "bbtkInterpreter.h"
00055 #include "bbtkBlackBoxInputDescriptor.h"
00056 #include "bbtkBlackBoxOutputDescriptor.h"
00057 #include "bbtkWxBlackBox.h"
00058 #include "wx/grid.h"
00059 #include <wx/statline.h>
00060 
00061 
00062 namespace bbtk
00063 {
00064   //================================================================
00065   WxGUIPackageBrowserBlackBox::
00066   WxGUIPackageBrowserBlackBox(wxWindow* parent,
00067                               WxGUIPackageBrowser* browser,
00068                               BlackBoxDescriptor::Pointer descr) :
00069     wxPanel(parent, -1),
00070     mBrowser(browser),
00071     mDescriptor(descr)
00072   {
00073     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00074     
00075     wxStaticText* s = new wxStaticText(this,-1,
00076                                        std2wx(descr->GetDescription()));
00077     sizer->Add(s,0,wxGROW);
00078     s = new wxStaticText(this,-1,
00079                          std2wx(descr->GetAuthor()));
00080     sizer->Add(s,0,wxGROW);
00081     s = new wxStaticText(this,-1,
00082                          std2wx(descr->GetCategory()));
00083     sizer->Add(s,0,wxGROW);
00084 
00085     std::vector<std::vector<std::string> > user_defined;
00086     std::vector<std::vector<std::string> > ubb_defined;
00087     std::vector<std::vector<std::string> > wxbb_defined;
00088     
00089     std::string titlecol("#BBBBFF");
00090     std::string usercol("#FFFFFF");
00091     std::string ubbcol("#DDFFFF");
00092     std::string wxbbcol("#EEFFFF");
00093 
00094    const BlackBoxDescriptor::InputDescriptorMapType& imap = 
00095       descr->GetInputDescriptorMap();
00096     BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
00097     for ( in = imap.begin();  in != imap.end(); ++in ) 
00098     {
00099       // Skips system-defined inputs
00100       std::string col(usercol);
00101       int iotype = 0;
00102       if (in->second->GetCreatorTypeInfo() == 
00103           typeid(AtomicBlackBoxDescriptor))
00104         {
00105           col = ubbcol; 
00106           iotype = 1;
00107         }
00108       else if (in->second->GetCreatorTypeInfo() == 
00109                typeid(WxBlackBoxDescriptor))
00110         {
00111           col = wxbbcol; 
00112           iotype = 2;
00113         }
00114 
00115       std::string name(in->second->GetName());
00116       //Utilities::html_format(name);
00117       
00118       std::string type("<");
00119       type += in->second->GetTypeName();    
00120       type += ">";
00121       //Utilities::html_format(type);
00122       
00123       std::string descr(in->second->GetDescription());
00124       //Utilities::html_format(descr);
00125       
00126       std::vector<std::string> out;
00127       out.push_back(name);
00128       out.push_back(type);
00129       out.push_back(descr);
00130 
00131       if (iotype==0) user_defined.push_back(out);
00132       else if (iotype==1) ubb_defined.push_back(out);
00133       else if (iotype==2) wxbb_defined.push_back(out);
00134       
00135     }
00136 
00137  
00138     wxBoxSizer *inputs = 
00139       new wxStaticBoxSizer
00140       ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );    
00141     wxFlexGridSizer* grid = new wxFlexGridSizer(3);
00142 
00143     wxTextAttr ionameattr(*wxRED,*wxBLACK);
00144     wxTextAttr iotypeattr(*wxBLACK,*wxRED);
00145 
00146     int n = 0;
00147     std::vector<std::vector<std::string> >::iterator hi;
00148     for (hi=user_defined.begin();hi!=user_defined.end();++hi) 
00149       {
00150         
00151         grid->Add( new wxStaticText(this,-1,std2wx((*hi)[0])));
00152         grid->Add( new wxStaticText(this,-1,std2wx((*hi)[1])));
00153         grid->Add( new wxStaticText(this,-1,std2wx((*hi)[2])));
00154         //      grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
00155         //      grid->SetReadOnly( n, 0 );
00156      }
00157     // grid->Add( new wxStaticLine(this,-1));
00158    for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) 
00159       {
00160         grid->Add( new wxStaticText(this,-1,
00161                                     std2wx((*hi)[0])));
00162         grid->Add( new wxStaticText(this,-1,
00163                                     std2wx((*hi)[1])));
00164         grid->Add( new wxStaticText(this,-1,
00165                                     std2wx((*hi)[2])));
00166       }
00167     for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) 
00168       {
00169         grid->Add( new wxStaticText(this,-1,
00170                                     std2wx((*hi)[0])));
00171         grid->Add( new wxStaticText(this,-1,
00172                                     std2wx((*hi)[1])));
00173         grid->Add( new wxStaticText(this,-1,
00174                                     std2wx((*hi)[2])));
00175       }
00176 
00177     inputs->Add(grid,0,wxGROW);
00178     sizer->Add(inputs,0,wxGROW);
00179 
00180     // Outputs
00181     user_defined.clear();
00182     ubb_defined.clear();
00183     wxbb_defined.clear();
00184     const BlackBoxDescriptor::OutputDescriptorMapType& omap = 
00185       descr->GetOutputDescriptorMap();
00186     BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
00187     for ( out = omap.begin();  out != omap.end(); ++out ) 
00188     {
00189       // Skips system-defined inputs
00190       std::string col(usercol);
00191       int iotype = 0;
00192       if (out->second->GetCreatorTypeInfo() == 
00193           typeid(AtomicBlackBoxDescriptor))
00194         {
00195           col = ubbcol; 
00196           iotype = 1;
00197         }
00198       else if (out->second->GetCreatorTypeInfo() == 
00199                typeid(WxBlackBoxDescriptor))
00200         {
00201           col = wxbbcol; 
00202           iotype = 2;
00203         }
00204 
00205       std::string name(out->second->GetName());
00206       //Utilities::html_format(name);
00207       
00208       std::string type("<");
00209       type += out->second->GetTypeName();    
00210       type += ">";
00211       //Utilities::html_format(type);
00212       
00213       std::string descr(out->second->GetDescription());
00214       //Utilities::html_format(descr);
00215       
00216       std::vector<std::string> out;
00217       out.push_back(name);
00218       out.push_back(type);
00219       out.push_back(descr);
00220 
00221       if (iotype==0) user_defined.push_back(out);
00222       else if (iotype==1) ubb_defined.push_back(out);
00223       else if (iotype==2) wxbb_defined.push_back(out);
00224       
00225     }
00226 
00227     wxBoxSizer *outputs = 
00228       new wxStaticBoxSizer
00229       ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );    
00230     wxFlexGridSizer* ogrid = new wxFlexGridSizer(3);
00231 
00232 
00233     n = 0;
00234     for (hi=user_defined.begin();hi!=user_defined.end();++hi) 
00235       {
00236         ogrid->Add( new wxStaticText(this,-1,
00237                                     std2wx((*hi)[0])));
00238         ogrid->Add( new wxStaticText(this,-1,
00239                                     std2wx((*hi)[1])));
00240         ogrid->Add( new wxStaticText(this,-1,
00241                                     std2wx((*hi)[2])));
00242         //      grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
00243         //      grid->SetReadOnly( n, 0 );
00244      }
00245     for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) 
00246       {
00247         ogrid->Add( new wxStaticText(this,-1,
00248                                     std2wx((*hi)[0])));
00249         ogrid->Add( new wxStaticText(this,-1,
00250                                     std2wx((*hi)[1])));
00251         ogrid->Add( new wxStaticText(this,-1,
00252                                     std2wx((*hi)[2])));
00253       }
00254     for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) 
00255       {
00256         ogrid->Add( new wxStaticText(this,-1,
00257                                     std2wx((*hi)[0])));
00258         ogrid->Add( new wxStaticText(this,-1,
00259                                     std2wx((*hi)[1])));
00260         ogrid->Add( new wxStaticText(this,-1,
00261                                     std2wx((*hi)[2])));
00262       }
00263 
00264     outputs->Add(ogrid,0,wxGROW);
00265     sizer->Add(outputs,0,wxGROW);
00266 
00267   
00268     SetSizer(sizer);
00269     SetAutoLayout(true);
00270     Layout();
00271   }
00272   //================================================================
00273 
00274 
00275   //================================================================
00276   WxGUIPackageBrowserBlackBox::~WxGUIPackageBrowserBlackBox()
00277   {
00278   }
00279   //================================================================
00280 
00281 
00282   //================================================================
00283   WxGUIPackageBrowser::WxGUIPackageBrowser( wxWindow *parent,
00284                                     WxGUIPackageBrowserUser* user )
00285     : wxPanel(parent, -1),
00286       mUser(user),
00287       mInterpreter()
00288   {
00289 
00290     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00291     mTree = new wxTreeMultiCtrl(this, -1);
00292     
00293     mTree->SetBackgroundColour(*wxWHITE);
00294     sizer->Add(mTree,1,wxGROW);
00295 
00296 #ifndef LINUX
00297     wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
00298 #else
00299     wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
00300 #endif
00301     
00302     // make it a bit bigger
00303     wxFont somefont;
00304     somefont = mTree->GetCaptionFont();
00305     somefont.SetFamily(wxMODERN);
00306     somefont.SetWeight(wxBOLD);
00307     somefont.SetPointSize(somefont.GetPointSize()+1);
00308     mTree->SetCaptionFont(somefont);
00309 
00310     mTree->SetSpacingY(1);
00311     // mTree->SetCheckboxView(true);
00312 
00313     SetSizer(sizer);
00314     SetAutoLayout(true);
00315     Layout();
00316     
00317   }
00318   //================================================================
00319 
00320   //================================================================
00321   WxGUIPackageBrowser::~WxGUIPackageBrowser()
00322   {
00323     // std::cout << "del interpreter" << std::endl;
00324     //   if (mInterpreter) delete mInterpreter;
00325     //    std::cout << "ok" << std::endl;
00326   }
00327   //================================================================
00328 
00329   //================================================================
00330   void WxGUIPackageBrowser::IncludeAll()
00331   {
00332     if (!mInterpreter) mInterpreter = bbtk::Interpreter::New();
00333     mInterpreter->SetCommandLine(true);
00334     mInterpreter->InterpretLine("include *");
00335 
00336     Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
00337     BuildFromFactory(F);
00338   }
00339   //================================================================
00340   //================================================================
00341   
00342   void WxGUIPackageBrowser::BuildFromFactory(Factory::Pointer F)
00343   {
00344 #ifndef LINUX
00345     wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
00346 #else
00347     wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
00348 #endif
00349     mTree->DeleteAllItems();    
00350     const Factory::PackageMapType& M = F->GetPackageMap();
00351     Factory::PackageMapType::const_iterator i;
00352     for (i=M.begin();i!=M.end();++i)
00353       {
00354         Package::Pointer P = i->second;
00355         wxString packname = std2wx(P->GetName());
00356         if (packname==_T("user")) continue;
00357         wxTreeMultiItem pack = mTree->AddRoot(packname,packname);
00358 
00359         wxString packinfo = std2wx(P->GetDescription());
00360         packinfo += _T(" - by ")+ std2wx(P->GetAuthor());
00361         packinfo += _T(" - v. ")+ std2wx(P->GetVersion());
00362         mTree->AppendWindow(pack, 
00363                             new wxStaticText(mTree,
00364                                              -1,packinfo));
00365         Package::BlackBoxMapType::iterator j;
00366         for (j=P->GetBlackBoxMap().begin();
00367              j!=P->GetBlackBoxMap().end();
00368              ++j)
00369           {
00370             wxString boxname = std2wx(j->second->GetTypeName());
00371             wxTreeMultiItem box = mTree->AppendNode(pack,boxname,boxname);
00372             WxGUIPackageBrowserBlackBox* boxdescr 
00373               = new WxGUIPackageBrowserBlackBox(mTree,this,j->second);
00374             mTree->AppendWindow(box, boxdescr, _T(""), 
00375                                 wndinfo, wxTMC_SPAN_WIDTH);
00376 
00377           }
00378       }
00379     mTree->CollapseNodes(true);
00380 
00381     // Test exclude 
00382     wxTreeMultiItem item = mTree->FindItem(_T("Add"));
00383     if(item.IsOk()) mTree->Exclude(item);
00384   }
00385   //================================================================
00386 
00387   //================================================================
00388   WxGUIPackageBrowserWindow::WxGUIPackageBrowserWindow( wxWindow *parent, 
00389                                                     wxString title, 
00390                                                     wxSize size)
00391     : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
00392   {     
00393     
00394     
00395     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00396 
00397     mBrowser = new WxGUIPackageBrowser(this);
00398     mBrowser->IncludeAll();
00399     sizer->Add(mBrowser,1,wxGROW);
00400     
00401     //    WxGUICommand* com = new WxGUICommand(this,this);
00402     //    sizer->Add(com);
00403     
00404     SetSizer(sizer); 
00405 
00406 
00407     // Creates the parent window of all bbtk windows as a child of this
00408     Wx::CreateTopWindow(this);
00409     //    bbtkAddWxObserver(WxGUIConsole::OnWxSignal);
00410 
00411 
00412     SetAutoLayout(true);
00413     Layout();
00414   }
00415   //================================================================
00416 
00417   //================================================================
00418   WxGUIPackageBrowserWindow::~WxGUIPackageBrowserWindow()
00419   {
00420   }
00421   //================================================================
00422 
00423 } // namespace bbtk
00424 
00425 
00426 #endif //_USE_WXWIDGETS_
00427 */

Generated on Wed Nov 12 11:37:08 2008 for BBTK by  doxygen 1.5.6