1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
6 Date: $Date: 2008/04/18 12:59:16 $
7 Version: $Revision: 1.5 $
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::Pointer 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);
130 // TO DO : STORE SHARED POINTER
131 // kNewItem.SetData(d.get());
132 // BlackBoxDescriptor::Pointer* d2 = (BlackBoxDescriptor::Pointer*)kNewItem.GetData();
133 // std::cout << "Descr = "<<d<<" = "<<d2<<std::endl;
134 this->InsertItem(kNewItem);
135 this->SetItem(nID, 0, std2wx(d->GetPackage()->GetName()) );
136 this->SetItem(nID, 1, std2wx(d->GetTypeName()) );
137 this->SetItem(nID, 2, std2wx(d->GetDescription()) );
142 kNewItem.SetBackgroundColour(wxColour(192,192,192));
143 this->SetItem(kNewItem);
150 void WxGUIBlackBoxList::OnCacheHint(wxListEvent& event)
152 //wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"),
153 // event.GetCacheFrom(), event.GetCacheTo() );
156 void WxGUIBlackBoxList::SetColumnImage(int col, int image)
160 item.SetMask(wxLIST_MASK_IMAGE);
161 item.SetImage(image);
162 SetColumn(col, item);
166 void WxGUIBlackBoxList::OnColClick(wxListEvent& event)
168 int col = event.GetColumn();
170 // set or unset image
171 static bool x = false;
173 SetColumnImage(col, x ? 0 : -1);
175 // wxLogMessage( wxT("OnColumnClick at %d."), col );
178 void WxGUIBlackBoxList::OnColRightClick(wxListEvent& event)
180 int col = event.GetColumn();
183 SetColumnImage(col, -1);
186 // Show popupmenu at position
187 wxMenu menu(wxT("Test"));
188 menu.Append(-1, _T("&About"));
189 PopupMenu(&menu, event.GetPoint());
191 //wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
194 void WxGUIBlackBoxList::LogColEvent(const wxListEvent& event, const wxChar *name)
196 const int col = event.GetColumn();
199 wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
202 event.GetItem().GetWidth(),
203 GetColumnWidth(col));
207 void WxGUIBlackBoxList::OnColBeginDrag(wxListEvent& event)
209 LogColEvent( event, wxT("OnColBeginDrag") );
211 if ( event.GetColumn() == 0 )
213 //wxLogMessage(_T("Resizing this column shouldn't work."));
220 void WxGUIBlackBoxList::OnColDragging(wxListEvent& event)
222 LogColEvent( event, wxT("OnColDragging") );
225 void WxGUIBlackBoxList::OnColEndDrag(wxListEvent& event)
227 LogColEvent( event, wxT("OnColEndDrag") );
230 void WxGUIBlackBoxList::OnBeginDrag(wxListEvent& event)
232 const wxPoint& pt = event.m_pointDrag;
235 //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
236 // pt.x, pt.y, HitTest(pt, flags) );
239 void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
241 //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
242 // event.m_pointDrag.x, event.m_pointDrag.y );
245 void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
247 //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
250 void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
252 //wxLogMessage( wxT("OnEndLabelEdit: %s"),
253 // event.IsEditCancelled() ? _T("[cancelled]")
254 // : event.m_item.m_text.c_str());
257 void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
259 LogEvent(event, _T("OnDeleteItem"));
260 std::cout << "cannot del"<<std::endl;
262 //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
265 void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
267 LogEvent(event, _T("OnDeleteAllItems"));
271 #if WXWIN_COMPATIBILITY_2_4
272 void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
276 msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
277 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
278 msg << _T(" wxLIST_MASK_STATE");
279 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
280 msg << _T(" wxLIST_MASK_TEXT");
281 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
282 msg << _T(" wxLIST_MASK_IMAGE");
283 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
284 msg << _T(" wxLIST_MASK_DATA");
285 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
286 msg << _T(" wxLIST_SET_ITEM");
287 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
288 msg << _T(" wxLIST_MASK_WIDTH");
289 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
290 msg << _T(" wxLIST_MASK_WIDTH");
292 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
294 event.m_item.m_text = _T("My callback text");
300 void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
302 LogEvent(event, _T("OnSetInfo"));
306 void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
308 if (mUser==0) return;
311 info.m_itemId = event.m_itemIndex;
313 info.m_mask = wxLIST_MASK_DATA;
316 // TO DO : STORE SHARED
317 // BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
318 // if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
322 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
326 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
328 LogEvent(event, _T("OnDeselected"));
331 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
333 LogEvent(event, _T("OnActivated"));
336 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
338 LogEvent(event, _T("OnFocused"));
343 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
347 switch ( event.GetKeyCode() )
349 case 'c': // colorize
353 info.m_itemId = event.GetIndex();
354 if ( info.m_itemId == -1 )
362 wxListItemAttr *attr = info.GetAttributes();
363 if ( !attr || !attr->HasTextColour() )
365 info.SetTextColour(*wxCYAN);
369 RefreshItem(info.m_itemId);
376 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
377 if ( item++ == GetItemCount() - 1 )
382 //wxLogMessage(_T("Focusing item %ld"), item);
384 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
388 case 'r': // show bounding Rect
391 item = event.GetIndex();
393 if ( !GetItemRect(item, r) )
395 //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
399 //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
400 // item, r.x, r.y, r.x + r.width, r.y + r.height);
405 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
411 //wxLogMessage(_T("Item %ld deleted"), item);
413 // -1 because the indices were shifted by DeleteItem()
414 item = GetNextItem(item - 1,
415 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
421 if ( GetWindowStyle() & wxLC_REPORT )
423 if ( GetWindowStyle() & wxLC_VIRTUAL )
425 SetItemCount(GetItemCount() + 1);
429 //InsertItemInReportView(event.GetIndex());
435 LogEvent(event, _T("OnListKeyDown"));
441 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
443 //wxLogMessage(_T("Got char event."));
445 switch ( event.GetKeyCode() )
451 // these are the keys we process ourselves
459 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
461 if ( !event.ControlDown() )
469 long item = HitTest(event.GetPosition(), flags, &subitem);
474 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
475 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
476 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
477 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
478 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
479 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
480 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
481 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
482 default: where = _T("not clear exactly where on"); break;
485 //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
486 // where.c_str(), item, subitem);
489 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
491 //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
492 // event.GetIndex(), eventName,
493 // event.GetText().c_str(), event.GetData());
496 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
499 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
501 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
506 return wxString::Format(_T("Column %ld of item %ld"), column, item);
510 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
515 if (!(item %3) && column == 1)
521 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
523 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
528 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
530 wxPoint point = event.GetPosition();
532 if (point.x == -1 && point.y == -1) {
533 wxSize size = GetSize();
534 point.x = size.x / 2;
535 point.y = size.y / 2;
537 point = ScreenToClient(point);
539 ShowContextMenu(point);
543 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
547 menu.Append(wxID_ABOUT, _T("&About"));
548 menu.AppendSeparator();
549 menu.Append(wxID_EXIT, _T("E&xit"));
551 PopupMenu(&menu, pos.x, pos.y);
553 //================================================================
557 //================================================================
558 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
563 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
565 // mName = new wxStaticText(this,-1,_T(""));
566 // sizer->Add(mName,0,wxGROW);
567 mDescription = new wxStaticText(this,-1,_T(""));
568 sizer->Add(mDescription,0,wxGROW);
569 mAuthor = new wxStaticText(this,-1,_T(""));
570 sizer->Add(mAuthor,0,wxGROW);
571 mCategory = new wxStaticText(this,-1,_T(""));
572 sizer->Add(mCategory,0,wxGROW);
577 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
578 mInputList = new wxListCtrl(this, -1,
581 wxLC_REPORT //wxLC_LIST
585 inputs->Add(mInputList,1,wxGROW);
586 sizer->Add(inputs,1,wxGROW);
588 wxBoxSizer *outputs =
590 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
591 mOutputList = new wxListCtrl(this, -1,
594 wxLC_REPORT //wxLC_LIST
597 outputs->Add(mOutputList,1,wxGROW);
598 sizer->Add(outputs,1,wxGROW);
605 //================================================================
608 //================================================================
609 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor::Pointer descr)
612 // mName->SetLabel(std2wx(descr->GetTypeName()));
613 mDescription->SetLabel(std2wx(descr->GetDescription()));
614 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
615 mCategory->SetLabel(std2wx(descr->GetCategory()));
617 mInputList->ClearAll();
618 mInputList->InsertColumn( 0, _("Name"),
619 wxLIST_FORMAT_LEFT, 80 );
620 mInputList->InsertColumn( 1, _("Type"),
621 wxLIST_FORMAT_LEFT, 100 );
622 mInputList->InsertColumn( 2, _("Nature"),
623 wxLIST_FORMAT_LEFT, 100 );
624 mInputList->InsertColumn( 3, _("Description"),
625 wxLIST_FORMAT_LEFT, 500 );
627 mOutputList->ClearAll();
628 mOutputList->InsertColumn( 0, _("Name"),
629 wxLIST_FORMAT_LEFT, 80 );
630 mOutputList->InsertColumn( 1, _("Type"),
631 wxLIST_FORMAT_LEFT, 100 );
632 mOutputList->InsertColumn( 2, _("Nature"),
633 wxLIST_FORMAT_LEFT, 100 );
634 mOutputList->InsertColumn( 3, _("Description"),
635 wxLIST_FORMAT_LEFT, 500 );
638 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
639 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
640 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
642 const BlackBoxDescriptor::InputDescriptorMapType& imap =
643 descr->GetInputDescriptorMap();
644 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
645 for ( in = imap.begin(); in != imap.end(); ++in )
648 if (in->second->GetCreatorTypeInfo() ==
649 typeid(AtomicBlackBoxDescriptor))
653 else if (in->second->GetCreatorTypeInfo() ==
654 typeid(WxBlackBoxDescriptor))
658 if (iotype==0) user_defined.push_back(in->second);
659 else if (iotype==1) ubb_defined.push_back(in->second);
660 else if (iotype==2) wxbb_defined.push_back(in->second);
664 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
665 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
667 InsertInputOutput(mInputList,*hi);
669 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
671 InsertInputOutput(mInputList,*hi);
673 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
675 InsertInputOutput(mInputList,*hi);
679 user_defined.clear();
681 wxbb_defined.clear();
682 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
683 descr->GetOutputDescriptorMap();
684 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
685 for ( out = omap.begin(); out != omap.end(); ++out )
688 if (out->second->GetCreatorTypeInfo() ==
689 typeid(AtomicBlackBoxDescriptor))
693 else if (out->second->GetCreatorTypeInfo() ==
694 typeid(WxBlackBoxDescriptor))
699 if (iotype==0) user_defined.push_back(out->second);
700 else if (iotype==1) ubb_defined.push_back(out->second);
701 else if (iotype==2) wxbb_defined.push_back(out->second);
704 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
706 InsertInputOutput(mOutputList,*hi);
708 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
710 InsertInputOutput(mOutputList,*hi);
712 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
714 InsertInputOutput(mOutputList,*hi);
717 //================================================================
720 //================================================================
721 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
722 BlackBoxInputOutputDescriptor* d)
725 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
726 int nID = l->GetItemCount();
727 // std::cout << nID << std::endl;
729 // kNewItem.SetMask(wxLIST_MASK_DATA);
730 // kNewItem.SetData(d);
731 l->InsertItem(kNewItem);
732 l->SetItem(nID, 0, std2wx(d->GetName()) );
733 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
734 l->SetItem(nID, 2, std2wx(d->GetNature()) );
735 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
737 //================================================================
739 //================================================================
740 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
743 //================================================================
758 //================================================================
759 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
760 WxGUIPackageBrowser2User* user )
761 : wxPanel(parent, -1),
765 m_mgr.SetManagedWindow(this);
767 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
768 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
771 wxLC_REPORT //wxLC_LIST
773 mBoxList->SetUser(this);
774 mBoxList->SetBackgroundColour(*wxWHITE);
776 m_mgr.AddPane(mBoxList,
777 wxAuiPaneInfo().Name(wxT("BoxList"))
778 .Caption(wxT("Black Boxes"))
779 .MinimizeButton(true)
780 .MaximizeButton(true)
782 .MinSize(wxSize(100,100))
784 // sizer->Add(mBoxList,5,wxGROW);
786 mBoxInfo = new WxGUIBlackBoxInfo(this);
787 // sizer->Add(mBoxInfo,3,wxGROW);
789 m_mgr.AddPane(mBoxInfo,
790 wxAuiPaneInfo().Name(wxT("Box"))
792 .MinimizeButton(true)
793 .MaximizeButton(true)
795 .MinSize(wxSize(100,300))
799 wxPanel* filters = new wxPanel(this,-1);
800 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
803 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
804 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
808 fpack->Add(mPackageFilter,1,wxGROW);
809 fsizer->Add(fpack,0,wxGROW);
812 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
813 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
817 fname->Add(mNameFilter,1,wxGROW);
818 fsizer->Add(fname,0,wxGROW);
821 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
822 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
826 fdescr->Add(mDescriptionFilter,1,wxGROW);
827 fsizer->Add(fdescr,0,wxGROW);
830 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
831 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
835 fcat->Add(mCategoryFilter,1,wxGROW);
836 fsizer->Add(fcat,0,wxGROW);
837 wxBoxSizer *fintype =
839 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
840 mInputTypeFilter = new wxTextCtrl(filters,id_f4,_T(""),
844 fintype->Add(mInputTypeFilter,1,wxGROW);
845 fsizer->Add(fintype,0,wxGROW);
846 wxBoxSizer *fouttype =
848 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
849 mOutputTypeFilter = new wxTextCtrl(filters,id_f4,_T(""),
853 fouttype->Add(mOutputTypeFilter,1,wxGROW);
854 fsizer->Add(fouttype,0,wxGROW);
856 filters->SetSizer(fsizer);
858 m_mgr.AddPane(filters,
859 wxAuiPaneInfo().Name(wxT("Filter"))
860 .Caption(wxT("Filter"))
861 .MinimizeButton(true)
862 .MaximizeButton(true)
864 .MinSize(wxSize(100,100)) );
868 // sizer->Add(fsizer,1,wxGROW);
876 //================================================================
878 //================================================================
879 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
883 //================================================================
885 //================================================================
886 // User callback when a box is selected in the list
887 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected( BlackBoxDescriptor::Pointer d)
889 mBoxInfo->UpdateInfo(d);
890 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
891 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
895 //================================================================
897 //================================================================
898 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
901 // std::cout << "del interpreter" << std::endl;
902 // if (mInterpreter) delete mInterpreter;
903 // std::cout << "ok" << std::endl;
905 //================================================================
907 //================================================================
908 void WxGUIPackageBrowser2::IncludeAll()
910 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
911 mInterpreter->SetCommandLine(true);
912 mInterpreter->InterpretLine("include *");
914 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
917 //================================================================
919 //================================================================
920 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
925 //================================================================
927 //================================================================
928 void WxGUIPackageBrowser2::RebuildList()
931 mBoxList->ClearAll();
933 const Factory::PackageMapType& M = mFactory->GetPackageMap();
934 Factory::PackageMapType::const_iterator i;
935 for (i=M.begin();i!=M.end();++i)
937 Package::Pointer P = i->second;
938 if (P->GetName() == "user") continue;
940 Package::BlackBoxMapType::iterator j;
941 for (j=P->GetBlackBoxMap().begin();
942 j!=P->GetBlackBoxMap().end();
945 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
946 if (IsVisible(j->second))
947 mBoxList->Insert(j->second);
952 //================================================================
954 //================================================================
955 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
957 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
958 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
959 if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) )
960 == std::string::npos ) return false;
961 if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) )
962 == std::string::npos ) return false;
963 if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) )
964 == std::string::npos ) return false;
965 if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) )
966 == std::string::npos ) return false;
967 if (mInputTypeFilter->GetValue().size()>0)
969 std::string s = wx2std(mInputTypeFilter->GetValue());
971 const BlackBoxDescriptor::InputDescriptorMapType& imap =
972 d->GetInputDescriptorMap();
973 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
974 for ( in = imap.begin(); in != imap.end(); ++in )
976 if (in->second->GetTypeName().find(s)!=std::string::npos)
982 if (!found) return false;
984 if (mOutputTypeFilter->GetValue().size()>0)
986 std::string s = wx2std(mOutputTypeFilter->GetValue());
988 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
989 d->GetOutputDescriptorMap();
990 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
991 for ( in = imap.begin(); in != imap.end(); ++in )
993 if (in->second->GetTypeName().find(s)!=std::string::npos)
999 if (!found) return false;
1005 //========================================================================
1007 //========================================================================
1008 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1009 EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1010 EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1011 EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1012 EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1013 EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1014 EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1016 //========================================================================
1020 //================================================================
1021 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1024 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1028 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1030 mBrowser = new WxGUIPackageBrowser2(this);
1031 mBrowser->IncludeAll();
1032 sizer->Add(mBrowser,1,wxGROW);
1034 // WxGUICommand* com = new WxGUICommand(this,this);
1039 // Creates and sets the parent window of all bbtk windows
1040 wxWindow* top = new wxPanel(this,-1);
1043 Wx::SetTopWindow(top);
1045 SetAutoLayout(true);
1048 //================================================================
1050 //================================================================
1051 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1054 //================================================================
1059 #endif //_USE_WXWIDGETS_