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))
123 WxGUIBlackBoxList::WxGUIBlackBoxList(wxWindow *parent,
128 : wxListCtrl(parent, id, pos, size, style),
130 m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
137 void WxGUIBlackBoxList::Insert(BlackBoxDescriptor::Pointer d)
139 if (GetColumnCount()!=3)
141 InsertColumn( 0, _("Package"),
142 wxLIST_FORMAT_LEFT, 90 );
143 InsertColumn( 1, _("Box"),
144 wxLIST_FORMAT_LEFT, 150 );
145 InsertColumn( 2, _("Description"),
146 wxLIST_FORMAT_LEFT, 500 );
150 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
152 int nID = this->GetItemCount();
154 kNewItem.SetMask(wxLIST_MASK_DATA);
155 // TO DO : STORE SMART POINTER ?
156 kNewItem.SetData(d.get());
157 // BlackBoxDescriptor::Pointer* d2 = (BlackBoxDescriptor::Pointer*)kNewItem.GetData();
158 // std::cout << "Descr = "<<d<<" = "<<d2<<std::endl;
159 this->InsertItem(kNewItem);
160 this->SetItem(nID, 0, std2wx(d->GetPackage()->GetName()) );
161 this->SetItem(nID, 1, std2wx(d->GetTypeName()) );
162 this->SetItem(nID, 2, std2wx(d->GetDescription()) );
167 kNewItem.SetBackgroundColour(wxColour(192,192,192));
168 this->SetItem(kNewItem);
174 void WxGUIBlackBoxList::OnCacheHint(wxListEvent& event)
176 //wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"),
177 // event.GetCacheFrom(), event.GetCacheTo() );
180 void WxGUIBlackBoxList::SetColumnImage(int col, int image)
184 item.SetMask(wxLIST_MASK_IMAGE);
185 item.SetImage(image);
186 SetColumn(col, item);
190 void WxGUIBlackBoxList::OnColClick(wxListEvent& event)
192 int col = event.GetColumn();
194 // set or unset image
195 static bool x = false;
197 SetColumnImage(col, x ? 0 : -1);
199 // wxLogMessage( wxT("OnColumnClick at %d."), col );
202 void WxGUIBlackBoxList::OnColRightClick(wxListEvent& event)
204 int col = event.GetColumn();
207 SetColumnImage(col, -1);
210 // Show popupmenu at position
211 wxMenu menu(wxT("Test"));
212 menu.Append(-1, _T("&About"));
213 PopupMenu(&menu, event.GetPoint());
215 //wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
218 void WxGUIBlackBoxList::LogColEvent(const wxListEvent& event, const wxChar *name)
220 // const int col = event.GetColumn();
223 wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
226 event.GetItem().GetWidth(),
227 GetColumnWidth(col));
231 void WxGUIBlackBoxList::OnColBeginDrag(wxListEvent& event)
233 LogColEvent( event, wxT("OnColBeginDrag") );
235 if ( event.GetColumn() == 0 )
237 //wxLogMessage(_T("Resizing this column shouldn't work."));
244 void WxGUIBlackBoxList::OnColDragging(wxListEvent& event)
246 LogColEvent( event, wxT("OnColDragging") );
249 void WxGUIBlackBoxList::OnColEndDrag(wxListEvent& event)
251 LogColEvent( event, wxT("OnColEndDrag") );
254 void WxGUIBlackBoxList::OnBeginDrag(wxListEvent& event)
256 std::cout<<"RaC DRAG TABLE"<<std::endl;
258 wxString text(this->GetItemText(event.GetIndex()));
260 info.m_itemId = event.m_itemIndex;
262 info.m_mask = wxLIST_MASK_DATA;
263 wxString sendtext(_T(""));
266 // TO DO : STORE SMART PTR ?
267 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
270 //DFGO -> To identify it is a box
271 sendtext += crea::std2wx("box:");
272 sendtext += crea::std2wx(d->GetFullTypeName());
277 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
280 wxTextDataObject tdo(sendtext);
281 wxDropSource tds(tdo, this);
284 // const wxPoint& pt = event.m_pointDrag;
286 //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
287 // pt.x, pt.y, HitTest(pt, flags) );
290 void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
292 //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
293 // event.m_pointDrag.x, event.m_pointDrag.y );
296 void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
298 //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
301 void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
303 //wxLogMessage( wxT("OnEndLabelEdit: %s"),
304 // event.IsEditCancelled() ? _T("[cancelled]")
305 // : event.m_item.m_text.c_str());
308 void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
310 LogEvent(event, _T("OnDeleteItem"));
311 std::cout << "cannot del"<<std::endl;
313 //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
316 void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
318 LogEvent(event, _T("OnDeleteAllItems"));
322 #if WXWIN_COMPATIBILITY_2_4
323 void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
327 msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
328 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
329 msg << _T(" wxLIST_MASK_STATE");
330 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
331 msg << _T(" wxLIST_MASK_TEXT");
332 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
333 msg << _T(" wxLIST_MASK_IMAGE");
334 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
335 msg << _T(" wxLIST_MASK_DATA");
336 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
337 msg << _T(" wxLIST_SET_ITEM");
338 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
339 msg << _T(" wxLIST_MASK_WIDTH");
340 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
341 msg << _T(" wxLIST_MASK_WIDTH");
343 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
345 event.m_item.m_text = _T("My callback text");
351 void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
353 LogEvent(event, _T("OnSetInfo"));
357 void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
359 if (mUser==0) return;
362 info.m_itemId = event.m_itemIndex;
364 info.m_mask = wxLIST_MASK_DATA;
367 // TO DO : STORE SMART PTR ?
368 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
369 if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
373 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
377 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
379 LogEvent(event, _T("OnDeselected"));
382 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
384 LogEvent(event, _T("OnActivated"));
387 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
389 LogEvent(event, _T("OnFocused"));
394 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
398 switch ( event.GetKeyCode() )
400 case 'c': // colorize
404 info.m_itemId = event.GetIndex();
405 if ( info.m_itemId == -1 )
413 wxListItemAttr *attr = info.GetAttributes();
414 if ( !attr || !attr->HasTextColour() )
416 info.SetTextColour(*wxCYAN);
420 RefreshItem(info.m_itemId);
427 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
428 if ( item++ == GetItemCount() - 1 )
433 //wxLogMessage(_T("Focusing item %ld"), item);
435 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
439 case 'r': // show bounding Rect
442 item = event.GetIndex();
444 if ( !GetItemRect(item, r) )
446 //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
450 //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
451 // item, r.x, r.y, r.x + r.width, r.y + r.height);
456 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
462 //wxLogMessage(_T("Item %ld deleted"), item);
464 // -1 because the indices were shifted by DeleteItem()
465 item = GetNextItem(item - 1,
466 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
472 if ( GetWindowStyle() & wxLC_REPORT )
474 if ( GetWindowStyle() & wxLC_VIRTUAL )
476 SetItemCount(GetItemCount() + 1);
480 //InsertItemInReportView(event.GetIndex());
486 LogEvent(event, _T("OnListKeyDown"));
492 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
494 //wxLogMessage(_T("Got char event."));
496 switch ( event.GetKeyCode() )
502 // these are the keys we process ourselves
510 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
512 if ( !event.ControlDown() )
521 HitTest(event.GetPosition(), flags, &subitem);
526 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
527 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
528 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
529 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
530 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
531 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
532 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
533 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
534 default: where = _T("not clear exactly where on"); break;
537 //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
538 // where.c_str(), item, subitem);
541 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
543 //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
544 // event.GetIndex(), eventName,
545 // event.GetText().c_str(), event.GetData());
548 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
551 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
553 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
558 return wxString::Format(_T("Column %ld of item %ld"), column, item);
562 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
567 if (!(item %3) && column == 1)
573 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
575 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
580 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
582 wxPoint point = event.GetPosition();
584 if (point.x == -1 && point.y == -1) {
585 wxSize size = GetSize();
586 point.x = size.x / 2;
587 point.y = size.y / 2;
589 point = ScreenToClient(point);
591 ShowContextMenu(point);
595 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
599 menu.Append(wxID_ABOUT, _T("&About"));
600 menu.AppendSeparator();
601 menu.Append(wxID_EXIT, _T("E&xit"));
603 PopupMenu(&menu, pos.x, pos.y);
605 //================================================================
609 //================================================================
610 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
615 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
617 // mName = new wxStaticText(this,-1,_T(""));
618 // sizer->Add(mName,0,wxGROW);
619 mDescription = new wxStaticText(this,-1,_T(""));
620 sizer->Add(mDescription,0,wxGROW);
621 mAuthor = new wxStaticText(this,-1,_T(""));
622 sizer->Add(mAuthor,0,wxGROW);
623 mCategory = new wxStaticText(this,-1,_T(""));
624 sizer->Add(mCategory,0,wxGROW);
628 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
629 mInputList = new wxListCtrl(this, -1,
632 wxLC_REPORT //wxLC_LIST
635 inputs->Add(mInputList,1,wxGROW);
636 sizer->Add(inputs,1,wxGROW);
638 wxBoxSizer *outputs =
640 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
641 mOutputList = new wxListCtrl(this, -1,
644 wxLC_REPORT //wxLC_LIST
647 outputs->Add(mOutputList,1,wxGROW);
648 sizer->Add(outputs,1,wxGROW);
654 //================================================================
657 //================================================================
658 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
661 // mName->SetLabel(std2wx(descr->GetTypeName()));
662 mDescription->SetLabel(std2wx(descr->GetDescription()));
663 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
664 mCategory->SetLabel(std2wx(descr->GetCategory()));
666 mInputList->ClearAll();
667 mInputList->InsertColumn( 0, _("Name"),
668 wxLIST_FORMAT_LEFT, 80 );
669 mInputList->InsertColumn( 1, _("Type"),
670 wxLIST_FORMAT_LEFT, 100 );
671 mInputList->InsertColumn( 2, _("Nature"),
672 wxLIST_FORMAT_LEFT, 100 );
673 mInputList->InsertColumn( 3, _("Description"),
674 wxLIST_FORMAT_LEFT, 500 );
676 mOutputList->ClearAll();
677 mOutputList->InsertColumn( 0, _("Name"),
678 wxLIST_FORMAT_LEFT, 80 );
679 mOutputList->InsertColumn( 1, _("Type"),
680 wxLIST_FORMAT_LEFT, 100 );
681 mOutputList->InsertColumn( 2, _("Nature"),
682 wxLIST_FORMAT_LEFT, 100 );
683 mOutputList->InsertColumn( 3, _("Description"),
684 wxLIST_FORMAT_LEFT, 500 );
687 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
688 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
689 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
691 const BlackBoxDescriptor::InputDescriptorMapType& imap =
692 descr->GetInputDescriptorMap();
693 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
694 for ( in = imap.begin(); in != imap.end(); ++in )
697 if (in->second->GetCreatorTypeInfo() ==
698 typeid(AtomicBlackBoxDescriptor))
702 else if (in->second->GetCreatorTypeInfo() ==
703 typeid(WxBlackBoxDescriptor))
707 if (iotype==0) user_defined.push_back(in->second);
708 else if (iotype==1) ubb_defined.push_back(in->second);
709 else if (iotype==2) wxbb_defined.push_back(in->second);
713 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
714 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
716 InsertInputOutput(mInputList,*hi);
718 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
720 InsertInputOutput(mInputList,*hi);
722 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
724 InsertInputOutput(mInputList,*hi);
728 user_defined.clear();
730 wxbb_defined.clear();
731 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
732 descr->GetOutputDescriptorMap();
733 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
734 for ( out = omap.begin(); out != omap.end(); ++out )
737 if (out->second->GetCreatorTypeInfo() ==
738 typeid(AtomicBlackBoxDescriptor))
742 else if (out->second->GetCreatorTypeInfo() ==
743 typeid(WxBlackBoxDescriptor))
748 if (iotype==0) user_defined.push_back(out->second);
749 else if (iotype==1) ubb_defined.push_back(out->second);
750 else if (iotype==2) wxbb_defined.push_back(out->second);
753 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
755 InsertInputOutput(mOutputList,*hi);
757 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
759 InsertInputOutput(mOutputList,*hi);
761 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
763 InsertInputOutput(mOutputList,*hi);
766 //================================================================
769 //================================================================
770 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
771 BlackBoxInputOutputDescriptor* d)
774 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
775 int nID = l->GetItemCount();
776 // std::cout << nID << std::endl;
778 // kNewItem.SetMask(wxLIST_MASK_DATA);
779 // kNewItem.SetData(d);
780 l->InsertItem(kNewItem);
781 l->SetItem(nID, 0, std2wx(d->GetName()) );
782 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
783 l->SetItem(nID, 2, std2wx(d->GetNature()) );
784 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
786 //================================================================
788 //================================================================
789 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
792 //================================================================
810 //================================================================
811 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
812 WxGUIPackageBrowser2User* user )
813 : wxPanel(parent, -1),
817 _actualSelected=NULL;
818 m_mgr.SetManagedWindow(this);
820 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
821 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
824 wxLC_REPORT //wxLC_LIST
826 mBoxList->SetUser(this);
827 mBoxList->SetBackgroundColour(*wxWHITE);
830 // JGRR & CM DISABLED CLOSE BUTTON
831 m_mgr.AddPane(mBoxList,
832 wxAuiPaneInfo().Name(wxT("BoxList"))
833 .Caption(wxT("Black Boxes"))
834 .MinimizeButton(true)
835 .MaximizeButton(true)
837 .MinSize(wxSize(100,100))
840 // sizer->Add(mBoxList,5,wxGROW);
842 mBoxInfo = new WxGUIBlackBoxInfo(this);
843 // sizer->Add(mBoxInfo,3,wxGROW);
845 // JGRR & CM DISABLED CLOSE BUTTON
846 m_mgr.AddPane(mBoxInfo,
847 wxAuiPaneInfo().Name(wxT("Box"))
849 .MinimizeButton(true)
850 .MaximizeButton(true)
852 .MinSize(wxSize(100,200))
856 wxPanel* filters = new wxPanel(this,-1);
857 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
860 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
861 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
865 fpack->Add(mPackageFilter,1,wxGROW);
866 fsizer->Add(fpack,0,wxGROW);
869 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
870 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
874 fname->Add(mNameFilter,1,wxGROW);
875 fsizer->Add(fname,0,wxGROW);
878 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
879 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
883 fdescr->Add(mDescriptionFilter,1,wxGROW);
884 fsizer->Add(fdescr,0,wxGROW);
887 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
888 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
892 fcat->Add(mCategoryFilter,1,wxGROW);
893 fsizer->Add(fcat,0,wxGROW);
894 wxBoxSizer *fintype =
896 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
897 mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
901 fintype->Add(mInputTypeFilter,1,wxGROW);
902 fsizer->Add(fintype,0,wxGROW);
903 wxBoxSizer *fouttype =
905 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
906 mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
910 fouttype->Add(mOutputTypeFilter,1,wxGROW);
911 fsizer->Add(fouttype,0,wxGROW);
914 ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL );
915 mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
919 finnat->Add(mInputNatureFilter,1,wxGROW);
920 fsizer->Add(finnat,0,wxGROW);
921 wxBoxSizer *foutnat =
923 ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL );
924 mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
928 foutnat->Add(mOutputNatureFilter,1,wxGROW);
929 fsizer->Add(foutnat,0,wxGROW);
931 mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
932 mShowWidgetsFilter->SetValue(true);
933 fsizer->Add(mShowWidgetsFilter,0,wxGROW);
935 mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
936 mShowAdaptorsFilter->SetValue(false);
937 fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
939 mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
940 mShowGUIsFilter->SetValue(false);
941 fsizer->Add(mShowGUIsFilter,0,wxGROW);
943 filters->SetSizer(fsizer);
945 // JGRR & CM DISABLED CLOSE BUTTON
946 m_mgr.AddPane(filters,
947 wxAuiPaneInfo().Name(wxT("Filter"))
948 .Caption(wxT("Filter"))
949 .MinimizeButton(true)
950 .MaximizeButton(true)
952 .MinSize(wxSize(100,100))
956 // sizer->Add(fsizer,1,wxGROW);
964 //================================================================
966 Factory::Pointer WxGUIPackageBrowser2::GetFactory()
971 //================================================================
974 //================================================================
975 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
979 //================================================================
981 //================================================================
982 // User callback when a box is selected in the list
983 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
984 ( BlackBoxDescriptor* d)
989 mBoxInfo->UpdateInfo(d);
990 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
991 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
995 //================================================================
997 //================================================================
998 BlackBoxDescriptor* WxGUIPackageBrowser2::GetActualSelected()
1000 return _actualSelected;
1003 //================================================================
1005 //================================================================
1006 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
1009 mInterpreter.reset();
1010 // Object::PrintObjectListInfo("");
1013 //================================================================
1015 //================================================================
1016 void WxGUIPackageBrowser2::IncludeAll()
1018 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
1019 mInterpreter->SetCommandLine(true);
1020 std::stringstream* buf = new std::stringstream;
1021 *buf << "exec freeze_no_error" << std::endl;
1022 *buf << "message max 0" << std::endl;
1023 *buf << "include *" << std::endl;
1024 mInterpreter->InterpretBuffer(buf);
1026 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
1027 BuildFromFactory(F);
1029 //================================================================
1031 //================================================================
1032 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
1038 //================================================================
1040 //================================================================
1041 void WxGUIPackageBrowser2::RebuildList()
1044 mBoxList->ClearAll();
1046 const Factory::PackageMapType& M = mFactory->GetPackageMap();
1047 Factory::PackageMapType::const_iterator i;
1048 for (i=M.begin();i!=M.end();++i)
1050 Package::Pointer P = i->second;
1051 if (P->GetName() == "user") continue;
1053 Package::DescriptorMapType::iterator j;
1054 for (j=P->GetDescriptorMap().begin();
1055 j!=P->GetDescriptorMap().end();
1058 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
1059 if (IsVisible(j->second))
1060 mBoxList->Insert(j->second);
1065 //================================================================
1067 bool WxGUIPackageBrowser2::findnpos(const std::string &strA, const std::string &strB )
1069 if ((strB=="") || (strA=="") )
1076 std::string strAA=strA;
1077 std::string strBB=strB;
1080 size=strAA.length();
1081 for (i=0;i<size;i++)
1083 if ((strAA[i]>='A')&&(strAA[i]<='Z'))
1085 strAA[i]=strAA[i]+32;
1089 size=strBB.length();
1090 for (i=0;i<size;i++)
1092 if ((strBB[i]>='A')&&(strBB[i]<='Z'))
1094 strBB[i]=strBB[i]+32;
1099 if ( strAA.find(strBB) == std::string::npos )
1107 //================================================================
1108 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
1110 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
1111 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
1112 if ((!mShowAdaptorsFilter->IsChecked())&&
1113 ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
1114 (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
1119 if ((!mShowGUIsFilter->IsChecked())&&
1120 ((d->GetKind()==BlackBoxDescriptor::GUI)||
1121 (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
1126 //EED if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) ) == std::string::npos )
1127 if ( findnpos(d->GetPackage()->GetName(),wx2std(mPackageFilter->GetValue())) == true )
1132 //EED if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) ) == std::string::npos )
1133 if ( findnpos(d->GetTypeName(),wx2std(mNameFilter->GetValue())) == true )
1138 //EED if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) ) == std::string::npos )
1139 if ( findnpos(d->GetDescription(),wx2std(mDescriptionFilter->GetValue())) == true )
1144 //EED if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) ) == std::string::npos )
1145 if ( findnpos(d->GetCategory(),wx2std(mCategoryFilter->GetValue())) == true )
1150 if (!mShowWidgetsFilter->IsChecked())
1153 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1154 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1155 for ( in = imap.begin(); in != imap.end(); ++in )
1157 if (in->second->GetName() == "Widget" )
1169 if (mInputTypeFilter->GetValue().size()>0)
1171 std::string s = wx2std(mInputTypeFilter->GetValue());
1173 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
1174 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1175 for ( in = imap.begin(); in != imap.end(); ++in )
1177 //EED if (in->second->GetTypeName().find(s)!=std::string::npos)
1178 if ( findnpos( in->second->GetTypeName() , s ) == true )
1190 if (mOutputTypeFilter->GetValue().size()>0)
1192 std::string s = wx2std(mOutputTypeFilter->GetValue());
1194 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1195 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1196 for ( in = imap.begin(); in != imap.end(); ++in )
1198 //EED if (in->second->GetTypeName().find(s)!=std::string::npos)
1199 if ( findnpos( in->second->GetTypeName() , s ) == true )
1211 if (mInputNatureFilter->GetValue().size()>0)
1213 std::string s = wx2std(mInputNatureFilter->GetValue());
1215 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
1216 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1217 for ( in = imap.begin(); in != imap.end(); ++in )
1219 //EED if (in->second->GetNature().find(s)!=std::string::npos)
1220 if ( findnpos( in->second->GetNature() , s ) == true )
1232 if (mOutputNatureFilter->GetValue().size()>0)
1234 std::string s = wx2std(mOutputNatureFilter->GetValue());
1236 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1237 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1238 for ( in = imap.begin(); in != imap.end(); ++in )
1240 //EED if (in->second->GetNature().find(s)!=std::string::npos)
1241 if ( findnpos( in->second->GetNature() , s ) == true )
1256 //========================================================================
1258 //========================================================================
1259 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1260 //EED EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1261 //EED EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1262 //EED EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1263 //EED EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1264 //EED EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1265 //EED EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1266 //EED EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
1267 //EED EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
1269 EVT_TEXT(id_f1, WxGUIPackageBrowser2::OnFilter )
1270 EVT_TEXT(id_f2, WxGUIPackageBrowser2::OnFilter )
1271 EVT_TEXT(id_f3, WxGUIPackageBrowser2::OnFilter )
1272 EVT_TEXT(id_f4, WxGUIPackageBrowser2::OnFilter )
1273 EVT_TEXT(id_f5, WxGUIPackageBrowser2::OnFilter )
1274 EVT_TEXT(id_f6, WxGUIPackageBrowser2::OnFilter )
1275 EVT_TEXT(id_f7, WxGUIPackageBrowser2::OnFilter )
1276 EVT_TEXT(id_f8, WxGUIPackageBrowser2::OnFilter )
1278 EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
1279 EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
1280 EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
1282 //========================================================================
1286 //================================================================
1287 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1290 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1292 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1294 mBrowser = new WxGUIPackageBrowser2(this);
1295 mBrowser->IncludeAll();
1296 sizer->Add(mBrowser,1,wxGROW);
1298 // WxGUICommand* com = new WxGUICommand(this,this);
1303 // Creates the parent window of all bbtk windows as a child of this
1304 // Wx::CreateTopWindow(this);
1305 // Add the method OnWxSignal as a Wx::Signal observer
1306 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
1308 SetAutoLayout(true);
1311 //================================================================
1313 //================================================================
1314 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1317 //================================================================
1322 #endif //_USE_WXWIDGETS_