From 141959873bfc3610f427de9a7690458a8b18bd2a Mon Sep 17 00:00:00 2001 From: guigues Date: Mon, 10 Mar 2008 12:28:43 +0000 Subject: [PATCH] Fixed X Window Server errors with wxvtk::Viewer2D (bad synchro between wx and vtk objects). --- kernel/src/bbtkWxBlackBox.cxx | 61 +++++++++++++++--- kernel/src/bbtkWxBlackBox.h | 63 ++++++++++++++----- kernel/src/bbtkWxConsole.cxx | 16 +++-- packages/wx/src/bbwxSlider.cxx | 10 +-- .../wxvtk/bbs/appli/ExampleSimpleSlicer.bbs | 1 + packages/wxvtk/bbs/appli/ExampleViewer2D.bbs | 13 +--- packages/wxvtk/bbs/boxes/bbSimpleSlicer.bbs | 13 ++-- packages/wxvtk/src/bbwxvtkViewer2D.cxx | 35 ++++++++--- packages/wxvtk/src/bbwxvtkViewer2D.h | 7 ++- 9 files changed, 155 insertions(+), 64 deletions(-) diff --git a/kernel/src/bbtkWxBlackBox.cxx b/kernel/src/bbtkWxBlackBox.cxx index f214188..5b8e52f 100644 --- a/kernel/src/bbtkWxBlackBox.cxx +++ b/kernel/src/bbtkWxBlackBox.cxx @@ -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()<<")"<bbSetWindow(this); Wx::IncNbWindowsAlive(); - bbtkDebugMessage("Wx",9," -> Number of windows alive = " + bbtkDebugMessage("Wx",5," -> Number of windows alive = " <bbSetWindow(0); Wx::DecNbWindowsAlive(); - bbtkDebugMessage("Wx",9," -> Number of windows alive = " + bbtkDebugMessage("Wx",5," -> Number of windows alive = " <bbGetFullName()<<"]"< Number of windows shown = " + bbtkDebugMessage("Wx",5," -> Number of windows shown = " <bbGetFullName()<<"]"< Number of windows shown = " + bbtkDebugMessage("Wx",5," -> Number of windows shown = " <bbGetFullName()<<")"<bbUserOnShow(); + // wxFrame::SetFocus(); } //========================================================================= @@ -233,7 +239,8 @@ namespace bbtk bbtkDebugMessage("Wx",9,"WxBlackBoxFrame::bbHide() ["<< bbGetBlackBox()->bbGetFullName()<<"]"<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 diff --git a/kernel/src/bbtkWxBlackBox.h b/kernel/src/bbtkWxBlackBox.h index b7a3eab..700fa3e 100644 --- a/kernel/src/bbtkWxBlackBox.h +++ b/kernel/src/bbtkWxBlackBox.h @@ -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(); //================================================================== diff --git a/kernel/src/bbtkWxConsole.cxx b/kernel/src/bbtkWxConsole.cxx index a599ead..31ca73b 100644 --- a/kernel/src/bbtkWxConsole.cxx +++ b/kernel/src/bbtkWxConsole.cxx @@ -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(); diff --git a/packages/wx/src/bbwxSlider.cxx b/packages/wx/src/bbwxSlider.cxx index 6261380..192553b 100644 --- a/packages/wx/src/bbwxSlider.cxx +++ b/packages/wx/src/bbwxSlider.cxx @@ -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 = "<GetRenderer()->ResetCamera(x1,x2,y1,y2,z1,z2); } - - if (backImageData!=NULL) + // std::cout << "update"<=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()"<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 diff --git a/packages/wxvtk/src/bbwxvtkViewer2D.h b/packages/wxvtk/src/bbwxvtkViewer2D.h index 9fed719..d24947c 100644 --- a/packages/wxvtk/src/bbwxvtkViewer2D.h +++ b/packages/wxvtk/src/bbwxvtkViewer2D.h @@ -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(); }; //================================================================= -- 2.45.1