bbtkWxGUIPackageBrowser2.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
00004   Language:  C++
00005   Date:      $Date: 2009/06/08 14:50:04 $
00006   Version:   $Revision: 1.13 $
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 
00032 /* \brief Short description in one line
00033  * 
00034  * Long description which 
00035  * can span multiple lines
00036  */
00037  
00048 #ifdef _USE_WXWIDGETS_
00049 
00050 #define CHECKBOXVIEW 1
00051 
00052 #include "bbtkWxGUIPackageBrowser2.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 #define LIST_CTRL 1000
00062 
00063 
00064 namespace bbtk
00065 {
00066 
00067 
00068   BEGIN_EVENT_TABLE(WxGUIBlackBoxList, wxListCtrl)
00069     EVT_LIST_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginDrag)
00070     EVT_LIST_BEGIN_RDRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginRDrag)
00071     EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnBeginLabelEdit)
00072     EVT_LIST_END_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnEndLabelEdit)
00073     EVT_LIST_DELETE_ITEM(LIST_CTRL, WxGUIBlackBoxList::OnDeleteItem)
00074     EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, WxGUIBlackBoxList::OnDeleteAllItems)
00075 #if WXWIN_COMPATIBILITY_2_4
00076     EVT_LIST_GET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnGetInfo)
00077     EVT_LIST_SET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnSetInfo)
00078 #endif
00079     EVT_LIST_ITEM_SELECTED(LIST_CTRL, WxGUIBlackBoxList::OnSelected)
00080     EVT_LIST_ITEM_DESELECTED(LIST_CTRL, WxGUIBlackBoxList::OnDeselected)
00081     EVT_LIST_KEY_DOWN(LIST_CTRL, WxGUIBlackBoxList::OnListKeyDown)
00082     EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, WxGUIBlackBoxList::OnActivated)
00083     EVT_LIST_ITEM_FOCUSED(LIST_CTRL, WxGUIBlackBoxList::OnFocused)
00084     
00085     EVT_LIST_COL_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColClick)
00086     EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColRightClick)
00087     EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColBeginDrag)
00088     EVT_LIST_COL_DRAGGING(LIST_CTRL, WxGUIBlackBoxList::OnColDragging)
00089     EVT_LIST_COL_END_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColEndDrag)
00090     
00091     EVT_LIST_CACHE_HINT(LIST_CTRL, WxGUIBlackBoxList::OnCacheHint)
00092     
00093 #if USE_CONTEXT_MENU
00094     EVT_CONTEXT_MENU(WxGUIBlackBoxList::OnContextMenu)
00095 #endif
00096     EVT_CHAR(WxGUIBlackBoxList::OnChar)
00097     
00098     EVT_RIGHT_DOWN(WxGUIBlackBoxList::OnRightClick)
00099     END_EVENT_TABLE()
00100     
00101     int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData))
00102   {
00103     // inverse the order
00104     if (item1 < item2)
00105       return -1;
00106     if (item1 > item2)
00107       return 1;
00108     
00109     return 0;
00110   }
00111   
00112   // WxGUIBlackBoxList
00113   WxGUIBlackBoxList::WxGUIBlackBoxList(wxWindow *parent,
00114                                  const wxWindowID id,
00115                                  const wxPoint& pos,
00116                                  const wxSize& size,
00117                                  long style)
00118     : wxListCtrl(parent, id, pos, size, style),
00119       mUser(0),
00120       m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
00121   {
00122 #ifdef __POCKETPC__
00123     EnableContextMenu();
00124 #endif
00125   }
00126   
00127   void WxGUIBlackBoxList::Insert(BlackBoxDescriptor::Pointer d)
00128   {
00129     if (GetColumnCount()!=3)
00130       {
00131         InsertColumn( 0, _("Package"), 
00132                       wxLIST_FORMAT_LEFT, 60  ); 
00133         InsertColumn( 1, _("Box"), 
00134                       wxLIST_FORMAT_LEFT, 200 ); 
00135         InsertColumn( 2, _("Description"), 
00136                       wxLIST_FORMAT_LEFT, 500  ); 
00137       }
00138     
00139     wxListItem kNewItem;
00140     kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
00141     
00142     int nID = this->GetItemCount();
00143     kNewItem.SetId(nID);
00144     kNewItem.SetMask(wxLIST_MASK_DATA);
00145     // TO DO : STORE SMART POINTER ?
00146     kNewItem.SetData(d.get());  
00147     //    BlackBoxDescriptor::Pointer* d2 = (BlackBoxDescriptor::Pointer*)kNewItem.GetData();
00148     //    std::cout << "Descr = "<<d<<" = "<<d2<<std::endl;
00149     this->InsertItem(kNewItem);
00150     this->SetItem(nID, 0, std2wx(d->GetPackage()->GetName()) );
00151     this->SetItem(nID, 1, std2wx(d->GetTypeName()) );
00152     this->SetItem(nID, 2, std2wx(d->GetDescription()) );
00153     
00154     /*
00155       if (nID % 2)
00156       {
00157       kNewItem.SetBackgroundColour(wxColour(192,192,192));
00158       this->SetItem(kNewItem);
00159       }
00160     */
00161     
00162   }
00163   
00164   
00165   void WxGUIBlackBoxList::OnCacheHint(wxListEvent& event)
00166   {
00167     //wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"),
00168     //                  event.GetCacheFrom(), event.GetCacheTo() );
00169   }
00170   
00171   void WxGUIBlackBoxList::SetColumnImage(int col, int image)
00172   {
00173     /*
00174       wxListItem item;
00175       item.SetMask(wxLIST_MASK_IMAGE);
00176       item.SetImage(image);
00177       SetColumn(col, item);
00178     */
00179   }
00180 
00181   void WxGUIBlackBoxList::OnColClick(wxListEvent& event)
00182   {
00183     int col = event.GetColumn();
00184 
00185     // set or unset image
00186     static bool x = false;
00187     x = !x;
00188     SetColumnImage(col, x ? 0 : -1);
00189 
00190     //    wxLogMessage( wxT("OnColumnClick at %d."), col );
00191   }
00192 
00193   void WxGUIBlackBoxList::OnColRightClick(wxListEvent& event)
00194   {
00195     int col = event.GetColumn();
00196     if ( col != -1 )
00197       {
00198         SetColumnImage(col, -1);
00199       }
00200 
00201     // Show popupmenu at position
00202     wxMenu menu(wxT("Test"));
00203     menu.Append(-1, _T("&About"));
00204     PopupMenu(&menu, event.GetPoint());
00205 
00206     //wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
00207   }
00208 
00209   void WxGUIBlackBoxList::LogColEvent(const wxListEvent& event, const wxChar *name)
00210   {
00211     //    const int col = event.GetColumn();
00212 
00213     /*
00214       wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
00215       name,
00216       col,
00217       event.GetItem().GetWidth(),
00218       GetColumnWidth(col));
00219     */
00220   }
00221 
00222   void WxGUIBlackBoxList::OnColBeginDrag(wxListEvent& event)
00223   {
00224     LogColEvent( event, wxT("OnColBeginDrag") );
00225     /*
00226       if ( event.GetColumn() == 0 )
00227       {
00228       //wxLogMessage(_T("Resizing this column shouldn't work."));
00229 
00230       event.Veto();
00231       }
00232     */
00233   }
00234 
00235   void WxGUIBlackBoxList::OnColDragging(wxListEvent& event)
00236   {
00237     LogColEvent( event, wxT("OnColDragging") );
00238   }
00239 
00240   void WxGUIBlackBoxList::OnColEndDrag(wxListEvent& event)
00241   {
00242     LogColEvent( event, wxT("OnColEndDrag") );
00243   }
00244 
00245   void WxGUIBlackBoxList::OnBeginDrag(wxListEvent& event)
00246   {
00247     //    const wxPoint& pt = event.m_pointDrag;
00248 
00249     //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
00250     //          pt.x, pt.y, HitTest(pt, flags) );
00251   }
00252 
00253   void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
00254   {
00255     //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
00256     //        event.m_pointDrag.x, event.m_pointDrag.y );
00257   }
00258 
00259   void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
00260   {
00261     //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
00262   }
00263 
00264   void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
00265   {
00266     //wxLogMessage( wxT("OnEndLabelEdit: %s"),
00267     //        event.IsEditCancelled() ? _T("[cancelled]")
00268     //                                      : event.m_item.m_text.c_str());
00269   }
00270 
00271   void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
00272   {
00273     LogEvent(event, _T("OnDeleteItem"));
00274     std::cout << "cannot del"<<std::endl;
00275     event.Veto();
00276     //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
00277   }
00278 
00279   void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
00280   {
00281     LogEvent(event, _T("OnDeleteAllItems"));
00282     event.Veto();
00283   }
00284 
00285 #if WXWIN_COMPATIBILITY_2_4
00286   void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
00287   {
00288     wxString msg;
00289 
00290     msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
00291     if ( event.m_item.m_mask & wxLIST_MASK_STATE )
00292       msg << _T(" wxLIST_MASK_STATE");
00293     if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
00294       msg << _T(" wxLIST_MASK_TEXT");
00295     if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
00296       msg << _T(" wxLIST_MASK_IMAGE");
00297     if ( event.m_item.m_mask & wxLIST_MASK_DATA )
00298       msg << _T(" wxLIST_MASK_DATA");
00299     if ( event.m_item.m_mask & wxLIST_SET_ITEM )
00300       msg << _T(" wxLIST_SET_ITEM");
00301     if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
00302       msg << _T(" wxLIST_MASK_WIDTH");
00303     if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
00304       msg << _T(" wxLIST_MASK_WIDTH");
00305 
00306     if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
00307       {
00308         event.m_item.m_text = _T("My callback text");
00309       }
00310 
00311     //wxLogMessage(msg);
00312   }
00313 
00314   void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
00315   {
00316     LogEvent(event, _T("OnSetInfo"));
00317   }
00318 #endif
00319 
00320   void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
00321   {
00322     if (mUser==0) return;
00323 
00324     wxListItem info;
00325     info.m_itemId = event.m_itemIndex;
00326     info.m_col = 0;
00327     info.m_mask = wxLIST_MASK_DATA;
00328     if ( GetItem(info) )
00329       {
00330         // TO DO : STORE SMART PTR ?
00331         BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
00332         if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
00333       }
00334     else
00335       {
00336         wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
00337       }
00338   }
00339 
00340   void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
00341   {
00342     LogEvent(event, _T("OnDeselected"));
00343   }
00344 
00345   void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
00346   {
00347     LogEvent(event, _T("OnActivated"));
00348   }
00349 
00350   void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
00351   {
00352     LogEvent(event, _T("OnFocused"));
00353 
00354     event.Skip();
00355   }
00356 
00357   void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
00358   {
00359     long item;
00360 
00361     switch ( event.GetKeyCode() )
00362       {
00363       case 'c': // colorize
00364       case 'C':
00365         {
00366           wxListItem info;
00367           info.m_itemId = event.GetIndex();
00368           if ( info.m_itemId == -1 )
00369             {
00370               // no item
00371               break;
00372             }
00373 
00374           GetItem(info);
00375 
00376           wxListItemAttr *attr = info.GetAttributes();
00377           if ( !attr || !attr->HasTextColour() )
00378             {
00379               info.SetTextColour(*wxCYAN);
00380 
00381               SetItem(info);
00382 
00383               RefreshItem(info.m_itemId);
00384             }
00385         }
00386         break;
00387 
00388       case 'n': // next
00389       case 'N':
00390         item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
00391         if ( item++ == GetItemCount() - 1 )
00392           {
00393             item = 0;
00394           }
00395 
00396         //wxLogMessage(_T("Focusing item %ld"), item);
00397 
00398         SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
00399         EnsureVisible(item);
00400         break;
00401 
00402       case 'r': // show bounding Rect
00403       case 'R':
00404         {
00405           item = event.GetIndex();
00406           wxRect r;
00407           if ( !GetItemRect(item, r) )
00408             {
00409               //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
00410               break;
00411             }
00412 
00413           //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
00414           //   item, r.x, r.y, r.x + r.width, r.y + r.height);
00415         }
00416         break;
00417 
00418       case WXK_DELETE:
00419         item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
00420         /*
00421           while ( item != -1 )
00422           {
00423           DeleteItem(item);
00424 
00425           //wxLogMessage(_T("Item %ld deleted"), item);
00426 
00427           // -1 because the indices were shifted by DeleteItem()
00428           item = GetNextItem(item - 1,
00429           wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
00430           }
00431         */
00432         break;
00433 
00434       case WXK_INSERT:
00435         if ( GetWindowStyle() & wxLC_REPORT )
00436           {
00437             if ( GetWindowStyle() & wxLC_VIRTUAL )
00438               {
00439                 SetItemCount(GetItemCount() + 1);
00440               }
00441             else // !virtual
00442               {
00443                 //InsertItemInReportView(event.GetIndex());
00444               }
00445           }
00446         //else: fall through
00447 
00448       default:
00449         LogEvent(event, _T("OnListKeyDown"));
00450 
00451         event.Skip();
00452       }
00453   }
00454 
00455   void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
00456   {
00457     //wxLogMessage(_T("Got char event."));
00458 
00459     switch ( event.GetKeyCode() )
00460       {
00461       case 'n':
00462       case 'N':
00463       case 'c':
00464       case 'C':
00465         // these are the keys we process ourselves
00466         break;
00467 
00468       default:
00469         event.Skip();
00470       }
00471   }
00472 
00473   void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
00474   {
00475     if ( !event.ControlDown() )
00476       {
00477         event.Skip();
00478         return;
00479       }
00480 
00481     int flags;
00482     long subitem;
00483     //    long item = 
00484     HitTest(event.GetPosition(), flags, &subitem);
00485 
00486     wxString where;
00487     switch ( flags )
00488       {
00489       case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
00490       case wxLIST_HITTEST_BELOW: where = _T("below"); break;
00491       case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
00492       case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
00493       case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
00494       case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
00495       case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
00496       case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
00497       default: where = _T("not clear exactly where on"); break;
00498       }
00499 
00500     //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
00501     //             where.c_str(), item, subitem);
00502   }
00503 
00504   void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
00505   {
00506     //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
00507     //            event.GetIndex(), eventName,
00508     //              event.GetText().c_str(), event.GetData());
00509   }
00510 
00511   wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
00512   {
00513     /*
00514       if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
00515       {
00516       return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
00517       }
00518       else
00519       {
00520     */
00521     return wxString::Format(_T("Column %ld of item %ld"), column, item);
00522     //  }
00523   }
00524 
00525   int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
00526   {
00527     if (!column)
00528       return 0;
00529 
00530     if (!(item %3) && column == 1)
00531       return 0;
00532 
00533     return -1;
00534   }
00535 
00536   wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
00537   {
00538     return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
00539   }
00540 
00541 
00542 #if USE_CONTEXT_MENU
00543   void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
00544   {
00545     wxPoint point = event.GetPosition();
00546     // If from keyboard
00547     if (point.x == -1 && point.y == -1) {
00548       wxSize size = GetSize();
00549       point.x = size.x / 2;
00550       point.y = size.y / 2;
00551     } else {
00552       point = ScreenToClient(point);
00553     }
00554     ShowContextMenu(point);
00555   }
00556 #endif
00557 
00558   void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
00559   {
00560     wxMenu menu;
00561   
00562     menu.Append(wxID_ABOUT, _T("&About"));
00563     menu.AppendSeparator();
00564     menu.Append(wxID_EXIT, _T("E&xit"));
00565   
00566     PopupMenu(&menu, pos.x, pos.y);
00567   }
00568   //================================================================
00569 
00570 
00571 
00572   //================================================================
00573   WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
00574     :
00575     wxPanel(parent, -1),
00576     mDescriptor()
00577   {
00578     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00579     
00580     //    mName = new wxStaticText(this,-1,_T(""));
00581     //    sizer->Add(mName,0,wxGROW);
00582     mDescription = new wxStaticText(this,-1,_T(""));
00583     sizer->Add(mDescription,0,wxGROW);
00584     mAuthor = new wxStaticText(this,-1,_T(""));
00585     sizer->Add(mAuthor,0,wxGROW);
00586     mCategory = new wxStaticText(this,-1,_T(""));
00587     sizer->Add(mCategory,0,wxGROW);
00588 
00589 
00590     wxBoxSizer *inputs = 
00591       new wxStaticBoxSizer
00592       ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );    
00593     mInputList = new wxListCtrl(this, -1,
00594                                 wxDefaultPosition,
00595                                 wxDefaultSize,
00596                                 wxLC_REPORT //wxLC_LIST
00597                                 | wxSUNKEN_BORDER);
00598     
00599     
00600     inputs->Add(mInputList,1,wxGROW);
00601     sizer->Add(inputs,1,wxGROW);
00602 
00603     wxBoxSizer *outputs = 
00604       new wxStaticBoxSizer
00605       ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );    
00606     mOutputList = new wxListCtrl(this, -1,
00607                                  wxDefaultPosition,
00608                                  wxDefaultSize,
00609                                  wxLC_REPORT //wxLC_LIST
00610                                  | wxSUNKEN_BORDER);
00611     
00612     outputs->Add(mOutputList,1,wxGROW);
00613     sizer->Add(outputs,1,wxGROW);
00614     
00615     
00616     SetSizer(sizer);
00617     SetAutoLayout(true);
00618     Layout();
00619   }
00620   //================================================================
00621 
00622     
00623   //================================================================
00624   void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
00625   {
00626 
00627     //    mName->SetLabel(std2wx(descr->GetTypeName()));
00628     mDescription->SetLabel(std2wx(descr->GetDescription()));
00629     mAuthor->SetLabel(std2wx(descr->GetAuthor()));
00630     mCategory->SetLabel(std2wx(descr->GetCategory()));
00631     
00632     mInputList->ClearAll();
00633     mInputList->InsertColumn( 0, _("Name"), 
00634                                wxLIST_FORMAT_LEFT, 80  ); 
00635     mInputList->InsertColumn( 1, _("Type"), 
00636                                wxLIST_FORMAT_LEFT, 100 ); 
00637     mInputList->InsertColumn( 2, _("Nature"), 
00638                                wxLIST_FORMAT_LEFT, 100  ); 
00639     mInputList->InsertColumn( 3, _("Description"), 
00640                                wxLIST_FORMAT_LEFT, 500  ); 
00641 
00642     mOutputList->ClearAll();
00643     mOutputList->InsertColumn( 0, _("Name"), 
00644                                wxLIST_FORMAT_LEFT, 80  ); 
00645     mOutputList->InsertColumn( 1, _("Type"), 
00646                                wxLIST_FORMAT_LEFT, 100 ); 
00647     mOutputList->InsertColumn( 2, _("Nature"), 
00648                                wxLIST_FORMAT_LEFT, 100  ); 
00649     mOutputList->InsertColumn( 3, _("Description"), 
00650                                wxLIST_FORMAT_LEFT, 500  ); 
00651     
00652 
00653     std::vector<BlackBoxInputOutputDescriptor*> user_defined;
00654     std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
00655     std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
00656     
00657     const BlackBoxDescriptor::InputDescriptorMapType& imap = 
00658       descr->GetInputDescriptorMap();
00659     BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
00660     for ( in = imap.begin();  in != imap.end(); ++in ) 
00661       {
00662         int iotype = 0;
00663         if (in->second->GetCreatorTypeInfo() == 
00664             typeid(AtomicBlackBoxDescriptor))
00665           {
00666             iotype = 1;
00667           }
00668         else if (in->second->GetCreatorTypeInfo() == 
00669                  typeid(WxBlackBoxDescriptor))
00670           {
00671             iotype = 2;
00672           }
00673         if (iotype==0) user_defined.push_back(in->second);
00674         else if (iotype==1) ubb_defined.push_back(in->second);
00675         else if (iotype==2) wxbb_defined.push_back(in->second);
00676         
00677       }
00678 
00679     std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
00680     for (hi=user_defined.begin();hi!=user_defined.end();++hi) 
00681       {
00682         InsertInputOutput(mInputList,*hi);
00683       }
00684     for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) 
00685       {
00686         InsertInputOutput(mInputList,*hi);
00687       }
00688     for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) 
00689       {
00690         InsertInputOutput(mInputList,*hi);
00691       }
00692     
00693     // Outputs
00694     user_defined.clear();
00695     ubb_defined.clear();
00696     wxbb_defined.clear();
00697     const BlackBoxDescriptor::OutputDescriptorMapType& omap = 
00698       descr->GetOutputDescriptorMap();
00699     BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
00700     for ( out = omap.begin();  out != omap.end(); ++out ) 
00701       {
00702         int iotype = 0;
00703         if (out->second->GetCreatorTypeInfo() == 
00704             typeid(AtomicBlackBoxDescriptor))
00705           {
00706             iotype = 1;
00707           }
00708         else if (out->second->GetCreatorTypeInfo() == 
00709                  typeid(WxBlackBoxDescriptor))
00710           {
00711             iotype = 2;
00712           }
00713        
00714         if (iotype==0) user_defined.push_back(out->second);
00715         else if (iotype==1) ubb_defined.push_back(out->second);
00716         else if (iotype==2) wxbb_defined.push_back(out->second);
00717 
00718       }
00719     for (hi=user_defined.begin();hi!=user_defined.end();++hi) 
00720       {
00721         InsertInputOutput(mOutputList,*hi);
00722       }
00723     for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) 
00724       {
00725         InsertInputOutput(mOutputList,*hi);
00726       }
00727     for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) 
00728       {
00729         InsertInputOutput(mOutputList,*hi);
00730       }
00731   }
00732   //================================================================
00733 
00734 
00735   //================================================================
00736   void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
00737                                             BlackBoxInputOutputDescriptor* d)
00738   {
00739     wxListItem kNewItem;
00740     kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
00741     int nID = l->GetItemCount();
00742     //    std::cout << nID << std::endl;
00743     kNewItem.SetId(nID);
00744     //    kNewItem.SetMask(wxLIST_MASK_DATA);
00745     //    kNewItem.SetData(d);  
00746     l->InsertItem(kNewItem);
00747     l->SetItem(nID, 0, std2wx(d->GetName()) );
00748     l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
00749     l->SetItem(nID, 2, std2wx(d->GetNature()) );
00750     l->SetItem(nID, 3, std2wx(d->GetDescription()) );
00751   }
00752   //================================================================
00753 
00754   //================================================================
00755   WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
00756   {
00757   }
00758   //================================================================
00759 
00760 
00761  enum 
00762     {
00763       id_f1,
00764       id_f2,
00765       id_f3,
00766       id_f4,
00767       id_f5,
00768       id_f6,
00769       id_f7,
00770       id_f8,
00771       id_fc1,
00772       id_fc2,
00773       id_fc3
00774     };
00775 
00776 
00777   //================================================================
00778   WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
00779                                               WxGUIPackageBrowser2User* user )
00780     : wxPanel(parent, -1),
00781       mUser(user),
00782       mInterpreter()
00783   {
00784     m_mgr.SetManagedWindow(this);
00785 
00786     //    wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00787     mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
00788                                      wxDefaultPosition,
00789                                      wxDefaultSize,
00790                                      wxLC_REPORT //wxLC_LIST
00791                                      | wxSUNKEN_BORDER);
00792     mBoxList->SetUser(this);
00793     mBoxList->SetBackgroundColour(*wxWHITE);
00794 
00795     m_mgr.AddPane(mBoxList,
00796                   wxAuiPaneInfo().Name(wxT("BoxList"))
00797                   .Caption(wxT("Black Boxes"))
00798                   .MinimizeButton(true)
00799                   .MaximizeButton(true)
00800                   .Center()
00801                   .MinSize(wxSize(100,100))
00802                   );     
00803     //    sizer->Add(mBoxList,5,wxGROW);
00804 
00805     mBoxInfo = new WxGUIBlackBoxInfo(this);
00806     //    sizer->Add(mBoxInfo,3,wxGROW);
00807 
00808     m_mgr.AddPane(mBoxInfo,
00809                   wxAuiPaneInfo().Name(wxT("Box"))
00810                   .Caption(wxT(""))
00811                   .MinimizeButton(true)
00812                   .MaximizeButton(true)
00813                   .Bottom()
00814                   .MinSize(wxSize(100,300))
00815                   );     
00816     
00817 
00818     wxPanel* filters = new wxPanel(this,-1);
00819     wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );    
00820     wxBoxSizer *fpack = 
00821       new wxStaticBoxSizer
00822       ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );    
00823     mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
00824                                     wxDefaultPosition,
00825                                     wxDefaultSize,
00826                                     wxTE_PROCESS_ENTER);
00827     fpack->Add(mPackageFilter,1,wxGROW);
00828     fsizer->Add(fpack,0,wxGROW);
00829     wxBoxSizer *fname = 
00830       new wxStaticBoxSizer
00831       ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );    
00832     mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
00833                                     wxDefaultPosition,
00834                                     wxDefaultSize,
00835                                     wxTE_PROCESS_ENTER);
00836     fname->Add(mNameFilter,1,wxGROW);
00837     fsizer->Add(fname,0,wxGROW);
00838     wxBoxSizer *fdescr = 
00839       new wxStaticBoxSizer
00840       ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
00841     mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
00842                                     wxDefaultPosition,
00843                                     wxDefaultSize,
00844                                     wxTE_PROCESS_ENTER);
00845     fdescr->Add(mDescriptionFilter,1,wxGROW);
00846     fsizer->Add(fdescr,0,wxGROW);
00847     wxBoxSizer *fcat = 
00848       new wxStaticBoxSizer
00849       ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );    
00850     mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
00851                                     wxDefaultPosition,
00852                                     wxDefaultSize,
00853                                     wxTE_PROCESS_ENTER);
00854     fcat->Add(mCategoryFilter,1,wxGROW);
00855     fsizer->Add(fcat,0,wxGROW);
00856     wxBoxSizer *fintype = 
00857       new wxStaticBoxSizer
00858       ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
00859     mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
00860                                     wxDefaultPosition,
00861                                     wxDefaultSize,
00862                                     wxTE_PROCESS_ENTER);
00863     fintype->Add(mInputTypeFilter,1,wxGROW);
00864     fsizer->Add(fintype,0,wxGROW);
00865     wxBoxSizer *fouttype = 
00866       new wxStaticBoxSizer
00867       ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
00868     mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
00869                                     wxDefaultPosition,
00870                                     wxDefaultSize,
00871                                     wxTE_PROCESS_ENTER);
00872     fouttype->Add(mOutputTypeFilter,1,wxGROW);
00873     fsizer->Add(fouttype,0,wxGROW);
00874     wxBoxSizer *finnat = 
00875       new wxStaticBoxSizer
00876       ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL ); 
00877     mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
00878                                         wxDefaultPosition,
00879                                         wxDefaultSize,
00880                                         wxTE_PROCESS_ENTER);
00881     finnat->Add(mInputNatureFilter,1,wxGROW);
00882     fsizer->Add(finnat,0,wxGROW);
00883     wxBoxSizer *foutnat = 
00884       new wxStaticBoxSizer
00885       ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL ); 
00886     mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
00887                                         wxDefaultPosition,
00888                                         wxDefaultSize,
00889                                         wxTE_PROCESS_ENTER);
00890     foutnat->Add(mOutputNatureFilter,1,wxGROW);
00891     fsizer->Add(foutnat,0,wxGROW);
00892 
00893 
00894     mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
00895     mShowWidgetsFilter->SetValue(true);
00896     fsizer->Add(mShowWidgetsFilter,0,wxGROW);
00897 
00898     mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
00899     mShowAdaptorsFilter->SetValue(false);
00900     fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
00901 
00902     mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
00903     mShowGUIsFilter->SetValue(false);
00904     fsizer->Add(mShowGUIsFilter,0,wxGROW);
00905 
00906     filters->SetSizer(fsizer);
00907 
00908     m_mgr.AddPane(filters,
00909                   wxAuiPaneInfo().Name(wxT("Filter"))
00910                   .Caption(wxT("Filter"))
00911                   .MinimizeButton(true)
00912                   .MaximizeButton(true)
00913                   .Right()
00914                   .MinSize(wxSize(100,100)) );
00915 
00916     
00917 
00918     //    sizer->Add(fsizer,1,wxGROW);
00919     m_mgr.Update();
00920 
00921     //    SetSizer(sizer);
00922     SetAutoLayout(true);
00923     Layout();
00924     
00925   }
00926   //================================================================
00927 
00928   //================================================================
00929   void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
00930   {
00931     RebuildList();
00932   }
00933   //================================================================
00934 
00935   //================================================================
00936   // User callback when a box is selected in the list 
00937   void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
00938   ( BlackBoxDescriptor* d)
00939   {
00940     mBoxInfo->UpdateInfo(d);
00941     std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
00942     m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
00943     m_mgr.Update();
00944   }
00945   
00946   //================================================================
00947 
00948   //================================================================
00949   WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
00950   {
00951     mFactory.reset();
00952     mInterpreter.reset();
00953     //    Object::PrintObjectListInfo("");
00954     m_mgr.UnInit();
00955   }
00956   //================================================================
00957 
00958   //================================================================
00959   void WxGUIPackageBrowser2::IncludeAll()
00960   {
00961     if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
00962     mInterpreter->SetCommandLine(true);
00963     std::stringstream* buf = new std::stringstream;
00964     *buf << "exec freeze_no_error" << std::endl;
00965     *buf << "message max 0" << std::endl; 
00966     *buf << "include *" << std::endl;
00967     mInterpreter->InterpretBuffer(buf);
00968 
00969     Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
00970     BuildFromFactory(F);
00971   }
00972   //================================================================
00973 
00974   //================================================================
00975   void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
00976   {
00977     mFactory = F;
00978     RebuildList();
00979   }  
00980   //================================================================
00981 
00982   //================================================================
00983   void WxGUIPackageBrowser2::RebuildList()
00984   {
00985     mBoxList->Hide();
00986     mBoxList->ClearAll();    
00987     
00988     const Factory::PackageMapType& M = mFactory->GetPackageMap();
00989     Factory::PackageMapType::const_iterator i;
00990     for (i=M.begin();i!=M.end();++i)
00991       {
00992         Package::Pointer P = i->second;
00993         if (P->GetName() == "user") continue;
00994         
00995         Package::DescriptorMapType::iterator j;
00996         for (j=P->GetDescriptorMap().begin();
00997              j!=P->GetDescriptorMap().end();
00998              ++j)
00999           {
01000             //      std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
01001             if (IsVisible(j->second))
01002               mBoxList->Insert(j->second);
01003           }
01004       }
01005     mBoxList->Show();
01006   }
01007   //================================================================
01008 
01009   //================================================================
01010   bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
01011   {
01012     //    std::cout << "   '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
01013     //    std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
01014     if ((!mShowAdaptorsFilter->IsChecked())&&
01015         ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
01016          (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
01017       return false;
01018     if ((!mShowGUIsFilter->IsChecked())&&
01019         ((d->GetKind()==BlackBoxDescriptor::GUI)||
01020          (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
01021       return false;
01022     if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) ) 
01023         == std::string::npos ) return false;
01024    if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) ) 
01025         == std::string::npos ) return false;
01026    if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) ) 
01027         == std::string::npos ) return false;
01028    if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) ) 
01029         == std::string::npos ) return false;
01030    if (!mShowWidgetsFilter->IsChecked())
01031      {
01032        bool found = false;
01033        const BlackBoxDescriptor::OutputDescriptorMapType& imap = 
01034          d->GetOutputDescriptorMap();
01035        BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
01036        for ( in = imap.begin();  in != imap.end(); ++in ) 
01037          {
01038            if (in->second->GetName() == "Widget" )
01039              {
01040                found = true;
01041                break;
01042              }
01043          }
01044        if (found) return false;
01045      }
01046    if (mInputTypeFilter->GetValue().size()>0)
01047      {
01048        std::string s = wx2std(mInputTypeFilter->GetValue());
01049        bool found = false;
01050        const BlackBoxDescriptor::InputDescriptorMapType& imap = 
01051          d->GetInputDescriptorMap();
01052        BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
01053        for ( in = imap.begin();  in != imap.end(); ++in ) 
01054          {
01055            if (in->second->GetTypeName().find(s)!=std::string::npos)
01056              {
01057                found = true;
01058                break;
01059              }
01060          }
01061        if (!found) return false;
01062      }
01063    if (mOutputTypeFilter->GetValue().size()>0)
01064      {
01065        std::string s = wx2std(mOutputTypeFilter->GetValue());
01066        bool found = false;
01067        const BlackBoxDescriptor::OutputDescriptorMapType& imap = 
01068          d->GetOutputDescriptorMap();
01069        BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
01070        for ( in = imap.begin();  in != imap.end(); ++in ) 
01071          {
01072            if (in->second->GetTypeName().find(s)!=std::string::npos)
01073              {
01074                found = true;
01075                break;
01076              }
01077          }
01078        if (!found) return false;
01079      }
01080    if (mInputNatureFilter->GetValue().size()>0)
01081      {
01082        std::string s = wx2std(mInputNatureFilter->GetValue());
01083        bool found = false;
01084        const BlackBoxDescriptor::InputDescriptorMapType& imap = 
01085          d->GetInputDescriptorMap();
01086        BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
01087        for ( in = imap.begin();  in != imap.end(); ++in ) 
01088          {
01089            if (in->second->GetNature().find(s)!=std::string::npos)
01090              {
01091                found = true;
01092                break;
01093              }
01094          }
01095        if (!found) return false;
01096      }
01097    if (mOutputNatureFilter->GetValue().size()>0)
01098      {
01099        std::string s = wx2std(mOutputNatureFilter->GetValue());
01100        bool found = false;
01101        const BlackBoxDescriptor::OutputDescriptorMapType& imap = 
01102          d->GetOutputDescriptorMap();
01103        BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
01104        for ( in = imap.begin();  in != imap.end(); ++in ) 
01105          {
01106            if (in->second->GetNature().find(s)!=std::string::npos)
01107              {
01108                found = true;
01109                break;
01110              }
01111          }
01112        if (!found) return false;
01113      }
01114 
01115     return true;
01116   }
01117   //========================================================================
01118 
01119   //========================================================================
01120   BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
01121     EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
01122     EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
01123     EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
01124     EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
01125     EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
01126     EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
01127     EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
01128     EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
01129     EVT_CHECKBOX(  id_fc1, WxGUIPackageBrowser2::OnFilter )
01130     EVT_CHECKBOX(  id_fc2, WxGUIPackageBrowser2::OnFilter )
01131     EVT_CHECKBOX(  id_fc3, WxGUIPackageBrowser2::OnFilter )
01132     END_EVENT_TABLE()
01133   //========================================================================
01134 
01135 
01136 
01137   //================================================================
01138   WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent, 
01139                                                             wxString title, 
01140                                                             wxSize size)
01141       : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
01142   {     
01143     
01144     
01145     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
01146 
01147     mBrowser = new WxGUIPackageBrowser2(this);
01148     mBrowser->IncludeAll();
01149     sizer->Add(mBrowser,1,wxGROW);
01150     
01151     //    WxGUICommand* com = new WxGUICommand(this,this);
01152     //    sizer->Add(com);
01153     
01154     SetSizer(sizer);
01155 
01156      // Creates the parent window of all bbtk windows as a child of this
01157 //    Wx::CreateTopWindow(this);
01158     // Add the method OnWxSignal as a Wx::Signal observer 
01159     //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
01160  
01161     SetAutoLayout(true);
01162     Layout();
01163   }
01164   //================================================================
01165 
01166   //================================================================
01167   WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
01168   {
01169   }
01170   //================================================================
01171 
01172 } // namespace bbtk
01173 
01174 
01175 #endif //_USE_WXWIDGETS_

Generated on Mon Jul 27 14:59:14 2009 for BBTK by  doxygen 1.5.3