1 /*=========================================================================
3 Module: $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
5 Date: $Date: 2012/05/23 13:59:56 $
6 Version: $Revision: 1.25 $
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 * ------------------------------------------------------------------------ */
31 /* \brief Short description in one line
33 * Long description which
34 * can span multiple lines
47 #ifdef _USE_WXWIDGETS_
49 #define CHECKBOXVIEW 1
51 #include "bbtkWxGUIPackageBrowser2.h"
52 //#include "ThirdParty/wx/treemultictrl/wxTreeMultiCtrl.h"
53 #include "bbtkInterpreter.h"
54 #include "bbtkBlackBoxInputDescriptor.h"
55 #include "bbtkBlackBoxOutputDescriptor.h"
56 #include "bbtkWxBlackBox.h"
57 //#include "wx/grid.h"
58 //#include <wx/statline.h>
62 #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);
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(this->GetItemText(event.GetIndex()));
250 info.m_itemId = event.m_itemIndex;
252 info.m_mask = wxLIST_MASK_DATA;
253 wxString sendtext(_T(""));
256 // TO DO : STORE SMART PTR ?
257 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
260 sendtext += crea::std2wx(d->GetFullTypeName());
265 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
268 wxTextDataObject tdo(sendtext);
269 wxDropSource tds(tdo, this);
272 // const wxPoint& pt = event.m_pointDrag;
274 //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
275 // pt.x, pt.y, HitTest(pt, flags) );
278 void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
280 //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
281 // event.m_pointDrag.x, event.m_pointDrag.y );
284 void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
286 //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
289 void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
291 //wxLogMessage( wxT("OnEndLabelEdit: %s"),
292 // event.IsEditCancelled() ? _T("[cancelled]")
293 // : event.m_item.m_text.c_str());
296 void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
298 LogEvent(event, _T("OnDeleteItem"));
299 std::cout << "cannot del"<<std::endl;
301 //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
304 void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
306 LogEvent(event, _T("OnDeleteAllItems"));
310 #if WXWIN_COMPATIBILITY_2_4
311 void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
315 msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
316 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
317 msg << _T(" wxLIST_MASK_STATE");
318 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
319 msg << _T(" wxLIST_MASK_TEXT");
320 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
321 msg << _T(" wxLIST_MASK_IMAGE");
322 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
323 msg << _T(" wxLIST_MASK_DATA");
324 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
325 msg << _T(" wxLIST_SET_ITEM");
326 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
327 msg << _T(" wxLIST_MASK_WIDTH");
328 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
329 msg << _T(" wxLIST_MASK_WIDTH");
331 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
333 event.m_item.m_text = _T("My callback text");
339 void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
341 LogEvent(event, _T("OnSetInfo"));
345 void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
347 if (mUser==0) return;
350 info.m_itemId = event.m_itemIndex;
352 info.m_mask = wxLIST_MASK_DATA;
355 // TO DO : STORE SMART PTR ?
356 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
357 if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
361 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
365 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
367 LogEvent(event, _T("OnDeselected"));
370 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
372 LogEvent(event, _T("OnActivated"));
375 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
377 LogEvent(event, _T("OnFocused"));
382 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
386 switch ( event.GetKeyCode() )
388 case 'c': // colorize
392 info.m_itemId = event.GetIndex();
393 if ( info.m_itemId == -1 )
401 wxListItemAttr *attr = info.GetAttributes();
402 if ( !attr || !attr->HasTextColour() )
404 info.SetTextColour(*wxCYAN);
408 RefreshItem(info.m_itemId);
415 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
416 if ( item++ == GetItemCount() - 1 )
421 //wxLogMessage(_T("Focusing item %ld"), item);
423 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
427 case 'r': // show bounding Rect
430 item = event.GetIndex();
432 if ( !GetItemRect(item, r) )
434 //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
438 //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
439 // item, r.x, r.y, r.x + r.width, r.y + r.height);
444 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
450 //wxLogMessage(_T("Item %ld deleted"), item);
452 // -1 because the indices were shifted by DeleteItem()
453 item = GetNextItem(item - 1,
454 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
460 if ( GetWindowStyle() & wxLC_REPORT )
462 if ( GetWindowStyle() & wxLC_VIRTUAL )
464 SetItemCount(GetItemCount() + 1);
468 //InsertItemInReportView(event.GetIndex());
474 LogEvent(event, _T("OnListKeyDown"));
480 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
482 //wxLogMessage(_T("Got char event."));
484 switch ( event.GetKeyCode() )
490 // these are the keys we process ourselves
498 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
500 if ( !event.ControlDown() )
509 HitTest(event.GetPosition(), flags, &subitem);
514 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
515 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
516 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
517 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
518 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
519 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
520 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
521 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
522 default: where = _T("not clear exactly where on"); break;
525 //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
526 // where.c_str(), item, subitem);
529 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
531 //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
532 // event.GetIndex(), eventName,
533 // event.GetText().c_str(), event.GetData());
536 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
539 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
541 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
546 return wxString::Format(_T("Column %ld of item %ld"), column, item);
550 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
555 if (!(item %3) && column == 1)
561 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
563 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
568 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
570 wxPoint point = event.GetPosition();
572 if (point.x == -1 && point.y == -1) {
573 wxSize size = GetSize();
574 point.x = size.x / 2;
575 point.y = size.y / 2;
577 point = ScreenToClient(point);
579 ShowContextMenu(point);
583 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
587 menu.Append(wxID_ABOUT, _T("&About"));
588 menu.AppendSeparator();
589 menu.Append(wxID_EXIT, _T("E&xit"));
591 PopupMenu(&menu, pos.x, pos.y);
593 //================================================================
597 //================================================================
598 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
603 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
605 // mName = new wxStaticText(this,-1,_T(""));
606 // sizer->Add(mName,0,wxGROW);
607 mDescription = new wxStaticText(this,-1,_T(""));
608 sizer->Add(mDescription,0,wxGROW);
609 mAuthor = new wxStaticText(this,-1,_T(""));
610 sizer->Add(mAuthor,0,wxGROW);
611 mCategory = new wxStaticText(this,-1,_T(""));
612 sizer->Add(mCategory,0,wxGROW);
616 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
617 mInputList = new wxListCtrl(this, -1,
620 wxLC_REPORT //wxLC_LIST
623 inputs->Add(mInputList,1,wxGROW);
624 sizer->Add(inputs,1,wxGROW);
626 wxBoxSizer *outputs =
628 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
629 mOutputList = new wxListCtrl(this, -1,
632 wxLC_REPORT //wxLC_LIST
635 outputs->Add(mOutputList,1,wxGROW);
636 sizer->Add(outputs,1,wxGROW);
642 //================================================================
645 //================================================================
646 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
649 // mName->SetLabel(std2wx(descr->GetTypeName()));
650 mDescription->SetLabel(std2wx(descr->GetDescription()));
651 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
652 mCategory->SetLabel(std2wx(descr->GetCategory()));
654 mInputList->ClearAll();
655 mInputList->InsertColumn( 0, _("Name"),
656 wxLIST_FORMAT_LEFT, 80 );
657 mInputList->InsertColumn( 1, _("Type"),
658 wxLIST_FORMAT_LEFT, 100 );
659 mInputList->InsertColumn( 2, _("Nature"),
660 wxLIST_FORMAT_LEFT, 100 );
661 mInputList->InsertColumn( 3, _("Description"),
662 wxLIST_FORMAT_LEFT, 500 );
664 mOutputList->ClearAll();
665 mOutputList->InsertColumn( 0, _("Name"),
666 wxLIST_FORMAT_LEFT, 80 );
667 mOutputList->InsertColumn( 1, _("Type"),
668 wxLIST_FORMAT_LEFT, 100 );
669 mOutputList->InsertColumn( 2, _("Nature"),
670 wxLIST_FORMAT_LEFT, 100 );
671 mOutputList->InsertColumn( 3, _("Description"),
672 wxLIST_FORMAT_LEFT, 500 );
675 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
676 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
677 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
679 const BlackBoxDescriptor::InputDescriptorMapType& imap =
680 descr->GetInputDescriptorMap();
681 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
682 for ( in = imap.begin(); in != imap.end(); ++in )
685 if (in->second->GetCreatorTypeInfo() ==
686 typeid(AtomicBlackBoxDescriptor))
690 else if (in->second->GetCreatorTypeInfo() ==
691 typeid(WxBlackBoxDescriptor))
695 if (iotype==0) user_defined.push_back(in->second);
696 else if (iotype==1) ubb_defined.push_back(in->second);
697 else if (iotype==2) wxbb_defined.push_back(in->second);
701 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
702 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
704 InsertInputOutput(mInputList,*hi);
706 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
708 InsertInputOutput(mInputList,*hi);
710 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
712 InsertInputOutput(mInputList,*hi);
716 user_defined.clear();
718 wxbb_defined.clear();
719 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
720 descr->GetOutputDescriptorMap();
721 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
722 for ( out = omap.begin(); out != omap.end(); ++out )
725 if (out->second->GetCreatorTypeInfo() ==
726 typeid(AtomicBlackBoxDescriptor))
730 else if (out->second->GetCreatorTypeInfo() ==
731 typeid(WxBlackBoxDescriptor))
736 if (iotype==0) user_defined.push_back(out->second);
737 else if (iotype==1) ubb_defined.push_back(out->second);
738 else if (iotype==2) wxbb_defined.push_back(out->second);
741 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
743 InsertInputOutput(mOutputList,*hi);
745 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
747 InsertInputOutput(mOutputList,*hi);
749 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
751 InsertInputOutput(mOutputList,*hi);
754 //================================================================
757 //================================================================
758 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
759 BlackBoxInputOutputDescriptor* d)
762 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
763 int nID = l->GetItemCount();
764 // std::cout << nID << std::endl;
766 // kNewItem.SetMask(wxLIST_MASK_DATA);
767 // kNewItem.SetData(d);
768 l->InsertItem(kNewItem);
769 l->SetItem(nID, 0, std2wx(d->GetName()) );
770 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
771 l->SetItem(nID, 2, std2wx(d->GetNature()) );
772 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
774 //================================================================
776 //================================================================
777 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
780 //================================================================
798 //================================================================
799 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
800 WxGUIPackageBrowser2User* user )
801 : wxPanel(parent, -1),
805 _actualSelected=NULL;
806 m_mgr.SetManagedWindow(this);
808 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
809 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
812 wxLC_REPORT //wxLC_LIST
814 mBoxList->SetUser(this);
815 mBoxList->SetBackgroundColour(*wxWHITE);
818 // JGRR & CM DISABLED CLOSE BUTTON
819 m_mgr.AddPane(mBoxList,
820 wxAuiPaneInfo().Name(wxT("BoxList"))
821 .Caption(wxT("Black Boxes"))
822 .MinimizeButton(true)
823 .MaximizeButton(true)
825 .MinSize(wxSize(100,100))
828 // sizer->Add(mBoxList,5,wxGROW);
830 mBoxInfo = new WxGUIBlackBoxInfo(this);
831 // sizer->Add(mBoxInfo,3,wxGROW);
833 // JGRR & CM DISABLED CLOSE BUTTON
834 m_mgr.AddPane(mBoxInfo,
835 wxAuiPaneInfo().Name(wxT("Box"))
837 .MinimizeButton(true)
838 .MaximizeButton(true)
840 .MinSize(wxSize(100,300))
844 wxPanel* filters = new wxPanel(this,-1);
845 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
848 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
849 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
853 fpack->Add(mPackageFilter,1,wxGROW);
854 fsizer->Add(fpack,0,wxGROW);
857 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
858 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
862 fname->Add(mNameFilter,1,wxGROW);
863 fsizer->Add(fname,0,wxGROW);
866 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
867 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
871 fdescr->Add(mDescriptionFilter,1,wxGROW);
872 fsizer->Add(fdescr,0,wxGROW);
875 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
876 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
880 fcat->Add(mCategoryFilter,1,wxGROW);
881 fsizer->Add(fcat,0,wxGROW);
882 wxBoxSizer *fintype =
884 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
885 mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
889 fintype->Add(mInputTypeFilter,1,wxGROW);
890 fsizer->Add(fintype,0,wxGROW);
891 wxBoxSizer *fouttype =
893 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
894 mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
898 fouttype->Add(mOutputTypeFilter,1,wxGROW);
899 fsizer->Add(fouttype,0,wxGROW);
902 ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL );
903 mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
907 finnat->Add(mInputNatureFilter,1,wxGROW);
908 fsizer->Add(finnat,0,wxGROW);
909 wxBoxSizer *foutnat =
911 ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL );
912 mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
916 foutnat->Add(mOutputNatureFilter,1,wxGROW);
917 fsizer->Add(foutnat,0,wxGROW);
919 mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
920 mShowWidgetsFilter->SetValue(true);
921 fsizer->Add(mShowWidgetsFilter,0,wxGROW);
923 mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
924 mShowAdaptorsFilter->SetValue(false);
925 fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
927 mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
928 mShowGUIsFilter->SetValue(false);
929 fsizer->Add(mShowGUIsFilter,0,wxGROW);
931 filters->SetSizer(fsizer);
933 // JGRR & CM DISABLED CLOSE BUTTON
934 m_mgr.AddPane(filters,
935 wxAuiPaneInfo().Name(wxT("Filter"))
936 .Caption(wxT("Filter"))
937 .MinimizeButton(true)
938 .MaximizeButton(true)
940 .MinSize(wxSize(100,100))
944 // sizer->Add(fsizer,1,wxGROW);
952 //================================================================
954 Factory::Pointer WxGUIPackageBrowser2::GetFactory()
959 //================================================================
962 //================================================================
963 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
967 //================================================================
969 //================================================================
970 // User callback when a box is selected in the list
971 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
972 ( BlackBoxDescriptor* d)
977 mBoxInfo->UpdateInfo(d);
978 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
979 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
983 //================================================================
985 //================================================================
986 BlackBoxDescriptor* WxGUIPackageBrowser2::GetActualSelected()
988 return _actualSelected;
991 //================================================================
993 //================================================================
994 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
997 mInterpreter.reset();
998 // Object::PrintObjectListInfo("");
1001 //================================================================
1003 //================================================================
1004 void WxGUIPackageBrowser2::IncludeAll()
1006 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
1007 mInterpreter->SetCommandLine(true);
1008 std::stringstream* buf = new std::stringstream;
1009 *buf << "exec freeze_no_error" << std::endl;
1010 *buf << "message max 0" << std::endl;
1011 *buf << "include *" << std::endl;
1012 mInterpreter->InterpretBuffer(buf);
1014 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
1015 BuildFromFactory(F);
1017 //================================================================
1019 //================================================================
1020 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
1026 //================================================================
1028 //================================================================
1029 void WxGUIPackageBrowser2::RebuildList()
1032 mBoxList->ClearAll();
1034 const Factory::PackageMapType& M = mFactory->GetPackageMap();
1035 Factory::PackageMapType::const_iterator i;
1036 for (i=M.begin();i!=M.end();++i)
1038 Package::Pointer P = i->second;
1039 if (P->GetName() == "user") continue;
1041 Package::DescriptorMapType::iterator j;
1042 for (j=P->GetDescriptorMap().begin();
1043 j!=P->GetDescriptorMap().end();
1046 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
1047 if (IsVisible(j->second))
1048 mBoxList->Insert(j->second);
1053 //================================================================
1055 bool WxGUIPackageBrowser2::findnpos(const std::string &strA, const std::string &strB )
1057 if ((strB=="") || (strA=="") )
1064 std::string strAA=strA;
1065 std::string strBB=strB;
1068 size=strAA.length();
1069 for (i=0;i<size;i++)
1071 if ((strAA[i]>='A')&&(strAA[i]<='Z'))
1073 strAA[i]=strAA[i]+32;
1077 size=strBB.length();
1078 for (i=0;i<size;i++)
1080 if ((strBB[i]>='A')&&(strBB[i]<='Z'))
1082 strBB[i]=strBB[i]+32;
1087 if ( strAA.find(strBB) == std::string::npos )
1095 //================================================================
1096 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
1098 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
1099 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
1100 if ((!mShowAdaptorsFilter->IsChecked())&&
1101 ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
1102 (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
1107 if ((!mShowGUIsFilter->IsChecked())&&
1108 ((d->GetKind()==BlackBoxDescriptor::GUI)||
1109 (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
1114 //EED if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) ) == std::string::npos )
1115 if ( findnpos(d->GetPackage()->GetName(),wx2std(mPackageFilter->GetValue())) == true )
1120 //EED if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) ) == std::string::npos )
1121 if ( findnpos(d->GetTypeName(),wx2std(mNameFilter->GetValue())) == true )
1126 //EED if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) ) == std::string::npos )
1127 if ( findnpos(d->GetDescription(),wx2std(mDescriptionFilter->GetValue())) == true )
1132 //EED if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) ) == std::string::npos )
1133 if ( findnpos(d->GetCategory(),wx2std(mCategoryFilter->GetValue())) == true )
1138 if (!mShowWidgetsFilter->IsChecked())
1141 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1142 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1143 for ( in = imap.begin(); in != imap.end(); ++in )
1145 if (in->second->GetName() == "Widget" )
1157 if (mInputTypeFilter->GetValue().size()>0)
1159 std::string s = wx2std(mInputTypeFilter->GetValue());
1161 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
1162 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1163 for ( in = imap.begin(); in != imap.end(); ++in )
1165 //EED if (in->second->GetTypeName().find(s)!=std::string::npos)
1166 if ( findnpos( in->second->GetTypeName() , s ) == true )
1178 if (mOutputTypeFilter->GetValue().size()>0)
1180 std::string s = wx2std(mOutputTypeFilter->GetValue());
1182 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1183 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1184 for ( in = imap.begin(); in != imap.end(); ++in )
1186 //EED if (in->second->GetTypeName().find(s)!=std::string::npos)
1187 if ( findnpos( in->second->GetTypeName() , s ) == true )
1199 if (mInputNatureFilter->GetValue().size()>0)
1201 std::string s = wx2std(mInputNatureFilter->GetValue());
1203 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
1204 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1205 for ( in = imap.begin(); in != imap.end(); ++in )
1207 //EED if (in->second->GetNature().find(s)!=std::string::npos)
1208 if ( findnpos( in->second->GetNature() , s ) == true )
1220 if (mOutputNatureFilter->GetValue().size()>0)
1222 std::string s = wx2std(mOutputNatureFilter->GetValue());
1224 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1225 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1226 for ( in = imap.begin(); in != imap.end(); ++in )
1228 //EED if (in->second->GetNature().find(s)!=std::string::npos)
1229 if ( findnpos( in->second->GetNature() , s ) == true )
1244 //========================================================================
1246 //========================================================================
1247 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1248 //EED EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1249 //EED EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1250 //EED EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1251 //EED EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1252 //EED EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1253 //EED EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1254 //EED EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
1255 //EED EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
1257 EVT_TEXT(id_f1, WxGUIPackageBrowser2::OnFilter )
1258 EVT_TEXT(id_f2, WxGUIPackageBrowser2::OnFilter )
1259 EVT_TEXT(id_f3, WxGUIPackageBrowser2::OnFilter )
1260 EVT_TEXT(id_f4, WxGUIPackageBrowser2::OnFilter )
1261 EVT_TEXT(id_f5, WxGUIPackageBrowser2::OnFilter )
1262 EVT_TEXT(id_f6, WxGUIPackageBrowser2::OnFilter )
1263 EVT_TEXT(id_f7, WxGUIPackageBrowser2::OnFilter )
1264 EVT_TEXT(id_f8, WxGUIPackageBrowser2::OnFilter )
1266 EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
1267 EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
1268 EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
1270 //========================================================================
1274 //================================================================
1275 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1278 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1280 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1282 mBrowser = new WxGUIPackageBrowser2(this);
1283 mBrowser->IncludeAll();
1284 sizer->Add(mBrowser,1,wxGROW);
1286 // WxGUICommand* com = new WxGUICommand(this,this);
1291 // Creates the parent window of all bbtk windows as a child of this
1292 // Wx::CreateTopWindow(this);
1293 // Add the method OnWxSignal as a Wx::Signal observer
1294 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
1296 SetAutoLayout(true);
1299 //================================================================
1301 //================================================================
1302 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1305 //================================================================
1310 #endif //_USE_WXWIDGETS_