1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
6 Date: $Date: 2008/04/04 08:04:05 $
7 Version: $Revision: 1.1 $
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.
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.
17 =========================================================================*//**
18 * \brief Short description in one line
20 * Long description which
21 * can span multiple lines
33 #ifdef _USE_WXWIDGETS_
35 #define CHECKBOXVIEW 1
37 #include "bbtkWxGUIPackageBrowser2.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>
46 #define LIST_CTRL 1000
53 BEGIN_EVENT_TABLE(WxGUIBlackBoxList, wxListCtrl)
54 EVT_LIST_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginDrag)
55 EVT_LIST_BEGIN_RDRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginRDrag)
56 EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnBeginLabelEdit)
57 EVT_LIST_END_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnEndLabelEdit)
58 EVT_LIST_DELETE_ITEM(LIST_CTRL, WxGUIBlackBoxList::OnDeleteItem)
59 EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, WxGUIBlackBoxList::OnDeleteAllItems)
60 #if WXWIN_COMPATIBILITY_2_4
61 EVT_LIST_GET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnGetInfo)
62 EVT_LIST_SET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnSetInfo)
64 EVT_LIST_ITEM_SELECTED(LIST_CTRL, WxGUIBlackBoxList::OnSelected)
65 EVT_LIST_ITEM_DESELECTED(LIST_CTRL, WxGUIBlackBoxList::OnDeselected)
66 EVT_LIST_KEY_DOWN(LIST_CTRL, WxGUIBlackBoxList::OnListKeyDown)
67 EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, WxGUIBlackBoxList::OnActivated)
68 EVT_LIST_ITEM_FOCUSED(LIST_CTRL, WxGUIBlackBoxList::OnFocused)
70 EVT_LIST_COL_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColClick)
71 EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColRightClick)
72 EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColBeginDrag)
73 EVT_LIST_COL_DRAGGING(LIST_CTRL, WxGUIBlackBoxList::OnColDragging)
74 EVT_LIST_COL_END_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColEndDrag)
76 EVT_LIST_CACHE_HINT(LIST_CTRL, WxGUIBlackBoxList::OnCacheHint)
79 EVT_CONTEXT_MENU(WxGUIBlackBoxList::OnContextMenu)
81 EVT_CHAR(WxGUIBlackBoxList::OnChar)
83 EVT_RIGHT_DOWN(WxGUIBlackBoxList::OnRightClick)
86 int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData))
98 WxGUIBlackBoxList::WxGUIBlackBoxList(wxWindow *parent,
103 : wxListCtrl(parent, id, pos, size, style),
105 m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
112 void WxGUIBlackBoxList::Insert(BlackBoxDescriptor* d)
114 if (GetColumnCount()!=3)
116 InsertColumn( 0, _("Package"),
117 wxLIST_FORMAT_LEFT, 40 );
118 InsertColumn( 1, _("Box"),
119 wxLIST_FORMAT_LEFT, 200 );
120 InsertColumn( 2, _("Description"),
121 wxLIST_FORMAT_LEFT, 500 );
125 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
127 int nID = this->GetItemCount();
129 kNewItem.SetMask(wxLIST_MASK_DATA);
131 // BlackBoxDescriptor* d2 = (BlackBoxDescriptor*)kNewItem.GetData();
132 // std::cout << "Descr = "<<d<<" = "<<d2<<std::endl;
133 this->InsertItem(kNewItem);
134 this->SetItem(nID, 0, std2wx(d->GetPackage()->GetName()) );
135 this->SetItem(nID, 1, std2wx(d->GetTypeName()) );
136 this->SetItem(nID, 2, std2wx(d->GetDescription()) );
141 kNewItem.SetBackgroundColour(wxColour(192,192,192));
142 this->SetItem(kNewItem);
149 void WxGUIBlackBoxList::OnCacheHint(wxListEvent& event)
151 //wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"),
152 // event.GetCacheFrom(), event.GetCacheTo() );
155 void WxGUIBlackBoxList::SetColumnImage(int col, int image)
159 item.SetMask(wxLIST_MASK_IMAGE);
160 item.SetImage(image);
161 SetColumn(col, item);
165 void WxGUIBlackBoxList::OnColClick(wxListEvent& event)
167 int col = event.GetColumn();
169 // set or unset image
170 static bool x = false;
172 SetColumnImage(col, x ? 0 : -1);
174 // wxLogMessage( wxT("OnColumnClick at %d."), col );
177 void WxGUIBlackBoxList::OnColRightClick(wxListEvent& event)
179 int col = event.GetColumn();
182 SetColumnImage(col, -1);
185 // Show popupmenu at position
186 wxMenu menu(wxT("Test"));
187 menu.Append(-1, _T("&About"));
188 PopupMenu(&menu, event.GetPoint());
190 //wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
193 void WxGUIBlackBoxList::LogColEvent(const wxListEvent& event, const wxChar *name)
195 const int col = event.GetColumn();
198 wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
201 event.GetItem().GetWidth(),
202 GetColumnWidth(col));
206 void WxGUIBlackBoxList::OnColBeginDrag(wxListEvent& event)
208 LogColEvent( event, wxT("OnColBeginDrag") );
210 if ( event.GetColumn() == 0 )
212 //wxLogMessage(_T("Resizing this column shouldn't work."));
219 void WxGUIBlackBoxList::OnColDragging(wxListEvent& event)
221 LogColEvent( event, wxT("OnColDragging") );
224 void WxGUIBlackBoxList::OnColEndDrag(wxListEvent& event)
226 LogColEvent( event, wxT("OnColEndDrag") );
229 void WxGUIBlackBoxList::OnBeginDrag(wxListEvent& event)
231 const wxPoint& pt = event.m_pointDrag;
234 //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
235 // pt.x, pt.y, HitTest(pt, flags) );
238 void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
240 //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
241 // event.m_pointDrag.x, event.m_pointDrag.y );
244 void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
246 //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
249 void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
251 //wxLogMessage( wxT("OnEndLabelEdit: %s"),
252 // event.IsEditCancelled() ? _T("[cancelled]")
253 // : event.m_item.m_text.c_str());
256 void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
258 LogEvent(event, _T("OnDeleteItem"));
259 std::cout << "cannot del"<<std::endl;
261 //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
264 void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
266 LogEvent(event, _T("OnDeleteAllItems"));
270 #if WXWIN_COMPATIBILITY_2_4
271 void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
275 msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
276 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
277 msg << _T(" wxLIST_MASK_STATE");
278 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
279 msg << _T(" wxLIST_MASK_TEXT");
280 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
281 msg << _T(" wxLIST_MASK_IMAGE");
282 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
283 msg << _T(" wxLIST_MASK_DATA");
284 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
285 msg << _T(" wxLIST_SET_ITEM");
286 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
287 msg << _T(" wxLIST_MASK_WIDTH");
288 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
289 msg << _T(" wxLIST_MASK_WIDTH");
291 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
293 event.m_item.m_text = _T("My callback text");
299 void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
301 LogEvent(event, _T("OnSetInfo"));
305 void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
307 if (mUser==0) return;
310 info.m_itemId = event.m_itemIndex;
312 info.m_mask = wxLIST_MASK_DATA;
315 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
316 if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
320 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
324 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
326 LogEvent(event, _T("OnDeselected"));
329 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
331 LogEvent(event, _T("OnActivated"));
334 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
336 LogEvent(event, _T("OnFocused"));
341 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
345 switch ( event.GetKeyCode() )
347 case 'c': // colorize
351 info.m_itemId = event.GetIndex();
352 if ( info.m_itemId == -1 )
360 wxListItemAttr *attr = info.GetAttributes();
361 if ( !attr || !attr->HasTextColour() )
363 info.SetTextColour(*wxCYAN);
367 RefreshItem(info.m_itemId);
374 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
375 if ( item++ == GetItemCount() - 1 )
380 //wxLogMessage(_T("Focusing item %ld"), item);
382 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
386 case 'r': // show bounding Rect
389 item = event.GetIndex();
391 if ( !GetItemRect(item, r) )
393 //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
397 //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
398 // item, r.x, r.y, r.x + r.width, r.y + r.height);
403 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
409 //wxLogMessage(_T("Item %ld deleted"), item);
411 // -1 because the indices were shifted by DeleteItem()
412 item = GetNextItem(item - 1,
413 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
419 if ( GetWindowStyle() & wxLC_REPORT )
421 if ( GetWindowStyle() & wxLC_VIRTUAL )
423 SetItemCount(GetItemCount() + 1);
427 //InsertItemInReportView(event.GetIndex());
433 LogEvent(event, _T("OnListKeyDown"));
439 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
441 //wxLogMessage(_T("Got char event."));
443 switch ( event.GetKeyCode() )
449 // these are the keys we process ourselves
457 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
459 if ( !event.ControlDown() )
467 long item = HitTest(event.GetPosition(), flags, &subitem);
472 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
473 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
474 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
475 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
476 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
477 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
478 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
479 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
480 default: where = _T("not clear exactly where on"); break;
483 //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
484 // where.c_str(), item, subitem);
487 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
489 //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
490 // event.GetIndex(), eventName,
491 // event.GetText().c_str(), event.GetData());
494 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
497 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
499 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
504 return wxString::Format(_T("Column %ld of item %ld"), column, item);
508 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
513 if (!(item %3) && column == 1)
519 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
521 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
526 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
528 wxPoint point = event.GetPosition();
530 if (point.x == -1 && point.y == -1) {
531 wxSize size = GetSize();
532 point.x = size.x / 2;
533 point.y = size.y / 2;
535 point = ScreenToClient(point);
537 ShowContextMenu(point);
541 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
545 menu.Append(wxID_ABOUT, _T("&About"));
546 menu.AppendSeparator();
547 menu.Append(wxID_EXIT, _T("E&xit"));
549 PopupMenu(&menu, pos.x, pos.y);
551 //================================================================
555 //================================================================
556 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
561 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
563 mName = new wxStaticText(this,-1,_T(""));
564 sizer->Add(mName,0,wxGROW);
565 mDescription = new wxStaticText(this,-1,_T(""));
566 sizer->Add(mDescription,0,wxGROW);
567 mAuthor = new wxStaticText(this,-1,_T(""));
568 sizer->Add(mAuthor,0,wxGROW);
569 mCategory = new wxStaticText(this,-1,_T(""));
570 sizer->Add(mCategory,0,wxGROW);
575 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
576 mInputList = new wxListCtrl(this, -1,
579 wxLC_REPORT //wxLC_LIST
583 inputs->Add(mInputList,0,wxGROW);
584 sizer->Add(inputs,0,wxGROW);
586 wxBoxSizer *outputs =
588 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
589 mOutputList = new wxListCtrl(this, -1,
592 wxLC_REPORT //wxLC_LIST
595 outputs->Add(mOutputList,0,wxGROW);
596 sizer->Add(outputs,0,wxGROW);
603 //================================================================
606 //================================================================
607 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
609 std::cout << "UpdateInfo "<<descr<<std::endl;
610 mName->SetLabel(std2wx(descr->GetTypeName()));
611 mDescription->SetLabel(std2wx(descr->GetDescription()));
612 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
613 mCategory->SetLabel(std2wx(descr->GetCategory()));
615 mInputList->ClearAll();
616 mInputList->InsertColumn( 0, _("Name"),
617 wxLIST_FORMAT_LEFT, 80 );
618 mInputList->InsertColumn( 1, _("Type"),
619 wxLIST_FORMAT_LEFT, 100 );
620 mInputList->InsertColumn( 2, _("Description"),
621 wxLIST_FORMAT_LEFT, 500 );
623 mOutputList->ClearAll();
624 mOutputList->InsertColumn( 0, _("Name"),
625 wxLIST_FORMAT_LEFT, 80 );
626 mOutputList->InsertColumn( 1, _("Type"),
627 wxLIST_FORMAT_LEFT, 100 );
628 mOutputList->InsertColumn( 2, _("Description"),
629 wxLIST_FORMAT_LEFT, 500 );
632 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
633 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
634 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
636 const BlackBoxDescriptor::InputDescriptorMapType& imap =
637 descr->GetInputDescriptorMap();
638 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
639 for ( in = imap.begin(); in != imap.end(); ++in )
642 if (in->second->GetCreatorTypeInfo() ==
643 typeid(AtomicBlackBoxDescriptor))
647 else if (in->second->GetCreatorTypeInfo() ==
648 typeid(WxBlackBoxDescriptor))
652 if (iotype==0) user_defined.push_back(in->second);
653 else if (iotype==1) ubb_defined.push_back(in->second);
654 else if (iotype==2) wxbb_defined.push_back(in->second);
658 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
659 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
661 InsertInputOutput(mInputList,*hi);
663 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
665 InsertInputOutput(mInputList,*hi);
667 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
669 InsertInputOutput(mInputList,*hi);
673 user_defined.clear();
675 wxbb_defined.clear();
676 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
677 descr->GetOutputDescriptorMap();
678 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
679 for ( out = omap.begin(); out != omap.end(); ++out )
682 if (out->second->GetCreatorTypeInfo() ==
683 typeid(AtomicBlackBoxDescriptor))
687 else if (out->second->GetCreatorTypeInfo() ==
688 typeid(WxBlackBoxDescriptor))
693 if (iotype==0) user_defined.push_back(out->second);
694 else if (iotype==1) ubb_defined.push_back(out->second);
695 else if (iotype==2) wxbb_defined.push_back(out->second);
698 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
700 InsertInputOutput(mOutputList,*hi);
702 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
704 InsertInputOutput(mOutputList,*hi);
706 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
708 InsertInputOutput(mOutputList,*hi);
711 //================================================================
714 //================================================================
715 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
716 BlackBoxInputOutputDescriptor* d)
719 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
720 int nID = l->GetItemCount();
721 std::cout << nID << std::endl;
723 // kNewItem.SetMask(wxLIST_MASK_DATA);
724 // kNewItem.SetData(d);
725 l->InsertItem(kNewItem);
726 l->SetItem(nID, 0, std2wx(d->GetName()) );
727 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
728 l->SetItem(nID, 2, std2wx(d->GetDescription()) );
730 //================================================================
732 //================================================================
733 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
736 //================================================================
751 //================================================================
752 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
753 WxGUIPackageBrowser2User* user )
754 : wxPanel(parent, -1),
759 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
760 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
763 wxLC_REPORT //wxLC_LIST
765 mBoxList->SetUser(this);
766 mBoxList->SetBackgroundColour(*wxWHITE);
767 sizer->Add(mBoxList,5,wxGROW);
769 mBoxInfo = new WxGUIBlackBoxInfo(this);
770 sizer->Add(mBoxInfo,3,wxGROW);
774 wxBoxSizer *fsizer = new wxStaticBoxSizer
775 ( new wxStaticBox(this, wxID_ANY, _T("Filters")), wxHORIZONTAL );
777 mPackageFilter = new wxTextCtrl(this,id_f1,_T(""),
781 fsizer->Add(mPackageFilter,1,wxGROW);
782 mNameFilter = new wxTextCtrl(this,id_f2,_T(""),
786 fsizer->Add(mNameFilter,1,wxGROW);
787 mDescriptionFilter = new wxTextCtrl(this,id_f3,_T(""),
791 fsizer->Add(mDescriptionFilter,1,wxGROW);
792 mCategoryFilter = new wxTextCtrl(this,id_f4,_T(""),
796 fsizer->Add(mCategoryFilter,1,wxGROW);
797 mInputTypeFilter = new wxTextCtrl(this,id_f4,_T(""),
801 fsizer->Add(mInputTypeFilter,1,wxGROW);
802 mOutputTypeFilter = new wxTextCtrl(this,id_f4,_T(""),
806 fsizer->Add(mOutputTypeFilter,1,wxGROW);
809 sizer->Add(fsizer,1,wxGROW);
816 //================================================================
818 //================================================================
819 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
823 //================================================================
825 //================================================================
826 // User callback when a box is selected in the list
827 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected( BlackBoxDescriptor* d)
829 mBoxInfo->UpdateInfo(d);
832 //================================================================
834 //================================================================
835 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
837 std::cout << "del interpreter" << std::endl;
838 if (mInterpreter) delete mInterpreter;
839 std::cout << "ok" << std::endl;
841 //================================================================
843 //================================================================
844 void WxGUIPackageBrowser2::IncludeAll()
846 if (!mInterpreter) mInterpreter = new bbtk::Interpreter();
847 mInterpreter->SetCommandLine(true);
848 mInterpreter->InterpretLine("include *");
850 Factory* F = mInterpreter->GetExecuter()->GetFactory();
853 //================================================================
855 //================================================================
856 void WxGUIPackageBrowser2::BuildFromFactory(Factory* F)
861 //================================================================
863 //================================================================
864 void WxGUIPackageBrowser2::RebuildList()
867 mBoxList->ClearAll();
869 const Factory::PackageMapType& M = mFactory->GetPackageMap();
870 Factory::PackageMapType::const_iterator i;
871 for (i=M.begin();i!=M.end();++i)
873 Package* P = i->second.mPackage;
874 if (P->GetName() == "user") continue;
876 Package::BlackBoxMapType::iterator j;
877 for (j=P->GetBlackBoxMap().begin();
878 j!=P->GetBlackBoxMap().end();
881 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
882 if (IsVisible(j->second))
883 mBoxList->Insert(j->second);
888 //================================================================
890 //================================================================
891 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor* d)
893 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
894 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
895 if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) )
896 == std::string::npos ) return false;
897 if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) )
898 == std::string::npos ) return false;
899 if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) )
900 == std::string::npos ) return false;
901 if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) )
902 == std::string::npos ) return false;
903 if (mInputTypeFilter->GetValue().size()>0)
905 std::string s = wx2std(mInputTypeFilter->GetValue());
907 const BlackBoxDescriptor::InputDescriptorMapType& imap =
908 d->GetInputDescriptorMap();
909 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
910 for ( in = imap.begin(); in != imap.end(); ++in )
912 if (in->second->GetTypeName().find(s)!=std::string::npos)
918 if (!found) return false;
920 if (mOutputTypeFilter->GetValue().size()>0)
922 std::string s = wx2std(mOutputTypeFilter->GetValue());
924 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
925 d->GetOutputDescriptorMap();
926 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
927 for ( in = imap.begin(); in != imap.end(); ++in )
929 if (in->second->GetTypeName().find(s)!=std::string::npos)
935 if (!found) return false;
941 //========================================================================
943 //========================================================================
944 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
945 EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
946 EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
947 EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
948 EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
949 EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
950 EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
952 //========================================================================
956 //================================================================
957 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
960 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
964 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
966 mBrowser = new WxGUIPackageBrowser2(this);
967 mBrowser->IncludeAll();
968 sizer->Add(mBrowser,1,wxGROW);
970 // WxGUICommand* com = new WxGUICommand(this,this);
975 // Creates and sets the parent window of all bbtk windows
976 wxWindow* top = new wxPanel(this,-1);
979 Wx::SetTopWindow(top);
984 //================================================================
986 //================================================================
987 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
990 //================================================================
995 #endif //_USE_WXWIDGETS_