Browse Source

ctkVTKRenderView::OrientationWidget was not initialized

Derived classes must call init on the pimpl manually. Calling init() in the
mother class may results in actions on a derived public class not yet
finished to be created
Julien Finet 14 years ago
parent
commit
57045186ad

+ 2 - 2
Libs/Visualization/VTK/Widgets/ctkVTKAbstractView.cpp

@@ -105,8 +105,8 @@ ctkVTKAbstractView::ctkVTKAbstractView(ctkVTKAbstractViewPrivate* pimpl, QWidget
   : Superclass(parentWidget)
   , d_ptr(pimpl)
 {
-  Q_D(ctkVTKAbstractView);
-  d->init();
+  // derived classes must call init manually. Calling init() here may results in
+  // actions on a derived public class not yet finished to be created
 }
 
 //----------------------------------------------------------------------------

+ 11 - 4
Libs/Visualization/VTK/Widgets/ctkVTKRenderView.cpp

@@ -47,6 +47,7 @@ ctkVTKRenderViewPrivate::ctkVTKRenderViewPrivate(ctkVTKRenderView& object)
 {
   qRegisterMetaType<ctkAxesWidget::Axis>("ctkAxesWidget::Axis");
   this->Renderer = vtkSmartPointer<vtkRenderer>::New();
+  this->Axes = vtkSmartPointer<vtkAxesActor>::New();
   this->Orientation = vtkSmartPointer<vtkOrientationMarkerWidget>::New();
   this->ZoomFactor = 0.05;
   this->PitchRollYawIncrement = 5;
@@ -60,6 +61,8 @@ ctkVTKRenderViewPrivate::ctkVTKRenderViewPrivate(ctkVTKRenderView& object)
   this->RockEnabled = false;
   this->RockIncrement = 0;
   this->RockLength = 200;
+
+  this->Orientation->SetOrientationMarker(this->Axes);
 }
 
 // --------------------------------------------------------------------------
@@ -76,9 +79,15 @@ void ctkVTKRenderViewPrivate::setupCornerAnnotation()
 //---------------------------------------------------------------------------
 void ctkVTKRenderViewPrivate::setupRendering()
 {
+  Q_Q(ctkVTKRenderView);
   // Add renderer
   this->RenderWindow->AddRenderer(this->Renderer);
   this->ctkVTKAbstractViewPrivate::setupRendering();
+  // The interactor in RenderWindow exists after the renderwindow is set to
+  // the QVTKWidet
+  this->Orientation->SetInteractor(this->RenderWindow->GetInteractor());
+  this->Orientation->SetEnabled(1);
+  this->Orientation->InteractiveOff();
 }
 
 //----------------------------------------------------------------------------
@@ -197,6 +206,8 @@ void ctkVTKRenderViewPrivate::doRock()
 ctkVTKRenderView::ctkVTKRenderView(QWidget* parentWidget)
   : Superclass(new ctkVTKRenderViewPrivate(*this), parentWidget)
 {
+  Q_D(ctkVTKRenderView);
+  d->init();
 }
 
 //----------------------------------------------------------------------------
@@ -207,13 +218,9 @@ ctkVTKRenderView::~ctkVTKRenderView()
 void ctkVTKRenderView::setInteractor(vtkRenderWindowInteractor* newInteractor)
 {
   Q_D(ctkVTKRenderView);
-
   logger.trace("setInteractor");
   this->Superclass::setInteractor(newInteractor);
-  d->Orientation->SetOrientationMarker(d->Axes);
   d->Orientation->SetInteractor(newInteractor);
-  d->Orientation->SetEnabled(1);
-  d->Orientation->InteractiveOff();
 }
 
 // --------------------------------------------------------------------------

+ 2 - 0
Libs/Visualization/VTK/Widgets/ctkVTKSliceView.cpp

@@ -101,6 +101,8 @@ void ctkVTKSliceViewPrivate::setupRendering()
 ctkVTKSliceView::ctkVTKSliceView(QWidget* parentWidget)
   : Superclass(new ctkVTKSliceViewPrivate(*this), parentWidget)
 {
+  Q_D(ctkVTKSliceView);
+  d->init();
 }
 
 // --------------------------------------------------------------------------