2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.27 $
34 =========================================================================*/
38 /* \brief Short description in one line
40 * Long description which
41 * can span multiple lines
54 #ifdef _USE_WXWIDGETS_
56 #define CHECKBOXVIEW 1
58 #include "bbtkWxGUIPackageBrowser2.h"
59 //#include "ThirdParty/wx/treemultictrl/wxTreeMultiCtrl.h"
60 #include "bbtkInterpreter.h"
61 #include "bbtkBlackBoxInputDescriptor.h"
62 #include "bbtkBlackBoxOutputDescriptor.h"
63 #include "bbtkWxBlackBox.h"
64 //#include "wx/grid.h"
65 //#include <wx/statline.h>
69 #define LIST_CTRL 1000
75 BEGIN_EVENT_TABLE(WxGUIBlackBoxList, wxListCtrl)
76 EVT_LIST_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginDrag)
77 EVT_LIST_BEGIN_RDRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginRDrag)
78 EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnBeginLabelEdit)
79 EVT_LIST_END_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnEndLabelEdit)
80 EVT_LIST_DELETE_ITEM(LIST_CTRL, WxGUIBlackBoxList::OnDeleteItem)
81 EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, WxGUIBlackBoxList::OnDeleteAllItems)
82 #if WXWIN_COMPATIBILITY_2_4
83 EVT_LIST_GET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnGetInfo)
84 EVT_LIST_SET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnSetInfo)
86 EVT_LIST_ITEM_SELECTED(LIST_CTRL, WxGUIBlackBoxList::OnSelected)
87 EVT_LIST_ITEM_DESELECTED(LIST_CTRL, WxGUIBlackBoxList::OnDeselected)
88 EVT_LIST_KEY_DOWN(LIST_CTRL, WxGUIBlackBoxList::OnListKeyDown)
89 EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, WxGUIBlackBoxList::OnActivated)
90 EVT_LIST_ITEM_FOCUSED(LIST_CTRL, WxGUIBlackBoxList::OnFocused)
92 EVT_LIST_COL_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColClick)
93 EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColRightClick)
94 EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColBeginDrag)
95 EVT_LIST_COL_DRAGGING(LIST_CTRL, WxGUIBlackBoxList::OnColDragging)
96 EVT_LIST_COL_END_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColEndDrag)
98 EVT_LIST_CACHE_HINT(LIST_CTRL, WxGUIBlackBoxList::OnCacheHint)
101 EVT_CONTEXT_MENU(WxGUIBlackBoxList::OnContextMenu)
103 EVT_CHAR(WxGUIBlackBoxList::OnChar)
105 EVT_RIGHT_DOWN(WxGUIBlackBoxList::OnRightClick)
108 int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData))
120 WxGUIBlackBoxList::WxGUIBlackBoxList(wxWindow *parent,
125 : wxListCtrl(parent, id, pos, size, style),
127 m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
134 void WxGUIBlackBoxList::Insert(BlackBoxDescriptor::Pointer d)
136 if (GetColumnCount()!=3)
138 InsertColumn( 0, _("Package"),
139 wxLIST_FORMAT_LEFT, 90 );
140 InsertColumn( 1, _("Box"),
141 wxLIST_FORMAT_LEFT, 150 );
142 InsertColumn( 2, _("Description"),
143 wxLIST_FORMAT_LEFT, 500 );
147 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
149 int nID = this->GetItemCount();
151 kNewItem.SetMask(wxLIST_MASK_DATA);
152 // TO DO : STORE SMART POINTER ?
153 kNewItem.SetData(d.get());
154 // BlackBoxDescriptor::Pointer* d2 = (BlackBoxDescriptor::Pointer*)kNewItem.GetData();
155 // std::cout << "Descr = "<<d<<" = "<<d2<<std::endl;
156 this->InsertItem(kNewItem);
157 this->SetItem(nID, 0, std2wx(d->GetPackage()->GetName()) );
158 this->SetItem(nID, 1, std2wx(d->GetTypeName()) );
159 this->SetItem(nID, 2, std2wx(d->GetDescription()) );
164 kNewItem.SetBackgroundColour(wxColour(192,192,192));
165 this->SetItem(kNewItem);
171 void WxGUIBlackBoxList::OnCacheHint(wxListEvent& event)
173 //wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"),
174 // event.GetCacheFrom(), event.GetCacheTo() );
177 void WxGUIBlackBoxList::SetColumnImage(int col, int image)
181 item.SetMask(wxLIST_MASK_IMAGE);
182 item.SetImage(image);
183 SetColumn(col, item);
187 void WxGUIBlackBoxList::OnColClick(wxListEvent& event)
189 int col = event.GetColumn();
191 // set or unset image
192 static bool x = false;
194 SetColumnImage(col, x ? 0 : -1);
196 // wxLogMessage( wxT("OnColumnClick at %d."), col );
199 void WxGUIBlackBoxList::OnColRightClick(wxListEvent& event)
201 int col = event.GetColumn();
204 SetColumnImage(col, -1);
207 // Show popupmenu at position
208 wxMenu menu(wxT("Test"));
209 menu.Append(-1, _T("&About"));
210 PopupMenu(&menu, event.GetPoint());
212 //wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
215 void WxGUIBlackBoxList::LogColEvent(const wxListEvent& event, const wxChar *name)
217 // const int col = event.GetColumn();
220 wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
223 event.GetItem().GetWidth(),
224 GetColumnWidth(col));
228 void WxGUIBlackBoxList::OnColBeginDrag(wxListEvent& event)
230 LogColEvent( event, wxT("OnColBeginDrag") );
232 if ( event.GetColumn() == 0 )
234 //wxLogMessage(_T("Resizing this column shouldn't work."));
241 void WxGUIBlackBoxList::OnColDragging(wxListEvent& event)
243 LogColEvent( event, wxT("OnColDragging") );
246 void WxGUIBlackBoxList::OnColEndDrag(wxListEvent& event)
248 LogColEvent( event, wxT("OnColEndDrag") );
251 void WxGUIBlackBoxList::OnBeginDrag(wxListEvent& event)
253 std::cout<<"RaC DRAG TABLE"<<std::endl;
255 wxString text(this->GetItemText(event.GetIndex()));
257 info.m_itemId = event.m_itemIndex;
259 info.m_mask = wxLIST_MASK_DATA;
260 wxString sendtext(_T(""));
263 // TO DO : STORE SMART PTR ?
264 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
267 sendtext += crea::std2wx(d->GetFullTypeName());
272 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
275 wxTextDataObject tdo(sendtext);
276 wxDropSource tds(tdo, this);
279 // const wxPoint& pt = event.m_pointDrag;
281 //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
282 // pt.x, pt.y, HitTest(pt, flags) );
285 void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
287 //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
288 // event.m_pointDrag.x, event.m_pointDrag.y );
291 void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
293 //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
296 void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
298 //wxLogMessage( wxT("OnEndLabelEdit: %s"),
299 // event.IsEditCancelled() ? _T("[cancelled]")
300 // : event.m_item.m_text.c_str());
303 void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
305 LogEvent(event, _T("OnDeleteItem"));
306 std::cout << "cannot del"<<std::endl;
308 //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
311 void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
313 LogEvent(event, _T("OnDeleteAllItems"));
317 #if WXWIN_COMPATIBILITY_2_4
318 void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
322 msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
323 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
324 msg << _T(" wxLIST_MASK_STATE");
325 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
326 msg << _T(" wxLIST_MASK_TEXT");
327 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
328 msg << _T(" wxLIST_MASK_IMAGE");
329 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
330 msg << _T(" wxLIST_MASK_DATA");
331 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
332 msg << _T(" wxLIST_SET_ITEM");
333 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
334 msg << _T(" wxLIST_MASK_WIDTH");
335 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
336 msg << _T(" wxLIST_MASK_WIDTH");
338 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
340 event.m_item.m_text = _T("My callback text");
346 void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
348 LogEvent(event, _T("OnSetInfo"));
352 void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
354 if (mUser==0) return;
357 info.m_itemId = event.m_itemIndex;
359 info.m_mask = wxLIST_MASK_DATA;
362 // TO DO : STORE SMART PTR ?
363 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
364 if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
368 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
372 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
374 LogEvent(event, _T("OnDeselected"));
377 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
379 LogEvent(event, _T("OnActivated"));
382 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
384 LogEvent(event, _T("OnFocused"));
389 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
393 switch ( event.GetKeyCode() )
395 case 'c': // colorize
399 info.m_itemId = event.GetIndex();
400 if ( info.m_itemId == -1 )
408 wxListItemAttr *attr = info.GetAttributes();
409 if ( !attr || !attr->HasTextColour() )
411 info.SetTextColour(*wxCYAN);
415 RefreshItem(info.m_itemId);
422 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
423 if ( item++ == GetItemCount() - 1 )
428 //wxLogMessage(_T("Focusing item %ld"), item);
430 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
434 case 'r': // show bounding Rect
437 item = event.GetIndex();
439 if ( !GetItemRect(item, r) )
441 //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
445 //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
446 // item, r.x, r.y, r.x + r.width, r.y + r.height);
451 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
457 //wxLogMessage(_T("Item %ld deleted"), item);
459 // -1 because the indices were shifted by DeleteItem()
460 item = GetNextItem(item - 1,
461 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
467 if ( GetWindowStyle() & wxLC_REPORT )
469 if ( GetWindowStyle() & wxLC_VIRTUAL )
471 SetItemCount(GetItemCount() + 1);
475 //InsertItemInReportView(event.GetIndex());
481 LogEvent(event, _T("OnListKeyDown"));
487 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
489 //wxLogMessage(_T("Got char event."));
491 switch ( event.GetKeyCode() )
497 // these are the keys we process ourselves
505 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
507 if ( !event.ControlDown() )
516 HitTest(event.GetPosition(), flags, &subitem);
521 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
522 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
523 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
524 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
525 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
526 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
527 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
528 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
529 default: where = _T("not clear exactly where on"); break;
532 //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
533 // where.c_str(), item, subitem);
536 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
538 //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
539 // event.GetIndex(), eventName,
540 // event.GetText().c_str(), event.GetData());
543 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
546 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
548 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
553 return wxString::Format(_T("Column %ld of item %ld"), column, item);
557 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
562 if (!(item %3) && column == 1)
568 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
570 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
575 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
577 wxPoint point = event.GetPosition();
579 if (point.x == -1 && point.y == -1) {
580 wxSize size = GetSize();
581 point.x = size.x / 2;
582 point.y = size.y / 2;
584 point = ScreenToClient(point);
586 ShowContextMenu(point);
590 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
594 menu.Append(wxID_ABOUT, _T("&About"));
595 menu.AppendSeparator();
596 menu.Append(wxID_EXIT, _T("E&xit"));
598 PopupMenu(&menu, pos.x, pos.y);
600 //================================================================
604 //================================================================
605 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
610 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
612 // mName = new wxStaticText(this,-1,_T(""));
613 // sizer->Add(mName,0,wxGROW);
614 mDescription = new wxStaticText(this,-1,_T(""));
615 sizer->Add(mDescription,0,wxGROW);
616 mAuthor = new wxStaticText(this,-1,_T(""));
617 sizer->Add(mAuthor,0,wxGROW);
618 mCategory = new wxStaticText(this,-1,_T(""));
619 sizer->Add(mCategory,0,wxGROW);
623 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
624 mInputList = new wxListCtrl(this, -1,
627 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);
649 //================================================================
652 //================================================================
653 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
656 // mName->SetLabel(std2wx(descr->GetTypeName()));
657 mDescription->SetLabel(std2wx(descr->GetDescription()));
658 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
659 mCategory->SetLabel(std2wx(descr->GetCategory()));
661 mInputList->ClearAll();
662 mInputList->InsertColumn( 0, _("Name"),
663 wxLIST_FORMAT_LEFT, 80 );
664 mInputList->InsertColumn( 1, _("Type"),
665 wxLIST_FORMAT_LEFT, 100 );
666 mInputList->InsertColumn( 2, _("Nature"),
667 wxLIST_FORMAT_LEFT, 100 );
668 mInputList->InsertColumn( 3, _("Description"),
669 wxLIST_FORMAT_LEFT, 500 );
671 mOutputList->ClearAll();
672 mOutputList->InsertColumn( 0, _("Name"),
673 wxLIST_FORMAT_LEFT, 80 );
674 mOutputList->InsertColumn( 1, _("Type"),
675 wxLIST_FORMAT_LEFT, 100 );
676 mOutputList->InsertColumn( 2, _("Nature"),
677 wxLIST_FORMAT_LEFT, 100 );
678 mOutputList->InsertColumn( 3, _("Description"),
679 wxLIST_FORMAT_LEFT, 500 );
682 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
683 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
684 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
686 const BlackBoxDescriptor::InputDescriptorMapType& imap =
687 descr->GetInputDescriptorMap();
688 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
689 for ( in = imap.begin(); in != imap.end(); ++in )
692 if (in->second->GetCreatorTypeInfo() ==
693 typeid(AtomicBlackBoxDescriptor))
697 else if (in->second->GetCreatorTypeInfo() ==
698 typeid(WxBlackBoxDescriptor))
702 if (iotype==0) user_defined.push_back(in->second);
703 else if (iotype==1) ubb_defined.push_back(in->second);
704 else if (iotype==2) wxbb_defined.push_back(in->second);
708 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
709 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
711 InsertInputOutput(mInputList,*hi);
713 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
715 InsertInputOutput(mInputList,*hi);
717 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
719 InsertInputOutput(mInputList,*hi);
723 user_defined.clear();
725 wxbb_defined.clear();
726 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
727 descr->GetOutputDescriptorMap();
728 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
729 for ( out = omap.begin(); out != omap.end(); ++out )
732 if (out->second->GetCreatorTypeInfo() ==
733 typeid(AtomicBlackBoxDescriptor))
737 else if (out->second->GetCreatorTypeInfo() ==
738 typeid(WxBlackBoxDescriptor))
743 if (iotype==0) user_defined.push_back(out->second);
744 else if (iotype==1) ubb_defined.push_back(out->second);
745 else if (iotype==2) wxbb_defined.push_back(out->second);
748 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
750 InsertInputOutput(mOutputList,*hi);
752 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
754 InsertInputOutput(mOutputList,*hi);
756 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
758 InsertInputOutput(mOutputList,*hi);
761 //================================================================
764 //================================================================
765 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
766 BlackBoxInputOutputDescriptor* d)
769 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
770 int nID = l->GetItemCount();
771 // std::cout << nID << std::endl;
773 // kNewItem.SetMask(wxLIST_MASK_DATA);
774 // kNewItem.SetData(d);
775 l->InsertItem(kNewItem);
776 l->SetItem(nID, 0, std2wx(d->GetName()) );
777 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
778 l->SetItem(nID, 2, std2wx(d->GetNature()) );
779 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
781 //================================================================
783 //================================================================
784 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
787 //================================================================
805 //================================================================
806 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
807 WxGUIPackageBrowser2User* user )
808 : wxPanel(parent, -1),
812 _actualSelected=NULL;
813 m_mgr.SetManagedWindow(this);
815 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
816 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
819 wxLC_REPORT //wxLC_LIST
821 mBoxList->SetUser(this);
822 mBoxList->SetBackgroundColour(*wxWHITE);
825 // JGRR & CM DISABLED CLOSE BUTTON
826 m_mgr.AddPane(mBoxList,
827 wxAuiPaneInfo().Name(wxT("BoxList"))
828 .Caption(wxT("Black Boxes"))
829 .MinimizeButton(true)
830 .MaximizeButton(true)
832 .MinSize(wxSize(100,100))
835 // sizer->Add(mBoxList,5,wxGROW);
837 mBoxInfo = new WxGUIBlackBoxInfo(this);
838 // sizer->Add(mBoxInfo,3,wxGROW);
840 // JGRR & CM DISABLED CLOSE BUTTON
841 m_mgr.AddPane(mBoxInfo,
842 wxAuiPaneInfo().Name(wxT("Box"))
844 .MinimizeButton(true)
845 .MaximizeButton(true)
847 .MinSize(wxSize(100,200))
851 wxPanel* filters = new wxPanel(this,-1);
852 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
855 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
856 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
860 fpack->Add(mPackageFilter,1,wxGROW);
861 fsizer->Add(fpack,0,wxGROW);
864 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
865 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
869 fname->Add(mNameFilter,1,wxGROW);
870 fsizer->Add(fname,0,wxGROW);
873 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
874 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
878 fdescr->Add(mDescriptionFilter,1,wxGROW);
879 fsizer->Add(fdescr,0,wxGROW);
882 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
883 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
887 fcat->Add(mCategoryFilter,1,wxGROW);
888 fsizer->Add(fcat,0,wxGROW);
889 wxBoxSizer *fintype =
891 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
892 mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
896 fintype->Add(mInputTypeFilter,1,wxGROW);
897 fsizer->Add(fintype,0,wxGROW);
898 wxBoxSizer *fouttype =
900 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
901 mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
905 fouttype->Add(mOutputTypeFilter,1,wxGROW);
906 fsizer->Add(fouttype,0,wxGROW);
909 ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL );
910 mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
914 finnat->Add(mInputNatureFilter,1,wxGROW);
915 fsizer->Add(finnat,0,wxGROW);
916 wxBoxSizer *foutnat =
918 ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL );
919 mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
923 foutnat->Add(mOutputNatureFilter,1,wxGROW);
924 fsizer->Add(foutnat,0,wxGROW);
926 mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
927 mShowWidgetsFilter->SetValue(true);
928 fsizer->Add(mShowWidgetsFilter,0,wxGROW);
930 mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
931 mShowAdaptorsFilter->SetValue(false);
932 fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
934 mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
935 mShowGUIsFilter->SetValue(false);
936 fsizer->Add(mShowGUIsFilter,0,wxGROW);
938 filters->SetSizer(fsizer);
940 // JGRR & CM DISABLED CLOSE BUTTON
941 m_mgr.AddPane(filters,
942 wxAuiPaneInfo().Name(wxT("Filter"))
943 .Caption(wxT("Filter"))
944 .MinimizeButton(true)
945 .MaximizeButton(true)
947 .MinSize(wxSize(100,100))
951 // sizer->Add(fsizer,1,wxGROW);
959 //================================================================
961 Factory::Pointer WxGUIPackageBrowser2::GetFactory()
966 //================================================================
969 //================================================================
970 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
974 //================================================================
976 //================================================================
977 // User callback when a box is selected in the list
978 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
979 ( BlackBoxDescriptor* d)
984 mBoxInfo->UpdateInfo(d);
985 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
986 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
990 //================================================================
992 //================================================================
993 BlackBoxDescriptor* WxGUIPackageBrowser2::GetActualSelected()
995 return _actualSelected;
998 //================================================================
1000 //================================================================
1001 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
1004 mInterpreter.reset();
1005 // Object::PrintObjectListInfo("");
1008 //================================================================
1010 //================================================================
1011 void WxGUIPackageBrowser2::IncludeAll()
1013 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
1014 mInterpreter->SetCommandLine(true);
1015 std::stringstream* buf = new std::stringstream;
1016 *buf << "exec freeze_no_error" << std::endl;
1017 *buf << "message max 0" << std::endl;
1018 *buf << "include *" << std::endl;
1019 mInterpreter->InterpretBuffer(buf);
1021 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
1022 BuildFromFactory(F);
1024 //================================================================
1026 //================================================================
1027 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
1033 //================================================================
1035 //================================================================
1036 void WxGUIPackageBrowser2::RebuildList()
1039 mBoxList->ClearAll();
1041 const Factory::PackageMapType& M = mFactory->GetPackageMap();
1042 Factory::PackageMapType::const_iterator i;
1043 for (i=M.begin();i!=M.end();++i)
1045 Package::Pointer P = i->second;
1046 if (P->GetName() == "user") continue;
1048 Package::DescriptorMapType::iterator j;
1049 for (j=P->GetDescriptorMap().begin();
1050 j!=P->GetDescriptorMap().end();
1053 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
1054 if (IsVisible(j->second))
1055 mBoxList->Insert(j->second);
1060 //================================================================
1062 bool WxGUIPackageBrowser2::findnpos(const std::string &strA, const std::string &strB )
1064 if ((strB=="") || (strA=="") )
1071 std::string strAA=strA;
1072 std::string strBB=strB;
1075 size=strAA.length();
1076 for (i=0;i<size;i++)
1078 if ((strAA[i]>='A')&&(strAA[i]<='Z'))
1080 strAA[i]=strAA[i]+32;
1084 size=strBB.length();
1085 for (i=0;i<size;i++)
1087 if ((strBB[i]>='A')&&(strBB[i]<='Z'))
1089 strBB[i]=strBB[i]+32;
1094 if ( strAA.find(strBB) == std::string::npos )
1102 //================================================================
1103 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
1105 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
1106 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
1107 if ((!mShowAdaptorsFilter->IsChecked())&&
1108 ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
1109 (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
1114 if ((!mShowGUIsFilter->IsChecked())&&
1115 ((d->GetKind()==BlackBoxDescriptor::GUI)||
1116 (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
1121 //EED if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) ) == std::string::npos )
1122 if ( findnpos(d->GetPackage()->GetName(),wx2std(mPackageFilter->GetValue())) == true )
1127 //EED if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) ) == std::string::npos )
1128 if ( findnpos(d->GetTypeName(),wx2std(mNameFilter->GetValue())) == true )
1133 //EED if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) ) == std::string::npos )
1134 if ( findnpos(d->GetDescription(),wx2std(mDescriptionFilter->GetValue())) == true )
1139 //EED if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) ) == std::string::npos )
1140 if ( findnpos(d->GetCategory(),wx2std(mCategoryFilter->GetValue())) == true )
1145 if (!mShowWidgetsFilter->IsChecked())
1148 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1149 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1150 for ( in = imap.begin(); in != imap.end(); ++in )
1152 if (in->second->GetName() == "Widget" )
1164 if (mInputTypeFilter->GetValue().size()>0)
1166 std::string s = wx2std(mInputTypeFilter->GetValue());
1168 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
1169 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1170 for ( in = imap.begin(); in != imap.end(); ++in )
1172 //EED if (in->second->GetTypeName().find(s)!=std::string::npos)
1173 if ( findnpos( in->second->GetTypeName() , s ) == true )
1185 if (mOutputTypeFilter->GetValue().size()>0)
1187 std::string s = wx2std(mOutputTypeFilter->GetValue());
1189 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1190 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1191 for ( in = imap.begin(); in != imap.end(); ++in )
1193 //EED if (in->second->GetTypeName().find(s)!=std::string::npos)
1194 if ( findnpos( in->second->GetTypeName() , s ) == true )
1206 if (mInputNatureFilter->GetValue().size()>0)
1208 std::string s = wx2std(mInputNatureFilter->GetValue());
1210 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
1211 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1212 for ( in = imap.begin(); in != imap.end(); ++in )
1214 //EED if (in->second->GetNature().find(s)!=std::string::npos)
1215 if ( findnpos( in->second->GetNature() , s ) == true )
1227 if (mOutputNatureFilter->GetValue().size()>0)
1229 std::string s = wx2std(mOutputNatureFilter->GetValue());
1231 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1232 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1233 for ( in = imap.begin(); in != imap.end(); ++in )
1235 //EED if (in->second->GetNature().find(s)!=std::string::npos)
1236 if ( findnpos( in->second->GetNature() , s ) == true )
1251 //========================================================================
1253 //========================================================================
1254 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1255 //EED EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1256 //EED EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1257 //EED EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1258 //EED EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1259 //EED EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1260 //EED EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1261 //EED EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
1262 //EED EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
1264 EVT_TEXT(id_f1, WxGUIPackageBrowser2::OnFilter )
1265 EVT_TEXT(id_f2, WxGUIPackageBrowser2::OnFilter )
1266 EVT_TEXT(id_f3, WxGUIPackageBrowser2::OnFilter )
1267 EVT_TEXT(id_f4, WxGUIPackageBrowser2::OnFilter )
1268 EVT_TEXT(id_f5, WxGUIPackageBrowser2::OnFilter )
1269 EVT_TEXT(id_f6, WxGUIPackageBrowser2::OnFilter )
1270 EVT_TEXT(id_f7, WxGUIPackageBrowser2::OnFilter )
1271 EVT_TEXT(id_f8, WxGUIPackageBrowser2::OnFilter )
1273 EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
1274 EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
1275 EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
1277 //========================================================================
1281 //================================================================
1282 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1285 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1287 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1289 mBrowser = new WxGUIPackageBrowser2(this);
1290 mBrowser->IncludeAll();
1291 sizer->Add(mBrowser,1,wxGROW);
1293 // WxGUICommand* com = new WxGUICommand(this,this);
1298 // Creates the parent window of all bbtk windows as a child of this
1299 // Wx::CreateTopWindow(this);
1300 // Add the method OnWxSignal as a Wx::Signal observer
1301 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
1303 SetAutoLayout(true);
1306 //================================================================
1308 //================================================================
1309 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1312 //================================================================
1317 #endif //_USE_WXWIDGETS_