1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
6 Date: $Date: 2008/04/04 09:45:04 $
7 Version: $Revision: 1.2 $
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, _("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),
758 m_mgr.SetManagedWindow(this);
760 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
761 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
764 wxLC_REPORT //wxLC_LIST
766 mBoxList->SetUser(this);
767 mBoxList->SetBackgroundColour(*wxWHITE);
769 m_mgr.AddPane(mBoxList,
770 wxAuiPaneInfo().Name(wxT("BoxList"))
771 .Caption(wxT("Black Boxes"))
772 .MinimizeButton(true)
773 .MaximizeButton(true)
775 .MinSize(wxSize(100,100))
777 // sizer->Add(mBoxList,5,wxGROW);
779 mBoxInfo = new WxGUIBlackBoxInfo(this);
780 // sizer->Add(mBoxInfo,3,wxGROW);
782 m_mgr.AddPane(mBoxInfo,
783 wxAuiPaneInfo().Name(wxT("Box"))
785 .MinimizeButton(true)
786 .MaximizeButton(true)
788 .MinSize(wxSize(100,100))
792 wxPanel* filters = new wxPanel(this,-1);
793 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
796 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
797 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
801 fpack->Add(mPackageFilter,1,wxGROW);
802 fsizer->Add(fpack,0,wxGROW);
805 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
806 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
810 fname->Add(mNameFilter,1,wxGROW);
811 fsizer->Add(fname,0,wxGROW);
814 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
815 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
819 fdescr->Add(mDescriptionFilter,1,wxGROW);
820 fsizer->Add(fdescr,0,wxGROW);
823 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
824 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
828 fcat->Add(mCategoryFilter,1,wxGROW);
829 fsizer->Add(fcat,0,wxGROW);
830 wxBoxSizer *fintype =
832 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
833 mInputTypeFilter = new wxTextCtrl(filters,id_f4,_T(""),
837 fintype->Add(mInputTypeFilter,1,wxGROW);
838 fsizer->Add(fintype,0,wxGROW);
839 wxBoxSizer *fouttype =
841 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
842 mOutputTypeFilter = new wxTextCtrl(filters,id_f4,_T(""),
846 fouttype->Add(mOutputTypeFilter,1,wxGROW);
847 fsizer->Add(fouttype,0,wxGROW);
849 filters->SetSizer(fsizer);
851 m_mgr.AddPane(filters,
852 wxAuiPaneInfo().Name(wxT("Filter"))
853 .Caption(wxT("Filter"))
854 .MinimizeButton(true)
855 .MaximizeButton(true)
857 .MinSize(wxSize(100,100)) );
861 // sizer->Add(fsizer,1,wxGROW);
869 //================================================================
871 //================================================================
872 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
876 //================================================================
878 //================================================================
879 // User callback when a box is selected in the list
880 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected( BlackBoxDescriptor* d)
882 mBoxInfo->UpdateInfo(d);
883 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
884 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
888 //================================================================
890 //================================================================
891 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
893 std::cout << "del interpreter" << std::endl;
894 if (mInterpreter) delete mInterpreter;
895 std::cout << "ok" << std::endl;
897 //================================================================
899 //================================================================
900 void WxGUIPackageBrowser2::IncludeAll()
902 if (!mInterpreter) mInterpreter = new bbtk::Interpreter();
903 mInterpreter->SetCommandLine(true);
904 mInterpreter->InterpretLine("include *");
906 Factory* F = mInterpreter->GetExecuter()->GetFactory();
909 //================================================================
911 //================================================================
912 void WxGUIPackageBrowser2::BuildFromFactory(Factory* F)
917 //================================================================
919 //================================================================
920 void WxGUIPackageBrowser2::RebuildList()
923 mBoxList->ClearAll();
925 const Factory::PackageMapType& M = mFactory->GetPackageMap();
926 Factory::PackageMapType::const_iterator i;
927 for (i=M.begin();i!=M.end();++i)
929 Package* P = i->second.mPackage;
930 if (P->GetName() == "user") continue;
932 Package::BlackBoxMapType::iterator j;
933 for (j=P->GetBlackBoxMap().begin();
934 j!=P->GetBlackBoxMap().end();
937 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
938 if (IsVisible(j->second))
939 mBoxList->Insert(j->second);
944 //================================================================
946 //================================================================
947 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor* d)
949 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
950 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
951 if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) )
952 == std::string::npos ) return false;
953 if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) )
954 == std::string::npos ) return false;
955 if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) )
956 == std::string::npos ) return false;
957 if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) )
958 == std::string::npos ) return false;
959 if (mInputTypeFilter->GetValue().size()>0)
961 std::string s = wx2std(mInputTypeFilter->GetValue());
963 const BlackBoxDescriptor::InputDescriptorMapType& imap =
964 d->GetInputDescriptorMap();
965 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
966 for ( in = imap.begin(); in != imap.end(); ++in )
968 if (in->second->GetTypeName().find(s)!=std::string::npos)
974 if (!found) return false;
976 if (mOutputTypeFilter->GetValue().size()>0)
978 std::string s = wx2std(mOutputTypeFilter->GetValue());
980 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
981 d->GetOutputDescriptorMap();
982 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
983 for ( in = imap.begin(); in != imap.end(); ++in )
985 if (in->second->GetTypeName().find(s)!=std::string::npos)
991 if (!found) return false;
997 //========================================================================
999 //========================================================================
1000 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1001 EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1002 EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1003 EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1004 EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1005 EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1006 EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1008 //========================================================================
1012 //================================================================
1013 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1016 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1020 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1022 mBrowser = new WxGUIPackageBrowser2(this);
1023 mBrowser->IncludeAll();
1024 sizer->Add(mBrowser,1,wxGROW);
1026 // WxGUICommand* com = new WxGUICommand(this,this);
1031 // Creates and sets the parent window of all bbtk windows
1032 wxWindow* top = new wxPanel(this,-1);
1035 Wx::SetTopWindow(top);
1037 SetAutoLayout(true);
1040 //================================================================
1042 //================================================================
1043 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1046 //================================================================
1051 #endif //_USE_WXWIDGETS_