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);
175 void WxGUIBlackBoxList::OnCacheHint(wxListEvent& event)
177 //wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"),
178 // event.GetCacheFrom(), event.GetCacheTo() );
181 void WxGUIBlackBoxList::SetColumnImage(int col, int image)
185 item.SetMask(wxLIST_MASK_IMAGE);
186 item.SetImage(image);
187 SetColumn(col, item);
191 void WxGUIBlackBoxList::OnColClick(wxListEvent& event)
193 int col = event.GetColumn();
195 // set or unset image
196 static bool x = false;
198 SetColumnImage(col, x ? 0 : -1);
200 // wxLogMessage( wxT("OnColumnClick at %d."), col );
203 void WxGUIBlackBoxList::OnColRightClick(wxListEvent& event)
205 int col = event.GetColumn();
208 SetColumnImage(col, -1);
211 // Show popupmenu at position
212 wxMenu menu(wxT("Test"));
213 menu.Append(-1, _T("&About"));
214 PopupMenu(&menu, event.GetPoint());
216 //wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
219 void WxGUIBlackBoxList::LogColEvent(const wxListEvent& event, const wxChar *name)
221 // const int col = event.GetColumn();
224 wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
227 event.GetItem().GetWidth(),
228 GetColumnWidth(col));
232 void WxGUIBlackBoxList::OnColBeginDrag(wxListEvent& event)
234 LogColEvent( event, wxT("OnColBeginDrag") );
236 if ( event.GetColumn() == 0 )
238 //wxLogMessage(_T("Resizing this column shouldn't work."));
245 void WxGUIBlackBoxList::OnColDragging(wxListEvent& event)
247 LogColEvent( event, wxT("OnColDragging") );
250 void WxGUIBlackBoxList::OnColEndDrag(wxListEvent& event)
252 LogColEvent( event, wxT("OnColEndDrag") );
255 void WxGUIBlackBoxList::OnBeginDrag(wxListEvent& event)
257 std::cout<<"RaC DRAG TABLE"<<std::endl;
259 wxString text(this->GetItemText(event.GetIndex()));
261 info.m_itemId = event.m_itemIndex;
263 info.m_mask = wxLIST_MASK_DATA;
264 wxString sendtext(_T(""));
267 // TO DO : STORE SMART PTR ?
268 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
271 //DFGO -> To identify it is a box
272 sendtext += crea::std2wx("box:");
273 sendtext += crea::std2wx(d->GetFullTypeName());
274 sendtext += _T("<EndEED>");
275 printf("EED WxGUIBlackBoxList::OnBeginDrag <%s>%d <%s>%d\n",
276 (const char*)sendtext.mb_str(),sendtext.Len() , d->GetFullTypeName().c_str() , d->GetFullTypeName().length() );
279 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
282 wxTextDataObject tdo(sendtext);
283 printf("EED WxGUIBlackBoxList::OnBeginDrag <%s>\n",(const char*) tdo.GetText().mb_str() );
285 wxDropSource tds(tdo, this);
288 // const wxPoint& pt = event.m_pointDrag;
290 //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
291 // pt.x, pt.y, HitTest(pt, flags) );
294 void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
296 //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
297 // event.m_pointDrag.x, event.m_pointDrag.y );
300 void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
302 //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
305 void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
307 //wxLogMessage( wxT("OnEndLabelEdit: %s"),
308 // event.IsEditCancelled() ? _T("[cancelled]")
309 // : event.m_item.m_text.c_str());
312 void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
314 LogEvent(event, _T("OnDeleteItem"));
315 std::cout << "cannot del"<<std::endl;
317 //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
320 void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
322 LogEvent(event, _T("OnDeleteAllItems"));
326 #if WXWIN_COMPATIBILITY_2_4
327 void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
331 msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
332 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
333 msg << _T(" wxLIST_MASK_STATE");
334 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
335 msg << _T(" wxLIST_MASK_TEXT");
336 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
337 msg << _T(" wxLIST_MASK_IMAGE");
338 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
339 msg << _T(" wxLIST_MASK_DATA");
340 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
341 msg << _T(" wxLIST_SET_ITEM");
342 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
343 msg << _T(" wxLIST_MASK_WIDTH");
344 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
345 msg << _T(" wxLIST_MASK_WIDTH");
347 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
349 event.m_item.m_text = _T("My callback text");
355 void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
357 LogEvent(event, _T("OnSetInfo"));
361 void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
363 if (mUser==0) return;
366 info.m_itemId = event.m_itemIndex;
368 info.m_mask = wxLIST_MASK_DATA;
371 // TO DO : STORE SMART PTR ?
372 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
373 if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
377 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
381 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
383 LogEvent(event, _T("OnDeselected"));
386 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
388 LogEvent(event, _T("OnActivated"));
391 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
393 LogEvent(event, _T("OnFocused"));
398 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
402 switch ( event.GetKeyCode() )
404 case 'c': // colorize
408 info.m_itemId = event.GetIndex();
409 if ( info.m_itemId == -1 )
417 wxListItemAttr *attr = info.GetAttributes();
418 if ( !attr || !attr->HasTextColour() )
420 info.SetTextColour(*wxCYAN);
424 RefreshItem(info.m_itemId);
431 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
432 if ( item++ == GetItemCount() - 1 )
437 //wxLogMessage(_T("Focusing item %ld"), item);
439 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
443 case 'r': // show bounding Rect
446 item = event.GetIndex();
448 if ( !GetItemRect(item, r) )
450 //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
454 //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
455 // item, r.x, r.y, r.x + r.width, r.y + r.height);
460 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
466 //wxLogMessage(_T("Item %ld deleted"), item);
468 // -1 because the indices were shifted by DeleteItem()
469 item = GetNextItem(item - 1,
470 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
476 if ( GetWindowStyle() & wxLC_REPORT )
478 if ( GetWindowStyle() & wxLC_VIRTUAL )
480 SetItemCount(GetItemCount() + 1);
484 //InsertItemInReportView(event.GetIndex());
490 LogEvent(event, _T("OnListKeyDown"));
496 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
498 //wxLogMessage(_T("Got char event."));
500 switch ( event.GetKeyCode() )
506 // these are the keys we process ourselves
514 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
516 if ( !event.ControlDown() )
525 HitTest(event.GetPosition(), flags, &subitem);
530 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
531 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
532 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
533 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
534 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
535 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
536 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
537 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
538 default: where = _T("not clear exactly where on"); break;
541 //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
542 // where.c_str(), item, subitem);
545 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
547 //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
548 // event.GetIndex(), eventName,
549 // event.GetText().c_str(), event.GetData());
552 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
555 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
557 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
562 return wxString::Format(_T("Column %ld of item %ld"), column, item);
566 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
571 if (!(item %3) && column == 1)
577 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
579 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
584 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
586 wxPoint point = event.GetPosition();
588 if (point.x == -1 && point.y == -1) {
589 wxSize size = GetSize();
590 point.x = size.x / 2;
591 point.y = size.y / 2;
593 point = ScreenToClient(point);
595 ShowContextMenu(point);
599 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
603 menu.Append(wxID_ABOUT, _T("&About"));
604 menu.AppendSeparator();
605 menu.Append(wxID_EXIT, _T("E&xit"));
607 PopupMenu(&menu, pos.x, pos.y);
609 //================================================================
613 //================================================================
614 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
616 // wxPanel(parent, -1,wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE),
620 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
622 // mName = new wxStaticText(this,-1,_T(""));
623 // sizer->Add(mName,0,wxGROW);
624 mDescription = new wxStaticText(this,-1,_T(""));
625 sizer->Add(mDescription,0,wxGROW);
626 mAuthor = new wxStaticText(this,-1,_T(""));
627 sizer->Add(mAuthor,0,wxGROW);
628 mCategory = new wxStaticText(this,-1,_T(""));
629 sizer->Add(mCategory,0,wxGROW);
631 wxBoxSizer *inputs = new wxStaticBoxSizer ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
632 mInputList = new wxListCtrl(this, -1,
635 wxLC_REPORT //wxLC_LIST
638 inputs->Add(mInputList,1,wxGROW);
639 sizer->Add(inputs,1,wxGROW);
641 wxBoxSizer *outputs = new wxStaticBoxSizer ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
642 mOutputList = new wxListCtrl(this, -1,
645 wxLC_REPORT //wxLC_LIST
647 // | wxFULL_REPAINT_ON_RESIZE | wxVSCROLL);
649 outputs->Add(mOutputList,1,wxGROW);
650 sizer->Add(outputs,1,wxGROW);
653 // sizer->FitInside(this);
654 Connect( this->GetId(), wxEVT_ERASE_BACKGROUND , (wxObjectEventFunction) (void (WxGUIBlackBoxInfo::*)(wxEvent&)) &WxGUIBlackBoxInfo::OnEraseBackGround );
660 //================================================================
663 void WxGUIBlackBoxInfo::OnEraseBackGround( wxEvent& )
665 mInputList->ClearBackground();
666 mOutputList->ClearBackground();
671 //================================================================
672 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
675 // mName->SetLabel(std2wx(descr->GetTypeName()));
676 mDescription->SetLabel(std2wx(descr->GetDescription()));
677 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
678 mCategory->SetLabel(std2wx(descr->GetCategory()));
680 mInputList->ClearAll();
681 mInputList->InsertColumn( 0, _("Name"),
682 wxLIST_FORMAT_LEFT, 80 );
683 mInputList->InsertColumn( 1, _("Type"),
684 wxLIST_FORMAT_LEFT, 100 );
685 mInputList->InsertColumn( 2, _("Nature"),
686 wxLIST_FORMAT_LEFT, 100 );
687 mInputList->InsertColumn( 3, _("Description"),
688 wxLIST_FORMAT_LEFT, 500 );
690 mOutputList->ClearAll();
691 mOutputList->InsertColumn( 0, _("Name"),
692 wxLIST_FORMAT_LEFT, 80 );
693 mOutputList->InsertColumn( 1, _("Type"),
694 wxLIST_FORMAT_LEFT, 100 );
695 mOutputList->InsertColumn( 2, _("Nature"),
696 wxLIST_FORMAT_LEFT, 100 );
697 mOutputList->InsertColumn( 3, _("Description"),
698 wxLIST_FORMAT_LEFT, 500 );
701 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
702 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
703 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
705 const BlackBoxDescriptor::InputDescriptorMapType& imap =
706 descr->GetInputDescriptorMap();
707 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
708 for ( in = imap.begin(); in != imap.end(); ++in )
711 if (in->second->GetCreatorTypeInfo() ==
712 typeid(AtomicBlackBoxDescriptor))
716 else if (in->second->GetCreatorTypeInfo() ==
717 typeid(WxBlackBoxDescriptor))
721 if (iotype==0) user_defined.push_back(in->second);
722 else if (iotype==1) ubb_defined.push_back(in->second);
723 else if (iotype==2) wxbb_defined.push_back(in->second);
727 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
728 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
730 InsertInputOutput(mInputList,*hi);
732 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
734 InsertInputOutput(mInputList,*hi);
736 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
738 InsertInputOutput(mInputList,*hi);
742 user_defined.clear();
744 wxbb_defined.clear();
745 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
746 descr->GetOutputDescriptorMap();
747 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
748 for ( out = omap.begin(); out != omap.end(); ++out )
751 if (out->second->GetCreatorTypeInfo() ==
752 typeid(AtomicBlackBoxDescriptor))
756 else if (out->second->GetCreatorTypeInfo() ==
757 typeid(WxBlackBoxDescriptor))
762 if (iotype==0) user_defined.push_back(out->second);
763 else if (iotype==1) ubb_defined.push_back(out->second);
764 else if (iotype==2) wxbb_defined.push_back(out->second);
767 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
769 InsertInputOutput(mOutputList,*hi);
771 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
773 InsertInputOutput(mOutputList,*hi);
775 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
777 InsertInputOutput(mOutputList,*hi);
780 //================================================================
783 //================================================================
784 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
785 BlackBoxInputOutputDescriptor* d)
788 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
789 int nID = l->GetItemCount();
790 // std::cout << nID << std::endl;
792 // kNewItem.SetMask(wxLIST_MASK_DATA);
793 // kNewItem.SetData(d);
794 l->InsertItem(kNewItem);
795 l->SetItem(nID, 0, std2wx(d->GetName()) );
796 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
797 l->SetItem(nID, 2, std2wx(d->GetNature()) );
798 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
800 //================================================================
802 //================================================================
803 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
806 //================================================================
824 //================================================================
825 void WxGUIPackageBrowser2::OnEraseBackGround( wxEvent& )
827 mBoxList->ClearBackground();
832 //================================================================
835 //================================================================
836 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
837 WxGUIPackageBrowser2User* user )
838 : wxPanel(parent, -1),
842 _actualSelected=NULL;
843 m_mgr.SetManagedWindow(this);
845 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
846 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
849 wxLC_REPORT //wxLC_LIST
851 mBoxList->SetUser(this);
853 Connect( GetId(), wxEVT_SIZE , (wxObjectEventFunction) (void (WxGUIPackageBrowser2::*)(wxEvent&)) &WxGUIPackageBrowser2::OnEraseBackGround );
855 // JGRR & CM DISABLED CLOSE BUTTON
856 m_mgr.AddPane(mBoxList,
857 wxAuiPaneInfo().Name(wxT("BoxList"))
858 .Caption(wxT("Black Boxes"))
859 .MinimizeButton(true)
860 .MaximizeButton(true)
862 .MinSize(wxSize(100,100))
865 // sizer->Add(mBoxList,5,wxGROW);
867 mBoxInfo = new WxGUIBlackBoxInfo(this);
868 // sizer->Add(mBoxInfo,3,wxGROW);
870 // JGRR & CM DISABLED CLOSE BUTTON
871 m_mgr.AddPane(mBoxInfo,
872 wxAuiPaneInfo().Name(wxT("Box"))
874 .MinimizeButton(true)
875 .MaximizeButton(true)
877 .MinSize(wxSize(100,200))
881 wxPanel* filters = new wxPanel(this,-1);
882 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
885 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
886 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
890 fpack->Add(mPackageFilter,1,wxGROW);
891 fsizer->Add(fpack,0,wxGROW);
894 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
895 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
899 fname->Add(mNameFilter,1,wxGROW);
900 fsizer->Add(fname,0,wxGROW);
903 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
904 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
908 fdescr->Add(mDescriptionFilter,1,wxGROW);
909 fsizer->Add(fdescr,0,wxGROW);
912 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
913 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
917 fcat->Add(mCategoryFilter,1,wxGROW);
918 fsizer->Add(fcat,0,wxGROW);
919 wxBoxSizer *fintype =
921 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
922 mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
926 fintype->Add(mInputTypeFilter,1,wxGROW);
927 fsizer->Add(fintype,0,wxGROW);
928 wxBoxSizer *fouttype =
930 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
931 mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
935 fouttype->Add(mOutputTypeFilter,1,wxGROW);
936 fsizer->Add(fouttype,0,wxGROW);
939 ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL );
940 mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
944 finnat->Add(mInputNatureFilter,1,wxGROW);
945 fsizer->Add(finnat,0,wxGROW);
946 wxBoxSizer *foutnat =
948 ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL );
949 mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
953 foutnat->Add(mOutputNatureFilter,1,wxGROW);
954 fsizer->Add(foutnat,0,wxGROW);
956 mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
957 mShowWidgetsFilter->SetValue(true);
958 fsizer->Add(mShowWidgetsFilter,0,wxGROW);
960 mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
961 mShowAdaptorsFilter->SetValue(false);
962 fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
964 mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
965 mShowGUIsFilter->SetValue(false);
966 fsizer->Add(mShowGUIsFilter,0,wxGROW);
968 filters->SetSizer(fsizer);
970 // JGRR & CM DISABLED CLOSE BUTTON
971 m_mgr.AddPane(filters,
972 wxAuiPaneInfo().Name(wxT("Filter"))
973 .Caption(wxT("Filter"))
974 .MinimizeButton(true)
975 .MaximizeButton(true)
977 .MinSize(wxSize(100,100))
981 // sizer->Add(fsizer,1,wxGROW);
991 //================================================================
992 Factory::Pointer WxGUIPackageBrowser2::GetFactory()
997 //================================================================
1000 //================================================================
1001 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
1005 //================================================================
1007 //================================================================
1008 // User callback when a box is selected in the list
1009 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
1010 ( BlackBoxDescriptor* d)
1015 mBoxInfo->UpdateInfo(d);
1016 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
1017 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
1021 //================================================================
1023 //================================================================
1024 BlackBoxDescriptor* WxGUIPackageBrowser2::GetActualSelected()
1026 return _actualSelected;
1029 //================================================================
1031 //================================================================
1032 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
1035 mInterpreter.reset();
1036 // Object::PrintObjectListInfo("");
1039 //================================================================
1041 //================================================================
1042 void WxGUIPackageBrowser2::IncludeAll()
1044 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
1045 mInterpreter->SetCommandLine(true);
1046 std::stringstream* buf = new std::stringstream;
1047 *buf << "exec freeze_no_error" << std::endl;
1048 *buf << "message max 0" << std::endl;
1049 *buf << "include *" << std::endl;
1050 mInterpreter->InterpretBuffer(buf);
1052 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
1053 BuildFromFactory(F);
1055 //================================================================
1057 //================================================================
1058 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
1064 //================================================================
1066 //================================================================
1067 void WxGUIPackageBrowser2::RebuildList()
1069 // mBoxList->Hide();
1070 mBoxList->ClearAll();
1071 mBoxList->ClearBackground();
1072 const Factory::PackageMapType& M = mFactory->GetPackageMap();
1073 Factory::PackageMapType::const_iterator i;
1074 for (i=M.begin();i!=M.end();++i)
1076 Package::Pointer P = i->second;
1077 if (P->GetName() == "user") continue;
1079 Package::DescriptorMapType::iterator j;
1080 for (j=P->GetDescriptorMap().begin();
1081 j!=P->GetDescriptorMap().end();
1084 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
1085 if (IsVisible(j->second))
1086 mBoxList->Insert(j->second);
1091 //================================================================
1093 bool WxGUIPackageBrowser2::findnpos(const std::string &strA, const std::string &strB )
1095 if ((strB=="") || (strA=="") )
1102 std::string strAA=strA;
1103 std::string strBB=strB;
1106 size=strAA.length();
1107 for (i=0;i<size;i++)
1109 if ((strAA[i]>='A')&&(strAA[i]<='Z'))
1111 strAA[i]=strAA[i]+32;
1115 size=strBB.length();
1116 for (i=0;i<size;i++)
1118 if ((strBB[i]>='A')&&(strBB[i]<='Z'))
1120 strBB[i]=strBB[i]+32;
1125 if ( strAA.find(strBB) == std::string::npos )
1133 //================================================================
1134 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
1136 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
1137 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
1138 if ((!mShowAdaptorsFilter->IsChecked())&&
1139 ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
1140 (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
1145 if ((!mShowGUIsFilter->IsChecked())&&
1146 ((d->GetKind()==BlackBoxDescriptor::GUI)||
1147 (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
1152 //EED if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) ) == std::string::npos )
1153 if ( findnpos(d->GetPackage()->GetName(),wx2std(mPackageFilter->GetValue())) == true )
1158 //EED if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) ) == std::string::npos )
1159 if ( findnpos(d->GetTypeName(),wx2std(mNameFilter->GetValue())) == true )
1164 //EED if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) ) == std::string::npos )
1165 if ( findnpos(d->GetDescription(),wx2std(mDescriptionFilter->GetValue())) == true )
1170 //EED if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) ) == std::string::npos )
1171 if ( findnpos(d->GetCategory(),wx2std(mCategoryFilter->GetValue())) == true )
1176 if (!mShowWidgetsFilter->IsChecked())
1179 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1180 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1181 for ( in = imap.begin(); in != imap.end(); ++in )
1183 if (in->second->GetName() == "Widget" )
1195 if (mInputTypeFilter->GetValue().size()>0)
1197 std::string s = wx2std(mInputTypeFilter->GetValue());
1199 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
1200 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1201 for ( in = imap.begin(); in != imap.end(); ++in )
1203 //EED if (in->second->GetTypeName().find(s)!=std::string::npos)
1204 if ( findnpos( in->second->GetTypeName() , s ) == true )
1216 if (mOutputTypeFilter->GetValue().size()>0)
1218 std::string s = wx2std(mOutputTypeFilter->GetValue());
1220 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1221 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1222 for ( in = imap.begin(); in != imap.end(); ++in )
1224 //EED if (in->second->GetTypeName().find(s)!=std::string::npos)
1225 if ( findnpos( in->second->GetTypeName() , s ) == true )
1237 if (mInputNatureFilter->GetValue().size()>0)
1239 std::string s = wx2std(mInputNatureFilter->GetValue());
1241 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
1242 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1243 for ( in = imap.begin(); in != imap.end(); ++in )
1245 //EED if (in->second->GetNature().find(s)!=std::string::npos)
1246 if ( findnpos( in->second->GetNature() , s ) == true )
1258 if (mOutputNatureFilter->GetValue().size()>0)
1260 std::string s = wx2std(mOutputNatureFilter->GetValue());
1262 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1263 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1264 for ( in = imap.begin(); in != imap.end(); ++in )
1266 //EED if (in->second->GetNature().find(s)!=std::string::npos)
1267 if ( findnpos( in->second->GetNature() , s ) == true )
1282 //========================================================================
1284 //========================================================================
1285 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1286 //EED EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1287 //EED EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1288 //EED EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1289 //EED EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1290 //EED EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1291 //EED EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1292 //EED EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
1293 //EED EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
1295 EVT_TEXT(id_f1, WxGUIPackageBrowser2::OnFilter )
1296 EVT_TEXT(id_f2, WxGUIPackageBrowser2::OnFilter )
1297 EVT_TEXT(id_f3, WxGUIPackageBrowser2::OnFilter )
1298 EVT_TEXT(id_f4, WxGUIPackageBrowser2::OnFilter )
1299 EVT_TEXT(id_f5, WxGUIPackageBrowser2::OnFilter )
1300 EVT_TEXT(id_f6, WxGUIPackageBrowser2::OnFilter )
1301 EVT_TEXT(id_f7, WxGUIPackageBrowser2::OnFilter )
1302 EVT_TEXT(id_f8, WxGUIPackageBrowser2::OnFilter )
1304 EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
1305 EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
1306 EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
1308 //========================================================================
1312 //================================================================
1313 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1316 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1318 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1320 mBrowser = new WxGUIPackageBrowser2(this);
1321 mBrowser->IncludeAll();
1322 sizer->Add(mBrowser,1,wxGROW);
1324 // WxGUICommand* com = new WxGUICommand(this,this);
1329 // Creates the parent window of all bbtk windows as a child of this
1330 // Wx::CreateTopWindow(this);
1331 // Add the method OnWxSignal as a Wx::Signal observer
1332 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
1334 SetAutoLayout(true);
1337 //================================================================
1339 //================================================================
1340 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1343 //================================================================
1348 #endif //_USE_WXWIDGETS_