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());
278 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
281 wxTextDataObject tdo(sendtext);
282 wxDropSource tds(tdo, this);
285 // const wxPoint& pt = event.m_pointDrag;
287 //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
288 // pt.x, pt.y, HitTest(pt, flags) );
291 void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
293 //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
294 // event.m_pointDrag.x, event.m_pointDrag.y );
297 void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
299 //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
302 void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
304 //wxLogMessage( wxT("OnEndLabelEdit: %s"),
305 // event.IsEditCancelled() ? _T("[cancelled]")
306 // : event.m_item.m_text.c_str());
309 void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
311 LogEvent(event, _T("OnDeleteItem"));
312 std::cout << "cannot del"<<std::endl;
314 //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
317 void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
319 LogEvent(event, _T("OnDeleteAllItems"));
323 #if WXWIN_COMPATIBILITY_2_4
324 void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
328 msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
329 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
330 msg << _T(" wxLIST_MASK_STATE");
331 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
332 msg << _T(" wxLIST_MASK_TEXT");
333 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
334 msg << _T(" wxLIST_MASK_IMAGE");
335 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
336 msg << _T(" wxLIST_MASK_DATA");
337 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
338 msg << _T(" wxLIST_SET_ITEM");
339 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
340 msg << _T(" wxLIST_MASK_WIDTH");
341 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
342 msg << _T(" wxLIST_MASK_WIDTH");
344 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
346 event.m_item.m_text = _T("My callback text");
352 void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
354 LogEvent(event, _T("OnSetInfo"));
358 void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
360 if (mUser==0) return;
363 info.m_itemId = event.m_itemIndex;
365 info.m_mask = wxLIST_MASK_DATA;
368 // TO DO : STORE SMART PTR ?
369 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
370 if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
374 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
378 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
380 LogEvent(event, _T("OnDeselected"));
383 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
385 LogEvent(event, _T("OnActivated"));
388 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
390 LogEvent(event, _T("OnFocused"));
395 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
399 switch ( event.GetKeyCode() )
401 case 'c': // colorize
405 info.m_itemId = event.GetIndex();
406 if ( info.m_itemId == -1 )
414 wxListItemAttr *attr = info.GetAttributes();
415 if ( !attr || !attr->HasTextColour() )
417 info.SetTextColour(*wxCYAN);
421 RefreshItem(info.m_itemId);
428 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
429 if ( item++ == GetItemCount() - 1 )
434 //wxLogMessage(_T("Focusing item %ld"), item);
436 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
440 case 'r': // show bounding Rect
443 item = event.GetIndex();
445 if ( !GetItemRect(item, r) )
447 //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
451 //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
452 // item, r.x, r.y, r.x + r.width, r.y + r.height);
457 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
463 //wxLogMessage(_T("Item %ld deleted"), item);
465 // -1 because the indices were shifted by DeleteItem()
466 item = GetNextItem(item - 1,
467 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
473 if ( GetWindowStyle() & wxLC_REPORT )
475 if ( GetWindowStyle() & wxLC_VIRTUAL )
477 SetItemCount(GetItemCount() + 1);
481 //InsertItemInReportView(event.GetIndex());
487 LogEvent(event, _T("OnListKeyDown"));
493 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
495 //wxLogMessage(_T("Got char event."));
497 switch ( event.GetKeyCode() )
503 // these are the keys we process ourselves
511 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
513 if ( !event.ControlDown() )
522 HitTest(event.GetPosition(), flags, &subitem);
527 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
528 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
529 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
530 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
531 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
532 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
533 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
534 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
535 default: where = _T("not clear exactly where on"); break;
538 //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
539 // where.c_str(), item, subitem);
542 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
544 //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
545 // event.GetIndex(), eventName,
546 // event.GetText().c_str(), event.GetData());
549 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
552 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
554 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
559 return wxString::Format(_T("Column %ld of item %ld"), column, item);
563 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
568 if (!(item %3) && column == 1)
574 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
576 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
581 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
583 wxPoint point = event.GetPosition();
585 if (point.x == -1 && point.y == -1) {
586 wxSize size = GetSize();
587 point.x = size.x / 2;
588 point.y = size.y / 2;
590 point = ScreenToClient(point);
592 ShowContextMenu(point);
596 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
600 menu.Append(wxID_ABOUT, _T("&About"));
601 menu.AppendSeparator();
602 menu.Append(wxID_EXIT, _T("E&xit"));
604 PopupMenu(&menu, pos.x, pos.y);
606 //================================================================
610 //================================================================
611 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
613 // wxPanel(parent, -1,wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE),
617 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
619 // mName = new wxStaticText(this,-1,_T(""));
620 // sizer->Add(mName,0,wxGROW);
621 mDescription = new wxStaticText(this,-1,_T(""));
622 sizer->Add(mDescription,0,wxGROW);
623 mAuthor = new wxStaticText(this,-1,_T(""));
624 sizer->Add(mAuthor,0,wxGROW);
625 mCategory = new wxStaticText(this,-1,_T(""));
626 sizer->Add(mCategory,0,wxGROW);
628 wxBoxSizer *inputs = new wxStaticBoxSizer ( 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 = new wxStaticBoxSizer ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
639 mOutputList = new wxListCtrl(this, -1,
642 wxLC_REPORT //wxLC_LIST
644 // | wxFULL_REPAINT_ON_RESIZE | wxVSCROLL);
646 outputs->Add(mOutputList,1,wxGROW);
647 sizer->Add(outputs,1,wxGROW);
650 // sizer->FitInside(this);
651 Connect( this->GetId(), wxEVT_ERASE_BACKGROUND , (wxObjectEventFunction) (void (WxGUIBlackBoxInfo::*)(wxEvent&)) &WxGUIBlackBoxInfo::OnEraseBackGround );
657 //================================================================
660 void WxGUIBlackBoxInfo::OnEraseBackGround( wxEvent& )
662 mInputList->ClearBackground();
663 mOutputList->ClearBackground();
668 //================================================================
669 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
672 // mName->SetLabel(std2wx(descr->GetTypeName()));
673 mDescription->SetLabel(std2wx(descr->GetDescription()));
674 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
675 mCategory->SetLabel(std2wx(descr->GetCategory()));
677 mInputList->ClearAll();
678 mInputList->InsertColumn( 0, _("Name"),
679 wxLIST_FORMAT_LEFT, 80 );
680 mInputList->InsertColumn( 1, _("Type"),
681 wxLIST_FORMAT_LEFT, 100 );
682 mInputList->InsertColumn( 2, _("Nature"),
683 wxLIST_FORMAT_LEFT, 100 );
684 mInputList->InsertColumn( 3, _("Description"),
685 wxLIST_FORMAT_LEFT, 500 );
687 mOutputList->ClearAll();
688 mOutputList->InsertColumn( 0, _("Name"),
689 wxLIST_FORMAT_LEFT, 80 );
690 mOutputList->InsertColumn( 1, _("Type"),
691 wxLIST_FORMAT_LEFT, 100 );
692 mOutputList->InsertColumn( 2, _("Nature"),
693 wxLIST_FORMAT_LEFT, 100 );
694 mOutputList->InsertColumn( 3, _("Description"),
695 wxLIST_FORMAT_LEFT, 500 );
698 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
699 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
700 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
702 const BlackBoxDescriptor::InputDescriptorMapType& imap =
703 descr->GetInputDescriptorMap();
704 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
705 for ( in = imap.begin(); in != imap.end(); ++in )
708 if (in->second->GetCreatorTypeInfo() ==
709 typeid(AtomicBlackBoxDescriptor))
713 else if (in->second->GetCreatorTypeInfo() ==
714 typeid(WxBlackBoxDescriptor))
718 if (iotype==0) user_defined.push_back(in->second);
719 else if (iotype==1) ubb_defined.push_back(in->second);
720 else if (iotype==2) wxbb_defined.push_back(in->second);
724 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
725 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
727 InsertInputOutput(mInputList,*hi);
729 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
731 InsertInputOutput(mInputList,*hi);
733 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
735 InsertInputOutput(mInputList,*hi);
739 user_defined.clear();
741 wxbb_defined.clear();
742 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
743 descr->GetOutputDescriptorMap();
744 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
745 for ( out = omap.begin(); out != omap.end(); ++out )
748 if (out->second->GetCreatorTypeInfo() ==
749 typeid(AtomicBlackBoxDescriptor))
753 else if (out->second->GetCreatorTypeInfo() ==
754 typeid(WxBlackBoxDescriptor))
759 if (iotype==0) user_defined.push_back(out->second);
760 else if (iotype==1) ubb_defined.push_back(out->second);
761 else if (iotype==2) wxbb_defined.push_back(out->second);
764 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
766 InsertInputOutput(mOutputList,*hi);
768 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
770 InsertInputOutput(mOutputList,*hi);
772 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
774 InsertInputOutput(mOutputList,*hi);
777 //================================================================
780 //================================================================
781 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
782 BlackBoxInputOutputDescriptor* d)
785 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
786 int nID = l->GetItemCount();
787 // std::cout << nID << std::endl;
789 // kNewItem.SetMask(wxLIST_MASK_DATA);
790 // kNewItem.SetData(d);
791 l->InsertItem(kNewItem);
792 l->SetItem(nID, 0, std2wx(d->GetName()) );
793 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
794 l->SetItem(nID, 2, std2wx(d->GetNature()) );
795 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
797 //================================================================
799 //================================================================
800 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
803 //================================================================
821 //================================================================
822 void WxGUIPackageBrowser2::OnEraseBackGround( wxEvent& )
824 mBoxList->ClearBackground();
829 //================================================================
832 //================================================================
833 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
834 WxGUIPackageBrowser2User* user )
835 : wxPanel(parent, -1),
839 _actualSelected=NULL;
840 m_mgr.SetManagedWindow(this);
842 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
843 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
846 wxLC_REPORT //wxLC_LIST
848 mBoxList->SetUser(this);
850 Connect( GetId(), wxEVT_SIZE , (wxObjectEventFunction) (void (WxGUIPackageBrowser2::*)(wxEvent&)) &WxGUIPackageBrowser2::OnEraseBackGround );
852 // JGRR & CM DISABLED CLOSE BUTTON
853 m_mgr.AddPane(mBoxList,
854 wxAuiPaneInfo().Name(wxT("BoxList"))
855 .Caption(wxT("Black Boxes"))
856 .MinimizeButton(true)
857 .MaximizeButton(true)
859 .MinSize(wxSize(100,100))
862 // sizer->Add(mBoxList,5,wxGROW);
864 mBoxInfo = new WxGUIBlackBoxInfo(this);
865 // sizer->Add(mBoxInfo,3,wxGROW);
867 // JGRR & CM DISABLED CLOSE BUTTON
868 m_mgr.AddPane(mBoxInfo,
869 wxAuiPaneInfo().Name(wxT("Box"))
871 .MinimizeButton(true)
872 .MaximizeButton(true)
874 .MinSize(wxSize(100,200))
878 wxPanel* filters = new wxPanel(this,-1);
879 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
882 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
883 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
887 fpack->Add(mPackageFilter,1,wxGROW);
888 fsizer->Add(fpack,0,wxGROW);
891 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
892 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
896 fname->Add(mNameFilter,1,wxGROW);
897 fsizer->Add(fname,0,wxGROW);
900 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
901 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
905 fdescr->Add(mDescriptionFilter,1,wxGROW);
906 fsizer->Add(fdescr,0,wxGROW);
909 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
910 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
914 fcat->Add(mCategoryFilter,1,wxGROW);
915 fsizer->Add(fcat,0,wxGROW);
916 wxBoxSizer *fintype =
918 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
919 mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
923 fintype->Add(mInputTypeFilter,1,wxGROW);
924 fsizer->Add(fintype,0,wxGROW);
925 wxBoxSizer *fouttype =
927 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
928 mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
932 fouttype->Add(mOutputTypeFilter,1,wxGROW);
933 fsizer->Add(fouttype,0,wxGROW);
936 ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL );
937 mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
941 finnat->Add(mInputNatureFilter,1,wxGROW);
942 fsizer->Add(finnat,0,wxGROW);
943 wxBoxSizer *foutnat =
945 ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL );
946 mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
950 foutnat->Add(mOutputNatureFilter,1,wxGROW);
951 fsizer->Add(foutnat,0,wxGROW);
953 mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
954 mShowWidgetsFilter->SetValue(true);
955 fsizer->Add(mShowWidgetsFilter,0,wxGROW);
957 mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
958 mShowAdaptorsFilter->SetValue(false);
959 fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
961 mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
962 mShowGUIsFilter->SetValue(false);
963 fsizer->Add(mShowGUIsFilter,0,wxGROW);
965 filters->SetSizer(fsizer);
967 // JGRR & CM DISABLED CLOSE BUTTON
968 m_mgr.AddPane(filters,
969 wxAuiPaneInfo().Name(wxT("Filter"))
970 .Caption(wxT("Filter"))
971 .MinimizeButton(true)
972 .MaximizeButton(true)
974 .MinSize(wxSize(100,100))
978 // sizer->Add(fsizer,1,wxGROW);
988 //================================================================
989 Factory::Pointer WxGUIPackageBrowser2::GetFactory()
994 //================================================================
997 //================================================================
998 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
1002 //================================================================
1004 //================================================================
1005 // User callback when a box is selected in the list
1006 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
1007 ( BlackBoxDescriptor* d)
1012 mBoxInfo->UpdateInfo(d);
1013 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
1014 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
1018 //================================================================
1020 //================================================================
1021 BlackBoxDescriptor* WxGUIPackageBrowser2::GetActualSelected()
1023 return _actualSelected;
1026 //================================================================
1028 //================================================================
1029 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
1032 mInterpreter.reset();
1033 // Object::PrintObjectListInfo("");
1036 //================================================================
1038 //================================================================
1039 void WxGUIPackageBrowser2::IncludeAll()
1041 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
1042 mInterpreter->SetCommandLine(true);
1043 std::stringstream* buf = new std::stringstream;
1044 *buf << "exec freeze_no_error" << std::endl;
1045 *buf << "message max 0" << std::endl;
1046 *buf << "include *" << std::endl;
1047 mInterpreter->InterpretBuffer(buf);
1049 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
1050 BuildFromFactory(F);
1052 //================================================================
1054 //================================================================
1055 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
1061 //================================================================
1063 //================================================================
1064 void WxGUIPackageBrowser2::RebuildList()
1066 // mBoxList->Hide();
1067 mBoxList->ClearAll();
1068 mBoxList->ClearBackground();
1069 const Factory::PackageMapType& M = mFactory->GetPackageMap();
1070 Factory::PackageMapType::const_iterator i;
1071 for (i=M.begin();i!=M.end();++i)
1073 Package::Pointer P = i->second;
1074 if (P->GetName() == "user") continue;
1076 Package::DescriptorMapType::iterator j;
1077 for (j=P->GetDescriptorMap().begin();
1078 j!=P->GetDescriptorMap().end();
1081 // std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
1082 if (IsVisible(j->second))
1083 mBoxList->Insert(j->second);
1088 //================================================================
1090 bool WxGUIPackageBrowser2::findnpos(const std::string &strA, const std::string &strB )
1092 if ((strB=="") || (strA=="") )
1099 std::string strAA=strA;
1100 std::string strBB=strB;
1103 size=strAA.length();
1104 for (i=0;i<size;i++)
1106 if ((strAA[i]>='A')&&(strAA[i]<='Z'))
1108 strAA[i]=strAA[i]+32;
1112 size=strBB.length();
1113 for (i=0;i<size;i++)
1115 if ((strBB[i]>='A')&&(strBB[i]<='Z'))
1117 strBB[i]=strBB[i]+32;
1122 if ( strAA.find(strBB) == std::string::npos )
1130 //================================================================
1131 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
1133 // std::cout << " '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
1134 // std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
1135 if ((!mShowAdaptorsFilter->IsChecked())&&
1136 ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
1137 (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
1142 if ((!mShowGUIsFilter->IsChecked())&&
1143 ((d->GetKind()==BlackBoxDescriptor::GUI)||
1144 (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
1149 //EED if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) ) == std::string::npos )
1150 if ( findnpos(d->GetPackage()->GetName(),wx2std(mPackageFilter->GetValue())) == true )
1155 //EED if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) ) == std::string::npos )
1156 if ( findnpos(d->GetTypeName(),wx2std(mNameFilter->GetValue())) == true )
1161 //EED if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) ) == std::string::npos )
1162 if ( findnpos(d->GetDescription(),wx2std(mDescriptionFilter->GetValue())) == true )
1167 //EED if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) ) == std::string::npos )
1168 if ( findnpos(d->GetCategory(),wx2std(mCategoryFilter->GetValue())) == true )
1173 if (!mShowWidgetsFilter->IsChecked())
1176 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1177 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1178 for ( in = imap.begin(); in != imap.end(); ++in )
1180 if (in->second->GetName() == "Widget" )
1192 if (mInputTypeFilter->GetValue().size()>0)
1194 std::string s = wx2std(mInputTypeFilter->GetValue());
1196 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
1197 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1198 for ( in = imap.begin(); in != imap.end(); ++in )
1200 //EED if (in->second->GetTypeName().find(s)!=std::string::npos)
1201 if ( findnpos( in->second->GetTypeName() , s ) == true )
1213 if (mOutputTypeFilter->GetValue().size()>0)
1215 std::string s = wx2std(mOutputTypeFilter->GetValue());
1217 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1218 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1219 for ( in = imap.begin(); in != imap.end(); ++in )
1221 //EED if (in->second->GetTypeName().find(s)!=std::string::npos)
1222 if ( findnpos( in->second->GetTypeName() , s ) == true )
1234 if (mInputNatureFilter->GetValue().size()>0)
1236 std::string s = wx2std(mInputNatureFilter->GetValue());
1238 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
1239 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1240 for ( in = imap.begin(); in != imap.end(); ++in )
1242 //EED if (in->second->GetNature().find(s)!=std::string::npos)
1243 if ( findnpos( in->second->GetNature() , s ) == true )
1255 if (mOutputNatureFilter->GetValue().size()>0)
1257 std::string s = wx2std(mOutputNatureFilter->GetValue());
1259 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
1260 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1261 for ( in = imap.begin(); in != imap.end(); ++in )
1263 //EED if (in->second->GetNature().find(s)!=std::string::npos)
1264 if ( findnpos( in->second->GetNature() , s ) == true )
1279 //========================================================================
1281 //========================================================================
1282 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1283 //EED EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1284 //EED EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1285 //EED EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1286 //EED EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1287 //EED EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1288 //EED EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1289 //EED EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
1290 //EED EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
1292 EVT_TEXT(id_f1, WxGUIPackageBrowser2::OnFilter )
1293 EVT_TEXT(id_f2, WxGUIPackageBrowser2::OnFilter )
1294 EVT_TEXT(id_f3, WxGUIPackageBrowser2::OnFilter )
1295 EVT_TEXT(id_f4, WxGUIPackageBrowser2::OnFilter )
1296 EVT_TEXT(id_f5, WxGUIPackageBrowser2::OnFilter )
1297 EVT_TEXT(id_f6, WxGUIPackageBrowser2::OnFilter )
1298 EVT_TEXT(id_f7, WxGUIPackageBrowser2::OnFilter )
1299 EVT_TEXT(id_f8, WxGUIPackageBrowser2::OnFilter )
1301 EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
1302 EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
1303 EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
1305 //========================================================================
1309 //================================================================
1310 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
1313 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1315 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1317 mBrowser = new WxGUIPackageBrowser2(this);
1318 mBrowser->IncludeAll();
1319 sizer->Add(mBrowser,1,wxGROW);
1321 // WxGUICommand* com = new WxGUICommand(this,this);
1326 // Creates the parent window of all bbtk windows as a child of this
1327 // Wx::CreateTopWindow(this);
1328 // Add the method OnWxSignal as a Wx::Signal observer
1329 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
1331 SetAutoLayout(true);
1334 //================================================================
1336 //================================================================
1337 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1340 //================================================================
1345 #endif //_USE_WXWIDGETS_