1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
6 Date: $Date: 2008/06/10 19:19:42 $
7 Version: $Revision: 1.9 $
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, 60 );
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 SMART 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;
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 // TO DO : STORE SMART PTR ?
316 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
317 if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
321 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
325 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
327 LogEvent(event, _T("OnDeselected"));
330 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
332 LogEvent(event, _T("OnActivated"));
335 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
337 LogEvent(event, _T("OnFocused"));
342 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
346 switch ( event.GetKeyCode() )
348 case 'c': // colorize
352 info.m_itemId = event.GetIndex();
353 if ( info.m_itemId == -1 )
361 wxListItemAttr *attr = info.GetAttributes();
362 if ( !attr || !attr->HasTextColour() )
364 info.SetTextColour(*wxCYAN);
368 RefreshItem(info.m_itemId);
375 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
376 if ( item++ == GetItemCount() - 1 )
381 //wxLogMessage(_T("Focusing item %ld"), item);
383 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
387 case 'r': // show bounding Rect
390 item = event.GetIndex();
392 if ( !GetItemRect(item, r) )
394 //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
398 //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
399 // item, r.x, r.y, r.x + r.width, r.y + r.height);
404 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
410 //wxLogMessage(_T("Item %ld deleted"), item);
412 // -1 because the indices were shifted by DeleteItem()
413 item = GetNextItem(item - 1,
414 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
420 if ( GetWindowStyle() & wxLC_REPORT )
422 if ( GetWindowStyle() & wxLC_VIRTUAL )
424 SetItemCount(GetItemCount() + 1);
428 //InsertItemInReportView(event.GetIndex());
434 LogEvent(event, _T("OnListKeyDown"));
440 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
442 //wxLogMessage(_T("Got char event."));
444 switch ( event.GetKeyCode() )
450 // these are the keys we process ourselves
458 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
460 if ( !event.ControlDown() )
468 long item = HitTest(event.GetPosition(), flags, &subitem);
473 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
474 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
475 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
476 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
477 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
478 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
479 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
480 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
481 default: where = _T("not clear exactly where on"); break;
484 //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
485 // where.c_str(), item, subitem);
488 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
490 //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
491 // event.GetIndex(), eventName,
492 // event.GetText().c_str(), event.GetData());
495 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
498 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
500 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
505 return wxString::Format(_T("Column %ld of item %ld"), column, item);
509 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
514 if (!(item %3) && column == 1)
520 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
522 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
527 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
529 wxPoint point = event.GetPosition();
531 if (point.x == -1 && point.y == -1) {
532 wxSize size = GetSize();
533 point.x = size.x / 2;
534 point.y = size.y / 2;
536 point = ScreenToClient(point);
538 ShowContextMenu(point);
542 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
546 menu.Append(wxID_ABOUT, _T("&About"));
547 menu.AppendSeparator();
548 menu.Append(wxID_EXIT, _T("E&xit"));
550 PopupMenu(&menu, pos.x, pos.y);
552 //================================================================
556 //================================================================
557 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
562 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
564 // mName = new wxStaticText(this,-1,_T(""));
565 // sizer->Add(mName,0,wxGROW);
566 mDescription = new wxStaticText(this,-1,_T(""));
567 sizer->Add(mDescription,0,wxGROW);
568 mAuthor = new wxStaticText(this,-1,_T(""));
569 sizer->Add(mAuthor,0,wxGROW);
570 mCategory = new wxStaticText(this,-1,_T(""));
571 sizer->Add(mCategory,0,wxGROW);
576 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
577 mInputList = new wxListCtrl(this, -1,
580 wxLC_REPORT //wxLC_LIST
584 inputs->Add(mInputList,1,wxGROW);
585 sizer->Add(inputs,1,wxGROW);
587 wxBoxSizer *outputs =
589 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
590 mOutputList = new wxListCtrl(this, -1,
593 wxLC_REPORT //wxLC_LIST
596 outputs->Add(mOutputList,1,wxGROW);
597 sizer->Add(outputs,1,wxGROW);
604 //================================================================
607 //================================================================
608 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
611 // mName->SetLabel(std2wx(descr->GetTypeName()));
612 mDescription->SetLabel(std2wx(descr->GetDescription()));
613 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
614 mCategory->SetLabel(std2wx(descr->GetCategory()));
616 mInputList->ClearAll();
617 mInputList->InsertColumn( 0, _("Name"),
618 wxLIST_FORMAT_LEFT, 80 );
619 mInputList->InsertColumn( 1, _("Type"),
620 wxLIST_FORMAT_LEFT, 100 );
621 mInputList->InsertColumn( 2, _("Nature"),
622 wxLIST_FORMAT_LEFT, 100 );
623 mInputList->InsertColumn( 3, _("Description"),
624 wxLIST_FORMAT_LEFT, 500 );
626 mOutputList->ClearAll();
627 mOutputList->InsertColumn( 0, _("Name"),
628 wxLIST_FORMAT_LEFT, 80 );
629 mOutputList->InsertColumn( 1, _("Type"),
630 wxLIST_FORMAT_LEFT, 100 );
631 mOutputList->InsertColumn( 2, _("Nature"),
632 wxLIST_FORMAT_LEFT, 100 );
633 mOutputList->InsertColumn( 3, _("Description"),
634 wxLIST_FORMAT_LEFT, 500 );
637 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
638 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
639 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
641 const BlackBoxDescriptor::InputDescriptorMapType& imap =
642 descr->GetInputDescriptorMap();
643 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
644 for ( in = imap.begin(); in != imap.end(); ++in )
647 if (in->second->GetCreatorTypeInfo() ==
648 typeid(AtomicBlackBoxDescriptor))
652 else if (in->second->GetCreatorTypeInfo() ==
653 typeid(WxBlackBoxDescriptor))
657 if (iotype==0) user_defined.push_back(in->second);
658 else if (iotype==1) ubb_defined.push_back(in->second);
659 else if (iotype==2) wxbb_defined.push_back(in->second);
663 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
664 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
666 InsertInputOutput(mInputList,*hi);
668 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
670 InsertInputOutput(mInputList,*hi);
672 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
674 InsertInputOutput(mInputList,*hi);
678 user_defined.clear();
680 wxbb_defined.clear();
681 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
682 descr->GetOutputDescriptorMap();
683 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
684 for ( out = omap.begin(); out != omap.end(); ++out )
687 if (out->second->GetCreatorTypeInfo() ==
688 typeid(AtomicBlackBoxDescriptor))
692 else if (out->second->GetCreatorTypeInfo() ==
693 typeid(WxBlackBoxDescriptor))
698 if (iotype==0) user_defined.push_back(out->second);
699 else if (iotype==1) ubb_defined.push_back(out->second);
700 else if (iotype==2) wxbb_defined.push_back(out->second);
703 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
705 InsertInputOutput(mOutputList,*hi);
707 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
709 InsertInputOutput(mOutputList,*hi);
711 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
713 InsertInputOutput(mOutputList,*hi);
716 //================================================================
719 //================================================================
720 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
721 BlackBoxInputOutputDescriptor* d)
724 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
725 int nID = l->GetItemCount();
726 // std::cout << nID << std::endl;
728 // kNewItem.SetMask(wxLIST_MASK_DATA);
729 // kNewItem.SetData(d);
730 l->InsertItem(kNewItem);
731 l->SetItem(nID, 0, std2wx(d->GetName()) );
732 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
733 l->SetItem(nID, 2, std2wx(d->GetNature()) );
734 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
736 //================================================================
738 //================================================================
739 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
742 //================================================================
761 //================================================================
762 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
763 WxGUIPackageBrowser2User* user )
764 : wxPanel(parent, -1),
768 m_mgr.SetManagedWindow(this);
770 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
771 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
774 wxLC_REPORT //wxLC_LIST
776 mBoxList->SetUser(this);
777 mBoxList->SetBackgroundColour(*wxWHITE);
779 m_mgr.AddPane(mBoxList,
780 wxAuiPaneInfo().Name(wxT("BoxList"))
781 .Caption(wxT("Black Boxes"))
782 .MinimizeButton(true)
783 .MaximizeButton(true)
785 .MinSize(wxSize(100,100))
787 // sizer->Add(mBoxList,5,wxGROW);
789 mBoxInfo = new WxGUIBlackBoxInfo(this);
790 // sizer->Add(mBoxInfo,3,wxGROW);
792 m_mgr.AddPane(mBoxInfo,
793 wxAuiPaneInfo().Name(wxT("Box"))
795 .MinimizeButton(true)
796 .MaximizeButton(true)
798 .MinSize(wxSize(100,300))
802 wxPanel* filters = new wxPanel(this,-1);
803 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
806 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
807 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
811 fpack->Add(mPackageFilter,1,wxGROW);
812 fsizer->Add(fpack,0,wxGROW);
815 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
816 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
820 fname->Add(mNameFilter,1,wxGROW);
821 fsizer->Add(fname,0,wxGROW);
824 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
825 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
829 fdescr->Add(mDescriptionFilter,1,wxGROW);
830 fsizer->Add(fdescr,0,wxGROW);
833 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
834 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
838 fcat->Add(mCategoryFilter,1,wxGROW);
839 fsizer->Add(fcat,0,wxGROW);
840 wxBoxSizer *fintype =
842 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
843 mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
847 fintype->Add(mInputTypeFilter,1,wxGROW);
848 fsizer->Add(fintype,0,wxGROW);
849 wxBoxSizer *fouttype =
851 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
852 mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
856 fouttype->Add(mOutputTypeFilter,1,wxGROW);
857 fsizer->Add(fouttype,0,wxGROW);
860 ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL );
861 mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
865 finnat->Add(mInputNatureFilter,1,wxGROW);
866 fsizer->Add(finnat,0,wxGROW);
867 wxBoxSizer *foutnat =
869 ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL );
870 mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
874 foutnat->Add(mOutputNatureFilter,1,wxGROW);
875 fsizer->Add(foutnat,0,wxGROW);
878 mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
879 mShowWidgetsFilter->SetValue(true);
880 fsizer->Add(mShowWidgetsFilter,0,wxGROW);
882 mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
883 mShowAdaptorsFilter->SetValue(false);
884 fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
886 mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
887 mShowGUIsFilter->SetValue(false);
888 fsizer->Add(mShowGUIsFilter,0,wxGROW);
890 filters->SetSizer(fsizer);
892 m_mgr.AddPane(filters,
893 wxAuiPaneInfo().Name(wxT("Filter"))
894 .Caption(wxT("Filter"))
895 .MinimizeButton(true)
896 .MaximizeButton(true)
898 .MinSize(wxSize(100,100)) );
902 // sizer->Add(fsizer,1,wxGROW);
910 //================================================================
912 //================================================================
913 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
917 //================================================================
919 //================================================================
920 // User callback when a box is selected in the list
921 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
922 ( BlackBoxDescriptor* d)
924 mBoxInfo->UpdateInfo(d);
925 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
926 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
930 //================================================================
932 //================================================================
933 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
936 mInterpreter.reset();
937 // Object::PrintObjectListInfo("");
940 //================================================================
942 //================================================================
943 void WxGUIPackageBrowser2::IncludeAll()
945 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
946 mInterpreter->SetCommandLine(true);
947 std::stringstream* buf = new std::stringstream;
948 *buf << "message max 0" << std::endl;
949 *buf << "include *" << std::endl;
950 mInterpreter->InterpretBuffer(buf);
952 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
955 //================================================================
957 //================================================================
958 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
963 //================================================================
965 //================================================================
966 void WxGUIPackageBrowser2::RebuildList()
969 mBoxList->ClearAll();
971 const Factory::PackageMapType& M = mFactory->GetPackageMap();
972 Factory::PackageMapType::const_iterator i;
973 for (i=M.begin();i!=M.end();++i)
975 Package::Pointer P = i->second;
976 if (P->GetName() == "user") continue;
978 Package::BlackBoxMapType::iterator j;
979 for (j=P->GetBlackBoxMap().begin();
980 j!=P->GetBlackBoxMap().end();
983 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
984 if (IsVisible(j->second))
985 mBoxList->Insert(j->second);
990 //================================================================
992 //================================================================
993 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
995 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
996 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
997 if ((!mShowAdaptorsFilter->IsChecked())&&
998 ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
999 (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
1001 if ((!mShowGUIsFilter->IsChecked())&&
1002 ((d->GetKind()==BlackBoxDescriptor::GUI)||
1003 (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
1005 if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) )
1006 == std::string::npos ) return false;
1007 if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) )
1008 == std::string::npos ) return false;
1009 if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) )
1010 == std::string::npos ) return false;
1011 if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) )
1012 == std::string::npos ) return false;
1013 if (!mShowWidgetsFilter->IsChecked())
1016 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1017 d->GetOutputDescriptorMap();
1018 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1019 for ( in = imap.begin(); in != imap.end(); ++in )
1021 if (in->second->GetName() == "Widget" )
1027 if (found) return false;
1029 if (mInputTypeFilter->GetValue().size()>0)
1031 std::string s = wx2std(mInputTypeFilter->GetValue());
1033 const BlackBoxDescriptor::InputDescriptorMapType& imap =
1034 d->GetInputDescriptorMap();
1035 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1036 for ( in = imap.begin(); in != imap.end(); ++in )
1038 if (in->second->GetTypeName().find(s)!=std::string::npos)
1044 if (!found) return false;
1046 if (mOutputTypeFilter->GetValue().size()>0)
1048 std::string s = wx2std(mOutputTypeFilter->GetValue());
1050 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1051 d->GetOutputDescriptorMap();
1052 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1053 for ( in = imap.begin(); in != imap.end(); ++in )
1055 if (in->second->GetTypeName().find(s)!=std::string::npos)
1061 if (!found) return false;
1063 if (mInputNatureFilter->GetValue().size()>0)
1065 std::string s = wx2std(mInputNatureFilter->GetValue());
1067 const BlackBoxDescriptor::InputDescriptorMapType& imap =
1068 d->GetInputDescriptorMap();
1069 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1070 for ( in = imap.begin(); in != imap.end(); ++in )
1072 if (in->second->GetNature().find(s)!=std::string::npos)
1078 if (!found) return false;
1080 if (mOutputNatureFilter->GetValue().size()>0)
1082 std::string s = wx2std(mOutputNatureFilter->GetValue());
1084 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1085 d->GetOutputDescriptorMap();
1086 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1087 for ( in = imap.begin(); in != imap.end(); ++in )
1089 if (in->second->GetNature().find(s)!=std::string::npos)
1095 if (!found) return false;
1100 //========================================================================
1102 //========================================================================
1103 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1104 EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1105 EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1106 EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1107 EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1108 EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1109 EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1110 EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
1111 EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
1112 EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
1113 EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
1114 EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
1116 //========================================================================
1120 //================================================================
1121 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1124 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1128 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1130 mBrowser = new WxGUIPackageBrowser2(this);
1131 mBrowser->IncludeAll();
1132 sizer->Add(mBrowser,1,wxGROW);
1134 // WxGUICommand* com = new WxGUICommand(this,this);
1139 // Creates the parent window of all bbtk windows as a child of this
1140 // Wx::CreateTopWindow(this);
1141 // Add the method OnWxSignal as a Wx::Signal observer
1142 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
1144 SetAutoLayout(true);
1147 //================================================================
1149 //================================================================
1150 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1153 //================================================================
1158 #endif //_USE_WXWIDGETS_