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 //DFGO -> To identify it is a box
268 sendtext += crea::std2wx("box:");
269 sendtext += crea::std2wx(d->GetFullTypeName());
274 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
277 wxTextDataObject tdo(sendtext);
278 wxDropSource tds(tdo, this);
281 // const wxPoint& pt = event.m_pointDrag;
283 //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
284 // pt.x, pt.y, HitTest(pt, flags) );
287 void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
289 //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
290 // event.m_pointDrag.x, event.m_pointDrag.y );
293 void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
295 //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
298 void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
300 //wxLogMessage( wxT("OnEndLabelEdit: %s"),
301 // event.IsEditCancelled() ? _T("[cancelled]")
302 // : event.m_item.m_text.c_str());
305 void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
307 LogEvent(event, _T("OnDeleteItem"));
308 std::cout << "cannot del"<<std::endl;
310 //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
313 void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
315 LogEvent(event, _T("OnDeleteAllItems"));
319 #if WXWIN_COMPATIBILITY_2_4
320 void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
324 msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
325 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
326 msg << _T(" wxLIST_MASK_STATE");
327 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
328 msg << _T(" wxLIST_MASK_TEXT");
329 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
330 msg << _T(" wxLIST_MASK_IMAGE");
331 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
332 msg << _T(" wxLIST_MASK_DATA");
333 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
334 msg << _T(" wxLIST_SET_ITEM");
335 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
336 msg << _T(" wxLIST_MASK_WIDTH");
337 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
338 msg << _T(" wxLIST_MASK_WIDTH");
340 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
342 event.m_item.m_text = _T("My callback text");
348 void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
350 LogEvent(event, _T("OnSetInfo"));
354 void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
356 if (mUser==0) return;
359 info.m_itemId = event.m_itemIndex;
361 info.m_mask = wxLIST_MASK_DATA;
364 // TO DO : STORE SMART PTR ?
365 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
366 if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
370 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
374 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
376 LogEvent(event, _T("OnDeselected"));
379 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
381 LogEvent(event, _T("OnActivated"));
384 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
386 LogEvent(event, _T("OnFocused"));
391 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
395 switch ( event.GetKeyCode() )
397 case 'c': // colorize
401 info.m_itemId = event.GetIndex();
402 if ( info.m_itemId == -1 )
410 wxListItemAttr *attr = info.GetAttributes();
411 if ( !attr || !attr->HasTextColour() )
413 info.SetTextColour(*wxCYAN);
417 RefreshItem(info.m_itemId);
424 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
425 if ( item++ == GetItemCount() - 1 )
430 //wxLogMessage(_T("Focusing item %ld"), item);
432 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
436 case 'r': // show bounding Rect
439 item = event.GetIndex();
441 if ( !GetItemRect(item, r) )
443 //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
447 //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
448 // item, r.x, r.y, r.x + r.width, r.y + r.height);
453 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
459 //wxLogMessage(_T("Item %ld deleted"), item);
461 // -1 because the indices were shifted by DeleteItem()
462 item = GetNextItem(item - 1,
463 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
469 if ( GetWindowStyle() & wxLC_REPORT )
471 if ( GetWindowStyle() & wxLC_VIRTUAL )
473 SetItemCount(GetItemCount() + 1);
477 //InsertItemInReportView(event.GetIndex());
483 LogEvent(event, _T("OnListKeyDown"));
489 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
491 //wxLogMessage(_T("Got char event."));
493 switch ( event.GetKeyCode() )
499 // these are the keys we process ourselves
507 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
509 if ( !event.ControlDown() )
518 HitTest(event.GetPosition(), flags, &subitem);
523 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
524 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
525 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
526 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
527 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
528 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
529 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
530 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
531 default: where = _T("not clear exactly where on"); break;
534 //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
535 // where.c_str(), item, subitem);
538 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
540 //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
541 // event.GetIndex(), eventName,
542 // event.GetText().c_str(), event.GetData());
545 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
548 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
550 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
555 return wxString::Format(_T("Column %ld of item %ld"), column, item);
559 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
564 if (!(item %3) && column == 1)
570 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
572 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
577 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
579 wxPoint point = event.GetPosition();
581 if (point.x == -1 && point.y == -1) {
582 wxSize size = GetSize();
583 point.x = size.x / 2;
584 point.y = size.y / 2;
586 point = ScreenToClient(point);
588 ShowContextMenu(point);
592 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
596 menu.Append(wxID_ABOUT, _T("&About"));
597 menu.AppendSeparator();
598 menu.Append(wxID_EXIT, _T("E&xit"));
600 PopupMenu(&menu, pos.x, pos.y);
602 //================================================================
606 //================================================================
607 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
612 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
614 // mName = new wxStaticText(this,-1,_T(""));
615 // sizer->Add(mName,0,wxGROW);
616 mDescription = new wxStaticText(this,-1,_T(""));
617 sizer->Add(mDescription,0,wxGROW);
618 mAuthor = new wxStaticText(this,-1,_T(""));
619 sizer->Add(mAuthor,0,wxGROW);
620 mCategory = new wxStaticText(this,-1,_T(""));
621 sizer->Add(mCategory,0,wxGROW);
625 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
626 mInputList = new wxListCtrl(this, -1,
629 wxLC_REPORT //wxLC_LIST
632 inputs->Add(mInputList,1,wxGROW);
633 sizer->Add(inputs,1,wxGROW);
635 wxBoxSizer *outputs =
637 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
638 mOutputList = new wxListCtrl(this, -1,
641 wxLC_REPORT //wxLC_LIST
644 outputs->Add(mOutputList,1,wxGROW);
645 sizer->Add(outputs,1,wxGROW);
651 //================================================================
654 //================================================================
655 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
658 // mName->SetLabel(std2wx(descr->GetTypeName()));
659 mDescription->SetLabel(std2wx(descr->GetDescription()));
660 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
661 mCategory->SetLabel(std2wx(descr->GetCategory()));
663 mInputList->ClearAll();
664 mInputList->InsertColumn( 0, _("Name"),
665 wxLIST_FORMAT_LEFT, 80 );
666 mInputList->InsertColumn( 1, _("Type"),
667 wxLIST_FORMAT_LEFT, 100 );
668 mInputList->InsertColumn( 2, _("Nature"),
669 wxLIST_FORMAT_LEFT, 100 );
670 mInputList->InsertColumn( 3, _("Description"),
671 wxLIST_FORMAT_LEFT, 500 );
673 mOutputList->ClearAll();
674 mOutputList->InsertColumn( 0, _("Name"),
675 wxLIST_FORMAT_LEFT, 80 );
676 mOutputList->InsertColumn( 1, _("Type"),
677 wxLIST_FORMAT_LEFT, 100 );
678 mOutputList->InsertColumn( 2, _("Nature"),
679 wxLIST_FORMAT_LEFT, 100 );
680 mOutputList->InsertColumn( 3, _("Description"),
681 wxLIST_FORMAT_LEFT, 500 );
684 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
685 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
686 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
688 const BlackBoxDescriptor::InputDescriptorMapType& imap =
689 descr->GetInputDescriptorMap();
690 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
691 for ( in = imap.begin(); in != imap.end(); ++in )
694 if (in->second->GetCreatorTypeInfo() ==
695 typeid(AtomicBlackBoxDescriptor))
699 else if (in->second->GetCreatorTypeInfo() ==
700 typeid(WxBlackBoxDescriptor))
704 if (iotype==0) user_defined.push_back(in->second);
705 else if (iotype==1) ubb_defined.push_back(in->second);
706 else if (iotype==2) wxbb_defined.push_back(in->second);
710 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
711 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
713 InsertInputOutput(mInputList,*hi);
715 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
717 InsertInputOutput(mInputList,*hi);
719 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
721 InsertInputOutput(mInputList,*hi);
725 user_defined.clear();
727 wxbb_defined.clear();
728 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
729 descr->GetOutputDescriptorMap();
730 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
731 for ( out = omap.begin(); out != omap.end(); ++out )
734 if (out->second->GetCreatorTypeInfo() ==
735 typeid(AtomicBlackBoxDescriptor))
739 else if (out->second->GetCreatorTypeInfo() ==
740 typeid(WxBlackBoxDescriptor))
745 if (iotype==0) user_defined.push_back(out->second);
746 else if (iotype==1) ubb_defined.push_back(out->second);
747 else if (iotype==2) wxbb_defined.push_back(out->second);
750 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
752 InsertInputOutput(mOutputList,*hi);
754 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
756 InsertInputOutput(mOutputList,*hi);
758 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
760 InsertInputOutput(mOutputList,*hi);
763 //================================================================
766 //================================================================
767 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
768 BlackBoxInputOutputDescriptor* d)
771 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
772 int nID = l->GetItemCount();
773 // std::cout << nID << std::endl;
775 // kNewItem.SetMask(wxLIST_MASK_DATA);
776 // kNewItem.SetData(d);
777 l->InsertItem(kNewItem);
778 l->SetItem(nID, 0, std2wx(d->GetName()) );
779 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
780 l->SetItem(nID, 2, std2wx(d->GetNature()) );
781 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
783 //================================================================
785 //================================================================
786 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
789 //================================================================
807 //================================================================
808 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
809 WxGUIPackageBrowser2User* user )
810 : wxPanel(parent, -1),
814 _actualSelected=NULL;
815 m_mgr.SetManagedWindow(this);
817 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
818 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
821 wxLC_REPORT //wxLC_LIST
823 mBoxList->SetUser(this);
824 mBoxList->SetBackgroundColour(*wxWHITE);
827 // JGRR & CM DISABLED CLOSE BUTTON
828 m_mgr.AddPane(mBoxList,
829 wxAuiPaneInfo().Name(wxT("BoxList"))
830 .Caption(wxT("Black Boxes"))
831 .MinimizeButton(true)
832 .MaximizeButton(true)
834 .MinSize(wxSize(100,100))
837 // sizer->Add(mBoxList,5,wxGROW);
839 mBoxInfo = new WxGUIBlackBoxInfo(this);
840 // sizer->Add(mBoxInfo,3,wxGROW);
842 // JGRR & CM DISABLED CLOSE BUTTON
843 m_mgr.AddPane(mBoxInfo,
844 wxAuiPaneInfo().Name(wxT("Box"))
846 .MinimizeButton(true)
847 .MaximizeButton(true)
849 .MinSize(wxSize(100,200))
853 wxPanel* filters = new wxPanel(this,-1);
854 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
857 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
858 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
862 fpack->Add(mPackageFilter,1,wxGROW);
863 fsizer->Add(fpack,0,wxGROW);
866 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
867 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
871 fname->Add(mNameFilter,1,wxGROW);
872 fsizer->Add(fname,0,wxGROW);
875 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
876 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
880 fdescr->Add(mDescriptionFilter,1,wxGROW);
881 fsizer->Add(fdescr,0,wxGROW);
884 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
885 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
889 fcat->Add(mCategoryFilter,1,wxGROW);
890 fsizer->Add(fcat,0,wxGROW);
891 wxBoxSizer *fintype =
893 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
894 mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
898 fintype->Add(mInputTypeFilter,1,wxGROW);
899 fsizer->Add(fintype,0,wxGROW);
900 wxBoxSizer *fouttype =
902 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
903 mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
907 fouttype->Add(mOutputTypeFilter,1,wxGROW);
908 fsizer->Add(fouttype,0,wxGROW);
911 ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL );
912 mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
916 finnat->Add(mInputNatureFilter,1,wxGROW);
917 fsizer->Add(finnat,0,wxGROW);
918 wxBoxSizer *foutnat =
920 ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL );
921 mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
925 foutnat->Add(mOutputNatureFilter,1,wxGROW);
926 fsizer->Add(foutnat,0,wxGROW);
928 mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
929 mShowWidgetsFilter->SetValue(true);
930 fsizer->Add(mShowWidgetsFilter,0,wxGROW);
932 mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
933 mShowAdaptorsFilter->SetValue(false);
934 fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
936 mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
937 mShowGUIsFilter->SetValue(false);
938 fsizer->Add(mShowGUIsFilter,0,wxGROW);
940 filters->SetSizer(fsizer);
942 // JGRR & CM DISABLED CLOSE BUTTON
943 m_mgr.AddPane(filters,
944 wxAuiPaneInfo().Name(wxT("Filter"))
945 .Caption(wxT("Filter"))
946 .MinimizeButton(true)
947 .MaximizeButton(true)
949 .MinSize(wxSize(100,100))
953 // sizer->Add(fsizer,1,wxGROW);
961 //================================================================
963 Factory::Pointer WxGUIPackageBrowser2::GetFactory()
968 //================================================================
971 //================================================================
972 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
976 //================================================================
978 //================================================================
979 // User callback when a box is selected in the list
980 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
981 ( BlackBoxDescriptor* d)
986 mBoxInfo->UpdateInfo(d);
987 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
988 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
992 //================================================================
994 //================================================================
995 BlackBoxDescriptor* WxGUIPackageBrowser2::GetActualSelected()
997 return _actualSelected;
1000 //================================================================
1002 //================================================================
1003 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
1006 mInterpreter.reset();
1007 // Object::PrintObjectListInfo("");
1010 //================================================================
1012 //================================================================
1013 void WxGUIPackageBrowser2::IncludeAll()
1015 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
1016 mInterpreter->SetCommandLine(true);
1017 std::stringstream* buf = new std::stringstream;
1018 *buf << "exec freeze_no_error" << std::endl;
1019 *buf << "message max 0" << std::endl;
1020 *buf << "include *" << std::endl;
1021 mInterpreter->InterpretBuffer(buf);
1023 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
1024 BuildFromFactory(F);
1026 //================================================================
1028 //================================================================
1029 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
1035 //================================================================
1037 //================================================================
1038 void WxGUIPackageBrowser2::RebuildList()
1041 mBoxList->ClearAll();
1043 const Factory::PackageMapType& M = mFactory->GetPackageMap();
1044 Factory::PackageMapType::const_iterator i;
1045 for (i=M.begin();i!=M.end();++i)
1047 Package::Pointer P = i->second;
1048 if (P->GetName() == "user") continue;
1050 Package::DescriptorMapType::iterator j;
1051 for (j=P->GetDescriptorMap().begin();
1052 j!=P->GetDescriptorMap().end();
1055 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
1056 if (IsVisible(j->second))
1057 mBoxList->Insert(j->second);
1062 //================================================================
1064 bool WxGUIPackageBrowser2::findnpos(const std::string &strA, const std::string &strB )
1066 if ((strB=="") || (strA=="") )
1073 std::string strAA=strA;
1074 std::string strBB=strB;
1077 size=strAA.length();
1078 for (i=0;i<size;i++)
1080 if ((strAA[i]>='A')&&(strAA[i]<='Z'))
1082 strAA[i]=strAA[i]+32;
1086 size=strBB.length();
1087 for (i=0;i<size;i++)
1089 if ((strBB[i]>='A')&&(strBB[i]<='Z'))
1091 strBB[i]=strBB[i]+32;
1096 if ( strAA.find(strBB) == std::string::npos )
1104 //================================================================
1105 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
1107 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
1108 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
1109 if ((!mShowAdaptorsFilter->IsChecked())&&
1110 ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
1111 (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
1116 if ((!mShowGUIsFilter->IsChecked())&&
1117 ((d->GetKind()==BlackBoxDescriptor::GUI)||
1118 (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
1123 //EED if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) ) == std::string::npos )
1124 if ( findnpos(d->GetPackage()->GetName(),wx2std(mPackageFilter->GetValue())) == true )
1129 //EED if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) ) == std::string::npos )
1130 if ( findnpos(d->GetTypeName(),wx2std(mNameFilter->GetValue())) == true )
1135 //EED if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) ) == std::string::npos )
1136 if ( findnpos(d->GetDescription(),wx2std(mDescriptionFilter->GetValue())) == true )
1141 //EED if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) ) == std::string::npos )
1142 if ( findnpos(d->GetCategory(),wx2std(mCategoryFilter->GetValue())) == true )
1147 if (!mShowWidgetsFilter->IsChecked())
1150 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1151 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1152 for ( in = imap.begin(); in != imap.end(); ++in )
1154 if (in->second->GetName() == "Widget" )
1166 if (mInputTypeFilter->GetValue().size()>0)
1168 std::string s = wx2std(mInputTypeFilter->GetValue());
1170 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
1171 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1172 for ( in = imap.begin(); in != imap.end(); ++in )
1174 //EED if (in->second->GetTypeName().find(s)!=std::string::npos)
1175 if ( findnpos( in->second->GetTypeName() , s ) == true )
1187 if (mOutputTypeFilter->GetValue().size()>0)
1189 std::string s = wx2std(mOutputTypeFilter->GetValue());
1191 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1192 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1193 for ( in = imap.begin(); in != imap.end(); ++in )
1195 //EED if (in->second->GetTypeName().find(s)!=std::string::npos)
1196 if ( findnpos( in->second->GetTypeName() , s ) == true )
1208 if (mInputNatureFilter->GetValue().size()>0)
1210 std::string s = wx2std(mInputNatureFilter->GetValue());
1212 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
1213 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1214 for ( in = imap.begin(); in != imap.end(); ++in )
1216 //EED if (in->second->GetNature().find(s)!=std::string::npos)
1217 if ( findnpos( in->second->GetNature() , s ) == true )
1229 if (mOutputNatureFilter->GetValue().size()>0)
1231 std::string s = wx2std(mOutputNatureFilter->GetValue());
1233 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1234 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1235 for ( in = imap.begin(); in != imap.end(); ++in )
1237 //EED if (in->second->GetNature().find(s)!=std::string::npos)
1238 if ( findnpos( in->second->GetNature() , s ) == true )
1253 //========================================================================
1255 //========================================================================
1256 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1257 //EED EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1258 //EED EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1259 //EED EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1260 //EED EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1261 //EED EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1262 //EED EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1263 //EED EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
1264 //EED EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
1266 EVT_TEXT(id_f1, WxGUIPackageBrowser2::OnFilter )
1267 EVT_TEXT(id_f2, WxGUIPackageBrowser2::OnFilter )
1268 EVT_TEXT(id_f3, WxGUIPackageBrowser2::OnFilter )
1269 EVT_TEXT(id_f4, WxGUIPackageBrowser2::OnFilter )
1270 EVT_TEXT(id_f5, WxGUIPackageBrowser2::OnFilter )
1271 EVT_TEXT(id_f6, WxGUIPackageBrowser2::OnFilter )
1272 EVT_TEXT(id_f7, WxGUIPackageBrowser2::OnFilter )
1273 EVT_TEXT(id_f8, WxGUIPackageBrowser2::OnFilter )
1275 EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
1276 EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
1277 EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
1279 //========================================================================
1283 //================================================================
1284 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1287 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1289 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1291 mBrowser = new WxGUIPackageBrowser2(this);
1292 mBrowser->IncludeAll();
1293 sizer->Add(mBrowser,1,wxGROW);
1295 // WxGUICommand* com = new WxGUICommand(this,this);
1300 // Creates the parent window of all bbtk windows as a child of this
1301 // Wx::CreateTopWindow(this);
1302 // Add the method OnWxSignal as a Wx::Signal observer
1303 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
1305 SetAutoLayout(true);
1308 //================================================================
1310 //================================================================
1311 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1314 //================================================================
1319 #endif //_USE_WXWIDGETS_