1 /*=========================================================================
3 Module: $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
5 Date: $Date: 2010/04/28 22:19:59 $
6 Version: $Revision: 1.20 $
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
67 BEGIN_EVENT_TABLE(WxGUIBlackBoxList, wxListCtrl)
68 EVT_LIST_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginDrag)
69 EVT_LIST_BEGIN_RDRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginRDrag)
70 EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnBeginLabelEdit)
71 EVT_LIST_END_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnEndLabelEdit)
72 EVT_LIST_DELETE_ITEM(LIST_CTRL, WxGUIBlackBoxList::OnDeleteItem)
73 EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, WxGUIBlackBoxList::OnDeleteAllItems)
74 #if WXWIN_COMPATIBILITY_2_4
75 EVT_LIST_GET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnGetInfo)
76 EVT_LIST_SET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnSetInfo)
78 EVT_LIST_ITEM_SELECTED(LIST_CTRL, WxGUIBlackBoxList::OnSelected)
79 EVT_LIST_ITEM_DESELECTED(LIST_CTRL, WxGUIBlackBoxList::OnDeselected)
80 EVT_LIST_KEY_DOWN(LIST_CTRL, WxGUIBlackBoxList::OnListKeyDown)
81 EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, WxGUIBlackBoxList::OnActivated)
82 EVT_LIST_ITEM_FOCUSED(LIST_CTRL, WxGUIBlackBoxList::OnFocused)
84 EVT_LIST_COL_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColClick)
85 EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColRightClick)
86 EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColBeginDrag)
87 EVT_LIST_COL_DRAGGING(LIST_CTRL, WxGUIBlackBoxList::OnColDragging)
88 EVT_LIST_COL_END_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColEndDrag)
90 EVT_LIST_CACHE_HINT(LIST_CTRL, WxGUIBlackBoxList::OnCacheHint)
93 EVT_CONTEXT_MENU(WxGUIBlackBoxList::OnContextMenu)
95 EVT_CHAR(WxGUIBlackBoxList::OnChar)
97 EVT_RIGHT_DOWN(WxGUIBlackBoxList::OnRightClick)
100 int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData))
112 WxGUIBlackBoxList::WxGUIBlackBoxList(wxWindow *parent,
117 : wxListCtrl(parent, id, pos, size, style),
119 m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
126 void WxGUIBlackBoxList::Insert(BlackBoxDescriptor::Pointer d)
128 if (GetColumnCount()!=3)
130 InsertColumn( 0, _("Package"),
131 wxLIST_FORMAT_LEFT, 60 );
132 InsertColumn( 1, _("Box"),
133 wxLIST_FORMAT_LEFT, 200 );
134 InsertColumn( 2, _("Description"),
135 wxLIST_FORMAT_LEFT, 500 );
139 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
141 int nID = this->GetItemCount();
143 kNewItem.SetMask(wxLIST_MASK_DATA);
144 // TO DO : STORE SMART POINTER ?
145 kNewItem.SetData(d.get());
146 // BlackBoxDescriptor::Pointer* d2 = (BlackBoxDescriptor::Pointer*)kNewItem.GetData();
147 // std::cout << "Descr = "<<d<<" = "<<d2<<std::endl;
148 this->InsertItem(kNewItem);
149 this->SetItem(nID, 0, std2wx(d->GetPackage()->GetName()) );
150 this->SetItem(nID, 1, std2wx(d->GetTypeName()) );
151 this->SetItem(nID, 2, std2wx(d->GetDescription()) );
156 kNewItem.SetBackgroundColour(wxColour(192,192,192));
157 this->SetItem(kNewItem);
164 void WxGUIBlackBoxList::OnCacheHint(wxListEvent& event)
166 //wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"),
167 // event.GetCacheFrom(), event.GetCacheTo() );
170 void WxGUIBlackBoxList::SetColumnImage(int col, int image)
174 item.SetMask(wxLIST_MASK_IMAGE);
175 item.SetImage(image);
176 SetColumn(col, item);
180 void WxGUIBlackBoxList::OnColClick(wxListEvent& event)
182 int col = event.GetColumn();
184 // set or unset image
185 static bool x = false;
187 SetColumnImage(col, x ? 0 : -1);
189 // wxLogMessage( wxT("OnColumnClick at %d."), col );
192 void WxGUIBlackBoxList::OnColRightClick(wxListEvent& event)
194 int col = event.GetColumn();
197 SetColumnImage(col, -1);
200 // Show popupmenu at position
201 wxMenu menu(wxT("Test"));
202 menu.Append(-1, _T("&About"));
203 PopupMenu(&menu, event.GetPoint());
205 //wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
208 void WxGUIBlackBoxList::LogColEvent(const wxListEvent& event, const wxChar *name)
210 // const int col = event.GetColumn();
213 wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
216 event.GetItem().GetWidth(),
217 GetColumnWidth(col));
221 void WxGUIBlackBoxList::OnColBeginDrag(wxListEvent& event)
223 LogColEvent( event, wxT("OnColBeginDrag") );
225 if ( event.GetColumn() == 0 )
227 //wxLogMessage(_T("Resizing this column shouldn't work."));
234 void WxGUIBlackBoxList::OnColDragging(wxListEvent& event)
236 LogColEvent( event, wxT("OnColDragging") );
239 void WxGUIBlackBoxList::OnColEndDrag(wxListEvent& event)
241 LogColEvent( event, wxT("OnColEndDrag") );
244 void WxGUIBlackBoxList::OnBeginDrag(wxListEvent& event)
246 std::cout<<"RaC DRAG TABLE"<<std::endl;
248 wxString text(wxT(this->GetItemText(event.GetIndex())));
250 info.m_itemId = event.m_itemIndex;
252 info.m_mask = wxLIST_MASK_DATA;
253 wxString sendtext(wxT(""));
256 // TO DO : STORE SMART PTR ?
257 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
260 sendtext += wxT(d->GetFullTypeName());
265 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
269 wxTextDataObject tdo(wxT(sendtext));
270 wxDropSource tds(tdo, this);
274 // const wxPoint& pt = event.m_pointDrag;
276 //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
277 // pt.x, pt.y, HitTest(pt, flags) );
280 void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
282 //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
283 // event.m_pointDrag.x, event.m_pointDrag.y );
286 void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
288 //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
291 void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
293 //wxLogMessage( wxT("OnEndLabelEdit: %s"),
294 // event.IsEditCancelled() ? _T("[cancelled]")
295 // : event.m_item.m_text.c_str());
298 void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
300 LogEvent(event, _T("OnDeleteItem"));
301 std::cout << "cannot del"<<std::endl;
303 //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
306 void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
308 LogEvent(event, _T("OnDeleteAllItems"));
312 #if WXWIN_COMPATIBILITY_2_4
313 void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
317 msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
318 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
319 msg << _T(" wxLIST_MASK_STATE");
320 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
321 msg << _T(" wxLIST_MASK_TEXT");
322 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
323 msg << _T(" wxLIST_MASK_IMAGE");
324 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
325 msg << _T(" wxLIST_MASK_DATA");
326 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
327 msg << _T(" wxLIST_SET_ITEM");
328 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
329 msg << _T(" wxLIST_MASK_WIDTH");
330 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
331 msg << _T(" wxLIST_MASK_WIDTH");
333 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
335 event.m_item.m_text = _T("My callback text");
341 void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
343 LogEvent(event, _T("OnSetInfo"));
347 void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
349 if (mUser==0) return;
352 info.m_itemId = event.m_itemIndex;
354 info.m_mask = wxLIST_MASK_DATA;
357 // TO DO : STORE SMART PTR ?
358 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
359 if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
363 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
367 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
369 LogEvent(event, _T("OnDeselected"));
372 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
374 LogEvent(event, _T("OnActivated"));
377 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
379 LogEvent(event, _T("OnFocused"));
384 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
388 switch ( event.GetKeyCode() )
390 case 'c': // colorize
394 info.m_itemId = event.GetIndex();
395 if ( info.m_itemId == -1 )
403 wxListItemAttr *attr = info.GetAttributes();
404 if ( !attr || !attr->HasTextColour() )
406 info.SetTextColour(*wxCYAN);
410 RefreshItem(info.m_itemId);
417 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
418 if ( item++ == GetItemCount() - 1 )
423 //wxLogMessage(_T("Focusing item %ld"), item);
425 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
429 case 'r': // show bounding Rect
432 item = event.GetIndex();
434 if ( !GetItemRect(item, r) )
436 //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
440 //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
441 // item, r.x, r.y, r.x + r.width, r.y + r.height);
446 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
452 //wxLogMessage(_T("Item %ld deleted"), item);
454 // -1 because the indices were shifted by DeleteItem()
455 item = GetNextItem(item - 1,
456 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
462 if ( GetWindowStyle() & wxLC_REPORT )
464 if ( GetWindowStyle() & wxLC_VIRTUAL )
466 SetItemCount(GetItemCount() + 1);
470 //InsertItemInReportView(event.GetIndex());
476 LogEvent(event, _T("OnListKeyDown"));
482 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
484 //wxLogMessage(_T("Got char event."));
486 switch ( event.GetKeyCode() )
492 // these are the keys we process ourselves
500 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
502 if ( !event.ControlDown() )
511 HitTest(event.GetPosition(), flags, &subitem);
516 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
517 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
518 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
519 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
520 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
521 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
522 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
523 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
524 default: where = _T("not clear exactly where on"); break;
527 //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
528 // where.c_str(), item, subitem);
531 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
533 //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
534 // event.GetIndex(), eventName,
535 // event.GetText().c_str(), event.GetData());
538 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
541 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
543 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
548 return wxString::Format(_T("Column %ld of item %ld"), column, item);
552 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
557 if (!(item %3) && column == 1)
563 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
565 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
570 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
572 wxPoint point = event.GetPosition();
574 if (point.x == -1 && point.y == -1) {
575 wxSize size = GetSize();
576 point.x = size.x / 2;
577 point.y = size.y / 2;
579 point = ScreenToClient(point);
581 ShowContextMenu(point);
585 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
589 menu.Append(wxID_ABOUT, _T("&About"));
590 menu.AppendSeparator();
591 menu.Append(wxID_EXIT, _T("E&xit"));
593 PopupMenu(&menu, pos.x, pos.y);
595 //================================================================
599 //================================================================
600 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
605 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
607 // mName = new wxStaticText(this,-1,_T(""));
608 // sizer->Add(mName,0,wxGROW);
609 mDescription = new wxStaticText(this,-1,_T(""));
610 sizer->Add(mDescription,0,wxGROW);
611 mAuthor = new wxStaticText(this,-1,_T(""));
612 sizer->Add(mAuthor,0,wxGROW);
613 mCategory = new wxStaticText(this,-1,_T(""));
614 sizer->Add(mCategory,0,wxGROW);
618 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
619 mInputList = new wxListCtrl(this, -1,
622 wxLC_REPORT //wxLC_LIST
625 inputs->Add(mInputList,1,wxGROW);
626 sizer->Add(inputs,1,wxGROW);
628 wxBoxSizer *outputs =
630 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
631 mOutputList = new wxListCtrl(this, -1,
634 wxLC_REPORT //wxLC_LIST
637 outputs->Add(mOutputList,1,wxGROW);
638 sizer->Add(outputs,1,wxGROW);
644 //================================================================
647 //================================================================
648 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
651 // mName->SetLabel(std2wx(descr->GetTypeName()));
652 mDescription->SetLabel(std2wx(descr->GetDescription()));
653 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
654 mCategory->SetLabel(std2wx(descr->GetCategory()));
656 mInputList->ClearAll();
657 mInputList->InsertColumn( 0, _("Name"),
658 wxLIST_FORMAT_LEFT, 80 );
659 mInputList->InsertColumn( 1, _("Type"),
660 wxLIST_FORMAT_LEFT, 100 );
661 mInputList->InsertColumn( 2, _("Nature"),
662 wxLIST_FORMAT_LEFT, 100 );
663 mInputList->InsertColumn( 3, _("Description"),
664 wxLIST_FORMAT_LEFT, 500 );
666 mOutputList->ClearAll();
667 mOutputList->InsertColumn( 0, _("Name"),
668 wxLIST_FORMAT_LEFT, 80 );
669 mOutputList->InsertColumn( 1, _("Type"),
670 wxLIST_FORMAT_LEFT, 100 );
671 mOutputList->InsertColumn( 2, _("Nature"),
672 wxLIST_FORMAT_LEFT, 100 );
673 mOutputList->InsertColumn( 3, _("Description"),
674 wxLIST_FORMAT_LEFT, 500 );
677 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
678 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
679 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
681 const BlackBoxDescriptor::InputDescriptorMapType& imap =
682 descr->GetInputDescriptorMap();
683 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
684 for ( in = imap.begin(); in != imap.end(); ++in )
687 if (in->second->GetCreatorTypeInfo() ==
688 typeid(AtomicBlackBoxDescriptor))
692 else if (in->second->GetCreatorTypeInfo() ==
693 typeid(WxBlackBoxDescriptor))
697 if (iotype==0) user_defined.push_back(in->second);
698 else if (iotype==1) ubb_defined.push_back(in->second);
699 else if (iotype==2) wxbb_defined.push_back(in->second);
703 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
704 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
706 InsertInputOutput(mInputList,*hi);
708 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
710 InsertInputOutput(mInputList,*hi);
712 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
714 InsertInputOutput(mInputList,*hi);
718 user_defined.clear();
720 wxbb_defined.clear();
721 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
722 descr->GetOutputDescriptorMap();
723 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
724 for ( out = omap.begin(); out != omap.end(); ++out )
727 if (out->second->GetCreatorTypeInfo() ==
728 typeid(AtomicBlackBoxDescriptor))
732 else if (out->second->GetCreatorTypeInfo() ==
733 typeid(WxBlackBoxDescriptor))
738 if (iotype==0) user_defined.push_back(out->second);
739 else if (iotype==1) ubb_defined.push_back(out->second);
740 else if (iotype==2) wxbb_defined.push_back(out->second);
743 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
745 InsertInputOutput(mOutputList,*hi);
747 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
749 InsertInputOutput(mOutputList,*hi);
751 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
753 InsertInputOutput(mOutputList,*hi);
756 //================================================================
759 //================================================================
760 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
761 BlackBoxInputOutputDescriptor* d)
764 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
765 int nID = l->GetItemCount();
766 // std::cout << nID << std::endl;
768 // kNewItem.SetMask(wxLIST_MASK_DATA);
769 // kNewItem.SetData(d);
770 l->InsertItem(kNewItem);
771 l->SetItem(nID, 0, std2wx(d->GetName()) );
772 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
773 l->SetItem(nID, 2, std2wx(d->GetNature()) );
774 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
776 //================================================================
778 //================================================================
779 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
782 //================================================================
800 //================================================================
801 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
802 WxGUIPackageBrowser2User* user )
803 : wxPanel(parent, -1),
807 m_mgr.SetManagedWindow(this);
809 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
810 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
813 wxLC_REPORT //wxLC_LIST
815 mBoxList->SetUser(this);
816 mBoxList->SetBackgroundColour(*wxWHITE);
818 m_mgr.AddPane(mBoxList,
819 wxAuiPaneInfo().Name(wxT("BoxList"))
820 .Caption(wxT("Black Boxes"))
821 .MinimizeButton(true)
822 .MaximizeButton(true)
824 .MinSize(wxSize(100,100))
826 // sizer->Add(mBoxList,5,wxGROW);
828 mBoxInfo = new WxGUIBlackBoxInfo(this);
829 // sizer->Add(mBoxInfo,3,wxGROW);
831 m_mgr.AddPane(mBoxInfo,
832 wxAuiPaneInfo().Name(wxT("Box"))
834 .MinimizeButton(true)
835 .MaximizeButton(true)
837 .MinSize(wxSize(100,300))
840 wxPanel* filters = new wxPanel(this,-1);
841 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
844 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
845 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
849 fpack->Add(mPackageFilter,1,wxGROW);
850 fsizer->Add(fpack,0,wxGROW);
853 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
854 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
858 fname->Add(mNameFilter,1,wxGROW);
859 fsizer->Add(fname,0,wxGROW);
862 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
863 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
867 fdescr->Add(mDescriptionFilter,1,wxGROW);
868 fsizer->Add(fdescr,0,wxGROW);
871 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
872 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
876 fcat->Add(mCategoryFilter,1,wxGROW);
877 fsizer->Add(fcat,0,wxGROW);
878 wxBoxSizer *fintype =
880 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
881 mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
885 fintype->Add(mInputTypeFilter,1,wxGROW);
886 fsizer->Add(fintype,0,wxGROW);
887 wxBoxSizer *fouttype =
889 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
890 mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
894 fouttype->Add(mOutputTypeFilter,1,wxGROW);
895 fsizer->Add(fouttype,0,wxGROW);
898 ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL );
899 mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
903 finnat->Add(mInputNatureFilter,1,wxGROW);
904 fsizer->Add(finnat,0,wxGROW);
905 wxBoxSizer *foutnat =
907 ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL );
908 mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
912 foutnat->Add(mOutputNatureFilter,1,wxGROW);
913 fsizer->Add(foutnat,0,wxGROW);
915 mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
916 mShowWidgetsFilter->SetValue(true);
917 fsizer->Add(mShowWidgetsFilter,0,wxGROW);
919 mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
920 mShowAdaptorsFilter->SetValue(false);
921 fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
923 mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
924 mShowGUIsFilter->SetValue(false);
925 fsizer->Add(mShowGUIsFilter,0,wxGROW);
927 filters->SetSizer(fsizer);
929 m_mgr.AddPane(filters,
930 wxAuiPaneInfo().Name(wxT("Filter"))
931 .Caption(wxT("Filter"))
932 .MinimizeButton(true)
933 .MaximizeButton(true)
935 .MinSize(wxSize(100,100)) );
937 // sizer->Add(fsizer,1,wxGROW);
945 //================================================================
947 //================================================================
948 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
952 //================================================================
954 //================================================================
955 // User callback when a box is selected in the list
956 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
957 ( BlackBoxDescriptor* d)
962 mBoxInfo->UpdateInfo(d);
963 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
964 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
968 //================================================================
970 //================================================================
971 BlackBoxDescriptor* WxGUIPackageBrowser2::GetActualSelected()
973 return _actualSelected;
976 //================================================================
978 //================================================================
979 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
982 mInterpreter.reset();
983 // Object::PrintObjectListInfo("");
986 //================================================================
988 //================================================================
989 void WxGUIPackageBrowser2::IncludeAll()
991 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
992 mInterpreter->SetCommandLine(true);
993 std::stringstream* buf = new std::stringstream;
994 *buf << "exec freeze_no_error" << std::endl;
995 *buf << "message max 0" << std::endl;
996 *buf << "include *" << std::endl;
997 mInterpreter->InterpretBuffer(buf);
999 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
1000 BuildFromFactory(F);
1002 //================================================================
1004 //================================================================
1005 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
1011 //================================================================
1013 //================================================================
1014 void WxGUIPackageBrowser2::RebuildList()
1017 mBoxList->ClearAll();
1019 const Factory::PackageMapType& M = mFactory->GetPackageMap();
1020 Factory::PackageMapType::const_iterator i;
1021 for (i=M.begin();i!=M.end();++i)
1023 Package::Pointer P = i->second;
1024 if (P->GetName() == "user") continue;
1026 Package::DescriptorMapType::iterator j;
1027 for (j=P->GetDescriptorMap().begin();
1028 j!=P->GetDescriptorMap().end();
1031 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
1032 if (IsVisible(j->second))
1033 mBoxList->Insert(j->second);
1038 //================================================================
1040 //================================================================
1041 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
1043 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
1044 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
1045 if ((!mShowAdaptorsFilter->IsChecked())&&
1046 ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
1047 (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
1049 if ((!mShowGUIsFilter->IsChecked())&&
1050 ((d->GetKind()==BlackBoxDescriptor::GUI)||
1051 (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
1053 if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) )
1054 == std::string::npos ) return false;
1055 if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) )
1056 == std::string::npos ) return false;
1057 if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) )
1058 == std::string::npos ) return false;
1059 if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) )
1060 == std::string::npos ) return false;
1061 if (!mShowWidgetsFilter->IsChecked())
1064 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1065 d->GetOutputDescriptorMap();
1066 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1067 for ( in = imap.begin(); in != imap.end(); ++in )
1069 if (in->second->GetName() == "Widget" )
1075 if (found) return false;
1077 if (mInputTypeFilter->GetValue().size()>0)
1079 std::string s = wx2std(mInputTypeFilter->GetValue());
1081 const BlackBoxDescriptor::InputDescriptorMapType& imap =
1082 d->GetInputDescriptorMap();
1083 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1084 for ( in = imap.begin(); in != imap.end(); ++in )
1086 if (in->second->GetTypeName().find(s)!=std::string::npos)
1092 if (!found) return false;
1094 if (mOutputTypeFilter->GetValue().size()>0)
1096 std::string s = wx2std(mOutputTypeFilter->GetValue());
1098 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1099 d->GetOutputDescriptorMap();
1100 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1101 for ( in = imap.begin(); in != imap.end(); ++in )
1103 if (in->second->GetTypeName().find(s)!=std::string::npos)
1109 if (!found) return false;
1111 if (mInputNatureFilter->GetValue().size()>0)
1113 std::string s = wx2std(mInputNatureFilter->GetValue());
1115 const BlackBoxDescriptor::InputDescriptorMapType& imap =
1116 d->GetInputDescriptorMap();
1117 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1118 for ( in = imap.begin(); in != imap.end(); ++in )
1120 if (in->second->GetNature().find(s)!=std::string::npos)
1126 if (!found) return false;
1128 if (mOutputNatureFilter->GetValue().size()>0)
1130 std::string s = wx2std(mOutputNatureFilter->GetValue());
1132 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1133 d->GetOutputDescriptorMap();
1134 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1135 for ( in = imap.begin(); in != imap.end(); ++in )
1137 if (in->second->GetNature().find(s)!=std::string::npos)
1143 if (!found) return false;
1147 //========================================================================
1149 //========================================================================
1150 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1151 EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1152 EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1153 EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1154 EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1155 EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1156 EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1157 EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
1158 EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
1159 EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
1160 EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
1161 EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
1163 //========================================================================
1167 //================================================================
1168 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1171 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1173 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1175 mBrowser = new WxGUIPackageBrowser2(this);
1176 mBrowser->IncludeAll();
1177 sizer->Add(mBrowser,1,wxGROW);
1179 // WxGUICommand* com = new WxGUICommand(this,this);
1184 // Creates the parent window of all bbtk windows as a child of this
1185 // Wx::CreateTopWindow(this);
1186 // Add the method OnWxSignal as a Wx::Signal observer
1187 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
1189 SetAutoLayout(true);
1192 //================================================================
1194 //================================================================
1195 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1198 //================================================================
1203 #endif //_USE_WXWIDGETS_