1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
6 Date: $Date: 2008/04/08 06:59:30 $
7 Version: $Revision: 1.3 $
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,1,wxGROW);
584 sizer->Add(inputs,1,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,1,wxGROW);
596 sizer->Add(outputs,1,wxGROW);
603 //================================================================
606 //================================================================
607 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
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, _("Nature"),
621 wxLIST_FORMAT_LEFT, 100 );
622 mInputList->InsertColumn( 3, _("Description"),
623 wxLIST_FORMAT_LEFT, 500 );
625 mOutputList->ClearAll();
626 mOutputList->InsertColumn( 0, _("Name"),
627 wxLIST_FORMAT_LEFT, 80 );
628 mOutputList->InsertColumn( 1, _("Type"),
629 wxLIST_FORMAT_LEFT, 100 );
630 mOutputList->InsertColumn( 2, _("Nature"),
631 wxLIST_FORMAT_LEFT, 100 );
632 mOutputList->InsertColumn( 3, _("Description"),
633 wxLIST_FORMAT_LEFT, 500 );
636 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
637 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
638 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
640 const BlackBoxDescriptor::InputDescriptorMapType& imap =
641 descr->GetInputDescriptorMap();
642 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
643 for ( in = imap.begin(); in != imap.end(); ++in )
646 if (in->second->GetCreatorTypeInfo() ==
647 typeid(AtomicBlackBoxDescriptor))
651 else if (in->second->GetCreatorTypeInfo() ==
652 typeid(WxBlackBoxDescriptor))
656 if (iotype==0) user_defined.push_back(in->second);
657 else if (iotype==1) ubb_defined.push_back(in->second);
658 else if (iotype==2) wxbb_defined.push_back(in->second);
662 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
663 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
665 InsertInputOutput(mInputList,*hi);
667 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
669 InsertInputOutput(mInputList,*hi);
671 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
673 InsertInputOutput(mInputList,*hi);
677 user_defined.clear();
679 wxbb_defined.clear();
680 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
681 descr->GetOutputDescriptorMap();
682 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
683 for ( out = omap.begin(); out != omap.end(); ++out )
686 if (out->second->GetCreatorTypeInfo() ==
687 typeid(AtomicBlackBoxDescriptor))
691 else if (out->second->GetCreatorTypeInfo() ==
692 typeid(WxBlackBoxDescriptor))
697 if (iotype==0) user_defined.push_back(out->second);
698 else if (iotype==1) ubb_defined.push_back(out->second);
699 else if (iotype==2) wxbb_defined.push_back(out->second);
702 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
704 InsertInputOutput(mOutputList,*hi);
706 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
708 InsertInputOutput(mOutputList,*hi);
710 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
712 InsertInputOutput(mOutputList,*hi);
715 //================================================================
718 //================================================================
719 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
720 BlackBoxInputOutputDescriptor* d)
723 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
724 int nID = l->GetItemCount();
725 std::cout << nID << std::endl;
727 // kNewItem.SetMask(wxLIST_MASK_DATA);
728 // kNewItem.SetData(d);
729 l->InsertItem(kNewItem);
730 l->SetItem(nID, 0, std2wx(d->GetName()) );
731 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
732 l->SetItem(nID, 2, std2wx(d->GetNature()) );
733 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
735 //================================================================
737 //================================================================
738 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
741 //================================================================
756 //================================================================
757 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
758 WxGUIPackageBrowser2User* user )
759 : wxPanel(parent, -1),
763 m_mgr.SetManagedWindow(this);
765 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
766 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
769 wxLC_REPORT //wxLC_LIST
771 mBoxList->SetUser(this);
772 mBoxList->SetBackgroundColour(*wxWHITE);
774 m_mgr.AddPane(mBoxList,
775 wxAuiPaneInfo().Name(wxT("BoxList"))
776 .Caption(wxT("Black Boxes"))
777 .MinimizeButton(true)
778 .MaximizeButton(true)
780 .MinSize(wxSize(100,100))
782 // sizer->Add(mBoxList,5,wxGROW);
784 mBoxInfo = new WxGUIBlackBoxInfo(this);
785 // sizer->Add(mBoxInfo,3,wxGROW);
787 m_mgr.AddPane(mBoxInfo,
788 wxAuiPaneInfo().Name(wxT("Box"))
790 .MinimizeButton(true)
791 .MaximizeButton(true)
793 .MinSize(wxSize(100,100))
797 wxPanel* filters = new wxPanel(this,-1);
798 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
801 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
802 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
806 fpack->Add(mPackageFilter,1,wxGROW);
807 fsizer->Add(fpack,0,wxGROW);
810 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
811 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
815 fname->Add(mNameFilter,1,wxGROW);
816 fsizer->Add(fname,0,wxGROW);
819 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
820 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
824 fdescr->Add(mDescriptionFilter,1,wxGROW);
825 fsizer->Add(fdescr,0,wxGROW);
828 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
829 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
833 fcat->Add(mCategoryFilter,1,wxGROW);
834 fsizer->Add(fcat,0,wxGROW);
835 wxBoxSizer *fintype =
837 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
838 mInputTypeFilter = new wxTextCtrl(filters,id_f4,_T(""),
842 fintype->Add(mInputTypeFilter,1,wxGROW);
843 fsizer->Add(fintype,0,wxGROW);
844 wxBoxSizer *fouttype =
846 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
847 mOutputTypeFilter = new wxTextCtrl(filters,id_f4,_T(""),
851 fouttype->Add(mOutputTypeFilter,1,wxGROW);
852 fsizer->Add(fouttype,0,wxGROW);
854 filters->SetSizer(fsizer);
856 m_mgr.AddPane(filters,
857 wxAuiPaneInfo().Name(wxT("Filter"))
858 .Caption(wxT("Filter"))
859 .MinimizeButton(true)
860 .MaximizeButton(true)
862 .MinSize(wxSize(100,100)) );
866 // sizer->Add(fsizer,1,wxGROW);
874 //================================================================
876 //================================================================
877 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
881 //================================================================
883 //================================================================
884 // User callback when a box is selected in the list
885 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected( BlackBoxDescriptor* d)
887 mBoxInfo->UpdateInfo(d);
888 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
889 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
893 //================================================================
895 //================================================================
896 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
898 std::cout << "del interpreter" << std::endl;
899 if (mInterpreter) delete mInterpreter;
900 std::cout << "ok" << std::endl;
902 //================================================================
904 //================================================================
905 void WxGUIPackageBrowser2::IncludeAll()
907 if (!mInterpreter) mInterpreter = new bbtk::Interpreter();
908 mInterpreter->SetCommandLine(true);
909 mInterpreter->InterpretLine("include *");
911 Factory* F = mInterpreter->GetExecuter()->GetFactory();
914 //================================================================
916 //================================================================
917 void WxGUIPackageBrowser2::BuildFromFactory(Factory* F)
922 //================================================================
924 //================================================================
925 void WxGUIPackageBrowser2::RebuildList()
928 mBoxList->ClearAll();
930 const Factory::PackageMapType& M = mFactory->GetPackageMap();
931 Factory::PackageMapType::const_iterator i;
932 for (i=M.begin();i!=M.end();++i)
934 Package* P = i->second.mPackage;
935 if (P->GetName() == "user") continue;
937 Package::BlackBoxMapType::iterator j;
938 for (j=P->GetBlackBoxMap().begin();
939 j!=P->GetBlackBoxMap().end();
942 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
943 if (IsVisible(j->second))
944 mBoxList->Insert(j->second);
949 //================================================================
951 //================================================================
952 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor* d)
954 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
955 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
956 if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) )
957 == std::string::npos ) return false;
958 if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) )
959 == std::string::npos ) return false;
960 if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) )
961 == std::string::npos ) return false;
962 if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) )
963 == std::string::npos ) return false;
964 if (mInputTypeFilter->GetValue().size()>0)
966 std::string s = wx2std(mInputTypeFilter->GetValue());
968 const BlackBoxDescriptor::InputDescriptorMapType& imap =
969 d->GetInputDescriptorMap();
970 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
971 for ( in = imap.begin(); in != imap.end(); ++in )
973 if (in->second->GetTypeName().find(s)!=std::string::npos)
979 if (!found) return false;
981 if (mOutputTypeFilter->GetValue().size()>0)
983 std::string s = wx2std(mOutputTypeFilter->GetValue());
985 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
986 d->GetOutputDescriptorMap();
987 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
988 for ( in = imap.begin(); in != imap.end(); ++in )
990 if (in->second->GetTypeName().find(s)!=std::string::npos)
996 if (!found) return false;
1002 //========================================================================
1004 //========================================================================
1005 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1006 EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1007 EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1008 EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1009 EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1010 EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1011 EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1013 //========================================================================
1017 //================================================================
1018 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1021 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1025 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1027 mBrowser = new WxGUIPackageBrowser2(this);
1028 mBrowser->IncludeAll();
1029 sizer->Add(mBrowser,1,wxGROW);
1031 // WxGUICommand* com = new WxGUICommand(this,this);
1036 // Creates and sets the parent window of all bbtk windows
1037 wxWindow* top = new wxPanel(this,-1);
1040 Wx::SetTopWindow(top);
1042 SetAutoLayout(true);
1045 //================================================================
1047 //================================================================
1048 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1051 //================================================================
1056 #endif //_USE_WXWIDGETS_