]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkWxGUIPackageBrowser2.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWxGUIPackageBrowser2.cxx
index acae35486618ae4f09ec5b3b3ec31edcd0467194..462c40dac2e732b8a8d75cc1eebd3fe052e10858 100644 (file)
@@ -3,8 +3,8 @@
 Program:   bbtk
 Module:    $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
 Language:  C++
-Date:      $Date: 2008/04/04 09:45:04 $
-Version:   $Revision: 1.2 $
+Date:      $Date: 2008/07/23 11:46:11 $
+Version:   $Revision: 1.10 $
                                                                                 
 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
 l'Image). All rights reserved. See Doc/License.txt or
@@ -109,12 +109,12 @@ namespace bbtk
 #endif
   }
   
-  void WxGUIBlackBoxList::Insert(BlackBoxDescriptor* d)
+  void WxGUIBlackBoxList::Insert(BlackBoxDescriptor::Pointer d)
   {
     if (GetColumnCount()!=3)
       {
        InsertColumn( 0, _("Package"), 
-                     wxLIST_FORMAT_LEFT, 40  ); 
+                     wxLIST_FORMAT_LEFT, 60  ); 
        InsertColumn( 1, _("Box"), 
                      wxLIST_FORMAT_LEFT, 200 ); 
        InsertColumn( 2, _("Description"), 
@@ -127,8 +127,9 @@ namespace bbtk
     int nID = this->GetItemCount();
     kNewItem.SetId(nID);
     kNewItem.SetMask(wxLIST_MASK_DATA);
-    kNewItem.SetData(d);  
-    //    BlackBoxDescriptor* d2 = (BlackBoxDescriptor*)kNewItem.GetData();
+    // TO DO : STORE SMART POINTER ?
+    kNewItem.SetData(d.get());  
+    //    BlackBoxDescriptor::Pointer* d2 = (BlackBoxDescriptor::Pointer*)kNewItem.GetData();
     //    std::cout << "Descr = "<<d<<" = "<<d2<<std::endl;
     this->InsertItem(kNewItem);
     this->SetItem(nID, 0, std2wx(d->GetPackage()->GetName()) );
@@ -192,7 +193,7 @@ namespace bbtk
 
   void WxGUIBlackBoxList::LogColEvent(const wxListEvent& event, const wxChar *name)
   {
-    const int col = event.GetColumn();
+    //    const int col = event.GetColumn();
 
     /*
       wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
@@ -228,9 +229,8 @@ namespace bbtk
 
   void WxGUIBlackBoxList::OnBeginDrag(wxListEvent& event)
   {
-    const wxPoint& pt = event.m_pointDrag;
+    //    const wxPoint& pt = event.m_pointDrag;
 
-    int flags;
     //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
     //          pt.x, pt.y, HitTest(pt, flags) );
   }
@@ -312,6 +312,7 @@ namespace bbtk
     info.m_mask = wxLIST_MASK_DATA;
     if ( GetItem(info) )
       {
+       // TO DO : STORE SMART PTR ?
        BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
        if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
       }
@@ -464,7 +465,8 @@ namespace bbtk
 
     int flags;
     long subitem;
-    long item = HitTest(event.GetPosition(), flags, &subitem);
+    //    long item = 
+    HitTest(event.GetPosition(), flags, &subitem);
 
     wxString where;
     switch ( flags )
@@ -556,7 +558,7 @@ namespace bbtk
   WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
     :
     wxPanel(parent, -1),
-    mDescriptor(0)
+    mDescriptor()
   {
     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
     
@@ -617,7 +619,9 @@ namespace bbtk
                               wxLIST_FORMAT_LEFT, 80  ); 
     mInputList->InsertColumn( 1, _("Type"), 
                               wxLIST_FORMAT_LEFT, 100 ); 
-    mInputList->InsertColumn( 2, _("Description"), 
+    mInputList->InsertColumn( 2, _("Nature"), 
+                              wxLIST_FORMAT_LEFT, 100  ); 
+    mInputList->InsertColumn( 3, _("Description"), 
                               wxLIST_FORMAT_LEFT, 500  ); 
 
     mOutputList->ClearAll();
@@ -625,7 +629,9 @@ namespace bbtk
                               wxLIST_FORMAT_LEFT, 80  ); 
     mOutputList->InsertColumn( 1, _("Type"), 
                               wxLIST_FORMAT_LEFT, 100 ); 
-    mOutputList->InsertColumn( 2, _("Description"), 
+    mOutputList->InsertColumn( 2, _("Nature"), 
+                              wxLIST_FORMAT_LEFT, 100  ); 
+    mOutputList->InsertColumn( 3, _("Description"), 
                               wxLIST_FORMAT_LEFT, 500  ); 
     
 
@@ -718,14 +724,15 @@ namespace bbtk
     wxListItem kNewItem;
     kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
     int nID = l->GetItemCount();
-    std::cout << nID << std::endl;
+    //    std::cout << nID << std::endl;
     kNewItem.SetId(nID);
     //    kNewItem.SetMask(wxLIST_MASK_DATA);
     //    kNewItem.SetData(d);  
     l->InsertItem(kNewItem);
     l->SetItem(nID, 0, std2wx(d->GetName()) );
     l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
-    l->SetItem(nID, 2, std2wx(d->GetDescription()) );
+    l->SetItem(nID, 2, std2wx(d->GetNature()) );
+    l->SetItem(nID, 3, std2wx(d->GetDescription()) );
   }
   //================================================================
 
@@ -743,8 +750,12 @@ namespace bbtk
       id_f3,
       id_f4,
       id_f5,
-      id_f6
-
+      id_f6,
+      id_f7,
+      id_f8,
+      id_fc1,
+      id_fc2,
+      id_fc3
     };
 
 
@@ -753,7 +764,7 @@ namespace bbtk
                                              WxGUIPackageBrowser2User* user )
     : wxPanel(parent, -1),
       mUser(user),
-      mInterpreter(0)
+      mInterpreter()
   {
     m_mgr.SetManagedWindow(this);
 
@@ -785,7 +796,7 @@ namespace bbtk
                  .MinimizeButton(true)
                  .MaximizeButton(true)
                  .Bottom()
-                 .MinSize(wxSize(100,100))
+                 .MinSize(wxSize(100,300))
                  );     
     
 
@@ -829,8 +840,8 @@ namespace bbtk
     fsizer->Add(fcat,0,wxGROW);
     wxBoxSizer *fintype = 
       new wxStaticBoxSizer
-      ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );    
-    mInputTypeFilter = new wxTextCtrl(filters,id_f4,_T(""),
+      ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
+    mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
                                    wxDefaultPosition,
                                    wxDefaultSize,
                                    wxTE_PROCESS_ENTER);
@@ -839,12 +850,43 @@ namespace bbtk
     wxBoxSizer *fouttype = 
       new wxStaticBoxSizer
       ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
-    mOutputTypeFilter = new wxTextCtrl(filters,id_f4,_T(""),
+    mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
                                    wxDefaultPosition,
                                    wxDefaultSize,
                                    wxTE_PROCESS_ENTER);
     fouttype->Add(mOutputTypeFilter,1,wxGROW);
     fsizer->Add(fouttype,0,wxGROW);
+    wxBoxSizer *finnat = 
+      new wxStaticBoxSizer
+      ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL ); 
+    mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
+                                       wxDefaultPosition,
+                                       wxDefaultSize,
+                                       wxTE_PROCESS_ENTER);
+    finnat->Add(mInputNatureFilter,1,wxGROW);
+    fsizer->Add(finnat,0,wxGROW);
+    wxBoxSizer *foutnat = 
+      new wxStaticBoxSizer
+      ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL ); 
+    mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
+                                       wxDefaultPosition,
+                                       wxDefaultSize,
+                                       wxTE_PROCESS_ENTER);
+    foutnat->Add(mOutputNatureFilter,1,wxGROW);
+    fsizer->Add(foutnat,0,wxGROW);
+
+
+    mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
+    mShowWidgetsFilter->SetValue(true);
+    fsizer->Add(mShowWidgetsFilter,0,wxGROW);
+
+    mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
+    mShowAdaptorsFilter->SetValue(false);
+    fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
+
+    mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
+    mShowGUIsFilter->SetValue(false);
+    fsizer->Add(mShowGUIsFilter,0,wxGROW);
 
     filters->SetSizer(fsizer);
 
@@ -877,7 +919,8 @@ namespace bbtk
 
   //================================================================
   // User callback when a box is selected in the list 
-  void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected( BlackBoxDescriptor* d)
+  void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
+  ( BlackBoxDescriptor* d)
   {
     mBoxInfo->UpdateInfo(d);
     std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
@@ -890,26 +933,30 @@ namespace bbtk
   //================================================================
   WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
   {
-    std::cout << "del interpreter" << std::endl;
-    if (mInterpreter) delete mInterpreter;
-    std::cout << "ok" << std::endl;
+    mFactory.reset();
+    mInterpreter.reset();
+    //    Object::PrintObjectListInfo("");
+    m_mgr.UnInit();
   }
   //================================================================
 
   //================================================================
   void WxGUIPackageBrowser2::IncludeAll()
   {
-    if (!mInterpreter) mInterpreter = new bbtk::Interpreter();
+    if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
     mInterpreter->SetCommandLine(true);
-    mInterpreter->InterpretLine("include *");
+    std::stringstream* buf = new std::stringstream;
+    *buf << "message max 0" << std::endl; 
+    *buf << "include *" << std::endl;
+    mInterpreter->InterpretBuffer(buf);
 
-    Factory* F = mInterpreter->GetExecuter()->GetFactory();
+    Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
     BuildFromFactory(F);
   }
   //================================================================
 
   //================================================================
-  void WxGUIPackageBrowser2::BuildFromFactory(Factory* F)
+  void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
   {
     mFactory = F;
     RebuildList();
@@ -926,7 +973,7 @@ namespace bbtk
     Factory::PackageMapType::const_iterator i;
     for (i=M.begin();i!=M.end();++i)
       {
-       Package* P = i->second.mPackage;
+       Package::Pointer P = i->second;
        if (P->GetName() == "user") continue;
        
        Package::BlackBoxMapType::iterator j;
@@ -944,10 +991,18 @@ namespace bbtk
   //================================================================
 
   //================================================================
-  bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor* d)
+  bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
   {
     //    std::cout << "   '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
     //    std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
+    if ((!mShowAdaptorsFilter->IsChecked())&&
+       ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
+        (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
+      return false;
+    if ((!mShowGUIsFilter->IsChecked())&&
+       ((d->GetKind()==BlackBoxDescriptor::GUI)||
+        (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
+      return false;
     if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) ) 
        == std::string::npos ) return false;
    if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) ) 
@@ -956,6 +1011,22 @@ namespace bbtk
        == std::string::npos ) return false;
    if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) ) 
        == std::string::npos ) return false;
+   if (!mShowWidgetsFilter->IsChecked())
+     {
+       bool found = false;
+       const BlackBoxDescriptor::OutputDescriptorMapType& imap = 
+        d->GetOutputDescriptorMap();
+       BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
+       for ( in = imap.begin();  in != imap.end(); ++in ) 
+        {
+          if (in->second->GetName() == "Widget" )
+            {
+              found = true;
+              break;
+            }
+        }
+       if (found) return false;
+     }
    if (mInputTypeFilter->GetValue().size()>0)
      {
        std::string s = wx2std(mInputTypeFilter->GetValue());
@@ -990,7 +1061,40 @@ namespace bbtk
         }
        if (!found) return false;
      }
-
+   if (mInputNatureFilter->GetValue().size()>0)
+     {
+       std::string s = wx2std(mInputNatureFilter->GetValue());
+       bool found = false;
+       const BlackBoxDescriptor::InputDescriptorMapType& imap = 
+        d->GetInputDescriptorMap();
+       BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
+       for ( in = imap.begin();  in != imap.end(); ++in ) 
+        {
+          if (in->second->GetNature().find(s)!=std::string::npos)
+            {
+              found = true;
+              break;
+            }
+        }
+       if (!found) return false;
+     }
+   if (mOutputNatureFilter->GetValue().size()>0)
+     {
+       std::string s = wx2std(mOutputNatureFilter->GetValue());
+       bool found = false;
+       const BlackBoxDescriptor::OutputDescriptorMapType& imap = 
+        d->GetOutputDescriptorMap();
+       BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
+       for ( in = imap.begin();  in != imap.end(); ++in ) 
+        {
+          if (in->second->GetNature().find(s)!=std::string::npos)
+            {
+              found = true;
+              break;
+            }
+        }
+       if (!found) return false;
+     }
 
     return true;
   }
@@ -1004,6 +1108,11 @@ namespace bbtk
     EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
     EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
     EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
+    EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
+    EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
+    EVT_CHECKBOX(  id_fc1, WxGUIPackageBrowser2::OnFilter )
+    EVT_CHECKBOX(  id_fc2, WxGUIPackageBrowser2::OnFilter )
+    EVT_CHECKBOX(  id_fc3, WxGUIPackageBrowser2::OnFilter )
     END_EVENT_TABLE()
   //========================================================================
 
@@ -1028,12 +1137,11 @@ namespace bbtk
     
     SetSizer(sizer);
 
-    // Creates and sets the parent window of all bbtk windows
-    wxWindow* top = new wxPanel(this,-1);
-    top->Hide();
-    
-    Wx::SetTopWindow(top);
-   
+     // Creates the parent window of all bbtk windows as a child of this
+//    Wx::CreateTopWindow(this);
+    // Add the method OnWxSignal as a Wx::Signal observer 
+    //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
     SetAutoLayout(true);
     Layout();
   }