]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
To improve Initialize functionality in order to
authorapo <apo@opencascade.com>
Wed, 21 Sep 2005 11:47:51 +0000 (11:47 +0000)
committerapo <apo@opencascade.com>
Wed, 21 Sep 2005 11:47:51 +0000 (11:47 +0000)
provide explicit way of SVTK initialization

src/SVTK/SVTK_RenderWindowInteractor.cxx
src/SVTK/SVTK_RenderWindowInteractor.h
src/SVTK/SVTK_View.cxx
src/SVTK/SVTK_View.h
src/SVTK/SVTK_ViewWindow.cxx

index e004c782add0390ce3149b1598a809b45bf1cf06..d627fd7614198b05bedbcd49beda745c607e235b 100644 (file)
@@ -76,13 +76,31 @@ static int MYDEBUG = 0;
 QVTK_RenderWindowInteractor
 ::QVTK_RenderWindowInteractor(QWidget* theParent, 
                              const char* theName):
-  QWidget(theParent,theName)
+  QWidget(theParent,theName),
+  myRenderWindow(vtkRenderWindow::New())
 {
   if(MYDEBUG) INFOS("QVTK_RenderWindowInteractor() - "<<this);
   setMouseTracking(true);
+
+  myRenderWindow->Delete();
+  myRenderWindow->DoubleBufferOn();
 }
 
 
+void 
+QVTK_RenderWindowInteractor
+::Initialize(vtkGenericRenderWindowInteractor* theDevice)
+{
+  if(GetDevice())
+    myDevice->SetRenderWindow(NULL);
+
+  myDevice = theDevice;
+
+  if(theDevice)
+    theDevice->SetRenderWindow(getRenderWindow());
+}
+
+//----------------------------------------------------------------------------
 QVTK_RenderWindowInteractor
 ::~QVTK_RenderWindowInteractor() 
 {
@@ -93,6 +111,7 @@ QVTK_RenderWindowInteractor
       aSpaceMouse->close(x11Display());
 }
 
+
 //----------------------------------------------------------------------------
 vtkGenericRenderWindowInteractor* 
 QVTK_RenderWindowInteractor
@@ -101,27 +120,12 @@ QVTK_RenderWindowInteractor
   return myDevice.GetPointer();
 }
 
-void 
-QVTK_RenderWindowInteractor
-::SetDevice(vtkGenericRenderWindowInteractor* theDevice)
-{
-  myDevice = theDevice;
-}
-
 //----------------------------------------------------------------------------
-void
-QVTK_RenderWindowInteractor
-::SetRenderWindow(vtkRenderWindow *theRenderWindow)
-{
-  GetDevice()->SetRenderWindow(theRenderWindow);
-  theRenderWindow->DoubleBufferOn();
-}
-
 vtkRenderWindow*
 QVTK_RenderWindowInteractor
-::GetRenderWindow()
+::getRenderWindow()
 {
-  return GetDevice()->GetRenderWindow();
+  return myRenderWindow.GetPointer();
 }
 
 //----------------------------------------------------------------------------
@@ -149,9 +153,9 @@ QVTK_RenderWindowInteractor
   // Final initialization just before the widget is displayed
   GetDevice()->SetSize(width(),height());
 #ifndef WNT
-  GetRenderWindow()->SetDisplayId((void*)x11Display());
+  getRenderWindow()->SetDisplayId((void*)x11Display());
 #endif
-  GetRenderWindow()->SetWindowId((void*)winId());
+  getRenderWindow()->SetWindowId((void*)winId());
   GetDevice()->Enable();
 }
 
@@ -183,7 +187,7 @@ void
 QVTK_RenderWindowInteractor
 ::resizeEvent( QResizeEvent* theEvent )
 {
-  int* aSize = GetRenderWindow()->GetSize();
+  int* aSize = getRenderWindow()->GetSize();
   int aWidth = aSize[0];
   int aHeight = aSize[1];
 
@@ -191,7 +195,7 @@ QVTK_RenderWindowInteractor
 
   if(isVisible() && aWidth && aHeight){
     if( aWidth != width() || aHeight != height() ) {
-      vtkRendererCollection * aRenderers = GetRenderWindow()->GetRenderers();
+      vtkRendererCollection * aRenderers = getRenderWindow()->GetRenderers();
       aRenderers->InitTraversal();
       double aCoeff = 1.0;
       if(vtkRenderer *aRenderer = aRenderers->GetNextItem()) {
@@ -374,8 +378,7 @@ SVTK_RenderWindowInteractor
 ::SVTK_RenderWindowInteractor(QWidget* theParent, 
                               const char* theName):
   QVTK_RenderWindowInteractor(theParent,theName),
-  myEventCallbackCommand(vtkCallbackCommand::New()),
-  myRenderWindow(vtkRenderWindow::New())
+  myEventCallbackCommand(vtkCallbackCommand::New())
 {
   if(MYDEBUG) INFOS("SVTK_RenderWindowInteractor() - "<<this);
 
@@ -385,22 +388,20 @@ SVTK_RenderWindowInteractor
   myPriority = 0.0;
 
   myEventCallbackCommand->SetCallback(SVTK_RenderWindowInteractor::ProcessEvents);
+}
 
-  SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New();
-  SetDevice(aDevice);
-  aDevice->Delete();
-
-  aDevice->SetRenderWidget(this);
-
-  SetSelector(SVTK_Selector::New());
-  mySelector->Delete();
-
-  aDevice->SetSelector(GetSelector());
-
-  GetDevice()->SetRenderWindow(getRenderWindow()); 
-  myRenderWindow->Delete();
+void
+SVTK_RenderWindowInteractor
+::Initialize(vtkGenericRenderWindowInteractor* theDevice,
+            SVTK_Renderer* theRenderer,
+            SVTK_Selector* theSelector)
+{
+  QVTK_RenderWindowInteractor::Initialize(theDevice);
+  SetRenderer(theRenderer);
+  SetSelector(theSelector);
 }
 
+//----------------------------------------------------------------------------
 SVTK_RenderWindowInteractor
 ::~SVTK_RenderWindowInteractor() 
 {
@@ -420,14 +421,6 @@ SVTK_RenderWindowInteractor
   GetDevice()->SetRenderWindow(NULL);
 }
 
-vtkRenderWindow* 
-SVTK_RenderWindowInteractor
-::getRenderWindow()
-{
-  return myRenderWindow.GetPointer();
-}
-
-
 //----------------------------------------------------------------------------
 SVTK_Renderer* 
 SVTK_RenderWindowInteractor
index e36bfd23dc1d7e511883b4ac1bc4b988e9e82b68..4655bdadd9d58f7f7ea66416fad734e106cfddc9 100644 (file)
@@ -57,17 +57,15 @@ class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget
 
   ~QVTK_RenderWindowInteractor();
 
-  vtkGenericRenderWindowInteractor* 
-  GetDevice();
-
+  virtual
   void
-  SetDevice(vtkGenericRenderWindowInteractor* theDevice);
+  Initialize(vtkGenericRenderWindowInteractor* theDevice);
 
-  void
-  SetRenderWindow(vtkRenderWindow *theRenderWindow);
+  vtkGenericRenderWindowInteractor* 
+  GetDevice();
 
   vtkRenderWindow*
-  GetRenderWindow();
+  getRenderWindow();
 
   virtual
   void
@@ -98,6 +96,7 @@ class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget
 
   virtual bool x11Event( XEvent *e );
 
+  vtkSmartPointer<vtkRenderWindow> myRenderWindow;
   vtkSmartPointer<vtkGenericRenderWindowInteractor> myDevice;
 };
 
@@ -113,13 +112,13 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto
 
   ~SVTK_RenderWindowInteractor();
 
-  vtkRenderWindow*
-  getRenderWindow();
-
-  //----------------------------------------------------------------------------
+  virtual
   void
-  SetRenderer(SVTK_Renderer *theRenderer);
+  Initialize(vtkGenericRenderWindowInteractor* theDevice,
+            SVTK_Renderer* theRenderer,
+            SVTK_Selector* theSelector);
 
+  //----------------------------------------------------------------------------
   SVTK_Renderer* 
   GetRenderer();
 
@@ -140,9 +139,6 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto
   SVTK_Selector* 
   GetSelector();
 
-  void
-  SetSelector(SVTK_Selector* theSelector);
-
   Selection_Mode 
   SelectionMode() const;
 
@@ -178,6 +174,12 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto
   virtual void keyReleaseEvent( QKeyEvent* );
   virtual void contextMenuEvent( QContextMenuEvent * e );
 
+  void
+  SetRenderer(SVTK_Renderer *theRenderer);
+
+  void
+  SetSelector(SVTK_Selector* theSelector);
+
   void
   InitInteractorStyle(vtkInteractorStyle* theStyle);
 
@@ -198,7 +200,6 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto
   vtkSmartPointer<SVTK_Selector> mySelector;
 
   vtkSmartPointer<SVTK_Renderer> myRenderer;
-  vtkSmartPointer<vtkRenderWindow> myRenderWindow;
 
   typedef vtkSmartPointer<vtkInteractorStyle> PInteractorStyle;
   typedef std::stack<PInteractorStyle> TInteractorStyles;
index b1f648c3dfb5939c40aeadbec74ba8103ee6f972..3507b138cc3f5d8e1fe9e6d607bf420af737ba82 100644 (file)
@@ -95,24 +95,16 @@ SVTK_MainWindow
 
 void
 SVTK_MainWindow
-::Initialize(SVTK_Renderer *theRenderer)
+::Initialize(SVTK_RenderWindowInteractor* theInteractor)
 {
-  SetInteractor(new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor"));
-
-  SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New();
-  GetInteractor()->PushInteractorStyle(aStyle);
-  aStyle->Delete();
+  myInteractor = theInteractor;
+  SetEventDispatcher(myInteractor->GetDevice());
 
-  GetInteractor()->SetRenderer(theRenderer);
-}
+  setCentralWidget(myInteractor);
 
-void
-SVTK_MainWindow
-::Initialize()
-{
-  SVTK_Renderer* aRenderer = SVTK_Renderer::New();
-  Initialize(aRenderer);
-  aRenderer->Delete();
+  myInteractor->setFocusPolicy(StrongFocus);
+  myInteractor->setFocus();
+  setFocusProxy(myInteractor);
 }
 
 
@@ -125,20 +117,6 @@ SVTK_MainWindow
 
 
 //----------------------------------------------------------------------------
-void
-SVTK_MainWindow
-::SetInteractor(SVTK_RenderWindowInteractor* theInteractor)
-{
-  myInteractor = theInteractor;
-  SetEventDispatcher(myInteractor->GetDevice());
-
-  setCentralWidget(myInteractor);
-
-  myInteractor->setFocusPolicy(StrongFocus);
-  myInteractor->setFocus();
-  setFocusProxy(myInteractor);
-}
-
 SVTK_RenderWindowInteractor*
 SVTK_MainWindow
 ::GetInteractor()
@@ -217,13 +195,6 @@ SVTK_MainWindow
   return GetInteractor()->GetSelector();
 }
 
-void
-SVTK_MainWindow
-::SetSelector(SVTK_Selector* theSelector)
-{
-  GetInteractor()->SetSelector(theSelector);
-}
-
 Selection_Mode
 SVTK_MainWindow
 ::SelectionMode()
@@ -240,13 +211,6 @@ SVTK_MainWindow
 
 
 //----------------------------------------------------------------------------
-void
-SVTK_MainWindow
-::SetRenderer(SVTK_Renderer* theRenderer)
-{
-  GetInteractor()->SetRenderer(theRenderer);
-}
-
 SVTK_Renderer* 
 SVTK_MainWindow
 ::GetRenderer()
index caa7fae7b1eba8f4abb0143503dc5c77e8d04bed..0365e2a073155bde483e46fbd02e2c74a0c612fa 100644 (file)
@@ -53,11 +53,7 @@ public:
 
   virtual
   void
-  Initialize(SVTK_Renderer *theRenderer);
-
-  virtual
-  void
-  Initialize();
+  Initialize(SVTK_RenderWindowInteractor* theInteractor);
 
   virtual
   ~SVTK_MainWindow();
@@ -98,9 +94,6 @@ public:
   SVTK_Selector* 
   GetSelector();
 
-  void
-  SetSelector(SVTK_Selector* theSelector);
-
   Selection_Mode
   SelectionMode();
 
@@ -108,9 +101,6 @@ public:
   SetSelectionMode(Selection_Mode theMode);
 
   //----------------------------------------------------------------------------
-  void
-  SetRenderer(SVTK_Renderer* theRenderer);
-
   SVTK_Renderer* 
   GetRenderer();
 
index d75358b6cf1335a902708f771eacedfa75b170b5..d37277477e82ab8e2ae8f661c2a5a14453ef5379 100755 (executable)
 #include "VTKViewer_CellRectPicker.h"
 
 #include "SVTK_Event.h"
+#include "SVTK_Renderer.h"
 #include "SVTK_ViewWindow.h"
 #include "SVTK_ViewModelBase.h"
+#include "SVTK_InteractorStyle.h"
+#include "SVTK_RenderWindowInteractor.h"
+#include "SVTK_GenericRenderWindowInteractor.h"
 
 #include "SALOME_ListIteratorOfListIO.hxx"
 
@@ -52,7 +56,30 @@ SVTK_ViewWindow
 {
   if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){
     myMainWindow = new SVTK_MainWindow(this,"SVTK_MainWindow",aResourceMgr);
-    myMainWindow->Initialize();
+
+    SVTK_RenderWindowInteractor* anIteractor = 
+      new SVTK_RenderWindowInteractor(myMainWindow,"SVTK_RenderWindowInteractor");
+
+    SVTK_Renderer* aRenderer = SVTK_Renderer::New();
+
+    SVTK_Selector* aSelector = SVTK_Selector::New();
+
+    SVTK_GenericRenderWindowInteractor* aDevice = 
+      SVTK_GenericRenderWindowInteractor::New();
+    aDevice->SetRenderWidget(anIteractor);
+    aDevice->SetSelector(aSelector);
+
+    anIteractor->Initialize(aDevice,aRenderer,aSelector);
+
+    aDevice->Delete();
+    aRenderer->Delete();
+    aSelector->Delete();
+
+    myMainWindow->Initialize(anIteractor);
+
+    SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New();
+    anIteractor->PushInteractorStyle(aStyle);
+    aStyle->Delete();
 
     setCentralWidget(myMainWindow);