]> Creatis software - bbtk.git/commitdiff
Fixed X Window Server errors with wxvtk::Viewer2D (bad synchro between wx and vtk...
authorguigues <guigues>
Mon, 10 Mar 2008 12:28:43 +0000 (12:28 +0000)
committerguigues <guigues>
Mon, 10 Mar 2008 12:28:43 +0000 (12:28 +0000)
kernel/src/bbtkWxBlackBox.cxx
kernel/src/bbtkWxBlackBox.h
kernel/src/bbtkWxConsole.cxx
packages/wx/src/bbwxSlider.cxx
packages/wxvtk/bbs/appli/ExampleSimpleSlicer.bbs
packages/wxvtk/bbs/appli/ExampleViewer2D.bbs
packages/wxvtk/bbs/boxes/bbSimpleSlicer.bbs
packages/wxvtk/src/bbwxvtkViewer2D.cxx
packages/wxvtk/src/bbwxvtkViewer2D.h

index f214188..5b8e52f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxBlackBox.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/03/10 10:01:14 $
-  Version:   $Revision: 1.9 $
+  Date:      $Date: 2008/03/10 12:28:43 $
+  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
@@ -55,7 +55,7 @@ namespace bbtk
                     mBox->bbGetFullName()<<")"<<std::endl);
     mBox->bbSetWindow(this);
     Wx::IncNbWindowsAlive();
-    bbtkDebugMessage("Wx",9," -> Number of windows alive = "
+    bbtkDebugMessage("Wx",5," -> Number of windows alive = "
                     <<Wx::GetNbWindowsAlive()<<std::endl);
   }
   //=========================================================================
@@ -68,7 +68,7 @@ namespace bbtk
     bbHide();
     mBox->bbSetWindow(0);
     Wx::DecNbWindowsAlive();
-    bbtkDebugMessage("Wx",9," -> Number of windows alive = "
+    bbtkDebugMessage("Wx",5," -> Number of windows alive = "
                     <<Wx::GetNbWindowsAlive()<<std::endl);
      
 
@@ -84,7 +84,7 @@ namespace bbtk
                     mBox->bbGetFullName()<<"]"<<std::endl);
     Wx::IncNbWindowsShown();
     mShown = true;
-    bbtkDebugMessage("Wx",9," -> Number of windows shown = "
+    bbtkDebugMessage("Wx",5," -> Number of windows shown = "
                     <<Wx::GetNbWindowsShown()<<std::endl);
   }
   //=========================================================================
@@ -97,7 +97,7 @@ namespace bbtk
                     mBox->bbGetFullName()<<"]"<<std::endl);
     Wx::DecNbWindowsShown();
     mShown = false;
-    bbtkDebugMessage("Wx",9," -> Number of windows shown = "
+    bbtkDebugMessage("Wx",5," -> Number of windows shown = "
                     <<Wx::GetNbWindowsShown()<<std::endl);
   }
   //=========================================================================
@@ -223,7 +223,13 @@ namespace bbtk
     bbtkDebugMessage("Wx",5,"WxBlackBoxFrame::bbShow("
                     <<bbGetBlackBox()->bbGetFullName()<<")"<<std::endl);
     WxBlackBoxWindow::bbShow();
-    wxFrame::Show(); 
+    wxFrame::Show();
+    // This Update is ** MANDATORY ** 
+    // to synchronize wxvtkRenderWindowInteractor objects
+    // (force wx objects creation **NOW**)
+    wxFrame::Update();
+    bbGetBlackBox()->bbUserOnShow();
+    //    wxFrame::SetFocus();
   }
   //=========================================================================
 
@@ -233,7 +239,8 @@ namespace bbtk
     bbtkDebugMessage("Wx",9,"WxBlackBoxFrame::bbHide() ["<<
                     bbGetBlackBox()->bbGetFullName()<<"]"<<std::endl);
     WxBlackBoxWindow::bbHide();
-    Hide();
+    wxFrame::Hide();
+    bbGetBlackBox()->bbUserOnHide();
   }
   //=========================================================================
 
@@ -524,6 +531,15 @@ namespace bbtk
   //=========================================================================
 
 
+  //=========================================================================
+  void WxBlackBox::bbProcess()
+  { 
+    if (bbGetOutputWidget()==0) this->bbUserCreateWidget();
+    this->bbUserProcess(); 
+    bbShowWindow();
+  }
+  //=========================================================================
+  
   //==================================================================
   /// Specific methods for window creation during pipeline execution
   /// Shows the window associated to the box 
@@ -654,6 +670,35 @@ namespace bbtk
   //==================================================================
 
 
+  //==================================================================
+  WxBlackBox::Window* WxBlackBox::bbGetContainingWindow()
+  {
+    if (bbGetWindow()!=0) return bbGetWindow();
+    BlackBox::OutputConnectorMapType::const_iterator i 
+      = bbGetOutputConnectorMap().find("Widget");
+    if ( i->second->GetConnectionVector().size() != 0 ) 
+      {
+       return ((WxBlackBox*)i->second->GetConnectionVector().front()
+               ->GetBlackBoxTo())->bbGetContainingWindow();
+      }
+    return 0;
+  }
+  //==================================================================
+
+
+  //==================================================================
+  wxWindow* WxBlackBox::bbGetWxParent() { return Wx::GetTopWindow(); }
+  //==================================================================
+  
+  
+  //==================================================================
+  bool WxBlackBox::bbIsShown()
+  {
+    if (bbGetContainingWindow()!=0)
+      return bbGetContainingWindow()->bbIsShown();
+    return false;
+  }
+  //==================================================================
 
 
 }//namespace bbtk
index b7a3eab..700fa3e 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxBlackBox.h,v $
   Language:  C++
-  Date:      $Date: 2008/03/06 09:23:43 $
-  Version:   $Revision: 1.8 $
+  Date:      $Date: 2008/03/10 12:28:43 $
+  Version:   $Revision: 1.9 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -74,15 +74,37 @@ namespace bbtk
   public:
     typedef WxBlackBoxWindow Window;
     
-    /// Returns the window associated to the box
+    /// Returns the **OWN** window associated to the box
     /// If 0 returned = no window
     Window* bbGetWindow() { return bbmWindow; }
 
-    /// Returns the Parent Window that must be used to create the widget 
-    wxWindow* bbGetWxParent() { return Wx::GetTopWindow(); }
+    /// Returns the window containing the widget associated to the box
+    /// Which can be the own window of **ANOTHER** box in case of 
+    /// a hierarchy of widgets.
+    /// More precisely :
+    /// If bbGetWindow() != 0 then returns bbGetWindow()
+    /// Else if the output 'Widget' is connected 
+    ///  then returns bbGetContainingWindow() of the box connected to 'Widget'
+    /// Else returns 0;
+    Window* bbGetContainingWindow();
 
+    /// Returns the parent wxWindow that must be used to create the widget 
+    wxWindow* bbGetWxParent();
 
+    /// Returns true iff the 'containing window' exists and is shown 
+    /// (see bbGetContainingWindow).
+    bool bbIsShown();
+
+    //==================================================================    
+    /// User callback invoked when the containing window is shown
+    virtual void bbUserOnShow() {}
+    //==================================================================    
  
+    //==================================================================    
+    /// User callback invoked when the containing window is hidden
+    virtual void bbUserOnHide() {}
+    //==================================================================    
+
   protected:
     
   
@@ -100,24 +122,35 @@ namespace bbtk
     /// ** Must be defined **
     virtual void bbUserCreateWidget() 
     {
-      bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is undefined : cannot work !!");
+      bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
     }
     //==================================================================    
+
+
     
+
+
+
+
+
+
     //==================================================================
-    /// Calls the user defined widget creation method 
-    /// and the user processing method and then displays the window
-    virtual void bbProcess() 
-    { 
-      if (bbGetOutputWidget()==0) this->bbUserCreateWidget();
-      this->bbUserProcess(); 
-      bbShowWindow();
-    }
+    /// Overloaded processing method for WxBlackBoxes :
+    /// 1) if the widget is null then 
+    ///    calls the user defined widget creation method : bbUserCreateWidget()
+    /// 2) calls the user defined processing method : bbUserProcess()
+    /// 3) displays the window : bbShowWindow();
+    virtual void bbProcess();
     //==================================================================
 
     //==================================================================
-    /// Specific methods for windows creation during pipeline execution
+    /// If necessary creates the WxBlackBoxWindow associated to the box
+    /// and shows it 
+    /// (does nothing if the box output 'Widget' is connected which 
+    /// means that the box does not have its own window but is contained 
+    /// into another window)
     void bbShowWindow();
+    /// Hides the WxBlackBoxWindow associated to the box (if exists)
     void bbHideWindow();
     //==================================================================
 
index a599ead..31ca73b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxConsole.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/03/10 10:01:14 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2008/03/10 12:28:43 $
+  Version:   $Revision: 1.11 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -330,11 +330,15 @@ namespace bbtk
       new WxTextCtrlStreamRedirector(std::cerr,mwxTextHistory,*wxGREEN,true); 
         
     // Creates and sets the parent window of all bbtk windows
-    wxFrame* top = new wxFrame(this,-1,_T("bbtk"),
-                              wxDefaultPosition,
-                              wxSize(0,0),
-                              wxFRAME_TOOL_WINDOW) ;//wxMINIMIZE_BOX);
+    wxWindow* top = new wxPanel(this,-1);//,_T("top"));
+    top->Hide();
+    //new wxFrame(this,-1,_T("bbtk"),
+    //                        wxDefaultPosition,
+    //                        wxSize(0,0),
+    //                        wxFRAME_TOOL_WINDOW) ;//wxMINIMIZE_BOX);
+    
     Wx::SetTopWindow(top);
+
     //    top->Show();
     
 
index 6261380..192553b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbwxSlider.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/03/10 10:01:15 $
-  Version:   $Revision: 1.9 $
+  Date:      $Date: 2008/03/10 12:28:43 $
+  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
@@ -356,7 +356,7 @@ namespace bbwx
     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|V|VERTICAL")==true)    { orientation=1; }
     
     
-    std::cout << "bbGetWxParent = "<<bbGetWxParent()<<std::endl;
+    //    std::cout << "bbGetWxParent = "<<bbGetWxParent()<<std::endl;
     SliderWidget *w =  new SliderWidget(this, 
                                        bbGetWxParent(),
                                        orientation , 
@@ -368,8 +368,8 @@ namespace bbwx
                                        bbGetInputIn(),
                                        bbGetInputReactiveOnTrack()
                                        ); 
-    std::cout << "w = "<<w<<std::endl;
-         //    w->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );
+    //    std::cout << "w = "<<w<<std::endl;
+    // w->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );
          
     bbSetOutputWidget( w );
   }
index 38f596a..536bce5 100644 (file)
@@ -13,6 +13,7 @@ load std
 set viewer.WinTitle "ExampleSimpleSlicer"
 set viewer.WinWidth 350
 set viewer.WinHeight 400
+set viewer.Slice 20
 
 exec viewer
 
index 7eb6c5e..b6a8373 100644 (file)
@@ -13,18 +13,7 @@ connect image.Out viewer.In
 load std
 set viewer.WinTitle "ExampleViewer2D"
 set viewer.Slice 20
-
 set viewer.WinWidth 400
 set viewer.WinHeight 400
 
-# BUG :
-#exec viewer
-
-# The same :
-new LayoutLine l
-connect viewer.Widget l.Widget1
-exec l
-
-
-
-
+exec viewer
index 7c4b51e..d1a3235 100644 (file)
@@ -9,28 +9,29 @@ define SimpleSlicer
  category "viewer"
 
  new LayoutLine main
- new Viewer2D slicer
+ new Viewer2D viewer2D
  new Slider slider
  # WE NEED A MultipleInputs BOX TO CONNECT BOTH 
  # slider.BoxChange AND THE INPUT BoxExecute 
- # OF THE COMPLEX BOX TO slicer.BoxExecute
+ # OF THE COMPLEX BOX TO viewer2D.BoxExecute
  new MultipleInputs refresh
 
- connect slicer.Widget main.Widget1
+ connect viewer2D.Widget main.Widget1
  connect slider.Widget main.Widget2
- connect slider.Out slicer.Slice
+ connect slider.Out viewer2D.Slice
 
  connect slider.BoxChange refresh.In1
- connect refresh.Out slicer.BoxExecute
+ connect refresh.Out viewer2D.BoxExecute
 
  #set main.Proportion 80
  set slider.Title "Slice"
 
- input In slicer.In "Input image"
+ input In viewer2D.In "Input image"
  input WinTitle main.WinTitle "Title of the window"
  input WinWidth main.WinWidth "Width of the window"
  input WinHeight main.WinHeight "Height of the window"
  input BoxExecute refresh.In2 "Execute the box"
+ input Slice slider.In "Initial slice"
  output Widget main.Widget "Widget"
 
  # EXECUTING THE COMPLEX BOX EXECUTES main
index 18882c4..43a20b3 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbwxvtkViewer2D.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/03/03 13:14:27 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2008/03/10 12:28:44 $
+  Version:   $Revision: 1.2 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -75,7 +75,7 @@ namespace bbwxvtk
 
 
 
-  void Viewer2DWidget::Update()
+  void Viewer2DWidget::UpdateView()
   {
 
     if (imageViewer==NULL){
@@ -116,14 +116,22 @@ namespace bbwxvtk
        //              imageViewer->GetRenderer()->ResetCamera(x1,x2,y1,y2,z1,z2);
       }
   
-  
-    if (backImageData!=NULL)
+    //    std::cout << "update"<<std::endl;   
+    //    std::cout << "OW = "<< mBox->bbGetWindow() << std::endl;
+    //    std::cout << "CW = "<< mBox->bbGetContainingWindow() << std::endl;
+    //    std::cout << "Sh = "<< mBox->bbIsShown() << std::endl;
+
+    // mBox->bbIsShown() is necessary to be sure that the wxWindow is already 
+    // created and displayed. 
+    // Else when slice != 0 we get an X Window System error with wxGTK
+    if ((backImageData!=NULL)&&(mBox->bbIsShown()))
       {
        int z = mBox->bbGetInputSlice();
-
+       //      std::cout << "slice = "<<z<<std::endl;
        int ext[6];
        backImageData->GetWholeExtent(ext);
 
+       //      std::cout << "ext = "<<ext[4]<<" - "<<ext[5]<<std::endl;
 
        if (z<ext[4]) { z=ext[4]; }
        if (z>=ext[5]) { z=ext[5]-1; }
@@ -135,12 +143,14 @@ namespace bbwxvtk
        imageViewer->SetZSlice( z );
 #endif
 
+
       }
     
     wxvtkrenderwindowinteractor->Render();
     //    wxvtkrenderwindowinteractor->Refresh();
     
-    //    Refresh();
+
+    //Refresh();
   }
 
 
@@ -157,7 +167,7 @@ namespace bbwxvtk
 
   void Viewer2D::Process() 
   { 
-    ((Viewer2DWidget*)bbGetOutputWidget())->Update();
+    ((Viewer2DWidget*)bbGetOutputWidget())->UpdateView();
     bbSetOutputOut( bbGetInputSlice() );
   }
   
@@ -172,13 +182,20 @@ namespace bbwxvtk
     bbtkDebugMessageInc("Core",9,"Viewer2D::CreateWidget()"<<std::endl);
 
     Viewer2DWidget* w = new Viewer2DWidget(this,bbGetWxParent());
-    w->Update();
     bbSetOutputWidget(w);
 
     bbtkDebugDecTab("Core",9);
   }
 
 
+  // This callback is necessary to get actual processing of the view 
+  // when window is shown
+  void  Viewer2D::bbUserOnShow()
+  {
+    ((Viewer2DWidget*)bbGetOutputWidget())->UpdateView();
+  }
+  
+
 }//namespace bbtk
 
 #endif
index 9fed719..d24947c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbwxvtkViewer2D.h,v $
   Language:  C++
-  Date:      $Date: 2008/03/03 13:14:27 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2008/03/10 12:28:44 $
+  Version:   $Revision: 1.2 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -57,7 +57,7 @@ namespace bbwxvtk
   public:
     Viewer2DWidget(Viewer2D* box, wxWindow *parent);
     ~Viewer2DWidget();
-    void Update();
+    void UpdateView();
   private:
     Viewer2D                     *mBox;
     vtkImageViewer2             *imageViewer;
@@ -83,6 +83,7 @@ namespace bbwxvtk
     void Process();
     BBTK_CREATE_WIDGET(CreateWidget);
     void CreateWidget();
+    void bbUserOnShow();
   };
    
   //=================================================================