1 /*=========================================================================
3 Module: $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
5 Date: $Date: 2010/03/29 16:08:24 $
6 Version: $Revision: 1.18 $
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 std::cout<<"RaC DRAG TABLE"<<std::endl;
250 wxString text(wxT(this->GetItemText(event.GetIndex())));
252 info.m_itemId = event.m_itemIndex;
254 info.m_mask = wxLIST_MASK_DATA;
255 wxString sendtext(wxT(""));
258 // TO DO : STORE SMART PTR ?
259 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
262 sendtext += wxT(d->GetFullTypeName());
267 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
271 wxTextDataObject tdo(wxT(sendtext));
272 wxDropSource tds(tdo, this);
277 // const wxPoint& pt = event.m_pointDrag;
279 //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
280 // pt.x, pt.y, HitTest(pt, flags) );
283 void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
285 //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
286 // event.m_pointDrag.x, event.m_pointDrag.y );
289 void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
291 //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
294 void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
296 //wxLogMessage( wxT("OnEndLabelEdit: %s"),
297 // event.IsEditCancelled() ? _T("[cancelled]")
298 // : event.m_item.m_text.c_str());
301 void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
303 LogEvent(event, _T("OnDeleteItem"));
304 std::cout << "cannot del"<<std::endl;
306 //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
309 void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
311 LogEvent(event, _T("OnDeleteAllItems"));
315 #if WXWIN_COMPATIBILITY_2_4
316 void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
320 msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
321 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
322 msg << _T(" wxLIST_MASK_STATE");
323 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
324 msg << _T(" wxLIST_MASK_TEXT");
325 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
326 msg << _T(" wxLIST_MASK_IMAGE");
327 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
328 msg << _T(" wxLIST_MASK_DATA");
329 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
330 msg << _T(" wxLIST_SET_ITEM");
331 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
332 msg << _T(" wxLIST_MASK_WIDTH");
333 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
334 msg << _T(" wxLIST_MASK_WIDTH");
336 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
338 event.m_item.m_text = _T("My callback text");
344 void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
346 LogEvent(event, _T("OnSetInfo"));
350 void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
352 if (mUser==0) return;
355 info.m_itemId = event.m_itemIndex;
357 info.m_mask = wxLIST_MASK_DATA;
360 // TO DO : STORE SMART PTR ?
361 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
362 if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
366 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
370 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
372 LogEvent(event, _T("OnDeselected"));
375 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
377 LogEvent(event, _T("OnActivated"));
380 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
382 LogEvent(event, _T("OnFocused"));
387 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
391 switch ( event.GetKeyCode() )
393 case 'c': // colorize
397 info.m_itemId = event.GetIndex();
398 if ( info.m_itemId == -1 )
406 wxListItemAttr *attr = info.GetAttributes();
407 if ( !attr || !attr->HasTextColour() )
409 info.SetTextColour(*wxCYAN);
413 RefreshItem(info.m_itemId);
420 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
421 if ( item++ == GetItemCount() - 1 )
426 //wxLogMessage(_T("Focusing item %ld"), item);
428 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
432 case 'r': // show bounding Rect
435 item = event.GetIndex();
437 if ( !GetItemRect(item, r) )
439 //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
443 //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
444 // item, r.x, r.y, r.x + r.width, r.y + r.height);
449 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
455 //wxLogMessage(_T("Item %ld deleted"), item);
457 // -1 because the indices were shifted by DeleteItem()
458 item = GetNextItem(item - 1,
459 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
465 if ( GetWindowStyle() & wxLC_REPORT )
467 if ( GetWindowStyle() & wxLC_VIRTUAL )
469 SetItemCount(GetItemCount() + 1);
473 //InsertItemInReportView(event.GetIndex());
479 LogEvent(event, _T("OnListKeyDown"));
485 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
487 //wxLogMessage(_T("Got char event."));
489 switch ( event.GetKeyCode() )
495 // these are the keys we process ourselves
503 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
505 if ( !event.ControlDown() )
514 HitTest(event.GetPosition(), flags, &subitem);
519 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
520 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
521 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
522 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
523 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
524 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
525 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
526 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
527 default: where = _T("not clear exactly where on"); break;
530 //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
531 // where.c_str(), item, subitem);
534 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
536 //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
537 // event.GetIndex(), eventName,
538 // event.GetText().c_str(), event.GetData());
541 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
544 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
546 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
551 return wxString::Format(_T("Column %ld of item %ld"), column, item);
555 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
560 if (!(item %3) && column == 1)
566 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
568 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
573 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
575 wxPoint point = event.GetPosition();
577 if (point.x == -1 && point.y == -1) {
578 wxSize size = GetSize();
579 point.x = size.x / 2;
580 point.y = size.y / 2;
582 point = ScreenToClient(point);
584 ShowContextMenu(point);
588 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
592 menu.Append(wxID_ABOUT, _T("&About"));
593 menu.AppendSeparator();
594 menu.Append(wxID_EXIT, _T("E&xit"));
596 PopupMenu(&menu, pos.x, pos.y);
598 //================================================================
602 //================================================================
603 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
608 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
610 // mName = new wxStaticText(this,-1,_T(""));
611 // sizer->Add(mName,0,wxGROW);
612 mDescription = new wxStaticText(this,-1,_T(""));
613 sizer->Add(mDescription,0,wxGROW);
614 mAuthor = new wxStaticText(this,-1,_T(""));
615 sizer->Add(mAuthor,0,wxGROW);
616 mCategory = new wxStaticText(this,-1,_T(""));
617 sizer->Add(mCategory,0,wxGROW);
622 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
623 mInputList = new wxListCtrl(this, -1,
626 wxLC_REPORT //wxLC_LIST
630 inputs->Add(mInputList,1,wxGROW);
631 sizer->Add(inputs,1,wxGROW);
633 wxBoxSizer *outputs =
635 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
636 mOutputList = new wxListCtrl(this, -1,
639 wxLC_REPORT //wxLC_LIST
642 outputs->Add(mOutputList,1,wxGROW);
643 sizer->Add(outputs,1,wxGROW);
650 //================================================================
653 //================================================================
654 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
657 // mName->SetLabel(std2wx(descr->GetTypeName()));
658 mDescription->SetLabel(std2wx(descr->GetDescription()));
659 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
660 mCategory->SetLabel(std2wx(descr->GetCategory()));
662 mInputList->ClearAll();
663 mInputList->InsertColumn( 0, _("Name"),
664 wxLIST_FORMAT_LEFT, 80 );
665 mInputList->InsertColumn( 1, _("Type"),
666 wxLIST_FORMAT_LEFT, 100 );
667 mInputList->InsertColumn( 2, _("Nature"),
668 wxLIST_FORMAT_LEFT, 100 );
669 mInputList->InsertColumn( 3, _("Description"),
670 wxLIST_FORMAT_LEFT, 500 );
672 mOutputList->ClearAll();
673 mOutputList->InsertColumn( 0, _("Name"),
674 wxLIST_FORMAT_LEFT, 80 );
675 mOutputList->InsertColumn( 1, _("Type"),
676 wxLIST_FORMAT_LEFT, 100 );
677 mOutputList->InsertColumn( 2, _("Nature"),
678 wxLIST_FORMAT_LEFT, 100 );
679 mOutputList->InsertColumn( 3, _("Description"),
680 wxLIST_FORMAT_LEFT, 500 );
683 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
684 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
685 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
687 const BlackBoxDescriptor::InputDescriptorMapType& imap =
688 descr->GetInputDescriptorMap();
689 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
690 for ( in = imap.begin(); in != imap.end(); ++in )
693 if (in->second->GetCreatorTypeInfo() ==
694 typeid(AtomicBlackBoxDescriptor))
698 else if (in->second->GetCreatorTypeInfo() ==
699 typeid(WxBlackBoxDescriptor))
703 if (iotype==0) user_defined.push_back(in->second);
704 else if (iotype==1) ubb_defined.push_back(in->second);
705 else if (iotype==2) wxbb_defined.push_back(in->second);
709 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
710 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
712 InsertInputOutput(mInputList,*hi);
714 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
716 InsertInputOutput(mInputList,*hi);
718 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
720 InsertInputOutput(mInputList,*hi);
724 user_defined.clear();
726 wxbb_defined.clear();
727 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
728 descr->GetOutputDescriptorMap();
729 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
730 for ( out = omap.begin(); out != omap.end(); ++out )
733 if (out->second->GetCreatorTypeInfo() ==
734 typeid(AtomicBlackBoxDescriptor))
738 else if (out->second->GetCreatorTypeInfo() ==
739 typeid(WxBlackBoxDescriptor))
744 if (iotype==0) user_defined.push_back(out->second);
745 else if (iotype==1) ubb_defined.push_back(out->second);
746 else if (iotype==2) wxbb_defined.push_back(out->second);
749 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
751 InsertInputOutput(mOutputList,*hi);
753 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
755 InsertInputOutput(mOutputList,*hi);
757 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
759 InsertInputOutput(mOutputList,*hi);
762 //================================================================
765 //================================================================
766 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
767 BlackBoxInputOutputDescriptor* d)
770 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
771 int nID = l->GetItemCount();
772 // std::cout << nID << std::endl;
774 // kNewItem.SetMask(wxLIST_MASK_DATA);
775 // kNewItem.SetData(d);
776 l->InsertItem(kNewItem);
777 l->SetItem(nID, 0, std2wx(d->GetName()) );
778 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
779 l->SetItem(nID, 2, std2wx(d->GetNature()) );
780 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
782 //================================================================
784 //================================================================
785 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
788 //================================================================
807 //================================================================
808 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
809 WxGUIPackageBrowser2User* user )
810 : wxPanel(parent, -1),
814 m_mgr.SetManagedWindow(this);
816 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
817 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
820 wxLC_REPORT //wxLC_LIST
822 mBoxList->SetUser(this);
823 mBoxList->SetBackgroundColour(*wxWHITE);
825 m_mgr.AddPane(mBoxList,
826 wxAuiPaneInfo().Name(wxT("BoxList"))
827 .Caption(wxT("Black Boxes"))
828 .MinimizeButton(true)
829 .MaximizeButton(true)
831 .MinSize(wxSize(100,100))
833 // sizer->Add(mBoxList,5,wxGROW);
835 mBoxInfo = new WxGUIBlackBoxInfo(this);
836 // sizer->Add(mBoxInfo,3,wxGROW);
838 m_mgr.AddPane(mBoxInfo,
839 wxAuiPaneInfo().Name(wxT("Box"))
841 .MinimizeButton(true)
842 .MaximizeButton(true)
844 .MinSize(wxSize(100,300))
848 wxPanel* filters = new wxPanel(this,-1);
849 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
852 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
853 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
857 fpack->Add(mPackageFilter,1,wxGROW);
858 fsizer->Add(fpack,0,wxGROW);
861 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
862 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
866 fname->Add(mNameFilter,1,wxGROW);
867 fsizer->Add(fname,0,wxGROW);
870 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
871 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
875 fdescr->Add(mDescriptionFilter,1,wxGROW);
876 fsizer->Add(fdescr,0,wxGROW);
879 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
880 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
884 fcat->Add(mCategoryFilter,1,wxGROW);
885 fsizer->Add(fcat,0,wxGROW);
886 wxBoxSizer *fintype =
888 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
889 mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
893 fintype->Add(mInputTypeFilter,1,wxGROW);
894 fsizer->Add(fintype,0,wxGROW);
895 wxBoxSizer *fouttype =
897 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
898 mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
902 fouttype->Add(mOutputTypeFilter,1,wxGROW);
903 fsizer->Add(fouttype,0,wxGROW);
906 ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL );
907 mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
911 finnat->Add(mInputNatureFilter,1,wxGROW);
912 fsizer->Add(finnat,0,wxGROW);
913 wxBoxSizer *foutnat =
915 ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL );
916 mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
920 foutnat->Add(mOutputNatureFilter,1,wxGROW);
921 fsizer->Add(foutnat,0,wxGROW);
924 mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
925 mShowWidgetsFilter->SetValue(true);
926 fsizer->Add(mShowWidgetsFilter,0,wxGROW);
928 mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
929 mShowAdaptorsFilter->SetValue(false);
930 fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
932 mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
933 mShowGUIsFilter->SetValue(false);
934 fsizer->Add(mShowGUIsFilter,0,wxGROW);
936 filters->SetSizer(fsizer);
938 m_mgr.AddPane(filters,
939 wxAuiPaneInfo().Name(wxT("Filter"))
940 .Caption(wxT("Filter"))
941 .MinimizeButton(true)
942 .MaximizeButton(true)
944 .MinSize(wxSize(100,100)) );
948 // sizer->Add(fsizer,1,wxGROW);
956 //================================================================
958 //================================================================
959 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
963 //================================================================
965 //================================================================
966 // User callback when a box is selected in the list
967 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
968 ( BlackBoxDescriptor* d)
973 mBoxInfo->UpdateInfo(d);
974 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
975 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
979 //================================================================
981 //================================================================
982 BlackBoxDescriptor* WxGUIPackageBrowser2::GetActualSelected()
984 return _actualSelected;
988 //================================================================
990 //================================================================
991 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
994 mInterpreter.reset();
995 // Object::PrintObjectListInfo("");
998 //================================================================
1000 //================================================================
1001 void WxGUIPackageBrowser2::IncludeAll()
1003 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
1004 mInterpreter->SetCommandLine(true);
1005 std::stringstream* buf = new std::stringstream;
1006 *buf << "exec freeze_no_error" << std::endl;
1007 *buf << "message max 0" << std::endl;
1008 *buf << "include *" << std::endl;
1009 mInterpreter->InterpretBuffer(buf);
1011 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
1012 BuildFromFactory(F);
1014 //================================================================
1016 //================================================================
1017 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
1023 //================================================================
1025 //================================================================
1026 void WxGUIPackageBrowser2::RebuildList()
1029 mBoxList->ClearAll();
1031 const Factory::PackageMapType& M = mFactory->GetPackageMap();
1032 Factory::PackageMapType::const_iterator i;
1033 for (i=M.begin();i!=M.end();++i)
1035 Package::Pointer P = i->second;
1036 if (P->GetName() == "user") continue;
1038 Package::DescriptorMapType::iterator j;
1039 for (j=P->GetDescriptorMap().begin();
1040 j!=P->GetDescriptorMap().end();
1043 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
1044 if (IsVisible(j->second))
1045 mBoxList->Insert(j->second);
1050 //================================================================
1052 //================================================================
1053 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
1055 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
1056 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
1057 if ((!mShowAdaptorsFilter->IsChecked())&&
1058 ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
1059 (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
1061 if ((!mShowGUIsFilter->IsChecked())&&
1062 ((d->GetKind()==BlackBoxDescriptor::GUI)||
1063 (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
1065 if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) )
1066 == std::string::npos ) return false;
1067 if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) )
1068 == std::string::npos ) return false;
1069 if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) )
1070 == std::string::npos ) return false;
1071 if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) )
1072 == std::string::npos ) return false;
1073 if (!mShowWidgetsFilter->IsChecked())
1076 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1077 d->GetOutputDescriptorMap();
1078 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1079 for ( in = imap.begin(); in != imap.end(); ++in )
1081 if (in->second->GetName() == "Widget" )
1087 if (found) return false;
1089 if (mInputTypeFilter->GetValue().size()>0)
1091 std::string s = wx2std(mInputTypeFilter->GetValue());
1093 const BlackBoxDescriptor::InputDescriptorMapType& imap =
1094 d->GetInputDescriptorMap();
1095 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1096 for ( in = imap.begin(); in != imap.end(); ++in )
1098 if (in->second->GetTypeName().find(s)!=std::string::npos)
1104 if (!found) return false;
1106 if (mOutputTypeFilter->GetValue().size()>0)
1108 std::string s = wx2std(mOutputTypeFilter->GetValue());
1110 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1111 d->GetOutputDescriptorMap();
1112 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1113 for ( in = imap.begin(); in != imap.end(); ++in )
1115 if (in->second->GetTypeName().find(s)!=std::string::npos)
1121 if (!found) return false;
1123 if (mInputNatureFilter->GetValue().size()>0)
1125 std::string s = wx2std(mInputNatureFilter->GetValue());
1127 const BlackBoxDescriptor::InputDescriptorMapType& imap =
1128 d->GetInputDescriptorMap();
1129 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1130 for ( in = imap.begin(); in != imap.end(); ++in )
1132 if (in->second->GetNature().find(s)!=std::string::npos)
1138 if (!found) return false;
1140 if (mOutputNatureFilter->GetValue().size()>0)
1142 std::string s = wx2std(mOutputNatureFilter->GetValue());
1144 const BlackBoxDescriptor::OutputDescriptorMapType& imap =
1145 d->GetOutputDescriptorMap();
1146 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1147 for ( in = imap.begin(); in != imap.end(); ++in )
1149 if (in->second->GetNature().find(s)!=std::string::npos)
1155 if (!found) return false;
1160 //========================================================================
1162 //========================================================================
1163 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1164 EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1165 EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1166 EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1167 EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1168 EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1169 EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1170 EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
1171 EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
1172 EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
1173 EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
1174 EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
1176 //========================================================================
1180 //================================================================
1181 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1184 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1188 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1190 mBrowser = new WxGUIPackageBrowser2(this);
1191 mBrowser->IncludeAll();
1192 sizer->Add(mBrowser,1,wxGROW);
1194 // WxGUICommand* com = new WxGUICommand(this,this);
1199 // Creates the parent window of all bbtk windows as a child of this
1200 // Wx::CreateTopWindow(this);
1201 // Add the method OnWxSignal as a Wx::Signal observer
1202 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
1204 SetAutoLayout(true);
1207 //================================================================
1209 //================================================================
1210 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1213 //================================================================
1218 #endif //_USE_WXWIDGETS_