1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
6 Date: $Date: 2008/07/23 11:46:11 $
7 Version: $Revision: 1.10 $
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() )
469 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* 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 //================================================================
762 //================================================================
763 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
764 WxGUIPackageBrowser2User* user )
765 : wxPanel(parent, -1),
769 m_mgr.SetManagedWindow(this);
771 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
772 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
775 wxLC_REPORT //wxLC_LIST
777 mBoxList->SetUser(this);
778 mBoxList->SetBackgroundColour(*wxWHITE);
780 m_mgr.AddPane(mBoxList,
781 wxAuiPaneInfo().Name(wxT("BoxList"))
782 .Caption(wxT("Black Boxes"))
783 .MinimizeButton(true)
784 .MaximizeButton(true)
786 .MinSize(wxSize(100,100))
788 // sizer->Add(mBoxList,5,wxGROW);
790 mBoxInfo = new WxGUIBlackBoxInfo(this);
791 // sizer->Add(mBoxInfo,3,wxGROW);
793 m_mgr.AddPane(mBoxInfo,
794 wxAuiPaneInfo().Name(wxT("Box"))
796 .MinimizeButton(true)
797 .MaximizeButton(true)
799 .MinSize(wxSize(100,300))
803 wxPanel* filters = new wxPanel(this,-1);
804 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
807 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
808 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
812 fpack->Add(mPackageFilter,1,wxGROW);
813 fsizer->Add(fpack,0,wxGROW);
816 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
817 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
821 fname->Add(mNameFilter,1,wxGROW);
822 fsizer->Add(fname,0,wxGROW);
825 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
826 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
830 fdescr->Add(mDescriptionFilter,1,wxGROW);
831 fsizer->Add(fdescr,0,wxGROW);
834 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
835 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
839 fcat->Add(mCategoryFilter,1,wxGROW);
840 fsizer->Add(fcat,0,wxGROW);
841 wxBoxSizer *fintype =
843 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
844 mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
848 fintype->Add(mInputTypeFilter,1,wxGROW);
849 fsizer->Add(fintype,0,wxGROW);
850 wxBoxSizer *fouttype =
852 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
853 mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
857 fouttype->Add(mOutputTypeFilter,1,wxGROW);
858 fsizer->Add(fouttype,0,wxGROW);
861 ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL );
862 mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
866 finnat->Add(mInputNatureFilter,1,wxGROW);
867 fsizer->Add(finnat,0,wxGROW);
868 wxBoxSizer *foutnat =
870 ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL );
871 mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
875 foutnat->Add(mOutputNatureFilter,1,wxGROW);
876 fsizer->Add(foutnat,0,wxGROW);
879 mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
880 mShowWidgetsFilter->SetValue(true);
881 fsizer->Add(mShowWidgetsFilter,0,wxGROW);
883 mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
884 mShowAdaptorsFilter->SetValue(false);
885 fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
887 mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
888 mShowGUIsFilter->SetValue(false);
889 fsizer->Add(mShowGUIsFilter,0,wxGROW);
891 filters->SetSizer(fsizer);
893 m_mgr.AddPane(filters,
894 wxAuiPaneInfo().Name(wxT("Filter"))
895 .Caption(wxT("Filter"))
896 .MinimizeButton(true)
897 .MaximizeButton(true)
899 .MinSize(wxSize(100,100)) );
903 // sizer->Add(fsizer,1,wxGROW);
911 //================================================================
913 //================================================================
914 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
918 //================================================================
920 //================================================================
921 // User callback when a box is selected in the list
922 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
923 ( BlackBoxDescriptor* d)
925 mBoxInfo->UpdateInfo(d);
926 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
927 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
931 //================================================================
933 //================================================================
934 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
937 mInterpreter.reset();
938 // Object::PrintObjectListInfo("");
941 //================================================================
943 //================================================================
944 void WxGUIPackageBrowser2::IncludeAll()
946 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
947 mInterpreter->SetCommandLine(true);
948 std::stringstream* buf = new std::stringstream;
949 *buf << "message max 0" << std::endl;
950 *buf << "include *" << std::endl;
951 mInterpreter->InterpretBuffer(buf);
953 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
956 //================================================================
958 //================================================================
959 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
964 //================================================================
966 //================================================================
967 void WxGUIPackageBrowser2::RebuildList()
970 mBoxList->ClearAll();
972 const Factory::PackageMapType& M = mFactory->GetPackageMap();
973 Factory::PackageMapType::const_iterator i;
974 for (i=M.begin();i!=M.end();++i)
976 Package::Pointer P = i->second;
977 if (P->GetName() == "user") continue;
979 Package::BlackBoxMapType::iterator j;
980 for (j=P->GetBlackBoxMap().begin();
981 j!=P->GetBlackBoxMap().end();
984 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
985 if (IsVisible(j->second))
986 mBoxList->Insert(j->second);
991 //================================================================
993 //================================================================
994 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
996 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
997 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
998 if ((!mShowAdaptorsFilter->IsChecked())&&
999 ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
1000 (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
1002 if ((!mShowGUIsFilter->IsChecked())&&
1003 ((d->GetKind()==BlackBoxDescriptor::GUI)||
1004 (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
1006 if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) )
1007 == std::string::npos ) return false;
1008 if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) )
1009 == std::string::npos ) return false;
1010 if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) )
1011 == std::string::npos ) return false;
1012 if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) )
1013 == std::string::npos ) return false;
1014 if (!mShowWidgetsFilter->IsChecked())
1017 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1018 d->GetOutputDescriptorMap();
1019 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1020 for ( in = imap.begin(); in != imap.end(); ++in )
1022 if (in->second->GetName() == "Widget" )
1028 if (found) return false;
1030 if (mInputTypeFilter->GetValue().size()>0)
1032 std::string s = wx2std(mInputTypeFilter->GetValue());
1034 const BlackBoxDescriptor::InputDescriptorMapType& imap =
1035 d->GetInputDescriptorMap();
1036 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1037 for ( in = imap.begin(); in != imap.end(); ++in )
1039 if (in->second->GetTypeName().find(s)!=std::string::npos)
1045 if (!found) return false;
1047 if (mOutputTypeFilter->GetValue().size()>0)
1049 std::string s = wx2std(mOutputTypeFilter->GetValue());
1051 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1052 d->GetOutputDescriptorMap();
1053 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1054 for ( in = imap.begin(); in != imap.end(); ++in )
1056 if (in->second->GetTypeName().find(s)!=std::string::npos)
1062 if (!found) return false;
1064 if (mInputNatureFilter->GetValue().size()>0)
1066 std::string s = wx2std(mInputNatureFilter->GetValue());
1068 const BlackBoxDescriptor::InputDescriptorMapType& imap =
1069 d->GetInputDescriptorMap();
1070 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1071 for ( in = imap.begin(); in != imap.end(); ++in )
1073 if (in->second->GetNature().find(s)!=std::string::npos)
1079 if (!found) return false;
1081 if (mOutputNatureFilter->GetValue().size()>0)
1083 std::string s = wx2std(mOutputNatureFilter->GetValue());
1085 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1086 d->GetOutputDescriptorMap();
1087 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1088 for ( in = imap.begin(); in != imap.end(); ++in )
1090 if (in->second->GetNature().find(s)!=std::string::npos)
1096 if (!found) return false;
1101 //========================================================================
1103 //========================================================================
1104 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1105 EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1106 EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1107 EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1108 EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1109 EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1110 EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1111 EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
1112 EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
1113 EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
1114 EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
1115 EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
1117 //========================================================================
1121 //================================================================
1122 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1125 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1129 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1131 mBrowser = new WxGUIPackageBrowser2(this);
1132 mBrowser->IncludeAll();
1133 sizer->Add(mBrowser,1,wxGROW);
1135 // WxGUICommand* com = new WxGUICommand(this,this);
1140 // Creates the parent window of all bbtk windows as a child of this
1141 // Wx::CreateTopWindow(this);
1142 // Add the method OnWxSignal as a Wx::Signal observer
1143 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
1145 SetAutoLayout(true);
1148 //================================================================
1150 //================================================================
1151 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1154 //================================================================
1159 #endif //_USE_WXWIDGETS_