1 /*=========================================================================
3 Module: $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
5 Date: $Date: 2009/06/08 14:50:04 $
6 Version: $Revision: 1.13 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
32 /* \brief Short description in one line
34 * Long description which
35 * can span multiple lines
48 #ifdef _USE_WXWIDGETS_
50 #define CHECKBOXVIEW 1
52 #include "bbtkWxGUIPackageBrowser2.h"
53 //#include "ThirdParty/wx/treemultictrl/wxTreeMultiCtrl.h"
54 #include "bbtkInterpreter.h"
55 #include "bbtkBlackBoxInputDescriptor.h"
56 #include "bbtkBlackBoxOutputDescriptor.h"
57 #include "bbtkWxBlackBox.h"
58 //#include "wx/grid.h"
59 //#include <wx/statline.h>
61 #define LIST_CTRL 1000
68 BEGIN_EVENT_TABLE(WxGUIBlackBoxList, wxListCtrl)
69 EVT_LIST_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginDrag)
70 EVT_LIST_BEGIN_RDRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginRDrag)
71 EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnBeginLabelEdit)
72 EVT_LIST_END_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnEndLabelEdit)
73 EVT_LIST_DELETE_ITEM(LIST_CTRL, WxGUIBlackBoxList::OnDeleteItem)
74 EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, WxGUIBlackBoxList::OnDeleteAllItems)
75 #if WXWIN_COMPATIBILITY_2_4
76 EVT_LIST_GET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnGetInfo)
77 EVT_LIST_SET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnSetInfo)
79 EVT_LIST_ITEM_SELECTED(LIST_CTRL, WxGUIBlackBoxList::OnSelected)
80 EVT_LIST_ITEM_DESELECTED(LIST_CTRL, WxGUIBlackBoxList::OnDeselected)
81 EVT_LIST_KEY_DOWN(LIST_CTRL, WxGUIBlackBoxList::OnListKeyDown)
82 EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, WxGUIBlackBoxList::OnActivated)
83 EVT_LIST_ITEM_FOCUSED(LIST_CTRL, WxGUIBlackBoxList::OnFocused)
85 EVT_LIST_COL_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColClick)
86 EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColRightClick)
87 EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColBeginDrag)
88 EVT_LIST_COL_DRAGGING(LIST_CTRL, WxGUIBlackBoxList::OnColDragging)
89 EVT_LIST_COL_END_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColEndDrag)
91 EVT_LIST_CACHE_HINT(LIST_CTRL, WxGUIBlackBoxList::OnCacheHint)
94 EVT_CONTEXT_MENU(WxGUIBlackBoxList::OnContextMenu)
96 EVT_CHAR(WxGUIBlackBoxList::OnChar)
98 EVT_RIGHT_DOWN(WxGUIBlackBoxList::OnRightClick)
101 int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData))
113 WxGUIBlackBoxList::WxGUIBlackBoxList(wxWindow *parent,
118 : wxListCtrl(parent, id, pos, size, style),
120 m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
127 void WxGUIBlackBoxList::Insert(BlackBoxDescriptor::Pointer d)
129 if (GetColumnCount()!=3)
131 InsertColumn( 0, _("Package"),
132 wxLIST_FORMAT_LEFT, 60 );
133 InsertColumn( 1, _("Box"),
134 wxLIST_FORMAT_LEFT, 200 );
135 InsertColumn( 2, _("Description"),
136 wxLIST_FORMAT_LEFT, 500 );
140 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
142 int nID = this->GetItemCount();
144 kNewItem.SetMask(wxLIST_MASK_DATA);
145 // TO DO : STORE SMART POINTER ?
146 kNewItem.SetData(d.get());
147 // BlackBoxDescriptor::Pointer* d2 = (BlackBoxDescriptor::Pointer*)kNewItem.GetData();
148 // std::cout << "Descr = "<<d<<" = "<<d2<<std::endl;
149 this->InsertItem(kNewItem);
150 this->SetItem(nID, 0, std2wx(d->GetPackage()->GetName()) );
151 this->SetItem(nID, 1, std2wx(d->GetTypeName()) );
152 this->SetItem(nID, 2, std2wx(d->GetDescription()) );
157 kNewItem.SetBackgroundColour(wxColour(192,192,192));
158 this->SetItem(kNewItem);
165 void WxGUIBlackBoxList::OnCacheHint(wxListEvent& event)
167 //wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"),
168 // event.GetCacheFrom(), event.GetCacheTo() );
171 void WxGUIBlackBoxList::SetColumnImage(int col, int image)
175 item.SetMask(wxLIST_MASK_IMAGE);
176 item.SetImage(image);
177 SetColumn(col, item);
181 void WxGUIBlackBoxList::OnColClick(wxListEvent& event)
183 int col = event.GetColumn();
185 // set or unset image
186 static bool x = false;
188 SetColumnImage(col, x ? 0 : -1);
190 // wxLogMessage( wxT("OnColumnClick at %d."), col );
193 void WxGUIBlackBoxList::OnColRightClick(wxListEvent& event)
195 int col = event.GetColumn();
198 SetColumnImage(col, -1);
201 // Show popupmenu at position
202 wxMenu menu(wxT("Test"));
203 menu.Append(-1, _T("&About"));
204 PopupMenu(&menu, event.GetPoint());
206 //wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
209 void WxGUIBlackBoxList::LogColEvent(const wxListEvent& event, const wxChar *name)
211 // const int col = event.GetColumn();
214 wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
217 event.GetItem().GetWidth(),
218 GetColumnWidth(col));
222 void WxGUIBlackBoxList::OnColBeginDrag(wxListEvent& event)
224 LogColEvent( event, wxT("OnColBeginDrag") );
226 if ( event.GetColumn() == 0 )
228 //wxLogMessage(_T("Resizing this column shouldn't work."));
235 void WxGUIBlackBoxList::OnColDragging(wxListEvent& event)
237 LogColEvent( event, wxT("OnColDragging") );
240 void WxGUIBlackBoxList::OnColEndDrag(wxListEvent& event)
242 LogColEvent( event, wxT("OnColEndDrag") );
245 void WxGUIBlackBoxList::OnBeginDrag(wxListEvent& event)
247 // const wxPoint& pt = event.m_pointDrag;
249 //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
250 // pt.x, pt.y, HitTest(pt, flags) );
253 void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
255 //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
256 // event.m_pointDrag.x, event.m_pointDrag.y );
259 void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
261 //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
264 void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
266 //wxLogMessage( wxT("OnEndLabelEdit: %s"),
267 // event.IsEditCancelled() ? _T("[cancelled]")
268 // : event.m_item.m_text.c_str());
271 void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
273 LogEvent(event, _T("OnDeleteItem"));
274 std::cout << "cannot del"<<std::endl;
276 //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
279 void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
281 LogEvent(event, _T("OnDeleteAllItems"));
285 #if WXWIN_COMPATIBILITY_2_4
286 void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
290 msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
291 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
292 msg << _T(" wxLIST_MASK_STATE");
293 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
294 msg << _T(" wxLIST_MASK_TEXT");
295 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
296 msg << _T(" wxLIST_MASK_IMAGE");
297 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
298 msg << _T(" wxLIST_MASK_DATA");
299 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
300 msg << _T(" wxLIST_SET_ITEM");
301 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
302 msg << _T(" wxLIST_MASK_WIDTH");
303 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
304 msg << _T(" wxLIST_MASK_WIDTH");
306 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
308 event.m_item.m_text = _T("My callback text");
314 void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
316 LogEvent(event, _T("OnSetInfo"));
320 void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
322 if (mUser==0) return;
325 info.m_itemId = event.m_itemIndex;
327 info.m_mask = wxLIST_MASK_DATA;
330 // TO DO : STORE SMART PTR ?
331 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
332 if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
336 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
340 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
342 LogEvent(event, _T("OnDeselected"));
345 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
347 LogEvent(event, _T("OnActivated"));
350 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
352 LogEvent(event, _T("OnFocused"));
357 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
361 switch ( event.GetKeyCode() )
363 case 'c': // colorize
367 info.m_itemId = event.GetIndex();
368 if ( info.m_itemId == -1 )
376 wxListItemAttr *attr = info.GetAttributes();
377 if ( !attr || !attr->HasTextColour() )
379 info.SetTextColour(*wxCYAN);
383 RefreshItem(info.m_itemId);
390 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
391 if ( item++ == GetItemCount() - 1 )
396 //wxLogMessage(_T("Focusing item %ld"), item);
398 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
402 case 'r': // show bounding Rect
405 item = event.GetIndex();
407 if ( !GetItemRect(item, r) )
409 //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
413 //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
414 // item, r.x, r.y, r.x + r.width, r.y + r.height);
419 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
425 //wxLogMessage(_T("Item %ld deleted"), item);
427 // -1 because the indices were shifted by DeleteItem()
428 item = GetNextItem(item - 1,
429 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
435 if ( GetWindowStyle() & wxLC_REPORT )
437 if ( GetWindowStyle() & wxLC_VIRTUAL )
439 SetItemCount(GetItemCount() + 1);
443 //InsertItemInReportView(event.GetIndex());
449 LogEvent(event, _T("OnListKeyDown"));
455 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
457 //wxLogMessage(_T("Got char event."));
459 switch ( event.GetKeyCode() )
465 // these are the keys we process ourselves
473 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
475 if ( !event.ControlDown() )
484 HitTest(event.GetPosition(), flags, &subitem);
489 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
490 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
491 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
492 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
493 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
494 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
495 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
496 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
497 default: where = _T("not clear exactly where on"); break;
500 //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
501 // where.c_str(), item, subitem);
504 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
506 //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
507 // event.GetIndex(), eventName,
508 // event.GetText().c_str(), event.GetData());
511 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
514 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
516 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
521 return wxString::Format(_T("Column %ld of item %ld"), column, item);
525 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
530 if (!(item %3) && column == 1)
536 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
538 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
543 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
545 wxPoint point = event.GetPosition();
547 if (point.x == -1 && point.y == -1) {
548 wxSize size = GetSize();
549 point.x = size.x / 2;
550 point.y = size.y / 2;
552 point = ScreenToClient(point);
554 ShowContextMenu(point);
558 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
562 menu.Append(wxID_ABOUT, _T("&About"));
563 menu.AppendSeparator();
564 menu.Append(wxID_EXIT, _T("E&xit"));
566 PopupMenu(&menu, pos.x, pos.y);
568 //================================================================
572 //================================================================
573 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
578 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
580 // mName = new wxStaticText(this,-1,_T(""));
581 // sizer->Add(mName,0,wxGROW);
582 mDescription = new wxStaticText(this,-1,_T(""));
583 sizer->Add(mDescription,0,wxGROW);
584 mAuthor = new wxStaticText(this,-1,_T(""));
585 sizer->Add(mAuthor,0,wxGROW);
586 mCategory = new wxStaticText(this,-1,_T(""));
587 sizer->Add(mCategory,0,wxGROW);
592 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
593 mInputList = new wxListCtrl(this, -1,
596 wxLC_REPORT //wxLC_LIST
600 inputs->Add(mInputList,1,wxGROW);
601 sizer->Add(inputs,1,wxGROW);
603 wxBoxSizer *outputs =
605 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
606 mOutputList = new wxListCtrl(this, -1,
609 wxLC_REPORT //wxLC_LIST
612 outputs->Add(mOutputList,1,wxGROW);
613 sizer->Add(outputs,1,wxGROW);
620 //================================================================
623 //================================================================
624 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
627 // mName->SetLabel(std2wx(descr->GetTypeName()));
628 mDescription->SetLabel(std2wx(descr->GetDescription()));
629 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
630 mCategory->SetLabel(std2wx(descr->GetCategory()));
632 mInputList->ClearAll();
633 mInputList->InsertColumn( 0, _("Name"),
634 wxLIST_FORMAT_LEFT, 80 );
635 mInputList->InsertColumn( 1, _("Type"),
636 wxLIST_FORMAT_LEFT, 100 );
637 mInputList->InsertColumn( 2, _("Nature"),
638 wxLIST_FORMAT_LEFT, 100 );
639 mInputList->InsertColumn( 3, _("Description"),
640 wxLIST_FORMAT_LEFT, 500 );
642 mOutputList->ClearAll();
643 mOutputList->InsertColumn( 0, _("Name"),
644 wxLIST_FORMAT_LEFT, 80 );
645 mOutputList->InsertColumn( 1, _("Type"),
646 wxLIST_FORMAT_LEFT, 100 );
647 mOutputList->InsertColumn( 2, _("Nature"),
648 wxLIST_FORMAT_LEFT, 100 );
649 mOutputList->InsertColumn( 3, _("Description"),
650 wxLIST_FORMAT_LEFT, 500 );
653 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
654 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
655 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
657 const BlackBoxDescriptor::InputDescriptorMapType& imap =
658 descr->GetInputDescriptorMap();
659 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
660 for ( in = imap.begin(); in != imap.end(); ++in )
663 if (in->second->GetCreatorTypeInfo() ==
664 typeid(AtomicBlackBoxDescriptor))
668 else if (in->second->GetCreatorTypeInfo() ==
669 typeid(WxBlackBoxDescriptor))
673 if (iotype==0) user_defined.push_back(in->second);
674 else if (iotype==1) ubb_defined.push_back(in->second);
675 else if (iotype==2) wxbb_defined.push_back(in->second);
679 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
680 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
682 InsertInputOutput(mInputList,*hi);
684 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
686 InsertInputOutput(mInputList,*hi);
688 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
690 InsertInputOutput(mInputList,*hi);
694 user_defined.clear();
696 wxbb_defined.clear();
697 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
698 descr->GetOutputDescriptorMap();
699 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
700 for ( out = omap.begin(); out != omap.end(); ++out )
703 if (out->second->GetCreatorTypeInfo() ==
704 typeid(AtomicBlackBoxDescriptor))
708 else if (out->second->GetCreatorTypeInfo() ==
709 typeid(WxBlackBoxDescriptor))
714 if (iotype==0) user_defined.push_back(out->second);
715 else if (iotype==1) ubb_defined.push_back(out->second);
716 else if (iotype==2) wxbb_defined.push_back(out->second);
719 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
721 InsertInputOutput(mOutputList,*hi);
723 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
725 InsertInputOutput(mOutputList,*hi);
727 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
729 InsertInputOutput(mOutputList,*hi);
732 //================================================================
735 //================================================================
736 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
737 BlackBoxInputOutputDescriptor* d)
740 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
741 int nID = l->GetItemCount();
742 // std::cout << nID << std::endl;
744 // kNewItem.SetMask(wxLIST_MASK_DATA);
745 // kNewItem.SetData(d);
746 l->InsertItem(kNewItem);
747 l->SetItem(nID, 0, std2wx(d->GetName()) );
748 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
749 l->SetItem(nID, 2, std2wx(d->GetNature()) );
750 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
752 //================================================================
754 //================================================================
755 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
758 //================================================================
777 //================================================================
778 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
779 WxGUIPackageBrowser2User* user )
780 : wxPanel(parent, -1),
784 m_mgr.SetManagedWindow(this);
786 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
787 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
790 wxLC_REPORT //wxLC_LIST
792 mBoxList->SetUser(this);
793 mBoxList->SetBackgroundColour(*wxWHITE);
795 m_mgr.AddPane(mBoxList,
796 wxAuiPaneInfo().Name(wxT("BoxList"))
797 .Caption(wxT("Black Boxes"))
798 .MinimizeButton(true)
799 .MaximizeButton(true)
801 .MinSize(wxSize(100,100))
803 // sizer->Add(mBoxList,5,wxGROW);
805 mBoxInfo = new WxGUIBlackBoxInfo(this);
806 // sizer->Add(mBoxInfo,3,wxGROW);
808 m_mgr.AddPane(mBoxInfo,
809 wxAuiPaneInfo().Name(wxT("Box"))
811 .MinimizeButton(true)
812 .MaximizeButton(true)
814 .MinSize(wxSize(100,300))
818 wxPanel* filters = new wxPanel(this,-1);
819 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
822 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
823 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
827 fpack->Add(mPackageFilter,1,wxGROW);
828 fsizer->Add(fpack,0,wxGROW);
831 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
832 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
836 fname->Add(mNameFilter,1,wxGROW);
837 fsizer->Add(fname,0,wxGROW);
840 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
841 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
845 fdescr->Add(mDescriptionFilter,1,wxGROW);
846 fsizer->Add(fdescr,0,wxGROW);
849 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
850 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
854 fcat->Add(mCategoryFilter,1,wxGROW);
855 fsizer->Add(fcat,0,wxGROW);
856 wxBoxSizer *fintype =
858 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
859 mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
863 fintype->Add(mInputTypeFilter,1,wxGROW);
864 fsizer->Add(fintype,0,wxGROW);
865 wxBoxSizer *fouttype =
867 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
868 mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
872 fouttype->Add(mOutputTypeFilter,1,wxGROW);
873 fsizer->Add(fouttype,0,wxGROW);
876 ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL );
877 mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
881 finnat->Add(mInputNatureFilter,1,wxGROW);
882 fsizer->Add(finnat,0,wxGROW);
883 wxBoxSizer *foutnat =
885 ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL );
886 mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
890 foutnat->Add(mOutputNatureFilter,1,wxGROW);
891 fsizer->Add(foutnat,0,wxGROW);
894 mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
895 mShowWidgetsFilter->SetValue(true);
896 fsizer->Add(mShowWidgetsFilter,0,wxGROW);
898 mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
899 mShowAdaptorsFilter->SetValue(false);
900 fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
902 mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
903 mShowGUIsFilter->SetValue(false);
904 fsizer->Add(mShowGUIsFilter,0,wxGROW);
906 filters->SetSizer(fsizer);
908 m_mgr.AddPane(filters,
909 wxAuiPaneInfo().Name(wxT("Filter"))
910 .Caption(wxT("Filter"))
911 .MinimizeButton(true)
912 .MaximizeButton(true)
914 .MinSize(wxSize(100,100)) );
918 // sizer->Add(fsizer,1,wxGROW);
926 //================================================================
928 //================================================================
929 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
933 //================================================================
935 //================================================================
936 // User callback when a box is selected in the list
937 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
938 ( BlackBoxDescriptor* d)
940 mBoxInfo->UpdateInfo(d);
941 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
942 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
946 //================================================================
948 //================================================================
949 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
952 mInterpreter.reset();
953 // Object::PrintObjectListInfo("");
956 //================================================================
958 //================================================================
959 void WxGUIPackageBrowser2::IncludeAll()
961 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
962 mInterpreter->SetCommandLine(true);
963 std::stringstream* buf = new std::stringstream;
964 *buf << "exec freeze_no_error" << std::endl;
965 *buf << "message max 0" << std::endl;
966 *buf << "include *" << std::endl;
967 mInterpreter->InterpretBuffer(buf);
969 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
972 //================================================================
974 //================================================================
975 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
980 //================================================================
982 //================================================================
983 void WxGUIPackageBrowser2::RebuildList()
986 mBoxList->ClearAll();
988 const Factory::PackageMapType& M = mFactory->GetPackageMap();
989 Factory::PackageMapType::const_iterator i;
990 for (i=M.begin();i!=M.end();++i)
992 Package::Pointer P = i->second;
993 if (P->GetName() == "user") continue;
995 Package::DescriptorMapType::iterator j;
996 for (j=P->GetDescriptorMap().begin();
997 j!=P->GetDescriptorMap().end();
1000 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
1001 if (IsVisible(j->second))
1002 mBoxList->Insert(j->second);
1007 //================================================================
1009 //================================================================
1010 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
1012 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
1013 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
1014 if ((!mShowAdaptorsFilter->IsChecked())&&
1015 ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
1016 (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
1018 if ((!mShowGUIsFilter->IsChecked())&&
1019 ((d->GetKind()==BlackBoxDescriptor::GUI)||
1020 (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
1022 if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) )
1023 == std::string::npos ) return false;
1024 if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) )
1025 == std::string::npos ) return false;
1026 if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) )
1027 == std::string::npos ) return false;
1028 if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) )
1029 == std::string::npos ) return false;
1030 if (!mShowWidgetsFilter->IsChecked())
1033 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1034 d->GetOutputDescriptorMap();
1035 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1036 for ( in = imap.begin(); in != imap.end(); ++in )
1038 if (in->second->GetName() == "Widget" )
1044 if (found) return false;
1046 if (mInputTypeFilter->GetValue().size()>0)
1048 std::string s = wx2std(mInputTypeFilter->GetValue());
1050 const BlackBoxDescriptor::InputDescriptorMapType& imap =
1051 d->GetInputDescriptorMap();
1052 BlackBoxDescriptor::InputDescriptorMapType::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 (mOutputTypeFilter->GetValue().size()>0)
1065 std::string s = wx2std(mOutputTypeFilter->GetValue());
1067 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1068 d->GetOutputDescriptorMap();
1069 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1070 for ( in = imap.begin(); in != imap.end(); ++in )
1072 if (in->second->GetTypeName().find(s)!=std::string::npos)
1078 if (!found) return false;
1080 if (mInputNatureFilter->GetValue().size()>0)
1082 std::string s = wx2std(mInputNatureFilter->GetValue());
1084 const BlackBoxDescriptor::InputDescriptorMapType& imap =
1085 d->GetInputDescriptorMap();
1086 BlackBoxDescriptor::InputDescriptorMapType::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;
1097 if (mOutputNatureFilter->GetValue().size()>0)
1099 std::string s = wx2std(mOutputNatureFilter->GetValue());
1101 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1102 d->GetOutputDescriptorMap();
1103 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1104 for ( in = imap.begin(); in != imap.end(); ++in )
1106 if (in->second->GetNature().find(s)!=std::string::npos)
1112 if (!found) return false;
1117 //========================================================================
1119 //========================================================================
1120 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1121 EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1122 EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1123 EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1124 EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1125 EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1126 EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1127 EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
1128 EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
1129 EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
1130 EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
1131 EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
1133 //========================================================================
1137 //================================================================
1138 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1141 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1145 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1147 mBrowser = new WxGUIPackageBrowser2(this);
1148 mBrowser->IncludeAll();
1149 sizer->Add(mBrowser,1,wxGROW);
1151 // WxGUICommand* com = new WxGUICommand(this,this);
1156 // Creates the parent window of all bbtk windows as a child of this
1157 // Wx::CreateTopWindow(this);
1158 // Add the method OnWxSignal as a Wx::Signal observer
1159 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
1161 SetAutoLayout(true);
1164 //================================================================
1166 //================================================================
1167 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1170 //================================================================
1175 #endif //_USE_WXWIDGETS_